ContentDeleteActionFactory.java
9.43 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.Page
* com.day.cq.wcm.api.PageManager
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.LiveAction
* com.day.cq.wcm.msm.api.LiveRelationship
* com.day.cq.wcm.msm.api.LiveRelationshipManager
* com.day.cq.wcm.msm.api.LiveStatus
* com.day.cq.wcm.msm.api.RolloutManager
* com.day.cq.wcm.msm.commons.BaseActionFactory
* com.day.cq.wcm.msm.commons.FilteredAction
* com.day.cq.wcm.msm.commons.ItemFilterImpl
* com.day.cq.wcm.msm.commons.ItemFilterUtil
* javax.jcr.Node
* javax.jcr.RepositoryException
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Modified
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.msm.impl.actions;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveAction;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.LiveRelationshipManager;
import com.day.cq.wcm.msm.api.LiveStatus;
import com.day.cq.wcm.msm.api.RolloutManager;
import com.day.cq.wcm.msm.commons.BaseActionFactory;
import com.day.cq.wcm.msm.commons.FilteredAction;
import com.day.cq.wcm.msm.commons.ItemFilterImpl;
import com.day.cq.wcm.msm.commons.ItemFilterUtil;
import com.day.cq.wcm.msm.impl.Utils;
import java.util.Calendar;
import java.util.Dictionary;
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.Modified;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=1, label="%cq.wcm.msm.impl.actions.contentdelete.label", description="%cq.wcm.msm.impl.actions.contentdelete.description")
@Service
public class ContentDeleteActionFactory
extends BaseActionFactory<FilteredAction> {
@Deprecated
@Property(name="cq.wcm.msm.action.rank", propertyPrivate=1)
private static final int RANK = 304;
@Deprecated
@Property(name="cq.wcm.msm.action.title", propertyPrivate=1)
private static final String TITLE = "Delete content";
@Deprecated
@Property(name="cq.wcm.msm.action.parameter", propertyPrivate=1)
private static final String PARAMETER = "msm:actionContentDelete";
@Deprecated
@Property(name="actiontype", propertyPrivate=1)
private static final String ACTION_TYPE = "contentdelete";
@Property(name="cq.wcm.msm.action.excludednodetypes")
private static final String[] DEFAULT_FILTER_NODE_TYPES = ItemFilterUtil.EMPTY_PROPERTIES;
@Property(name="cq.wcm.msm.action.excludedparagraphitems")
private static final String[] DEFAULT_EXCLUDED_PARAGRAPH_ITEMS = ItemFilterUtil.EMPTY_PROPERTIES;
@Property(name="cq.wcm.msm.action.excludedprops")
private static final String[] DEFAULT_EXCLUDED_PROPERTIES = ItemFilterUtil.EMPTY_PROPERTIES;
@Property(name="liveActionName", propertyPrivate=1)
private static final String[] LIVE_ACTION_NAME = new String[]{ContentDeleteAction.class.getSimpleName(), "contentDelete"};
@Reference
private LiveRelationshipManager liveRelationshipManager = null;
@Reference
private RolloutManager rolloutManager = null;
private Dictionary properties;
public String createsAction() {
return LIVE_ACTION_NAME[0];
}
protected ContentDeleteAction newActionInstance(ValueMap config) {
return new ContentDeleteAction(config, this);
}
@Activate
@Modified
protected void configure(ComponentContext componentContext) {
this.properties = componentContext.getProperties();
}
protected Dictionary getFactoryConfig() {
return this.properties;
}
private LiveRelationshipManager getLiveRelationshipManager() {
return this.liveRelationshipManager;
}
protected void bindLiveRelationshipManager(LiveRelationshipManager liveRelationshipManager) {
this.liveRelationshipManager = liveRelationshipManager;
}
protected void unbindLiveRelationshipManager(LiveRelationshipManager liveRelationshipManager) {
if (this.liveRelationshipManager == liveRelationshipManager) {
this.liveRelationshipManager = null;
}
}
protected void bindRolloutManager(RolloutManager rolloutManager) {
this.rolloutManager = rolloutManager;
}
protected void unbindRolloutManager(RolloutManager rolloutManager) {
if (this.rolloutManager == rolloutManager) {
this.rolloutManager = null;
}
}
private static final class ContentDeleteAction
extends FilteredAction {
private static final Logger log = LoggerFactory.getLogger(ContentDeleteAction.class);
private final LiveRelationshipManager relationshipMgr;
private final boolean skipCancelled;
public static final String SKIP_CANCELLED_LC_PARAM = "skipCancelledLiveCopy";
protected ContentDeleteAction(ValueMap config, ContentDeleteActionFactory actionFactory) {
super(config, ItemFilterUtil.createPageFilter((ValueMap)config, (RolloutManager)actionFactory.rolloutManager), ItemFilterUtil.createComponentFilter((ValueMap)config, (RolloutManager)actionFactory.rolloutManager), (BaseActionFactory)actionFactory);
this.relationshipMgr = actionFactory.getLiveRelationshipManager();
this.skipCancelled = config != null && "true".equalsIgnoreCase((String)config.get("skipCancelledLiveCopy", String.class));
}
protected boolean doHandle(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws RepositoryException, WCMException {
Node slaveNode;
if (relation.getStatus().isSourceExisting()) {
log.debug("Call to delete on existing source at {}: nothing to do for", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
return false;
}
Node node = slaveNode = target != null ? (Node)target.adaptTo(Node.class) : null;
if (slaveNode == null) {
log.debug("Call to delete on non existing Node at {}", (Object)relation.getTargetPath());
return false;
}
return true;
}
protected void doExecute(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws RepositoryException, WCMException {
Page page;
Node slaveNode = Utils.getHierarchyNode((Node)target.adaptTo(Node.class));
if (slaveNode == null) {
log.error("Target Node at {} is null, though checked on call to handles", (Object)relation.getTargetPath());
return;
}
ResourceResolver resolver = target.getResourceResolver();
if (!slaveNode.getPath().equals(target.getPath())) {
target = resolver.getResource(slaveNode.getPath());
}
if (this.skipCancelled && this.hasLCCancelledChildren(relation) && !resetRollout) {
log.debug("Resource {} LC is cancelled and skipCancelled=true for the ContentDeleteAction, skipping the resource!", (Object)target.getPath());
return;
}
if (relation.getStatus().isPage() && (page = (Page)target.adaptTo(Page.class)) != null) {
if (this.relationshipMgr != null) {
this.relationshipMgr.endRelationship(target, false);
}
page.getPageManager().delete(page, false);
log.debug("Deleted Page for {} at {}", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
} else {
Page containingPage;
String strSlaveNodePath = slaveNode.getPath();
slaveNode.remove();
PageManager pm = (PageManager)resolver.adaptTo(PageManager.class);
Page page2 = containingPage = pm == null ? null : pm.getContainingPage(relation.getTargetPath());
if (containingPage != null && !strSlaveNodePath.equals(containingPage.getPath())) {
containingPage.getPageManager().touch((Node)containingPage.adaptTo(Node.class), true, Calendar.getInstance(), false);
}
log.debug("Deleted Resource for {} at {}", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
}
}
private boolean hasLCCancelledChildren(LiveRelationship relation) throws WCMException {
Boolean hasCancelledChild = relation.getStatus().getAdvancedStatus("msm:isTargetCancelledChild");
if (hasCancelledChild == null) {
hasCancelledChild = false;
}
return relation.getStatus().isCancelled() || hasCancelledChild != false;
}
}
}