CreateLanguageCopyLaunchProcess.java
7.62 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.launches.api.Launch
* com.adobe.cq.launches.api.LaunchManager
* com.adobe.cq.launches.api.LaunchManager$CreateOptions
* com.adobe.cq.launches.api.LaunchManagerFactory
* com.day.cq.workflow.WorkflowException
* com.day.cq.workflow.WorkflowSession
* com.day.cq.workflow.exec.WorkItem
* com.day.cq.workflow.exec.WorkflowData
* com.day.cq.workflow.exec.WorkflowProcess
* com.day.cq.workflow.metadata.MetaDataMap
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.ModifiableValueMap
* 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.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.wcm.translation.impl.process;
import com.adobe.cq.launches.api.Launch;
import com.adobe.cq.launches.api.LaunchManager;
import com.adobe.cq.launches.api.LaunchManagerFactory;
import com.adobe.cq.wcm.translation.impl.process.AbstractWCMTranslationProcess;
import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.WorkflowData;
import com.day.cq.workflow.exec.WorkflowProcess;
import com.day.cq.workflow.metadata.MetaDataMap;
import java.util.Calendar;
import java.util.Collections;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ModifiableValueMap;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service(value={WorkflowProcess.class})
@Properties(value={@Property(name="service.description", value={"Create Launch for Language Copy Workflow Process"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"WCM: Create Launch for Language Copy Process"})})
public class CreateLanguageCopyLaunchProcess
extends AbstractWCMTranslationProcess {
private static final Logger log = LoggerFactory.getLogger(CreateLanguageCopyLaunchProcess.class);
private static final String META_TITLE = "workflowLaunchTitle";
private static final String META_LIVE_DATE = "liveDate";
private static final String PROP_IS_UPDATE_LANGUAGE_COPY = "isUpdateLanguageCopy";
@Reference
private ResourceResolverFactory resourceResolverFactory = null;
@Reference
LaunchManagerFactory launchesManagerFactory = null;
public void execute(WorkItem item, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
log.debug("creating launch for workitem {}", (Object)(item != null ? item.getId() : "<null>"));
String processArgs = (String)args.get("PROCESS_ARGS", String.class);
if (processArgs == null) {
throw new WorkflowException("Provide launch rollout configs as process arguments");
}
String[] arguments = processArgs.trim().split(" ");
if (arguments.length != 3) {
throw new WorkflowException("Provide 3 rollout configs: source rollout, source rollout (shallow) and promote rollout");
}
String sourceRolloutConfig = arguments[0];
String sourceRolloutConfigShallow = arguments[1];
String promoteRolloutConfig = arguments[2];
ResourceResolver resourceResolver = null;
try {
resourceResolver = this.resourceResolverFactory.getServiceResourceResolver(Collections.singletonMap("sling.service.subservice", "translation-job"));
LaunchManager launchManager = this.launchesManagerFactory.getLaunchManager(resourceResolver);
WorkflowData data = item.getWorkflowData();
MetaDataMap metaData = data.getMetaDataMap();
String payloadData = this.getPayloadPath(data);
Resource launchResource = resourceResolver.getResource(payloadData);
if (launchResource == null || ResourceUtil.isNonExistingResource((Resource)launchResource)) {
throw new WorkflowException("Failed to load content path from payload");
}
String masterLanguage = (String)metaData.get("language", String.class);
if (StringUtils.isEmpty((CharSequence)masterLanguage)) {
throw new WorkflowException("Failed to load master language from payload.");
}
String title = (String)metaData.get("workflowLaunchTitle", String.class);
Calendar liveDate = (Calendar)metaData.get("liveDate", Calendar.class);
boolean deep = "true".equals(metaData.get("deep", String.class));
LaunchManager.CreateOptions options = new LaunchManager.CreateOptions();
options.resource = launchResource;
options.title = title;
options.liveDate = liveDate;
options.isDeep = deep;
options.isLiveCopy = false;
String[] arrstring = new String[1];
arrstring[0] = deep ? sourceRolloutConfig : sourceRolloutConfigShallow;
options.sourceRolloutConfigs = arrstring;
options.promoteRolloutConfigs = new String[]{promoteRolloutConfig};
Launch launch = launchManager.createLaunch(options);
if (launch != null) {
Resource contentResource = launch.getResource().getChild("jcr:content");
if (contentResource != null) {
ModifiableValueMap properties = (ModifiableValueMap)contentResource.adaptTo(ModifiableValueMap.class);
properties.put((Object)"isUpdateLanguageCopy", (Object)true);
contentResource.getResourceResolver().commit();
}
String newPayloadPath = launch.getResource().getPath();
this.updateWorkflowData(item, workflowSession, "launchRootResourcePath", newPayloadPath);
}
}
catch (Exception e) {
log.error("Error during execution of launch creation for language copy process.", (Throwable)e);
throw new WorkflowException((Throwable)e);
}
finally {
if (resourceResolver != null && resourceResolver.isLive()) {
resourceResolver.close();
}
}
}
protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resourceResolverFactory = resourceResolverFactory;
}
protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resourceResolverFactory == resourceResolverFactory) {
this.resourceResolverFactory = null;
}
}
protected void bindLaunchesManagerFactory(LaunchManagerFactory launchManagerFactory) {
this.launchesManagerFactory = launchManagerFactory;
}
protected void unbindLaunchesManagerFactory(LaunchManagerFactory launchManagerFactory) {
if (this.launchesManagerFactory == launchManagerFactory) {
this.launchesManagerFactory = null;
}
}
}