ScriptedPayloadMapper.java
5.52 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemfd.docmanager.Document
* com.adobe.granite.workflow.exec.Workflow
* javax.jcr.Binary
* javax.jcr.Node
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.scripting.SlingBindings
* org.apache.sling.api.scripting.SlingScript
*/
package com.adobe.aemfd.watchfolder.workflow;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.aemfd.watchfolder.util.SessionUtil;
import com.adobe.aemfd.watchfolder.workflow.api.payload.PayloadMapper;
import com.adobe.aemfd.watchfolder.workflow.api.payload.WorkflowExecutionContext;
import com.adobe.aemfd.watchfolder.workflow.api.payload.WorkflowInitializationContext;
import com.adobe.aemfd.watchfolder.workflow.api.payload.WorkflowVariable;
import com.adobe.granite.workflow.exec.Workflow;
import java.util.Collection;
import java.util.Map;
import javax.jcr.Binary;
import javax.jcr.Node;
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.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.api.scripting.SlingScript;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(immediate=1)
@Service(value={PayloadMapper.class})
public class ScriptedPayloadMapper
implements PayloadMapper {
@Reference
private SessionUtil sessionUtil;
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
protected /* varargs */ Object doExecute(WorkflowInitializationContext wfInitContext, String method, Object ... args) throws Exception {
Object object;
String scriptPath = (String)wfInitContext.getConfigParameters().get("payload.mapper.script.path");
ResourceResolver rr = this.sessionUtil.getServiceResolver("scripts");
try {
SlingBindings sb = new SlingBindings();
SlingScript script = null;
Resource r = rr.getResource(scriptPath);
if (r != null) {
script = (SlingScript)r.adaptTo(SlingScript.class);
}
if (script == null) {
throw new Exception("Failed to resolve script at path " + scriptPath + ". Verify that the resource exists, is an executable script and is accessible to the" + " service-user used for watch-folder script execution.");
}
object = script.call(sb, method, args);
Object var11_10 = null;
}
catch (Throwable var10_12) {
Object var11_11 = null;
rr.close();
throw var10_12;
}
rr.close();
return object;
}
@Override
public Node createPayload(WorkflowInitializationContext wfInitCtxt, Node stagingFolder, String uniquePayloadName, Map<String, Binary> inputs, Collection<WorkflowVariable> variableDefs) throws Exception {
return (Node)this.doExecute(wfInitCtxt, "createPayload", new Object[]{wfInitCtxt, stagingFolder, uniquePayloadName, inputs, variableDefs});
}
@Override
public Map<String, Document> getInputs(WorkflowInitializationContext wfInitCtxt, WorkflowExecutionContext wfExecCtxt, Node payload, ResourceResolver resourceResolver) throws Exception {
return (Map)this.doExecute(wfInitCtxt, "getInputs", new Object[]{wfInitCtxt, wfExecCtxt, payload, resourceResolver});
}
@Override
public void setOutput(WorkflowInitializationContext wfInitCtxt, WorkflowExecutionContext wfExecCtxt, Node payload, String fileName, Binary contents, int outputMode) throws Exception {
this.doExecute(wfInitCtxt, "setOutput", new Object[]{wfInitCtxt, wfExecCtxt, payload, fileName, contents, outputMode});
}
@Override
public Map<String, Document> getIntermediateOutputs(WorkflowInitializationContext wfInitCtxt, WorkflowExecutionContext wfExecCtxt, Node payload, ResourceResolver resourceResolver) throws Exception {
return (Map)this.doExecute(wfInitCtxt, "getIntermediateOutputs", new Object[]{wfInitCtxt, wfExecCtxt, payload, resourceResolver});
}
@Override
public Map<String, Document> getFinalOutputs(WorkflowInitializationContext wfInitCtxt, Workflow workflow, Node payload, ResourceResolver resourceResolver) throws Exception {
return (Map)this.doExecute(wfInitCtxt, "getFinalOutputs", new Object[]{wfInitCtxt, workflow, payload, resourceResolver});
}
@Override
public void setVariable(WorkflowInitializationContext wfInitCtxt, WorkflowExecutionContext wfExecCtxt, Node payload, WorkflowVariable variable) throws Exception {
this.doExecute(wfInitCtxt, "setVariable", new Object[]{wfInitCtxt, wfExecCtxt, payload, variable});
}
@Override
public Map<String, Object> getVariables(WorkflowInitializationContext wfInitCtxt, WorkflowExecutionContext wfExecCtxt, Node payload) throws Exception {
return (Map)this.doExecute(wfInitCtxt, "getVariables", new Object[]{wfInitCtxt, wfExecCtxt, payload});
}
protected void bindSessionUtil(SessionUtil sessionUtil) {
this.sessionUtil = sessionUtil;
}
protected void unbindSessionUtil(SessionUtil sessionUtil) {
if (this.sessionUtil == sessionUtil) {
this.sessionUtil = null;
}
}
}