Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/main/java/com/hellosign/sdk/resource/SignatureRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.hellosign.sdk.resource.support.ResponseData;
import com.hellosign.sdk.resource.support.Signature;
import com.hellosign.sdk.resource.support.Signer;
import com.hellosign.sdk.resource.support.Attachment;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -37,13 +38,33 @@ public class SignatureRequest extends AbstractRequest {
public static final String SIGREQ_SIGNING_URL = "signing_url";
public static final String SIGREQ_DETAILS_URL = "details_url";
public static final String SIGREQ_IS_DECLINED = "is_declined";
public static final String SIGREQ_ATTACHMENTS = "attachments";
public static final String SIGREQ_ATTACHMENTS_NAME = "name";
public static final String SIGREQ_ATTACHMENTS_INSTRUCTIONS = "instructions";
public static final String SIGREQ_ATTACHMENTS_INDEX = "signer_index";
public static final String SIGREQ_ATTACHMENTS_REQUIRED = "required";


public static final String SIGREQ_FORMAT_ZIP = "zip";
public static final String SIGREQ_FORMAT_PDF = "pdf";

// Fields specific to request
private List<Signer> signers = new ArrayList<Signer>();

private List<Attachment> attachments = new ArrayList<>();

public List<Attachment> getAttachments() {
return attachments;
}

public List<Attachment> getAttachmentsInResponse(){
return getList(Attachment.class, SIGREQ_ATTACHMENTS);
}

public void setAttachments(List<Attachment> attachments){
this.attachments = attachments;
}

public SignatureRequest() {
super();
}
Expand Down Expand Up @@ -256,6 +277,14 @@ public Map<String, Serializable> getPostFields() throws HelloSignException {
s.getAccessCode());
}
}
List<Attachment> attachmentList = getAttachments();
for(int i=0; i<attachmentList.size(); i++){
Attachment attachment = attachmentList.get(i);
fields.put(SIGREQ_ATTACHMENTS + "[" + i + "][" + SIGREQ_ATTACHMENTS_NAME + "]", attachment.getName());
fields.put(SIGREQ_ATTACHMENTS + "[" + i + "][" + SIGREQ_ATTACHMENTS_INSTRUCTIONS + "]", attachment.getInstructions());
fields.put(SIGREQ_ATTACHMENTS + "[" + i + "][" + SIGREQ_ATTACHMENTS_INDEX + "]", attachment.getSigner_index());
fields.put(SIGREQ_ATTACHMENTS + "[" + i + "][" + SIGREQ_ATTACHMENTS_REQUIRED+ "]",attachment.isRequired());
}
List<String> ccz = getCCs();
for (int i = 0; i < ccz.size(); i++) {
String cc = ccz.get(i);
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/hellosign/sdk/resource/TemplateDraft.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hellosign.sdk.resource;

import com.hellosign.sdk.HelloSignException;
import com.hellosign.sdk.resource.support.Attachment;
import com.hellosign.sdk.resource.support.CustomField;
import com.hellosign.sdk.resource.support.Document;
import com.hellosign.sdk.resource.support.types.FieldType;
Expand All @@ -25,6 +26,11 @@ public class TemplateDraft extends AbstractRequest {
public static final String TEMPLATE_DRAFT_ID = "template_id";
public static final String TEMPLATE_EDIT_URL = "edit_url";
public static final String TEMPLATE_EXPIRES_AT = "expires_at";
public static final String SIGREQ_ATTACHMENTS = "attachments";
public static final String SIGREQ_ATTACHMENTS_NAME = "name";
public static final String SIGREQ_ATTACHMENTS_INSTRUCTIONS = "instructions";
public static final String SIGREQ_ATTACHMENTS_INDEX = "signer_index";
public static final String SIGREQ_ATTACHMENTS_REQUIRED = "required";

private List<String> ccRoles = new ArrayList<>();
private List<String> signerRoles = new ArrayList<>();
Expand All @@ -38,6 +44,21 @@ public TemplateDraft(JSONObject json) throws HelloSignException {
super(json, TEMPLATE_DRAFT_KEY);
}

// List of Attachment
private List<Attachment> attachments = new ArrayList<>();

public List<Attachment> getAttachments() {
return attachments;
}

/**
* Set List of Attachments to the request.
* @param attachments
*/
public void setAttachments(List<Attachment> attachments) {
this.attachments = attachments;
}

/**
* Helper method to convert a Java Map into the JSON string required by the HelloSign API.
*
Expand Down Expand Up @@ -260,6 +281,14 @@ public Map<String, Serializable> getPostFields() throws HelloSignException {
fields.put("signer_roles[" + i + "][order]", i);
}
}
List<Attachment> attachmentList = getAttachments();
for(int i=0; i<attachmentList.size(); i++){
Attachment attachment = attachmentList.get(i);
fields.put(SIGREQ_ATTACHMENTS + "[" + i + "][" + SIGREQ_ATTACHMENTS_NAME + "]", attachment.getName());
fields.put(SIGREQ_ATTACHMENTS + "[" + i + "][" + SIGREQ_ATTACHMENTS_INSTRUCTIONS + "]", attachment.getInstructions());
fields.put(SIGREQ_ATTACHMENTS + "[" + i + "][" + SIGREQ_ATTACHMENTS_INDEX + "]", attachment.getSigner_index());
fields.put(SIGREQ_ATTACHMENTS + "[" + i + "][" + SIGREQ_ATTACHMENTS_REQUIRED+ "]",attachment.isRequired());
}

List<String> ccRoles = getCCRoles();
for (int i = 0; i < ccRoles.size(); i++) {
Expand Down
82 changes: 82 additions & 0 deletions src/main/java/com/hellosign/sdk/resource/support/Attachment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.hellosign.sdk.resource.support;

public class Attachment {
String name;
String instructions;
int signer_index;
boolean isRequired;
int signer;

public Attachment(){
}

/***
* Method to add/request attachments with Signature Request.
* @param name : Signer name
* @param instructions : Instruction for Signer
* @param signer_index : Signer Index (It should be in accordance with signer's order: first signer is 0, second is
* 1 and so on.. )
* @param isRequired : Whether it is mandatory or not.
*/
public Attachment(String name, String instructions, int signer_index, boolean isRequired){
setName(name);
setInstructions(instructions);
setSigner_index(signer_index);
setRequired(isRequired);
}

/**
* Get Instruction for signer.
* @return
*/
public String getInstructions() {
return instructions;
}

public void setInstructions(String instructions) {
if(!instructions.isBlank()){
this.instructions = instructions;
}
}

public int getSigner() {
return signer;
}

/**
* Provide signer_index, in accordance to the order, signer is added.
* Example : first signer : signer_index = 0
* second signer : signer_index = 1
* @param signer_index
*/
public void setSigner_index(int signer_index) {
this.signer_index= signer_index;
}

public int getSigner_index() {
return signer_index;
}


public boolean isRequired() {
return isRequired;
}

public void setRequired(boolean required) {
if(required){
isRequired = required;
}
}

public String getName() {
return name;
}

public void setName(String name) {
if(!name.isBlank()){
this.name = name;
}
}

}

84 changes: 84 additions & 0 deletions src/test/java/com/hellosign/sdk/HelloSignClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.hellosign.sdk.resource.support.TemplateList;
import com.hellosign.sdk.resource.support.TemplateRole;
import com.hellosign.sdk.resource.support.WhiteLabelingOptions;
import com.hellosign.sdk.resource.support.Attachment;
import com.hellosign.sdk.resource.support.types.FieldType;
import com.hellosign.sdk.resource.support.types.UnclaimedDraftType;
import java.io.File;
Expand All @@ -45,6 +46,8 @@
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.Arrays;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Assert;
Expand Down Expand Up @@ -375,6 +378,87 @@ public void testSendSignatureRequest() throws Exception {
assertTrue(req.isTestMode());
}

@Test
public void testSendSignatureRequestWithAttachment() throws Exception {
String subject = "From Vaibhavi";
String message = "Pls sign";
SignatureRequest req = new SignatureRequest();
req.setTestMode(true);
req.addSigner("vaibhavij+stg@hellosign.com", "Vaibhavi Joshi");
req.addSigner("vaibhavij+stg1@hellosign.com","Vaibhavi");
req.addFileUrl("http://www.orimi.com/pdf-test.pdf");
req.setSubject(subject);
req.setMessage(message);
Attachment attachment1 = new Attachment("License","Pl provide copy of license.",0,true);
Attachment attachment2 = new Attachment("California Id","Pl provide copy of California Id.",1,true);
req.setAttachments(Arrays.asList(attachment1,attachment2));
System.out.println(req);
SignatureRequest sentReq = client.sendSignatureRequest(req);

assertNotNull(sentReq);
assertTrue(sentReq.hasId());
assertNotNull(sentReq.getSignature("vaibhavij+stg@hellosign.com", "Vaibhavi Joshi"));
assertEquals(subject, sentReq.getSubject());
assertEquals(message, sentReq.getMessage());
assertTrue(req.isTestMode());

//sentReq.getResponseData().
JSONObject responseObject = sentReq.getJSONObject();
JSONArray attachmentsObject = responseObject.getJSONArray("attachments");
JSONObject attachmentObj1 = (JSONObject) attachmentsObject.get(0);
JSONObject attachmentObj2 = (JSONObject) attachmentsObject.get(1);

// Assert on Signer 1 attachment.
Assert.assertTrue(attachmentObj1.get("name").equals("License"));
Assert.assertTrue(attachmentObj1.get("instructions").equals("Pl provide copy of license."));
Assert.assertTrue(attachmentObj1.get("signer").equals(1));
Assert.assertTrue(attachmentObj1.get("required").equals(true));

// Assert on Signer 2 attachment.
Assert.assertTrue(attachmentObj2.get("name").equals("California Id"));
Assert.assertTrue(attachmentObj2.get("instructions").equals("Pl provide copy of California Id."));
Assert.assertTrue(attachmentObj2.get("signer").equals(2));
Assert.assertTrue(attachmentObj2.get("required").equals(true));
}


@Test
public void testCreateEmbeddedRequestWithAttachment() throws Exception {
SignatureRequest req = new SignatureRequest();
req.addFileUrl("http://www.orimi.com/pdf-test.pdf");
req.addSigner("vaibhavij+stg@hellosign.com", "Chris");
req.setTestMode(true);
req.addMetadata("test_key", "test_value");
Attachment attachment1 = new Attachment("License","Pl provide copy of license.",0,true);
req.setAttachments(Arrays.asList(attachment1));
EmbeddedRequest embeddedReq = new EmbeddedRequest("82d8101db9a2147f8e07244f9ca030a6", req);
Map<String, String> fields = new HashMap<>();
fields.put("Field A", "Hello");
fields.put("Field B", "World!");
fields.put("Checkbox A", "true");
fields.put("Checkbox B", "false");
embeddedReq.setCustomFields(fields);
AbstractRequest newReq = client.createEmbeddedRequest(embeddedReq);
assertNotNull(newReq);
assertNotNull(newReq.getId());
assertEquals(req.getMetadata("test_key"), newReq.getMetadata("test_key"));
for (CustomField cf : newReq.getCustomFields()) {
assertEquals(fields.get(cf.getName()), cf.getValue());
}
//sentReq.getResponseData().
JSONObject responseObject = newReq.getJSONObject();
JSONArray attachmentsObject = responseObject.getJSONArray("attachments");
JSONObject attachmentObj1 = (JSONObject) attachmentsObject.get(0);

// Assert on Signer 1 attachment.
Assert.assertTrue(attachmentObj1.get("name").equals("License"));
Assert.assertTrue(attachmentObj1.get("instructions").equals("Pl provide copy of license."));
Assert.assertTrue(attachmentObj1.get("signer").equals(1));
Assert.assertTrue(attachmentObj1.get("required").equals(true));

}


@Test(expected = HelloSignException.class)
public void testSendSignatureRequestInvalid() throws Exception {
mockResponseCode(400);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"signature_request":{
"signature_request_id":"3cb8286f6ee3770aa7c5670e035362e62245f129",
"test_mode":true,
"title":"pdf-test",
"original_title":"pdf-test",
"subject":null,
"message":null,
"metadata":{
"test_key":"test_value"
},
"created_at":1589207125,
"attachments":[
{
"id":"92376dfb14fb3698faf17592ce731368295f8140",
"signer":1,
"name":"License",
"instructions":"Pl provide copy of license.",
"required":true,
"uploaded_at":null
}
],
"is_complete":false,
"is_declined":false,
"has_error":false,
"custom_fields":[

],
"response_data":[

],
"signing_url":null,
"signing_redirect_url":null,
"final_copy_uri":"\/v3\/signature_request\/final_copy\/3cb8286f6ee3770aa7c5670e035362e62245f129",
"files_url":"https:\/\/api.hellosign.com\/v3\/signature_request\/files\/3cb8286f6ee3770aa7c5670e035362e62245f129",
"details_url":"https:\/\/app.hellosign.com\/home\/manage?guid=3cb8286f6ee3770aa7c5670e035362e62245f129",
"requester_email_address":"vaibhavij+prd@hellosign.com",
"signatures":[
{
"signature_id":"5bfaf1af15b13f7f3fe57361e78577fd",
"has_pin":false,
"signer_email_address":"vaibhavij+stg@hellosign.com",
"signer_name":"Chris",
"signer_role":null,
"order":null,
"status_code":"awaiting_signature",
"signed_at":null,
"last_viewed_at":null,
"last_reminded_at":null,
"error":null
}
],
"cc_email_addresses":[

],
"template_ids":null,
"client_id":"82d8101db9a2147f8e07244f9ca030a6"
}
}
Loading