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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
|
package com.c2kernel.entity.agent;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lifecycle.instance.Activity;
import com.c2kernel.lifecycle.instance.stateMachine.Transition;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.EntityPath;
import com.c2kernel.lookup.InvalidEntityPathException;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.persistency.outcome.Schema;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
import com.c2kernel.scripting.ErrorInfo;
import com.c2kernel.utils.CastorHashMap;
import com.c2kernel.utils.KeyValuePair;
import com.c2kernel.utils.Logger;
/*******************************************************************************
* @author $Author: abranson $ $Date: 2005/05/20 13:07:49 $
* @version $Revision: 1.62 $
******************************************************************************/
public class Job implements C2KLocalObject
{
// persistent
private int id;
private int itemSysKey;
private String stepName;
private String stepPath;
private String stepType;
private int transitionId;
private int currentStateId;
private int targetStateId;
private int agentId = -1;
private String agentRole;
private String schemaName;
private int schemaVersion;
private boolean outcomeRequired;
private String scriptName;
private int scriptVersion;
private CastorHashMap actProps = new CastorHashMap();
// non-persistent
private String name;
private String agentName;
private String outcomeData;
private ErrorInfo error;
private ItemProxy item = null;
private AgentProxy agent = null;
private boolean outcomeSet;
/***************************************************************************
* Empty constructor for Castor
**************************************************************************/
public Job()
{
}
public Job(Activity act, int itemSysKey, Transition transition, AgentPath agent, String role) throws InvalidDataException, ObjectNotFoundException {
setItemSysKey(itemSysKey);
setStepPath(act.getPath());
setTransitionId(transition.getId());
setCurrentStateId(transition.getOriginStateCode());
setTargetStateId(transition.getTerminalStateCode());
setStepName(act.getName());
setActProps(act.getProperties());
setStepType(act.getType());
setAgentName(agent.getAgentName());
setAgentRole(role);
if (transition.hasOutcome()) {
Schema schema = transition.getSchema(act.getProperties());
setSchemaName(schema.docType);
setSchemaVersion(schema.docVersion);
outcomeRequired = transition.getOutcome().isRequired();
}
if (transition.hasScript()) {
setScriptName(transition.getScript().getScriptName());
setScriptVersion(Integer.parseInt(transition.getScript().getScriptVersion()));
}
}
// Castor persistent fields
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
name = String.valueOf(id);
}
public int getItemSysKey() {
return itemSysKey;
}
public void setItemSysKey(int sysKey) {
itemSysKey = sysKey;
item = null;
}
public String getStepName() {
return stepName;
}
public void setStepName(String string) {
stepName = string;
}
public String getStepPath() {
return stepPath;
}
public void setStepPath(String string) {
stepPath = string;
}
public String getStepType() {
return stepType;
}
public void setStepType(String actType) {
stepType = actType;
}
public int getTransitionId() {
return transitionId;
}
public void setTransitionId(int tid) {
transitionId = tid;
}
public int getCurrentStateId() {
return currentStateId;
}
public void setCurrentStateId(int stateId) {
currentStateId = stateId;
}
public int getTargetStateId() {
return targetStateId;
}
public void setTargetStateId(int targetStateId) {
this.targetStateId = targetStateId;
}
public int getAgentId() throws ObjectNotFoundException {
if (agentId == -1)
agentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath(getAgentName()).getSysKey();
return agentId;
}
public void setAgentId(int id) {
agentId = id;
agent = null;
}
public String getAgentName()
{
if (agentName == null)
agentName = (String) actProps.get("Agent Name");
return agentName;
}
public void setAgentName(String agentName)
{
this.agentName = agentName;
}
public String getAgentRole() {
return agentRole;
}
public void setAgentRole(String role) {
agentRole = role;
}
public String getSchemaName() {
return schemaName;
}
public void setSchemaName(String schemaName) {
this.schemaName = schemaName;
}
public int getSchemaVersion() {
return schemaVersion;
}
public void setSchemaVersion(int schemaVersion) {
this.schemaVersion = schemaVersion;
}
public boolean isOutcomeRequired()
{
return outcomeRequired;
}
public void setOutcomeRequired(boolean outcomeRequired) {
this.outcomeRequired = outcomeRequired;
}
public String getScriptName() {
return scriptName;
}
public void setScriptName(String scriptName) {
this.scriptName = scriptName;
}
public int getScriptVersion() {
return scriptVersion;
}
public void setScriptVersion(int scriptVersion) {
this.scriptVersion = scriptVersion;
}
public KeyValuePair[] getKeyValuePairs() {
return actProps.getKeyValuePairs();
}
public void setKeyValuePairs(KeyValuePair[] pairs) {
actProps.setKeyValuePairs(pairs);
}
// Non-persistent fields
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
try {
id = Integer.parseInt(name);
} catch (NumberFormatException ex) {
id = -1;
}
}
public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidEntityPathException {
if (item == null)
item = (ItemProxy) Gateway.getProxyManager().getProxy(new EntityPath(itemSysKey));
return item;
}
public AgentProxy getAgentProxy() throws ObjectNotFoundException, InvalidEntityPathException {
if (agent == null)
agent = (AgentProxy) Gateway.getProxyManager().getProxy(new EntityPath(getAgentId()));
return agent;
}
public String getDescription()
{
String desc = (String) actProps.get("Description");
if (desc == null)
desc = "No Description";
return desc;
}
public void setOutcome(String outcome)
{
outcomeData = outcome;
outcomeSet = !(outcomeData == null);
}
public void setError(ErrorInfo errors)
{
error = errors;
try {
outcomeData = Gateway.getMarshaller().marshall(error);
} catch (Exception e) {
Logger.error("Error marshalling ErrorInfo in job");
Logger.error(e);
}
}
public String getOutcomeString()
{
if (outcomeData == null && isOutcomeRequired())
{
String viewName = (String) getActProp("Viewpoint");
outcomeData = null;
if (viewName.length() > 0)
try
{
Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(), ClusterStorage.VIEWPOINT + "/" + getSchemaName() + "/" + viewName, null);
outcomeData = view.getOutcome().getData();
outcomeSet = true;
} catch (Exception ex)
{
outcomeData = null;
outcomeSet = false;
}
}
return outcomeData;
}
public Outcome getOutcome()
{
return new Outcome(-1, getOutcomeString(), getSchemaName(), getSchemaVersion());
}
public boolean hasOutcome() {
return schemaName!=null;
}
public boolean hasScript() {
return scriptName!=null;
}
public boolean isOutcomeSet() {
return outcomeSet;
}
@Override
public String getClusterType()
{
return ClusterStorage.JOB;
}
public boolean equals(Job job)
{
return (getItemSysKey() == job.getItemSysKey()) && this.stepPath.equals(job.stepPath) && this.transitionId == job.transitionId;
}
private void setActProps(CastorHashMap actProps) {
this.actProps = actProps;
}
public Object getActProp(String name)
{
return actProps.get(name);
}
public String getActPropString(String name)
{
return String.valueOf(actProps.get(name));
}
// Deprecated methods from old state machine
@Deprecated
public String getSchemaType()
{
return getSchemaName();
}
@Deprecated
public int getPossibleTransition()
{
return transitionId;
}
@Deprecated
public void setPossibleTransition(int lint)
{
transitionId = lint;
}
@Deprecated
public CastorHashMap getActProps()
{
return actProps;
}
@Deprecated
public int getCurrentState()
{
return getCurrentStateId();
}
@Deprecated
public int getTargetState() {
return getTargetStateId();
}
}
|