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
|
/**************************************************************************
* ItemProxy.java
*
* $Revision: 1.25 $
* $Date: 2005/05/10 11:40:09 $
*
* Copyright (C) 2001 CERN - European Organization for Nuclear Research
* All rights reserved.
**************************************************************************/
package com.c2kernel.entity.proxy;
import java.util.ArrayList;
import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.common.ObjectAlreadyExistsException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.Item;
import com.c2kernel.entity.ItemHelper;
import com.c2kernel.entity.ManageableEntity;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.entity.agent.JobArrayList;
import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
/******************************************************************************
* It is a wrapper for the connection and communication with Item
* It caches data loaded from the Item to reduce communication
*
* @version $Revision: 1.25 $ $Date: 2005/05/10 11:40:09 $
* @author $Author: abranson $
******************************************************************************/
public class ItemProxy extends EntityProxy
{
/**************************************************************************
*
**************************************************************************/
protected ItemProxy( org.omg.CORBA.Object ior,
int systemKey)
throws ObjectNotFoundException
{
super(ior, systemKey);
}
@Override
public ManageableEntity narrow() throws ObjectNotFoundException
{
try {
return ItemHelper.narrow(mIOR);
} catch (org.omg.CORBA.BAD_PARAM ex) { }
throw new ObjectNotFoundException("CORBA Object was not an Item, or the server is down.");
}
/**************************************************************************
*
*
**************************************************************************/
public void initialise( int agentId,
String itemProps,
String workflow )
throws AccessRightsException,
InvalidDataException,
PersistencyException,
ObjectNotFoundException
{
Logger.msg(7, "ItemProxy::initialise - started");
((Item)getEntity()).initialise( agentId, itemProps, workflow );
}
public void setProperty(AgentProxy agent, String name, String value)
throws AccessRightsException,
PersistencyException
{
String[] params = new String[2];
params[0] = name;
params[1] = value;
try {
agent.execute(this, "WriteProperty", params);
} catch (AccessRightsException e) {
throw (e);
} catch (PersistencyException e) {
throw (e);
} catch (Exception e) {
Logger.error(e);
throw new PersistencyException("Could not store property");
}
}
/**************************************************************************
*
**************************************************************************/
protected void requestAction( Job thisJob )
throws AccessRightsException,
InvalidTransitionException,
ObjectNotFoundException,
InvalidDataException,
PersistencyException,
ObjectAlreadyExistsException
{
String outcome = thisJob.getOutcomeString();
// check fields that should have been filled in
if (outcome==null)
if (thisJob.isOutcomeUsed())
throw new InvalidDataException("Outcome is required.", "");
else
outcome="";
if (thisJob.getAgentId() == -1)
throw new InvalidDataException("No Agent specified.", "");
Logger.msg(7, "ItemProxy - executing "+thisJob.getStepPath()+" for "+thisJob.getAgentName());
requestAction (thisJob.getAgentId(), thisJob.getStepPath(),
thisJob.getPossibleTransition(), outcome);
}
//requestData is xmlString
public void requestAction( int agentId,
String stepPath,
int transitionID,
String requestData
)
throws AccessRightsException,
InvalidTransitionException,
ObjectNotFoundException,
InvalidDataException,
PersistencyException,
ObjectAlreadyExistsException
{
((Item)getEntity()).requestAction( agentId,
stepPath,
transitionID,
requestData );
}
/**************************************************************************
*
**************************************************************************/
public String queryLifeCycle( int agentId,
boolean filter
)
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException
{
return ((Item)getEntity()).queryLifeCycle( agentId,
filter );
}
/**************************************************************************
*
**************************************************************************/
private ArrayList<Job> getJobList(int agentId, boolean filter)
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException
{
JobArrayList thisJobList;
try {
String jobs = queryLifeCycle(agentId, filter);
thisJobList = (JobArrayList)Gateway.getMarshaller().unmarshall(jobs);
}
catch (Exception e) {
Logger.error(e);
throw new PersistencyException("Exception::ItemProxy::getJobList() - Cannot unmarshall the jobs", null);
}
return thisJobList.list;
}
public ArrayList<Job> getJobList(AgentProxy agent)
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException
{
return getJobList(agent.getSystemKey());
}
private ArrayList<Job> getJobList(int agentId)
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException
{
return getJobList(agentId, true);
}
private Job getJobByName(String actName, int agentId)
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException {
ArrayList<Job> jobList = getJobList(agentId);
for (Job job : jobList) {
int transition = job.getPossibleTransition();
if (job.getStepName().equals(actName))
if (transition == Transitions.COMPLETE || transition == Transitions.DONE)
return job;
}
return null;
}
public Job getJobByName(String actName, AgentProxy agent)
throws AccessRightsException,
ObjectNotFoundException,
PersistencyException {
return getJobByName(actName, agent.getSystemKey());
}
}
|