BaseAction.java
6.95 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
/*
* 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.RepositoryException
* javax.jcr.nodetype.NodeDefinition
* javax.jcr.nodetype.NodeType
* org.apache.sling.api.resource.PersistenceException
* 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.day.cq.wcm.msm.commons;
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 com.day.cq.wcm.msm.commons.BaseActionFactory;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
import org.apache.sling.api.resource.PersistenceException;
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;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public abstract class BaseAction
implements LiveAction {
private static final Logger log = LoggerFactory.getLogger(BaseAction.class);
private final ValueMap config;
private final BaseActionFactory<? extends LiveAction> liveActionFactory;
protected BaseAction(ValueMap config, BaseActionFactory<? extends LiveAction> liveActionFactory) {
this.config = config;
this.liveActionFactory = liveActionFactory;
}
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) 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, isResetRollout);
log.debug("Executed action {} on rolling out source {} to target {}", (Object[])new String[]{this.getName(), relation.getSourcePath(), relation.getTargetPath()});
if (autoSave && (BaseAction.resourceHasNode(source) || BaseAction.resourceHasNode(target))) {
ResourceResolver resourceResolver;
ResourceResolver resourceResolver2 = resourceResolver = source == null ? target.getResourceResolver() : source.getResourceResolver();
if (resourceResolver != null && resourceResolver.hasChanges()) {
resourceResolver.commit();
}
}
} else {
log.debug("{} did not act on request to roll-out {} to {}: precondition was not met", (Object[])new String[]{this.getName(), relation.getSourcePath(), relation.getTargetPath()});
}
}
catch (RepositoryException e) {
throw new WCMException((Throwable)e);
}
catch (PersistenceException pe) {
throw new WCMException((Throwable)pe);
}
}
protected ValueMap getConfig() {
return this.config;
}
protected BaseActionFactory<? extends LiveAction> getActionFactory() {
return this.liveActionFactory;
}
public static boolean resourceHasNode(Resource resource) {
return resource != null && resource.adaptTo(Node.class) != null;
}
public static boolean isPage(Node node) throws RepositoryException {
if (node == null) {
return false;
}
boolean isPage = node.isNodeType("cq:Page");
if (!isPage) {
isPage = "jcr:content".equals(node.getName()) && node.getDefinition().getDeclaringNodeType().isNodeType("cq:Page");
}
return isPage;
}
@Deprecated
public void execute(ResourceResolver resolver, LiveRelationship relation, ActionConfig config, boolean autoSave) throws WCMException {
this.execute(resolver, relation, config, autoSave, false);
}
@Deprecated
public void execute(ResourceResolver resolver, LiveRelationship relation, ActionConfig config, boolean autoSave, boolean isResetRollout) throws WCMException {
ValueMapDecorator valueMap = new ValueMapDecorator(new HashMap<K, V>());
valueMap.putAll(config.getProperties());
LiveAction liveAction = this.liveActionFactory.newActionInstance((ValueMap)valueMap);
liveAction.execute(resolver.getResource(relation.getSourcePath()), resolver.getResource(relation.getTargetPath()), relation, autoSave, isResetRollout);
}
@Deprecated
public String getParameterName() {
String paramName = this.config != null ? (String)this.config.get("cq.wcm.msm.action.parameter", (Object)"") : "";
return paramName;
}
@Deprecated
public int getRank() {
return 0;
}
@Deprecated
public String getTitle() {
String title = this.config != null ? (String)this.config.get("jcr:title", (Object)this.getName()) : "";
return title;
}
@Deprecated
public String[] getPropertiesNames() {
HashSet<String> propertySet = new HashSet<String>();
if (this.config != null) {
for (String key : this.config.keySet()) {
if (key == null || key.matches("^(cq|sling|jcr):.*") || this.config.get(key, String.class) == null) continue;
propertySet.add(key);
}
}
return propertySet.toArray(new String[propertySet.size()]);
}
@Deprecated
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();
}
}