WorkflowActionFactory.java
6.71 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.LiveAction
* com.day.cq.wcm.msm.api.LiveRelationship
* com.day.cq.wcm.msm.api.LiveStatus
* com.day.cq.wcm.msm.commons.BaseAction
* com.day.cq.wcm.msm.commons.BaseActionFactory
* com.day.cq.workflow.WorkflowException
* com.day.cq.workflow.WorkflowService
* com.day.cq.workflow.WorkflowSession
* com.day.cq.workflow.exec.Workflow
* com.day.cq.workflow.exec.WorkflowData
* com.day.cq.workflow.model.WorkflowModel
* javax.jcr.Node
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Modified
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.msm.impl.actions;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveAction;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.LiveStatus;
import com.day.cq.wcm.msm.commons.BaseAction;
import com.day.cq.wcm.msm.commons.BaseActionFactory;
import com.day.cq.wcm.msm.impl.Utils;
import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowService;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.Workflow;
import com.day.cq.workflow.exec.WorkflowData;
import com.day.cq.workflow.model.WorkflowModel;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Modified;
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.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service
public class WorkflowActionFactory
extends BaseActionFactory<BaseAction> {
public static final String WF_DATA_SRC_PATH = "srcPath";
public static final String ACTION_PARAM_TARGET = "target";
@Deprecated
@Property(name="cq.wcm.msm.action.rank")
private static final int RANK = 701;
@Deprecated
@Property(name="cq.wcm.msm.action.title")
private static final String TITLE = "Start target workflow";
@Deprecated
@Property(name="cq.wcm.msm.action.parameter")
private static final String PARAMETER = "msm:actionWorkflow";
@Deprecated
@Property(name="cq.wcm.msm.action.properties")
private static final String[] PROPS = new String[]{"target"};
private static final Logger log = LoggerFactory.getLogger(WorkflowActionFactory.class);
@Property(name="liveActionName")
private static final String[] LIVE_ACTION_NAME = new String[]{WorkflowActionFactory.class.getSimpleName(), "workflow"};
@Reference
private WorkflowService workflowService = null;
public String createsAction() {
return LIVE_ACTION_NAME[0];
}
protected WorkflowAction newActionInstance(ValueMap config) {
if (config != null && config.containsKey((Object)"target")) {
return new WorkflowAction(config, this, this.workflowService);
}
log.debug("Config not sufficient for Action, need Workflow Model ID");
return null;
}
@Activate
@Modified
protected void activate(ComponentContext context) {
}
protected void bindWorkflowService(WorkflowService workflowService) {
this.workflowService = workflowService;
}
protected void unbindWorkflowService(WorkflowService workflowService) {
if (this.workflowService == workflowService) {
this.workflowService = null;
}
}
private static final class WorkflowAction
extends BaseAction {
private final WorkflowService workflowService;
private final String workflowModelID;
private WorkflowModel model;
private WorkflowAction(ValueMap config, BaseActionFactory<BaseAction> factory, WorkflowService workflowService) {
super(config, factory);
this.workflowService = workflowService;
this.workflowModelID = (String)config.get("target", String.class);
}
protected boolean handles(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws WCMException, RepositoryException {
if (!relation.getStatus().isPage()) {
log.debug("Relation is not a Page {}: do not handle", (Object)relation.getTargetPath());
return false;
}
Node masterNode = (Node)source.adaptTo(Node.class);
if (masterNode != null && this.workflowService != null) {
try {
WorkflowSession wfSession = this.workflowService.getWorkflowSession(masterNode.getSession());
this.model = wfSession.getModel(this.workflowModelID);
if (this.model == null) {
log.debug("Configured Workflow-Model {} does not exist: do not handle", (Object)this.workflowModelID);
return false;
}
return true;
}
catch (WorkflowException e) {
throw new WCMException((Throwable)e);
}
}
return false;
}
protected void doExecute(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws RepositoryException, WCMException {
assert (source.adaptTo(Node.class) != null && this.workflowService != null && this.model != null);
Node masterNode = (Node)source.adaptTo(Node.class);
try {
WorkflowSession wfSession = this.workflowService.getWorkflowSession(masterNode.getSession());
WorkflowData data = wfSession.newWorkflowData("JCR_PATH", (Object)Utils.getPagePath(relation.getTargetPath()));
HashMap<String, String> metaData = new HashMap<String, String>();
metaData.put("srcPath", Utils.getPagePath(source.getPath()));
wfSession.startWorkflow(this.model, data, metaData);
}
catch (WorkflowException e) {
throw new WCMException((Throwable)e);
}
}
}
}