com.silanis.esl.sdk.service.PackageService Maven / Gradle / Ivy
package com.silanis.esl.sdk.service;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.silanis.esl.api.model.Approval;
import com.silanis.esl.api.model.Document;
import com.silanis.esl.api.model.Field;
import com.silanis.esl.api.model.Package;
import com.silanis.esl.api.model.Result;
import com.silanis.esl.api.model.Role;
import com.silanis.esl.api.model.Signer;
import com.silanis.esl.api.model.SigningUrl;
import com.silanis.esl.api.util.JacksonUtil;
import com.silanis.esl.sdk.DocumentId;
import com.silanis.esl.sdk.DocumentPackage;
import com.silanis.esl.sdk.EslException;
import com.silanis.esl.sdk.FastTrackRole;
import com.silanis.esl.sdk.FastTrackSigner;
import com.silanis.esl.sdk.GroupId;
import com.silanis.esl.sdk.PackageId;
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;
import com.silanis.esl.sdk.Visibility;
import com.silanis.esl.sdk.builder.FastTrackRoleBuilder;
import com.silanis.esl.sdk.internal.DateHelper;
import com.silanis.esl.sdk.internal.EslServerException;
import com.silanis.esl.sdk.internal.RedirectResolver;
import com.silanis.esl.sdk.internal.RequestException;
import com.silanis.esl.sdk.internal.RestClient;
import com.silanis.esl.sdk.internal.Serialization;
import com.silanis.esl.sdk.internal.UrlTemplate;
import com.silanis.esl.sdk.internal.converter.DocumentConverter;
import com.silanis.esl.sdk.internal.converter.DocumentPackageConverter;
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;
import org.apache.commons.lang3.StringUtils;
import java.util.*;
/**
* The PackageService class provides methods to help create packages and download documents after the
* package is complete.
*/
public class PackageService extends EslComponent {
private ReportService reportService;
public PackageService(RestClient client, String baseUrl) {
super(client, baseUrl);
reportService = new ReportService(client, baseUrl);
}
/**
* Creates a package with roles.
*
* @param aPackage
* @return PackageId
* @throws com.silanis.esl.sdk.EslException
*/
public PackageId createPackage(Package aPackage) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.PACKAGE_PATH)
.build();
String packageJson = Serialization.toJson(aPackage);
try {
String response = getClient().post(path, packageJson);
return Serialization.fromJson(response, PackageId.class);
} catch (RequestException e) {
throw new EslServerException("Could not create a new package", e);
} catch (Exception e) {
throw new EslException("Could not create a new package", e);
}
}
/**
* Creates a package and uploads the documents in one step
*
* @param aPackage
* @param documents
* @return
* @throws EslException
*/
public PackageId createPackageOneStep(Package aPackage, Collection documents) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.PACKAGE_PATH)
.build();
String packageJson = Serialization.toJson(aPackage);
try {
String response = getClient().postMultipartPackage(path, documents, packageJson);
return Serialization.fromJson(response, PackageId.class);
} catch (RequestException e) {
throw new EslServerException("Could not create a new package in one-step", e);
} catch (Exception e) {
throw new EslException("Could not create a new package in one-step", e);
}
}
/**
* Create a new package based on an existing template.
*
* @param packageId
* @param aPackage
* @return PackageId
*/
public PackageId createPackageFromTemplate(PackageId packageId, Package aPackage) {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.TEMPLATE_PATH)
.replace("{packageId}", packageId.getId())
.build();
List roles = aPackage.getRoles();
aPackage.setRoles(Collections.emptyList());
String packageJson = Serialization.toJson(aPackage);
PackageId newPackageId = null;
try {
String response = getClient().post(path, packageJson);
newPackageId = Serialization.fromJson(response, PackageId.class);
} catch (RequestException e) {
throw new EslServerException("Could not create a new package", e);
} catch (Exception e) {
throw new EslException("Could not create a new package", e);
}
Package createdPackage = getApiPackage(newPackageId.getId());
for (Role role : roles) {
String roleUid = findRoleUidByName(createdPackage.getRoles(), role.getName());
if (roleUid == null) {
continue;
}
role.setId(roleUid);
updateRole(newPackageId, role);
}
return newPackageId;
}
private String findRoleUidByName(List roles, String roleName) {
if (roleName == null || roleName.trim().isEmpty()) {
return null;
}
for (Role role : roles) {
if (roleName.equalsIgnoreCase(role.getName())) {
return role.getId();
}
}
return null;
}
/**
* Updates the package's fields and roles.
*
* @param packageId
* @param sdkPackage
* @throws EslException
*/
public void updatePackage( PackageId packageId, DocumentPackage sdkPackage ) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor( UrlTemplate.PACKAGE_ID_PATH )
.replace("{packageId}", packageId.getId())
.build();
Package aPackage = new DocumentPackageConverter(sdkPackage).toAPIPackage();
String packageJson = Serialization.toJson( aPackage );
try {
getClient().put(path, packageJson);
} catch (RequestException e) {
throw new EslServerException("Could not update the package.", e);
} catch (Exception e) {
throw new EslException("Could not update the package.", e);
}
}
/**
* Change the package's status to DRAFT.
*
* @param packageId
* @throws EslException
*/
public void changePackageStatusToDraft(PackageId packageId) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor( UrlTemplate.PACKAGE_ID_PATH )
.replace("{packageId}", packageId.getId())
.build();
try {
getClient().put(path, "{\"status\":\"DRAFT\"}");
} catch (RequestException e) {
throw new EslServerException("Could not change the package status to DRAFT.", e);
} catch (Exception e) {
throw new EslException("Could not change the package status to DRAFT.", e);
}
}
/**
* Configure a document visibility.
*
* @param packageId
* @param visibility the document visibility
* @throws EslException
*/
public void configureDocumentVisibility(PackageId packageId, com.silanis.esl.sdk.DocumentVisibility visibility) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor( UrlTemplate.DOCUMENT_VISIBILITY_PATH )
.replace("{packageId}", packageId.getId())
.build();
com.silanis.esl.api.model.DocumentVisibility apiVisibility = new DocumentVisibilityConverter(visibility).toAPIDocumentVisibility();
String json = Serialization.toJson(apiVisibility);
try {
getClient().post(path, json);
} catch (RequestException e) {
throw new EslServerException("Could not configure document visibility.", e);
} catch (Exception e) {
throw new EslException("Could not configure document visibility.", e);
}
}
/**
* Get a document visibility.
*
* @param packageId
* @throws EslException
*/
public com.silanis.esl.sdk.DocumentVisibility getDocumentVisibility(PackageId packageId) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor( UrlTemplate.DOCUMENT_VISIBILITY_PATH )
.replace("{packageId}", packageId.getId())
.build();
try {
String response = getClient().get(path);
com.silanis.esl.api.model.DocumentVisibility apiVisibility = Serialization.fromJson(response, com.silanis.esl.api.model.DocumentVisibility.class);
return new DocumentVisibilityConverter(apiVisibility).toSDKDocumentVisibility();
} catch (RequestException e) {
throw new EslServerException("Could not get document visibility.", e);
} catch (Exception e) {
throw new EslException("Could not get document visibility.", e);
}
}
public DocumentPackage getPackage(PackageId packageId) {
Package aPackage = getApiPackage(packageId.getId());
DocumentPackage documentPackage = packageConverter(aPackage).toSDKPackage();
return documentPackage;
}
public List getDocuments(PackageId packageId, String signerId) {
DocumentPackage documentPackage = getPackage(packageId);
final com.silanis.esl.sdk.DocumentVisibility visibility = getDocumentVisibility(packageId);
return visibility.getDocuments(documentPackage, signerId);
}
public List getSigners(PackageId packageId, String documentId) {
DocumentPackage documentPackage = getPackage(packageId);
final com.silanis.esl.sdk.DocumentVisibility visibility = getDocumentVisibility(packageId);
return visibility.getSigners(documentPackage, documentId);
}
private DocumentPackageConverter packageConverter(Package aPackage){
return new DocumentPackageConverter(aPackage);
}
/**
* Gets the package.
*
* @param packageId
* @return Package
* @throws EslException
*/
public Package getApiPackage(String packageId) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.PACKAGE_ID_PATH)
.replace("{packageId}", packageId)
.build();
String stringResponse;
try {
stringResponse = getClient().get(path);
} catch (RequestException e) {
throw new EslServerException("Could not get package.", e);
} catch (Exception e) {
throw new EslException("Could not get package.", e);
}
return Serialization.fromJson(stringResponse, Package.class);
}
/**
* @deprecated Please use uploadDocument(PackageId packageId, String fileName, byte[] fileBytes, com.silanis.esl.sdk.Document document) instead of this method.
*/
@Deprecated
public com.silanis.esl.sdk.Document uploadDocument(PackageId packageId, String fileName, byte[] fileBytes, com.silanis.esl.sdk.Document document, DocumentPackage documentPackage) throws EslException {
return uploadDocument(packageId, fileName, fileBytes, document);
}
/**
* Uploads the Document and file in byte[] to the package.
*
* @param packageId
* @param fileName Name of the file
* @param fileBytes The file to upload in bytes
* @param document The document with approvals and fields
* @throws EslException
*/
public com.silanis.esl.sdk.Document uploadDocument(PackageId packageId, String fileName, byte[] fileBytes, com.silanis.esl.sdk.Document document) throws EslException {
Package apiPackage = getApiPackage(packageId.getId());
Document apiDocument = new DocumentConverter(document).toAPIDocument(apiPackage);
return uploadApiDocument(packageId.getId(), fileName, fileBytes, apiDocument);
}
public com.silanis.esl.sdk.Document uploadApiDocument(String packageId, String fileName, byte[] fileBytes, Document document) {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.DOCUMENT_PATH)
.replace("{packageId}", packageId)
.build();
String documentJson = Serialization.toJson(document);
try {
String response = getClient().postMultipartFile(path, fileName, fileBytes, documentJson);
com.silanis.esl.api.model.Document uploadedDocument = Serialization.fromJson(response, com.silanis.esl.api.model.Document.class);
return new DocumentConverter(uploadedDocument, getApiPackage(packageId)).toSDKDocument();
} catch (RequestException e) {
throw new EslServerException("Could not upload document to package.", e);
} catch (Exception e) {
throw new EslException("Could not upload document to package.", e);
}
}
public List uploadDocuments(final String packageId, List documents) {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.DOCUMENT_PATH)
.replace("{packageId}", packageId)
.build();
final Package apiPackage = getApiPackage(packageId);
List apiDocuments = Lists.newArrayList(Iterables.transform(documents, new Function() {
@Override
public Document apply(final com.silanis.esl.sdk.Document input) {
return new DocumentConverter(input).toAPIDocument(apiPackage);
}
}));
String documentsJson = Serialization.toJson(apiDocuments);
try {
String response = getClient().postMultipartPackage(path, documents, documentsJson);
List uploadedDocuments = Serialization.fromJsonToList(response, Document.class);
return Lists.newArrayList(Iterables.transform(uploadedDocuments, new Function() {
@Override
public com.silanis.esl.sdk.Document apply(final Document input) {
return new DocumentConverter(input, getApiPackage(packageId)).toSDKDocument();
}
}));
} catch (RequestException e) {
throw new EslServerException("Could not upload documents to package.", e);
} catch (Exception e) {
throw new EslException("Could not upload documents to package.", e);
}
}
/**
* Upload documents with base64 content to the package.
*
* @param packageId
*/
public List addDocumentWithBase64Content(String packageId, List providerDocuments){
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.DOCUMENT_PATH)
.replace("{packageId}", packageId)
.build();
final Package apiPackage = getApiPackage(packageId);
List apiDocuments = new ArrayList();
for( com.silanis.esl.sdk.Document document : providerDocuments){
apiDocuments.add(new DocumentConverter(document).toAPIDocument(apiPackage));
}
try {
String json = Serialization.toJson(apiDocuments);
String response = getClient().post(path, json);
List uploadedDocuments = Serialization.fromJsonToList(response, Document.class);
return Lists.newArrayList(Iterables.transform(uploadedDocuments, new Function() {
@Override
public com.silanis.esl.sdk.Document apply(final Document input) {
return new DocumentConverter(input, getApiPackage(packageId)).toSDKDocument();
}
}));
} catch (RequestException e) {
throw new EslServerException("Could not upload the documents.", e);
} catch (Exception e) {
throw new EslException("Could not upload the documents." + " Exception: " + e.getMessage());
}
}
/**
* Deletes the document from the package.
*
* @param packageId
* @param documentId
* @throws EslException
*/
public void deleteDocument(PackageId packageId, String documentId) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.DOCUMENT_ID_PATH)
.replace("{packageId}", packageId.getId())
.replace("{documentId}", documentId)
.build();
try {
getClient().delete(path);
} catch (RequestException e) {
throw new EslServerException("Could not delete document from package.", e);
} catch (Exception e) {
throw new EslException("Could not delete document from package.", e);
}
}
/**
* Deletes the documents from the package.
*
* @param packageId
* @param documentIds
* @throws EslException
*/
public void deleteDocuments(PackageId packageId, DocumentId... documentIds) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.DOCUMENT_PATH)
.replace("{packageId}", packageId.getId())
.build();
try {
String json = Serialization.toJson(Lists.transform(Arrays.asList(documentIds),
new Function() {
@Override
public String apply(DocumentId documentId) {
return documentId.getId();
}
}));
getClient().delete(path, json);
} catch (RequestException e) {
throw new EslServerException("Could not delete documents from package.", e);
} catch (Exception e) {
throw new EslException("Could not delete documents from package.", e);
}
}
/**
* Get the document's metadata from the package.
*
* @param documentPackage The DocumentPackage we want to get document from.
* @param documentId Id of document to get.
* @return the document's metadata
*/
public com.silanis.esl.sdk.Document getDocumentMetadata(DocumentPackage documentPackage, String documentId) {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.DOCUMENT_ID_PATH)
.replace("{packageId}", documentPackage.getId().getId())
.replace("{documentId}", documentId)
.build();
try {
String response = getClient().get(path);
Document apilDocument = Serialization.fromJson(response, Document.class);
// Wipe out the members not related to the metadata
apilDocument.setApprovals(new ArrayList());
apilDocument.setFields(new ArrayList());
apilDocument.setPages(new ArrayList());
return new DocumentConverter(apilDocument, new DocumentPackageConverter(documentPackage).toAPIPackage()).toSDKDocument();
} catch (RequestException e) {
throw new EslServerException("Could not get the document's metadata.", e);
} catch (Exception e) {
throw new EslException("Could not get the document's metadata." + " Exception: " + e.getMessage());
}
}
/**
* Updates the document's metadata from the package.
*
* @param documentPackage
* @param document
*/
public void updateDocumentMetadata(DocumentPackage documentPackage, com.silanis.esl.sdk.Document document) {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.DOCUMENT_ID_PATH)
.replace("{packageId}", documentPackage.getId().getId())
.replace("{documentId}", document.getId().toString())
.build();
Document internalDoc = new DocumentConverter(document).toAPIDocumentMetadata();
try {
String json = Serialization.toJson(internalDoc);
getClient().put(path, json);
} catch (RequestException e) {
throw new EslServerException("Could not update the document's metadata.", e);
} catch (Exception e) {
throw new EslException("Could not update the document's metadata." + " Exception: " + e.getMessage());
}
}
/**
* Updates the documents signing order
*
* @param documentPackage
*/
public void orderDocuments(DocumentPackage documentPackage){
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.DOCUMENT_PATH)
.replace("{packageId}", documentPackage.getId().getId())
.build();
List documents = new ArrayList();
for( com.silanis.esl.sdk.Document document : documentPackage.getDocuments()){
documents.add(new DocumentConverter(document).toAPIDocumentMetadata());
}
try {
String json = Serialization.toJson(documents);
getClient().put(path, json);
} catch (RequestException e) {
throw new EslServerException("Could not order the documents.", e);
} catch (Exception e) {
throw new EslException("Could not order the documents." + " Exception: " + e.getMessage());
}
}
/**
* Upload documents with external content to the package.
*
* @param packageId
*/
public void addDocumentWithExternalContent(String packageId, List providerDocuments){
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.DOCUMENT_PATH)
.replace("{packageId}", packageId)
.build();
List apiDocuments = new ArrayList();
for( com.silanis.esl.sdk.Document document : providerDocuments){
apiDocuments.add(new DocumentConverter(document).toAPIDocumentMetadata());
}
try {
String json = Serialization.toJson(apiDocuments);
getClient().post(path, json);
} catch (RequestException e) {
throw new EslServerException("Could not upload the documents.", e);
} catch (Exception e) {
throw new EslException("Could not upload the documents." + " Exception: " + e.getMessage());
}
}
/**
* Gets the documents from the history list
*
* @return
*/
public List getDocuments(){
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.PROVIDER_DOCUMENTS).build();
try {
String stringResponse = getClient().get(path);
List apiResponse = JacksonUtil.deserialize(stringResponse, new TypeReference>() {
});
List documents = new ArrayList();
for (Document document : apiResponse) {
documents.add(new DocumentConverter(document, null).toSDKDocument());
}
return documents;
}
catch (RequestException e) {
throw new EslServerException("Failed to retrieve documents from history List.", e);
}
catch (Exception e) {
throw new EslException("Failed to retrieve documents from history list.", e);
}
}
/**
* Sends the package.
*
* @param packageId
* @throws EslException
*/
public void sendPackage(PackageId packageId) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.PACKAGE_ID_PATH)
.replace("{packageId}", packageId.getId())
.build();
String json = "{\"status\":\"SENT\"}";
try {
getClient().post(path, json);
} catch (RequestException e) {
throw new EslServerException("Could not send the package.", e);
} catch (Exception e) {
throw new EslException("Could not send the package.", e);
}
}
/**
* Gets the roles for a package.
*
* @param packageId
* @return A list of the roles in the package
* @throws EslException
*/
public List getRoles(PackageId packageId) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.ROLE_PATH)
.replace("{packageId}", packageId.getId())
.build();
String stringResponse;
try {
stringResponse = getClient().get(path);
} catch (RequestException e) {
throw new EslServerException("Could not retrieve list of roles for package with id " + packageId.getId(), e);
} catch (Exception e) {
throw new EslException("Could not retrieve list of roles for package with id " + packageId.getId(), e);
}
return Serialization.fromJson(stringResponse, RoleList.class).getResults();
}
/**
* Adds a role to the package.
*
* @param packageId
* @param role
* @return The role added
* @throws EslException
*/
public Role addRole(PackageId packageId, Role role) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.ROLE_PATH)
.replace("{packageId}", packageId.getId())
.build();
String roleJson = JacksonUtil.serializeDirty(role);
String stringResponse;
try {
stringResponse = getClient().post(path, roleJson);
} catch (RequestException e) {
throw new EslServerException("Could not add role.", e);
} catch (Exception e) {
throw new EslException("Could not add role.", e);
}
return Serialization.fromJson(stringResponse, Role.class);
}
/**
* Updates a role from the package.
*
* @param packageId
* @param role
* @return The updated role
* @throws EslException
*/
public Role updateRole(PackageId packageId, Role role) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.ROLE_ID_PATH)
.replace("{packageId}", packageId.getId())
.replace("{roleId}", role.getId())
.build();
String roleJson = JacksonUtil.serializeDirty(role);
String stringResponse;
try {
stringResponse = getClient().put(path, roleJson);
} catch (RequestException e) {
throw new EslServerException("Could not update role", e);
} catch (Exception e) {
throw new EslException("Could not update role", e);
}
return Serialization.fromJson(stringResponse, Role.class);
}
/**
* Deletes a role from the package.
*
* @param packageId
* @param role
* @throws EslException
*/
public void deleteRole(PackageId packageId, Role role) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.ROLE_ID_PATH)
.replace("{packageId}", packageId.getId())
.replace("{roleId}", role.getId())
.build();
try {
getClient().delete(path);
} catch (RequestException e) {
throw new EslServerException("Could not delete role", e);
} catch (Exception e) {
throw new EslException("Could not delete role", e);
}
}
/**
* Downloads a document from the package and returns a byte[].
*
* @param packageId Id of the DocumentPackage we want to download
* @param document Id of the Document we want to download
* @return The document in bytes
* @throws EslException
*/
public byte[] downloadDocument(PackageId packageId, Document document) throws EslException {
return downloadDocument(packageId, document.getId());
}
public byte[] downloadDocument(PackageId packageId, String documentId) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.PDF_PATH)
.replace("{packageId}", packageId.getId())
.replace("{documentId}", documentId)
.build();
try {
return getClient().getBytesAsOctetStream(path).getContents();
} catch (RequestException e) {
throw new EslServerException("Could not download the pdf document.", e);
} catch (Exception e) {
throw new EslException("Could not download the pdf document.", e);
}
}
/**
* Downloads the original document (without fields) from the package and returns a byte[].
*
* @param packageId Id of the DocumentPackage we want to download
* @param documentId Id of the Document we want to download
* @return The original document in bytes
* @throws EslException
*/
public byte[] downloadOriginalDocument(PackageId packageId, String documentId) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.ORIGINAL_PATH)
.replace("{packageId}", packageId.getId())
.replace("{documentId}", documentId)
.build();
try {
return getClient().getBytesAsOctetStream(path).getContents();
} catch (RequestException e) {
throw new EslServerException("Could not download the original document.", e);
} catch (Exception e) {
throw new EslException("Could not download the original document.", e);
}
}
/**
* Downloads the documents (in a zip archive) from the package and returns a byte[].
*
* @param packageId Id of the DocumentPackage we want to download
* @return The zipped documents in bytes
* @throws EslException
*/
public byte[] downloadZippedDocuments(PackageId packageId) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.ZIP_PATH)
.replace("{packageId}", packageId.getId())
.build();
try {
return getClient().getBytes(path).getContents();
} catch (RequestException e) {
throw new EslServerException("Could not download the documents to a zip file.", e);
} catch (Exception e) {
throw new EslException("Could not download the documents to a zip file.", e);
}
}
/**
* Downloads the evidence summary (in PDF) from the package and returns a byte[].
*
* @param packageId
* @return The evidence summary in bytes
* @throws EslException
*/
public byte[] downloadEvidenceSummary(PackageId packageId) throws EslException {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.EVIDENCE_SUMMARY_PATH)
.replace("{packageId}", packageId.getId())
.build();
try {
return getClient().getBytes(path).getContents();
} catch (RequestException e) {
throw new EslServerException("Could not download the evidence summary.", e);
} catch (Exception e) {
throw new EslException("Could not download the evidence summary.", e);
}
}
/**
* Retrieves the current signing status of the DocumentPackage, Document or Signer specified.
*
* @param packageId Id of the DocumentPackage who's status we are to retrieve
* @param signerId If not null, the id of the signer who's status we are to retrieve
* @param documentId If not null, the id of the document who's status we are to retrieve
* @return One of the following values:
* INACTIVE - process is not active
* COMPLETE - process has been completed
* ARCHIVED - process has been archived
* SIGNING-PENDING - process is active, but not all signatures have been added
* SIGNING-COMPLETE - process is active, all signaures have been added
*/
public SigningStatus getSigningStatus(PackageId packageId, SignerId signerId, DocumentId documentId) {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.SIGNING_STATUS_PATH)
.replace("{packageId}", packageId.getId())
.replace("{signerId}", signerId != null ? signerId.getId() : "")
.replace("{documentId}", documentId != null ? documentId.getId() : "")
.build();
try {
String stringResponse = getClient().get(path);
ObjectMapper objectMapper = new ObjectMapper();
JsonNode topNode = objectMapper.readTree(stringResponse);
String statusString = topNode.get("status").textValue();
return SigningStatus.statusForToken(statusString);
} catch (RequestException e) {
throw new EslServerException("Could not retrieve signing status.", e);
} catch (Exception e) {
throw new EslException("Could not retrieve signing status.", e);
}
}
/**
* Returns a Page of DocumentPackages, which represents a paginated query response. Important once you have many DocumentPackages.
*
* @param status Returned DocumentPackages must have their status set to this value to be included in the result set
* @param ownerUserId
* @param ownerEmail
* @param request Identifying which page of results to return
* @return List of DocumentPackages that populate the specified page
*/
public com.silanis.esl.sdk.Page getPackages(String status, PageRequest request) {
String path = new UrlTemplate(getBaseUrl()).urlFor(UrlTemplate.PACKAGE_LIST_PATH)
.replace("{status}", status)
.replace("{from}", Integer.toString(request.getFrom()))
.replace("{to}", Integer.toString(request.to()))
.build();
try {
String response = getClient().get(path);
Result results = JacksonUtil.deserialize(response, new TypeReference>() {
});
return convertToPage(results, 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 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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy