AdobeSignStatusHandlerImpl.java
12.6 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aem.adobesign.handler.AdobeSignHandlerObject
* com.adobe.aem.adobesign.handler.AdobeSignStatusHandler
* com.adobe.aem.adobesign.recipient.ParticipantInfo
* com.adobe.aem.adobesign.recipient.ParticipantSetInfo
* com.adobe.aem.adobesign.service.AdobeSignServiceException
* com.adobe.aem.adobesign.service.AgreementStatusOptions
* com.adobe.aem.adobesign.service.AgreementStatusResponse
* com.adobe.aem.adobesign.service.AgreementStatusResponse$AgreementStatus
* com.adobe.aemfd.docmanager.Document
* com.adobe.granite.resourceresolverhelper.ResourceResolverHelper
* com.adobe.granite.workflow.WorkflowException
* com.adobe.granite.workflow.WorkflowSession
* com.adobe.granite.workflow.collection.util.ResultSet
* com.adobe.granite.workflow.exec.Route
* com.adobe.granite.workflow.exec.WorkItem
* com.adobe.granite.workflow.exec.filter.WorkItemFilter
* com.adobe.granite.workflow.metadata.MetaDataMap
* com.adobe.granite.workflow.model.WorkflowNode
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.commons.lang.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.LoginException
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.jcr.api.SlingRepository
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.fd.workflow.adobesign.ItemStatus;
import com.adobe.aem.adobesign.handler.AdobeSignHandlerObject;
import com.adobe.aem.adobesign.handler.AdobeSignStatusHandler;
import com.adobe.aem.adobesign.recipient.ParticipantInfo;
import com.adobe.aem.adobesign.recipient.ParticipantSetInfo;
import com.adobe.aem.adobesign.service.AdobeSignServiceException;
import com.adobe.aem.adobesign.service.AgreementStatusOptions;
import com.adobe.aem.adobesign.service.AgreementStatusResponse;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.workflow.adobesign.ItemStatus.AdobeSignWorkItemFilter;
import com.adobe.fd.workflow.adobesign.internal.utils.AgreementCreationUtils;
import com.adobe.fd.workflow.utils.CommonUtils;
import com.adobe.fd.workflow.utils.DocumentUtils;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.collection.util.ResultSet;
import com.adobe.granite.workflow.exec.Route;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.filter.WorkItemFilter;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.adobe.granite.workflow.model.WorkflowNode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1)
@Service(value={AdobeSignStatusHandler.class})
public class AdobeSignStatusHandlerImpl
implements AdobeSignStatusHandler {
private final Logger logger = LoggerFactory.getLogger(AdobeSignStatusHandlerImpl.class);
@Reference
private SlingRepository slingRepository;
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Reference
private ResourceResolverHelper resourceResolverHelper;
public Map<String, AdobeSignHandlerObject> getPendingAgreements() throws AdobeSignServiceException {
ResourceResolver resourceResolver = null;
try {
resourceResolver = CommonUtils.getFnDServiceUserResourceResolver(this.resourceResolverFactory);
}
catch (LoginException e1) {
this.logger.error("Exception while login via fd-user");
throw new AdobeSignServiceException((Throwable)e1);
}
WorkflowSession graniteWorkflowSession = (WorkflowSession)resourceResolver.adaptTo(WorkflowSession.class);
AdobeSignWorkItemFilter filter = new AdobeSignWorkItemFilter();
ResultSet workItems = null;
try {
workItems = graniteWorkflowSession.getActiveWorkItems(0, -1, (WorkItemFilter)filter);
}
catch (WorkflowException e) {
throw new AdobeSignServiceException((Throwable)e);
}
finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
WorkItem[] allWorkflowsItems = null;
if (workItems != null) {
allWorkflowsItems = (WorkItem[])workItems.getItems();
}
HashMap<String, AdobeSignHandlerObject> agreements = new HashMap<String, AdobeSignHandlerObject>();
for (WorkItem pendingItems : allWorkflowsItems) {
AdobeSignHandlerObject handlerObj = new AdobeSignHandlerObject();
handlerObj.getStatusOptions().setFetchSignedDocument(true);
handlerObj.getStatusOptions().setFetchAttachments(false);
handlerObj.getStatusOptions().setFetchFormData(true);
String signConfig = null;
if (pendingItems.getNode().getMetaDataMap().get("signConfig", String.class) != null) {
signConfig = (String)pendingItems.getNode().getMetaDataMap().get("signConfig", String.class);
}
handlerObj.setSignConfig(signConfig);
handlerObj.setSystemId(pendingItems.getId());
agreements.put((String)pendingItems.getMetaDataMap().get("agreementId", String.class), handlerObj);
}
return agreements;
}
public Map<String, Object> updateAgreementStatus(String systemId, AgreementStatusResponse asr) throws AdobeSignServiceException {
block26 : {
Session _session;
ResourceResolver resourceResolver = null;
try {
resourceResolver = CommonUtils.getFnDServiceUserResourceResolver(this.resourceResolverFactory);
}
catch (LoginException e1) {
this.logger.error("Exception while login via fd-user");
throw new AdobeSignServiceException((Throwable)e1);
}
WorkflowSession graniteWorkflowSession = (WorkflowSession)resourceResolver.adaptTo(WorkflowSession.class);
try {
_session = CommonUtils.getFDServiceUserSession(this.slingRepository);
}
catch (RepositoryException e1) {
this.logger.error("Exception while getting session from sling repository");
throw new AdobeSignServiceException((Throwable)e1);
}
try {
if (StringUtils.isEmpty((String)systemId)) {
throw new AdobeSignServiceException("System Id must be specified for updating e sign properties.");
}
WorkItem currentWorkItem = graniteWorkflowSession.getWorkItem(systemId);
if (asr == null) {
this.logger.info("Respone return from scheduler is null");
Map<String, Object> map = null;
return map;
}
String inputId = asr.getAgreementId();
String storedId = null;
storedId = (String)currentWorkItem.getMetaDataMap().get("agreementId", String.class);
if (!storedId.equals(inputId)) {
this.logger.error("Cannot update sign status properties with differing agreement Id.");
throw new AdobeSignServiceException("Cannot update sign status properties with differing agreement Id.");
}
if (asr.getAgreementStatus() != AgreementStatusResponse.AgreementStatus.OUT_FOR_SIGNATURE) {
if (asr.getAgreementStatus() == AgreementStatusResponse.AgreementStatus.SIGNED) {
String payload = CommonUtils.getPayloadPath(currentWorkItem);
MetaDataMap metaDataMap = currentWorkItem.getNode().getMetaDataMap();
String locUnderPayload = (String)metaDataMap.get("output", String.class);
DocumentUtils.createOrUpdateDocument(_session, new Document(asr.getSignedDocument()), payload, locUnderPayload);
AgreementCreationUtils.writeVariabletoMetadata(currentWorkItem, "variableForStatus", asr.getAgreementStatus().toString());
List routes = graniteWorkflowSession.getRoutes(currentWorkItem, false);
Route route = null;
if (routes.size() > 0) {
for (Route r : routes) {
if (!r.hasDefault()) continue;
route = r;
}
}
if (route == null) {
route = (Route)routes.get(0);
}
graniteWorkflowSession.complete(currentWorkItem, route);
} else {
AgreementCreationUtils.writeVariabletoMetadata(currentWorkItem, "variableForStatus", asr.getAgreementStatus().toString());
List routes = graniteWorkflowSession.getRoutes(currentWorkItem, false);
Route route = null;
if (routes.size() > 0) {
for (Route r : routes) {
if (!r.hasDefault()) continue;
route = r;
}
}
if (route == null) {
route = (Route)routes.get(0);
}
graniteWorkflowSession.complete(currentWorkItem, route);
}
_session.save();
break block26;
}
ArrayList<String> nextEmails = new ArrayList<String>();
List nextParticipants = asr.getNextParticipantSets();
for (ParticipantSetInfo particiants : nextParticipants) {
List participantInfo = particiants.getMembers();
for (ParticipantInfo eachParticipantInfo : participantInfo) {
String email = eachParticipantInfo.getEmail();
nextEmails.add(email);
}
}
String[] emails = nextEmails.toArray(new String[0]);
Node _node = _session.getNode(currentWorkItem.getId() + "/metaData");
_node.setProperty("nextParticipants", emails);
_session.save();
}
catch (AdobeSignServiceException e) {
throw e;
}
catch (Exception e) {
throw new AdobeSignServiceException((Throwable)e);
}
finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
}
return null;
}
protected void bindSlingRepository(SlingRepository slingRepository) {
this.slingRepository = slingRepository;
}
protected void unbindSlingRepository(SlingRepository slingRepository) {
if (this.slingRepository == slingRepository) {
this.slingRepository = null;
}
}
protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resourceResolverFactory = resourceResolverFactory;
}
protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resourceResolverFactory == resourceResolverFactory) {
this.resourceResolverFactory = null;
}
}
protected void bindResourceResolverHelper(ResourceResolverHelper resourceResolverHelper) {
this.resourceResolverHelper = resourceResolverHelper;
}
protected void unbindResourceResolverHelper(ResourceResolverHelper resourceResolverHelper) {
if (this.resourceResolverHelper == resourceResolverHelper) {
this.resourceResolverHelper = null;
}
}
}