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 for (JaxbWorkflowConfiguration config : configurations) {
182 if (config.getKey().equals(key))
183 return config.getValue();
184 }
185 return null;
186 }
187
188
189
190
191
192
193 public void removeConfiguration(String key) {
194 if (key == null || configurations == null)
195 return;
196 for (Iterator<JaxbWorkflowConfiguration> configIter = configurations.iterator(); configIter.hasNext();) {
197 JaxbWorkflowConfiguration config = configIter.next();
198 if (config.getKey().equals(key)) {
199 configIter.remove();
200 return;
201 }
202 }
203 }
204
205
206
207
208
209
210 public void setConfiguration(String key, String value) {
211 if (key == null || configurations == null)
212 return;
213 for (JaxbWorkflowConfiguration config : configurations) {
214 if (config.getKey().equals(key)) {
215 config.setValue(value);
216 return;
217 }
218 }
219
220 configurations.add(new JaxbWorkflowConfiguration(key, value));
221 }
222
223
224
225
226
227
228 @Override
229 public Set<String> getConfigurationKeys() {
230 Set<String> set = new TreeSet<String>();
231 if (configurations != null) {
232 for (JaxbWorkflowConfiguration config : configurations) {
233 set.add(config.getKey());
234 }
235 }
236 return set;
237 }
238
239
240
241
242
243
244
245 @Override
246 public RetryStrategy getRetryStrategy() {
247 return retryStrategy;
248 }
249
250
251
252
253
254 public void setRetryStrategy(RetryStrategy retryStrategy) {
255 this.retryStrategy = retryStrategy;
256 }
257
258
259
260
261
262
263 @Override
264 public int getMaxAttempts() {
265 return maxAttempts;
266 }
267
268
269
270
271
272 public void setMaxAttempts(int maxAttempts) {
273 this.maxAttempts = maxAttempts;
274 }
275
276
277
278
279
280
281 @Override
282 public String toString() {
283 return "operation definition:'" + id + "'";
284 }
285
286 }