summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java
blob: 33c80a483e91d090bbc019abf7956721eb380f26 (plain)
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
package com.c2kernel.lifecycle.instance;
import java.util.ArrayList;
import java.util.UUID;

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.C2KLocalObject;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.events.History;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.graph.model.TypeNameAndConstructionInfo;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.InvalidAgentPathException;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.utils.Language;
import com.c2kernel.utils.Logger;
/**
 * @version $Revision: 1.64 $ $Date: 2005/09/30 07:09:48 $
 * @author $Author: abranson $
 */
public class Workflow extends CompositeActivity implements C2KLocalObject
{
	public History history;
	private ItemPath itemPath = null;
	
	/** TypeNameAndConstructionInfo[] variables added by Steve */
	private final TypeNameAndConstructionInfo[] mVertexTypeNameAndConstructionInfo =
		{
			new TypeNameAndConstructionInfo(Language.translate("AND Split"), "AndSplit"),
			new TypeNameAndConstructionInfo(Language.translate("OR Split"), "OrSplit"),
			new TypeNameAndConstructionInfo(Language.translate("XOR Split"), "XOrSplit"),
			new TypeNameAndConstructionInfo(Language.translate("Join"), "Join"),
			new TypeNameAndConstructionInfo(Language.translate("Loop"), "LoopSplit"),
			new TypeNameAndConstructionInfo(Language.translate("Activity"), "Atomic"),
			new TypeNameAndConstructionInfo(Language.translate("Composite"), "Composite")
			};
	private final TypeNameAndConstructionInfo[] mEdgeTypeNameAndConstructionInfo =
		{
			new TypeNameAndConstructionInfo(Language.translate("Next"), "Next")
		};
	/**
	 * @see java.lang.Object#Object()
	 */
	public Workflow()
	{
	}

	public Workflow(CompositeActivity domain, PredefinedStepContainer predef) {
		this();
		domain.setName("domain");
		initChild(domain, true, new GraphPoint(150, 100));
		addChild(predef, new GraphPoint(300, 100));
	}
	
	public History getHistory() throws InvalidDataException {
		if (history == null) {
			if (itemPath == null)
				throw new InvalidDataException("Workflow not initialized.", "");
			history = new History(itemPath, this);
		}
		return history;
	}

	/**
	 * Method getVertexTypeNameAndConstructionInfo.
	 *
	 * @return TypeNameAndConstructionInfo[]
	 */
	/** getVertexTypeNameAndConstructionInfo() added by Steve */
	public TypeNameAndConstructionInfo[] getVertexTypeNameAndConstructionInfo()
	{
		return mVertexTypeNameAndConstructionInfo;
	}
	/**
	 * Method getEdgeTypeNameAndConstructionInfo.
	 *
	 * @return TypeNameAndConstructionInfo[]
	 */
	/** getVertexTypeNameAndConstructionInfo() added by Steve */
	public TypeNameAndConstructionInfo[] getEdgeTypeNameAndConstructionInfo()
	{
		return mEdgeTypeNameAndConstructionInfo;
	}
	/**
	 * Method requestAction.
	 *
	 * @param agentInfo
	 * @param stepPath
	 * @param transitionID
	 * @param reguestData
	 * @throws ObjectNotFoundException
	 * @throws AccessRightsException
	 * @throws InvalidTransitionException
	 * @throws InvalidDataException
	 * @throws PersistencyException 
	 */
	//requestData is xmlstring
	public String requestAction(AgentPath agent, String stepPath, ItemPath itemPath, int transitionID, String requestData)
		throws ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, PersistencyException
	{
		Logger.msg(3, "Action: " + transitionID + " " + stepPath + " by " + agent);
		if (search(stepPath) != null)
			 return ((Activity) search(stepPath)).request(agent, itemPath, transitionID, requestData);
		else
			throw new ObjectNotFoundException(stepPath + " not found", "");
	}

	/**
	 * @see com.c2kernel.graph.model.GraphableVertex#getPath()
	 */
	@Override
	public String getPath()
	{
		return "workflow";
	}
	/**
	 * @see com.c2kernel.graph.model.Vertex#getName()
	 */
	@Override
	public String getName()
	{
		return "workflow";
	}
	/**
	 * @see com.c2kernel.lifecycle.instance.Activity#getType()
	 */
	@Override
	public String getType()
	{
		return "workflow";
	}
	/**
	 * @see com.c2kernel.graph.model.Vertex#setName(java.lang.String)
	 */
	@Override
	public void setName(String name)
	{
	}
	/**
	 * @see com.c2kernel.lifecycle.instance.WfVertex#verify()
	 */
	@Override
	public boolean verify()
	{
		for (int i = 0; i < getChildren().length; i++)
		{
			if (!((WfVertex) getChildren()[i]).verify())
			{
				mErrors.add("error in children");
				return false;
			}
		}
		return true;
	}
	/**
	 * @see com.c2kernel.lifecycle.instance.Activity#getWf()
	 */
	@Override
	public Workflow getWf()
	{
		return this;
	}
	/**
	 * Method initialise.
	 *
	 * @param systemKey
	 * @throws InvalidDataException 
	 * @throws ObjectNotFoundException 
	 * @throws AccessRightsException 
	 * @throws InvalidTransitionException 
	 */
	public void initialise(ItemPath itemPath, AgentPath agent) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException
	{
		setItemPath(itemPath);
		try
		{
			runFirst(agent, itemPath);
		}
		catch (InvalidDataException ex)
		{
			Logger.error(ex);
		} catch (PersistencyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public ItemPath getItemPath() {
		return itemPath;
	}

	public void setItemPath(ItemPath itemPath) {
		this.itemPath = itemPath;
	}
	
    public void setItemUUID( String uuid )
    {
    	setItemPath(new ItemPath(UUID.fromString(uuid)));
    }
    
    public String getItemUUID() {
    	return getItemPath().getUUID().toString();
    }

	/**
	 * if type = 0 only domain steps will be queried if type = 1 only predefined steps will be queried else both will be queried
	 * @param agent
	 * @param itemSysKey
	 * @param type
	 * @return
	 * @throws ObjectNotFoundException
	 * @throws InvalidDataException
	 * @throws InvalidAgentPathException 
	 */
	public ArrayList<Job> calculateJobs(AgentPath agent, ItemPath itemPath, int type) throws ObjectNotFoundException, InvalidDataException, InvalidAgentPathException
	{
		ArrayList<Job> jobs = new ArrayList<Job>();
		if (type != 1)
			jobs.addAll(((CompositeActivity) search("workflow/domain")).calculateJobs(agent, itemPath, true));
		if (type != 0)
			jobs.addAll(((CompositeActivity) search("workflow/predefined")).calculateJobs(agent, itemPath, true));
		return jobs;
	}
	/**
	 * @see com.c2kernel.lifecycle.instance.CompositeActivity#hasGoodNumberOfActivity()
	 */
	@Override
	public boolean hasGoodNumberOfActivity()
	{
		return true;
	}
	/**
	 * @see com.c2kernel.entity.C2KLocalObject#getClusterType()
	 */
	@Override
	public String getClusterType()
	{
		return ClusterStorage.LIFECYCLE;
	}

}