ActionManagerBridge.java
14.8 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.api.msm.ActionConfig
* com.day.cq.wcm.api.msm.ActionManager
* com.day.cq.wcm.api.msm.LiveAction
* com.day.cq.wcm.api.msm.LiveCopy
* com.day.cq.wcm.api.msm.LiveRelationship
* com.day.cq.wcm.api.msm.LiveRelationshipManager
* com.day.cq.wcm.api.msm.RolloutManager
* com.day.cq.wcm.api.msm.RolloutManager$Trigger
* com.day.cq.wcm.msm.api.ActionConfig
* com.day.cq.wcm.msm.api.ActionManager
* 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.api.RolloutManager
* com.day.cq.wcm.msm.api.RolloutManager$Trigger
* javax.jcr.Node
* javax.jcr.RepositoryException
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* 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.JSONException
* org.apache.sling.commons.json.io.JSONWriter
* org.osgi.framework.BundleContext
* org.osgi.framework.ServiceRegistration
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.msm.impl.compat;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.api.msm.LiveCopy;
import com.day.cq.wcm.api.msm.LiveRelationship;
import com.day.cq.wcm.api.msm.LiveRelationshipManager;
import com.day.cq.wcm.api.msm.RolloutManager;
import com.day.cq.wcm.msm.api.ActionConfig;
import com.day.cq.wcm.msm.api.ActionManager;
import com.day.cq.wcm.msm.api.LiveAction;
import com.day.cq.wcm.msm.api.LiveStatus;
import com.day.cq.wcm.msm.api.RolloutManager;
import com.day.cq.wcm.msm.impl.compat.ActionConfigAdaptor;
import com.day.cq.wcm.msm.impl.compat.LiveRelationshipManagerBridge;
import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
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.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
public class ActionManagerBridge
implements com.day.cq.wcm.api.msm.ActionManager {
@Reference
private ActionManager actionManager = null;
@Reference(referenceInterface=LiveRelationshipManager.class, target="(service.pid=com.day.cq.wcm.msm.impl.compat.LiveRelationshipManagerBridge)")
private LiveRelationshipManagerBridge liveRelationshipMgr;
private Logger log = LoggerFactory.getLogger(ActionManagerBridge.class);
private ComponentContext componentContext;
private final Map<String, ServiceRegistration> registered = new HashMap<String, ServiceRegistration>();
@Activate
protected void activate(ComponentContext context) {
this.componentContext = context;
}
protected void bindLiveRelationshipMgr(LiveRelationshipManager relationMgr) {
this.liveRelationshipMgr = (LiveRelationshipManagerBridge)relationMgr;
}
public void executeActions(ResourceResolver resolver, LiveRelationship relation, boolean autoSave) throws WCMException {
this.executeActions(resolver, relation, autoSave, false);
}
public void executeActions(ResourceResolver resolver, LiveRelationship relation, boolean autoSave, boolean isResetRollout) throws WCMException {
com.day.cq.wcm.msm.api.LiveRelationship rel = this.liveRelationshipMgr.adapt(relation, resolver);
if (rel != null) {
RolloutManager.Trigger tr3 = relation.getLiveCopy().getTrigger();
RolloutManager.Trigger trigger = tr3 == null ? null : RolloutManager.Trigger.fromName((String)tr3.name());
this.actionManager.executeActions(resolver, rel, trigger, autoSave, isResetRollout);
} else {
this.log.debug("Didn't find Relation for {} to {}: no action executed", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
}
}
public void executeAction(ResourceResolver resolver, LiveRelationship relation, com.day.cq.wcm.api.msm.ActionConfig config, boolean autoSave) throws WCMException {
this.executeAction(resolver, relation, config, autoSave, false);
}
public void executeAction(ResourceResolver resolver, LiveRelationship relation, final com.day.cq.wcm.api.msm.ActionConfig config, boolean autoSave, boolean isResetRollout) throws WCMException {
com.day.cq.wcm.msm.api.LiveRelationship rel = this.liveRelationshipMgr.adapt(relation, resolver);
if (rel != null) {
ActionConfig newActionCfg = config == null ? null : new ActionConfig(){
public String getName() {
return config.getName();
}
public String getParameterName() {
return config.getParameterName();
}
public Map<String, String> getProperties() {
return config.getProperties();
}
public String getProperty(String propertyName) {
return config.getProperty(propertyName);
}
public boolean hasProperty(String propertyName) {
return config.hasProperty(propertyName);
}
public int getRank() {
return config.getRank();
}
public int compareTo(ActionConfig o) {
int cmp = this.getName().compareTo(config.getName());
return cmp != 0 ? this.getRank() - config.getRank() : 0;
}
public void write(JSONWriter out) throws JSONException {
config.write(out);
}
};
this.actionManager.executeAction(resolver, rel, newActionCfg, autoSave, isResetRollout);
} else {
this.log.debug("Didn't find Relation for {} to {}: no action executed", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
}
}
public Set<com.day.cq.wcm.api.msm.ActionConfig> getActionsConfig(Node node, String resourceNodeType, String actionNodeName, boolean inherited) throws RepositoryException {
this.log.warn("Parameter resourceNodeType and actionNodeName are no longer supported, defaults are used {} resp {}", (Object)"cq:LiveSync", (Object)"cq:LiveSyncAction");
if (node == null || node.getParent() == null) {
return null;
}
HashSet<com.day.cq.wcm.api.msm.ActionConfig> ret = new HashSet<com.day.cq.wcm.api.msm.ActionConfig>();
for (ActionConfig conf : this.actionManager.getActionsConfig(node.getParent())) {
ret.add(new ActionConfigAdaptor(conf, inherited));
}
return ret;
}
public Set<com.day.cq.wcm.api.msm.ActionConfig> getActionsConfig(Resource resource, String resourceNodeType, String actionNodeName, boolean inherited) throws RepositoryException {
return this.getActionsConfig((Node)resource.adaptTo(Node.class), resourceNodeType, actionNodeName, inherited);
}
public com.day.cq.wcm.api.msm.ActionConfig getActionConfig(Node root, boolean inherited) throws RepositoryException {
if (root == null || root.getParent() == null) {
return null;
}
Set ret = this.actionManager.getActionsConfig(root.getParent());
for (ActionConfig conf : ret) {
if (!conf.getName().equals(root.getName())) continue;
this.log.debug("Found action configuration for Action {} at Node {}", (Object)conf.getName(), (Object)root.getName());
return new ActionConfigAdaptor(conf, false);
}
return null;
}
public com.day.cq.wcm.api.msm.ActionConfig getActionConfig(Resource resource, boolean inherited) throws RepositoryException {
return this.getActionConfig((Node)resource.adaptTo(Node.class), inherited);
}
public boolean isActionUpdated(SlingHttpServletRequest request, LiveRelationship relation) throws WCMException {
try {
Set configs = relation.getActions();
HashMap<String, String> requestParameters = new HashMap<String, String>();
HashSet<String> requestEmptyParameters = new HashSet<String>();
for (LiveAction action : this.actionManager.getRegistredActions().values()) {
String[] params;
String paramName = action.getParameterName();
for (String param : params = action.getPropertiesNames()) {
String value = request.getParameter(paramName + "/" + param);
if (value == null) continue;
if (!value.equals("")) {
requestParameters.put(paramName + "/" + param, value);
continue;
}
requestEmptyParameters.add(paramName + "/" + param);
}
}
for (com.day.cq.wcm.api.msm.ActionConfig config : configs) {
String configuredParam = config.getParameterName();
Map properties = config.getProperties();
if (properties == null) continue;
for (String name : properties.keySet()) {
String value = (String)properties.get(name);
if (requestParameters.containsKey(configuredParam + "/" + name)) {
String postedValue = (String)requestParameters.get(configuredParam + "/" + name);
if (!postedValue.equalsIgnoreCase(value)) {
return true;
}
requestParameters.remove(configuredParam + "/" + name);
continue;
}
if (!requestEmptyParameters.contains(configuredParam + "/" + name) || value.equals("")) continue;
return true;
}
}
return !requestParameters.isEmpty();
}
catch (Exception e) {
throw new WCMException("Cannot write config from request", (Throwable)e);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void registerAcion(com.day.cq.wcm.api.msm.LiveAction action) {
LiveActionAdaptor adapted = new LiveActionAdaptor(action);
Map<String, ServiceRegistration> map = this.registered;
synchronized (map) {
this.registered.put(action.getName(), this.componentContext.getBundleContext().registerService(LiveAction.class.getName(), (Object)adapted, (Dictionary)new Properties()));
}
this.log.info("Registered LiveAction for {} that implements deprecated API", (Object)action.getName());
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void unregisterAcion(com.day.cq.wcm.api.msm.LiveAction action) {
Map<String, ServiceRegistration> map = this.registered;
synchronized (map) {
ServiceRegistration reg = this.registered.remove(action.getName());
if (reg != null) {
reg.unregister();
}
}
}
public void writeConfigFromRequest(SlingHttpServletRequest request, Node actionsNode) throws WCMException {
throw new UnsupportedOperationException("Config cant be written in CQ 5.3 format any longer");
}
protected void bindActionManager(ActionManager actionManager) {
this.actionManager = actionManager;
}
protected void unbindActionManager(ActionManager actionManager) {
if (this.actionManager == actionManager) {
this.actionManager = null;
}
}
protected void unbindLiveRelationshipMgr(LiveRelationshipManager liveRelationshipManager) {
if (this.liveRelationshipMgr == liveRelationshipManager) {
this.liveRelationshipMgr = null;
}
}
class LiveActionAdaptor
implements LiveAction {
private final com.day.cq.wcm.api.msm.LiveAction delegatee;
LiveActionAdaptor(com.day.cq.wcm.api.msm.LiveAction action) {
this.delegatee = action;
}
public String getTitle() {
return this.getName();
}
public void write(JSONWriter out) throws JSONException {
}
public String getName() {
return this.delegatee.getName();
}
public void execute(Resource source, Resource target, com.day.cq.wcm.msm.api.LiveRelationship relation, boolean autoSave, boolean isResetRollout) throws WCMException {
this.execute(source.getResourceResolver(), relation, null, autoSave, isResetRollout);
}
public int getRank() {
return this.delegatee.getRank();
}
public String[] getPropertiesNames() {
return this.delegatee.getPropertiesNames();
}
public String getParameterName() {
return this.delegatee.getParameterName();
}
public void execute(ResourceResolver resolver, com.day.cq.wcm.msm.api.LiveRelationship relation, ActionConfig config, boolean autoSave) throws WCMException {
this.execute(resolver, relation, config, autoSave, false);
}
public void execute(ResourceResolver resolver, com.day.cq.wcm.msm.api.LiveRelationship relation, ActionConfig config, boolean autoSave, boolean isResetRollout) throws WCMException {
Iterator<LiveRelationship> rels;
LiveRelationship rel = null;
if (relation.getStatus().isTargetExisting()) {
rel = ActionManagerBridge.this.liveRelationshipMgr.getLiveRelationship(resolver.getResource(relation.getTargetPath()), false);
} else if (relation.getStatus().isSourceExisting() && (rels = ActionManagerBridge.this.liveRelationshipMgr.getLiveRelationships(resolver.resolve(relation.getSourcePath()), null, new String[]{relation.getTargetPath()}, false).iterator()).hasNext()) {
rel = rels.next();
}
this.delegatee.execute(resolver, rel, (com.day.cq.wcm.api.msm.ActionConfig)new ActionConfigAdaptor(config, false), autoSave, isResetRollout);
}
}
}