1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.workflow.api;
23
24 import java.util.Iterator;
25 import java.util.Set;
26 import java.util.TreeSet;
27
28 import javax.xml.bind.annotation.XmlAccessType;
29 import javax.xml.bind.annotation.XmlAccessorType;
30 import javax.xml.bind.annotation.XmlAttribute;
31 import javax.xml.bind.annotation.XmlElement;
32 import javax.xml.bind.annotation.XmlElementWrapper;
33 import javax.xml.bind.annotation.XmlRootElement;
34 import javax.xml.bind.annotation.XmlType;
35 import javax.xml.bind.annotation.adapters.XmlAdapter;
36 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
37
38
39
40
41 @XmlType(name = "operation-definition", namespace = "http://workflow.opencastproject.org")
42 @XmlRootElement(name = "operation-definition", namespace = "http://workflow.opencastproject.org")
43 @XmlAccessorType(XmlAccessType.FIELD)
44 public class WorkflowOperationDefinitionImpl implements WorkflowOperationDefinition {
45
46 @XmlAttribute(name = "id")
47 protected String id;
48
49 @XmlAttribute(name = "description")
50 protected String description;
51
52 @XmlAttribute(name = "fail-on-error")
53 protected boolean failWorkflowOnException;
54
55 @XmlAttribute(name = "if")
56 protected String executeCondition;
57
58 @XmlAttribute(name = "unless")
59 protected String skipCondition;
60
61 @XmlAttribute(name = "exception-handler-workflow")
62 protected String exceptionHandlingWorkflow;
63
64 @XmlElement(name = "configuration")
65 @XmlElementWrapper(name = "configurations")
66 protected Set<JaxbWorkflowConfiguration> configurations;
67
68 @XmlAttribute(name = "max-attempts")
69 protected int maxAttempts;
70
71 @XmlJavaTypeAdapter(RetryStrategy.Adapter.class)
72 @XmlAttribute(name = "retry-strategy")
73 protected RetryStrategy retryStrategy;
74
75
76 public WorkflowOperationDefinitionImpl() {
77 super();
78 this.maxAttempts = 1;
79 this.failWorkflowOnException = true;
80 this.retryStrategy = RetryStrategy.NONE;
81 }
82
83
84
85
86
87
88
89
90
91
92
93 public WorkflowOperationDefinitionImpl(String id, String description, String exceptionHandlingWorkflow,
94 boolean failWorkflowOnException) {
95 this();
96 this.id = id;
97 this.description = description;
98 this.exceptionHandlingWorkflow = exceptionHandlingWorkflow;
99 this.failWorkflowOnException = failWorkflowOnException;
100 }
101
102 public String getId() {
103 return id;
104 }
105
106 public void setId(String id) {
107 this.id = id;
108 }
109
110 public String getDescription() {
111 return description;
112 }
113
114 public void setDescription(String description) {
115 this.description = description;
116 }
117
118 public void setExecutionCondition(String condition) {
119 this.executeCondition = condition;
120 }
121
122 public String getExecutionCondition() {
123 return executeCondition;
124 }
125
126 public void setSkipCondition(String condition) {
127 this.skipCondition = condition;
128 }
129
130 public String getSkipCondition() {
131 return skipCondition;
132 }
133
134
135
136
137
138
139 public String getExceptionHandlingWorkflow() {
140 return exceptionHandlingWorkflow;
141 }
142
143 public void setExceptionHandlingWorkflow(String exceptionHandlingWorkflow) {
144 this.exceptionHandlingWorkflow = exceptionHandlingWorkflow;
145 }
146
147
148
149
150
151
152 public boolean isFailWorkflowOnException() {
153 return failWorkflowOnException;
154 }
155
156 public void setFailWorkflowOnException(boolean failWorkflowOnException) {
157 this.failWorkflowOnException = failWorkflowOnException;
158 }
159
160
161
162
163 static class Adapter extends XmlAdapter<WorkflowOperationDefinitionImpl, WorkflowOperationDefinition> {
164 public WorkflowOperationDefinitionImpl marshal(WorkflowOperationDefinition op) throws Exception {
165 return (WorkflowOperationDefinitionImpl) op;
166 }
167
168 public WorkflowOperationDefinition unmarshal(WorkflowOperationDefinitionImpl op) throws Exception {
169 return op;
170 }
171 }
172
173
174
175
176
177
178 public String getConfiguration(String key) {
179 if (key == null || configurations == null) {
180 return null;
181 }
182 for (JaxbWorkflowConfiguration config : configurations) {
183 if (config.getKey().equals(key)) {
184 return config.getValue();
185 }
186 }
187 return null;
188 }
189
190
191
192
193
194
195 public void removeConfiguration(String key) {
196 if (key == null || configurations == null) {
197 return;
198 }
199 for (Iterator<JaxbWorkflowConfiguration> configIter = configurations.iterator(); configIter.hasNext();) {
200 JaxbWorkflowConfiguration config = configIter.next();
201 if (config.getKey().equals(key)) {
202 configIter.remove();
203 return;
204 }
205 }
206 }
207
208
209
210
211
212
213 public void setConfiguration(String key, String value) {
214 if (key == null || configurations == null) {
215 return;
216 }
217 for (JaxbWorkflowConfiguration config : configurations) {
218 if (config.getKey().equals(key)) {
219 config.setValue(value);
220 return;
221 }
222 }
223
224 configurations.add(new JaxbWorkflowConfiguration(key, value));
225 }
226
227
228
229
230
231
232 @Override
233 public Set<String> getConfigurationKeys() {
234 Set<String> set = new TreeSet<String>();
235 if (configurations != null) {
236 for (JaxbWorkflowConfiguration config : configurations) {
237 set.add(config.getKey());
238 }
239 }
240 return set;
241 }
242
243
244
245
246
247
248
249 @Override
250 public RetryStrategy getRetryStrategy() {
251 return retryStrategy;
252 }
253
254
255
256
257
258 public void setRetryStrategy(RetryStrategy retryStrategy) {
259 this.retryStrategy = retryStrategy;
260 }
261
262
263
264
265
266
267 @Override
268 public int getMaxAttempts() {
269 return maxAttempts;
270 }
271
272
273
274
275
276 public void setMaxAttempts(int maxAttempts) {
277 this.maxAttempts = maxAttempts;
278 }
279
280
281
282
283
284
285 @Override
286 public String toString() {
287 return "operation definition:'" + id + "'";
288 }
289
290 }