WorkflowLauncherImpl.java
7.96 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.workflow.WorkflowException
* com.adobe.granite.workflow.launcher.ConfigEntry
* com.adobe.granite.workflow.launcher.WorkflowLauncher
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.adapter.AdapterManager
* org.apache.sling.jcr.api.SlingRepository
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.workflow.launcher.impl;
import com.adobe.granite.workflow.WorkflowException;
import com.day.cq.workflow.launcher.ConfigEntry;
import com.day.cq.workflow.launcher.WorkflowLauncher;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
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.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.adapter.AdapterManager;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0, label="%cq.workflow.launcher.name", description="%cq.workflow.launcher.description")
@Property(name="service.description", value={"%cq.workflow.launcher.description"})
@Service(value={WorkflowLauncher.class})
public class WorkflowLauncherImpl
implements WorkflowLauncher {
private static final Logger log = LoggerFactory.getLogger(WorkflowLauncherImpl.class);
@Reference(policy=ReferencePolicy.STATIC)
private AdapterManager adapterManager = null;
@Reference(policy=ReferencePolicy.STATIC)
private SlingRepository repository = null;
private com.adobe.granite.workflow.launcher.WorkflowLauncher graniteLauncherConfig = null;
public WorkflowLauncherImpl() {
}
public WorkflowLauncherImpl(com.adobe.granite.workflow.launcher.WorkflowLauncher graniteLauncherConfig) {
this.graniteLauncherConfig = graniteLauncherConfig;
}
@Override
public void addConfigEntry(ConfigEntry entry) throws RepositoryException {
com.adobe.granite.workflow.launcher.ConfigEntry graniteConfigEntry = WorkflowLauncherImpl.translate(entry);
Session session = null;
try {
com.adobe.granite.workflow.launcher.WorkflowLauncher graniteLauncher = this.graniteLauncherConfig;
if (graniteLauncher == null) {
session = this.getWorkflowServiceSession();
graniteLauncher = (com.adobe.granite.workflow.launcher.WorkflowLauncher)this.adapterManager.getAdapter((Object)session, com.adobe.granite.workflow.launcher.WorkflowLauncher.class);
}
graniteLauncher.addConfigEntry(graniteConfigEntry);
session.save();
}
catch (WorkflowException e) {
throw new RepositoryException("Error adding config entry", (Throwable)e);
}
finally {
if (session != null && session.isLive()) {
session.logout();
}
}
}
private static com.adobe.granite.workflow.launcher.ConfigEntry translate(ConfigEntry entry) {
return new com.adobe.granite.workflow.launcher.ConfigEntry(entry.getEventType(), entry.getGlob(), entry.getNodetype(), entry.getWhereClause(), entry.getWorkflow(), entry.getId(), entry.getDescription(), entry.isEnabled(), entry.getExcludeList(), entry.getRunModes());
}
private static ConfigEntry translate(com.adobe.granite.workflow.launcher.ConfigEntry entry) {
return new ConfigEntry(entry.getEventType(), entry.getGlob(), entry.getNodetype(), entry.getWhereClause(), entry.getWorkflow(), entry.getId(), entry.getDescription(), entry.isEnabled(), entry.getExcludeList(), entry.getRunModes());
}
@Override
public void removeConfigEntry(String id) throws RepositoryException {
Session session = null;
try {
com.adobe.granite.workflow.launcher.WorkflowLauncher graniteLauncher = this.graniteLauncherConfig;
if (graniteLauncher == null) {
session = this.getWorkflowServiceSession();
graniteLauncher = (com.adobe.granite.workflow.launcher.WorkflowLauncher)this.adapterManager.getAdapter((Object)session, com.adobe.granite.workflow.launcher.WorkflowLauncher.class);
}
graniteLauncher.removeConfigEntry(id);
session.save();
}
catch (WorkflowException e) {
throw new RepositoryException("Error removing config entry", (Throwable)e);
}
finally {
if (session != null && session.isLive()) {
session.logout();
}
}
}
@Override
public List<ConfigEntry> getConfigEntries() {
ArrayList<ConfigEntry> entries;
Session session = null;
entries = new ArrayList<ConfigEntry>();
try {
com.adobe.granite.workflow.launcher.WorkflowLauncher graniteLauncher = this.graniteLauncherConfig;
if (graniteLauncher == null) {
session = this.getWorkflowServiceSession();
graniteLauncher = (com.adobe.granite.workflow.launcher.WorkflowLauncher)this.adapterManager.getAdapter((Object)session, com.adobe.granite.workflow.launcher.WorkflowLauncher.class);
}
Iterator graniteIterator = graniteLauncher.getConfigEntries();
while (graniteIterator.hasNext()) {
entries.add(WorkflowLauncherImpl.translate((com.adobe.granite.workflow.launcher.ConfigEntry)graniteIterator.next()));
}
}
catch (WorkflowException e) {
log.error("Error retrieving config entries", (Throwable)e);
throw new RuntimeException((Throwable)e);
}
finally {
if (session != null && session.isLive()) {
session.logout();
}
}
return entries;
}
@Override
public void editConfigEntry(String id, ConfigEntry configEntry) throws RepositoryException {
Session session = null;
try {
com.adobe.granite.workflow.launcher.WorkflowLauncher graniteLauncher = this.graniteLauncherConfig;
if (graniteLauncher == null) {
session = this.getWorkflowServiceSession();
graniteLauncher = (com.adobe.granite.workflow.launcher.WorkflowLauncher)this.adapterManager.getAdapter((Object)session, com.adobe.granite.workflow.launcher.WorkflowLauncher.class);
}
graniteLauncher.editConfigEntry(id, WorkflowLauncherImpl.translate(configEntry));
session.save();
}
catch (WorkflowException e) {
throw new RepositoryException("Error editing config entry", (Throwable)e);
}
finally {
if (session != null && session.isLive()) {
session.logout();
}
}
}
private Session getWorkflowServiceSession() {
try {
return this.repository.loginService(null, null);
}
catch (RepositoryException e) {
throw new RuntimeException("Unable to create workflow service session.", (Throwable)e);
}
}
protected void bindAdapterManager(AdapterManager adapterManager) {
this.adapterManager = adapterManager;
}
protected void unbindAdapterManager(AdapterManager adapterManager) {
if (this.adapterManager == adapterManager) {
this.adapterManager = null;
}
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
}