Skip to content

Commit

Permalink
Merge pull request #12 from simontrudeau/apply-layout-by-name
Browse files Browse the repository at this point in the history
PB-9090. Added LayoutService.applyLayoutByName method
  • Loading branch information
SeungChoi authored Mar 12, 2018
2 parents ce8b224 + 783322d commit 5493bdc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class DocumentLayoutExample extends SDKSample {
public static final String APPLY_LAYOUT_DOCUMENT_NAME = "Apply Layout Document";
public static final String APPLY_LAYOUT_DOCUMENT_ID = "docId";
public static final String APPLY_LAYOUT_DOCUMENT_DESCRIPTION = "Document with applied layout description.";
public static final String APPLY_LAYOUT_BY_NAME_DOCUMENT_NAME = "Apply Layout Document by Name";
public static final String APPLY_LAYOUT_BY_NAME_DOCUMENT_ID = "docId2";
public static final String APPLY_LAYOUT_BY_NAME_DOCUMENT_DESCRIPTION = "Document with applied layout by name description.";

public static void main(String... args) {
new DocumentLayoutExample().run();
Expand Down Expand Up @@ -89,12 +92,19 @@ public void execute() {
.withId(APPLY_LAYOUT_DOCUMENT_ID)
.withDescription(APPLY_LAYOUT_DOCUMENT_DESCRIPTION)
.fromStream(documentInputStream2, DocumentType.PDF))
.withDocument(newDocumentWithName(APPLY_LAYOUT_BY_NAME_DOCUMENT_NAME)
.withId(APPLY_LAYOUT_BY_NAME_DOCUMENT_ID)
.withDescription(APPLY_LAYOUT_BY_NAME_DOCUMENT_DESCRIPTION)
.fromStream(documentInputStream3, DocumentType.PDF))
.build();

packageId = eslClient.createPackage(packageFromLayout);

// Apply the layout to document in package
eslClient.getLayoutService().applyLayout(packageId, APPLY_LAYOUT_DOCUMENT_ID, layoutId);

// Apply the layout by name to document in package
eslClient.getLayoutService().applyLayout(packageId, APPLY_LAYOUT_BY_NAME_DOCUMENT_ID, LAYOUT_PACKAGE_NAME);

packageWithLayout = eslClient.getPackage(packageId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract public class SDKSample {
protected PackageId packageId;
protected String packageName;
protected DocumentPackage retrievedPackage;
protected InputStream documentInputStream1, documentInputStream2;
protected InputStream documentInputStream1, documentInputStream2, documentInputStream3;

protected Properties props = Props.get();

Expand Down Expand Up @@ -68,6 +68,7 @@ private void setProperties() {

documentInputStream1 = this.getClass().getClassLoader().getResourceAsStream( "document.pdf" );
documentInputStream2 = this.getClass().getClassLoader().getResourceAsStream( "document.pdf" );
documentInputStream3 = this.getClass().getClassLoader().getResourceAsStream( "document.pdf" );
}

protected EslClient getEslClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public class UrlTemplate {
public static final String LAYOUT_PATH = "/layouts";
public static final String LAYOUT_LIST_PATH = "/layouts?to={to}&from={from}&dir={dir}";
public static final String APPLY_LAYOUT_PATH = "/packages/{packageId}/documents/{documentId}/layout?layoutId={layoutId}";
public static final String APPLY_LAYOUT_PATH_BY_NAME = "/packages/{packageId}/documents/{documentId}/layout?layoutName={layoutName}";

// QR Code Service
public static final String QRCODE_PATH = "/packages/{packageId}/documents/{documentId}/fields";
Expand Down
24 changes: 24 additions & 0 deletions sdk/src/main/java/com/silanis/esl/sdk/service/LayoutService.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,29 @@ public void applyLayout(PackageId packageId, String documentId, String layoutId)
throw new EslException("Could not apply layout." + " Exception: " + e.getMessage());
}
}

/**
* Apply a document layout to a document in a DocumentPackage. Adds fields to signer's signature or if the signer
* does not exist, will create placeholders.
*
* @param packageId The package id of the DocumentPackage to apply layout.
* @param documentId The document id of the document to apply layout.
* @param layoutName The layout name of the layout to apply.
*/
public void applyLayoutByName(PackageId packageId, String documentId, String layoutName) {
String path = template.urlFor(UrlTemplate.APPLY_LAYOUT_PATH_BY_NAME)
.replace("{packageId}", packageId.getId())
.replace("{documentId}", documentId)
.replace("{layoutName}", layoutName)
.build();

try {
client.post(path, "");
} catch (RequestException e) {
throw new EslServerException("Could not apply layout.", e);
} catch (Exception e) {
throw new EslException("Could not apply layout." + " Exception: " + e.getMessage());
}
}

}

0 comments on commit 5493bdc

Please sign in to comment.