LiveRelationshipInfoProvider.java
5.79 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.ListInfoProvider
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.PageInfoProvider
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.Blueprint
* com.day.cq.wcm.msm.api.BlueprintManager
* 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.LiveStatus
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
*/
package com.day.cq.wcm.msm.impl;
import com.day.cq.commons.ListInfoProvider;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageInfoProvider;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.Blueprint;
import com.day.cq.wcm.msm.api.BlueprintManager;
import com.day.cq.wcm.msm.api.LiveCopy;
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 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.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
@Component(metatype=0, immediate=1)
@Service
public class LiveRelationshipInfoProvider
implements ListInfoProvider,
PageInfoProvider {
@Reference
protected LiveRelationshipManager relationshipManager = null;
public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
Page page = (Page)resource.adaptTo(Page.class);
if (page != null) {
try {
resource = (Resource)page.adaptTo(Resource.class);
BlueprintManager bpm = (BlueprintManager)resource.getResourceResolver().adaptTo(BlueprintManager.class);
JSONObject msm = new JSONObject();
info.put("msm", (Object)msm);
boolean isInBlueprint = bpm != null && bpm.getContainingBlueprint(resource.getPath()) != null;
msm.put("msm:isLiveCopy", this.relationshipManager.hasLiveRelationship(resource));
msm.put("msm:isInBlueprint", isInBlueprint);
msm.put("msm:isSource", isInBlueprint && this.relationshipManager.isSource(resource));
}
catch (WCMException e) {
throw new JSONException((Throwable)e);
}
}
}
public void updateListGlobalInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
}
public void updateListItemInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
try {
boolean isInBlueprint;
LiveRelationship liveRelationship = this.relationshipManager.getLiveRelationship(resource, true);
BlueprintManager bpm = (BlueprintManager)resource.getResourceResolver().adaptTo(BlueprintManager.class);
if (liveRelationship == null) {
info.put("msm:isLiveCopy", false);
} else {
info.put("msm:liveRelationship", (Object)LiveRelationshipInfoProvider.buildRelation(liveRelationship));
info.put("msm:isLiveCopy", this.relationshipManager.hasLiveRelationship(resource));
}
boolean bl = isInBlueprint = bpm != null && bpm.getContainingBlueprint(resource.getPath()) != null;
if (isInBlueprint) {
info.put("msm:isInBlueprint", true);
info.put("msm:isSource", this.relationshipManager.isSource(resource));
} else {
info.put("msm:isInBlueprint", false);
info.put("msm:isSource", false);
}
}
catch (WCMException e) {
throw new JSONException((Throwable)e);
}
}
private static JSONObject buildRelation(LiveRelationship relation) throws JSONException {
JSONObject ret = new JSONObject();
ret.put("msm:syncPath", (Object)relation.getSyncPath());
ret.put("msm:sourcePath", (Object)relation.getSourcePath());
ret.put("msm:targetPath", (Object)relation.getTargetPath());
ret.put("msm:isRootConfig", relation.getLiveCopy().isRoot());
ret.put("msm:status", (Object)LiveRelationshipInfoProvider.buildStatus(relation.getStatus()));
return ret;
}
private static JSONObject buildStatus(LiveStatus status) throws JSONException {
JSONObject ret = new JSONObject();
ret.put("msm:isCancelled", status.isCancelled());
ret.put("msm:isCancelledForChildren", status.isCancelledForChildren());
ret.put("msm:isTargetExisting", status.isTargetExisting());
ret.put("msm:isSourceExisting", status.isSourceExisting());
for (String key : status.getAdvancedStatus().keySet()) {
ret.put(key, (Object)status.getAdvancedStatus(key));
}
return ret;
}
protected void bindRelationshipManager(LiveRelationshipManager liveRelationshipManager) {
this.relationshipManager = liveRelationshipManager;
}
protected void unbindRelationshipManager(LiveRelationshipManager liveRelationshipManager) {
if (this.relationshipManager == liveRelationshipManager) {
this.relationshipManager = null;
}
}
}