-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PB-18505. Add support for the conditional field
- Loading branch information
mateusz
authored and
john
committed
Apr 12, 2019
1 parent
9019ad7
commit 4198dc2
Showing
17 changed files
with
842 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
sdk/src/main/java/com/silanis/esl/api/model/ConditionalField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
72
sdk/src/main/java/com/silanis/esl/api/model/FieldCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
sdk/src/main/java/com/silanis/esl/sdk/ConditionalField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
sdk/src/main/java/com/silanis/esl/sdk/examples/ConditionalFieldExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.