-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDocumentGroupRecipientsExample.java
More file actions
91 lines (79 loc) · 3.8 KB
/
DocumentGroupRecipientsExample.java
File metadata and controls
91 lines (79 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.signnow.api.documentgroup.request.DocumentGroupRecipientsGetRequest;
import com.signnow.api.documentgroup.request.DocumentGroupRecipientsPutRequest;
import com.signnow.api.documentgroup.request.data.CcCollection;
import com.signnow.api.documentgroup.request.data.recipient.Recipient;
import com.signnow.api.documentgroup.request.data.recipient.RecipientCollection;
import com.signnow.api.documentgroup.response.DocumentGroupRecipientsGetResponse;
import com.signnow.api.documentgroup.response.DocumentGroupRecipientsPutResponse;
import com.signnow.core.ApiClient;
import com.signnow.core.exception.SignNowApiException;
import com.signnow.core.factory.SdkFactory;
public class DocumentGroupRecipientsExample {
public static void main(String[] args) {
// Set your actual input data here
// Note: following values are dummy, just for example
// ----------------------------------------------------
// if it is not specified here, a new Bearer token will be created automatically
String bearerToken = "";
String documentGroupId = "5d66ca4accdd4ab28f8b2c71001093b5cb3bcb8a";
try {
ApiClient client = SdkFactory.createApiClientWithBearerToken(bearerToken);
// Get recipient
DocumentGroupRecipientsGetRequest request = new DocumentGroupRecipientsGetRequest()
.withDocumentGroupId(documentGroupId);
DocumentGroupRecipientsGetResponse response = (DocumentGroupRecipientsGetResponse) client.send(request)
.getResponse();
// Convert to request model and replace email
RecipientCollection recipientCollection = new RecipientCollection();
for (com.signnow.api.documentgroup.response.data.data.Recipient responseRecipient : response.getData()
.getRecipients()) {
Recipient reqRecipient = convertRecipient(responseRecipient);
if (reqRecipient == null) continue;
System.out.println("Original name: " + responseRecipient.getName());
System.out.println("Original email: " + responseRecipient.getEmail());
if (reqRecipient.getName().equals("Recipient 1")) {
// Replace email
Recipient updated = new Recipient(
reqRecipient.getName(),
"new.email@example.com",
reqRecipient.getOrder(),
reqRecipient.getDocuments(),
reqRecipient.getEmailGroup(),
reqRecipient.getAttributes());
recipientCollection.add(updated);
} else {
recipientCollection.add(reqRecipient);
}
}
// Send PUT request
DocumentGroupRecipientsPutRequest putRequest = new DocumentGroupRecipientsPutRequest(
recipientCollection,
new CcCollection()).withDocumentGroupId(documentGroupId);
DocumentGroupRecipientsPutResponse putResponse = (DocumentGroupRecipientsPutResponse) client.send(putRequest)
.getResponse();
System.out.println("Updated email: " + putResponse.getData().getRecipients().get(0).getEmail());
} catch (SignNowApiException e) {
System.out.println("ERROR: " + e.getMessage());
}
}
private static Recipient convertRecipient(
com.signnow.api.documentgroup.response.data.data.Recipient responseRecipient) {
ObjectMapper mapper = new ObjectMapper();
try {
String json = mapper.writeValueAsString(responseRecipient);
Recipient recipient = mapper.readValue(json, Recipient.class);
return new Recipient(
recipient.getName(),
recipient.getEmail(),
recipient.getOrder(),
recipient.getDocuments(),
recipient.getEmailGroup(),
recipient.getAttributes());
} catch (JsonProcessingException e) {
e.printStackTrace();
return null;
}
}
}