WorkflowConfigurationHandler.java
3.08 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Property
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Service
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemfd.watchfolder.workflow;
import com.adobe.aemfd.watchfolder.config.WatchFolderConfiguration;
import com.adobe.aemfd.watchfolder.spi.ConfigurationHandler;
import com.adobe.aemfd.watchfolder.util.JcrUtil;
import com.adobe.aemfd.watchfolder.workflow.VariableInfo;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.Property;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(immediate=1)
@Service(value={WorkflowConfigurationHandler.class})
public class WorkflowConfigurationHandler
implements ConfigurationHandler {
private static final String WF_VAR_PREFIX = "workflow.var.";
private static final String WF_VAR_MAP = "workflow.variables";
private static final Logger logger = LoggerFactory.getLogger(WorkflowConfigurationHandler.class);
@Override
public boolean enhanceConfiguration(WatchFolderConfiguration config, Property p) throws Exception {
String pName = p.getName();
if (!pName.startsWith("workflow.var.")) {
return false;
}
try {
Object varValue;
HashMap<String, VariableInfo> vars = (HashMap<String, VariableInfo>)config.getCustomData("workflow.variables");
if (vars == null) {
vars = new HashMap<String, VariableInfo>();
config.setCustomData("workflow.variables", vars);
}
String varName = pName.substring("workflow.var.".length());
VariableInfo vi = new VariableInfo();
vi.name = varName;
vi.propertyType = p.getType();
vi.isMultiple = p.isMultiple();
vi.value = varValue = JcrUtil.getPropertyValue(p, null, false);
vars.put(varName, vi);
logger.info("Set workflow variable " + varName + " to value " + JcrUtil.toString(varValue));
}
catch (Exception e) {
logger.warn("Error handling workflow variable " + pName + ", error = '" + e + "', skipping...");
}
return true;
}
Map<String, VariableInfo> getVariableDefinitions(WatchFolderConfiguration config) {
Map result = (Map)config.getCustomData("workflow.variables");
return result == null ? Collections.emptyMap() : result;
}
VariableInfo getVariableDefinition(WatchFolderConfiguration config, String varName) throws Exception {
Map<String, VariableInfo> vars = this.getVariableDefinitions(config);
VariableInfo vi = vars.get(varName);
if (vi == null) {
throw new Exception("No workflow variable with name " + varName + " defined for watch-folder " + config.getId());
}
return vi;
}
}