WorkflowPackageInfoProvider.java
8.51 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.wcm.api.Page
* com.day.cq.wcm.api.PageInfoProvider
* com.day.cq.wcm.api.PageManager
* com.day.cq.workflow.PayloadMap
* com.day.cq.workflow.collection.ResourceCollection
* com.day.cq.workflow.collection.ResourceCollectionManager
* com.day.jcr.vault.fs.api.Filter
* com.day.jcr.vault.fs.api.FilterSet
* com.day.jcr.vault.fs.api.PathFilter
* com.day.jcr.vault.fs.api.PathFilterSet
* com.day.jcr.vault.fs.config.DefaultWorkspaceFilter
* com.day.jcr.vault.fs.filter.DefaultPathFilter
* javax.jcr.Node
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.PropertyUnbounded
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.Service
* 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.commons.osgi.OsgiUtil
* 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.Page;
import com.day.cq.wcm.api.PageInfoProvider;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.workflow.PayloadMap;
import com.day.cq.workflow.collection.ResourceCollection;
import com.day.cq.workflow.collection.ResourceCollectionManager;
import com.day.jcr.vault.fs.api.Filter;
import com.day.jcr.vault.fs.api.FilterSet;
import com.day.jcr.vault.fs.api.PathFilter;
import com.day.jcr.vault.fs.api.PathFilterSet;
import com.day.jcr.vault.fs.config.DefaultWorkspaceFilter;
import com.day.jcr.vault.fs.filter.DefaultPathFilter;
import java.util.Dictionary;
import java.util.List;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
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.commons.osgi.OsgiUtil;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=1, label="%workflowpackageinfoprovider.name", description="%workflowpackageinfoprovider.description")
@Service
public class WorkflowPackageInfoProvider
implements PageInfoProvider {
private static final Logger log = LoggerFactory.getLogger(WorkflowPackageInfoProvider.class);
@Reference(policy=ReferencePolicy.STATIC)
private SlingRepository repository;
@Reference(policy=ReferencePolicy.STATIC)
private ResourceCollectionManager resourceCollectionManager;
@Reference(policy=ReferencePolicy.STATIC)
private PayloadMap payloadMap;
@Property(value={}, unbounded=PropertyUnbounded.ARRAY)
private static final String SCR_PROP_NAME_FILTER = "workflowpackageinfoprovider.filter";
@Property(value={"/"})
private static final String SCR_PROP_NAME_FILTERROOT = "workflowpackageinfoprovider.filter.rootpath";
private DefaultWorkspaceFilter filter;
public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
JSONObject workflowPackage = new JSONObject();
ResourceResolver resourceResolver = resource.getResourceResolver();
PageManager pageManager = (PageManager)resourceResolver.adaptTo(PageManager.class);
JSONArray selectedWorkflowPackages = new JSONArray();
JSONArray runningSelectedWorkflowPackages = new JSONArray();
List wpList = this.resourceCollectionManager.getCollections((Session)resourceResolver.adaptTo(Session.class));
JSONArray wpArray = new JSONArray();
if (wpList != null) {
int i = 0;
for (ResourceCollection wp : wpList) {
String wpPath = wp.getPath();
if (!this.filter.contains(wpPath)) continue;
try {
Page wpPage = pageManager.getPage(wpPath);
List instances = this.payloadMap.getWorkflowInstances(wpPath, false);
boolean isInCurrentWorkflowPackage = false;
for (Node wpContentNode : wp.list(new String[]{"cq:Page"})) {
if (!wpContentNode.getPath().equals(resource.getPath())) continue;
isInCurrentWorkflowPackage = true;
break;
}
JSONObject obj = new JSONObject();
obj.put("path", (Object)wpPath);
obj.put("title", (Object)wpPage.getTitle());
obj.put("isInWorkflowPackage", isInCurrentWorkflowPackage);
boolean isRunning = instances.size() > 0;
obj.put("isRunning", isRunning);
wpArray.put((Object)obj);
if (isInCurrentWorkflowPackage) {
selectedWorkflowPackages.put(i);
if (isRunning) {
runningSelectedWorkflowPackages.put(i);
}
}
++i;
}
catch (RepositoryException e) {
log.warn("Unable to get information for workflow package [{}]", (Object)wpPath, (Object)e);
}
}
}
workflowPackage.put("workflowPackages", (Object)wpArray);
workflowPackage.put("selectedWorkflowPackages", (Object)selectedWorkflowPackages);
workflowPackage.put("runningSelectedWorkflowPackages", (Object)runningSelectedWorkflowPackages);
info.put("workflowPackageInfo", (Object)workflowPackage);
}
protected void activate(ComponentContext context) {
this.filter = new DefaultWorkspaceFilter();
String filterRootPath = "/";
if (context.getProperties().get("workflowpackageinfoprovider.filter.rootpath") != null) {
filterRootPath = (String)context.getProperties().get("workflowpackageinfoprovider.filter.rootpath");
}
PathFilterSet set = new PathFilterSet(filterRootPath);
set.addInclude((Filter)PathFilter.ALL);
Object filterProp = context.getProperties().get("workflowpackageinfoprovider.filter");
if (filterProp != null) {
String[] filterPaths;
for (String filterPath : filterPaths = OsgiUtil.toStringArray(filterProp)) {
if (filterPath.startsWith("-")) {
set.addExclude((Filter)new DefaultPathFilter(filterPath.substring(1)));
continue;
}
if (filterPath.startsWith("+")) {
filterPath = filterPath.substring(1);
}
set.addInclude((Filter)new DefaultPathFilter(filterPath));
}
}
this.filter.add(set);
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
protected void bindResourceCollectionManager(ResourceCollectionManager resourceCollectionManager) {
this.resourceCollectionManager = resourceCollectionManager;
}
protected void unbindResourceCollectionManager(ResourceCollectionManager resourceCollectionManager) {
if (this.resourceCollectionManager == resourceCollectionManager) {
this.resourceCollectionManager = null;
}
}
protected void bindPayloadMap(PayloadMap payloadMap) {
this.payloadMap = payloadMap;
}
protected void unbindPayloadMap(PayloadMap payloadMap) {
if (this.payloadMap == payloadMap) {
this.payloadMap = null;
}
}
}