LiveCopyManagerImpl.java
31.4 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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.LiveCopy
* com.day.cq.wcm.msm.api.RolloutConfig
* com.day.cq.wcm.msm.api.RolloutConfigManager
* com.day.cq.wcm.msm.api.RolloutManager
* com.day.cq.wcm.msm.api.RolloutManager$Trigger
* com.day.text.Text
* javax.jcr.ItemNotFoundException
* javax.jcr.Node
* javax.jcr.PathNotFoundException
* javax.jcr.Property
* javax.jcr.RangeIterator
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.commons.collections.FunctorException
* org.apache.commons.collections.IteratorUtils
* org.apache.commons.collections.Predicate
* org.apache.commons.collections.Transformer
* org.apache.commons.collections.functors.NotNullPredicate
* org.apache.commons.lang.StringUtils
* org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter
* org.apache.sling.jcr.resource.JcrPropertyMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.msm.impl;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveCopy;
import com.day.cq.wcm.msm.api.RolloutConfig;
import com.day.cq.wcm.msm.api.RolloutConfigManager;
import com.day.cq.wcm.msm.api.RolloutManager;
import com.day.cq.wcm.msm.impl.LiveCopyIndexImpl;
import com.day.cq.wcm.msm.impl.SourceTargetFilter;
import com.day.cq.wcm.msm.impl.Utils;
import com.day.text.Text;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.RangeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.commons.collections.FunctorException;
import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.Transformer;
import org.apache.commons.collections.functors.NotNullPredicate;
import org.apache.commons.lang.StringUtils;
import org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter;
import org.apache.sling.jcr.resource.JcrPropertyMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LiveCopyManagerImpl {
static final String NN_LIVESYNCCONFIG = "cq:LiveSyncConfig";
static final String PN_MASTER = "cq:master";
static final String NT_LIVE_COPY = "cq:LiveCopy";
private static final String NT_LC_PATH_FILTER = "cq:LcPathFilter";
private static final String NT_LIVE_SYNC_CONFIG = "cq:LiveSyncConfig";
private static final String PN_ROLLOUT_CONFIGS = "cq:rolloutConfigs";
private static final String NT_LIVE_SYNC = "cq:LiveSync";
private static final String PN_MOVE_TARGET = "cq:moveTarget";
private static final String PATH_MASTER = "cq:LiveSyncConfig/cq:master";
private static final Logger log = LoggerFactory.getLogger(LiveCopyManagerImpl.class);
private static final String[] EMPTY_CONFIG = new String[0];
private final Session session;
private final LiveCopyIndexImpl liveCopyIndex;
private final RolloutConfigManager rolloutConfigManager;
LiveCopyManagerImpl(Session session, LiveCopyIndexImpl lcIndex, RolloutConfigManager rolloutConfigManager) {
this.session = session;
this.liveCopyIndex = lcIndex;
this.rolloutConfigManager = rolloutConfigManager;
}
public LiveCopyImpl get(String path) throws WCMException, RepositoryException {
LiveCopyImpl lc = null;
if (this.session.nodeExists(path)) {
try {
Node node = Utils.getWorkingNode(this.session.getNode(path));
if (LiveCopyManagerImpl.hasLiveCopy(node)) {
Node configNode = node.getNode("cq:LiveSyncConfig");
JcrPropertyMap map = new JcrPropertyMap(configNode);
lc = new LiveCopyImpl(SourceTargetFilter.read(configNode), (String)map.get("cq:moveTarget", String.class), this.rolloutConfigManager, (String[])map.get("cq:rolloutConfigs", String[].class));
this.liveCopyIndex.update(lc.getPath());
}
}
catch (ItemNotFoundException ignore) {
// empty catch block
}
}
return lc;
}
public /* varargs */ LiveCopyImpl create(String path, String blueprintPath, boolean isDeep, RolloutConfig ... rolloutConfig) throws PathNotFoundException, WCMException {
try {
return this.create(Utils.getHierarchyNode(this.session.getNode(path)), blueprintPath, isDeep, rolloutConfig);
}
catch (PathNotFoundException e) {
throw e;
}
catch (RepositoryException e) {
log.debug("Failed to access Repository to create LiveCopy {}", (Throwable)e);
throw new WCMException("Failed to access Repository to create LiveCopy", (Throwable)e);
}
}
public boolean remove(String path) throws WCMException, RepositoryException {
LiveCopyImpl liveCopy = this.get(path);
if (liveCopy == null) {
log.debug("ignore request to remove LiveCopy, that is not persisted {}", (Object)path);
return false;
}
try {
Node node = this.session.getNode(path);
log.debug("Try to remove LiveCopy stored at {}", (Object)node.getPath());
if (liveCopy.isRoot()) {
Utils.detachLiveCopy(node, true, false);
log.debug("Removed Root, detached LiveRelationship at {}", (Object)node.getPath());
} else {
LiveCopyImpl parent = this.getContainingLiveCopy(Text.getRelativeParent((String)liveCopy.getPath(), (int)1));
if (parent != null && !liveCopy.getExclusions().isEmpty()) {
for (String exclude : liveCopy.getExclusions()) {
String childPath = Utils.appendPath(liveCopy.getPath(), exclude);
if (!parent.contains(childPath)) continue;
parent.addExclusion(Utils.relativePath(parent.getPath(), childPath));
log.debug("Moved exclusion {} from deleted LiveCopy to {}", (Object)exclude, (Object)parent.getPath());
}
}
LiveCopyManagerImpl.removeMarker(Utils.getWorkingNode(node));
}
return true;
}
catch (RepositoryException e) {
log.debug("Failed to access repository for removal: {}", (Throwable)e);
throw new WCMException("Failed to access Repository for changes", (Throwable)e);
}
}
public LiveCopyImpl copy(LiveCopyImpl liveCopy, String target) throws WCMException, RepositoryException {
LiveCopyImpl copy = this.create(target, liveCopy.getBlueprintPath(), liveCopy.isDeep(), liveCopy.getRolloutConfigs().toArray((T[])new RolloutConfig[liveCopy.getRolloutConfigs().size()]));
if (!StringUtils.isEmpty((String)liveCopy.getMoveTarget())) {
String moveTarget = Text.getRelativeParent((String)liveCopy.getPath(), (int)1).equals(Text.getRelativeParent((String)liveCopy.getMoveTarget(), (int)1)) ? Utils.appendPath(Text.getRelativeParent((String)copy.getPath(), (int)1), Text.getName((String)liveCopy.getMoveTarget())) : liveCopy.getMoveTarget();
copy.setMovedTarget(moveTarget);
if (!copy.isRoot()) {
LiveCopyImpl copyParent = this.getContainingLiveCopy(Text.getRelativeParent((String)copy.getPath(), (int)1));
copyParent.addExclusion(moveTarget);
}
}
for (String exclude : liveCopy.getExclusions()) {
copy.addExclusion(exclude);
}
log.debug("Copied LiveCopy of from {} to {}", (Object)liveCopy.getPath(), (Object)copy.getPath());
return copy;
}
public LiveCopyImpl getContainingLiveCopy(String path) throws WCMException {
LiveCopyImpl closest = null;
try {
String parent = path;
while (closest == null && !StringUtils.isEmpty((String)parent)) {
closest = this.get(parent);
parent = Text.getRelativeParent((String)parent, (int)1);
}
if (closest != null && closest.contains(path)) {
return closest;
}
return null;
}
catch (RepositoryException e) {
log.error("Can not search for Containing LiveCopy {}:", (Object)e.getMessage());
throw new WCMException((Throwable)e);
}
}
public Set<String> moveDependentLiveCopies(String source, String target) throws WCMException, RepositoryException {
LiveCopyImpl targetLc;
HashSet<String> changed = new HashSet<String>();
Iterator<LiveCopyImpl> sourceDependents = this.getDependentLiveCopies(source);
while (sourceDependents.hasNext()) {
LiveCopyImpl sourceLc = sourceDependents.next();
targetLc = sourceLc.containsMaster(target) ? sourceLc : (sourceLc.getPath().equals(sourceLc.createCopyPath(source)) && sourceLc.isRoot() ? sourceLc : this.findDependentLiveCopy(target, this.getRootPath(sourceLc)));
if (targetLc == null) {
log.debug("Move of Blueprint to {} moved outside LiveCopy at {}", (Object)target, (Object)sourceLc.getPath());
continue;
}
if (targetLc.getPath().equals(targetLc.createCopyPath(target))) {
log.debug("Move of Blueprint to {} already mapped at ", (Object)target, (Object)targetLc.getPath());
continue;
}
String sourcePath = sourceLc.createCopyPath(source);
String targetPath = targetLc.createCopyPath(target);
if (sourceLc.getPath().equals(sourcePath)) {
if (sourceLc.isMoved()) {
String oldTarget = sourceLc.getMoveTarget();
SourceTargetFilter targetMatch = this.liveCopyIndex.getClosestLiveCopy(oldTarget);
LiveCopyImpl old = targetMatch.getTarget().equals(targetLc.getPath()) ? targetLc : this.get(targetMatch.getTarget());
log.debug("edit existing exclude of {} at {} to {} at {}", (Object[])new String[]{oldTarget, old.getPath(), targetPath, targetLc.getPath()});
old.removeExclusion(oldTarget);
targetLc.addExclusion(targetPath);
}
if (sourceLc.getPath().equals(targetPath) && sourceLc.isDeep() && !sourceLc.isRoot() && sourceLc.getRolloutConfigs().isEmpty()) {
this.remove(sourceLc.getPath());
log.debug("removed LiveCopy rendered retundand after move {}", (Object)sourcePath);
} else {
sourceLc.setBlueprintPath(target);
sourceLc.setMovedTarget(targetPath);
}
changed.add(sourceLc.getPath());
continue;
}
if (this.session.nodeExists(sourcePath) && Utils.getWorkingNode(this.session.getNode(sourcePath)).isNodeType("cq:LiveRelationship")) {
LiveCopyImpl newLc = this.create(sourcePath, target, true, new RolloutConfig[0]);
newLc.setMovedTarget(targetPath);
targetLc.addExclusion(targetPath);
log.debug("create new LiveCopy at {} for move", (Object)sourcePath);
changed.add(targetLc.getPath());
continue;
}
if (!this.session.nodeExists(sourcePath)) {
log.debug("Moved path {} not present in LiveCopy at {}: nothing to do", (Object)sourcePath, (Object)sourceLc.getPath());
continue;
}
log.debug("Moved path {} shadowed by a manual Page in LiveCopy at {}: nothing to do", (Object)sourcePath, (Object)sourceLc.getPath());
}
Iterator<LiveCopyImpl> targetDependents = this.getDependentLiveCopies(target);
while (targetDependents.hasNext()) {
targetLc = targetDependents.next();
if (!targetLc.getBlueprintPath().equals(target) || !targetLc.isMoved() || Text.getName((String)targetLc.getMoveTarget()).equals(Text.getName((String)target))) continue;
String oldTarget = targetLc.getMoveTarget();
SourceTargetFilter targetMatch = this.liveCopyIndex.getClosestLiveCopy(oldTarget);
LiveCopyImpl sourceLc = this.findDependentLiveCopy(target, this.getRootPath(targetLc));
LiveCopyImpl old = sourceLc != null && targetMatch.getTarget().equals(sourceLc.getPath()) ? sourceLc : this.get(targetMatch.getTarget());
String targetPath = sourceLc.createCopyPath(target);
log.debug("edit existing exclude of {} at {} to {} at {}", (Object[])new String[]{oldTarget, old.getPath(), targetPath, targetLc.getPath()});
old.removeExclusion(oldTarget);
sourceLc.addExclusion(targetPath);
targetLc.setMovedTarget(targetPath);
changed.add(targetLc.getPath());
}
return changed;
}
public List<LiveCopyImpl> getLiveCopiesInBranch(String path) throws WCMException, RepositoryException {
String rootPath = null;
LiveCopyImpl liveCopy = this.getContainingLiveCopy(path);
if (liveCopy != null) {
rootPath = this.getRootPath(liveCopy);
}
if (rootPath == null) {
return Collections.emptyList();
}
List<String> all = this.liveCopyIndex.getTargetBranch(rootPath);
ArrayList<LiveCopyImpl> ret = new ArrayList<LiveCopyImpl>(all.size());
for (String descendant : all) {
LiveCopyImpl local = this.get(descendant);
if (local == null) continue;
ret.add(local);
}
return ret;
}
public static void removeMarker(Node node) throws RepositoryException {
if (node.isNodeType("cq:LiveSync")) {
node.removeMixin("cq:LiveSync");
log.debug("Removed mixin type from storage {}", (Object)node.getPath());
if (node.hasProperty("cq:lastRolledout")) {
node.addMixin("cq:LiveRelationship");
log.debug("Set mixin type to LiveRelationship as LiveCopy has not been root {}", (Object)node.getPath());
}
}
if (node.hasNode("cq:LiveSyncConfig")) {
node.getNode("cq:LiveSyncConfig").remove();
log.debug("Removed config node {}", (Object)node.getPath());
}
}
public RangeIterator getAll() throws RepositoryException, WCMException {
Iterator all = IteratorUtils.transformedIterator(this.liveCopyIndex.getTargetBranch("/").iterator(), (Transformer)new Transformer(){
public Object transform(Object input) {
try {
return LiveCopyManagerImpl.this.get((String)input);
}
catch (Exception e) {
throw new FunctorException((Throwable)e);
}
}
});
return new RangeIteratorAdapter(IteratorUtils.filteredIterator((Iterator)all, (Predicate)NotNullPredicate.getInstance()));
}
static boolean hasLiveCopy(Node contentNode) throws RepositoryException {
try {
return contentNode.hasProperty("cq:LiveSyncConfig/cq:master");
}
catch (ItemNotFoundException e) {
return false;
}
}
/* varargs */ LiveCopyImpl create(Node hierarchyNode, String blueprintPath, boolean isDeep, RolloutConfig ... rolloutConfig) throws RepositoryException, WCMException {
String[] cfgPaths;
String lcPath = hierarchyNode.getPath();
Node workingNode = null;
try {
workingNode = Utils.getWorkingNode(hierarchyNode);
if (LiveCopyManagerImpl.hasLiveCopy(workingNode)) {
throw new IllegalArgumentException(String.format("Node %s is already a LiveCopy can't create a new one", hierarchyNode.getParent().getPath()));
}
}
catch (ItemNotFoundException ignore) {
// empty catch block
}
if (rolloutConfig == null) {
cfgPaths = new String[]{};
} else {
cfgPaths = new String[rolloutConfig.length];
for (int i = 0; i < rolloutConfig.length; ++i) {
cfgPaths[i] = rolloutConfig[i].getPath();
}
}
if (workingNode == null) {
workingNode = hierarchyNode.addNode("jcr:content", "nt:unstructured");
}
if (!workingNode.isNodeType("cq:LiveSync")) {
workingNode.addMixin("cq:LiveSync");
}
if (workingNode.hasNode("cq:LiveSyncConfig")) {
Node target = workingNode.getNode("cq:LiveSyncConfig");
if (!target.isNodeType("cq:LcPathFilter")) {
target.addMixin("cq:LcPathFilter");
}
} else {
workingNode.addNode("cq:LiveSyncConfig", "cq:LiveCopy");
}
Node configNode = workingNode.getNode("cq:LiveSyncConfig");
configNode.setProperty("cq:rolloutConfigs", cfgPaths);
String[] excludes = null;
LiveCopyImpl parent = this.getContainingLiveCopy(lcPath);
if (parent != null && !parent.getExclusions().isEmpty()) {
HashSet<String> childExclude = new HashSet<String>();
for (String exclude : parent.getExclusions()) {
String childPath = Utils.appendPath(parent.getPath(), exclude);
if (!Text.isDescendantOrEqual((String)lcPath, (String)childPath)) continue;
parent.removeExclusion(exclude);
childExclude.add(Utils.relativePath(lcPath, childPath));
log.debug("Moved exclusion {} from LiveCopy at {}", (Object)exclude, (Object)parent.getPath());
}
excludes = childExclude.toArray(new String[childExclude.size()]);
}
SourceTargetFilter filter = new SourceTargetFilter(blueprintPath, lcPath, isDeep, excludes);
SourceTargetFilter.write(filter, configNode);
return new LiveCopyImpl(filter, null, this.rolloutConfigManager, cfgPaths);
}
boolean dependsOn(String target, String source, boolean deep) throws RepositoryException, WCMException {
Iterator<LiveCopyImpl> itr = this.getDependentLiveCopies(source);
while (itr.hasNext()) {
LiveCopyImpl dep = itr.next();
if (dep.getPath().equals(target) || deep && Text.isDescendant((String)target, (String)dep.getPath())) {
return true;
}
if (!this.dependsOn(target, dep.getPath(), deep)) continue;
return true;
}
return false;
}
private LiveCopyImpl findDependentLiveCopy(String blueprintPath, String targetBranch) throws WCMException, RepositoryException {
List<String> desc = this.liveCopyIndex.getTargetBranch(targetBranch);
for (String path : desc) {
LiveCopyImpl lc = this.get(path);
if (lc == null || !lc.containsMaster(blueprintPath)) continue;
return lc;
}
return null;
}
private String getRootPath(LiveCopyImpl liveCopy) throws WCMException, RepositoryException {
while (!liveCopy.isRoot()) {
liveCopy = this.get(this.liveCopyIndex.getClosestLiveCopy(liveCopy.getPath()).getTarget());
}
return liveCopy.getPath();
}
Iterator<LiveCopyImpl> getDependentLiveCopies(String path) throws RepositoryException, WCMException {
String lcPath = Utils.getContainingPagePath(path);
Iterator transformed = IteratorUtils.transformedIterator(this.liveCopyIndex.getTargetLiveCopies(lcPath).iterator(), (Transformer)new Transformer(){
public Object transform(Object input) {
try {
return LiveCopyManagerImpl.this.get((String)input);
}
catch (WCMException e) {
throw new FunctorException((Throwable)e);
}
catch (RepositoryException e) {
throw new FunctorException((Throwable)e);
}
}
});
return IteratorUtils.filteredIterator((Iterator)transformed, (Predicate)new Predicate(){
public boolean evaluate(Object object) {
return object != null;
}
});
}
private /* varargs */ void setProperty(String path, String propertyName, String ... values) throws RepositoryException {
Node configNode = Utils.getWorkingNode(this.session.getNode(path)).getNode("cq:LiveSyncConfig");
if ((values == null || values.length == 0) && configNode.hasProperty(propertyName)) {
configNode.getProperty(propertyName).remove();
} else if (values != null && values.length != 0) {
configNode.setProperty(propertyName, values);
}
}
private void setProperty(String path, String propertyName, String value) throws RepositoryException {
Node configNode = Utils.getWorkingNode(this.session.getNode(path)).getNode("cq:LiveSyncConfig");
if (StringUtils.isEmpty((String)value) && configNode.hasProperty(propertyName)) {
configNode.getProperty(propertyName).remove();
} else if (!StringUtils.isEmpty((String)value)) {
configNode.setProperty(propertyName, value);
}
}
public class LiveCopyImpl
implements LiveCopy {
private SourceTargetFilter filter;
private final String contentPath;
private String moveTarget;
private String[] rolloutCfgPaths;
private final RolloutConfigManager rolloutConfigManager;
private /* varargs */ LiveCopyImpl(SourceTargetFilter filter, String moveTarget, RolloutConfigManager rolloutConfigManager, String ... rolloutCfgPaths) {
this.filter = filter;
this.moveTarget = moveTarget;
this.rolloutConfigManager = rolloutConfigManager;
this.rolloutCfgPaths = rolloutCfgPaths == null ? EMPTY_CONFIG : rolloutCfgPaths;
this.contentPath = Utils.appendPath(filter.getTarget(), "jcr:content");
}
public String getBlueprintPath() {
return this.filter.getSource();
}
public String getPath() {
return this.filter.getTarget();
}
public boolean isDeep() {
return this.filter.isDeep();
}
public List<RolloutConfig> getRolloutConfigs() {
ArrayList<RolloutConfig> rolloutConfigs = new ArrayList<RolloutConfig>(this.rolloutCfgPaths.length);
try {
Set all = this.rolloutConfigManager.getRolloutConfigs();
all.retainAll(Arrays.asList(this.rolloutCfgPaths));
for (String path : all) {
RolloutConfig cfg = this.rolloutConfigManager.getRolloutConfig(path);
if (cfg != null) {
rolloutConfigs.add(cfg);
continue;
}
log.warn("Configured RolloutConfig for {} not found at {}", (Object)this.getPath(), (Object)path);
}
}
catch (WCMException e) {
log.debug("Failed to access RolloutConfig for {} : {}", new Object[]{this.getPath(), e});
}
return rolloutConfigs;
}
public List<RolloutConfig> getRolloutConfigs(RolloutManager.Trigger trigger) {
ArrayList<RolloutConfig> res = new ArrayList<RolloutConfig>();
for (RolloutConfig rc : this.getRolloutConfigs()) {
if (!trigger.equals((Object)rc.getTrigger())) continue;
res.add(rc);
}
return res;
}
public boolean isTrigger(RolloutManager.Trigger trigger) {
for (RolloutConfig rc : this.getRolloutConfigs()) {
if (!trigger.equals((Object)rc.getTrigger())) continue;
return true;
}
return false;
}
public boolean isRoot() {
try {
return LiveCopyManagerImpl.this.liveCopyIndex.getClosestLiveCopy(this.getPath()) == null;
}
catch (RepositoryException e) {
log.error("Can not access Root status for LiveCopy at {}: {}", (Object)this.getPath(), (Object)e);
log.debug("Reason: {}", (Throwable)e);
}
catch (WCMException e) {
log.error("Can not access Root status for LiveCopy at {}: {}", (Object)this.getPath(), (Object)e);
log.debug("Reason: {}", (Throwable)e);
}
return false;
}
public boolean addExclusion(String path) {
boolean added = false;
if (!StringUtils.isEmpty((String)path)) {
String absPath = path;
if (!path.startsWith("/")) {
absPath = Utils.appendPath(this.getPath(), path);
}
if (this.contains(absPath) && !this.getPath().equals(absPath)) {
if (path.startsWith("/")) {
path = path.substring(this.getPath().length() + 1);
}
if (!this.filter.getExcludes().contains(path)) {
try {
HashSet<String> extend = new HashSet<String>();
extend.addAll(this.filter.getExcludes());
extend.add(path);
this.filter = new SourceTargetFilter(this.filter.getSource(), this.filter.getTarget(), this.filter.isDeep(), extend.toArray(new String[extend.size()]));
Node configNode = Utils.getWorkingNode(LiveCopyManagerImpl.this.session.getNode(this.filter.getTarget())).getNode("cq:LiveSyncConfig");
if (!configNode.isNodeType("cq:LiveCopy") && !configNode.isNodeType("cq:LcPathFilter")) {
configNode.setPrimaryType("cq:LiveCopy");
log.info("Updated LiveCopy at to support excludes", (Object)this.filter.getTarget());
}
SourceTargetFilter.write(this.filter, configNode);
added = true;
}
catch (RepositoryException e) {
log.error("Failed to add exclude {} from {}:{}", (Object[])new String[]{path, this.getPath(), e.getMessage()});
}
}
}
}
return added;
}
public boolean removeExclusion(String path) {
boolean removed = false;
if (!StringUtils.isEmpty((String)path)) {
String relPath = path;
if (path.startsWith(this.getPath() + "/")) {
relPath = path.substring(this.getPath().length() + 1);
}
if (this.filter.getExcludes().contains(relPath)) {
HashSet<String> shrunk = new HashSet<String>();
shrunk.addAll(this.filter.getExcludes());
shrunk.remove(relPath);
try {
this.filter = new SourceTargetFilter(this.filter.getSource(), this.filter.getTarget(), this.filter.isDeep(), shrunk.toArray(new String[shrunk.size()]));
SourceTargetFilter.write(this.filter, Utils.getWorkingNode(LiveCopyManagerImpl.this.session.getNode(this.filter.getTarget())).getNode("cq:LiveSyncConfig"));
removed = true;
}
catch (RepositoryException e) {
log.error("Failed to remove exclude {} from {}:{}", (Object[])new String[]{path, this.getPath(), e.getMessage()});
}
}
}
return removed;
}
public boolean contains(String path) {
boolean contains = this.isDeep() ? this.filter.contains(path) : this.getPath().equals(path) || Text.isDescendantOrEqual((String)this.contentPath, (String)path);
return contains && path != null && !path.endsWith("/cq:LiveSyncConfig");
}
public Set<String> getExclusions() {
return Collections.unmodifiableSet(this.filter.getExcludes());
}
public boolean containsMaster(String path) {
return this.createCopyPath(path) != null && this.contains(this.createCopyPath(path));
}
public String getMoveTarget() {
return this.moveTarget;
}
boolean isMoved() {
return this.getMoveTarget() != null;
}
public void setMovedTarget(String moved) throws RepositoryException {
this.moveTarget = moved;
LiveCopyManagerImpl.this.setProperty(this.getPath(), "cq:moveTarget", moved);
}
public void setDeep(boolean deep) throws RepositoryException {
if (this.filter.isDeep() != deep) {
this.filter = new SourceTargetFilter(this.filter.getSource(), this.filter.getTarget(), deep, this.getExclusions().toArray(new String[this.getExclusions().size()]));
SourceTargetFilter.write(this.filter, Utils.getWorkingNode(LiveCopyManagerImpl.this.session.getNode(this.filter.getTarget())).getNode("cq:LiveSyncConfig"));
}
}
public /* varargs */ void setRolloutConfigs(String ... rolloutConfigPath) throws RepositoryException {
this.rolloutCfgPaths = rolloutConfigPath;
LiveCopyManagerImpl.this.setProperty(this.getPath(), "cq:rolloutConfigs", rolloutConfigPath);
}
String createCopyPath(String blueprintPath) {
if (StringUtils.isEmpty((String)blueprintPath)) {
return null;
}
if (this.getBlueprintPath().equals(blueprintPath)) {
return this.getPath();
}
if (blueprintPath.startsWith(this.getBlueprintPath())) {
return this.getPath() + blueprintPath.substring(this.getBlueprintPath().length());
}
return null;
}
private void setBlueprintPath(String blueprintPath) throws RepositoryException {
if (!this.filter.getSource().equals(blueprintPath)) {
this.filter = new SourceTargetFilter(blueprintPath, this.filter.getTarget(), this.filter.isDeep(), this.filter.getExcludes().toArray(new String[this.filter.getExcludes().size()]));
SourceTargetFilter.write(this.filter, Utils.getWorkingNode(LiveCopyManagerImpl.this.session.getNode(this.filter.getTarget())).getNode("cq:LiveSyncConfig"));
}
}
public String toString() {
return String.format("path=%s, bp=%s, deep=%s, rcs=%s, excludes=%s", this.filter.getTarget(), this.filter.getSource(), this.filter.isDeep(), Arrays.toString(this.rolloutCfgPaths), Arrays.toString(this.filter.getExcludes().toArray(new String[this.filter.getExcludes().size()])));
}
public int hashCode() {
return this.getPath().hashCode();
}
public boolean equals(Object obj) {
if (!(obj instanceof LiveCopyImpl)) {
return false;
}
LiveCopyImpl other = (LiveCopyImpl)obj;
Set<String> excludes = this.filter.getExcludes();
return this.getPath().equals(other.getPath()) && this.isRoot() == other.isRoot() && this.isDeep() == other.isDeep() && Arrays.equals(this.getRolloutConfigs().toArray(), other.getRolloutConfigs().toArray()) && excludes.size() == other.getExclusions().size() && excludes.containsAll(other.getExclusions());
}
}
}