GuideLCServiceConnectorImpl.java
9.09 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemds.guide.service.GuideException
* com.adobe.aemds.guide.service.GuideLCServiceConnector
* com.adobe.idp.dsc.InvocationRequest
* com.adobe.idp.dsc.InvocationResponse
* com.adobe.idp.dsc.clientsdk.ServiceClient
* com.adobe.idp.dsc.clientsdk.ServiceClientFactory
* com.adobe.idp.dsc.filter.Condition
* com.adobe.idp.dsc.filter.FilterResult
* com.adobe.idp.dsc.filter.PagingFilter
* com.adobe.idp.dsc.registry.InputParameterNotFoundException
* com.adobe.idp.dsc.registry.OperationNotFoundException
* com.adobe.idp.dsc.registry.infomodel.InputParameter
* com.adobe.idp.dsc.registry.infomodel.Operation
* com.adobe.idp.dsc.registry.infomodel.ServiceConfiguration
* com.adobe.idp.dsc.registry.service.ServiceConfigurationFilter
* com.adobe.idp.dsc.registry.service.ServiceRegistry
* com.adobe.livecycle.dsc.clientsdk.ServiceClientFactoryProvider
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.commons.osgi.PropertiesUtil
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.addon.service.impl;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.service.GuideLCServiceConnector;
import com.adobe.idp.dsc.InvocationRequest;
import com.adobe.idp.dsc.InvocationResponse;
import com.adobe.idp.dsc.clientsdk.ServiceClient;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
import com.adobe.idp.dsc.filter.Condition;
import com.adobe.idp.dsc.filter.FilterResult;
import com.adobe.idp.dsc.filter.PagingFilter;
import com.adobe.idp.dsc.registry.InputParameterNotFoundException;
import com.adobe.idp.dsc.registry.OperationNotFoundException;
import com.adobe.idp.dsc.registry.infomodel.InputParameter;
import com.adobe.idp.dsc.registry.infomodel.Operation;
import com.adobe.idp.dsc.registry.infomodel.ServiceConfiguration;
import com.adobe.idp.dsc.registry.service.ServiceConfigurationFilter;
import com.adobe.idp.dsc.registry.service.ServiceRegistry;
import com.adobe.livecycle.dsc.clientsdk.ServiceClientFactoryProvider;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(label="Guide LiveCycle Process Locator and Invoker", description="Guide LC Process Locator and Invoker Service", immediate=1, metatype=1)
@Service(value={GuideLCServiceConnector.class})
public class GuideLCServiceConnectorImpl
implements GuideLCServiceConnector {
@Reference
private ServiceClientFactoryProvider serviceClientFactoryProvider;
@Reference
private ServiceRegistry serviceRegistry;
@Property(value={"dataxml"}, label="Name of the data xml parameter", description="Name of the parameter corresponding to data xml")
private static final String DATA_XML = "dataXml";
private String dataXml;
@Property(value={"fileAttachmentsList"}, label="Name of the file attachments parameter", description="Name of the parameter corresponding to the list of file attachments")
private static final String FILE_ATTACHMENTS_LIST = "fileAttachmentsList";
private String fileAttachmentsList;
@Property(value={"documentOfRecord"}, label="Name of the document of record parameter", description="Name of the parameter corresponding to document of record")
private static final String DOCUMENT_OF_RECORD = "documentOfRecord";
private String documentOfRecord;
private static final String INVOKE_METHOD = "invoke";
private Logger logger = LoggerFactory.getLogger(GuideLCServiceConnectorImpl.class);
protected void activate(ComponentContext context) {
Dictionary props = context.getProperties();
this.dataXml = PropertiesUtil.toString(props.get("dataXml"), (String)"dataXml");
this.fileAttachmentsList = PropertiesUtil.toString(props.get("fileAttachmentsList"), (String)"fileAttachmentsList");
this.documentOfRecord = PropertiesUtil.toString(props.get("documentOfRecord"), (String)"documentOfRecord");
}
public List<String> getServices() {
try {
ServiceConfigurationFilter filter = new ServiceConfigurationFilter();
filter.addCondition("type", (Object)"WKF");
FilterResult configs = this.serviceRegistry.getServiceConfigurations((PagingFilter)filter);
ArrayList<String> serviceNames = new ArrayList<String>();
for (Object config : configs) {
ServiceConfiguration serviceConfig = (ServiceConfiguration)config;
try {
Operation op = null;
try {
op = serviceConfig.getOperation("invoke");
if (op == null) continue;
InputParameter[] inParams = op.getInputParameters();
InputParameter data = null;
InputParameter files = null;
try {
data = op.getInputParameter(this.dataXml);
files = op.getInputParameter(this.fileAttachmentsList);
}
catch (InputParameterNotFoundException e) {
this.logger.info("No parameters found by the names " + this.dataXml + " and " + this.fileAttachmentsList, (Throwable)e);
}
if (data == null) continue;
serviceNames.add(serviceConfig.getServiceId());
}
catch (Exception e) {
this.logger.info("Ignoring process '" + serviceConfig.getServiceId() + "' - No operation found by the name '" + "invoke" + "'", (Throwable)e);
}
continue;
}
catch (Exception e) {
throw new GuideException(e);
}
}
return serviceNames;
}
catch (Exception e) {
throw new GuideException(e);
}
}
public String getXmlParameterName() {
return this.dataXml;
}
public String getFileListParameterName() {
return this.fileAttachmentsList;
}
public String getDocumentOfRecordParameterName() {
return this.documentOfRecord;
}
public Map invokeProcess(String process, Map inputParams) {
return this.invokeProcess(process, "invoke", inputParams, false);
}
private Map invokeProcess(String process, String method, Map inputParams, boolean waitForResponse) {
try {
HashMap outputParams = null;
boolean synchronous = false;
long l1 = System.currentTimeMillis();
try {
ServiceConfiguration serviceConfiguration = this.serviceRegistry.getHeadActiveConfiguration(process);
synchronous = !serviceConfiguration.getOperation(method).getLongLived();
}
catch (OperationNotFoundException e) {
throw new GuideException((Exception)e);
}
long l2 = System.currentTimeMillis();
ServiceClientFactory serviceClientFactory = this.serviceClientFactoryProvider.getDefaultServiceClientFactory();
InvocationRequest request = serviceClientFactory.createInvocationRequest(process, method, inputParams, synchronous);
request.setProperty("INVOKER_TYPE", (Object)"INVOKER_TYPE_SYSTEM");
InvocationResponse response = null;
response = serviceClientFactory.getServiceClient().invoke(request);
if (synchronous) {
outputParams = response.getOutputParameters();
} else {
outputParams = new HashMap();
String invocationId = response.getInvocationId();
}
return outputParams;
}
catch (Exception e) {
throw new GuideException(e);
}
}
protected void bindServiceClientFactoryProvider(ServiceClientFactoryProvider serviceClientFactoryProvider) {
this.serviceClientFactoryProvider = serviceClientFactoryProvider;
}
protected void unbindServiceClientFactoryProvider(ServiceClientFactoryProvider serviceClientFactoryProvider) {
if (this.serviceClientFactoryProvider == serviceClientFactoryProvider) {
this.serviceClientFactoryProvider = null;
}
}
protected void bindServiceRegistry(ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
protected void unbindServiceRegistry(ServiceRegistry serviceRegistry) {
if (this.serviceRegistry == serviceRegistry) {
this.serviceRegistry = null;
}
}
}