ConfigPostProcessor.java
6.07 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* 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.RolloutConfig
* 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.servlets.post.Modification
* org.apache.sling.servlets.post.SlingPostProcessor
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.msm.impl.postprocessing;
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.RolloutConfig;
import com.day.cq.wcm.msm.impl.BlueprintImpl;
import com.day.cq.wcm.msm.impl.BlueprintManagerImpl;
import com.day.cq.wcm.msm.impl.LiveCopyManagerImpl;
import com.day.cq.wcm.msm.impl.LiveCopyServiceImpl;
import com.day.cq.wcm.msm.impl.LiveRelationshipEditingUtil;
import java.util.List;
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.servlets.post.Modification;
import org.apache.sling.servlets.post.SlingPostProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service
public class ConfigPostProcessor
implements SlingPostProcessor {
private static final Logger log = LoggerFactory.getLogger(ConfigPostProcessor.class);
private static final String WRITE_BLUEPRINT_CONFIG_PARAM = "msm:writeBlueprintConfig";
private static final String BLUEPRINT_ROLLOUTCONFIGS_PARAM = "msm:blueprintRolloutConfigs";
private static final String WRITE_LIVECOPY_CONFIG_PARAM = "msm:writeLiveCopyConfig";
private static final String LIVECOPY_ROLLOUTCONFIGS_PARAM = "msm:liveCopyRolloutConfigs";
private static final String INHERIT_ROLLOUTCONFIGS_PARAM = "msm:inheritRolloutConfigs";
@Reference
private LiveRelationshipManager relationshipManager = null;
@Reference
private LiveCopyServiceImpl liveCopyService = null;
public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception {
if ("true".equals(request.getParameter("msm:writeBlueprintConfig"))) {
try {
Resource resource = request.getResource();
String[] rolloutConfigs = request.getParameterValues("msm:blueprintRolloutConfigs");
if (rolloutConfigs != null && rolloutConfigs.length == 1 && "".equals(rolloutConfigs[0])) {
rolloutConfigs = null;
}
Resource configResource = resource.getName().equals("jcr:content") ? resource.getParent() : resource;
ResourceResolver resolver = request.getResourceResolver();
BlueprintManagerImpl bpm = (BlueprintManagerImpl)resolver.adaptTo(BlueprintManager.class);
BlueprintImpl blueprint = bpm.getContainingBlueprint(configResource.getPath());
if (blueprint != null) {
String relPath = "";
if (configResource.getPath().length() > blueprint.getSitePath().length()) {
relPath = relPath + configResource.getPath().substring(blueprint.getSitePath().length() + 1);
}
blueprint.setRolloutConfigs(relPath, rolloutConfigs);
log.debug("Updated blueprint config at {}", (Object)configResource.getPath());
}
}
catch (Exception e) {
log.error("Error while updating blueprint config", (Throwable)e);
}
}
if ("true".equals(request.getParameter("msm:writeLiveCopyConfig"))) {
LiveRelationshipEditingUtil.processCancel(request, this.relationshipManager);
try {
ResourceResolver resolver = request.getResourceResolver();
Resource resource = request.getResource();
LiveRelationship currentRelation = this.relationshipManager.getLiveRelationship(resource, true);
String[] rolloutConfigs = request.getParameterValues("msm:liveCopyRolloutConfigs");
if (rolloutConfigs == null || "true".equals(request.getParameter("msm:inheritRolloutConfigs"))) {
rolloutConfigs = new String[]{};
}
Boolean deepParam = Boolean.valueOf(request.getParameter("msm:isDeep"));
log.debug("Updating LiveCopy at {}", (Object)currentRelation.getLiveCopy().getPath());
LiveCopyManagerImpl lcManager = this.liveCopyService.createLiveCopyManager(resolver);
LiveRelationshipEditingUtil.editLiveCopy(resolver, lcManager, this.relationshipManager, currentRelation, deepParam, rolloutConfigs);
}
catch (Exception e) {
log.error("Error while updating LiveCopy", (Throwable)e);
}
}
}
protected void bindRelationshipManager(LiveRelationshipManager liveRelationshipManager) {
this.relationshipManager = liveRelationshipManager;
}
protected void unbindRelationshipManager(LiveRelationshipManager liveRelationshipManager) {
if (this.relationshipManager == liveRelationshipManager) {
this.relationshipManager = null;
}
}
protected void bindLiveCopyService(LiveCopyServiceImpl liveCopyServiceImpl) {
this.liveCopyService = liveCopyServiceImpl;
}
protected void unbindLiveCopyService(LiveCopyServiceImpl liveCopyServiceImpl) {
if (this.liveCopyService == liveCopyServiceImpl) {
this.liveCopyService = null;
}
}
}