DTMPostProcessor.java
6.91 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.workflow.WorkflowService
* 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.PersistenceException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.commons.scheduler.Scheduler
* org.apache.sling.servlets.post.Modification
* org.apache.sling.servlets.post.ModificationType
* org.apache.sling.servlets.post.SlingPostProcessor
*/
package com.adobe.cq.dtm.impl;
import com.adobe.cq.dtm.impl.constants.DTMServerType;
import com.adobe.cq.dtm.impl.util.DTMConfigurationUtil;
import com.day.cq.workflow.WorkflowService;
import java.util.Iterator;
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.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.commons.scheduler.Scheduler;
import org.apache.sling.servlets.post.Modification;
import org.apache.sling.servlets.post.ModificationType;
import org.apache.sling.servlets.post.SlingPostProcessor;
@Component
@Service
public class DTMPostProcessor
implements SlingPostProcessor {
@Reference
private ResourceResolverFactory rrf = null;
@Reference
private Scheduler scheduler = null;
@Reference
private WorkflowService workflowService = null;
public void process(SlingHttpServletRequest request, List<Modification> changes) throws Exception {
Resource currentResource = request.getResource();
ResourceResolver resourceResolver = request.getResourceResolver();
if (currentResource.getPath().matches("/etc/cloudservices/dynamictagmanagement/[^/]+/jcr:content")) {
String dtmConfigPath = currentResource.getParent().getPath();
boolean isStagingPollingPresent = false;
boolean isProductionPollingPresent = false;
boolean isStagingUseSelfHostPresent = false;
boolean isProductionUseSelfHostPresent = false;
for (Modification change : changes) {
if (!ModificationType.MODIFY.equals((Object)change.getType())) continue;
if (change.getSource().endsWith((Object)((Object)DTMServerType.STAGING) + "PollingEnabler")) {
isStagingPollingPresent = true;
DTMConfigurationUtil.scheduleOrUnscheduleDTMJob(this.rrf, this.workflowService, this.scheduler, currentResource, DTMServerType.STAGING);
this.createOrRemoveDTMHookNode(resourceResolver, currentResource, DTMServerType.STAGING, false);
continue;
}
if (change.getSource().endsWith((Object)((Object)DTMServerType.PRODUCTION) + "PollingEnabler")) {
isProductionPollingPresent = true;
DTMConfigurationUtil.scheduleOrUnscheduleDTMJob(this.rrf, this.workflowService, this.scheduler, currentResource, DTMServerType.PRODUCTION);
this.createOrRemoveDTMHookNode(resourceResolver, currentResource, DTMServerType.PRODUCTION, false);
continue;
}
if (change.getSource().endsWith((Object)((Object)DTMServerType.STAGING) + "UseSelfHosting")) {
isStagingUseSelfHostPresent = true;
continue;
}
if (!change.getSource().endsWith((Object)((Object)DTMServerType.PRODUCTION) + "UseSelfHosting")) continue;
isProductionUseSelfHostPresent = true;
}
if (!isStagingPollingPresent) {
this.scheduler.unschedule(DTMConfigurationUtil.getDTMJobName(dtmConfigPath, DTMServerType.STAGING));
if (isStagingUseSelfHostPresent) {
this.createOrRemoveDTMHookNode(resourceResolver, currentResource, DTMServerType.STAGING, true);
} else {
this.createOrRemoveDTMHookNode(resourceResolver, currentResource, DTMServerType.STAGING, false);
}
}
if (!isProductionPollingPresent) {
this.scheduler.unschedule(DTMConfigurationUtil.getDTMJobName(dtmConfigPath, DTMServerType.PRODUCTION));
if (isProductionUseSelfHostPresent) {
this.createOrRemoveDTMHookNode(resourceResolver, currentResource, DTMServerType.PRODUCTION, true);
} else {
this.createOrRemoveDTMHookNode(resourceResolver, currentResource, DTMServerType.STAGING, false);
}
}
}
}
private void createOrRemoveDTMHookNode(ResourceResolver resourceResolver, Resource currentResource, DTMServerType dtmServerType, boolean isCreate) throws PersistenceException {
String dtmCloudConfigName = currentResource.getParent().getName();
String dtmHookPath = "/etc/dtm-hook/" + dtmCloudConfigName + "/" + (Object)((Object)dtmServerType);
if (isCreate) {
ResourceUtil.getOrCreateResource((ResourceResolver)resourceResolver, (String)dtmHookPath, (String)"etc/dtm/hook", (String)"nt:unstructured", (boolean)true);
} else {
Resource dtmHook = resourceResolver.getResource(dtmHookPath);
if (dtmHook != null) {
resourceResolver.delete(dtmHook);
Resource dtmHookParent = dtmHook.getParent();
if (!dtmHookParent.getChildren().iterator().hasNext()) {
resourceResolver.delete(dtmHookParent);
}
resourceResolver.commit();
}
}
}
protected void bindRrf(ResourceResolverFactory resourceResolverFactory) {
this.rrf = resourceResolverFactory;
}
protected void unbindRrf(ResourceResolverFactory resourceResolverFactory) {
if (this.rrf == resourceResolverFactory) {
this.rrf = null;
}
}
protected void bindScheduler(Scheduler scheduler) {
this.scheduler = scheduler;
}
protected void unbindScheduler(Scheduler scheduler) {
if (this.scheduler == scheduler) {
this.scheduler = null;
}
}
protected void bindWorkflowService(WorkflowService workflowService) {
this.workflowService = workflowService;
}
protected void unbindWorkflowService(WorkflowService workflowService) {
if (this.workflowService == workflowService) {
this.workflowService = null;
}
}
}