CQDynamicParticipantExecutor.java
6.76 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.workflow.WorkflowSession
* com.adobe.granite.workflow.exec.DynamicParticipantExecutor
* com.adobe.granite.workflow.exec.WorkItem
* com.adobe.granite.workflow.metadata.MetaDataMap
* com.adobe.granite.workflow.model.WorkflowNode
* com.day.cq.workflow.WorkflowService
* com.day.cq.workflow.WorkflowSession
* com.day.cq.workflow.exec.ParticipantChooser
* com.day.cq.workflow.exec.ParticipantStepChooser
* com.day.cq.workflow.exec.WorkItem
* com.day.cq.workflow.metadata.MetaDataMap
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* 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.day.cq.workflow.compatibility;
import com.adobe.granite.workflow.exec.DynamicParticipantExecutor;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.adobe.granite.workflow.model.WorkflowNode;
import com.day.cq.workflow.WorkflowService;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.ParticipantChooser;
import com.day.cq.workflow.exec.ParticipantStepChooser;
import com.day.cq.workflow.impl.CQWorkflowSessionWrapper;
import com.day.cq.workflow.impl.exec.CQWorkItemWrapper;
import com.day.cq.workflow.impl.metadata.CQMetaDataMap;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
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.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(metatype=1, label="%cq.workflow.compat.executor.dynamicparticipant.name", description="%cq.workflow.compat.executor.dynamicparticipant.description")
@Property(name="service.description", value={"%cq.workflow.compat.executor.dynamicparticipant.description"})
@References(value={@Reference(name="ParticipantChooser", cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, referenceInterface=ParticipantChooser.class, policy=ReferencePolicy.DYNAMIC), @Reference(name="ParticipantStepChooser", cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, referenceInterface=ParticipantStepChooser.class, policy=ReferencePolicy.DYNAMIC)})
@Service
public class CQDynamicParticipantExecutor
implements DynamicParticipantExecutor {
protected final Logger log;
@Reference
private WorkflowService cqWorkflowService;
protected List<ParticipantChooser> participantChooser;
protected List<ParticipantStepChooser> participantStepChooser;
public CQDynamicParticipantExecutor() {
this.log = LoggerFactory.getLogger(this.getClass());
this.participantChooser = new CopyOnWriteArrayList<ParticipantChooser>();
this.participantStepChooser = new CopyOnWriteArrayList<ParticipantStepChooser>();
}
public void bindParticipantChooser(ParticipantChooser aParticipantChooser) {
this.participantChooser.add(aParticipantChooser);
}
public void unbindParticipantChooser(ParticipantChooser aParticipantChooser) {
this.participantChooser.remove((Object)aParticipantChooser);
}
public void bindParticipantStepChooser(ParticipantStepChooser aParticipantStepChooser) {
this.participantStepChooser.add(aParticipantStepChooser);
}
public void unbindParticipantStepChooser(ParticipantStepChooser aParticipantStepChooser) {
this.participantStepChooser.remove((Object)aParticipantStepChooser);
}
public boolean canExecute(String aResourceName) {
return this.evaluateExecutable(aResourceName) != null;
}
public String getParticipant(String aResourceName, WorkItem workItem, com.adobe.granite.workflow.WorkflowSession workflowSession, MetaDataMap metaDataMap) {
Object toBeExecuted = this.evaluateExecutable(aResourceName);
try {
if (toBeExecuted != null) {
CQWorkflowSessionWrapper sessionWrapper = new CQWorkflowSessionWrapper(this.cqWorkflowService, workflowSession);
CQWorkItemWrapper workItemWrapper = new CQWorkItemWrapper(workItem);
CQMetaDataMap cqMetaDataMap = new CQMetaDataMap(metaDataMap);
String[] args = this.getArgs(workItem);
if (toBeExecuted instanceof ParticipantStepChooser) {
ParticipantStepChooser chooser = (ParticipantStepChooser)toBeExecuted;
return chooser.getParticipant((com.day.cq.workflow.exec.WorkItem)workItemWrapper, (WorkflowSession)sessionWrapper, (com.day.cq.workflow.metadata.MetaDataMap)cqMetaDataMap);
}
if (toBeExecuted instanceof ParticipantChooser) {
ParticipantChooser chooser = (ParticipantChooser)toBeExecuted;
return chooser.getParticipant((com.day.cq.workflow.exec.WorkItem)workItemWrapper, (WorkflowSession)sessionWrapper, args);
}
}
}
catch (Exception e) {
this.log.error("ParticipantChooser execution resulted in an error: " + e.getMessage(), (Throwable)e);
}
return null;
}
private Object evaluateExecutable(String resource) {
ParticipantStepChooser toBeExecuted = null;
for (ParticipantStepChooser chooser2 : this.participantStepChooser) {
if (!resource.equals(chooser2.getClass().getName())) continue;
toBeExecuted = chooser2;
break;
}
if (toBeExecuted == null) {
for (ParticipantChooser chooser : this.participantChooser) {
if (!resource.equals(chooser.getClass().getName())) continue;
toBeExecuted = chooser;
break;
}
}
return toBeExecuted;
}
protected String[] getArgs(WorkItem item) {
String arguments = (String)item.getNode().getMetaDataMap().get("PROCESS_ARGS", String.class);
if (arguments != null && !arguments.equals("")) {
return arguments.split(",");
}
return new String[0];
}
protected void bindCqWorkflowService(WorkflowService workflowService) {
this.cqWorkflowService = workflowService;
}
protected void unbindCqWorkflowService(WorkflowService workflowService) {
if (this.cqWorkflowService == workflowService) {
this.cqWorkflowService = null;
}
}
}