CreateLanguageCopyProcess.java
6.64 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.LanguageUtil
* 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
* com.day.text.Text
* javax.jcr.Session
* 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.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.wcm.translation.impl.TranslationLanguageCopy;
import com.adobe.cq.wcm.translation.impl.process.AbstractWCMTranslationProcess;
import com.day.cq.commons.LanguageUtil;
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 com.day.text.Text;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import javax.jcr.Session;
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.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 Language Copy Workflow Process"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"WCM: Create Language Copy Process"})})
public class CreateLanguageCopyProcess
extends AbstractWCMTranslationProcess {
private static final Logger log = LoggerFactory.getLogger(CreateLanguageCopyProcess.class);
private static final String META_CREATE_NON_EMPTY_ANCESTORS_PARAM = "createNonEmptyAncestors";
@Reference
private ResourceResolverFactory resourceResolverFactory = null;
public void execute(WorkItem item, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
log.debug("Creating language copy for workitem {}", (Object)(item != null ? item.getId() : "<null>"));
ResourceResolver resourceResolver = null;
String payloadData = null;
String destinationPath = null;
try {
resourceResolver = this.resourceResolverFactory.getServiceResourceResolver(Collections.singletonMap("sling.service.subservice", "translation-job"));
Session session = (Session)resourceResolver.adaptTo(Session.class);
WorkflowData data = item.getWorkflowData();
MetaDataMap metaData = data.getMetaDataMap();
boolean deep = "true".equals(metaData.get("deep", String.class));
boolean copyMissingAncestors = "true".equals(metaData.get("createNonEmptyAncestors", String.class));
String translationWorkflowModel = (String)metaData.get("translationWorkflowModel", String.class);
String strProjectFolderPath = (String)metaData.get("projectFolderPath", String.class);
payloadData = this.getPayloadPath(data);
Resource pageResource = resourceResolver.getResource(payloadData);
if (pageResource == null || ResourceUtil.isNonExistingResource((Resource)pageResource)) {
throw new WorkflowException("Failed to load source path from payload.");
}
String langRootPagePath = LanguageUtil.getLanguageRoot((String)payloadData);
if (langRootPagePath == null) {
throw new WorkflowException("Language root page does not exist.");
}
String contentPath = Text.getRelativeParent((String)langRootPagePath, (int)1);
String pagePath = langRootPagePath.equals(payloadData) ? "" : "" + '/' + payloadData.substring(langRootPagePath.length() + 1);
String destLanguage = (String)metaData.get("language", String.class);
if (StringUtils.isEmpty((CharSequence)destLanguage)) {
throw new WorkflowException("Failed to load destination language from payload.");
}
String destLanguageTitle = LanguageUtil.getLanguage((String)destLanguage).getLocale().getDisplayName();
if (StringUtils.isEmpty((CharSequence)destLanguageTitle)) {
throw new WorkflowException("Destination language does not exist.");
}
destinationPath = contentPath + '/' + destLanguage + pagePath;
Resource destResource = resourceResolver.getResource(destinationPath);
if (destResource != null) {
throw new WorkflowException("Language copy already exists.");
}
destResource = TranslationLanguageCopy.createLanguagePage(resourceResolver, session, payloadData, destinationPath, destLanguage, copyMissingAncestors, deep);
metaData.remove((Object)"language");
this.startTranslationWorkflow(translationWorkflowModel, strProjectFolderPath, item, workflowSession, destinationPath, payloadData, metaData);
}
catch (Exception e) {
log.error("Error while creating the copy for {} at {}.", new Object[]{payloadData, destinationPath});
throw new WorkflowException("Error while creating the copy of " + payloadData + " at " + destinationPath + ".", (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;
}
}
}