DTMJobsInitializer.java
4.72 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.workflow.WorkflowService
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Deactivate
* org.apache.felix.scr.annotations.Reference
* org.apache.sling.api.resource.LoginException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.commons.scheduler.Scheduler
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
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.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.api.resource.LoginException;
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.commons.scheduler.Scheduler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1)
public class DTMJobsInitializer {
@Reference
ResourceResolverFactory resourceResolverFactory = null;
@Reference
private Scheduler scheduler = null;
@Reference
private WorkflowService workflowService = null;
private static final Logger LOG = LoggerFactory.getLogger(DTMJobsInitializer.class);
@Activate
public void activate(Map<String, Object> properties) {
LOG.info("Turning ON DTM Workflow triggering jobs.");
this.turnDTMJobsOnOrOff(true);
}
@Deactivate
public void deactivate(Map<String, Object> properties) {
LOG.info("Turning OFF DTM Workflow triggering jobs.");
this.turnDTMJobsOnOrOff(false);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void turnDTMJobsOnOrOff(boolean turnOnDTMJobs) {
ResourceResolver serviceResourceResolver = null;
try {
serviceResourceResolver = this.resourceResolverFactory.getServiceResourceResolver(null);
Resource dtmConfigsRoot = serviceResourceResolver.getResource("/etc/cloudservices/dynamictagmanagement");
if (dtmConfigsRoot != null) {
for (Resource dtmConfig : dtmConfigsRoot.getChildren()) {
Resource dtmConfigContent = dtmConfig.getChild("jcr:content");
if (dtmConfigContent == null) continue;
if (!turnOnDTMJobs) {
String dtmConfigPath = dtmConfig.getPath();
this.scheduler.unschedule(DTMConfigurationUtil.getDTMJobName(dtmConfigPath, DTMServerType.STAGING));
this.scheduler.unschedule(DTMConfigurationUtil.getDTMJobName(dtmConfigPath, DTMServerType.PRODUCTION));
continue;
}
DTMConfigurationUtil.scheduleOrUnscheduleDTMJob(this.resourceResolverFactory, this.workflowService, this.scheduler, dtmConfigContent, DTMServerType.STAGING);
DTMConfigurationUtil.scheduleOrUnscheduleDTMJob(this.resourceResolverFactory, this.workflowService, this.scheduler, dtmConfigContent, DTMServerType.PRODUCTION);
}
}
}
catch (LoginException e) {
LOG.error("Could not obtain a resource resolver.", (Throwable)e);
}
finally {
if (serviceResourceResolver != null) {
serviceResourceResolver.close();
}
}
}
protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resourceResolverFactory = resourceResolverFactory;
}
protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resourceResolverFactory == resourceResolverFactory) {
this.resourceResolverFactory = 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;
}
}
}