From 3f2687c858f5f2c198b712ad6b001a3665e01ff9 Mon Sep 17 00:00:00 2001 From: x_MacieMi1 Date: Thu, 13 Jun 2019 09:32:06 +0200 Subject: [PATCH] PB-25843 Referenced Conditions --- .../esl/api/model/ReferencedConditions.java | 48 ++++ .../esl/api/model/ReferencedDocument.java | 49 ++++ .../esl/api/model/ReferencedField.java | 47 ++++ .../api/model/ReferencedFieldConditions.java | 54 +++++ .../silanis/esl/sdk/ReferencedConditions.java | 25 ++ .../silanis/esl/sdk/ReferencedDocument.java | 25 ++ .../com/silanis/esl/sdk/ReferencedField.java | 23 ++ .../esl/sdk/ReferencedFieldConditions.java | 25 ++ .../sdk/builder/FieldConditionBuilder.java | 37 +++ .../PackageReferencedConditionsExample.java | 128 ++++++++++ .../silanis/esl/sdk/internal/UrlTemplate.java | 1 + .../ReferencedConditionsConverter.java | 39 +++ .../ReferencedDocumentConverter.java | 39 +++ .../ReferencedFieldConditionsConverter.java | 53 +++++ .../converter/ReferencedFieldConverter.java | 63 +++++ .../esl/sdk/service/PackageService.java | 46 ++++ .../builder/FieldConditionBuilderTest.java | 26 ++ .../ReferencedConditionsConverterTest.java | 222 ++++++++++++++++++ .../ReferencedDocumentConverterTest.java | 58 +++++ ...eferencedFieldConditionsConverterTest.java | 65 +++++ .../ReferencedFieldConverterTest.java | 57 +++++ .../converter/StaticConverterTest.java | 17 ++ ...ackageReferencedConditionsExampleTest.java | 35 +++ 23 files changed, 1182 insertions(+) create mode 100644 sdk/src/main/java/com/silanis/esl/api/model/ReferencedConditions.java create mode 100644 sdk/src/main/java/com/silanis/esl/api/model/ReferencedDocument.java create mode 100644 sdk/src/main/java/com/silanis/esl/api/model/ReferencedField.java create mode 100644 sdk/src/main/java/com/silanis/esl/api/model/ReferencedFieldConditions.java create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/ReferencedConditions.java create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/ReferencedDocument.java create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/ReferencedField.java create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/ReferencedFieldConditions.java create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/builder/FieldConditionBuilder.java create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/examples/PackageReferencedConditionsExample.java create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedConditionsConverter.java create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedDocumentConverter.java create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConditionsConverter.java create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConverter.java create mode 100644 sdk/src/test/java/com/silanis/esl/sdk/builder/FieldConditionBuilderTest.java create mode 100644 sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedConditionsConverterTest.java create mode 100644 sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedDocumentConverterTest.java create mode 100644 sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConditionsConverterTest.java create mode 100644 sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConverterTest.java create mode 100644 sdk/src/test/java/com/silanis/esl/sdk/internal/converter/StaticConverterTest.java create mode 100644 tester/src/test/java/com/silanis/esl/sdk/examples/PackageReferencedConditionsExampleTest.java diff --git a/sdk/src/main/java/com/silanis/esl/api/model/ReferencedConditions.java b/sdk/src/main/java/com/silanis/esl/api/model/ReferencedConditions.java new file mode 100644 index 000000000..26a25a028 --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/api/model/ReferencedConditions.java @@ -0,0 +1,48 @@ +package com.silanis.esl.api.model; + +import static com.silanis.esl.api.util.SchemaSanitizer.throwOnNull; +import static com.silanis.esl.api.util.SchemaSanitizer.trim; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.io.Serializable; +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ReferencedConditions extends Model implements Serializable { + + @JsonIgnore + public static final String PACKAGE_ID = "packageId"; + @JsonIgnore + public static final String REF_DOCUMENTS = "documents"; + + private String packageId; + private List documents; + + public ReferencedConditions setPackageId(String value) { + + throwOnNull(PACKAGE_ID, value); + value = trim(value); + + this.packageId = value; + setDirty(PACKAGE_ID); + return this; + } + + public String getPackageId() { + return packageId; + } + + public ReferencedConditions setDocuments(List value) { + + throwOnNull(REF_DOCUMENTS, value); + + this.documents = value; + setDirty(REF_DOCUMENTS); + return this; + } + + public List getDocuments() { + return documents; + } +} \ No newline at end of file diff --git a/sdk/src/main/java/com/silanis/esl/api/model/ReferencedDocument.java b/sdk/src/main/java/com/silanis/esl/api/model/ReferencedDocument.java new file mode 100644 index 000000000..27e3e84cc --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/api/model/ReferencedDocument.java @@ -0,0 +1,49 @@ +package com.silanis.esl.api.model; + +import static com.silanis.esl.api.util.SchemaSanitizer.throwOnNull; +import static com.silanis.esl.api.util.SchemaSanitizer.trim; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.io.Serializable; +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ReferencedDocument extends Model implements Serializable { + + @JsonIgnore + public static final String FIELD_ID = "documentId"; + @JsonIgnore + public static final String REF_FIELDS = "fields"; + + private String documentId; + private List fields; + + public ReferencedDocument setDocumentId(String value) { + + throwOnNull(FIELD_ID, value); + value = trim(value); + + this.documentId = value; + setDirty(FIELD_ID); + return this; + } + + public String getDocumentId() { + return documentId; + } + + public ReferencedDocument setFields(List value) { + + throwOnNull(REF_FIELDS, value); + + this.fields = value; + setDirty(REF_FIELDS); + return this; + } + + public List getFields() { + return fields; + } +} + diff --git a/sdk/src/main/java/com/silanis/esl/api/model/ReferencedField.java b/sdk/src/main/java/com/silanis/esl/api/model/ReferencedField.java new file mode 100644 index 000000000..93aa32afb --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/api/model/ReferencedField.java @@ -0,0 +1,47 @@ +package com.silanis.esl.api.model; + +import static com.silanis.esl.api.util.SchemaSanitizer.throwOnNull; +import static com.silanis.esl.api.util.SchemaSanitizer.trim; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.io.Serializable; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ReferencedField extends Model implements Serializable { + + @JsonIgnore + public static final String FIELD_ID = "fieldId"; + @JsonIgnore + public static final String REF_CONDITIONS = "conditions"; + + private String fieldId; + private ReferencedFieldConditions conditions; + + public ReferencedField setFieldId(String value) { + + throwOnNull(FIELD_ID, value); + value = trim(value); + + this.fieldId = value; + setDirty(FIELD_ID); + return this; + } + + public String getFieldId() { + return fieldId; + } + + public ReferencedField setConditions(ReferencedFieldConditions value) { + + throwOnNull(REF_CONDITIONS, value); + + this.conditions = value; + setDirty(REF_CONDITIONS); + return this; + } + + public ReferencedFieldConditions getConditions() { + return conditions; + } +} \ No newline at end of file diff --git a/sdk/src/main/java/com/silanis/esl/api/model/ReferencedFieldConditions.java b/sdk/src/main/java/com/silanis/esl/api/model/ReferencedFieldConditions.java new file mode 100644 index 000000000..c5b0ea4d9 --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/api/model/ReferencedFieldConditions.java @@ -0,0 +1,54 @@ +package com.silanis.esl.api.model; + +import static com.silanis.esl.api.util.SchemaSanitizer.throwOnNull; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.io.Serializable; +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ReferencedFieldConditions extends Model implements Serializable { + + @JsonIgnore + public static final String REF_IN_CONDITION = "referencedInCondition"; + @JsonIgnore + public static final String REF_IN_ACTION = "referencedInAction"; + + private List referencedInCondition; + private List referencedInAction; + + public ReferencedFieldConditions() { + } + + public ReferencedFieldConditions(List referencedInCondition, List referencedInAction) { + this.referencedInCondition = referencedInCondition; + this.referencedInAction = referencedInAction; + } + + public ReferencedFieldConditions setReferencedInCondition(List value) { + + throwOnNull(REF_IN_CONDITION, value); + + this.referencedInCondition = value; + setDirty(REF_IN_CONDITION); + return this; + } + + public List getReferencedInCondition() { + return referencedInCondition; + } + + public ReferencedFieldConditions setReferencedInAction(List value) { + + throwOnNull(REF_IN_ACTION, value); + + this.referencedInAction = value; + setDirty(REF_IN_ACTION); + return this; + } + + public List getReferencedInAction() { + return referencedInAction; + } +} \ No newline at end of file diff --git a/sdk/src/main/java/com/silanis/esl/sdk/ReferencedConditions.java b/sdk/src/main/java/com/silanis/esl/sdk/ReferencedConditions.java new file mode 100644 index 000000000..3b33435d4 --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/ReferencedConditions.java @@ -0,0 +1,25 @@ +package com.silanis.esl.sdk; + +import java.util.List; + +public class ReferencedConditions { + + private String packageId; + private List documents; + + public String getPackageId() { + return packageId; + } + + public void setPackageId(String packageId) { + this.packageId = packageId; + } + + public List getDocuments() { + return documents; + } + + public void setDocuments(List documents) { + this.documents = documents; + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/ReferencedDocument.java b/sdk/src/main/java/com/silanis/esl/sdk/ReferencedDocument.java new file mode 100644 index 000000000..73e0cbe0a --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/ReferencedDocument.java @@ -0,0 +1,25 @@ +package com.silanis.esl.sdk; + +import java.util.List; + +public class ReferencedDocument { + + private String documentId; + private List fields; + + public String getDocumentId() { + return documentId; + } + + public void setDocumentId(String documentId) { + this.documentId = documentId; + } + + public List getFields() { + return fields; + } + + public void setFields(List fields) { + this.fields = fields; + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/ReferencedField.java b/sdk/src/main/java/com/silanis/esl/sdk/ReferencedField.java new file mode 100644 index 000000000..f34e89f52 --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/ReferencedField.java @@ -0,0 +1,23 @@ +package com.silanis.esl.sdk; + +public class ReferencedField { + + private String fieldId; + private ReferencedFieldConditions conditions; + + public String getFieldId() { + return fieldId; + } + + public void setFieldId(String fieldId) { + this.fieldId = fieldId; + } + + public ReferencedFieldConditions getConditions() { + return conditions; + } + + public void setConditions(ReferencedFieldConditions conditions) { + this.conditions = conditions; + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/ReferencedFieldConditions.java b/sdk/src/main/java/com/silanis/esl/sdk/ReferencedFieldConditions.java new file mode 100644 index 000000000..bb6effffb --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/ReferencedFieldConditions.java @@ -0,0 +1,25 @@ +package com.silanis.esl.sdk; + +import java.util.List; + +public class ReferencedFieldConditions { + + private List referencedInCondition; + private List referencedInAction; + + public List getReferencedInCondition() { + return referencedInCondition; + } + + public void setReferencedInCondition(List referencedInCondition) { + this.referencedInCondition = referencedInCondition; + } + + public List getReferencedInAction() { + return referencedInAction; + } + + public void setReferencedInAction(List referencedInAction) { + this.referencedInAction = referencedInAction; + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/builder/FieldConditionBuilder.java b/sdk/src/main/java/com/silanis/esl/sdk/builder/FieldConditionBuilder.java new file mode 100644 index 000000000..dd4606954 --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/builder/FieldConditionBuilder.java @@ -0,0 +1,37 @@ +package com.silanis.esl.sdk.builder; + +import com.silanis.esl.sdk.FieldCondition; + +public class FieldConditionBuilder { + + private String id; + private String condition; + private String action; + + public static FieldConditionBuilder newFieldCondition() { + return new FieldConditionBuilder(); + } + + public FieldConditionBuilder withId(String id) { + this.id = id; + return this; + } + + public FieldConditionBuilder withCondition(String condition) { + this.condition = condition; + return this; + } + + public FieldConditionBuilder withAction(String action) { + this.action = action; + return this; + } + + public FieldCondition build() { + FieldCondition fieldCondition = new FieldCondition(); + fieldCondition.setId(this.id); + fieldCondition.setCondition(this.condition); + fieldCondition.setAction(this.action); + return fieldCondition; + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/examples/PackageReferencedConditionsExample.java b/sdk/src/main/java/com/silanis/esl/sdk/examples/PackageReferencedConditionsExample.java new file mode 100644 index 000000000..5c101d8a4 --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/examples/PackageReferencedConditionsExample.java @@ -0,0 +1,128 @@ +package com.silanis.esl.sdk.examples; + +import static com.silanis.esl.sdk.builder.DocumentBuilder.newDocumentWithName; +import static com.silanis.esl.sdk.builder.PackageBuilder.newPackageNamed; +import static com.silanis.esl.sdk.builder.SignatureBuilder.signatureFor; +import static com.silanis.esl.sdk.builder.SignerBuilder.newSignerWithEmail; +import static org.joda.time.DateTime.now; + +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.ReferencedConditions; +import com.silanis.esl.sdk.SignatureId; +import com.silanis.esl.sdk.builder.FieldBuilder; +import com.silanis.esl.sdk.builder.FieldConditionBuilder; + +/** + * Example SDK code for the /referencedConditions + * + * @author x_MacieMi1 (Michał Maciejewski) + */ +public class PackageReferencedConditionsExample extends SDKSample { + + private static final String DOCUMENT_ID_1 = "documentId1"; + private static final String DOCUMENT_ID_2 = "documentId2"; + + private final SignatureId signatureId1 = new SignatureId("signatureId1"); + private final SignatureId signatureId2 = new SignatureId("signatureId2"); + + private final FieldId fieldId1 = new FieldId("fieldId1"); + private final FieldId fieldId2 = new FieldId("fieldId2"); + private final FieldId fieldId3 = new FieldId("fieldId3"); + private final FieldId fieldId4 = new FieldId("fieldId4"); + private final FieldId fieldId5 = new FieldId("fieldId5"); + private final FieldId fieldId6 = new FieldId("fieldId6"); + + public ReferencedConditions packageLevelRefConditions; + public ReferencedConditions documentLevelRefConditions; + public ReferencedConditions fieldLevelRefConditions; + + public static void main(String... args) { + new PackageReferencedConditionsExample().run(); + } + + public void execute() { + DocumentPackage superDuperPackage = newPackageNamed(getPackageName()) + .describedAs("This is a package created using the eSignLive SDK") + .expiresAt(now().plusMonths(1).toDate()) + .withEmailMessage("This message should be delivered to all signers") + .withSigner(newSignerWithEmail(email1) + .withCustomId("signer1") + .withFirstName("firstName1") + .withLastName("lastName1")) + .withDocument(newDocumentWithName("PackageReferencedConditionsExampleDocument1") + .fromStream(documentInputStream1, DocumentType.PDF) + .withId(DOCUMENT_ID_1) + .withSignature(signatureFor(email1) + .onPage(0) + .atPosition(100, 100) + .withId(signatureId1) + .withField(FieldBuilder.textField() + .withName("field1") + .withId(fieldId1) + .atPosition(400, 100) + .onPage(0) + .build()) + .withField(FieldBuilder.textField() + .withName("field2") + .withId(fieldId2) + .atPosition(400, 200) + .onPage(0) + .build()) + .withField(FieldBuilder.textField() + .withName("field3") + .withId(fieldId3) + .atPosition(400, 300) + .onPage(0) + .build()) + ) + ) + .withDocument(newDocumentWithName("PackageReferencedConditionsExampleDocument2") + .fromStream(documentInputStream2, DocumentType.PDF) + .withId(DOCUMENT_ID_2) + .withSignature(signatureFor(email1) + .onPage(0) + .atPosition(100, 400) + .withId(signatureId2) + .withField(FieldBuilder.textField() + .withName("field4") + .withId(fieldId4) + .atPosition(400, 100) + .onPage(0) + .build()) + .withField(FieldBuilder.textField() + .withName("field5") + .withId(fieldId5) + .atPosition(400, 200) + .onPage(0) + .build()) + .withField(FieldBuilder.textField() + .withName("field6") + .withId(fieldId6) + .atPosition(400, 300) + .onPage(0) + .build()) + ) + ) + .withCondition(createCondition("condition1", DOCUMENT_ID_1, fieldId1.getId(), DOCUMENT_ID_1, fieldId2.getId())) + .withCondition(createCondition("condition2", DOCUMENT_ID_1, fieldId1.getId(), DOCUMENT_ID_1, fieldId3.getId())) + .withCondition(createCondition("condition3", DOCUMENT_ID_2, fieldId4.getId(), DOCUMENT_ID_2, fieldId5.getId())) + .build(); + + packageId = eslClient.createPackageOneStep(superDuperPackage); + + packageLevelRefConditions = eslClient.getPackageService().getReferencedConditions(packageId.getId()); + documentLevelRefConditions = eslClient.getPackageService().getReferencedConditions(packageId.getId(), DOCUMENT_ID_1); + fieldLevelRefConditions = eslClient.getPackageService().getReferencedConditions(packageId.getId(), DOCUMENT_ID_1, fieldId1.getId()); + } + + private FieldCondition createCondition(String id, String conditionDocId, String conditionFieldId, String actionDocId, String actionFieldId) { + return FieldConditionBuilder.newFieldCondition() + .withId(id) + .withCondition(String.format("document['%s'].field['%s'].empty == true", conditionDocId, conditionFieldId)) + .withAction(String.format("document['%s'].field['%s'].enabled = true", actionDocId, actionFieldId)) + .build(); + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java b/sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java index bfd3bbf81..a6bc00e59 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java @@ -17,6 +17,7 @@ public class UrlTemplate { public static final String PACKAGE_FIELDS_LIST_PATH = "/packages?query={status}&from={from}&to={to}&fields={fields}"; public static final String PACKAGE_LIST_STATUS_DATE_RANGE_PATH = "/packages?query={status}&from={from}&to={to}&lastUpdatedStartDate={lastUpdatedStartDate}&lastUpdatedEndDate={lastUpdatedEndDate}"; public static final String PACKAGE_ID_PATH = "/packages/{packageId}"; + public static final String PACKAGE_REFERENCED_CONDITIONS_PATH = "/packages/{packageId}/referencedConditions"; public static final String DOCUMENT_PATH = "/packages/{packageId}/documents"; public static final String DOCUMENT_VISIBILITY_PATH = "/packages/{packageId}/documents/visibility"; public static final String DOCUMENT_ID_PATH = "/packages/{packageId}/documents/{documentId}"; diff --git a/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedConditionsConverter.java b/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedConditionsConverter.java new file mode 100644 index 000000000..d9b30ab88 --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedConditionsConverter.java @@ -0,0 +1,39 @@ +package com.silanis.esl.sdk.internal.converter; + +import java.util.ArrayList; +import java.util.List; + +public class ReferencedConditionsConverter { + + public static com.silanis.esl.api.model.ReferencedConditions toAPI(com.silanis.esl.sdk.ReferencedConditions sdkReferencedConditions) { + if (sdkReferencedConditions == null) { + return null; + } + + List apiReferencedDocuments = new ArrayList(); + for (com.silanis.esl.sdk.ReferencedDocument sdkReferencedDocument : sdkReferencedConditions.getDocuments()) { + apiReferencedDocuments.add(ReferencedDocumentConverter.toAPI(sdkReferencedDocument)); + } + + com.silanis.esl.api.model.ReferencedConditions apiReferencedConditions = new com.silanis.esl.api.model.ReferencedConditions(); + apiReferencedConditions.setPackageId(sdkReferencedConditions.getPackageId()); + apiReferencedConditions.setDocuments(apiReferencedDocuments); + return apiReferencedConditions; + } + + public static com.silanis.esl.sdk.ReferencedConditions toSDK(com.silanis.esl.api.model.ReferencedConditions apiReferencedConditions) { + if (apiReferencedConditions == null) { + return null; + } + + List sdkReferencedDocuments = new ArrayList(); + for (com.silanis.esl.api.model.ReferencedDocument apiReferenceddocument : apiReferencedConditions.getDocuments()) { + sdkReferencedDocuments.add(ReferencedDocumentConverter.toSDK(apiReferenceddocument)); + } + + com.silanis.esl.sdk.ReferencedConditions sdkReferencedConditions = new com.silanis.esl.sdk.ReferencedConditions(); + sdkReferencedConditions.setPackageId(apiReferencedConditions.getPackageId()); + sdkReferencedConditions.setDocuments(sdkReferencedDocuments); + return sdkReferencedConditions; + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedDocumentConverter.java b/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedDocumentConverter.java new file mode 100644 index 000000000..22942161e --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedDocumentConverter.java @@ -0,0 +1,39 @@ +package com.silanis.esl.sdk.internal.converter; + +import java.util.ArrayList; +import java.util.List; + +public class ReferencedDocumentConverter { + + public static com.silanis.esl.api.model.ReferencedDocument toAPI(com.silanis.esl.sdk.ReferencedDocument sdkReferencedDocument) { + if (sdkReferencedDocument == null) { + return null; + } + + List apiReferencedFields = new ArrayList(); + for (com.silanis.esl.sdk.ReferencedField sdkReferencedField : sdkReferencedDocument.getFields()) { + apiReferencedFields.add(ReferencedFieldConverter.toAPI(sdkReferencedField)); + } + + com.silanis.esl.api.model.ReferencedDocument apiReferencedDocument = new com.silanis.esl.api.model.ReferencedDocument(); + apiReferencedDocument.setDocumentId(sdkReferencedDocument.getDocumentId()); + apiReferencedDocument.setFields(apiReferencedFields); + return apiReferencedDocument; + } + + public static com.silanis.esl.sdk.ReferencedDocument toSDK(com.silanis.esl.api.model.ReferencedDocument apiReferencedDocument) { + if (apiReferencedDocument == null) { + return null; + } + + List sdkReferencedFields = new ArrayList(); + for (com.silanis.esl.api.model.ReferencedField apiReferencedField : apiReferencedDocument.getFields()) { + sdkReferencedFields.add(ReferencedFieldConverter.toSDK(apiReferencedField)); + } + + com.silanis.esl.sdk.ReferencedDocument sdkReferencedDocument = new com.silanis.esl.sdk.ReferencedDocument(); + sdkReferencedDocument.setDocumentId(apiReferencedDocument.getDocumentId()); + sdkReferencedDocument.setFields(sdkReferencedFields); + return sdkReferencedDocument; + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConditionsConverter.java b/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConditionsConverter.java new file mode 100644 index 000000000..e86c8bb87 --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConditionsConverter.java @@ -0,0 +1,53 @@ +package com.silanis.esl.sdk.internal.converter; + +import java.util.ArrayList; +import java.util.List; + +public class ReferencedFieldConditionsConverter { + + public static com.silanis.esl.api.model.ReferencedFieldConditions toAPI(com.silanis.esl.sdk.ReferencedFieldConditions sdkReferencedFieldConditions) { + if (sdkReferencedFieldConditions == null) { + return null; + } + + List apiFieldConditionsInCondition = new ArrayList(); + for (com.silanis.esl.sdk.FieldCondition sdkFieldCondition : sdkReferencedFieldConditions.getReferencedInCondition()) { + FieldConditionConverter fieldConditionConverter = new FieldConditionConverter(sdkFieldCondition); + apiFieldConditionsInCondition.add(fieldConditionConverter.toAPIFieldCondition()); + } + + List apiFieldConditionsInAction = new ArrayList(); + for (com.silanis.esl.sdk.FieldCondition sdkFieldCondition : sdkReferencedFieldConditions.getReferencedInAction()) { + FieldConditionConverter fieldConditionConverter = new FieldConditionConverter(sdkFieldCondition); + apiFieldConditionsInAction.add(fieldConditionConverter.toAPIFieldCondition()); + } + + com.silanis.esl.api.model.ReferencedFieldConditions apiReferencedFieldConditions = new com.silanis.esl.api.model.ReferencedFieldConditions(); + apiReferencedFieldConditions.setReferencedInCondition(apiFieldConditionsInCondition); + apiReferencedFieldConditions.setReferencedInAction(apiFieldConditionsInAction); + return apiReferencedFieldConditions; + } + + public static com.silanis.esl.sdk.ReferencedFieldConditions toSDK(com.silanis.esl.api.model.ReferencedFieldConditions apiReferencedFieldConditions) { + if (apiReferencedFieldConditions == null) { + return null; + } + + List apiFieldConditionsInCondition = new ArrayList(); + for (com.silanis.esl.api.model.FieldCondition sdkFieldCondition : apiReferencedFieldConditions.getReferencedInCondition()) { + FieldConditionConverter fieldConditionConverter = new FieldConditionConverter(sdkFieldCondition); + apiFieldConditionsInCondition.add(fieldConditionConverter.toSDKFieldCondition()); + } + + List apiFieldConditionsInAction = new ArrayList(); + for (com.silanis.esl.api.model.FieldCondition sdkFieldCondition : apiReferencedFieldConditions.getReferencedInAction()) { + FieldConditionConverter fieldConditionConverter = new FieldConditionConverter(sdkFieldCondition); + apiFieldConditionsInAction.add(fieldConditionConverter.toSDKFieldCondition()); + } + + com.silanis.esl.sdk.ReferencedFieldConditions sdkReferencedFieldConditions = new com.silanis.esl.sdk.ReferencedFieldConditions(); + sdkReferencedFieldConditions.setReferencedInCondition(apiFieldConditionsInCondition); + sdkReferencedFieldConditions.setReferencedInAction(apiFieldConditionsInAction); + return sdkReferencedFieldConditions; + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConverter.java b/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConverter.java new file mode 100644 index 000000000..4c07760c5 --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConverter.java @@ -0,0 +1,63 @@ +package com.silanis.esl.sdk.internal.converter; + +import java.util.ArrayList; +import java.util.List; + +public class ReferencedFieldConverter { + + public static com.silanis.esl.api.model.ReferencedField toAPI(com.silanis.esl.sdk.ReferencedField sdkReferencedField) { + if (sdkReferencedField == null) { + return null; + } + + com.silanis.esl.sdk.ReferencedFieldConditions sdkReferencedFieldConditions = sdkReferencedField.getConditions(); + List apiReferencedInCondition = new ArrayList(); + for (com.silanis.esl.sdk.FieldCondition sdkFieldCondition : sdkReferencedFieldConditions.getReferencedInCondition()) { + FieldConditionConverter converter = new FieldConditionConverter(sdkFieldCondition); + apiReferencedInCondition.add(converter.toAPIFieldCondition()); + } + + List apiReferencedInAction = new ArrayList(); + for (com.silanis.esl.sdk.FieldCondition sdkFieldCondition : sdkReferencedFieldConditions.getReferencedInAction()) { + FieldConditionConverter converter = new FieldConditionConverter(sdkFieldCondition); + apiReferencedInAction.add(converter.toAPIFieldCondition()); + } + + com.silanis.esl.api.model.ReferencedFieldConditions apiReferencedFieldConditions = new com.silanis.esl.api.model.ReferencedFieldConditions(); + apiReferencedFieldConditions.setReferencedInCondition(apiReferencedInCondition); + apiReferencedFieldConditions.setReferencedInAction(apiReferencedInAction); + + com.silanis.esl.api.model.ReferencedField apiReferencedField = new com.silanis.esl.api.model.ReferencedField(); + apiReferencedField.setFieldId(sdkReferencedField.getFieldId()); + apiReferencedField.setConditions(apiReferencedFieldConditions); + return apiReferencedField; + } + + public static com.silanis.esl.sdk.ReferencedField toSDK(com.silanis.esl.api.model.ReferencedField apiReferencedField) { + if (apiReferencedField == null) { + return null; + } + + com.silanis.esl.api.model.ReferencedFieldConditions apiReferencedFieldConditions = apiReferencedField.getConditions(); + List sdkReferencedInCondition = new ArrayList(); + for (com.silanis.esl.api.model.FieldCondition apiFieldCondition : apiReferencedFieldConditions.getReferencedInCondition()) { + FieldConditionConverter converter = new FieldConditionConverter(apiFieldCondition); + sdkReferencedInCondition.add(converter.toSDKFieldCondition()); + } + + List sdkReferencedInAction = new ArrayList(); + for (com.silanis.esl.api.model.FieldCondition apiFieldCondition : apiReferencedFieldConditions.getReferencedInAction()) { + FieldConditionConverter converter = new FieldConditionConverter(apiFieldCondition); + sdkReferencedInAction.add(converter.toSDKFieldCondition()); + } + + com.silanis.esl.sdk.ReferencedFieldConditions sdkReferencedFieldConditions = new com.silanis.esl.sdk.ReferencedFieldConditions(); + sdkReferencedFieldConditions.setReferencedInCondition(sdkReferencedInCondition); + sdkReferencedFieldConditions.setReferencedInAction(sdkReferencedInAction); + + com.silanis.esl.sdk.ReferencedField sdkReferencedField = new com.silanis.esl.sdk.ReferencedField(); + sdkReferencedField.setFieldId(apiReferencedField.getFieldId()); + sdkReferencedField.setConditions(sdkReferencedFieldConditions); + return sdkReferencedField; + } +} diff --git a/sdk/src/main/java/com/silanis/esl/sdk/service/PackageService.java b/sdk/src/main/java/com/silanis/esl/sdk/service/PackageService.java index 91b18aa3b..02bf6b13f 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/service/PackageService.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/service/PackageService.java @@ -25,6 +25,7 @@ import com.silanis.esl.sdk.PackageStatus; import com.silanis.esl.sdk.Page; import com.silanis.esl.sdk.PageRequest; +import com.silanis.esl.sdk.ReferencedConditions; import com.silanis.esl.sdk.RoleList; import com.silanis.esl.sdk.SignerId; import com.silanis.esl.sdk.SigningStatus; @@ -42,6 +43,7 @@ import com.silanis.esl.sdk.internal.converter.DocumentVisibilityConverter; import com.silanis.esl.sdk.internal.converter.NotaryJournalEntryConverter; import com.silanis.esl.sdk.internal.converter.PackageStatusConverter; +import com.silanis.esl.sdk.internal.converter.ReferencedConditionsConverter; import com.silanis.esl.sdk.internal.converter.SignerConverter; import com.silanis.esl.sdk.internal.converter.SupportConfigurationConverter; import com.silanis.esl.sdk.io.DownloadedFile; @@ -1524,4 +1526,48 @@ public com.silanis.esl.sdk.SupportConfiguration getConfig(PackageId packageId) { throw new EslException("Could not get support configuration." + " Exception: " + e.getMessage()); } } + + /** + * @param packageId Package ID + * @return Conditions referenced to the provided packageId. + */ + public ReferencedConditions getReferencedConditions(String packageId) { + return this.getReferencedConditions(packageId, null, null); + } + + /** + * @param packageId Package ID + * @param documentId document to be filtered by + * @return Conditions referenced to the provided packageId filtered by documentId. + */ + public ReferencedConditions getReferencedConditions(String packageId, String documentId) { + return this.getReferencedConditions(packageId, documentId, null); + } + + /** + * @param packageId Package ID + * @param documentId document to be filtered by + * @param fieldId field to be filtered by + * @return Conditions referenced to the provided packageId filtered by document and field ID. + */ + public ReferencedConditions getReferencedConditions(String packageId, String documentId, String fieldId) { + String path = template.urlFor(UrlTemplate.PACKAGE_REFERENCED_CONDITIONS_PATH) + .replace("{packageId}", packageId) + .addParam("documentId", documentId) + .addParam("fieldId", fieldId) + .build(); + + String stringResponse; + try { + stringResponse = client.get(path); + } catch (RequestException e) { + throw new EslServerException("Could not get referenced conditions.", e); + } catch (Exception e) { + throw new EslException("Could not get referenced conditions.", e); + } + + com.silanis.esl.api.model.ReferencedConditions apiReferencedConditions = Serialization + .fromJson(stringResponse, com.silanis.esl.api.model.ReferencedConditions.class); + return ReferencedConditionsConverter.toSDK(apiReferencedConditions); + } } \ No newline at end of file diff --git a/sdk/src/test/java/com/silanis/esl/sdk/builder/FieldConditionBuilderTest.java b/sdk/src/test/java/com/silanis/esl/sdk/builder/FieldConditionBuilderTest.java new file mode 100644 index 000000000..b3f36639f --- /dev/null +++ b/sdk/src/test/java/com/silanis/esl/sdk/builder/FieldConditionBuilderTest.java @@ -0,0 +1,26 @@ +package com.silanis.esl.sdk.builder; + +import static org.junit.Assert.assertEquals; + +import com.silanis.esl.sdk.FieldCondition; +import org.junit.Test; + +public class FieldConditionBuilderTest { + + private static final String ID = "Condition1"; + private static final String CONDITION = "document['doc1'].field['field1'].empty == true"; + private static final String ACTION = "document['doc1'].field['field2'].enabled = true"; + + @Test + public void buildApiTest() { + FieldCondition fieldCondition = FieldConditionBuilder.newFieldCondition() + .withId(ID) + .withCondition(CONDITION) + .withAction(ACTION) + .build(); + + assertEquals(ID, fieldCondition.getId()); + assertEquals(CONDITION, fieldCondition.getCondition()); + assertEquals(ACTION, fieldCondition.getAction()); + } +} diff --git a/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedConditionsConverterTest.java b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedConditionsConverterTest.java new file mode 100644 index 000000000..5909e281a --- /dev/null +++ b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedConditionsConverterTest.java @@ -0,0 +1,222 @@ +package com.silanis.esl.sdk.internal.converter; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertTrue; + +import com.silanis.esl.sdk.FieldCondition; +import com.silanis.esl.sdk.ReferencedConditions; +import com.silanis.esl.sdk.ReferencedDocument; +import com.silanis.esl.sdk.ReferencedField; +import com.silanis.esl.sdk.ReferencedFieldConditions; +import com.silanis.esl.sdk.builder.FieldConditionBuilder; +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; + +public class ReferencedConditionsConverterTest implements StaticConverterTest { + + static final String PACKAGE_ID = "package1"; + static final String DOCUMENT_ID = "document1"; + static final String FIELD_1_ID = "field1"; + static final String FIELD_2_ID = "field2"; + + static final String FIELD_3_ID = "field3"; + static final String CONDITION_1_ID = "Condition1"; + static final String CONDITION_2_ID = "Condition2"; + static final String CONDITION = "document['document1'].field['%s'].empty == true"; + + static final String ACTION = "document['document1'].field['%s'].enabled = true"; + + @Override + @Test + public void convertNullSDKToAPI() { + com.silanis.esl.api.model.ReferencedConditions api = ReferencedConditionsConverter.toAPI(null); + assertThat("Converter didn't return a null api object for a null sdk object", api, is(nullValue())); + } + + @Override + @Test + public void convertNullAPIToSDK() { + com.silanis.esl.sdk.ReferencedConditions sdk = ReferencedConditionsConverter.toSDK(null); + assertThat("Converter didn't return a null sdk object for a null api object", sdk, is(nullValue())); + } + + @Override + @Test + public void convertAPIToSDK() { + List apiDocuments = createApiReferencedDocumentsForTest(); + + com.silanis.esl.api.model.ReferencedConditions api = new com.silanis.esl.api.model.ReferencedConditions(); + api.setPackageId(PACKAGE_ID); + api.setDocuments(apiDocuments); + + ReferencedConditions sdk = ReferencedConditionsConverter.toSDK(api); + + assertThat("Package ID was not correctly converted", sdk.getPackageId(), is(PACKAGE_ID)); + assertTrue("Referenced Documents was not correctly converted", compareReferencedDocuments(apiDocuments, sdk.getDocuments())); + } + + @Override + @Test + public void convertSDKToAPI() { + List sdkDocuments = createSdkReferencedDocumentsForTest(); + + ReferencedConditions sdk = new ReferencedConditions(); + sdk.setPackageId(PACKAGE_ID); + sdk.setDocuments(sdkDocuments); + + com.silanis.esl.api.model.ReferencedConditions api = ReferencedConditionsConverter.toAPI(sdk); + + assertThat("Package ID was not correctly converted", api.getPackageId(), is(PACKAGE_ID)); + assertTrue("Referenced Documents was not correctly converted", compareReferencedDocuments(api.getDocuments(), sdkDocuments)); + } + + static List createApiReferencedDocumentsForTest() { + List documents = new ArrayList(); + + com.silanis.esl.api.model.ReferencedDocument referencedDocument = new com.silanis.esl.api.model.ReferencedDocument(); + referencedDocument.setDocumentId(DOCUMENT_ID); + referencedDocument.setFields(createApiReferencedFieldsForTest()); + + documents.add(referencedDocument); + return documents; + } + + static List createApiReferencedFieldsForTest() { + List fields = new ArrayList(); + + com.silanis.esl.api.model.ReferencedField referencedField = new com.silanis.esl.api.model.ReferencedField(); + referencedField.setFieldId(FIELD_1_ID); + referencedField.setConditions(createApiReferencedFieldConditionsForTest()); + + return fields; + } + + static com.silanis.esl.api.model.ReferencedFieldConditions createApiReferencedFieldConditionsForTest() { + com.silanis.esl.api.model.ReferencedFieldConditions referencedFieldConditions = new com.silanis.esl.api.model.ReferencedFieldConditions(); + referencedFieldConditions.setReferencedInCondition(createApiFieldConditionsForTest(CONDITION_1_ID, FIELD_1_ID, FIELD_2_ID)); + referencedFieldConditions.setReferencedInAction(createApiFieldConditionsForTest(CONDITION_2_ID, FIELD_3_ID, FIELD_1_ID)); + return referencedFieldConditions; + } + + static List createApiFieldConditionsForTest(String conditionId, String fieldInConditionId, String fieldInActionId) { + List fieldConditions = new ArrayList(); + + com.silanis.esl.api.model.FieldCondition fieldCondition = new com.silanis.esl.api.model.FieldCondition(); + fieldCondition.setId(conditionId); + fieldCondition.setCondition(String.format(CONDITION, fieldInConditionId)); + fieldCondition.setAction(String.format(ACTION, fieldInActionId)); + + fieldConditions.add(fieldCondition); + return fieldConditions; + } + + static List createSdkReferencedDocumentsForTest() { + List documents = new ArrayList(); + + ReferencedDocument referencedDocument = new ReferencedDocument(); + referencedDocument.setDocumentId(DOCUMENT_ID); + referencedDocument.setFields(createSdkReferencedFieldsForTest()); + + documents.add(referencedDocument); + return documents; + } + + static List createSdkReferencedFieldsForTest() { + List fields = new ArrayList(); + + ReferencedField referencedField = new ReferencedField(); + referencedField.setFieldId(FIELD_1_ID); + referencedField.setConditions(createSdkReferencedFieldConditionsForTest()); + + fields.add(referencedField); + return fields; + } + + static ReferencedFieldConditions createSdkReferencedFieldConditionsForTest() { + ReferencedFieldConditions referencedFieldConditions = new ReferencedFieldConditions(); + referencedFieldConditions.setReferencedInCondition(createSdkFieldConditionsForTest(CONDITION_1_ID, FIELD_1_ID, FIELD_2_ID)); + referencedFieldConditions.setReferencedInAction(createSdkFieldConditionsForTest(CONDITION_2_ID, FIELD_3_ID, FIELD_1_ID)); + return referencedFieldConditions; + } + + static List createSdkFieldConditionsForTest(String conditionId, String fieldInConditionId, String fieldInActionId) { + List fieldConditions = new ArrayList(); + + fieldConditions.add(FieldConditionBuilder.newFieldCondition() + .withId(conditionId) + .withCondition(String.format(CONDITION, fieldInConditionId)) + .withAction(String.format(ACTION, fieldInActionId)) + .build()); + + return fieldConditions; + } + + static boolean compareReferencedDocuments(com.silanis.esl.api.model.ReferencedDocument apiRefDoc, ReferencedDocument sdkRefDoc) { + return apiRefDoc.getDocumentId().equals(sdkRefDoc.getDocumentId()) && + compareReferencedFields(apiRefDoc.getFields(), sdkRefDoc.getFields()); + } + + static boolean compareReferencedDocuments(List apiRefDocs, List sdkRefDocs) { + if (apiRefDocs.size() != sdkRefDocs.size()) { + return false; + } + + for (int i = 0; i < apiRefDocs.size(); i++) { + if (!compareReferencedDocuments(apiRefDocs.get(i), sdkRefDocs.get(i))) { + return false; + } + } + return true; + } + + static boolean compareReferencedFields(List apiRefFields, List sdkRefFields) { + if (apiRefFields.size() != sdkRefFields.size()) { + return false; + } + + for (int i = 0; i < apiRefFields.size(); i++) { + if (!compareReferencedFields(apiRefFields.get(i), sdkRefFields.get(i))) { + return false; + } + } + return true; + } + + static boolean compareReferencedFields(com.silanis.esl.api.model.ReferencedField apiRefField, ReferencedField sdkRefField) { + return apiRefField.getFieldId().equals(sdkRefField.getFieldId()) && + compareReferencedFieldConditions(apiRefField.getConditions(), sdkRefField.getConditions()); + } + + static boolean compareReferencedFieldConditions(com.silanis.esl.api.model.ReferencedFieldConditions apiReferencedFieldConditions, + ReferencedFieldConditions sdkReferencedFieldConditions) { + List apiReferencedInCondition = apiReferencedFieldConditions.getReferencedInCondition(); + List apiReferencedInAction = apiReferencedFieldConditions.getReferencedInAction(); + List sdkReferencedInCondition = sdkReferencedFieldConditions.getReferencedInCondition(); + List sdkReferencedInAction = sdkReferencedFieldConditions.getReferencedInAction(); + + return compareFieldConditions(apiReferencedInCondition, sdkReferencedInCondition) && + compareFieldConditions(apiReferencedInAction, sdkReferencedInAction); + } + + static boolean compareFieldConditions(com.silanis.esl.api.model.FieldCondition apiFieldCondition, FieldCondition sdkFieldCondition) { + return apiFieldCondition.getId().equals(sdkFieldCondition.getId()) && + apiFieldCondition.getCondition().equals(sdkFieldCondition.getCondition()) && + apiFieldCondition.getAction().equals(sdkFieldCondition.getAction()); + } + + static boolean compareFieldConditions(List apiFieldConditions, List sdkFieldConditions) { + if (apiFieldConditions.size() != sdkFieldConditions.size()) { + return false; + } + + for (int i = 0; i < apiFieldConditions.size(); i++) { + if (!compareFieldConditions(apiFieldConditions.get(i), sdkFieldConditions.get(i))) { + return false; + } + } + return true; + } +} diff --git a/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedDocumentConverterTest.java b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedDocumentConverterTest.java new file mode 100644 index 000000000..51071d8c5 --- /dev/null +++ b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedDocumentConverterTest.java @@ -0,0 +1,58 @@ +package com.silanis.esl.sdk.internal.converter; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertTrue; + +import com.silanis.esl.sdk.ReferencedDocument; +import com.silanis.esl.sdk.ReferencedField; +import java.util.List; +import org.junit.Test; + +public class ReferencedDocumentConverterTest extends ReferencedConditionsConverterTest { + + @Override + @Test + public void convertNullSDKToAPI() { + com.silanis.esl.api.model.ReferencedDocument api = ReferencedDocumentConverter.toAPI(null); + assertThat("Converter didn't return a null api object for a null sdk object", api, is(nullValue())); + } + + @Override + @Test + public void convertNullAPIToSDK() { + ReferencedDocument sdk = ReferencedDocumentConverter.toSDK(null); + assertThat("Converter didn't return a null sdk object for a null api object", sdk, is(nullValue())); + } + + @Override + @Test + public void convertAPIToSDK() { + List apiFields = createApiReferencedFieldsForTest(); + + com.silanis.esl.api.model.ReferencedDocument api = new com.silanis.esl.api.model.ReferencedDocument(); + api.setDocumentId(DOCUMENT_ID); + api.setFields(apiFields); + + ReferencedDocument sdk = ReferencedDocumentConverter.toSDK(api); + + assertThat("Document ID was not correctly converted", sdk.getDocumentId(), is(DOCUMENT_ID)); + assertTrue("Referenced Fields was not correctly converted", compareReferencedFields(apiFields, sdk.getFields())); + } + + @Override + @Test + public void convertSDKToAPI() { + List sdkFields = createSdkReferencedFieldsForTest(); + + ReferencedDocument sdk = new ReferencedDocument(); + sdk.setDocumentId(DOCUMENT_ID); + sdk.setFields(sdkFields); + + com.silanis.esl.api.model.ReferencedDocument api = ReferencedDocumentConverter.toAPI(sdk); + + assertThat("Document ID was not correctly converted", api.getDocumentId(), is(DOCUMENT_ID)); + assertTrue("Referenced Fields was not correctly converted", compareReferencedFields(api.getFields(), sdkFields)); + } +} diff --git a/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConditionsConverterTest.java b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConditionsConverterTest.java new file mode 100644 index 000000000..284ffe2f3 --- /dev/null +++ b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConditionsConverterTest.java @@ -0,0 +1,65 @@ +package com.silanis.esl.sdk.internal.converter; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertTrue; + +import com.silanis.esl.sdk.FieldCondition; +import com.silanis.esl.sdk.ReferencedFieldConditions; +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; + +public class ReferencedFieldConditionsConverterTest extends ReferencedConditionsConverterTest { + + @Override + @Test + public void convertNullSDKToAPI() { + com.silanis.esl.api.model.ReferencedFieldConditions api = ReferencedFieldConditionsConverter.toAPI(null); + assertThat("Converter didn't return a null api object for a null sdk object", api, is(nullValue())); + } + + @Override + @Test + public void convertNullAPIToSDK() { + ReferencedFieldConditions sdk = ReferencedFieldConditionsConverter.toSDK(null); + assertThat("Converter didn't return a null sdk object for a null api object", sdk, is(nullValue())); + } + + @Override + @Test + public void convertAPIToSDK() { + List apiFieldConditionsReferencedInCondition = createApiFieldConditionsForTest(CONDITION_1_ID, FIELD_1_ID, FIELD_2_ID); + List apiFieldConditionsReferencedInAction = new ArrayList(); + + com.silanis.esl.api.model.ReferencedFieldConditions api = new com.silanis.esl.api.model.ReferencedFieldConditions(); + api.setReferencedInCondition(apiFieldConditionsReferencedInCondition); + api.setReferencedInAction(apiFieldConditionsReferencedInAction); + + ReferencedFieldConditions sdk = ReferencedFieldConditionsConverter.toSDK(api); + + assertTrue("Field Conditions referenced in Condition was not correctly converted", + compareFieldConditions(apiFieldConditionsReferencedInCondition, sdk.getReferencedInCondition())); + assertTrue("Field Conditions referenced in Condition was not correctly converted", + compareFieldConditions(apiFieldConditionsReferencedInAction, sdk.getReferencedInAction())); + } + + @Override + @Test + public void convertSDKToAPI() { + List sdkFieldConditionsReferencedInCondition = createSdkFieldConditionsForTest(CONDITION_1_ID, FIELD_1_ID, FIELD_2_ID); + List sdkFieldConditionsReferencedInAction = new ArrayList(); + + ReferencedFieldConditions sdk = new ReferencedFieldConditions(); + sdk.setReferencedInCondition(sdkFieldConditionsReferencedInCondition); + sdk.setReferencedInAction(sdkFieldConditionsReferencedInAction); + + com.silanis.esl.api.model.ReferencedFieldConditions api = ReferencedFieldConditionsConverter.toAPI(sdk); + + assertTrue("Field Conditions referenced in Condition was not correctly converted", + compareFieldConditions(api.getReferencedInCondition(), sdkFieldConditionsReferencedInCondition)); + assertTrue("Field Conditions referenced in Condition was not correctly converted", + compareFieldConditions(api.getReferencedInAction(), sdkFieldConditionsReferencedInAction)); + } +} diff --git a/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConverterTest.java b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConverterTest.java new file mode 100644 index 000000000..e05c8c650 --- /dev/null +++ b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/ReferencedFieldConverterTest.java @@ -0,0 +1,57 @@ +package com.silanis.esl.sdk.internal.converter; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertTrue; + +import com.silanis.esl.sdk.ReferencedField; +import com.silanis.esl.sdk.ReferencedFieldConditions; +import org.junit.Test; + +public class ReferencedFieldConverterTest extends ReferencedConditionsConverterTest { + + @Override + @Test + public void convertNullSDKToAPI() { + com.silanis.esl.api.model.ReferencedField api = ReferencedFieldConverter.toAPI(null); + assertThat("Converter didn't return a null api object for a null sdk object", api, is(nullValue())); + } + + @Override + @Test + public void convertNullAPIToSDK() { + ReferencedField sdk = ReferencedFieldConverter.toSDK(null); + assertThat("Converter didn't return a null sdk object for a null api object", sdk, is(nullValue())); + } + + @Override + @Test + public void convertAPIToSDK() { + com.silanis.esl.api.model.ReferencedFieldConditions apiConditions = createApiReferencedFieldConditionsForTest(); + + com.silanis.esl.api.model.ReferencedField api = new com.silanis.esl.api.model.ReferencedField(); + api.setFieldId(FIELD_1_ID); + api.setConditions(apiConditions); + + ReferencedField sdk = ReferencedFieldConverter.toSDK(api); + + assertThat("Field ID was not correctly converted", sdk.getFieldId(), is(FIELD_1_ID)); + assertTrue("Referenced Field Conditions was not correctly converted", compareReferencedFieldConditions(apiConditions, sdk.getConditions())); + } + + @Override + @Test + public void convertSDKToAPI() { + ReferencedFieldConditions sdkConditions = createSdkReferencedFieldConditionsForTest(); + + ReferencedField sdk = new ReferencedField(); + sdk.setFieldId(FIELD_1_ID); + sdk.setConditions(sdkConditions); + + com.silanis.esl.api.model.ReferencedField api = ReferencedFieldConverter.toAPI(sdk); + + assertThat("Field ID was not correctly converted", api.getFieldId(), is(FIELD_1_ID)); + assertTrue("Referenced Field Conditions was not correctly converted", compareReferencedFieldConditions(api.getConditions(), sdkConditions)); + } +} diff --git a/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/StaticConverterTest.java b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/StaticConverterTest.java new file mode 100644 index 000000000..f3e62bf24 --- /dev/null +++ b/sdk/src/test/java/com/silanis/esl/sdk/internal/converter/StaticConverterTest.java @@ -0,0 +1,17 @@ +package com.silanis.esl.sdk.internal.converter; + +/** + * A Static Converter test interface. + * + * @author x_MacieMi1 (Michał Maciejewski) + */ +public interface StaticConverterTest { + + public void convertNullSDKToAPI(); + + public void convertNullAPIToSDK(); + + public void convertAPIToSDK(); + + public void convertSDKToAPI(); +} diff --git a/tester/src/test/java/com/silanis/esl/sdk/examples/PackageReferencedConditionsExampleTest.java b/tester/src/test/java/com/silanis/esl/sdk/examples/PackageReferencedConditionsExampleTest.java new file mode 100644 index 000000000..49b67a2e6 --- /dev/null +++ b/tester/src/test/java/com/silanis/esl/sdk/examples/PackageReferencedConditionsExampleTest.java @@ -0,0 +1,35 @@ +package com.silanis.esl.sdk.examples; + +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; + +import com.silanis.esl.sdk.ReferencedDocument; +import com.silanis.esl.sdk.ReferencedField; +import com.silanis.esl.sdk.ReferencedFieldConditions; +import java.util.List; +import org.junit.Test; + +public class PackageReferencedConditionsExampleTest { + + @Test + public void verifyResult() { + PackageReferencedConditionsExample example = new PackageReferencedConditionsExample(); + example.run(); + + assertThat("ReferencedConditions should not be null", example.packageLevelRefConditions, notNullValue()); + assertThat("Package level request should return conditions from both documents", example.packageLevelRefConditions.getDocuments(), hasSize(2)); + + List documentLevelRefConditionsDocuments = example.documentLevelRefConditions.getDocuments(); + assertThat("Document level request should return conditions from this particular document only", documentLevelRefConditionsDocuments, hasSize(1)); + assertThat("Document level request should return conditions from all the fields from this particular document", + documentLevelRefConditionsDocuments.get(0).getFields(), hasSize(3)); + + List fieldLevelRefConditionsDoc1Fields = example.fieldLevelRefConditions.getDocuments().get(0).getFields(); + assertThat("Field level request should return conditions from this particular field only", fieldLevelRefConditionsDoc1Fields, hasSize(1)); + + ReferencedFieldConditions field1Conditions = fieldLevelRefConditionsDoc1Fields.get(0).getConditions(); + assertThat("Field1 should be referenced twice in condition logic in this example", field1Conditions.getReferencedInCondition(), hasSize(2)); + assertThat("Field1 should not be referenced in action logic in this example", field1Conditions.getReferencedInAction(), hasSize(0)); + } +} \ No newline at end of file