romainlefebvre | Posts: 5

How to search DocumentPackage by attribute?

0 votes
Hi, I want to create empty packages with DRAFT status and one custom attribute (i.e internalID).
DocumentPackage documentPackage = newPackageNamed("TEST_PACKAGE")
                       .withAttributes(newDocumentPackageAttributes()
     	               .withAttribute("internalID", "123456" )
     	               .build())
.build();

PackageId packageId = eslClient.createPackage(documentPackage);
Then, how can I do a search of the DRAFT packages with specific attribute 'internalID' ?
Page resultPage = eslClient.getPackageService().getPackages(new PackageStatusConverter(PackageStatus.DRAFT).toAPIPackageStatus(), new PageRequest(1));
Thanks

Approved Answer
harishaidary | Posts: 1812

Reply to: How to search DocumentPackage by attribute?

0 votes
Hey Romain, What you will probably end up doing is going through your packages in draft and retrieve the attributes. Here's an example code on how to do so:
int i = 1;

Page resultPage = client.getPackageService().getPackages(new PackageStatusConverter(PackageStatus.DRAFT).toAPIPackageStatus(), new PageRequest(i, 50));
		
while (resultPage.getNumberOfElements() != 0) {
          for (DocumentPackage pack : resultPage) {
	  System.out.println(pack.getName());
          DocumentPackageAttributes attributes = pack.getAttributes();
	  Map attr = attributes.getContents();

	  for (Map.Entry entry : attr.entrySet()) {
                    System.out.println(entry.getKey() + ", " + entry.getValue());
	    }
            i++;
          }
          resultPage = client.getPackageService().getPackages(new PackageStatusConverter(PackageStatus.DRAFT).toAPIPackageStatus(), new PageRequest(i, 50));
}
Here, I used a variable "i" to keep track of the package index in the resulting page. Also, the maximum number of packages you can retrieve per page is 50. Having said this, this is an exhaustive method of searching your package attributes. This should be alright for a relatively small number of packages, but as you create more and more packages overtime, I wouldn't suggest this method. You would be better off keeping track of your attributes within your application and associate them with the package id that eSignLive returns you.

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