Skip to content

Commit

Permalink
PB-18505. Add support for the conditional field
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz authored and john committed Apr 12, 2019
1 parent 9019ad7 commit 4198dc2
Show file tree
Hide file tree
Showing 17 changed files with 842 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sdk/src/main/java/com/silanis/esl/api/model/BasePackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class BasePackage extends Entity
public static final String FIELD_CREATED = "created";
@JsonIgnore
public static final String FIELD_TIMEZONE_ID = "timezoneId";
@JsonIgnore
private static final String FIELD_CONDITIONS = "conditions";

// Empty Constructor
public BasePackage ( ) {}
Expand All @@ -91,6 +93,7 @@ public BasePackage ( ) {}
protected String _visibility = "ACCOUNT";
protected java.util.Date _created;
protected String _timezoneId;
protected List<FieldCondition> conditions;

// Accessors

Expand Down Expand Up @@ -579,4 +582,15 @@ public BasePackage safeSetTimezoneId( String value ){
public String getTimezoneId(){
return _timezoneId;
}

public BasePackage setConditions(List<FieldCondition> value) {

this.conditions = value;
setDirty(FIELD_CONDITIONS);
return this;
}

public List<FieldCondition> getConditions() {
return conditions;
}
}
28 changes: 28 additions & 0 deletions sdk/src/main/java/com/silanis/esl/api/model/ConditionalField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.silanis.esl.api.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public class ConditionalField extends Field {

@JsonIgnore
private static final String FIELD_CONDITIONS = "conditions";

private List<FieldCondition> conditions;

public ConditionalField() { }

public Field setConditions(List<FieldCondition> value) {

this.conditions = value;
setDirty(FIELD_CONDITIONS);
return this;
}

public List<FieldCondition> getConditions() {
return conditions;
}
}
72 changes: 72 additions & 0 deletions sdk/src/main/java/com/silanis/esl/api/model/FieldCondition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.silanis.esl.api.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.io.Serializable;

import static com.silanis.esl.api.util.SchemaSanitizer.throwOnNull;
import static com.silanis.esl.api.util.SchemaSanitizer.trim;

@JsonIgnoreProperties(ignoreUnknown = true)
public class FieldCondition extends Model implements Serializable {

@JsonIgnore
public static final String FIELD_ID = "id";
@JsonIgnore
public static final String FIELD_CONDITION = "condition";
@JsonIgnore
public static final String FIELD_ACTION = "action";

protected String id;
protected String condition;
protected String action;

public FieldCondition() {

}

public FieldCondition setId(String value) {

throwOnNull(FIELD_ID, value);
value = trim(value);

this.id = value;
setDirty(FIELD_ID);
return this;
}

public String getId() {
return id;
}

public FieldCondition setCondition(String value) {

throwOnNull(FIELD_CONDITION, value);
value = trim(value);

this.condition = value;
setDirty(FIELD_CONDITION);
return this;
}

public String getCondition() {
return condition;
}

public FieldCondition setAction(String value) {

throwOnNull(FIELD_ACTION, value);
value = trim(value);

this.action = value;
setDirty(FIELD_ACTION);
return this;
}

public String getAction() {
return action;
}
}


17 changes: 17 additions & 0 deletions sdk/src/main/java/com/silanis/esl/sdk/ConditionalField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.silanis.esl.sdk;

import java.io.Serializable;
import java.util.List;

