AgreementCreation.java
4.87 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aem.adobesign.service.AdobeSignService
* com.adobe.aem.adobesign.service.AgreementCreationOptions
* com.adobe.aem.adobesign.service.AgreementCreationResponse
* com.adobe.aemfd.docmanager.Document
* com.adobe.granite.workflow.WorkflowException
* com.adobe.granite.workflow.WorkflowSession
* com.adobe.granite.workflow.exec.WorkItem
* com.adobe.granite.workflow.metadata.MetaDataMap
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferenceCardinality
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.References
* org.apache.felix.scr.annotations.Service
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.fd.workflow.adobesign.impl;
import com.adobe.aem.adobesign.service.AdobeSignService;
import com.adobe.aem.adobesign.service.AgreementCreationOptions;
import com.adobe.aem.adobesign.service.AgreementCreationResponse;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.workflow.adobesign.api.RecipientInfoSpecifier;
import com.adobe.fd.workflow.adobesign.internal.utils.AgreementCreationUtils;
import com.adobe.fd.workflow.internal.common.AEMFDWorkflowProcess;
import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.References;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
@References(value={@Reference(name="RecipientInfoSpecifer", cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC, referenceInterface=RecipientInfoSpecifier.class)})
public class AgreementCreation
extends AEMFDWorkflowProcess {
@Reference
private AdobeSignService adobeSignService;
private static final Logger log = LoggerFactory.getLogger(AgreementCreation.class);
protected List<RecipientInfoSpecifier> recipientInfoSpecifer = new CopyOnWriteArrayList<RecipientInfoSpecifier>();
public void bindRecipientInfoSpecifer(RecipientInfoSpecifier chooser) {
this.recipientInfoSpecifer.add(chooser);
}
public void unbindRecipientInfoSpecifer(RecipientInfoSpecifier chooser) {
this.recipientInfoSpecifer.remove(chooser);
}
@Override
protected void internal_execute(WorkItem item, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
InputStream is = null;
try {
Document inDoc = AgreementCreationUtils.getInputDoc(item, args);
if (inDoc == null) {
log.error("Input Document is null");
throw new WorkflowException("Input Document can not be null");
}
String signConfig = AgreementCreationUtils.getAdobeSignCloudService(args);
AgreementCreationOptions agreementCreationOptions = AgreementCreationUtils.getAgreementCreationOptions(item, workflowSession, args, this.recipientInfoSpecifer);
is = inDoc.getInputStream();
AgreementCreationResponse response = this.adobeSignService.createAgreement(is, signConfig, agreementCreationOptions);
item.getMetaDataMap().put((Object)"agreementId", (Object)response.getAgreementId());
item.getMetaDataMap().put((Object)"FORM_WORK_ITEM_TYPE", (Object)"ADOBESIGN_STEP");
AgreementCreationUtils.writeVariabletoMetadata(item, "variableForStatus", "OUT_FOR_SIGNATURE");
}
catch (Exception e) {
log.error("Exception in Adobe Sign Service", (Throwable)e);
throw new WorkflowException("Exception in Adobe Sign Service", (Throwable)e);
}
finally {
try {
if (is != null) {
is.close();
}
}
catch (IOException e) {
log.error("Exception while closing document input stream " + e.getMessage());
throw new WorkflowException("Exception while closing document input stream ", (Throwable)e);
}
}
}
protected void bindAdobeSignService(AdobeSignService adobeSignService) {
this.adobeSignService = adobeSignService;
}
protected void unbindAdobeSignService(AdobeSignService adobeSignService) {
if (this.adobeSignService == adobeSignService) {
this.adobeSignService = null;
}
}
}