CreateLandingPageWorkflowProcess.java
7.56 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.projects.api.Project
* com.adobe.granite.taskmanagement.Task
* com.adobe.granite.taskmanagement.TaskManager
* com.adobe.granite.taskmanagement.TaskManagerException
* com.adobe.granite.taskmanagement.TaskManagerFactory
* com.adobe.granite.workflow.WorkflowException
* com.adobe.granite.workflow.WorkflowSession
* com.adobe.granite.workflow.exec.WorkItem
* com.adobe.granite.workflow.exec.WorkflowData
* com.adobe.granite.workflow.exec.WorkflowProcess
* com.adobe.granite.workflow.metadata.MetaDataMap
* com.day.cq.commons.jcr.JcrUtil
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.PageManager
* com.day.cq.wcm.api.PageManagerFactory
* com.day.cq.wcm.designimporter.CanvasBuildOptions
* com.day.cq.wcm.designimporter.DesignImportResult
* com.day.cq.wcm.designimporter.DesignPackageImporter
* 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.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.projects.wcm.impl.workflow;
import com.adobe.cq.projects.api.Project;
import com.adobe.cq.projects.wcm.impl.workflow.AbstractWCMProjectProcess;
import com.adobe.granite.taskmanagement.Task;
import com.adobe.granite.taskmanagement.TaskManager;
import com.adobe.granite.taskmanagement.TaskManagerException;
import com.adobe.granite.taskmanagement.TaskManagerFactory;
import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowData;
import com.adobe.granite.workflow.exec.WorkflowProcess;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.PageManagerFactory;
import com.day.cq.wcm.designimporter.CanvasBuildOptions;
import com.day.cq.wcm.designimporter.DesignImportResult;
import com.day.cq.wcm.designimporter.DesignPackageImporter;
import java.util.Calendar;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service(value={WorkflowProcess.class})
@Properties(value={@Property(name="service.description", value={"Create Landing Page Workflow Process"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"WCM: Create Landing Page Process"})})
public class CreateLandingPageWorkflowProcess
extends AbstractWCMProjectProcess {
private static final Logger log = LoggerFactory.getLogger(CreateLandingPageWorkflowProcess.class);
private static final String NAME_PARENT_PATH = "parentPath";
@Reference
private PageManagerFactory pageManagerFactory;
@Reference
private DesignPackageImporter designPackageImporter;
public void execute(WorkItem item, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
log.debug("creating landing page for workitem {}", (Object)(item != null ? item.getId() : "<null>"));
ResourceResolver resourceResolver = (ResourceResolver)workflowSession.adaptTo(ResourceResolver.class);
MetaDataMap metaData = item.getWorkflowData().getMetaDataMap();
String contentPath = this.getPayloadPath(item.getWorkflowData());
if (StringUtils.isEmpty((CharSequence)contentPath)) {
throw new WorkflowException("Failed to load content path from payload");
}
Resource landingResource = resourceResolver.getResource(contentPath);
if (landingResource == null) {
throw new WorkflowException("Failed to load content resource from payload");
}
String title = this.getStringParam(metaData, "workflowTitle", true, null);
String parentPath = this.getStringParam(metaData, "parentPath", true, null);
String designPackagePath = this.getDesignPackagePath(metaData, resourceResolver);
Calendar liveDate = this.getCalendarParam(metaData, "liveDate", false, null);
if (liveDate != null) {
metaData.put((Object)"absoluteTime", (Object)liveDate.getTimeInMillis());
}
try {
Resource projectResource;
Project project;
PageManager pm = this.pageManagerFactory.getPageManager(resourceResolver);
Page landingPage = pm.create(parentPath, JcrUtil.createValidName((String)title), "/libs/wcm/designimporter/templates/importerpage", title);
this.designPackageImporter.importDesignPackage(landingPage, designPackagePath, null);
String newPayloadPath = landingPage.getPath();
this.updateWorkflowPayload(item, workflowSession, newPayloadPath);
Resource workLinkResource = this.getProjectWorkLink(item.getWorkflowData(), resourceResolver);
if (workLinkResource != null) {
ModifiableValueMap valueMap = (ModifiableValueMap)workLinkResource.adaptTo(ModifiableValueMap.class);
valueMap.put((Object)"suffix", (Object)newPayloadPath);
}
if ((projectResource = (Resource)(project = this.getProject(item.getWorkflowData(), resourceResolver)).adaptTo(Resource.class)) != null) {
TaskManager taskManager = this.getTaskManager(projectResource);
Task task = taskManager.getTaskManagerFactory().newTask(landingPage.getTitle());
task.setCurrentAssignee(item.getCurrentAssignee());
task.setContentPath(newPayloadPath);
task.setName("Landing Page Creation Complete");
task.setDescription("The landing page creation has been completed. Please see payload for this task for the final result. An approval process has started.");
taskManager.createTask(task);
}
}
catch (TaskManagerException e) {
throw new WorkflowException("Failed to add task to " + landingResource.getPath(), (Throwable)e);
}
catch (Exception e) {
log.error("Error during execution of landing page creation process.", (Throwable)e);
throw new WorkflowException(e.getMessage());
}
}
protected void bindPageManagerFactory(PageManagerFactory pageManagerFactory) {
this.pageManagerFactory = pageManagerFactory;
}
protected void unbindPageManagerFactory(PageManagerFactory pageManagerFactory) {
if (this.pageManagerFactory == pageManagerFactory) {
this.pageManagerFactory = null;
}
}
protected void bindDesignPackageImporter(DesignPackageImporter designPackageImporter) {
this.designPackageImporter = designPackageImporter;
}
protected void unbindDesignPackageImporter(DesignPackageImporter designPackageImporter) {
if (this.designPackageImporter == designPackageImporter) {
this.designPackageImporter = null;
}
}
}