LiveRelationshipManagerBridge.java
12.7 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.WCMException
* 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.LiveStatus
* com.day.cq.wcm.api.msm.RolloutManager
* com.day.cq.wcm.api.msm.RolloutManager$Trigger
* com.day.cq.wcm.msm.api.Blueprint
* com.day.cq.wcm.msm.api.BlueprintManager
* com.day.cq.wcm.msm.api.BlueprintManagerFactory
* com.day.cq.wcm.msm.api.LiveCopy
* com.day.cq.wcm.msm.api.LiveRelationship
* com.day.cq.wcm.msm.api.LiveRelationshipManager
* com.day.cq.wcm.msm.api.RolloutConfig
* com.day.cq.wcm.msm.api.RolloutManager
* com.day.cq.wcm.msm.api.RolloutManager$Trigger
* com.day.text.Text
* org.apache.felix.scr.annotations.Component
* 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.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.msm.impl.compat;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.api.msm.LiveRelationship;
import com.day.cq.wcm.api.msm.LiveRelationshipManager;
import com.day.cq.wcm.api.msm.LiveStatus;
import com.day.cq.wcm.api.msm.RolloutManager;
import com.day.cq.wcm.msm.api.Blueprint;
import com.day.cq.wcm.msm.api.BlueprintManager;
import com.day.cq.wcm.msm.api.BlueprintManagerFactory;
import com.day.cq.wcm.msm.api.LiveCopy;
import com.day.cq.wcm.msm.api.RolloutConfig;
import com.day.cq.wcm.msm.api.RolloutManager;
import com.day.cq.wcm.msm.impl.compat.LiveCopyAdaptor;
import com.day.cq.wcm.msm.impl.compat.LiveRelationshipAdaptor;
import com.day.text.Text;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
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.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
public class LiveRelationshipManagerBridge
implements LiveRelationshipManager {
@Reference
private com.day.cq.wcm.msm.api.LiveRelationshipManager liveRelationMgr = null;
@Reference
private BlueprintManagerFactory blueprintManagerFactory;
private final Logger log = LoggerFactory.getLogger(LiveRelationshipManagerBridge.class);
public boolean isLiveCopy(Resource target) {
return this.liveRelationMgr.isLiveCopy(target);
}
public Map<String, com.day.cq.wcm.api.msm.LiveCopy> getLiveCopies() {
HashMap<String, com.day.cq.wcm.api.msm.LiveCopy> ret = new HashMap<String, com.day.cq.wcm.api.msm.LiveCopy>();
try {
for (Map.Entry entry : this.liveRelationMgr.getLiveCopies().entrySet()) {
ret.put((String)entry.getKey(), new LiveCopyAdaptor((LiveCopy)entry.getValue()));
}
}
catch (WCMException e) {
this.log.error("Failed to access LiveCopies: {}", (Throwable)e);
}
return ret;
}
public void reenablePropertyRelationship(ResourceResolver resolver, LiveRelationship relation, String[] names, boolean autoSave) throws WCMException {
com.day.cq.wcm.msm.api.LiveRelationship adapted = this.adapt(relation, resolver);
if (adapted != null) {
this.liveRelationMgr.reenablePropertyRelationship(resolver, adapted, names, autoSave);
} else {
this.log.debug("Didn't find relation from {} to {}, no execution of reenablePropertyRelation", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
}
}
public void cancelPropertyRelationship(ResourceResolver resolver, LiveRelationship relation, String[] names, boolean autoSave) throws WCMException {
com.day.cq.wcm.msm.api.LiveRelationship adapted = this.adapt(relation, resolver);
if (adapted != null) {
this.liveRelationMgr.cancelPropertyRelationship(resolver, adapted, names, autoSave);
} else {
this.log.debug("Didn't find relation from {} to {}, no execution of cancelPropertyRelation", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
}
}
public Collection<LiveRelationship> getLiveRelationships(Page source, RolloutManager.Trigger trigger, String[] targets, boolean advancedStatus) throws WCMException {
HashSet<LiveRelationship> ret = new HashSet<LiveRelationship>();
RolloutManager.Trigger adaptedTrigger = trigger == null ? null : RolloutManager.Trigger.fromName((String)trigger.name());
ResourceResolver resolver = ((Resource)source.adaptTo(Resource.class)).getResourceResolver();
for (com.day.cq.wcm.msm.api.LiveRelationship rel : this.liveRelationMgr.getLiveRelationships(source, adaptedTrigger, targets, advancedStatus)) {
List<RolloutConfig> blueprintActions = this.getBlueprintRolloutConfig(rel.getLiveCopy().getBlueprintPath(), resolver);
ret.add(new LiveRelationshipAdaptor(rel, blueprintActions));
}
return ret;
}
public Collection<LiveRelationship> getLiveRelationships(Resource source, RolloutManager.Trigger trigger, String[] targets, boolean advancedStatus) throws WCMException {
HashSet<LiveRelationship> ret = new HashSet<LiveRelationship>();
RolloutManager.Trigger adaptedTrigger = trigger == null ? null : RolloutManager.Trigger.fromName((String)trigger.name());
for (com.day.cq.wcm.msm.api.LiveRelationship rel : this.liveRelationMgr.getLiveRelationships(source, adaptedTrigger, targets, advancedStatus)) {
List<RolloutConfig> blueprintActions = this.getBlueprintRolloutConfig(rel.getLiveCopy().getBlueprintPath(), source.getResourceResolver());
ret.add(new LiveRelationshipAdaptor(rel, blueprintActions));
}
return ret;
}
public LiveRelationship getLiveRelationship(Resource target, boolean advancedStatus) throws WCMException {
com.day.cq.wcm.msm.api.LiveRelationship rel = this.liveRelationMgr.getLiveRelationship(target, advancedStatus);
if (rel != null) {
List<RolloutConfig> blueprintActions = this.getBlueprintRolloutConfig(rel.getLiveCopy().getBlueprintPath(), target.getResourceResolver());
return new LiveRelationshipAdaptor(rel, blueprintActions);
}
return null;
}
public com.day.cq.wcm.api.msm.LiveCopy getLiveCopy(Resource target) {
LiveCopy lc = null;
try {
lc = this.liveRelationMgr.getLiveCopy(target);
}
catch (WCMException e) {
this.log.error("Failed to access LiveCopy: {}", (Throwable)e);
}
if (lc != null) {
return new LiveCopyAdaptor(lc);
}
return null;
}
public void cancelRelationship(ResourceResolver resolver, LiveRelationship relation, boolean deep) throws WCMException {
this.cancelRelationship(resolver, relation, deep, true);
}
public void cancelRelationship(ResourceResolver resolver, LiveRelationship relation, boolean deep, boolean autoSave) throws WCMException {
com.day.cq.wcm.msm.api.LiveRelationship adapted = this.adapt(relation, resolver);
if (adapted != null) {
this.liveRelationMgr.cancelRelationship(resolver, adapted, deep, autoSave);
} else {
this.log.debug("Didn't find relation from {} to {}, no execution of cancelRelationship", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
}
}
public void reenableRelationship(ResourceResolver resolver, LiveRelationship relation) throws WCMException {
this.reenableRelationship(resolver, relation, true);
}
public void reenableRelationship(ResourceResolver resolver, LiveRelationship relation, boolean autoSave) throws WCMException {
com.day.cq.wcm.msm.api.LiveRelationship adapted = this.adapt(relation, resolver);
if (adapted != null) {
this.liveRelationMgr.reenableRelationship(resolver, adapted, autoSave);
} else {
this.log.debug("Didn't find relation from {} to {}, no execution of reenableRelation", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
}
}
public void toggleRelationship(ResourceResolver resolver, LiveRelationship relation, boolean deep) throws WCMException {
this.toggleRelationship(resolver, relation, deep, true);
}
public void toggleRelationship(ResourceResolver resolver, LiveRelationship relation, boolean deep, boolean autoSave) throws WCMException {
if (relation != null) {
if (relation.getStatus().isCancelled()) {
this.reenableRelationship(resolver, relation, autoSave);
} else {
this.cancelRelationship(resolver, relation, deep, autoSave);
}
}
}
public boolean isInBlueprint(Resource source) {
return this.liveRelationMgr.isInBlueprint(source);
}
public boolean isSource(Resource resource) {
return this.liveRelationMgr.isSource(resource);
}
public Map<String, Page> getSkippedSourcePages(Page parentTargetPage) throws WCMException {
return this.liveRelationMgr.getSkippedSourcePages(parentTargetPage);
}
public void addSkippedPage(Page parentPage, String childName, boolean autoSave) throws WCMException {
this.liveRelationMgr.addSkippedPages(parentPage, new String[]{childName}, autoSave);
}
public void addSkippedPages(Page parentPage, String[] childName, boolean autoSave) throws WCMException {
this.liveRelationMgr.addSkippedPages(parentPage, childName, autoSave);
}
public void removeSkippedPage(Page parentPage, String childName, boolean autoSave) throws WCMException {
this.liveRelationMgr.removeSkippedPages(parentPage, new String[]{childName}, autoSave);
}
public void removeSkippedPages(Page parentPage, String[] childName, boolean autoSave) throws WCMException {
this.liveRelationMgr.removeSkippedPages(parentPage, childName, autoSave);
}
public com.day.cq.wcm.msm.api.LiveRelationship adapt(LiveRelationship relation, ResourceResolver resolver) throws WCMException {
Iterator rels;
if (relation == null || resolver == null) {
return null;
}
RolloutManager.Trigger tr3 = relation.getLiveCopy().getTrigger();
RolloutManager.Trigger trigger = tr3 == null ? null : RolloutManager.Trigger.fromName((String)tr3.name());
com.day.cq.wcm.msm.api.LiveRelationship rel = null;
if (relation.getStatus().isTargetExisting()) {
rel = this.liveRelationMgr.getLiveRelationship(resolver.getResource(relation.getTargetPath()), false);
} else if (relation.getStatus().isSourceExisting() && (rels = this.liveRelationMgr.getLiveRelationships(resolver.resolve(relation.getSourcePath()), trigger, new String[]{relation.getTargetPath()}, false).iterator()).hasNext()) {
rel = (com.day.cq.wcm.msm.api.LiveRelationship)rels.next();
}
return rel;
}
private List<RolloutConfig> getBlueprintRolloutConfig(String blueprintPath, ResourceResolver resolver) throws WCMException {
Blueprint bp = this.blueprintManagerFactory.getBlueprintManager(resolver).getContainingBlueprint(blueprintPath);
if (bp != null) {
String sitePath = bp.getSitePath();
String relPath = null;
if (Text.isDescendant((String)(sitePath + "/" + "jcr:content"), (String)blueprintPath)) {
relPath = blueprintPath.substring((sitePath + "/" + "jcr:content").length() + 1);
}
return bp.getBlueprintRolloutConfig(relPath, true);
}
return Collections.emptyList();
}
protected void bindLiveRelationMgr(com.day.cq.wcm.msm.api.LiveRelationshipManager liveRelationshipManager) {
this.liveRelationMgr = liveRelationshipManager;
}
protected void unbindLiveRelationMgr(com.day.cq.wcm.msm.api.LiveRelationshipManager liveRelationshipManager) {
if (this.liveRelationMgr == liveRelationshipManager) {
this.liveRelationMgr = null;
}
}
protected void bindBlueprintManagerFactory(BlueprintManagerFactory blueprintManagerFactory) {
this.blueprintManagerFactory = blueprintManagerFactory;
}
protected void unbindBlueprintManagerFactory(BlueprintManagerFactory blueprintManagerFactory) {
if (this.blueprintManagerFactory == blueprintManagerFactory) {
this.blueprintManagerFactory = null;
}
}
}