blog

e-SignLive for New Users: Check Package Status and Download Files (Java SDK)

Developer
|  June 23, 2015 Michael Williams
esignlive code

Last time, I showed how to set up a Java project within Eclipse to allow you to create and send a package using the e-SignLive Java SDK. This week, I will cover some things you can do after sending the package, like:

  • Checking the package/signing status
  • Downloading the e-signed documents
  • Downloading the evidence summary

I will pick up right where I left off, last week. If you followed along, you had just looked in your e-SignLive inbox to see that your document package was created and sent properly after executing the Java class built in the tutorial.

 

inbox

 

Configuration

Initial Setup

Create a new .java file for this tutorial. You can place it in the same location as in the last tutorial or you can start a new project. Either way will work. I named my file, "SimpleCheckStatusAndDownload.java". If you need help with this setup, visit my previous blog for further instructions.

Locating the Package ID of your Existing Project

Since the package you are working with was created previously, we need to find the package ID for use in this project. If you select the project from the UI inbox, as seen above, the URL will have the package ID, like this:

 

https://sandbox.esignlive.com/packages/yourPackageID

 

In the Java class you created in the last blog, you will see you had access to this package ID when you created the package and used it to send the package. If you were creating a more complex application, you would likely store this package ID for use within other parts of your application, versus looking it up in your e-SignLive URLs.

If you want to see this package ID coming from the Java class made in last blog’s tutorial, you could add the line, System.out.println("PackageId: " + packageId); after the line, PackageId packageId = eslClient.createPackage( documentPackage );. If you run that class again, you will now see the package ID printed to the console view within Eclipse.

packageIdInConsole

The Code

You are now ready to write the code in your Java class. Copy the following code into your "SimpleCheckStatusAndDownload.java" file (or whatever you named it) that you created above.

package com.esignlive.example;

import com.silanis.esl.sdk.DocumentPackage;
import com.silanis.esl.sdk.EslClient;
import com.silanis.esl.sdk.PackageId;
import com.silanis.esl.sdk.PackageStatus;
import com.silanis.esl.sdk.SigningStatus;
import com.silanis.esl.sdk.io.Files;

public class SimpleCheckStatusAndDownload {
	
    public static final String API_KEY = "";
    public static final String API_URL = "https://sandbox.esignlive.com/api"; 
    // USE https://apps.e-signlive.com/api FOR PRODUCTION
 
    public static void main( String[] args ) {
      //connect to e-SignLive
    	EslClient eslClient = new EslClient( API_KEY, API_URL );

      //create a packageId using you packageId string
      PackageId packageId = new PackageId("");
    	
    	//get your package
    	DocumentPackage sentPackage = eslClient.getPackage(packageId);
    	
    	//checking package status
    	PackageStatus status = sentPackage.getStatus();
    	System.out.println(status);
    	
    	//checking signing status
    	SigningStatus sentSigningStatus = eslClient
                .getSigningStatus( packageId, null, null );
    	System.out.println(sentSigningStatus.getToken());
    	
    	//if signing is complete, download all documents
    	if(sentSigningStatus.getToken() == "SIGNING_PENDING"){
    		System.out.println("Cannot Download: Signing not complete");
    	}
    	else{
    		//download zip file
    		byte[] documentZip = eslClient.downloadZippedDocuments(packageId);
    		Files.saveTo(documentZip, "documentZip.zip");
    		System.out.println("Document Zip File Downloaded");
    		
    		//download evidence summary
    		byte[] evidenceSummary = eslClient
                        .downloadEvidenceSummary(packageId);
            Files.saveTo(evidenceSummary, "evidenceSummary.pdf");
            System.out.println("Evidence Summary Downloaded");
    	}
    }
}

 

Now, let’s take a closer look at the code. Just like last time, the first few lines define your connection information for e-SignLive.

 

Access the Package

public static final String API_KEY = "";
public static final String API_URL = "https://sandbox.esignlive.com/api"; 
// USE https://apps.e-signlive.com/api FOR PRODUCTION

 

Be sure to put your API_KEY in place of the placeholder.

Again, because this is a very simple example, the rest is done within the main method. The first line inside the main method is where you connect to e-SignLive using your connection info, from above.

//connect to e-SignLive
EslClient eslClient = new EslClient( API_KEY, API_URL );

Next, a PackageId object is created using the Package ID you got from your URL (or package creation Java class), above. Then, you will use that PackageId object to grab your previously sent package from the e-SignLive client.

//create a packageId using you packageId string
PackageId packageId = new PackageId("");
//get your package
DocumentPackage sentPackage = eslClient.getPackage(packageId);

Check the Status

Now that you have access to the document package, you can check uour package to see what the package status is. The possible values are ARCHIVED, COMPLETED, DECLINED, DRAFT, EXPIRED, OPTED_OUT, and SENT. Go ahead and print the status so we can see it in the console when we execute our class.

 

//checking package status
PackageStatus status = sentPackage.getStatus();
System.out.println(status);

 

Next, check the signing status of the package. The possible values for this one are ARCHIVED, CANCELED, COMPLETE, DECLINED, EXPIRED, INACTIVE, OPTED_OUT, COMPLETED, and SIGNING_PENDING. Print this status to the console, as well.

 

//checking signing status
SigningStatus sentSigningStatus = eslClient.getSigningStatus( packageId, null, null );
System.out.println(sentSigningStatus.getToken());

 

Download the Files

For the last part, you will check to see if the package is complete. If it is, the zip file of all documents will be downloaded, as well as the evidence summary. By putting just a file name for each file in the Files.saveTo… lines, the file will be saved to the root of your Java project in Eclipse. After each step, print to the console so that you know the event happened when you test the Java class in the next step.

//if signing is complete, download all documents
if(sentSigningStatus.getToken() != "SIGNING_COMPLETE"){
System.out.println("Cannot Download: Signing not complete");
}
else{
    	//download zip file
    	byte[] documentZip = eslClient.downloadZippedDocuments(packageId);
    	Files.saveTo(documentZip, "documentZip.zip");
    	System.out.println("Document Zip File Downloaded");
    		
    	//download evidence summary
    	byte[] evidenceSummary = eslClient.downloadEvidenceSummary(packageId);
       Files.saveTo(evidenceSummary, "evidenceSummary.pdf");
       System.out.println("Evidence Summary Downloaded");
}

 

Running the Code

With your simple class completed, it is time to execute the Java class. Run the class from the toolbar, menu bar, or by right clicking on the class in the Package Explorer and going to Run As -> Java Application.

If you have not yet signed your package, your Console should look like the following:

 

consoleSigningNotComplete

 

After signing your package, you will get the following output in your Console view:

 

consoleSigningComplete

 

If you refresh your project in your Package Explorer by right-clicking and going to Refresh, you will see that your files were successfully downloaded.

 

downloadedFiles with Java SDK

 

There you have it. You have successfully checked the status of and downloaded the files from your package.

Thanks for reading! If you have any questions or features you would like to see covered from a new user’s perspective, feel free to post in the comments section. Links to all of the posts from this blog series can be found, below. If you want to see more posts from me, see my author page.

– Michael Williams
Twitter | Facebook | LinkedIn

 

eSignLive for New Users Blog Series