LaunchLiveActionBase.java
8.72 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.ActionConfig
* com.day.cq.wcm.msm.api.LiveAction
* com.day.cq.wcm.msm.api.LiveRelationship
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.Property
* javax.jcr.PropertyIterator
* javax.jcr.RepositoryException
* javax.jcr.nodetype.NodeDefinition
* javax.jcr.nodetype.NodeType
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.wrappers.ValueMapDecorator
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.io.JSONWriter
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.wcm.launches.impl.msm.utils;
import com.adobe.cq.wcm.launches.impl.msm.utils.LaunchExclusionConfig;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.ActionConfig;
import com.day.cq.wcm.msm.api.LiveAction;
import com.day.cq.wcm.msm.api.LiveRelationship;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class LaunchLiveActionBase
implements LiveAction {
public static final String PROP_TITLE = "cq.wcm.msm.action.title";
public static final String PROP_RANK = "cq.wcm.msm.action.rank";
public static final String PROP_PROPS = "cq.wcm.msm.action.properties";
public static final String PROP_PARAMETER = "cq.wcm.msm.action.parameter";
public static final String ACTION_TYPE = "actiontype";
private final ValueMap config;
private final LaunchExclusionConfig exclusionConfig;
protected static final Logger log = LoggerFactory.getLogger(LaunchLiveActionBase.class);
protected LaunchLiveActionBase(ValueMap config, LaunchExclusionConfig exclusionConfig) {
this.config = config;
this.exclusionConfig = exclusionConfig != null ? exclusionConfig : LaunchExclusionConfig.EMPTY_EXCLUSION_CONFIG;
}
protected ValueMap getConfig() {
return this.config;
}
protected LaunchExclusionConfig getExclusionConfig() {
return this.exclusionConfig;
}
protected boolean isPageLevel(Node node) throws RepositoryException {
return node.isNodeType("cq:Page") || node.getParent().isNodeType("cq:Page");
}
protected boolean isExcludedNodeType(NodeType nodeType) {
return this.exclusionConfig != null && this.exclusionConfig.matchExcludedNodeType(nodeType.getName());
}
protected boolean isExcludedProperty(Property property) throws RepositoryException {
return this.exclusionConfig != null && (this.isPageLevel(property.getParent()) ? this.exclusionConfig.matchExcludedPageProperty(property.getName()) : this.exclusionConfig.matchExcludedParagraphItem(property.getName()));
}
protected boolean isExcludedNode(Node node) throws RepositoryException {
if (node == null || node.getDefinition().isProtected()) {
return true;
}
if (this.exclusionConfig.matchExcludedNodeType(node.getPrimaryNodeType().getName())) {
return true;
}
for (NodeType mixin : node.getMixinNodeTypes()) {
if (!this.exclusionConfig.matchExcludedNodeType(mixin.getName())) continue;
return true;
}
return false;
}
protected void applyFilters(Node node, boolean deep) throws RepositoryException {
String name = node.getName();
String primaryNodeType = node.getPrimaryNodeType().getName();
boolean pageNameIsExcluded = this.exclusionConfig.matchExcludedParagraphItem(name);
boolean pageTypeIsExcluded = this.exclusionConfig.matchExcludedNodeType(primaryNodeType);
if (pageNameIsExcluded || pageTypeIsExcluded) {
node.remove();
return;
}
for (NodeType mixin : node.getMixinNodeTypes()) {
if (!this.exclusionConfig.matchExcludedNodeType(mixin.getName())) continue;
node.removeMixin(mixin.getName());
}
boolean isPage = node.isNodeType("cq:Page");
PropertyIterator properties = node.getProperties();
while (properties.hasNext()) {
Property property = properties.nextProperty();
String propertyName = property.getName();
boolean bl = isPage ? this.exclusionConfig.matchExcludedParagraphItem(propertyName) || this.exclusionConfig.matchExcludedPageProperty(propertyName) : this.exclusionConfig.matchExcludedParagraphItem(propertyName);
boolean propertyIsExcluded = bl;
if (!propertyIsExcluded) continue;
property.remove();
}
if (node.hasNode("jcr:content")) {
Node content = node.getNode("jcr:content");
this.applyFilters(content, true);
}
if (deep) {
NodeIterator children = node.getNodes();
while (children.hasNext()) {
Node child = children.nextNode();
if ("jcr:content".equals(child.getName())) continue;
this.applyFilters(child, deep);
}
}
}
protected abstract LiveAction newInstance(ValueMap var1);
public String getName() {
return this.getClass().getSimpleName();
}
protected abstract boolean handles(Resource var1, Resource var2, LiveRelationship var3, boolean var4) throws RepositoryException, WCMException;
protected abstract void doExecute(Resource var1, Resource var2, LiveRelationship var3, boolean var4, boolean var5) throws RepositoryException, WCMException;
public void execute(Resource source, Resource target, LiveRelationship relation, boolean autoSave, boolean isResetRollout) throws WCMException {
try {
if (this.handles(source, target, relation, isResetRollout)) {
this.doExecute(source, target, relation, autoSave, isResetRollout);
} else {
log.debug("{} did not act on request to roll-out {} to {}: but precondition was not met", (Object[])new String[]{this.getName(), relation.getSourcePath(), relation.getTargetPath()});
}
}
catch (RepositoryException e) {
throw new WCMException((Throwable)e);
}
}
public void execute(ResourceResolver resolver, LiveRelationship relation, ActionConfig config, boolean autoSave) throws WCMException {
this.execute(resolver, relation, config, autoSave, false);
}
public void execute(ResourceResolver resolver, LiveRelationship relation, ActionConfig config, boolean autoSave, boolean isResetRollout) throws WCMException {
this.newInstance((ValueMap)new ValueMapDecorator(new HashMap<K, V>(config.getProperties()))).execute(resolver.getResource(relation.getSourcePath()), resolver.getResource(relation.getTargetPath()), relation, autoSave, isResetRollout);
}
public int getRank() {
return (Integer)this.getConfig().get("cq.wcm.msm.action.rank", (Object)Integer.MAX_VALUE);
}
public String[] getPropertiesNames() {
HashSet<String> ret = new HashSet<String>();
for (String key : this.getConfig().keySet()) {
if (key == null || key.matches("^(cq|sling|jcr):.*")) continue;
ret.add(key);
}
return ret.toArray(new String[ret.size()]);
}
public String getParameterName() {
return (String)this.getConfig().get("cq.wcm.msm.action.parameter", (Object)"");
}
public String getTitle() {
ValueMap config = this.getConfig();
return (String)config.get("jcr:title", config.get("cq.wcm.msm.action.title", (Object)this.getName()));
}
public void write(JSONWriter jsonWriter) throws JSONException {
jsonWriter.object();
jsonWriter.key("name").value((Object)this.getName());
jsonWriter.key("parameter").value((Object)this.getParameterName());
jsonWriter.key("title").value((Object)this.getTitle());
jsonWriter.key("rank").value((long)this.getRank());
jsonWriter.key("properites");
jsonWriter.array();
for (String prop : this.getPropertiesNames()) {
jsonWriter.value((Object)prop);
}
jsonWriter.endArray();
jsonWriter.endObject();
}
}