From 9033055e32e1234f69c663285746580fb90a0080 Mon Sep 17 00:00:00 2001 From: mateusz Date: Fri, 24 May 2019 15:27:12 +0200 Subject: [PATCH] PB-27291 Ability to return transaction GUIDs only --- .../examples/GetPackageFieldsListExample.java | 51 +++++++++++++++++++ .../silanis/esl/sdk/internal/UrlTemplate.java | 1 + .../esl/sdk/service/PackageService.java | 28 ++++++++++ .../GetPackageFieldsListExampleTest.java | 17 +++++++ 4 files changed, 97 insertions(+) create mode 100644 sdk/src/main/java/com/silanis/esl/sdk/examples/GetPackageFieldsListExample.java create mode 100644 tester/src/test/java/com/silanis/esl/sdk/examples/GetPackageFieldsListExampleTest.java diff --git a/sdk/src/main/java/com/silanis/esl/sdk/examples/GetPackageFieldsListExample.java b/sdk/src/main/java/com/silanis/esl/sdk/examples/GetPackageFieldsListExample.java new file mode 100644 index 000000000..0e78eaeaa --- /dev/null +++ b/sdk/src/main/java/com/silanis/esl/sdk/examples/GetPackageFieldsListExample.java @@ -0,0 +1,51 @@ +package com.silanis.esl.sdk.examples; + +import com.google.common.collect.Sets; +import com.silanis.esl.sdk.DocumentPackage; +import com.silanis.esl.sdk.DocumentType; +import com.silanis.esl.sdk.PackageStatus; +import com.silanis.esl.sdk.Page; +import com.silanis.esl.sdk.PageRequest; +import com.silanis.esl.sdk.builder.FieldBuilder; +import java.util.Map; + +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.DateMidnight.now; + +public class GetPackageFieldsListExample extends SDKSample { + + public Page> packages; + + public static void main( String... args ) { + new GetPackageFieldsListExample().run(); + } + + @Override + 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 ) + .withFirstName( "John" ) + .withLastName( "Smith" ) + .withTitle( "Managing Director" ) + .withCompany( "Acme Inc." ) ) + .withDocument( newDocumentWithName( "First Document" ) + .fromStream( documentInputStream1, DocumentType.PDF ) + .withSignature( signatureFor( email1 ) + .onPage( 0 ) + .atPosition( 100, 100 ) + .withField( FieldBuilder.textField() + .onPage( 0 ) + .atPosition( 400, 100 ) + .withSize( 200, 50 ) ) ) ) + .build(); + + packageId = eslClient.createPackage( superDuperPackage ); + packages = eslClient.getPackageService().getPackagesFields(PackageStatus.DRAFT, new PageRequest( 1 ), Sets.newHashSet("id")); + } +} 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 654e1fff7..bfd3bbf81 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 @@ -14,6 +14,7 @@ public class UrlTemplate { // Package Service public static final String PACKAGE_PATH = "/packages"; public static final String PACKAGE_LIST_PATH = "/packages?query={status}&from={from}&to={to}"; + 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 DOCUMENT_PATH = "/packages/{packageId}/documents"; 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 f5f737be5..633f9c6b9 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 @@ -829,6 +829,34 @@ public com.silanis.esl.sdk.Page getPackages(String status, Page } } + /** + * Returns a Page of Map, which represents a paginated query response which contains package fields and their values. + * + * @param status Packages must have their status set to this value to be included in the result set + * @param request Identifying which page of results to return + * @param fields Identifying which package fields to return + * @return List of Map that populate the specified page which contains fields and their values + */ + public com.silanis.esl.sdk.Page> getPackagesFields(PackageStatus status, PageRequest request, Set fields) { + String path = template.urlFor(UrlTemplate.PACKAGE_FIELDS_LIST_PATH) + .replace("{status}", new PackageStatusConverter(status).toAPIPackageStatus()) + .replace("{from}", Integer.toString(request.getFrom())) + .replace("{to}", Integer.toString(request.to())) + .replace("{fields}", StringUtils.join(fields, ",")) + .build(); + try { + String response = client.get(path); + Result> results = JacksonUtil.deserialize(response, new TypeReference>>() { + }); + return new com.silanis.esl.sdk.Page<>(results.getResults(), results.getCount(), request); + } catch (RequestException e) { + throw new EslServerException("Could not get package list.", e); + } catch (Exception e) { + e.printStackTrace(); + throw new EslException("Could not get package list. Exception: " + e.getMessage()); + } + } + /** * Returns a Page of DocumentPackages, that last updated in time range, which represents a paginated query response. Important once you have many DocumentPackages. * diff --git a/tester/src/test/java/com/silanis/esl/sdk/examples/GetPackageFieldsListExampleTest.java b/tester/src/test/java/com/silanis/esl/sdk/examples/GetPackageFieldsListExampleTest.java new file mode 100644 index 000000000..bc6a74c68 --- /dev/null +++ b/tester/src/test/java/com/silanis/esl/sdk/examples/GetPackageFieldsListExampleTest.java @@ -0,0 +1,17 @@ +package com.silanis.esl.sdk.examples; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +public class GetPackageFieldsListExampleTest { + @Test + public void verifyResult() { + GetPackageFieldsListExample example = new GetPackageFieldsListExample(); + example.run(); + + assertThat(example.packages.getResults().get(0).get("id"), is(example.packageId.getId())); + } + +} \ No newline at end of file