ProcessAssembler.java
7.54 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.workflow.WorkflowException
* com.day.cq.workflow.WorkflowSession
* com.day.cq.workflow.exec.JavaProcess
* com.day.cq.workflow.exec.JavaProcessExt
* com.day.cq.workflow.exec.WorkItem
* com.day.cq.workflow.exec.WorkflowProcess
* com.day.cq.workflow.metadata.MetaDataMap
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.osgi.framework.BundleContext
* org.osgi.framework.InvalidSyntaxException
* org.osgi.framework.ServiceReference
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.workflow.impl.process;
import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.JavaProcess;
import com.day.cq.workflow.exec.JavaProcessExt;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.WorkflowProcess;
import com.day.cq.workflow.impl.metadata.CQMetaDataMap;
import com.day.cq.workflow.metadata.MetaDataMap;
import java.util.ArrayList;
import java.util.List;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service(value={WorkflowProcess.class})
@Properties(value={@Property(name="service.description", value={"Workflow Process Assembler"}), @Property(name="process.label", value={"Process Assembler"})})
public class ProcessAssembler
implements WorkflowProcess {
protected final Logger log = LoggerFactory.getLogger(ProcessAssembler.class);
private ComponentContext context;
public void execute(WorkItem item, WorkflowSession session, MetaDataMap metaData) throws WorkflowException {
try {
String[] args = this.buildArguments(metaData);
List<ProcessConfiguration> processes = this.getProcesses(args);
long millies = System.currentTimeMillis();
this.log.info(item.getId() + ":Starting Process...");
for (ProcessConfiguration process : processes) {
Object proc = this.getProcess(process.getName());
if (proc != null) {
this.log.info(item.getId() + ": Executing " + proc.toString());
if (proc instanceof WorkflowProcess) {
CQMetaDataMap metaDataMap = new CQMetaDataMap();
metaDataMap.put((Object)Arguments.PROCESS_ARGS.name(), (Object)process.getProcessArgs());
((WorkflowProcess)proc).execute(item, session, (MetaDataMap)metaDataMap);
continue;
}
if (proc instanceof JavaProcessExt) {
((JavaProcessExt)proc).execute(item, session, process.getArgs());
continue;
}
((JavaProcess)proc).execute(item, session);
continue;
}
this.log.warn("No process found: " + process.toString());
}
this.log.info(item.getId() + ":Total Processing time is:" + (System.currentTimeMillis() - millies) + "ms");
}
catch (Exception e) {
throw new WorkflowException((Throwable)e);
}
}
public void execute(WorkItem item, WorkflowSession session, String[] args) throws Exception {
}
protected Object getProcess(String name) {
try {
WorkflowProcess process;
int i;
ServiceReference[] refs = this.context.getBundleContext().getAllServiceReferences(WorkflowProcess.class.getName(), null);
if (refs != null) {
for (i = 0; i < refs.length; ++i) {
process = (WorkflowProcess)this.context.getBundleContext().getService(refs[i]);
if (process == null || !process.getClass().getName().equals(name)) continue;
return process;
}
}
if ((refs = this.context.getBundleContext().getAllServiceReferences(JavaProcess.class.getName(), null)) != null) {
for (i = 0; i < refs.length; ++i) {
process = (JavaProcess)this.context.getBundleContext().getService(refs[i]);
if (process == null || !process.getClass().getName().equals(name)) continue;
return process;
}
}
if ((refs = this.context.getBundleContext().getAllServiceReferences(JavaProcessExt.class.getName(), null)) != null) {
for (i = 0; i < refs.length; ++i) {
process = (JavaProcessExt)this.context.getBundleContext().getService(refs[i]);
if (process == null || !process.getClass().getName().equals(name)) continue;
return process;
}
}
}
catch (InvalidSyntaxException e) {
// empty catch block
}
return null;
}
protected List<ProcessConfiguration> getProcesses(String[] args) {
ArrayList<ProcessConfiguration> procs = new ArrayList<ProcessConfiguration>();
if (args != null && args.length > 0) {
for (String arg : args) {
String[] splits = arg.split("::");
String name = splits[0];
String[] procArgs = splits.length > 1 ? splits[1].split(";") : new String[]{};
procs.add(new ProcessConfiguration(name, procArgs));
}
}
return procs;
}
@Activate
protected void activate(ComponentContext context) {
this.context = context;
}
public String[] buildArguments(MetaDataMap metaData) {
String processArgs = (String)metaData.get(Arguments.PROCESS_ARGS.name(), String.class);
if (processArgs != null && !processArgs.equals("")) {
return processArgs.split(",");
}
String[] processes = (String[])metaData.get(Arguments.PROCESSES.name(), String[].class);
return processes;
}
public class ProcessConfiguration {
String name;
String[] args;
public ProcessConfiguration(String name, String[] args) {
this.name = name;
this.args = args;
}
public String getName() {
return this.name;
}
public String[] getArgs() {
return this.args;
}
public String getProcessArgs() {
StringBuilder builder = new StringBuilder();
if (this.args != null && this.args.length > 0) {
for (int i = 0; i < this.args.length; ++i) {
builder.append(this.args[i]);
if (i >= this.args.length - 1) continue;
builder.append(",");
}
}
return builder.toString();
}
public String toString() {
return "name: " + this.name + " args " + this.args;
}
}
public static enum Arguments {
PROCESS_ARGS,
PROCESSES;
private Arguments() {
}
}
}