PreparePublishing.java
4.3 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.webservicesupport.Configuration
* com.day.cq.workflow.WorkflowException
* com.day.cq.workflow.WorkflowSession
* com.day.cq.workflow.exec.WorkItem
* com.day.cq.workflow.metadata.MetaDataMap
* org.apache.felix.scr.annotations.Component
* 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.PersistenceException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.mcm.campaign.impl;
import com.day.cq.mcm.campaign.ACConnectorException;
import com.day.cq.mcm.campaign.CampaignConnector;
import com.day.cq.mcm.campaign.impl.AbstractCampaignProcess;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.metadata.MetaDataMap;
import org.apache.felix.scr.annotations.Component;
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.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
@Property(name="process.label", value={"Adobe Campaign: Check prerequisites and prepare"})
public class PreparePublishing
extends AbstractCampaignProcess {
private final Logger log;
@Reference
private ResourceResolverFactory resolverFactory;
@Reference
private CampaignConnector connector;
public PreparePublishing() {
this.log = LoggerFactory.getLogger(this.getClass());
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException {
ResourceResolver resolver = this.getResourceResolver(this.resolverFactory, session);
if (resolver == null) {
throw new WorkflowException("Could not create ResourceResolver.");
}
try {
Page page = this.getPage(resolver, item);
try {
this.getWebserviceConfig(page, this.connector);
this.getTemplate(page);
}
catch (ACConnectorException e) {
this.log.info("Could not prepare publishing because of missing or invalid webservice configuration");
resolver.close();
return;
}
try {
Resource pageContent = page.getContentResource();
ModifiableValueMap props = (ModifiableValueMap)pageContent.adaptTo(ModifiableValueMap.class);
props.remove((Object)"acDelivery");
props.put((Object)"acPublishState", (Object)"prepared");
pageContent.getResourceResolver().commit();
}
catch (PersistenceException ioe) {
throw new WorkflowException("Could not modify publish status", (Throwable)ioe);
}
}
finally {
resolver.close();
}
}
protected void bindResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resolverFactory = resourceResolverFactory;
}
protected void unbindResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resolverFactory == resourceResolverFactory) {
this.resolverFactory = null;
}
}
protected void bindConnector(CampaignConnector campaignConnector) {
this.connector = campaignConnector;
}
protected void unbindConnector(CampaignConnector campaignConnector) {
if (this.connector == campaignConnector) {
this.connector = null;
}
}
}