public class ConditionalField extends Field implements Serializable {

private List<FieldCondition> conditions;

public void setConditions( List<FieldCondition> conditions ) {
this.conditions = conditions;
}

public List<FieldCondition> getConditions() {
return conditions;
}
}
5 changes: 5 additions & 0 deletions sdk/src/main/java/com/silanis/esl/sdk/DocumentPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class DocumentPackage implements Serializable {
private List<Message> messages;
private Visibility visibility;
private String timezoneId;
private List<FieldCondition> conditions;

/**
* @param name the name of the package
Expand Down Expand Up @@ -320,4 +321,8 @@ public void setVisibility(Visibility visibility) {
public String getTimezoneId() { return timezoneId; }

public void setTimezoneId(String timezoneId) { this.timezoneId = timezoneId; }

public List<FieldCondition> getConditions() { return conditions; }

public void setConditions(List<FieldCondition> conditions) { this.conditions = conditions; }
}
37 changes: 37 additions & 0 deletions sdk/src/main/java/com/silanis/esl/sdk/FieldCondition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.silanis.esl.sdk;

import java.io.Serializable;

public class FieldCondition implements Serializable {

private String id;
private String condition;
private String action;


public FieldCondition() {}

public String getId() {
return id;
}

public void setId( String id ) {
this.id = id;
}

public String getCondition() {
return condition;
}

public void setCondition( String condition ) {
this.condition = condition;
}

public String getAction() {
return action;
}

public void setAction( String action ) {
this.action = action;
}
}
16 changes: 16 additions & 0 deletions sdk/src/main/java/com/silanis/esl/sdk/builder/PackageBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class PackageBuilder {
private DocumentPackageAttributes attributes;
private Visibility visibility;
private String timezoneId;
private final List<FieldCondition> conditions = new ArrayList<FieldCondition>();

private static final String ORIGIN_KEY = "origin";

Expand Down Expand Up @@ -174,6 +175,10 @@ public DocumentPackage build() {
documentPackage.setTimezoneId(timezoneId);
}

if (conditions != null && !conditions.isEmpty()) {
documentPackage.setConditions(conditions);
}

return documentPackage;
}

Expand Down Expand Up @@ -347,4 +352,15 @@ public PackageBuilder withOrigin( String origin ) {
this.attributes.append(ORIGIN_KEY, origin);
return this;
}

/**
* Sets the condition for the package field.
*
* @param condition field condition
* @return the package builder itself
*/
public PackageBuilder withCondition( FieldCondition condition) {
this.conditions.add(condition);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.silanis.esl.sdk.examples;

import com.silanis.esl.sdk.ConditionalField;
import com.silanis.esl.sdk.DocumentPackage;
import com.silanis.esl.sdk.DocumentType;
import com.silanis.esl.sdk.FieldCondition;
import com.silanis.esl.sdk.FieldId;
import com.silanis.esl.sdk.FieldStyle;
import com.silanis.esl.sdk.PackageId;
import com.silanis.esl.sdk.SignatureId;
import com.silanis.esl.sdk.builder.PackageBuilder;
import com.silanis.esl.sdk.builder.SignerBuilder;

import java.util.ArrayList;
import java.util.List;

import static com.silanis.esl.sdk.builder.DocumentBuilder.newDocumentWithName;
import static com.silanis.esl.sdk.builder.FieldBuilder.*;
import static com.silanis.esl.sdk.builder.SignatureBuilder.signatureFor;

public class ConditionalFieldExample extends SDKSample {

private final String documentId = "DocumentId";
private final SignatureId signatureId = new SignatureId("signatureId");
private final FieldId fieldId1 = new FieldId("fieldId1");
private final FieldId fieldId2 = new FieldId("fieldId2");

public DocumentPackage retrievedPackageWithoutConditions;
public DocumentPackage retrievedPackageWithUpdatedConditions;

public static void main(String... args) {
new ConditionalFieldExample().run();
}

@Override
protected void execute() {
FieldCondition condition = new FieldCondition();
condition.setId("ConditionId");
condition.setCondition("document['DocumentId'].field['fieldId2'].value == 'X'");
condition.setAction("document['DocumentId'].field['fieldId1'].enabled = true");

DocumentPackage superDuperPackage = PackageBuilder.newPackageNamed(getPackageName())
.describedAs("Description")
.withSigner(SignerBuilder.newSignerWithEmail(email1)
.withFirstName("Patty")
.withLastName("Galant"))
.withDocument(newDocumentWithName("Document")
.withId(documentId)
.fromStream(documentInputStream1, DocumentType.PDF)
.withSignature(signatureFor(email1)
.withId(signatureId)
.onPage(0)
.atPosition(400, 100)
.withField(textField()
.withId(fieldId1)
.onPage(0)
.atPosition(0, 0))
.withField(checkBox()
.withId(fieldId2)
.onPage(0)
.atPosition(0, 0))))
.withCondition(condition)
.build();

PackageId packageId = eslClient.createPackageOneStep(superDuperPackage);
retrievedPackage = eslClient.getPackage(packageId);

FieldCondition newCondition = new FieldCondition();
newCondition.setId("ConditionId");
newCondition.setCondition("document['DocumentId'].field['fieldId2'].value == 'X'");
newCondition.setAction("document['DocumentId'].field['fieldId1'].enabled = false");
List<FieldCondition> conditions = new ArrayList<FieldCondition>();
conditions.add(newCondition);

ConditionalField conditionalField = new ConditionalField();
conditionalField.setId(fieldId2);
conditionalField.setConditions(conditions);
conditionalField.setStyle(FieldStyle.UNBOUND_CHECK_BOX);

eslClient.getApprovalService().updateConditionalField(packageId, documentId, signatureId, conditionalField);
retrievedPackageWithUpdatedConditions = eslClient.getPackage(packageId);

conditions.clear();
conditionalField.setConditions(conditions);
eslClient.getApprovalService().updateConditionalField(packageId, documentId, signatureId, conditionalField);
retrievedPackageWithoutConditions = eslClient.getPackage(packageId);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class UrlTemplate {
public static final String FIELD_PATH = "/packages/{packageId}/documents/{documentId}/approvals/{approvalId}/fields";
public static final String FIELD_ID_PATH = "/packages/{packageId}/documents/{documentId}/approvals/{approvalId}/fields/{fieldId}";
public static final String SIGNABLE_APPROVAL_PATH = "/packages/{packageId}/documents/{documentId}/signers/{signerId}/approvals";
public static final String CONDITIONAL_FIELD_PATH = "/packages/{packageId}/documents/{documentId}/approvals/{approvalId}/fields/{fieldId}/conditionalFields";

// Provider Document Resource
public static final String PROVIDER_DOCUMENTS = "/documents";
Expand Down
Loading

0 comments on commit 4198dc2

Please sign in to comment.