wendyguo

create a package by using layout or template via java SDK

0 votes

Hi,

Is it possible to create a package using layout or template vis Java SDK? If yes, could you please share some code sample?

Thanks

Wendy


Reply to: create a package by using layout or template via java SDK

0 votes

Hi Wendy,

 

You can build a DocumentPackage locally with replaced placeholder signer, and create package out of a template with one call(guide here):


DocumentPackage newPackage = PackageBuilder.newPackageNamed(PACKAGE_NAME)
        .withSigner(SignerBuilder.newSignerWithEmail(email2)
                  .withFirstName(PACKAGE_SIGNER_FIRST)
                  .withLastName(PACKAGE_SIGNER_LAST)

                  .withCustomId("your_placeholder_name"))
        .build();
PackageId packageId = eslClient.getTemplateService().createPackageFromTemplate(templateId, newPackage);

 

On the other side, to apply a layout, you need to first create a package, retrieve the package ID, then use below code:
eslClient.getLayoutService().applyLayout(packageId, "documentId", "layoutId");
eslClient.getLayoutService().applyLayout(packageId, "documentId", "layoutName");

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to:

0 votes

Hi Duo,

I first create a layout from sendUI named ad wendy-layout, then I tried to apply this layout with eslClient.getLayoutService().applyLayoutByName(esignLivePackageId, documentPackage.getDocuments().get(0).getId().getId(), "wendy-layout"); I can succssfully apply this layout, but I got the below error when I tried to call getEslClient().sendPackage(new PackageId(packageId.getId()));

Could not send the package. Exception: HTTP POST on URI https://xxx/api/packages/Vymzlds8h_OmNvgZZFxseeoDM3k= resulted in response with status code: [400, Bad Request]. Optional details: {"messageKey":"error.validation.packageActivation.unassignedRole","code":400,"message":"There is a role with no signer.","name":"Validation Error"}

If I don't apply layout, no any issue. What could the the cause?

Also how to find how many layout has been created via JAVA SDK? is it possible to create a layout via java SDK?

 

Thanks

Wendy


Reply to: create a package by using layout or template via java SDK

0 votes

Hi Wendy,

 

Please be aware that when applying a layout, OneSpan Sign system will match the signers in that layout against the signers in your current package, by the Role Name. Placeholders defined in layout whom doesn't have a match will still be added to your current package as a placeholder, as the error message said "There is a role with no signer - who remains the placeholder signer".

The easiest way to learn your layout is: in UI, create a testing package without adding extra signer, upload a dummy document and apply the layout to this document, observe the signers/placeholders automatically be added by the layout and their role Names.

If you have a use case where this additional placeholder is optional, use this code to remove all placeholder signers in a package after applying the layout:

        PackageId packageId = new PackageId("");
        DocumentPackage package1 = eslClient.getPackage(packageId);
        List<Signer> placeholders = package1.getPlaceholders();
        for (Signer placeholder : placeholders) {
            eslClient.getPackageService().removeSigner(packageId, placeholder.getId());
        }

 

To list all layouts, use this code:
int i = 1;
 
// The first step is to retrieve the layouts from the first page. In my example, I chose to retrieve 5 layouts at a time but you can set this to any number.
List<DocumentPackage> layouts = eslClient.getLayoutService().getLayouts(Direction.DESCENDING, new PageRequest(i, 5));
          
while (!layouts.isEmpty()) {
 
// Next, you will create your iterator object. It will enable you to iterate through your list of layouts.           
Iterator<DocumentPackage> index = layouts.iterator();
      
while (index.hasNext()) {          
   //This is where you retrieve your layout name and id.
   DocumentPackage myLayout = index.next();
   System.out.println(myLayout.getName() + " " + myLayout.getId());
   i++; 
}
       
// Finally, you will retrieve your next 5 layouts from the second page and start over up until you’ve retrieved all your layouts.    
layouts = eslClient.getLayoutService().getLayouts(Direction.DESCENDING, new PageRequest(i, 5));
}

 

To create layout out of a package, use this code:

String layoutId = eslClient.getLayoutService().createLayout(myPackage);

Make sure the DocumentPackage object "myPackage" only contains one document, otherwise create a copy of it and removed all other documents.

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to:

0 votes

Hi Duo,

 

Thanks for your information, I will try it.  for the below code

String layoutId = eslClient.getLayoutService().createLayout(myPackage);

You mean in order to create a layout, I have to first create a myPackage with only one document is included and signers as a placeholder?

 

Thanks

Wendy

 


Reply to: create a package by using layout or template via java SDK

0 votes

Hi Wendy,

 

Because the layout has to be created out of an existing package, so you have to retrieve the DocumentPackage object from server, instead of build locally:
        DocumentPackage myPackage = eslClient.getPackage(new PackageId("juHWmynuRnZINjKATR_rVgpfNoA="));
Layout is a "LAYOUT" type of package, with only one document, so you need to remove all unnecessary documents from myPackage:

        String documentId = "e5bfa6033d1b7bb47e01912caec78919d2f646a41063138c";      

        Iterator<Document> iterator = myPackage.getDocuments().iterator();
        if(iterator.hasNext()) {
            Document document = iterator.next();
            if(!documentId.equals(document.getId().getId())) {
                iterator.remove();
            }
        }
        DocumentPackage createAndGetLayout = client.getLayoutService().createAndGetLayout(package1);
        System.out.println(createAndGetLayout.getId());
        

All signers will keep their original signer type (won't be placeholders automatically), so you may need to update all signers' type (except sender) as well:
        List<Signer> signers = createAndGetLayout.getSigners();
        for (Signer signer : signers) {
            if(!"ACCOUNT_SENDER".equals(signer.getSignerType())) {
                client.getTemplateService().updatePlaceholder(createAndGetLayout.getId(), new Placeholder(signer.getId(),signer.getId(),signer.getSigningOrder()));
            }
        }

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off