WorkflowStatusProvider.java
9.64 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.PageInfoProvider
* com.day.cq.workflow.exec.WorkItem
* com.day.cq.workflow.exec.Workflow
* com.day.cq.workflow.exec.WorkflowData
* com.day.cq.workflow.exec.filter.WorkItemFilter
* com.day.cq.workflow.metadata.MetaDataMap
* com.day.cq.workflow.model.WorkflowModel
* com.day.cq.workflow.model.WorkflowNode
* com.day.cq.workflow.status.WorkflowStatus
* com.day.cq.xss.ProtectionContext
* com.day.cq.xss.XSSProtectionException
* com.day.cq.xss.XSSProtectionService
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.jackrabbit.api.JackrabbitSession
* org.apache.jackrabbit.api.security.user.Authorizable
* org.apache.jackrabbit.api.security.user.Group
* org.apache.jackrabbit.api.security.user.UserManager
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.apache.sling.jcr.api.SlingRepository
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.workflow.impl;
import com.day.cq.wcm.api.PageInfoProvider;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.Workflow;
import com.day.cq.workflow.exec.WorkflowData;
import com.day.cq.workflow.exec.filter.WorkItemFilter;
import com.day.cq.workflow.metadata.MetaDataMap;
import com.day.cq.workflow.model.WorkflowModel;
import com.day.cq.workflow.model.WorkflowNode;
import com.day.cq.workflow.status.WorkflowStatus;
import com.day.cq.xss.ProtectionContext;
import com.day.cq.xss.XSSProtectionException;
import com.day.cq.xss.XSSProtectionService;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.api.JackrabbitSession;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
public class WorkflowStatusProvider
implements PageInfoProvider {
private static final Logger log = LoggerFactory.getLogger(WorkflowStatusProvider.class);
@Reference
private SlingRepository repository;
@Reference
private XSSProtectionService xss;
public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
JSONObject workflow = new JSONObject();
WorkflowStatus wfState = (WorkflowStatus)resource.adaptTo(WorkflowStatus.class);
if (wfState != null) {
WorkflowModel wfModel;
Workflow wf;
workflow.put("isRunning", wfState.isInRunningWorkflow(true));
List wfList = wfState.getWorkflows(true);
Workflow workflow2 = wf = wfList.size() > 0 ? (Workflow)wfList.get(0) : null;
if (wf != null && null != (wfModel = wf.getWorkflowModel())) {
workflow.put("id", (Object)wf.getId());
workflow.put("state", (Object)wf.getState());
workflow.put("model", (Object)new JSONObject().put("title", (Object)wfModel.getTitle()));
String workflowTitle = (String)wf.getWorkflowData().getMetaDataMap().get("workflowTitle", String.class);
if (workflowTitle != null) {
workflow.put("title", (Object)workflowTitle);
}
JSONArray workitems = new JSONArray();
if (wf.getWorkItems().size() > 0) {
Session userSession = (Session)request.getResourceResolver().adaptTo(Session.class);
if (userSession instanceof JackrabbitSession) {
List items = wf.getWorkItems((WorkItemFilter)new UserFilter((JackrabbitSession)userSession));
for (WorkItem wi : items) {
WorkflowNode wn = wi.getNode();
if (!wn.getType().equals("PARTICIPANT") && !wn.getType().equals("DYNAMIC_PARTICIPANT")) continue;
JSONObject obj = new JSONObject();
obj.put("id", (Object)wi.getId());
obj.put("title", (Object)wn.getTitle());
if (this.xss != null) {
try {
obj.put("title_xss", (Object)this.xss.protectForContext(ProtectionContext.PLAIN_HTML_CONTENT, wn.getTitle()));
}
catch (XSSProtectionException e) {
log.warn("Unable to write protected value for workflow node title {}", (Object)wn.getTitle());
}
}
obj.put("description", (Object)wn.getDescription());
if (this.xss != null) {
try {
obj.put("description_xss", (Object)this.xss.protectForContext(ProtectionContext.PLAIN_HTML_CONTENT, wn.getDescription()));
}
catch (XSSProtectionException e) {
log.warn("Unable to write protected value for workflow node description {}", (Object)wn.getDescription());
}
}
obj.put("startTime", wi.getTimeStarted().getTime());
MetaDataMap metaMap = wn.getMetaDataMap();
String comment = (String)metaMap.get("comment", String.class);
obj.put("comment", (Object)(null == comment ? "" : comment));
String dialogPath = (String)metaMap.get("DIALOG_PATH", String.class);
obj.put("dialog_path", (Object)(null == dialogPath ? "" : dialogPath));
workitems.put((Object)obj);
}
} else {
log.warn("Unable to obtain JackrabbitSession at path {}", (Object)resource.getPath());
}
}
workflow.put("workitems", (Object)workitems);
}
}
info.put("workflowInfo", (Object)workflow);
}
protected void activate(ComponentContext context) {
}
protected void deactivate(ComponentContext context) {
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
protected void bindXss(XSSProtectionService xSSProtectionService) {
this.xss = xSSProtectionService;
}
protected void unbindXss(XSSProtectionService xSSProtectionService) {
if (this.xss == xSSProtectionService) {
this.xss = null;
}
}
public class UserFilter
implements WorkItemFilter {
private JackrabbitSession jackrabbitSession;
private List<Authorizable> authList;
public UserFilter(JackrabbitSession jackrabbitSession) {
this.authList = null;
this.jackrabbitSession = jackrabbitSession;
}
public boolean doInclude(WorkItem workItem) {
String assignee = workItem.getCurrentAssignee();
if (assignee != null) {
try {
for (Authorizable auth : this.getAuthorizables()) {
if (!assignee.equals(auth.getID())) continue;
return true;
}
}
catch (RepositoryException e) {
log.error(e.getMessage(), (Throwable)e);
}
}
return false;
}
private List<Authorizable> getAuthorizables() throws RepositoryException {
if (this.authList == null) {
ArrayList<Authorizable> auths = new ArrayList<Authorizable>();
Authorizable user = this.jackrabbitSession.getUserManager().getAuthorizable(this.jackrabbitSession.getUserID());
auths.add(user);
this.getGroups(user, auths);
this.authList = auths;
}
return this.authList;
}
private void getGroups(Authorizable authorizable, List<Authorizable> auths) throws RepositoryException {
Iterator groups = authorizable.memberOf();
while (groups.hasNext()) {
Group group = (Group)groups.next();
auths.add((Authorizable)group);
this.getGroups((Authorizable)group, auths);
}
}
}
}