summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/lifecycle/instance/Workflow.java
blob: a7066d835269df108f99f6d985619e8c858b0cf6 (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
package com.c2kernel.lifecycle.instance;
import java.awt.Point;
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.entity.C2KLocalObject;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.graph.model.TypeNameAndConstructionInfo;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer;
import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.scripting.ScriptingEngineException;
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
{
	/** 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("Atomic"), "Atomic"),
			new TypeNameAndConstructionInfo(Language.translate("Composite"), "Composite")
			};
	private final TypeNameAndConstructionInfo[] mEdgeTypeNameAndConstructionInfo =
		{
			new TypeNameAndConstructionInfo(Language.translate("Next Edge"), "Next")
		};
	/**
	 * @see java.lang.Object#Object()
	 */
	public Workflow()
	{
		getProperties().put("ItemSystemKey", null);
	}
	
	public Workflow(CompositeActivity domain) {
		this();
		domain.setName("domain");
		initChild(domain, true, new Point(150, 100));
		PredefinedStepContainer act = new PredefinedStepContainer();
		addChild(act, new GraphPoint(300, 100));
	}
	
	/**
	 * 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
	 */
	//requestData is xmlstring
	public void requestAction(AgentPath agent, String stepPath, int transitionID, String requestData)
		throws ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException
	{
		Logger.msg(3, "Action: " + Transitions.getTransitionName(transitionID) + " " + stepPath + " by " + agent.getAgentName());
		if (search(stepPath) != null)
			 ((Activity) search(stepPath)).request(agent, transitionID, requestData);
		else
			throw new ObjectNotFoundException(stepPath + " not found", "");
	}

	/**
	 * @see com.c2kernel.graph.model.GraphableVertex#getPath()
	 */
	public String getPath()
	{
		return "workflow";
	}
	/**
	 * @see com.c2kernel.graph.model.Vertex#getName()
	 */
	public String getName()
	{
		return "workflow";
	}
	/**
	 * @see com.c2kernel.lifecycle.instance.Activity#getType()
	 */
	public String getType()
	{
		return "workflow";
	}
	/**
	 * @see com.c2kernel.graph.model.Vertex#setName(java.lang.String)
	 */
	public void setName(String name)
	{
	}
	/**
	 * @see com.c2kernel.lifecycle.instance.WfVertex#verify()
	 */
	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()
	 */
	public Workflow getWf()
	{
		return this;
	}
	/**
	 * Method initialise.
	 * 
	 * @param systemKey
	 */
	public void initialise(int systemKey, AgentPath agent)
	{
		this.getProperties().put("ItemSystemKey", new Integer(systemKey));
		try
		{
			runfirst(agent);
		}
		catch (ScriptingEngineException ex)
		{
			Logger.error(ex);
		}
	}
	/**
	 * Method calculateJobs.
	 * 
	 * @param type
	 * @return JobList
	 */
	/**
	 * if type = 0 only domain steps will be queried if type = 1 only predefined steps will be queried else both will be queried
	 */
	public ArrayList calculateJobs(AgentPath agent, int type)
	{
		ArrayList jobs = new ArrayList();
		if (type != 1)
			jobs.addAll(((CompositeActivity) search("workflow/domain")).calculateJobs(agent, true));
		if (type != 0)
			jobs.addAll(((CompositeActivity) search("workflow/predefined")).calculateJobs(agent, true));
		return jobs;
	}
	/**
	 * @see com.c2kernel.lifecycle.instance.CompositeActivity#hasGoodNumberOfActivity()
	 */
	public boolean hasGoodNumberOfActivity()
	{
		return true;
	}
	/**
	 * @see com.c2kernel.entity.C2KLocalObject#getClusterType()
	 */
	public String getClusterType()
	{
		return ClusterStorage.LIFECYCLE;
	}

}