DeletePageProcess.java
3.66 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* 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
* javax.jcr.Node
* javax.jcr.RepositoryException
* javax.jcr.Session
* 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.jcr.resource.JcrResourceResolverFactory
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.workflow.process;
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 javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
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.jcr.resource.JcrResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service(value={WorkflowProcess.class})
@Properties(value={@Property(name="process.label", value={"Delete Page"})})
public class DeletePageProcess
implements WorkflowProcess {
@Reference
protected JcrResourceResolverFactory jcrResourceResolverFactory;
private static final Logger log = LoggerFactory.getLogger(DeletePageProcess.class);
private static final String TYPE_JCR_PATH = "JCR_PATH";
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
try {
String payloadData;
Session session = workflowSession.getSession();
ResourceResolver resolver = this.jcrResourceResolverFactory.getResourceResolver(session);
WorkflowData data = workItem.getWorkflowData();
String path = null;
String type = data.getPayloadType();
if (type.equals("JCR_PATH") && data.getPayload() != null && session.itemExists(payloadData = (String)data.getPayload())) {
path = payloadData;
}
if (path == null) {
throw new WorkflowException("No path was given for the workflow");
}
Resource resource = resolver.getResource(path);
Node node = (Node)resource.adaptTo(Node.class);
if (session.nodeExists(node.getPath())) {
node.remove();
}
session.save();
}
catch (RepositoryException e) {
throw new WorkflowException((Throwable)e);
}
}
protected void bindJcrResourceResolverFactory(JcrResourceResolverFactory jcrResourceResolverFactory) {
this.jcrResourceResolverFactory = jcrResourceResolverFactory;
}
protected void unbindJcrResourceResolverFactory(JcrResourceResolverFactory jcrResourceResolverFactory) {
if (this.jcrResourceResolverFactory == jcrResourceResolverFactory) {
this.jcrResourceResolverFactory = null;
}
}
}