Skip to content

Commit

Permalink
PB-27291 Ability to return transaction GUIDs only
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz authored and john committed May 28, 2019
1 parent 98a4b4a commit 9033055
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Map<String, String>> 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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
28 changes: 28 additions & 0 deletions sdk/src/main/java/com/silanis/esl/sdk/service/PackageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,34 @@ public com.silanis.esl.sdk.Page<DocumentPackage> 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<String, String> that populate the specified page which contains fields and their values
*/
public com.silanis.esl.sdk.Page<Map<String, String>> getPackagesFields(PackageStatus status, PageRequest request, Set<String> 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<Map<String, String>> results = JacksonUtil.deserialize(response, new TypeReference<Result<Map<String, String>>>() {
});
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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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()));
}

}

0 comments on commit 9033055

Please sign in to comment.