diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2013-11-18 09:48:03 +0100 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2013-11-18 17:25:00 +0100 |
| commit | d43164830403245353080f5d6f838ed9f56d9a35 (patch) | |
| tree | d880c9103fb61f5ef39f1723c4dbd634d5d83b67 /src/main/java/com/c2kernel | |
| parent | 37a3c3867cb4c7705065ed1d079bdac4f3f52f50 (diff) | |
3.0-SNAPSHOT (Will be first open source version)
New StateMachine desc
IssueID #28
Diffstat (limited to 'src/main/java/com/c2kernel')
65 files changed, 1719 insertions, 1913 deletions
diff --git a/src/main/java/com/c2kernel/collection/CollectionArrayList.java b/src/main/java/com/c2kernel/collection/CollectionArrayList.java new file mode 100644 index 0000000..586f99f --- /dev/null +++ b/src/main/java/com/c2kernel/collection/CollectionArrayList.java @@ -0,0 +1,31 @@ +package com.c2kernel.collection;
+
+import java.util.ArrayList;
+
+import com.c2kernel.utils.CastorArrayList;
+
+public class CollectionArrayList extends CastorArrayList<Collection<CollectionMember>> {
+ public CollectionArrayList()
+ {
+ super();
+ }
+
+ public CollectionArrayList(ArrayList<Collection<CollectionMember>> aList)
+ {
+ super();
+ for (Collection<CollectionMember> coll : aList) {
+ put(coll);
+ }
+ }
+
+ /** Overwrite */
+ public void put(Collection<CollectionMember> c) {
+ for (Collection<CollectionMember> thisColl : list) {
+ if (thisColl.getName().equals(c.getName())) {
+ list.remove(thisColl);
+ break;
+ }
+ }
+ list.add(c);
+ }
+}
diff --git a/src/main/java/com/c2kernel/entity/TraceableEntity.java b/src/main/java/com/c2kernel/entity/TraceableEntity.java index c6442a0..b6ccd8c 100644 --- a/src/main/java/com/c2kernel/entity/TraceableEntity.java +++ b/src/main/java/com/c2kernel/entity/TraceableEntity.java @@ -21,7 +21,6 @@ import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.agent.JobArrayList;
import com.c2kernel.lifecycle.instance.CompositeActivity;
import com.c2kernel.lifecycle.instance.Workflow;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.InvalidEntityPathException;
import com.c2kernel.persistency.ClusterStorage;
@@ -183,13 +182,14 @@ public class TraceableEntity extends ItemPOA try {
Logger.msg(1, "TraceableEntity::request("+mSystemKey+") - " +
- Transitions.getTransitionName(transitionID) + " "+stepPath + " by " +agentId );
+ transitionID + " "+stepPath + " by " +agentId );
AgentPath agent = new AgentPath(agentId);
Workflow lifeCycle = (Workflow)mStorage.get(mSystemKey, ClusterStorage.LIFECYCLE+"/workflow", null);
lifeCycle.requestAction( agent,
stepPath,
+ mSystemKey,
transitionID,
requestData );
@@ -261,7 +261,7 @@ public class TraceableEntity extends ItemPOA }
JobArrayList jobBag = new JobArrayList();
CompositeActivity domainWf = (CompositeActivity)wf.search("workflow/domain");
- jobBag.list = filter?domainWf.calculateJobs(agent, true):domainWf.calculateAllJobs(agent, true);
+ jobBag.list = filter?domainWf.calculateJobs(agent, mSystemKey, true):domainWf.calculateAllJobs(agent, mSystemKey, true);
Logger.msg(1, "TraceableEntity::queryLifeCycle("+mSystemKey+") - Returning "+jobBag.list.size()+" jobs.");
try {
return Gateway.getMarshaller().marshall( jobBag );
diff --git a/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java b/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java index d20fc1e..8d4dbfd 100644 --- a/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java +++ b/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java @@ -247,7 +247,7 @@ public class ActiveEntity extends AgentPOA // merge new jobs in
for (Object name : newJobList.list) {
Job newJob = (Job)name;
- Logger.msg(6, "Adding job for "+newJob.getItemSysKey()+"/"+newJob.getStepPath()+":"+newJob.getPossibleTransition());
+ Logger.msg(6, "Adding job for "+newJob.getItemSysKey()+"/"+newJob.getStepPath()+":"+newJob.getTransition().getId());
currentJobs.addJob(newJob);
}
diff --git a/src/main/java/com/c2kernel/entity/agent/Job.java b/src/main/java/com/c2kernel/entity/agent/Job.java index f1aa215..5f9e6dc 100644 --- a/src/main/java/com/c2kernel/entity/agent/Job.java +++ b/src/main/java/com/c2kernel/entity/agent/Job.java @@ -1,14 +1,18 @@ 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.stateMachine.Transitions;
+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;
@@ -20,37 +24,42 @@ import com.c2kernel.utils.Logger; * @author $Author: abranson $ $Date: 2005/05/20 13:07:49 $
* @version $Revision: 1.62 $
******************************************************************************/
+
public class Job implements C2KLocalObject
{
- private int mID;
-
- private String mName;
-
- private int mItemSysKey;
-
- private String mStepPath;
-
- private int mPossibleTransition;
-
- private int mCurrentState;
+ // persistent
+
+ private int id;
- private int mTargetState;
+ private int itemSysKey;
- private String mStepName;
-
- private int mAgentId = -1;
-
- private String mAgentName;
+ private String stepName;
+
+ private String stepPath;
+
+ private String stepType;
+
+ private Transition transition;
+
+ private String originStateName;
+
+ private String targetStateName;
- private String mAgentRole;
+ private int agentId = -1;
- private CastorHashMap mActProps = new CastorHashMap();
+ private String agentRole;
- private String mOutcome;
+ private CastorHashMap actProps = new CastorHashMap();
- private ErrorInfo mError;
-
- private String mStepType;
+ // non-persistent
+
+ private String name;
+
+ private String agentName;
+
+ private String outcomeData;
+
+ private ErrorInfo error;
private ItemProxy item = null;
@@ -65,305 +74,277 @@ public class Job implements C2KLocalObject {
}
- /***************************************************************************
- *
- **************************************************************************/
- public Job(int sysKey, String path, int transition, int currState, int targState, String stepName, CastorHashMap actProps, String stepType, String agentName)
- {
- setItemSysKey(sysKey);
- setStepPath(path);
- setPossibleTransition(transition);
- setCurrentState(currState);
- setTargetState(targState);
- setStepName(stepName);
- setActProps(actProps);
- setStepType(stepType);
- setAgentName(agentName);
- }
-
- public int getItemSysKey()
- {
- return mItemSysKey;
+ public Job(Activity act, int itemSysKey, Transition transition, AgentPath agent, String role) throws InvalidDataException, ObjectNotFoundException {
+
+ setItemSysKey(itemSysKey);
+ setStepPath(act.getPath());
+ setTransition(transition);
+ setOriginStateName(act.getStateMachine().getState(transition.getOriginStateId()).getName());
+ setTargetStateName(act.getStateMachine().getState(transition.getTargetStateId()).getName());
+ setStepName(act.getName());
+ setActProps(act.getProperties());
+ setStepType(act.getType());
+ setAgentName(agent.getAgentName());
+ setAgentRole(role);
}
- public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidEntityPathException
- {
- if (item == null)
- item = (ItemProxy) Gateway.getProxyManager().getProxy(new EntityPath(mItemSysKey));
- return item;
- }
+
+ // Castor persistent fields
+
+ public String getOriginStateName() {
+ return originStateName;
+ }
- public AgentProxy getAgentProxy() throws ObjectNotFoundException, InvalidEntityPathException
- {
- if (agent == null)
- agent = (AgentProxy) Gateway.getProxyManager().getProxy(new EntityPath(getAgentId()));
- return agent;
- }
+ public void setOriginStateName(String originStateName) {
+ this.originStateName = originStateName;
+ }
- public String getDescription()
- {
- String desc = (String) mActProps.get("Description");
- if (desc == null)
- desc = "No Description";
- return desc;
- }
+ public String getTargetStateName() {
+ return targetStateName;
+ }
- public String getSchemaType()
- {
- if (isError()) return "Errors";
- if (requiresOutcome()) return (String)mActProps.get("SchemaType");
- else return null;
- }
+ public void setTargetStateName(String targetStateName) {
+ this.targetStateName = targetStateName;
+ }
- public int getSchemaVersion()
- {
- if (isError()) return 0;
- if (requiresOutcome())
- try {
- return Integer.parseInt((String) mActProps.get("SchemaVersion"));
- } catch (NumberFormatException ex) {
- return -1;
- }
- return -1;
- }
-
- public void setOutcome(String outcome)
- {
- mOutcome = outcome;
- outcomeSet = !(mOutcome == null);
+ public int getId() {
+ return id;
}
- public void setError(ErrorInfo errors)
- {
- mError = errors;
- try {
- mOutcome = Gateway.getMarshaller().marshall(mError);
- } catch (Exception e) {
- Logger.error("Error marshalling ErrorInfo in job");
- Logger.error(e);
- }
+ 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 getOutcomeString()
- {
- if (mOutcome == null && requiresOutcome())
- {
- String viewName = (String) getActProp("Viewpoint");
- mOutcome = null;
- if (viewName.length() > 0)
- try
- {
- Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(), ClusterStorage.VIEWPOINT + "/" + getSchemaType() + "/" + viewName, null);
- mOutcome = view.getOutcome().getData();
- outcomeSet = true;
- } catch (Exception ex)
- {
- mOutcome = null;
- outcomeSet = false;
- }
-
- }
- return mOutcome;
+ public String getStepName() {
+ return stepName;
}
- public Outcome getOutcome()
- {
- return new Outcome(-1, getOutcomeString(), getSchemaType(), getSchemaVersion());
+ public void setStepName(String string) {
+ stepName = string;
}
- public int getAgentId() throws ObjectNotFoundException
- {
- if (mAgentId == -1)
- mAgentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath(getAgentName()).getSysKey();
- return mAgentId;
+ public String getStepPath() {
+ return stepPath;
}
- public void setAgentId(int id)
- {
- mAgentId = id;
- agent = null;
+ public void setStepPath(String string) {
+ stepPath = string;
}
- public String getAgentName()
- {
- if (mAgentName == null)
- mAgentName = (String) mActProps.get("AgentName");
- return mAgentName;
+ public String getStepType() {
+ return stepType;
}
- public void setAgentName(String agentName)
- {
- mAgentName = agentName;
+ public void setStepType(String actType) {
+ stepType = actType;
+ }
+
+ public Transition getTransition() {
+ return transition;
+ }
+
+ public void setTransition(Transition transition) {
+ this.transition = transition;
}
- public String getAgentRole()
- {
- if (mAgentRole == null)
- mAgentRole = (String) mActProps.get("Agent Role");
- return mAgentRole;
+ public int getAgentId() throws ObjectNotFoundException {
+ if (agentId == -1)
+ agentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath(getAgentName()).getSysKey();
+ return agentId;
}
- public void setAgentRole(String role)
+ public void setAgentId(int id) {
+ agentId = id;
+ agent = null;
+ }
+
+ public String getAgentName()
{
- mAgentRole = role;
+ if (agentName == null)
+ agentName = (String) actProps.get("Agent Name");
+ return agentName;
}
- public boolean requiresOutcome()
+ public void setAgentName(String agentName)
{
- String schemaType = (String) mActProps.get("SchemaType");
- return (mPossibleTransition == Transitions.DONE || mPossibleTransition == Transitions.COMPLETE) && !(schemaType == null || schemaType.equals(""));
+ this.agentName = agentName;
}
- public boolean isError() {
- return (mPossibleTransition == Transitions.SUSPEND);
+ public String getAgentRole() {
+ return agentRole;
+ }
+
+ public void setAgentRole(String role) {
+ agentRole = role;
}
- public boolean hasOutcome() {
- return requiresOutcome() || isError();
+ public String getSchemaName() throws InvalidDataException, ObjectNotFoundException {
+ if (transition.hasOutcome()) {
+ Schema schema = transition.getSchema(actProps);
+ return schema.docType;
+ }
+ return null;
}
- public boolean isOutcomeSet() {
- return outcomeSet;
+ public int getSchemaVersion() throws InvalidDataException, ObjectNotFoundException {
+ if (transition.hasOutcome()) {
+ Schema schema = transition.getSchema(actProps);
+ return schema.docVersion;
+ }
+ return -1;
}
- public int getID()
+ public boolean isOutcomeRequired()
{
- return mID;
+ return transition.hasOutcome() && transition.getOutcome().isRequired();
}
+
+ public String getScriptName() {
+ if (transition.hasScript()) {
+ return transition.getScript().getScriptName();
+ }
+ return null;
+ }
- @Override
- public String getName()
- {
- return mName;
+ public int getScriptVersion() throws InvalidDataException {
+ if (transition.hasScript()) {
+ return transition.getScriptVersion(actProps);
+ }
+ return -1;
+ }
+
+ public KeyValuePair[] getKeyValuePairs() {
+ return actProps.getKeyValuePairs();
}
- public void setID(int id)
- {
- mID = id;
- mName = String.valueOf(id);
+ public void setKeyValuePairs(KeyValuePair[] pairs) {
+ actProps.setKeyValuePairs(pairs);
}
-
+
+ // Non-persistent fields
+
@Override
- public void setName(String name)
- {
- mName = name;
- try
- {
- mID = Integer.parseInt(name);
- } catch (NumberFormatException ex)
- {
- mID = -1;
- }
- }
-
- public void setItemSysKey(int sysKey)
- {
- mItemSysKey = sysKey;
- item = null;
+ public String getName() {
+ return name;
}
-
+
@Override
- public String getClusterType()
- {
- return ClusterStorage.JOB;
- }
-
- public boolean equals(Job job)
- {
- return (getItemSysKey() == job.getItemSysKey()) && this.mStepPath.equals(job.mStepPath) && this.mPossibleTransition == job.mPossibleTransition;
- }
-
- public Object getActProp(String name)
- {
- return mActProps.get(name);
- }
-
- public String getActPropString(String name)
- {
- try
- {
- return mActProps.get(name).toString();
- } catch (NullPointerException ex)
- {
- return null;
+ public void setName(String name) {
+ this.name = name;
+ try {
+ id = Integer.parseInt(name);
+ } catch (NumberFormatException ex) {
+ id = -1;
}
}
-
- public String getStepName()
- {
- return mStepName;
+
+ public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidEntityPathException {
+ if (item == null)
+ item = (ItemProxy) Gateway.getProxyManager().getProxy(new EntityPath(itemSysKey));
+ return item;
}
- public void setStepName(String string)
- {
- mStepName = string;
+ public AgentProxy getAgentProxy() throws ObjectNotFoundException, InvalidEntityPathException {
+ if (agent == null)
+ agent = (AgentProxy) Gateway.getProxyManager().getProxy(new EntityPath(getAgentId()));
+ return agent;
}
- public String getStepPath()
+ public String getDescription()
{
- return mStepPath;
+ String desc = (String) actProps.get("Description");
+ if (desc == null)
+ desc = "No Description";
+ return desc;
}
-
- public void setStepPath(String string)
+ public void setOutcome(String outcome)
{
- mStepPath = string;
+ outcomeData = outcome;
+ outcomeSet = !(outcomeData == null);
}
-
- public int getPossibleTransition()
+
+ public void setError(ErrorInfo errors)
{
- return mPossibleTransition;
+ error = errors;
+ try {
+ outcomeData = Gateway.getMarshaller().marshall(error);
+ } catch (Exception e) {
+ Logger.error("Error marshalling ErrorInfo in job");
+ Logger.error(e);
+ }
}
- public void setPossibleTransition(int lint)
+ public String getOutcomeString()
{
- mPossibleTransition = lint;
- }
+ 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;
+ }
- public CastorHashMap getActProps()
- {
- return mActProps;
+ }
+ return outcomeData;
}
- public void setActProps(CastorHashMap map)
+ public Outcome getOutcome() throws InvalidDataException, ObjectNotFoundException
{
- mActProps = map;
+ return new Outcome(-1, getOutcomeString(), getSchemaName(), getSchemaVersion());
}
-
- public KeyValuePair[] getKeyValuePairs()
- {
- return mActProps.getKeyValuePairs();
+
+ public boolean hasOutcome() {
+ return transition.hasOutcome();
}
-
- public void setKeyValuePairs(KeyValuePair[] pairs)
- {
- mActProps.setKeyValuePairs(pairs);
+
+ public boolean hasScript() {
+ return transition.hasScript();
}
+
+ public boolean isOutcomeSet() {
+ return outcomeSet;
+ }
- public int getCurrentState()
+ @Override
+ public String getClusterType()
{
- return mCurrentState;
+ return ClusterStorage.JOB;
}
- public void setCurrentState(int string)
+ public boolean equals(Job job)
{
- mCurrentState = string;
+ return (getItemSysKey() == job.getItemSysKey()) && this.stepPath.equals(job.stepPath) && transition.getId() == job.getTransition().getId();
+ }
+
+ private void setActProps(CastorHashMap actProps) {
+ this.actProps = actProps;
}
- public int getTargetState() {
- return mTargetState;
- }
-
- public void setTargetState(int mTargetState) {
- this.mTargetState = mTargetState;
- }
-
- public String getStepType()
+ public Object getActProp(String name)
{
- return mStepType;
+ return actProps.get(name);
}
- public void setStepType(String actType)
+ public String getActPropString(String name)
{
- mStepType = actType;
+ return String.valueOf(actProps.get(name));
}
}
\ No newline at end of file diff --git a/src/main/java/com/c2kernel/entity/agent/JobList.java b/src/main/java/com/c2kernel/entity/agent/JobList.java index 3772c22..271decb 100644 --- a/src/main/java/com/c2kernel/entity/agent/JobList.java +++ b/src/main/java/com/c2kernel/entity/agent/JobList.java @@ -33,7 +33,7 @@ public class JobList extends RemoteMap<Job> {
synchronized(this) {
int jobId = getLastId()+1;
- job.setID(jobId);
+ job.setId(jobId);
put(String.valueOf(jobId), job);
}
}
@@ -65,7 +65,7 @@ public class JobList extends RemoteMap<Job> j = currentMembers.next();
if( j.getItemSysKey() == sysKey )
- remove( String.valueOf(j.getID()) );
+ remove( String.valueOf(j.getId()) );
}
Logger.msg(5, "JobList::removeJobsWithSysKey() - " + sysKey + " DONE." );
diff --git a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java index 24172dc..3569421 100644 --- a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java +++ b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java @@ -25,7 +25,6 @@ import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.ManageableEntity;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.EntityPath;
@@ -111,14 +110,13 @@ public class AgentProxy extends EntityProxy ScriptErrorException
{
OutcomeValidator validator = null;
- String scriptName = job.getActPropString("ScriptName");
Date startTime = new Date();
Logger.msg(3, "AgentProxy - executing "+job.getStepPath()+" for "+path.getAgentName());
// get the outcome validator if present
- if (job.requiresOutcome() || job.isError())
+ if (job.hasOutcome())
{
- String schemaName = job.isError()?"Errors":job.getSchemaType();
- int schemaVersion = job.isError()?0:job.getSchemaVersion();
+ String schemaName = job.getSchemaName();
+ int schemaVersion = job.getSchemaVersion();
Logger.msg(5, "AgentProxy - fetching schema "+schemaName+"_"+schemaVersion+" for validation");
// retrieve schema
@@ -134,9 +132,8 @@ public class AgentProxy extends EntityProxy }
}
- if(scriptName != null && scriptName.length() > 0 &&
- (job.getPossibleTransition() == Transitions.DONE || job.getPossibleTransition() == Transitions.COMPLETE)) {
- Logger.msg(3, "AgentProxy - executing script "+scriptName);
+ if(job.hasScript()) {
+ Logger.msg(3, "AgentProxy - executing script "+job.getScriptName()+" v"+job.getScriptVersion());
try {
// pre-validate outcome from script if there is one
@@ -151,7 +148,6 @@ public class AgentProxy extends EntityProxy // load script
ErrorInfo scriptErrors = (ErrorInfo)callScript(item, job);
-
String errorString = scriptErrors.toString();
if (scriptErrors.getFatal()) {
Logger.msg(3, "AgentProxy - fatal script error");
@@ -171,6 +167,7 @@ public class AgentProxy extends EntityProxy if (error.length() > 0)
throw new InvalidDataException(error, "");
}
+ else if (job.isOutcomeRequired())
job.setAgentId(getSystemKey());
Logger.msg(3, "AgentProxy - submitting job to item proxy");
@@ -243,7 +240,7 @@ public class AgentProxy extends EntityProxy PersistencyException,
ObjectAlreadyExistsException
{
- item.requestAction(getSystemKey(), "workflow/predefined/"+predefStep, Transitions.DONE, PredefinedStep.bundleData(params));
+ item.requestAction(getSystemKey(), "workflow/predefined/"+predefStep, PredefinedStep.DONE, PredefinedStep.bundleData(params));
}
/** Wrappers for scripts */
diff --git a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java index 67685e7..ceea6c3 100644 --- a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java +++ b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java @@ -26,7 +26,6 @@ import com.c2kernel.entity.ManageableEntity; import com.c2kernel.entity.agent.Job;
import com.c2kernel.entity.agent.JobArrayList;
import com.c2kernel.lifecycle.instance.Workflow;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
@@ -108,10 +107,10 @@ public class ItemProxy extends EntityProxy ObjectAlreadyExistsException
{
String outcome = thisJob.getOutcomeString();
- // check fields that should have been filled in
- if (outcome==null)
- if (thisJob.requiresOutcome())
- throw new InvalidDataException("Outcome is required.", "");
+ // check fields that should have been filled in
+ if (outcome==null)
+ if (thisJob.isOutcomeRequired())
+ throw new InvalidDataException("Outcome is required.", "");
else
outcome="";
@@ -120,7 +119,7 @@ public class ItemProxy extends EntityProxy Logger.msg(7, "ItemProxy - executing "+thisJob.getStepPath()+" for "+thisJob.getAgentName());
requestAction (thisJob.getAgentId(), thisJob.getStepPath(),
- thisJob.getPossibleTransition(), outcome);
+ thisJob.getTransition().getId(), outcome);
}
//requestData is xmlString
@@ -200,9 +199,7 @@ public class ItemProxy extends EntityProxy 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)
+ if (job.getStepName().equals(actName) && job.hasOutcome())
return job;
}
return null;
diff --git a/src/main/java/com/c2kernel/events/Event.java b/src/main/java/com/c2kernel/events/Event.java index 52781bd..37c3c58 100644 --- a/src/main/java/com/c2kernel/events/Event.java +++ b/src/main/java/com/c2kernel/events/Event.java @@ -28,12 +28,44 @@ import com.c2kernel.persistency.ClusterStorage; public class Event implements C2KLocalObject
{
- int mEntitySystemKey, mCurrentState, mTransition;
- Integer mID, mSchemaVersion;
- String mName, mStepName, mStepPath, mStepType, mSchemaName, mViewName, mAgentName, mAgentRole;
+ int mEntitySystemKey, mOriginState, mTransition, mTargetState;
+ Integer mID, mSchemaVersion, mStateMachineVersion;
+ String mName, mStepName, mStepPath, mStepType, mSchemaName, mStateMachineName, mViewName, mAgentName, mAgentRole;
GTimeStamp mTimeStamp;
- public void setID( Integer id ) {
+ public int getOriginState() {
+ return mOriginState;
+ }
+
+ public void setOriginState(int originState) {
+ this.mOriginState = originState;
+ }
+
+ public int getTargetState() {
+ return mTargetState;
+ }
+
+ public void setTargetState(int targetState) {
+ this.mTargetState = targetState;
+ }
+
+ public Integer getStateMachineVersion() {
+ return mStateMachineVersion;
+ }
+
+ public void setStateMachineVersion(Integer stateMachineVersion) {
+ this.mStateMachineVersion = stateMachineVersion;
+ }
+
+ public String getStateMachineName() {
+ return mStateMachineName;
+ }
+
+ public void setStateMachineName(String stateMachineName) {
+ this.mStateMachineName = stateMachineName;
+ }
+
+ public void setID( Integer id ) {
mID = id;
mName = String.valueOf(id);
}
@@ -90,11 +122,6 @@ public class Event implements C2KLocalObject this.mViewName = viewName;
}
- public void setCurrentState(int state)
- {
- mCurrentState = state;
- }
-
/**
* Set the AgentInfo in the Event, in parameter is an AgentInfo
*/
@@ -172,11 +199,6 @@ public class Event implements C2KLocalObject return mViewName;
}
- public int getCurrentState()
- {
- return mCurrentState;
- }
-
/**
* Return the AgentInfo of the Event.
*/
diff --git a/src/main/java/com/c2kernel/events/History.java b/src/main/java/com/c2kernel/events/History.java index 2eef8de..8ccd97a 100644 --- a/src/main/java/com/c2kernel/events/History.java +++ b/src/main/java/com/c2kernel/events/History.java @@ -2,6 +2,7 @@ package com.c2kernel.events; import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.lifecycle.instance.stateMachine.Transition;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.RemoteMap;
import com.c2kernel.utils.Logger;
@@ -24,36 +25,41 @@ public class History extends RemoteMap<Event> { super(sysKey, ClusterStorage.HISTORY, locker);
}
public Event addEvent(String agentName, String agentRole,
- int stepTransitionId,
String stepName,
String stepPath,
String stepType,
- int stepCurrentState) {
- return addEvent(agentName, agentRole, stepTransitionId, stepName, stepPath, stepType, null, null, null, stepCurrentState);
+ String stateMachineName,
+ Integer stateMachineVersion,
+ Transition transition) {
+ return addEvent(agentName, agentRole, stepName, stepPath, stepType, null, null, stateMachineName, stateMachineVersion, transition, null);
}
public Event addEvent(String agentName, String agentRole,
- int stepTransitionId,
String stepName,
String stepPath,
String stepType,
String schemaName,
Integer schemaVersion,
- String viewName,
- int stepCurrentState) {
- Logger.msg(7, "History.addEvent() - creating new event for "+stepTransitionId+" on "+stepName+" in "+mSysKey);
+ String stateMachineName,
+ Integer stateMachineVersion,
+ Transition transition,
+ String viewName) {
+ Logger.msg(7, "History.addEvent() - creating new event for "+transition.getName()+" on "+stepName+" in "+mSysKey);
Event newEvent = new Event();
newEvent.setEntitySystemKey(mSysKey);
newEvent.setAgentName(agentName);
newEvent.setAgentRole(agentRole);
- newEvent.setTransition(stepTransitionId);
newEvent.setStepName(stepName);
newEvent.setStepPath(stepPath);
newEvent.setStepType(stepType);
newEvent.setSchemaName(schemaName);
newEvent.setSchemaVersion(schemaVersion);
newEvent.setViewName(viewName);
- newEvent.setCurrentState(stepCurrentState);
+ newEvent.setOriginState(transition.getOriginStateId());
+ newEvent.setTargetState(transition.getTargetStateId());
+ newEvent.setTransition(transition.getId());
+ newEvent.setStateMachineName(stateMachineName);
+ newEvent.setStateMachineVersion(stateMachineVersion);
newEvent.setTimeStamp(Event.getGMT());
return storeNewEvent(newEvent);
}
@@ -63,34 +69,40 @@ public class History extends RemoteMap<Event> { String stepName,
String stepPath,
String stepType,
- int stepCurrentState,
+ String stateMachineName,
+ Integer stateMachineVersion,
+ Transition transition,
String timeString) throws InvalidDataException {
- return addEvent(agentName, agentRole, stepTransitionId, stepName, stepPath, stepType, null, null, null, stepCurrentState, timeString);
+ return addEvent(agentName, agentRole, stepName, stepPath, stepType, null, null, stateMachineName, stateMachineVersion, transition, null, timeString);
}
public Event addEvent(String agentName, String agentRole,
- int stepTransitionId,
String stepName,
String stepPath,
String stepType,
String schemaName,
Integer schemaVersion,
+ String stateMachineName,
+ Integer stateMachineVersion,
+ Transition transition,
String viewName,
- int stepCurrentState,
String timeString) throws InvalidDataException {
- Logger.msg(7, "History.addEvent() - creating new event for "+stepTransitionId+" on "+stepName+" in "+mSysKey);
+ Logger.msg(7, "History.addEvent() - creating new event for "+transition.getName()+" on "+stepName+" in "+mSysKey);
Event newEvent = new Event();
newEvent.setEntitySystemKey(mSysKey);
newEvent.setAgentName(agentName);
newEvent.setAgentRole(agentRole);
- newEvent.setTransition(stepTransitionId);
newEvent.setStepName(stepName);
newEvent.setStepPath(stepPath);
newEvent.setStepType(stepType);
newEvent.setSchemaName(schemaName);
newEvent.setSchemaVersion(schemaVersion);
newEvent.setViewName(viewName);
- newEvent.setCurrentState(stepCurrentState);
+ newEvent.setOriginState(transition.getOriginStateId());
+ newEvent.setTargetState(transition.getTargetStateId());
+ newEvent.setTransition(transition.getId());
+ newEvent.setStateMachineName(stateMachineName);
+ newEvent.setStateMachineVersion(stateMachineVersion);
newEvent.setTimeString(timeString);
return storeNewEvent(newEvent);
}
diff --git a/src/main/java/com/c2kernel/graph/model/GraphableVertex.java b/src/main/java/com/c2kernel/graph/model/GraphableVertex.java index 7c9adef..b0b74fd 100644 --- a/src/main/java/com/c2kernel/graph/model/GraphableVertex.java +++ b/src/main/java/com/c2kernel/graph/model/GraphableVertex.java @@ -5,6 +5,7 @@ package com.c2kernel.graph.model; */
+import com.c2kernel.common.InvalidDataException;
import com.c2kernel.utils.CastorHashMap;
import com.c2kernel.utils.KeyValuePair;
public abstract class GraphableVertex extends Vertex
@@ -25,6 +26,15 @@ public abstract class GraphableVertex extends Vertex {
return mProperties;
}
+ protected Integer getVersionNumberProperty(String propName) throws InvalidDataException {
+ Object val = getProperties().get(propName);
+ if (val == null || val.equals("") || val.toString().equals("-1")) return null;
+ try {
+ return new Integer(val.toString());
+ } catch (NumberFormatException ex) {
+ throw new InvalidDataException("Invalid version number for property '"+propName+"': "+val.toString(), "");
+ }
+ }
public KeyValuePair[] getKeyValuePairs()
{
return mProperties.getKeyValuePairs();
diff --git a/src/main/java/com/c2kernel/lifecycle/ActivityDef.java b/src/main/java/com/c2kernel/lifecycle/ActivityDef.java index 40d1f8a..f39badb 100644 --- a/src/main/java/com/c2kernel/lifecycle/ActivityDef.java +++ b/src/main/java/com/c2kernel/lifecycle/ActivityDef.java @@ -6,16 +6,17 @@ import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.lifecycle.instance.Activity;
import com.c2kernel.lifecycle.instance.WfVertex;
+import com.c2kernel.utils.DescriptionObject;
import com.c2kernel.utils.FileStringUtility;
/**
* @version $Revision: 1.45 $ $Date: 2005/10/05 07:39:36 $
* @author $Author: abranson $
*/
-public class ActivityDef extends WfVertexDef implements C2KLocalObject
+public class ActivityDef extends WfVertexDef implements C2KLocalObject, DescriptionObject
{
private int mId = -1;
private String mName = "";
- private String mVersion = "";
+ private int mVersion = -1;
public boolean changed = false;
/**
* @see java.lang.Object#Object()
@@ -61,14 +62,15 @@ public class ActivityDef extends WfVertexDef implements C2KLocalObject return mName;
}
- public void setVersion(String v)
+ public void setVersion(int v)
{
mVersion = v;
}
/**
* @see com.c2kernel.graph.model.Vertex#getName()
*/
- public String getVersion()
+ @Override
+ public int getVersion()
{
return mVersion;
}
diff --git a/src/main/java/com/c2kernel/lifecycle/ActivitySlotDef.java b/src/main/java/com/c2kernel/lifecycle/ActivitySlotDef.java index 74d8305..514dc72 100644 --- a/src/main/java/com/c2kernel/lifecycle/ActivitySlotDef.java +++ b/src/main/java/com/c2kernel/lifecycle/ActivitySlotDef.java @@ -39,12 +39,12 @@ public class ActivitySlotDef extends WfVertexDef public ActivitySlotDef()
{
getProperties().put("Name", "");
- getProperties().put("Version", "last");
+ getProperties().put("Version", 0);
}
public ActivityDef getTheActivityDef() throws ObjectNotFoundException, InvalidDataException
{
- ActivityDef actDef = LocalObjectLoader.getActDef(getActivityDef(), getActVersion());
+ ActivityDef actDef = LocalObjectLoader.getActDef(getActivityDef(), getVersionNumberProperty("Version"));
if (actDef instanceof CompositeActivityDef)
mIsComposite = true;
return actDef;
@@ -142,10 +142,6 @@ public class ActivitySlotDef extends WfVertexDef {
return (String) getProperties().get("Name");
}
- public String getActVersion()
- {
- return (String) getProperties().get("Version");
- }
@Override
public WfVertex instantiate() throws ObjectNotFoundException, InvalidDataException {
diff --git a/src/main/java/com/c2kernel/lifecycle/WfCastorHashMap.java b/src/main/java/com/c2kernel/lifecycle/WfCastorHashMap.java index eb9aa2a..5a9d472 100644 --- a/src/main/java/com/c2kernel/lifecycle/WfCastorHashMap.java +++ b/src/main/java/com/c2kernel/lifecycle/WfCastorHashMap.java @@ -1,5 +1,4 @@ package com.c2kernel.lifecycle;
-import com.c2kernel.lifecycle.instance.stateMachine.StateMachine;
import com.c2kernel.utils.CastorHashMap;
/**
* @version $Revision: 1.29 $ $Date: 2005/05/20 13:07:13 $
@@ -12,10 +11,6 @@ public class WfCastorHashMap extends CastorHashMap */
public WfCastorHashMap()
{
- //put(StateMachine.AUTOSTART, new Boolean(false));
- put(StateMachine.SKIPPABLE, new Boolean(false));
- put(StateMachine.REPEATABLE, new Boolean(false));
- put(StateMachine.IGNORABLE, new Boolean(false));
put("Show time", new Boolean(true));
put("Breakpoint", new Boolean(false));
put("Description", "");
@@ -25,6 +20,8 @@ public class WfCastorHashMap extends CastorHashMap put("SchemaVersion", "");
put("ScriptName", "");
put("ScriptVersion", "");
+ put("StateMachineName", "Default");
+ put("StateMachineVersion", 0);
put("Viewpoint", "");
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java index a8a2016..54df25c 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java @@ -1,5 +1,6 @@ package com.c2kernel.lifecycle.instance;
import java.util.ArrayList;
+import java.util.Map;
import java.util.Vector;
import com.c2kernel.common.AccessRightsException;
@@ -8,26 +9,27 @@ 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.agent.Job;
import com.c2kernel.events.Event;
import com.c2kernel.events.History;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.lifecycle.WfCastorHashMap;
+import com.c2kernel.lifecycle.instance.stateMachine.State;
import com.c2kernel.lifecycle.instance.stateMachine.StateMachine;
-import com.c2kernel.lifecycle.instance.stateMachine.States;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
+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.lookup.LDAPRoleManager;
import com.c2kernel.lookup.RolePath;
-import com.c2kernel.persistency.TransactionManager;
+import com.c2kernel.persistency.ClusterStorageException;
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.ScriptingEngineException;
import com.c2kernel.utils.DateUtility;
+import com.c2kernel.utils.LocalObjectLoader;
import com.c2kernel.utils.Logger;
+import com.c2kernel.utils.Resource;
/**
* @version $Revision: 1.222 $ $Date: 2005/10/05 07:39:37 $
* @author $Author: abranson $
@@ -40,54 +42,28 @@ public class Activity extends WfVertex protected Vector<String> mErrors;
/** @associates a State machine engine */
private StateMachine machine;
- /** true is avalaibe to be executed */
+ protected int state = -1;
+ /** true is available to be executed */
public boolean active = false;
/** used in verify() */
private boolean loopTested;
- private GTimeStamp mStartDate;
- private GTimeStamp mActiveDate;
+ private GTimeStamp mStateDate;
private String mType;
- private EntityPath mEntityPath;
+
public Activity()
{
super();
setProperties(new WfCastorHashMap());
+ getProperties().put("StateMachineName", getDefaultSMName());
mErrors = new Vector<String>(0, 1);
- machine = new StateMachine(this);
- mStartDate = new GTimeStamp();
- mActiveDate = new GTimeStamp();
- DateUtility.setToNow(mActiveDate);
- DateUtility.setToNow(mStartDate);
- }
- /** @return the SystemKey of the item that contains the workflow */
- public EntityPath getItemEntityPath()
- {
- if (mEntityPath == null)
- try
- {
- Integer i = (Integer) (getWf().getProperties().get("ItemSystemKey"));
- if (i == null)
- return null; // no item yet
- EntityPath entityPath = new EntityPath(i.intValue());
- mEntityPath = entityPath;
- }
- catch (InvalidEntityPathException ex)
- {
- Logger.error("InvalidEntityPathException::Activity::getItemSystemKey() " + ex.toString());
- return null;
- }
- return mEntityPath;
- }
- /** @return the StateMachine */
- public StateMachine getMachine()
- {
- return machine;
+ mStateDate = new GTimeStamp();
+ DateUtility.setToNow(mStateDate);
}
- /** sets the StateMachine (Only for Serialisation) */
- public void setMachine(StateMachine sm)
- {
- machine = sm;
+
+ protected String getDefaultSMName() {
+ return "Default";
}
+
/** add the activity which id is idNext as next of the current one */
void addNext(String idNext)
{
@@ -101,153 +77,140 @@ public class Activity extends WfVertex {
return new Next(this, vertex);
}
- /** return the current State of the State machine */
- public int getCurrentState()
- {
- return machine.getCurrentState();
+
+ public StateMachine getStateMachine() throws InvalidDataException {
+ if (machine == null) {
+ String name = (String)getProperties().get("StateMachineName");
+ int version = getVersionNumberProperty("StateMachineVersion");
+ try {
+ machine = LocalObjectLoader.getStateMachine(name, version);
+ } catch (ObjectNotFoundException ex) {
+ if (name.equals(getDefaultSMName()) && version == 0) { // default state machine not imported yet. Fake it.
+ try {
+ String marshalledSM = Resource.getTextResource(null, "boot/SM/"+getDefaultSMName()+".xml");
+ StateMachine bootstrap = (StateMachine)Gateway.getMarshaller().unmarshall(marshalledSM);
+ bootstrap.validate();
+ machine = bootstrap;
+ return bootstrap;
+ } catch (Exception ex2) {
+ Logger.error(ex2);
+ throw new InvalidDataException("Could not bootstrap default state machine from resources.", "");
+ }
+ }
+ Logger.error(ex);
+ throw new InvalidDataException("Error loading state machine '"+name+"' v"+version, "");
+ }
+ }
+ return machine;
}
+
/** return the current State of the State machine (Used in Serialisation) */
- public int getState()
- {
- if (machine == null)
- machine = new StateMachine(this);
- return getCurrentState();
- }
- /** Sets a new State in a State machine */
- public void setState(int stat)
+ public int getState() throws InvalidDataException
{
- if (machine == null)
- machine = new StateMachine(this);
- machine.state = stat;
+ if (state == -1)
+ state = getStateMachine().getInitialStateCode();
+ return state;
}
- /** check the abiltity of the agent passed in param to act on the activity */
- //return's the agentName
- public String checkAccessRights(AgentPath agent) throws AccessRightsException
+ public String getStateName() throws InvalidDataException
{
- String agentID = getCurrentAgentName();
- boolean authorised = agentID.equals(agent.getAgentName());
- String actRole = getCurrentAgentRole();
- if (!authorised)
- {
- authorised = actRole == null || actRole.equals("") || actRole.equals("all");
- }
- if (!authorised)
- {
- RolePath[] roles = agent.getRoles();
- for (int i = 0; !authorised && i < roles.length; i++)
- {
- if (roles[i].getName().equalsIgnoreCase("Admin"))
- authorised = true;
- if (roles[i].getName().equalsIgnoreCase(actRole))
- authorised = true;
- if (roles[i].getName().equalsIgnoreCase("Guest"))
- throw new AccessRightsException("Guest execution forbidden");
- }
- }
- if (!authorised)
- throw new AccessRightsException("Activity::checkAccessRights() - Agent does not hold the correct role.");
- return agent.getAgentName();
+ return getStateMachine().getState(getState()).getName();
}
- /** cf Item request */
- public void request(AgentPath agent, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException
+
+ /** Sets a new State */
+ public void setState(int state)
{
- int state = getState();
- String agentName = checkAccessRights(agent);
- if (machine.traverse(transitionID))
- {
- setReservation(transitionID, agentName);
- sendEventStoreOutcome(transitionID, requestData, agent);
- if (transitionID == Transitions.REPEAT)
- {
- setActive(true);
- if (getIsComposite())
- {
- WfVertex v = (WfVertex) ((CompositeActivity) this).search(getPath() + "/" + ((CompositeActivity) this).getChildGraphModel().getStartVertexId());
- v.reinit(getID());
- try
- {
- runfirst(agent);
- }
- catch (ScriptingEngineException e)
- {
- Logger.error(e);
- }
- }
- }
- if ((transitionID == Transitions.COMPLETE || transitionID == Transitions.DONE) &&
- (state == States.RSTARTED || getProperties().get("Breakpoint").equals(Boolean.TRUE)))
- setActive(false);
- else if (transitionID == Transitions.START)
- start();
- else if ((transitionID == Transitions.SKIP && getActive())
- || transitionID == Transitions.DONE
- || transitionID == Transitions.COMPLETE
- || transitionID == Transitions.PROCEED)
- try
- {
- runNext(agent);
- }
- catch (ScriptingEngineException e)
- {
- Logger.error(e);
- }
- // run post execution script now
- try
- {
- String postSubmitScr = (String) getProperties().get("PostExecScriptName");
- String postSubmitVer = (String) getProperties().get("PostExecScriptVersion");
- if (postSubmitScr != null && (transitionID == Transitions.COMPLETE || transitionID == Transitions.DONE))
- evaluateScript(postSubmitScr, postSubmitVer);
- }
- catch (ScriptingEngineException ex)
- {
- Logger.error(ex);
- }
- //refresh all the job lists
- pushJobsToAgents();
- }
- else
- throw new InvalidTransitionException("Activity is in the wrong state.");
+ this.state = state;
}
- public void setReservation(int transitionID, String agentName)
- {
- String actAgentName = (String) getProperties().get("Agent Name");
- switch (transitionID)
- {
- // these transition reserve the activity
- case Transitions.REASSIGN :
- case Transitions.RESERVE :
- case Transitions.START :
- actAgentName = agentName;
- break;
- // these clear any current reservation
- case Transitions.COMPLETE :
- case Transitions.DONE :
- case Transitions.IGNORE :
- case Transitions.SKIP :
- actAgentName = "";
- // other transitions have no effect on the reservations
- default :
- }
- getProperties().put("Agent Name", actAgentName);
+
+ public boolean isFinished() throws InvalidDataException {
+ return getStateMachine().getState(getState()).isFinished();
}
- public String getTransitions()
+
+
+ /** cf Item request
+ * @throws ObjectNotFoundException
+ * @throws PersistencyException */
+ public void request(AgentPath agent, int itemSysKey, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException
{
- String result = "<PossibleTransitions>";
- int i;
- for (i = 0; i < machine.possibleTransition().length; i++)
- {
- result += machine.possibleTransition()[i] + ",";
+
+ // Find requested transition
+ Transition transition = getStateMachine().getTransition(transitionID);
+
+ // Check if the transition is possible
+ String usedRole = transition.getPerformingRole(this, agent);
+
+ // Verify outcome
+ Schema schema = null;
+ String viewName = null;
+ boolean storeOutcome = false;
+ if (transition.hasOutcome()) {
+ schema = transition.getSchema(getProperties());
+ viewName = (String)getProperties().get("Viewpoint");
+ if (requestData != null && requestData.length()>0)
+ storeOutcome = true;
+ else if (transition.getOutcome().isRequired())
+ throw new InvalidDataException("Transition requires outcome data, but none was given", null);
}
- //cuts out the last comma(',') if required
- if (i > 0)
- {
- result = result.substring(0, result.length() - 1);
+
+ // Get new state
+ State newState = getStateMachine().traverse(this, transition, agent);
+
+ // Run extra logic in predefined steps here
+ runActivityLogic(agent, itemSysKey, transitionID, requestData);
+
+ // set new state and reservation
+ setState(newState.getId());
+ getProperties().put("Agent Name", transition.getReservation(this, agent));
+
+ // store new event
+ Event newEvent = null;
+ try {
+ History hist = getWf().getHistory();
+ if (storeOutcome)
+ newEvent = hist.addEvent(agent.getAgentName(), usedRole, getName(), getPath(), getType(), schema.docType, schema.docVersion,
+ getStateMachine().getName(), getStateMachine().getVersion(), transition, viewName);
+ else
+ newEvent = hist.addEvent(agent.getAgentName(), usedRole, getName(), getPath(), getType(),
+ getStateMachine().getName(), getStateMachine().getVersion(), transition);
+
+ Logger.msg(7, "Activity::auditEvent() - Event:" + newEvent.getName() + " was added to the AuditTrail");
+
+ if (storeOutcome) {
+ Outcome newOutcome = new Outcome(newEvent.getID(), requestData, schema.docType, schema.docVersion);
+ Gateway.getStorage().put(itemSysKey, newOutcome, this);
+
+ // update specific view if defined
+ if (viewName != null && !viewName.equals("")) {
+ Viewpoint currentView = new Viewpoint(itemSysKey, schema.docType, viewName, schema.docVersion, newEvent.getID());
+ Gateway.getStorage().put(itemSysKey, currentView, this);
+ }
+ // update last view
+ Viewpoint currentView = new Viewpoint(itemSysKey, schema.docType, "last", schema.docVersion, newEvent.getID());
+ Gateway.getStorage().put(itemSysKey, currentView, this);
+ }
+ Gateway.getStorage().commit(this);
+ } catch (ClusterStorageException ex) {
+ Logger.error(ex);
+ throw new PersistencyException("Exception storing event data");
}
- result += "</PossibleTransitions>";
- return result;
+
+ if (newState.isFinished()) {
+ if (!getProperties().get("Breakpoint").equals(Boolean.TRUE))
+ runNext(agent, itemSysKey);
+ }
+
+ DateUtility.setToNow(mStateDate);
+
+ //refresh all the job lists
+ pushJobsToAgents(itemSysKey);
}
- /** launch the verification of the activity */
+
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+ // Overriden in predefined steps
+ return requestData;
+ }
+
@Override
public boolean verify()
{
@@ -310,9 +273,14 @@ public class Activity extends WfVertex loopTested = false;
return loop2;
}
- /** sets the next activity available if possible */
+ /** sets the next activity available if possible
+ * @throws ObjectNotFoundException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
+ * @throws PersistencyException
+ * @throws ObjectAlreadyExistsException */
@Override
- public void runNext(AgentPath agent) throws ScriptingEngineException
+ public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
setActive(false);
try
@@ -336,7 +304,7 @@ public class Activity extends WfVertex }
Logger.debug(8, outVertices + " " + outVertices2);
if (!hasNoNext)
- ((WfVertex) outVertices[0]).run(agent);
+ ((WfVertex) outVertices[0]).run(agent, itemSysKey);
else
{
if (getParent() != null && getParent().getName().equals("domain")) // workflow
@@ -346,11 +314,11 @@ public class Activity extends WfVertex {
CompositeActivity parent = (CompositeActivity) getParent();
if (parent != null)
- parent.runNext(agent);
+ parent.runNext(agent, itemSysKey);
}
}
}
- catch (ScriptingEngineException s)
+ catch (InvalidDataException s)
{
setActive(true);
throw s;
@@ -364,13 +332,14 @@ public class Activity extends WfVertex else
return null;
}
- /** reinitialises the Activity and propagate (for Loop) */
+ /** reinitialises the Activity and propagate (for Loop)
+ * @throws InvalidDataException
+ * @throws ObjectNotFoundException */
@Override
- public void reinit(int idLoop)
+ public void reinit(int idLoop) throws InvalidDataException
{
- Logger.debug(7, "reinit " + getItemEntityPath().getSysKey() + " " + getPath());
Vertex[] outVertices = getOutGraphables();
- machine.state = States.WAITING;
+ setState(getStateMachine().getInitialState().getId());
if (outVertices.length > 0)
{
WfVertex nextAct = (WfVertex) outVertices[0];
@@ -387,32 +356,44 @@ public class Activity extends WfVertex }
/**
* called by precedent Activity runNext() for setting the activity able to be executed
+ * @throws InvalidDataException
+ * @throws ObjectAlreadyExistsException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
+ * @throws ObjectNotFoundException
+ * @throws PersistencyException
*/
@Override
- public void run(AgentPath agent) throws ScriptingEngineException
+ public void run(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
- Logger.debug(8, getPath() + " run " + getCurrentState());
- if (!getActive())
- setActive(true);
-
- if (getMachine().getCurrentState() == States.FINISHED)
+ Logger.debug(8, getPath() + " run " + getState());
+
+ if (!getActive()) setActive(true);
+ boolean finished = getStateMachine().getState(getState()).isFinished();
+ if (finished)
{
- runNext(agent);
+ runNext(agent, itemSysKey);
}
else
{
- DateUtility.setToNow(mActiveDate);
- pushJobsToAgents();
+ DateUtility.setToNow(mStateDate);
+ pushJobsToAgents(itemSysKey);
}
}
/**
* sets the activity available to be executed on start of Workflow or composite activity (when it is the first one of the (sub)process
+ * @throws InvalidDataException
+ * @throws ObjectAlreadyExistsException
+ * @throws ObjectNotFoundException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
+ * @throws PersistencyException
*/
@Override
- public void runfirst(AgentPath agent) throws ScriptingEngineException
+ public void runFirst(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
Logger.debug(8, getPath() + " runfirst");
- run(agent);
+ run(agent, itemSysKey);
}
/** @return the current ability to be executed */
public boolean getActive()
@@ -439,191 +420,35 @@ public class Activity extends WfVertex {
return (String) getProperties().get("Agent Role");
}
- /**
- * @return an array of Steps that matches the querry
- * @param agentID
- * Agent concerned by the query
- * @param agentRole
- * Agent concerned by the query @int stateID state to test in the query, use -1 for all
- * @param filter
- * if tru will be filtered by agent, else won't
- */
- public Activity[] query(AgentPath agent, int stateID, boolean filter)
- {
- if (getCurrentState() == stateID || stateID == -1)
- {
- Activity[] steps = { this };
- if (!filter)
- return steps;
- else
- {
- try
- {
- checkAccessRights(agent);
- return steps;
- }
- catch (AccessRightsException e)
- {
- //case that agent is not allowed
- Logger.msg(7, "Activity :: AccessRightsException in " + this.getItemEntityPath() + "/" + this.getPath());
- }
- }
- }
- return new Activity[0];
- }
+
/**
* returns the lists of jobs for the activity and children (cf com.c2kernel.entity.Job)
*/
- public ArrayList<Job> calculateJobs(AgentPath agent, boolean recurse)
+ public ArrayList<Job> calculateJobs(AgentPath agent, int itemSysKey, boolean recurse) throws ObjectNotFoundException, InvalidDataException
{
- return calculateJobsBase(agent, false);
+ return calculateJobsBase(agent, itemSysKey, false);
} //
- public ArrayList<Job> calculateAllJobs(AgentPath agent, boolean recurse)
+ public ArrayList<Job> calculateAllJobs(AgentPath agent, int itemSysKey, boolean recurse) throws ObjectNotFoundException, InvalidDataException
{
- return calculateJobsBase(agent, true);
+ return calculateJobsBase(agent, itemSysKey, true);
}
- private ArrayList<Job> calculateJobsBase(AgentPath agent, boolean all)
+ private ArrayList<Job> calculateJobsBase(AgentPath agent, int itemSysKey, boolean includeInactive) throws ObjectNotFoundException, InvalidDataException
{
Logger.msg(7, "calculateJobs - " + getPath());
- int[] transitions = {
- };
ArrayList<Job> jobs = new ArrayList<Job>();
- try
- {
- String agentName = checkAccessRights(agent);
- String currentAgentName = getCurrentAgentName();
- boolean isCurrent = currentAgentName == null || currentAgentName.equals("") || agentName.equals(currentAgentName);
- if ((all || getActive()) && !getName().equals("domain"))
- transitions = machine.possibleTransition();
- Logger.msg(7, "Activity.calculateJobs() - Got " + transitions.length + " transitions.");
- for (int i = 0; i < transitions.length; i++)
- {
- Logger.msg(7, "Creating Job object for transition " + transitions[i]);
- if ((isCurrent && !(transitions[i] == Transitions.REASSIGN && agentName.equals(currentAgentName))) || (transitions[i] == Transitions.REASSIGN && !agentName.equals(currentAgentName)))
- jobs.add(new Job(getItemEntityPath().getSysKey(), getPath(), transitions[i], getCurrentState(), machine.simulate(transitions[i]), getName(), getProperties(), getType(), agentName));
+ Map<Transition, String> transitions;
+ if ((includeInactive || getActive()) && !getName().equals("domain")) {
+ transitions = getStateMachine().getPossibleTransitions(this, agent);
+ Logger.msg(7, "Activity.calculateJobs() - Got " + transitions.size() + " transitions.");
+ for (Transition transition : transitions.keySet()) {
+ Logger.msg(7, "Creating Job object for transition " + transition);
+ jobs.add(new Job(this, itemSysKey, transition, agent, transitions.get(transition)));
}
}
- catch (AccessRightsException ex)
- {
- Logger.msg(6, "Agent "+ agent.getAgentName() +" is not allowed to interact with "+getItemEntityPath().getSysKey()+":"+getPath());
- } // empty joblist then
return jobs;
}
-
-
- /** Adds an event to the AuditTrail of the Item if any */
- private Event auditEvent(int transitionID, AgentPath agent, boolean hasOutcome, boolean isError)
- {
- EntityPath entityPath = getItemEntityPath();
- if (entityPath != null)
- {
- Event event = null;
- History hist = null;
- String viewName = hasOutcome?(String)getProperties().get("Viewpoint"):null;
- try
- {
- hist = getWf().getHistory();
- if (hasOutcome) {
- String schemaName = isError?"Errors":(String)getProperties().get("SchemaType");
- String schemaVersion = isError?"0":(String)getProperties().get("SchemaVersion");
- event = hist.addEvent(agent.getAgentName(), getCurrentAgentRole(), transitionID, getName(), getPath(), getType(), schemaName, Integer.valueOf(schemaVersion), viewName, getCurrentState());
- }
- else
- event = hist.addEvent(agent.getAgentName(), getCurrentAgentRole(), transitionID, getName(), getPath(), getType(), getCurrentState());
- Logger.msg(7, "Activity::auditEvent() - Event:" + event.getName() + " was added to the AuditTrail");
- }
- catch (Exception ex)
- {
- Logger.error("Activity::auditEvent() - Item '" + entityPath.toString() + "'!");
- Logger.error(ex);
- }
- return event;
- }
- else
- return null;
- }
-
- /**
- * Stores the request data as an outcome of the Item It does a great deal of storing outcomes in different configuration
- */ //requestdata is xmlstring
-
- private String storeOutcome(int eventID, String requestData, boolean isError) throws InvalidDataException
- {
- EntityPath entityPath = getItemEntityPath();
- if (requestData == null || requestData.length() == 0)
- throw new InvalidDataException("Empty outcome", "");
- if (entityPath != null)
- {
- String schemaType;
- int schemaVersion;
-
- if (isError) {
- schemaType="Errors";
- schemaVersion=0;
- }
- else {
- schemaType = (String) getProperties().get("SchemaType");
- if (schemaType == null || schemaType.length() == 0) return null;
- String versionString = (String) getProperties().get("SchemaVersion");
- try
- {
- schemaVersion = Integer.parseInt(versionString);
- } catch (Exception e) {
- throw new InvalidDataException("Activity.storeOutcome() - invalid schemaVersion " + versionString, "");
- }
- }
-
- Logger.msg(5, "Activity::storeOutcome() - type:" + schemaType + " version:" + schemaVersion);
- try
- {
- Object locker = getWf();
- Outcome newOutcome = new Outcome(eventID, requestData, schemaType, schemaVersion);
- Gateway.getStorage().put(entityPath.getSysKey(), newOutcome, locker);
- // update specific view if defined
- String specificView = (String) getProperties().get("Viewpoint");
- if (specificView != null && !specificView.equals(""))
- {
- Viewpoint currentView = new Viewpoint(entityPath.getSysKey(), schemaType, specificView, schemaVersion, eventID);
- Gateway.getStorage().put(entityPath.getSysKey(), currentView, locker);
- } // update last view
- Viewpoint currentView = new Viewpoint(entityPath.getSysKey(), schemaType, "last", schemaVersion, eventID);
- Gateway.getStorage().put(entityPath.getSysKey(), currentView, locker);
- return schemaType + "/" + schemaVersion + "/" + eventID;
- }
- catch (Exception ex)
- {
- Logger.error("ActivityBase::storeOutcome() - Item '" + entityPath.toString() + "'!");
- Logger.error(ex);
- }
- return null;
- }
- else
- return null;
- }
-
- /** the method to be called by the requestAction() method
- * @throws InvalidDataException */
- public void sendEventStoreOutcome(int transitionID, String requestData, AgentPath agent) throws InvalidDataException
- {
- int eventID = -1;
- String schemaType = (String) getProperties().get("SchemaType");
- boolean hasOutcome = (transitionID == Transitions.DONE || transitionID == Transitions.COMPLETE) && (schemaType != null && schemaType.length() > 0);
- boolean hasErrorOutcome = transitionID == Transitions.SUSPEND && requestData != null && requestData.length()>0;
- Object locker = getWf();
- Event event = auditEvent(transitionID, agent, hasOutcome, hasErrorOutcome);
- if (event != null)
- eventID = event.getID();
- if (hasOutcome || hasErrorOutcome)
- storeOutcome(eventID, requestData, hasErrorOutcome);
- EntityPath entityPath = getItemEntityPath();
- TransactionManager storage = Gateway.getStorage();
- if (entityPath != null)
- {
- storage.commit(locker);
- }
- }
- public void pushJobsToAgents()
+ public void pushJobsToAgents(int itemSysKey)
{
String agentRole = getCurrentAgentRole();
if (agentRole == null || agentRole.length()==0) return;
@@ -638,45 +463,33 @@ public class Activity extends WfVertex }
if (myRole.hasJobList())
- new JobPusher(this, myRole).start();
+ new JobPusher(this, itemSysKey, myRole).start();
}
-
-
- /**
- * Returns the activeDate.
- *
- * @return GTimeStamp
- */
- public GTimeStamp getActiveDate()
- {
- return mActiveDate;
- } /**
+
+ /**
* Returns the startDate.
*
* @return GTimeStamp
*/
- public GTimeStamp getStartDate()
- {
- return mStartDate;
- } /**
- * Sets the activeDate.
- *
- * @param activeDate
- * The activeDate to set
- */
- public void setActiveDate(GTimeStamp activeDate)
+ public GTimeStamp getStateDate()
{
- mActiveDate = activeDate;
- } /**
- * Sets the startDate.
- *
- * @param startDate
- * The startDate to set
- */
- public void setStartDate(GTimeStamp startDate)
+ return mStateDate;
+ }
+ public void setStateDate(GTimeStamp startDate)
{
- mStartDate = startDate;
- } /**
+ mStateDate = startDate;
+ }
+
+ @Deprecated
+ public void setActiveDate(GTimeStamp date)
+ { }
+ @Deprecated
+ public void setStartDate(GTimeStamp date)
+ {
+ setStateDate(date);
+ }
+
+ /**
* Returns the type.
*
* @return String
@@ -694,10 +507,5 @@ public class Activity extends WfVertex {
mType = type;
}
- private void start()
- {
- Logger.debug(8, getPath() + " start");
- DateUtility.setToNow(mStartDate);
- }
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/AdvancementCalculator.java b/src/main/java/com/c2kernel/lifecycle/instance/AdvancementCalculator.java index 982d951..6302dc7 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/AdvancementCalculator.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/AdvancementCalculator.java @@ -3,8 +3,8 @@ package com.c2kernel.lifecycle.instance; import java.io.Serializable;
import java.util.Hashtable;
+import com.c2kernel.common.InvalidDataException;
import com.c2kernel.graph.model.Vertex;
-import com.c2kernel.lifecycle.instance.stateMachine.States;
//import com.c2kernel.utils.Logger;
/** @author XSeb74 */
public class AdvancementCalculator implements Serializable
@@ -28,7 +28,7 @@ public class AdvancementCalculator implements Serializable HasNextMarked = new Hashtable<Vertex, Vertex>();
hasprevActive = new Hashtable<String, Vertex>();
}
- public void calculate(CompositeActivity act)
+ public void calculate(CompositeActivity act) throws InvalidDataException
{
// Logger.debug(0, act.getName()+" >>>>>>>>>");
if (act instanceof Workflow)
@@ -58,7 +58,7 @@ public class AdvancementCalculator implements Serializable j++;
if (j != 0 && j==nexts.length) current.HasNextMarked.put(v, nexts[0]);
}
- private void calc(Vertex v, AdvancementCalculator current)
+ private void calc(Vertex v, AdvancementCalculator current) throws InvalidDataException
{
if (current.isMarked.get(v) != null && !(v instanceof Join))
return;
@@ -87,20 +87,11 @@ public class AdvancementCalculator implements Serializable {
current.mCurrentNbActExp += 1;
current.mMaximuNbActexp += 1;
- if (act.getCurrentState() == States.FINISHED)
+ if (act.isFinished())
{
current.mNbActpassed += 1;
current.mNbActpassedWithCurrent += 1;
}
- else if (act.getActive()&&act.getState()<States.REPEATSTATESTART)
- {
- current.mIsbranchActive = true;
- current.mIsbranchFinished = false;
- current.mHasPrevActive = true;
-// Logger.debug(0, "set HasprevActive to true " + act.getName());
- current.mNbActpassedWithCurrent += 1;
- current.mNbActLeftWithCurrent += 1;
- }
else
{
current.mIsbranchFinished = false;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java b/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java index 63b5640..0ecdb7f 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java @@ -1,7 +1,11 @@ package com.c2kernel.lifecycle.instance;
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.scripting.ScriptingEngineException;
/**
* @version $Revision: 1.16 $ $Date: 2005/05/10 15:14:54 $
* @author $Author: abranson $
@@ -16,12 +20,12 @@ public class AndSplit extends Split super();
}
@Override
- public void runNext(AgentPath agent) throws ScriptingEngineException
+ public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
AdvancementCalculator adv = new AdvancementCalculator();
adv.calculate((CompositeActivity) getParent());
Vertex[] outVertices = getOutGraphables();
for (Vertex outVertice : outVertices)
- ((WfVertex) outVertice).run(agent);
+ ((WfVertex) outVertice).run(agent, itemSysKey);
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java b/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java index f3f5a81..f9ab0fe 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java @@ -1,20 +1,17 @@ package com.c2kernel.lifecycle.instance;
import java.util.ArrayList;
-import java.util.Vector;
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.agent.Job;
import com.c2kernel.graph.model.GraphModel;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.graph.model.GraphableVertex;
-import com.c2kernel.lifecycle.instance.stateMachine.States;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.scripting.ScriptingEngineException;
import com.c2kernel.utils.Logger;
/**
@@ -23,9 +20,8 @@ import com.c2kernel.utils.Logger; */
public class CompositeActivity extends Activity
{
- /**
- * @see java.lang.Object#Object()
- */
+
+
/*
* --------------------------------------------
* ----------------CONSTRUCTOR-----------------
@@ -37,6 +33,14 @@ public class CompositeActivity extends Activity setChildrenGraphModel(new GraphModel(new WfVertexOutlineCreator()));
setIsComposite(true);
}
+
+ // State machine
+ public static final int START = 0;
+ public static final int COMPLETE = 1;
+ @Override
+ protected String getDefaultSMName() {
+ return "CompositeActivity";
+ }
@Override
public void setChildrenGraphModel(GraphModel childrenGraph) {
@@ -276,66 +280,40 @@ public class CompositeActivity extends Activity }
/**
+ * @throws InvalidDataException
+ * @throws ObjectNotFoundException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
+ * @throws PersistencyException
* @see com.c2kernel.lifecycle.instance.WfVertex#run()
*/
@Override
- public void run(AgentPath agent) throws ScriptingEngineException
+ public void run(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
- super.run(agent);
- if (getChildrenGraphModel().getStartVertex() != null && getMachine().getCurrentState() != States.FINISHED)
+ super.run(agent, itemSysKey);
+ if (getChildrenGraphModel().getStartVertex() != null && !getStateMachine().getState(state).isFinished())
{
WfVertex first = (WfVertex) getChildrenGraphModel().getStartVertex();
- first.run(agent);
+ first.run(agent, itemSysKey);
}
}
@Override
- public void runNext(AgentPath agent) throws ScriptingEngineException
- {
- if (getMachine().state != States.FINISHED)
- getMachine().traverse(Transitions.COMPLETE);
- super.runNext(agent);
- }
-
- /**
- * @see com.c2kernel.lifecycle.instance.Activity#query(com.c2kernel.common.AgentInfo,
- * java.lang.String, boolean)
- */
- @Override
- public Activity[] query(AgentPath agent, int stateID, boolean filter)
+ public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException, AccessRightsException, InvalidTransitionException, ObjectNotFoundException, PersistencyException
{
- Vector<Activity[]> steps = new Vector<Activity[]>();
- Activity[] returnArray = null;
- for (int i = 0; i < getChildren().length; i++)
- {
- if (getChildren()[i] instanceof Activity)
- steps.addElement(((Activity) getChildren()[i]).query(agent, stateID, filter));
- }
- int j = 0;
- for (int i = 0; i < steps.size(); i++)
- j += steps.elementAt(i).length;
- Activity[] tmp = super.query(agent, stateID, filter);
- if (tmp.length == 1)
- {
- returnArray = new Activity[j + 1];
- returnArray[j] = tmp[0];
- } else
- returnArray = new Activity[j];
- j = 0;
- for (int i = 0; i < steps.size(); i++)
- {
- Activity[] stepArray = steps.elementAt(i);
- for (Activity element : stepArray)
- returnArray[j++] = element;
- }
- return returnArray;
+ if (!getStateMachine().getState(state).isFinished())
+ request(agent, itemSysKey, CompositeActivity.COMPLETE, null);
+ super.runNext(agent, itemSysKey);
}
+ /**
+ * @throws InvalidDataException
+ * @throws ObjectNotFoundException
* @see com.c2kernel.lifecycle.instance.Activity#calculateJobs()
*/
@Override
- public ArrayList<Job> calculateJobs(AgentPath agent, boolean recurse)
+ public ArrayList<Job> calculateJobs(AgentPath agent, int itemSysKey, boolean recurse) throws ObjectNotFoundException, InvalidDataException
{
ArrayList<Job> jobs = new ArrayList<Job>();
boolean childActive = false;
@@ -344,16 +322,16 @@ public class CompositeActivity extends Activity if (getChildren()[i] instanceof Activity)
{
Activity child = (Activity) getChildren()[i];
- jobs.addAll(child.calculateJobs(agent, recurse));
+ jobs.addAll(child.calculateJobs(agent, itemSysKey, recurse));
childActive |= child.active;
}
if (!childActive)
- jobs.addAll(super.calculateJobs(agent, recurse));
+ jobs.addAll(super.calculateJobs(agent, itemSysKey, recurse));
return jobs;
}
@Override
- public ArrayList<Job> calculateAllJobs(AgentPath agent, boolean recurse)
+ public ArrayList<Job> calculateAllJobs(AgentPath agent, int itemSysKey, boolean recurse) throws ObjectNotFoundException, InvalidDataException
{
ArrayList<Job> jobs = new ArrayList<Job>();
if (recurse)
@@ -361,9 +339,9 @@ public class CompositeActivity extends Activity if (getChildren()[i] instanceof Activity)
{
Activity child = (Activity) getChildren()[i];
- jobs.addAll(child.calculateAllJobs(agent, recurse));
+ jobs.addAll(child.calculateAllJobs(agent, itemSysKey, recurse));
}
- jobs.addAll(super.calculateAllJobs(agent, recurse));
+ jobs.addAll(super.calculateAllJobs(agent, itemSysKey, recurse));
return jobs;
}
@@ -425,36 +403,33 @@ public class CompositeActivity extends Activity }
/**
+ * @throws InvalidDataException
*
*/
@Override
- public void reinit(int idLoop)
+ public void reinit(int idLoop) throws InvalidDataException
{
super.reinit(idLoop);
- if (getChildrenGraphModel().getStartVertex() != null && getMachine().getCurrentState() != States.FINISHED)
+ if (getChildrenGraphModel().getStartVertex() != null && !getStateMachine().getState(state).isFinished())
((WfVertex) getChildrenGraphModel().getStartVertex()).reinit(idLoop);
}
@Override
- public void request(AgentPath agent, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException
+ public void request(AgentPath agent, int itemSysKey, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException
{
- if (getChildrenGraphModel().getStartVertex() != null && getMachine().getCurrentState() != States.FINISHED && transitionID == Transitions.START)
- try
- {
- ((WfVertex) getChildrenGraphModel().getStartVertex()).run(agent);
- } catch (ScriptingEngineException e)
- {
- Logger.error(e);
- }
- super.request(agent, transitionID, requestData);
+ if (getChildrenGraphModel().getStartVertex() != null && !getStateMachine().getState(state).isFinished() && transitionID == CompositeActivity.START)
+ ((WfVertex) getChildrenGraphModel().getStartVertex()).run(agent, itemSysKey);
+
+ super.request(agent, itemSysKey, transitionID, requestData);
}
- public void refreshJobs()
+
+ public void refreshJobs(int itemSysKey)
{
GraphableVertex[] children = getChildren();
for (GraphableVertex element : children)
if (element instanceof CompositeActivity)
- ((CompositeActivity) element).refreshJobs();
+ ((CompositeActivity) element).refreshJobs(itemSysKey);
else if (element instanceof Activity)
- ((Activity) element).pushJobsToAgents();
+ ((Activity) element).pushJobsToAgents(itemSysKey);
}
}
\ No newline at end of file diff --git a/src/main/java/com/c2kernel/lifecycle/instance/JobPusher.java b/src/main/java/com/c2kernel/lifecycle/instance/JobPusher.java index 190758a..a0a51d0 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/JobPusher.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/JobPusher.java @@ -1,13 +1,10 @@ package com.c2kernel.lifecycle.instance;
import java.util.Enumeration;
-import java.util.Iterator;
import com.c2kernel.entity.Agent;
import com.c2kernel.entity.AgentHelper;
-import com.c2kernel.entity.agent.Job;
import com.c2kernel.entity.agent.JobArrayList;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.RolePath;
import com.c2kernel.process.Gateway;
@@ -16,16 +13,18 @@ import com.c2kernel.utils.Logger; final class JobPusher extends Thread {
private final Activity activity;
private final RolePath myRole;
+ private final int itemSysKey;
- JobPusher(Activity activity, RolePath role) {
+ JobPusher(Activity activity, int itemSysKey, RolePath role) {
this.activity = activity;
+ this.itemSysKey = itemSysKey;
this.myRole = role;
}
@Override
public void run()
{
- Thread.currentThread().setName("Agent job pusher for "+activity.getName()+" to role "+myRole);
+ Thread.currentThread().setName("Agent job pusher for "+itemSysKey+":"+activity.getName()+" to role "+myRole);
for (Enumeration<AgentPath> e = myRole.getChildren(); e.hasMoreElements();)
{
AgentPath nextAgent = e.nextElement();
@@ -33,25 +32,14 @@ final class JobPusher extends Thread { try
{
// get joblist for user
- JobArrayList jobList = new JobArrayList(this.activity.calculateJobs(nextAgent, false));
- // only transmit start, complete and resume jobs
- for (Iterator<Job> element = jobList.list.iterator(); element.hasNext();)
- {
- Job thisJob = element.next();
- if (thisJob.getPossibleTransition() != Transitions.START
- && thisJob.getPossibleTransition() != Transitions.COMPLETE
- && thisJob.getPossibleTransition() != Transitions.RESUME
- && thisJob.getPossibleTransition() != Transitions.SUSPEND
- && thisJob.getPossibleTransition() != Transitions.REASSIGN)
- element.remove();
- }
+ JobArrayList jobList = new JobArrayList(this.activity.calculateJobs(nextAgent, itemSysKey, false));
Logger.msg(7, "Activity.pushJobsToAgents() - User will receive " + jobList.list.size() + " jobs");
String stringJobs = Gateway.getMarshaller().marshall(jobList);
// push it to the agent
org.omg.CORBA.Object agentIOR = nextAgent.getIOR();
Agent thisAgent = AgentHelper.narrow(agentIOR);
Logger.msg(7, "Calling agent "+thisAgent.getSystemKey()+" from "+activity.getPath());
- thisAgent.refreshJobList(this.activity.getItemEntityPath().getSysKey(), activity.getPath(), stringJobs);
+ thisAgent.refreshJobList(itemSysKey, activity.getPath(), stringJobs);
}
catch (Exception ex)
{
@@ -61,7 +49,7 @@ final class JobPusher extends Thread { + " of role "
+ myRole
+ " could not be found to be informed of a change in "
- + this.activity.getItemEntityPath().getSysKey());
+ + itemSysKey);
Logger.error(ex);
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Join.java b/src/main/java/com/c2kernel/lifecycle/instance/Join.java index 3a4fd7d..7f50ece 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Join.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Join.java @@ -1,10 +1,14 @@ package com.c2kernel.lifecycle.instance;
import java.util.Vector;
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.graph.traversal.GraphTraversal;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.scripting.ScriptingEngineException;
/**
* @version $Revision: 1.52 $ $Date: 2005/05/10 15:14:54 $
* @author $Author: abranson $
@@ -22,12 +26,17 @@ public class Join extends WfVertex }
private boolean loopTested;
public int counter = 0;
- private String mItemSystemKey = "";
+
/**
+ * @throws InvalidDataException
+ * @throws ObjectNotFoundException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
+ * @throws PersistencyException
* @see com.c2kernel.lifecycle.instance.WfVertex#runNext()
*/
@Override
- public void runNext(AgentPath agent) throws ScriptingEngineException
+ public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
AdvancementCalculator adv = new AdvancementCalculator();
adv.calculate((CompositeActivity) getParent());
@@ -37,10 +46,10 @@ public class Join extends WfVertex if (outVertices.length > 0)
{
WfVertex nextAct = (WfVertex) outVertices[0];
- nextAct.run(agent);
+ nextAct.run(agent, itemSysKey);
}
else
- super.runNext(agent);
+ super.runNext(agent, itemSysKey);
}
}
/**
@@ -53,10 +62,11 @@ public class Join extends WfVertex new Next(this, (WfVertex) getParent().search(idNext));
}
/**
+ * @throws InvalidDataException
* @see com.c2kernel.lifecycle.instance.WfVertex#reinit(int)
*/
@Override
- public void reinit(int idLoop)
+ public void reinit(int idLoop) throws InvalidDataException
{
Vertex[] outVertices = getOutGraphables();
if (outVertices.length == 1)
@@ -65,33 +75,7 @@ public class Join extends WfVertex nextAct.reinit(idLoop);
}
}
- /**
- * Method getItemSystemKey.
- *
- * @return String
- */
- /*
- * public CompositeActivity process() { return parent.process(); }
- */
- public String getItemSystemKey()
- {
- return mItemSystemKey;
- }
- /**
- * Method setItemSystemKey.
- *
- * @param itemSystemKey
- */
- public void setItemSystemKey(String itemSystemKey)
- {
- mItemSystemKey = itemSystemKey;
- }
- /**
- * @see com.c2kernel.lifecycle.instance.WfVertex#verify()
- */
- // public void initItemSystemKey(String systemKey) {
- // this.setItemSystemKey(systemKey);
- // }
+
@Override
public boolean verify()
{
@@ -165,12 +149,17 @@ public class Join extends WfVertex return mErrors.elementAt(0);
}
/**
+ * @throws InvalidDataException
+ * @throws ObjectNotFoundException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
+ * @throws PersistencyException
* @see com.c2kernel.lifecycle.instance.WfVertex#run()
*/
@Override
- public void run(AgentPath agent) throws ScriptingEngineException
+ public void run(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
- runNext(agent);
+ runNext(agent, itemSysKey);
}
/**
* @see com.c2kernel.lifecycle.instance.WfVertex#addNext(com.c2kernel.lifecycle.instance.WfVertex)
@@ -199,9 +188,9 @@ public class Join extends WfVertex return loop2;
}
@Override
- public void runfirst(AgentPath agent) throws ScriptingEngineException
+ public void runFirst(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
- runNext(agent);
+ runNext(agent, itemSysKey);
}
/*
* (non-Javadoc)
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Loop.java b/src/main/java/com/c2kernel/lifecycle/instance/Loop.java index 8228ba9..51d6133 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Loop.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Loop.java @@ -1,8 +1,12 @@ package com.c2kernel.lifecycle.instance;
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.graph.traversal.GraphTraversal;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.scripting.ScriptingEngineException;
import com.c2kernel.utils.Logger;
/**
* @version $Revision: 1.35 $ $Date: 2005/05/10 15:14:54 $
@@ -26,22 +30,23 @@ public class Loop extends XOrSplit return true;
}
@Override
- public void followNext(Next activeNext, AgentPath agent) throws ScriptingEngineException
+ public void followNext(Next activeNext, AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
WfVertex v = activeNext.getTerminusVertex();
if (!isInPrev(v))
- v.run(agent);
+ v.run(agent, itemSysKey);
else
{
v.reinit(getID());
- v.run(agent);
+ v.run(agent, itemSysKey);
}
}
/**
+ * @throws InvalidDataException
* @see com.c2kernel.lifecycle.instance.WfVertex#reinit(int)
*/
@Override
- public void reinit(int idLoop)
+ public void reinit(int idLoop) throws InvalidDataException
{
Logger.msg(8, "Loop.reinit");
if (idLoop == getID())
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java b/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java index aea34b2..b9fc263 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java @@ -1,6 +1,7 @@ package com.c2kernel.lifecycle.instance;
import java.util.StringTokenizer;
+import com.c2kernel.common.InvalidDataException;
import com.c2kernel.graph.model.DirectedEdge;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.scripting.ScriptingEngineException;
@@ -19,12 +20,17 @@ public class OrSplit extends Split super();
}
@Override
- public void runNext(AgentPath agent) throws ScriptingEngineException
+ public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException
{
- String nexts =
- this
- .evaluateScript((String) getProperties().get("RoutingScriptName"), (String) getProperties().get("RoutingScriptVersion"))
- .toString();
+ String nexts;
+ String scriptName = (String) getProperties().get("RoutingScriptName");
+ Integer scriptVersion = getVersionNumberProperty("RoutingScriptVersion");
+ try {
+ nexts = this.evaluateScript(scriptName, scriptVersion, itemSysKey).toString();
+ } catch (ScriptingEngineException e) {
+ Logger.error(e);
+ throw new InvalidDataException("Error running routing script "+scriptName+" v"+scriptVersion, null);
+ }
StringTokenizer tok = new StringTokenizer(nexts, ",");
Logger.msg(7, tok.countTokens() + " nexts to activate:" + nexts);
int active = 0;
@@ -42,7 +48,7 @@ public class OrSplit extends Split if (thisNext != null && thisNext.equals(nextEdge.getProperties().get("Alias")))
{
WfVertex term = nextEdge.getTerminusVertex();
- term.run(agent);
+ term.run(agent, itemSysKey);
Logger.msg(7, "Running " + nextEdge.getProperties().get("Alias"));
active++;
}
@@ -55,7 +61,7 @@ public class OrSplit extends Split Logger.error(e);
}
if (active == 0)
- throw new ScriptingEngineException("No nexts were activated!");
+ throw new InvalidDataException("No nexts were activated!", null);
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/ParserWF.java b/src/main/java/com/c2kernel/lifecycle/instance/ParserWF.java deleted file mode 100644 index 1e52e6b..0000000 --- a/src/main/java/com/c2kernel/lifecycle/instance/ParserWF.java +++ /dev/null @@ -1,356 +0,0 @@ -package com.c2kernel.lifecycle.instance;
-
-import java.io.IOException;
-import java.util.Vector;
-
-import com.c2kernel.graph.model.GraphPoint;
-import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.utils.CastorHashMap;
-import com.c2kernel.utils.Logger;
-
-/**
- * @version $Revision: 1.26 $ $Date: 2006/03/03 13:52:21 $
- * @author $Author: abranson $
- */
-public class ParserWF
-{
- static Vector<String[]> nexts;
- static String file = "";
- static int i;
- static CastorHashMap mInfo = new CastorHashMap();
-
- /**
- * Method addStep.
- * @param act
- * @param xmlfile
- * @return CompositeActivity
- * @throws IOException
- */
- /**
- * @associates <{com.c2kernel.lifecycle.instance.Workflow}>
- * @label creates
- */
- public static CompositeActivity addStep(CompositeActivity act, String xmlfile, AgentPath agent) throws IOException
- {
- nexts = new Vector<String[]>(1, 1);
- i = 0;
- file = xmlfile;
- while (i < file.length() - 5)
- {
- if (file.substring(i, i + 5).equals("<STEP"))
- {
- readStep(act);
- }
- else
- {
- i++;
- }
- }
- boolean flag = false;
- for (int j = 0; j < nexts.size(); j++)
- {
- for (int k = j + 1; k < nexts.size(); k++)
- {
- if (nexts.elementAt(j)[0].equals(nexts.elementAt(k)[0]))
- {
- int tmp = act.newSplitChild("And", new GraphPoint(0, 0)).getID();
- ((WfVertex) act.search(nexts.elementAt(k)[0])).addNext(act.search(tmp));
- ((Split) act.search(tmp)).addNext((WfVertex) act.search(nexts.elementAt(k)[1]));
- ((Split) act.search(tmp)).addNext((WfVertex) act.search(nexts.elementAt(j)[1]));
- nexts.removeElementAt(k--);
- flag = true;
- }
- }
- if (flag)
- {
- nexts.removeElementAt(j--);
- }
- flag = false;
- }
- for (int j = 0; j < nexts.size(); j++)
- {
- for (int k = j + 1; k < nexts.size(); k++)
- {
- if (nexts.elementAt(j)[1].equals(nexts.elementAt(k)[1]))
- {
- int tmp = act.newJoinChild(new GraphPoint(0, 0)).getID();
- ((WfVertex) act.search(nexts.elementAt(j)[0])).addNext(act.search(tmp));
- ((WfVertex) act.search(nexts.elementAt(k)[0])).addNext(act.search(tmp));
- ((Join) act.search(tmp)).addNext(nexts.elementAt(j)[1]);
- nexts.removeElementAt(k--);
- flag = true;
- }
- }
- if (flag)
- {
- nexts.removeElementAt(j--);
- }
- flag = false;
- }
- for (int j = 0; j < nexts.size(); j++)
- {
- Logger.msg(
- 7,
- "try to add next " + nexts.elementAt(j)[1] + " to " + nexts.elementAt(j)[0]);
- ((Activity) act.search(nexts.elementAt(j)[0])).addNext(nexts.elementAt(j)[1]);
- }
- if (act instanceof Workflow)
- try
- {
- act.run(agent);
- }
- catch (Exception ex)
- {
- Logger.error(ex);
- }
- return act;
- }
-
- private static void readStep(CompositeActivity parent)
- {
- Activity act = null;
- String[] step = new String[15];
- for (int j = 0; j < 15; j++)
- {
- step[j] = "";
- }
- i += 5;
- while (!file.substring(i, i + 7).equals("</STEP>"))
- {
- if (file.substring(i, i + 5).equals("<STEP"))
- {
- Logger.msg(7, "<STEP");
- if (!step[14].equals("done"))
- {
- act = parent.newCompChild(step[0], step[12].startsWith("true"), new GraphPoint(0, 0));
- }
- readStep((CompositeActivity) act);
- step[14] = "done";
- }
- else if (file.substring(i, i + 3).equals("Id="))
- {
- Logger.msg(7, "Id=");
- i += 4;
- int j = 0;
- while (file.charAt(i + j) != '"')
- {
- j++;
- }
- step[0] = file.substring(i, i + j);
- i += (j + 1);
- }
- else if (file.substring(i, i + 6).equals("Alias="))
- {
- Logger.msg(7, "Alias=");
- i += 7;
- int j = 0;
- while (file.charAt(i + j) != '"')
- {
- j++;
- }
- step[10] = file.substring(i, i + j);
- i += (j + 1);
- }
- else if (file.substring(i, i + 9).equals("Resource="))
- {
- Logger.msg(7, "Ressource=");
- i += 10;
- int j = 0;
- while (file.charAt(i + j) != '"')
- {
- j++;
- }
- step[1] = file.substring(i, i + j);
- i += (j + 1);
- }
- else if (file.substring(i, i + 6).equals("First="))
- {
- Logger.msg(7, "First=");
- i += 7;
- int j = 0;
- ;
- while (file.charAt(i + j) != '"')
- {
- j++;
- }
- step[12] = file.substring(i, i + j);
- i += (j + 1);
- }
- else if (file.substring(i, i + 3).equals("LC="))
- {
- Logger.msg(7, "LC=");
- i += 4;
- int j = 0;
- ;
- while (file.charAt(i + j) != '"')
- {
- j++;
- }
- step[2] = file.substring(i, i + j);
- i += (j + 1);
- }
- else if (file.substring(i, i + 3).equals("WC="))
- {
- Logger.msg(7, "WC=");
- i += 4;
- int j = 0;
- ;
- while (file.charAt(i + j) != '"')
- {
- j++;
- }
- step[3] = file.substring(i, i + j);
- i += (j + 1);
- }
- else if (file.substring(i, i + 6).equals("Posts="))
- {
- Logger.msg(7, "Posts=");
- i += 7;
- int j = 0;
- ;
- while (file.charAt(i + j) != '"')
- {
- j++;
- }
- step[4] = file.substring(i, i + j);
- i += (j + 1);
- }
- else if (file.substring(i, i + 17).equals("Preparation-Time="))
- {
- Logger.msg(7, "Preparation-Time=");
- i += 18;
- int j = 0;
- ;
- while (file.charAt(i + j) != '"')
- {
- j++;
- }
- step[5] = file.substring(i, i + j);
- i += (j + 1);
- }
- else if (file.substring(i, i + 12).equals("Active-Time="))
- {
- Logger.msg(7, "Active-Time=");
- i += 13;
- int j = 0;
- ;
- while (file.charAt(i + j) != '"')
- {
- j++;
- }
- step[6] = file.substring(i, i + j);
- i += (j + 1);
- }
- else if (file.substring(i, i + 13).equals("OP-Startdate="))
- {
- Logger.msg(7, "OP-Startdate=");
- i += 14;
- int j = 0;
- ;
- while (file.charAt(i + j) != '"')
- {
- j++;
- }
- step[7] = file.substring(i, i + j);
- i += (j + 1);
- }
- else if (file.substring(i, i + 11).equals("OP-Enddate="))
- {
- Logger.msg(7, "OP-Enddate=");
- i += 12;
- int j = 0;
- ;
- while (file.charAt(i + j) != '"')
- {
- j++;
- }
- step[8] = file.substring(i, i + j);
- i += (j + 1);
- }
- else if (file.substring(i, i + 13).equals("<DESCRIPTION>"))
- {
- Logger.msg(7, "<DESCRIPTION>");
- i += 13;
- int j = 0;
- ;
- while (file.charAt(i + j) != '<')
- {
- j++;
- }
- step[9] = file.substring(i, i + j);
- i += (j + 14);
- }
- else if (file.substring(i, i + 6).equals("<NEXT>"))
- {
- Logger.msg(7, "<NEXT>");
- i += 6;
- int j = 0;
- ;
- String[] tmp = new String[2];
- while (file.charAt(i + j) != '<')
- {
- j++;
- }
- tmp[0] = step[0];
- tmp[0] = parent.getPath() + "/" + tmp[0];
- tmp[1] = file.substring(i, i + j);
- tmp[1] = parent.getPath() + "/" + tmp[1];
- nexts.addElement(tmp);
- i += (j + 8);
- Logger.msg(7, "</NEXT>");
- }
- else if (file.substring(i, i + 5).equals("Path="))
- {
- Logger.msg(7, "Path=");
- i += 6;
- int j = 0;
- ;
- step[11] = file.substring(i, i + j);
- while (file.charAt(i + j) != '"')
- {
- j++;
- }
- i += (j + 1);
- }
- else
- {
- i++;
- }
- }
- i += 7;
- if (!step[14].equals("done"))
- act = parent.newAtomChild(step[0], step[12].startsWith("true"), new GraphPoint(0, 0));
- Logger.msg(7, "Step Created");
-
- try
- {
- Logger.msg(7, "Starting to create info");
- if (!step[1].equals(""))
- act.getProperties().put("Agent ID", step[1]);
- if (!step[2].equals(""))
- act.getProperties().put("Lc", step[2]);
- if (!step[3].equals(""))
- act.getProperties().put("Wc", step[3]);
- if (!step[4].equals(""))
- act.getProperties().put("Posts", step[4]);
- if (!step[5].equals(""))
- act.getProperties().put("PreparationTime", step[5]);
- if (!step[6].equals(""))
- act.getProperties().put("ActiveTime", step[6]);
- if (!step[7].equals(""))
- act.getProperties().put("OpStartdate", step[7]);
- if (!step[8].equals(""))
- act.getProperties().put("OpEnddate", step[8]);
- if (!step[9].equals(""))
- act.getProperties().put("Description", step[9]);
- Logger.msg(7, "create info for " + act.getID());
- Logger.msg(7, "Finished to create info");
- }
- catch (Exception e)
- {
- Logger.error(e);
- }
- file = file.substring(i);
- i = 0;
- }
-}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Split.java b/src/main/java/com/c2kernel/lifecycle/instance/Split.java index 4fe1bfc..a123391 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Split.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Split.java @@ -2,10 +2,14 @@ package com.c2kernel.lifecycle.instance; import java.util.Vector;
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.graph.traversal.GraphTraversal;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.scripting.ScriptingEngineException;
/**
* @version $Revision: 1.47 $ $Date: 2006/05/29 13:17:45 $
@@ -27,13 +31,16 @@ public abstract class Split extends WfVertex private boolean loopTested;
- private int mItemSystemKey = -1;
-
/**
+ * @throws InvalidDataException
+ * @throws ObjectNotFoundException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
+ * @throws PersistencyException
* @see com.c2kernel.lifecycle.instance.WfVertex#runNext()
*/
@Override
- public abstract void runNext(AgentPath agent) throws ScriptingEngineException;
+ public abstract void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException;
/**
* Method addNext.
@@ -64,34 +71,8 @@ public abstract class Split extends WfVertex return nxt;
}
- /**
- * Method getItemSystemKey.
- *
- * @return int
- */
- public int getItemSystemKey()
- {
- return mItemSystemKey;
- }
-
- /**
- * Method setItemSystemKey.
- *
- * @param itemSystemKey
- */
- public void setItemSystemKey(int itemSystemKey)
- {
- mItemSystemKey = itemSystemKey;
- }
-
- /**
- * @see com.c2kernel.lifecycle.instance.WfVertex#reinit(int)
- */
- // public void initItemSystemKey(String systemKey) {
- // setItemSystemKey(systemKey);
- // }
@Override
- public void reinit(int idLoop)
+ public void reinit(int idLoop) throws InvalidDataException
{
Vertex[] outVertices = getOutGraphables();
for (Vertex outVertice : outVertices)
@@ -165,12 +146,17 @@ public abstract class Split extends WfVertex }
/**
+ * @throws InvalidDataException
+ * @throws ObjectNotFoundException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
+ * @throws PersistencyException
* @see com.c2kernel.lifecycle.instance.WfVertex#run()
*/
@Override
- public void run(AgentPath agent) throws ScriptingEngineException
+ public void run(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
- runNext(agent);
+ runNext(agent, itemSysKey);
}
/**
@@ -217,9 +203,9 @@ public abstract class Split extends WfVertex }
@Override
- public void runfirst(AgentPath agent) throws ScriptingEngineException
+ public void runFirst(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
- runNext(agent);
+ runNext(agent, itemSysKey);
}
}
\ No newline at end of file diff --git a/src/main/java/com/c2kernel/lifecycle/instance/WfVertex.java b/src/main/java/com/c2kernel/lifecycle/instance/WfVertex.java index b74aac8..de5f56f 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/WfVertex.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/WfVertex.java @@ -4,10 +4,13 @@ package com.c2kernel.lifecycle.instance; import java.util.HashMap;
+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.graph.model.GraphableVertex;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.lifecycle.routingHelpers.ViewpointDataHelper;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.EntityPath;
@@ -25,8 +28,14 @@ import com.c2kernel.utils.Logger; public abstract class WfVertex extends GraphableVertex
{
/**sets the activity available to be executed on start of Workflow or composite activity (when it is the first one of the
- * (sub)process*/
- public abstract void runfirst(AgentPath agent) throws ScriptingEngineException;
+ * (sub)process
+ * @throws InvalidDataException
+ * @throws ObjectAlreadyExistsException
+ * @throws ObjectNotFoundException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
+ * @throws PersistencyException */
+ public abstract void runFirst(AgentPath agent, int itemSysKey) throws ScriptingEngineException, InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, ObjectAlreadyExistsException, PersistencyException;
/**
* @see java.lang.Object#Object()
@@ -40,12 +49,18 @@ public abstract class WfVertex extends GraphableVertex /**
* Method runNext.
+ * @throws InvalidDataException
+ * @throws ObjectNotFoundException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
+ * @throws PersistencyException
+ * @throws ObjectAlreadyExistsException
*/
- public void runNext(AgentPath agent) throws ScriptingEngineException
+ public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
try
{
- ((CompositeActivity)getParent()).request(agent, Transitions.COMPLETE, null);
+ ((CompositeActivity)getParent()).request(agent, itemSysKey, CompositeActivity.COMPLETE, null);
}
catch (Exception e)
{
@@ -57,8 +72,10 @@ public abstract class WfVertex extends GraphableVertex /**
* Method reinit.
* @param idLoop
+ * @throws InvalidDataException
+ * @throws ObjectNotFoundException
*/
- public abstract void reinit( int idLoop );
+ public abstract void reinit( int idLoop ) throws InvalidDataException;
/**
* Method verify.
@@ -74,8 +91,14 @@ public abstract class WfVertex extends GraphableVertex /**
* Method run.
+ * @throws InvalidDataException
+ * @throws ObjectAlreadyExistsException
+ * @throws ObjectNotFoundException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
+ * @throws PersistencyException
*/
- public abstract void run(AgentPath agent) throws ScriptingEngineException;
+ public abstract void run(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException;
/**
* Method loop.
@@ -89,12 +112,11 @@ public abstract class WfVertex extends GraphableVertex */
public abstract Next addNext(WfVertex vertex);
- protected Object evaluateScript(String scriptName, String scriptVersion) throws ScriptingEngineException
+ protected Object evaluateScript(String scriptName, Integer scriptVersion, int itemSysKey) throws ScriptingEngineException
{
try
{
- EntityPath entity = ((CompositeActivity) getParent()).getWf().getItemEntityPath();
Script script = getScript(scriptName, scriptVersion);
KeyValuePair[] k = getProperties().getKeyValuePairs();
@@ -109,7 +131,7 @@ public abstract class WfVertex extends GraphableVertex {
value = value.substring(11);
if (value.startsWith("."))
- value = entity.getSysKey() + value.substring(1);
+ value = itemSysKey + value.substring(1);
try {
inputParam = ViewpointDataHelper.get(value)[0];
} catch (ArrayIndexOutOfBoundsException ex) {
@@ -120,7 +142,7 @@ public abstract class WfVertex extends GraphableVertex {
value = value.substring(10);
try {
- inputParam = Gateway.getStorage().get(entity.getSysKey(), ClusterStorage.PROPERTY+"/"+value, null);
+ inputParam = Gateway.getStorage().get(itemSysKey, ClusterStorage.PROPERTY+"/"+value, null);
} catch (ObjectNotFoundException ex) {
inputParam = null;
}
@@ -131,7 +153,7 @@ public abstract class WfVertex extends GraphableVertex }
if (requiredInput.containsKey("item")) {
- script.setInputParamValue("item", Gateway.getProxyManager().getProxy(entity));
+ script.setInputParamValue("item", Gateway.getProxyManager().getProxy(new EntityPath(itemSysKey)));
}
if (requiredInput.containsKey("agent")) {
AgentPath systemAgent = Gateway.getLDAPLookup().getRoleManager().getAgentPath("system");
@@ -150,24 +172,18 @@ public abstract class WfVertex extends GraphableVertex }
}
- private static Script getScript(String name, String version) throws ScriptingEngineException
+ private static Script getScript(String name, Integer version) throws ScriptingEngineException
{
if (name == null || name.length() == 0)
throw new ScriptingEngineException("Script name is empty");
Script script;
- try
- {
- script = new Script(name, Integer.parseInt(version));
+ if (version!=null) {
+ Logger.debug(version.toString());
+ script = new Script(name, version);
}
- catch (NumberFormatException e)
- { // version not valid
+ else { // empty version: try expression
int split = name.indexOf(":");
- if (split > -1)
- {
- script = new Script(name.substring(0, split), name.substring(split + 1));
- }
- else
- throw new ScriptingEngineException("Script version is invalid");
+ script = new Script(name.substring(0, split), name.substring(split + 1));
}
return script;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java index 13a7db6..e3a6b7f 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java @@ -6,16 +6,15 @@ 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.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;
/**
@@ -45,7 +44,6 @@ public class Workflow extends CompositeActivity implements C2KLocalObject */
public Workflow()
{
- getProperties().put("ItemSystemKey", null);
}
public Workflow(CompositeActivity domain) {
@@ -96,14 +94,15 @@ public class Workflow extends CompositeActivity implements C2KLocalObject * @throws AccessRightsException
* @throws InvalidTransitionException
* @throws InvalidDataException
+ * @throws PersistencyException
*/
//requestData is xmlstring
- public void requestAction(AgentPath agent, String stepPath, int transitionID, String requestData)
- throws ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException
+ public void requestAction(AgentPath agent, String stepPath, int itemSysKey, int transitionID, String requestData)
+ throws ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, PersistencyException
{
- Logger.msg(3, "Action: " + Transitions.getTransitionName(transitionID) + " " + stepPath + " by " + agent.getAgentName());
+ Logger.msg(3, "Action: " + transitionID + " " + stepPath + " by " + agent.getAgentName());
if (search(stepPath) != null)
- ((Activity) search(stepPath)).request(agent, transitionID, requestData);
+ ((Activity) search(stepPath)).request(agent, itemSysKey, transitionID, requestData);
else
throw new ObjectNotFoundException(stepPath + " not found", "");
}
@@ -167,35 +166,42 @@ public class Workflow extends CompositeActivity implements C2KLocalObject * Method initialise.
*
* @param systemKey
+ * @throws InvalidDataException
+ * @throws ObjectNotFoundException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
*/
- public void initialise(int systemKey, AgentPath agent)
+ public void initialise(int systemKey, AgentPath agent) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException
{
- this.getProperties().put("ItemSystemKey", new Integer(systemKey));
try
{
- runfirst(agent);
+ runFirst(agent, systemKey);
}
- catch (ScriptingEngineException ex)
+ catch (InvalidDataException ex)
{
Logger.error(ex);
+ } catch (PersistencyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
}
- /**
- * 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
+ * @param agent
+ * @param itemSysKey
+ * @param type
+ * @return
+ * @throws ObjectNotFoundException
+ * @throws InvalidDataException
*/
- public ArrayList<Job> calculateJobs(AgentPath agent, int type)
+ public ArrayList<Job> calculateJobs(AgentPath agent, int itemSysKey, int type) throws ObjectNotFoundException, InvalidDataException
{
ArrayList<Job> jobs = new ArrayList<Job>();
if (type != 1)
- jobs.addAll(((CompositeActivity) search("workflow/domain")).calculateJobs(agent, true));
+ jobs.addAll(((CompositeActivity) search("workflow/domain")).calculateJobs(agent, itemSysKey, true));
if (type != 0)
- jobs.addAll(((CompositeActivity) search("workflow/predefined")).calculateJobs(agent, true));
+ jobs.addAll(((CompositeActivity) search("workflow/predefined")).calculateJobs(agent, itemSysKey, true));
return jobs;
}
/**
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java b/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java index 25baf0b..65bd4ba 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java @@ -3,9 +3,15 @@ package com.c2kernel.lifecycle.instance; import java.util.ArrayList;
import java.util.StringTokenizer;
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.graph.model.DirectedEdge;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.scripting.ScriptingEngineException;
+import com.c2kernel.utils.Logger;
/**
* @version $Revision: 1.23 $ $Date: 2006/03/03 13:52:21 $
@@ -22,12 +28,18 @@ public class XOrSplit extends Split }
@Override
- public void runNext(AgentPath agent) throws ScriptingEngineException
+ public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
{
ArrayList<DirectedEdge> nextsToFollow = new ArrayList<DirectedEdge>();
- String nexts = this.evaluateScript(
- (String) getProperties().get("RoutingScriptName"),
- (String) getProperties().get("RoutingScriptVersion")).toString();
+ String nexts;
+ String scriptName = (String) getProperties().get("RoutingScriptName");
+ Integer scriptVersion = getVersionNumberProperty("RoutingScriptVersion");
+ try {
+ nexts = this.evaluateScript(scriptName, scriptVersion, itemSysKey).toString();
+ } catch (ScriptingEngineException e) {
+ Logger.error(e);
+ throw new InvalidDataException("Error running routing script "+scriptName+" v"+scriptVersion, "");
+ }
StringTokenizer tok = new StringTokenizer(nexts,",");
String[] nextsTab = new String[tok.countTokens()];
@@ -41,14 +53,14 @@ public class XOrSplit extends Split }
// Logger.debug(0, getID()+" following "+nexts);
if (nextsToFollow.size() != 1)
- throw new ScriptingEngineException("not good number of active next");
+ throw new InvalidDataException("not good number of active next", null);
- followNext((Next)nextsToFollow.get(0), agent);
+ followNext((Next)nextsToFollow.get(0), agent, itemSysKey);
}
- public void followNext(Next activeNext, AgentPath agent) throws ScriptingEngineException {
- activeNext.getTerminusVertex().run(agent);
+ public void followNext(Next activeNext, AgentPath agent, int itemSysKey) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException {
+ activeNext.getTerminusVertex().run(agent, itemSysKey);
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddC2KObject.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddC2KObject.java index df0c62f..2f0cf95 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddC2KObject.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddC2KObject.java @@ -11,12 +11,9 @@ package com.c2kernel.lifecycle.instance.predefined;
-import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.EntityPath;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -37,38 +34,25 @@ public class AddC2KObject extends PredefinedStep //requestdata is xmlstring
@Override
- public void request( AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
Logger.msg(1, "AddC2KObject::request() - Starting.");
- checkAccessRights(agent);
- EntityPath entityPath = getItemEntityPath();
-
- if (entityPath!=null)
+ try
{
- try
- {
-
- Logger.msg(5, "AddC2KObject::request() - data:" + getDataList(requestData)[0]);
- C2KLocalObject obj = (C2KLocalObject)Gateway.getMarshaller().unmarshall(getDataList(requestData)[0]);
- Gateway.getStorage().put(entityPath.getSysKey(), obj, null );
- sendEventStoreOutcome(transitionID, requestData, agent);
- }
- catch( Exception ex )
- {
- Logger.error("AddC2KObject::request() - during unmarshall.");
- Logger.error(ex);
- throw new InvalidDataException(ex.toString(), "");
- }
-
- Logger.msg(1, "AddC2KObject::request() - DONE.");
+ Logger.msg(5, "AddC2KObject::request() - data:" + getDataList(requestData)[0]);
+ C2KLocalObject obj = (C2KLocalObject)Gateway.getMarshaller().unmarshall(getDataList(requestData)[0]);
+ Gateway.getStorage().put(itemSysKey, obj, null );
+ Logger.msg(1, "AddC2KObject::request() - DONE.");
+ return requestData;
+ }
+ catch( Exception ex )
+ {
+ Logger.error("AddC2KObject::request() - during unmarshall.");
+ Logger.error(ex);
+ throw new InvalidDataException(ex.toString(), "");
}
- else
- throw new InvalidDataException("EntityPath is null.", "");
}
-}
+}
\ No newline at end of file diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java index 2cf619e..d28fe3c 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java @@ -10,9 +10,7 @@ package com.c2kernel.lifecycle.instance.predefined; -import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.EntityPath;
@@ -30,25 +28,22 @@ public class AddDomainPath extends PredefinedStep //requestdata is xmlstring
@Override
- public void request( AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
Logger.msg(8,"AddAlias::request()");
LDAPLookup lookupManager = Gateway.getLDAPLookup();
Logger.msg(1,"AddAlias::request() - Starting.");
- checkAccessRights(agent);
try
{
- EntityPath entityPath = getItemEntityPath();
- DomainPath domainPath = new DomainPath(getDataList(requestData)[0], entityPath);
+ DomainPath domainPath = new DomainPath(getDataList(requestData)[0], new EntityPath(itemSysKey));
lookupManager.add(domainPath);
- Logger.msg(8,"AddDomainPath::request() - systemKey:" + entityPath.getSysKey() +
+ Logger.msg(8,"AddDomainPath::request() - systemKey:" + itemSysKey +
". Adding dompath. DONE.");
+ return requestData;
}
catch (InvalidEntityPathException ex)
{
@@ -62,6 +57,5 @@ public class AddDomainPath extends PredefinedStep throw new InvalidDataException(ex.toString(), "");
}
- sendEventStoreOutcome(transitionID, requestData, agent);
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java index 106a9aa..7153c52 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java @@ -14,13 +14,10 @@ package com.c2kernel.lifecycle.instance.predefined; import com.c2kernel.collection.Dependency;
import com.c2kernel.collection.MembershipException;
-import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.EntityPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
@@ -50,23 +47,17 @@ public class AddMemberToCollection extends PredefinedStep * 1 - target entity key
*/
@Override
- public void request(AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
- EntityPath entityPath = getItemEntityPath();
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
String collName;
int entityKey;
Dependency dep;
Logger.msg(1, "AddMemberToCollection::request() - Starting.");
- checkAccessRights(agent);
-
// extract parameters
try {
- entityPath = getItemEntityPath();
String[] params = getDataList(requestData);
collName = params[0];
entityKey = Integer.parseInt(params[1]);
@@ -77,7 +68,7 @@ public class AddMemberToCollection extends PredefinedStep // load collection
C2KLocalObject collObj;
try {
- collObj = Gateway.getStorage().get(entityPath.getSysKey(), ClusterStorage.COLLECTION+"/"+collName, null);
+ collObj = Gateway.getStorage().get(itemSysKey, ClusterStorage.COLLECTION+"/"+collName, null);
} catch (ObjectNotFoundException ex) {
throw new InvalidDataException("Collection '"+collName+"' not found in this Item", "");
} catch (ClusterStorageException ex) {
@@ -95,13 +86,13 @@ public class AddMemberToCollection extends PredefinedStep }
try {
- Gateway.getStorage().put(entityPath.getSysKey(), dep, null);
+ Gateway.getStorage().put(itemSysKey, dep, null);
} catch (ClusterStorageException e) {
Logger.error(e);
throw new InvalidDataException("Error storing collection", "");
}
- sendEventStoreOutcome(transitionID, requestData, agent);
Logger.msg(1, "AddMemberToCollection::request() - DONE.");
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java index 1bc13ef..e38f71d 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java @@ -13,13 +13,10 @@ package com.c2kernel.lifecycle.instance.predefined; import com.c2kernel.collection.Aggregation;
-import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.EntityPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
@@ -53,23 +50,17 @@ public class AddNewSlot extends PredefinedStep * 1 - Item Description key (optional)
*/
@Override
- public void request(AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
- EntityPath entityPath = getItemEntityPath();
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
String collName;
int descKey=-1;
Aggregation agg;
Logger.msg(1, "AddNewSlot::request() - Starting.");
- checkAccessRights(agent);
-
// extract parameters
try {
- entityPath = getItemEntityPath();
String[] params = getDataList(requestData);
collName = params[0];
if (params.length > 1) descKey = Integer.parseInt(params[1]);
@@ -80,7 +71,7 @@ public class AddNewSlot extends PredefinedStep // load collection
C2KLocalObject collObj;
try {
- collObj = Gateway.getStorage().get(entityPath.getSysKey(), ClusterStorage.COLLECTION+"/"+collName, null);
+ collObj = Gateway.getStorage().get(itemSysKey, ClusterStorage.COLLECTION+"/"+collName, null);
} catch (ObjectNotFoundException ex) {
throw new InvalidDataException("Collection '"+collName+"' not found in this Item", "");
} catch (ClusterStorageException ex) {
@@ -110,13 +101,13 @@ public class AddNewSlot extends PredefinedStep agg.addSlot(props, classProps.toString());
try {
- Gateway.getStorage().put(entityPath.getSysKey(), agg, null);
+ Gateway.getStorage().put(itemSysKey, agg, null);
} catch (ClusterStorageException e) {
Logger.error(e);
throw new InvalidDataException("Error storing collection", "");
}
- sendEventStoreOutcome(transitionID, requestData, agent);
Logger.msg(1, "AddNewSlot::request() - DONE.");
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddStepsFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddStepsFromDescription.java index 5a23424..30d014c 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddStepsFromDescription.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddStepsFromDescription.java @@ -1,9 +1,7 @@ package com.c2kernel.lifecycle.instance.predefined;
//Java
-import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.lifecycle.CompositeActivityDef;
import com.c2kernel.lifecycle.instance.CompositeActivity;
@@ -20,18 +18,16 @@ public class AddStepsFromDescription extends PredefinedStep }
@Override
- public void request( AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException, InvalidTransitionException, InvalidDataException
- {
- Workflow lifeCycle = getWf();
-
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
+
Logger.msg(1, "AddStepsFromDescription::request() - Starting ");
- checkAccessRights(agent);
+ Workflow lifeCycle = getWf();
try
{
-
Logger.msg(8, "AddStepsFromDescription::request() - data:" + getDataList(requestData)[0]);
lifeCycle.getChildGraphModel().removeVertex(lifeCycle.search("workflow/domain"));
CompositeActivityDef actDef = (CompositeActivityDef) Gateway.getMarshaller().unmarshall(getDataList(requestData)[0]);
@@ -39,10 +35,10 @@ public class AddStepsFromDescription extends PredefinedStep lifeCycle.initChild(domain, true, new GraphPoint(150, 100));
domain.setName("domain");
domain.setType(actDef.getName());
- lifeCycle.run(agent);
- Gateway.getStorage().put(getItemEntityPath().getSysKey(), lifeCycle, null);
+ lifeCycle.run(agent, itemSysKey);
+ Gateway.getStorage().put(itemSysKey, lifeCycle, null);
Logger.msg(1, "AddStepsFromDescription::request() - DONE.");
- sendEventStoreOutcome(transitionID, requestData, agent);
+ return requestData;
}
catch (Exception ex)
{
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java index f16d76d..7d36f35 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java @@ -15,13 +15,10 @@ package com.c2kernel.lifecycle.instance.predefined; import com.c2kernel.collection.Aggregation;
import com.c2kernel.collection.AggregationMember;
import com.c2kernel.collection.MembershipException;
-import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.EntityPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
@@ -50,12 +47,9 @@ public class AssignItemToSlot extends PredefinedStep * 2 - target entity key
*/
@Override
- public void request(AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
- EntityPath entityPath = getItemEntityPath();
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
String collName;
int slotNo;
int entityKey;
@@ -63,11 +57,9 @@ public class AssignItemToSlot extends PredefinedStep Logger.msg(1, "AssignItemToSlot::request() - Starting.");
- checkAccessRights(agent);
// extract parameters
try {
- entityPath = getItemEntityPath();
String[] params = getDataList(requestData);
collName = params[0];
slotNo = Integer.parseInt(params[1]);
@@ -79,7 +71,7 @@ public class AssignItemToSlot extends PredefinedStep // load collection
C2KLocalObject collObj;
try {
- collObj = Gateway.getStorage().get(entityPath.getSysKey(), ClusterStorage.COLLECTION+"/"+collName, null);
+ collObj = Gateway.getStorage().get(itemSysKey, ClusterStorage.COLLECTION+"/"+collName, null);
} catch (ObjectNotFoundException ex) {
throw new InvalidDataException("Collection '"+collName+"' not found in this Item", "");
} catch (ClusterStorageException ex) {
@@ -110,13 +102,12 @@ public class AssignItemToSlot extends PredefinedStep try {
- Gateway.getStorage().put(entityPath.getSysKey(), agg, null);
+ Gateway.getStorage().put(itemSysKey, agg, null);
} catch (ClusterStorageException e) {
Logger.error(e);
throw new InvalidDataException("Error storing collection", "");
}
- sendEventStoreOutcome(transitionID, requestData, agent);
-
Logger.msg(1, "AssignItemToSlot::request() - DONE.");
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java index 66df3b2..60e63f1 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java @@ -14,12 +14,9 @@ package com.c2kernel.lifecycle.instance.predefined; import com.c2kernel.collection.Aggregation;
import com.c2kernel.collection.AggregationMember;
-import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.EntityPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
@@ -47,23 +44,17 @@ public class ClearSlot extends PredefinedStep * 1 - slot number
*/
@Override
- public void request(AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
- EntityPath entityPath = getItemEntityPath();
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
String collName;
int slotNo;
Aggregation agg;
Logger.msg(1, "ClearSlot::request() - Starting.");
- checkAccessRights(agent);
-
// extract parameters
try {
- entityPath = getItemEntityPath();
String[] params = getDataList(requestData);
collName = params[0];
slotNo = Integer.parseInt(params[1]);
@@ -73,7 +64,7 @@ public class ClearSlot extends PredefinedStep // load collection
try {
- agg = (Aggregation)Gateway.getStorage().get(entityPath.getSysKey(), ClusterStorage.COLLECTION+"/"+collName, null);
+ agg = (Aggregation)Gateway.getStorage().get(itemSysKey, ClusterStorage.COLLECTION+"/"+collName, null);
} catch (ObjectNotFoundException ex) {
throw new InvalidDataException("Collection '"+collName+"' not found in this Item", "");
} catch (ClusterStorageException ex) {
@@ -98,13 +89,12 @@ public class ClearSlot extends PredefinedStep try {
- Gateway.getStorage().put(entityPath.getSysKey(), agg, null);
+ Gateway.getStorage().put(itemSysKey, agg, null);
} catch (ClusterStorageException e) {
Logger.error(e);
throw new InvalidDataException("Error storing collection", "");
}
- sendEventStoreOutcome(transitionID, requestData, agent);
-
Logger.msg(1, "ClearSlot::request() - DONE.");
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java index ce5ec73..10e54d1 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java @@ -19,13 +19,11 @@ import com.c2kernel.collection.CollectionDescription; import com.c2kernel.collection.CollectionMember;
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.CorbaServer;
import com.c2kernel.entity.TraceableEntity;
import com.c2kernel.lifecycle.CompositeActivityDef;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.EntityPath;
@@ -54,15 +52,15 @@ public class CreateItemFromDescription extends PredefinedStep //requestdata is xmlstring
@Override
- public void request(AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException, InvalidTransitionException, InvalidDataException,ObjectAlreadyExistsException
- {
- String[] input = getDataList(requestData);
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
+ String[] input = getDataList(requestData);
String newName = input[0];
String domPath = input[1];
CompositeActivityDef wfDef;
String wfDefName = null;
- String wfDefVer = null;
+ int wfDefVer = -1;
if (input.length > 2) // override wf
wfDefName = input[2];
@@ -70,8 +68,6 @@ public class CreateItemFromDescription extends PredefinedStep Logger.msg(1, "AddNewItem::request() - Starting.");
TransactionManager storage = Gateway.getStorage();
LDAPLookup lookup = Gateway.getLDAPLookup();
- EntityPath myPath = getItemEntityPath();
- checkAccessRights(agent);
try {
// check if the path is already taken
@@ -81,13 +77,13 @@ public class CreateItemFromDescription extends PredefinedStep throw new ObjectAlreadyExistsException("The item name " +newName+ " exists already.", "");
// get init objects
- String[] collNames = storage.getClusterContents(myPath.getSysKey(), ClusterStorage.COLLECTION);
+ String[] collNames = storage.getClusterContents(itemSysKey, ClusterStorage.COLLECTION);
ArrayList<String> collections = new ArrayList<String>();
// loop through collections to instantiate
for (String collName : collNames) {
- Collection<? extends CollectionMember> thisCol = (Collection<? extends CollectionMember>)storage.get(myPath.getSysKey(), ClusterStorage.COLLECTION+"/"+collName, null);
+ Collection<? extends CollectionMember> thisCol = (Collection<? extends CollectionMember>)storage.get(itemSysKey, ClusterStorage.COLLECTION+"/"+collName, null);
if (thisCol instanceof CollectionDescription) {
CollectionDescription<? extends CollectionMember> thisDesc = (CollectionDescription<? extends CollectionMember>)thisCol;
collections.add(Gateway.getMarshaller().marshall(thisDesc.newInstance()));
@@ -97,14 +93,19 @@ public class CreateItemFromDescription extends PredefinedStep // get the first member from the wf collection
CollectionMember wfMember = members.get(0);
wfDefName = wfMember.resolveEntity().getName();
- wfDefVer = (String)wfMember.getProperties().get("Version");
+ Object wfVerObj = wfMember.getProperties().get("Version");
+ try {
+ wfDefVer = Integer.parseInt(wfVerObj.toString());
+ } catch (NumberFormatException ex) {
+ throw new InvalidDataException("Invalid workflow version number: "+wfVerObj.toString(), "");
+ }
}
}
// load workflow def
if (wfDefName == null)
throw new InvalidDataException("No workflow given or defined", "");
- if (wfDefVer == null)
+ if (wfDefVer == -1)
throw new InvalidDataException("No workflow def version given","");
try {
@@ -117,7 +118,7 @@ public class CreateItemFromDescription extends PredefinedStep // copy properties -- intend to create from propdesc
- PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(myPath.getSysKey());
+ PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(itemSysKey);
props = pdList.instanciate();
// set Name prop or create if not present
boolean foundName = false;
@@ -162,7 +163,8 @@ public class CreateItemFromDescription extends PredefinedStep String[] colls = new String[1];
for (Iterator<String> iter = collections.iterator(); iter.hasNext();) {
colls[0] = iter.next();
- newItem.requestAction(agent.getSysKey(), "workflow/predefined/AddC2KObject", Transitions.DONE, PredefinedStep.bundleData(colls));
+ // TODO: initialize
+ newItem.requestAction(agent.getSysKey(), "workflow/predefined/AddC2KObject", PredefinedStep.DONE, PredefinedStep.bundleData(colls));
}
}
@@ -170,17 +172,11 @@ public class CreateItemFromDescription extends PredefinedStep Logger.msg(3, "CreateItemFromDescription - Creating "+context);
context.setEntity(entityPath);
Gateway.getLDAPLookup().add(context);
- } catch (ObjectAlreadyExistsException e) {
- Logger.error(e);
- throw e;
- } catch (AccessRightsException e) {
- Logger.error(e);
- throw e;
+ return requestData;
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException(e.getMessage(), "");
}
- sendEventStoreOutcome(transitionID, requestData, agent);
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/Erase.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/Erase.java index 84b1b78..20c9fb7 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/Erase.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/Erase.java @@ -15,9 +15,7 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Enumeration;
-import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.EntityPath;
@@ -42,35 +40,31 @@ public class Erase extends PredefinedStep //requestdata is xmlstring
@Override
- public void request(AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
Logger.msg(1, "Erase::request() - Starting.");
- checkAccessRights(agent);
try
{
- EntityPath entityPath = getItemEntityPath();
// FIXME: This should search for the entity key. Name shouldn't be unique.
// find entity name
- Property name = (Property)Gateway.getStorage().get(entityPath.getSysKey(), ClusterStorage.PROPERTY+"/Name", null);
+ Property name = (Property)Gateway.getStorage().get(itemSysKey, ClusterStorage.PROPERTY+"/Name", null);
// get all domain paths
Enumeration<Path> domPaths = Gateway.getLDAPLookup().search(new DomainPath(), name.getValue());
while (domPaths.hasMoreElements()) {
DomainPath path = (DomainPath)domPaths.nextElement();
// delete them
- if (path.getSysKey() == entityPath.getSysKey())
+ if (path.getSysKey() == itemSysKey)
Gateway.getLDAPLookup().delete(path);
}
//clear out all storages
- Gateway.getStorage().removeCluster(entityPath.getSysKey(), "", null);
+ Gateway.getStorage().removeCluster(itemSysKey, "", null);
- //remove domain path
- Gateway.getLDAPLookup().delete(entityPath);
+ //remove entity path
+ Gateway.getLDAPLookup().delete(new EntityPath(itemSysKey));
}
catch( Exception ex )
{
@@ -80,6 +74,7 @@ public class Erase extends PredefinedStep }
Logger.msg(1, "Erase::request() - DONE.");
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/Import.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/Import.java index cbdc33b..9b25546 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/Import.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/Import.java @@ -7,9 +7,7 @@ package com.c2kernel.lifecycle.instance.predefined;
-import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.events.Event;
import com.c2kernel.events.History;
import com.c2kernel.lookup.AgentPath;
@@ -39,17 +37,13 @@ public class Import extends PredefinedStep //requestdata is xmlstring
@Override
- public void request( AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
Logger.msg(8,"Import::request()");
Logger.msg(1,"Import::request() - Starting.");
- checkAccessRights(agent);
-
String[] params = getDataList(requestData);
@@ -75,22 +69,23 @@ public class Import extends PredefinedStep timestamp = Event.timeToString(Event.getGMT());
// write event, outcome and viewpoints to storage
- int syskey = getItemEntityPath().getSysKey();
+
TransactionManager storage = Gateway.getStorage();
Object locker = getWf();
History hist = getWf().getHistory();
- Event event = hist.addEvent(agent.getAgentName(), getCurrentAgentRole(), transitionID, getName(), getPath(), getType(), schemaName, schemaVersion, viewpoint, getCurrentState(), timestamp);
+ Event event = hist.addEvent(agent.getAgentName(), getCurrentAgentRole(), getName(), getPath(), getType(), schemaName, schemaVersion, getStateMachine().getName(), getStateMachine().getVersion(), getStateMachine().getTransition(transitionID), viewpoint, timestamp);
try {
- storage.put(syskey, new Outcome(event.getID(), requestData, schemaName, schemaVersion), locker);
- storage.put(syskey, new Viewpoint(syskey, schemaName, viewpoint, schemaVersion, event.getID()), locker);
+ storage.put(itemSysKey, new Outcome(event.getID(), requestData, schemaName, schemaVersion), this);
+ storage.put(itemSysKey, new Viewpoint(itemSysKey, schemaName, viewpoint, schemaVersion, event.getID()), this);
if (!"last".equals(viewpoint))
- storage.put(syskey, new Viewpoint(syskey, schemaName, "last", schemaVersion, event.getID()), locker);
+ storage.put(itemSysKey, new Viewpoint(itemSysKey, schemaName, "last", schemaVersion, event.getID()), this);
} catch (ClusterStorageException e) {
Logger.error(e);
storage.abort(locker);
throw new InvalidDataException("Could not store imported outcome. Rolled back.");
}
- storage.commit(locker);
+ storage.commit(this);
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java index 9531ede..3cf73ba 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java @@ -19,11 +19,12 @@ import com.c2kernel.utils.Logger; * @author $Author: sgaspard $ $Date: 2004/09/21 10:32:17 $
* @version $Revision: 1.14 $
**********************************************************************************************************************************************************************************************************************************************************************************************************/
-public class PredefinedStep extends Activity
+public abstract class PredefinedStep extends Activity
{
/*******************************************************************************************************************************************************************************************************************************************************************************************************
* predefined Steps are always Active, and have only one transition subclasses could override this method (if necessary)
******************************************************************************************************************************************************************************************************************************************************************************************************/
+
private boolean isPredefined = false;
@Override
public boolean getActive()
@@ -33,14 +34,14 @@ public class PredefinedStep extends Activity else
return super.getActive();
}
+
+ public static final int DONE = 0;
+ public static final int AVAILABLE = 0;
@Override
- public String getTransitions()
- {
- if (isPredefined)
- return "<PossibleTransitions>done</PossibleTransitions>";
- else
- return super.getTransitions();
+ protected String getDefaultSMName() {
+ return "PredefinedStep";
}
+
@Override
public String getErrors()
{
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java index f17e5e8..b57dca4 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java @@ -58,9 +58,4 @@ public class PredefinedStepContainer extends CompositeActivity {
return true;
}
- @Override
- public String getTransitions()
- {
- return "<PossibleTransitions></PossibleTransitions>";
- }
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveC2KObject.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveC2KObject.java index c9513a8..583e214 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveC2KObject.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveC2KObject.java @@ -13,11 +13,8 @@ package com.c2kernel.lifecycle.instance.predefined; -import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.EntityPath;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -36,24 +33,19 @@ public class RemoveC2KObject extends PredefinedStep //requestdata is xmlstring
@Override
- public void request(AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
Logger.msg(1, "RemoveC2KObject::request() - Starting.");
- checkAccessRights(agent);
String path = null;
try
{
path = getDataList(requestData)[0];
- EntityPath entityPath = getItemEntityPath();
Logger.msg(5, "RemoveC2KObject::request() - path:"+path);
- Gateway.getStorage().remove( entityPath.getSysKey(), path, null );
- sendEventStoreOutcome(transitionID, requestData, agent);
+ Gateway.getStorage().remove( itemSysKey, path, null );
}
catch( Exception ex )
{
@@ -63,5 +55,6 @@ public class RemoveC2KObject extends PredefinedStep }
Logger.msg(1, "RemoveC2KObject::request() - DONE.");
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java index 19ff7c6..642cf64 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java @@ -10,9 +10,7 @@ package com.c2kernel.lifecycle.instance.predefined; -import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.LDAPLookup;
@@ -28,24 +26,20 @@ public class RemoveDomainPath extends PredefinedStep //requestdata is xmlstring
@Override
- public void request( AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
Logger.msg(8,"RemoveDomainPath::request()");
LDAPLookup lookupManager = Gateway.getLDAPLookup();
Logger.msg(1,"RemoveDomainPath::request() - Starting.");
- checkAccessRights(agent);
-
try
{
DomainPath domainPath = new DomainPath(getDataList(requestData)[0]);
lookupManager.delete(domainPath);
Logger.msg(8,"AddAlias::request() - context:" + domainPath.toString() + " DONE.");
-
+ return requestData;
}
catch( Exception ex )
{
@@ -54,6 +48,5 @@ public class RemoveDomainPath extends PredefinedStep throw new InvalidDataException(ex.toString(), "");
}
- sendEventStoreOutcome(transitionID, requestData, agent);
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java index 897183d..3cc9f7c 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java @@ -15,12 +15,9 @@ package com.c2kernel.lifecycle.instance.predefined; import com.c2kernel.collection.Collection;
import com.c2kernel.collection.CollectionMember;
import com.c2kernel.collection.MembershipException;
-import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.EntityPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
@@ -49,12 +46,9 @@ public class RemoveSlotFromCollection extends PredefinedStep * 2 - target entity key
*/
@Override
- public void request(AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
- EntityPath entityPath = getItemEntityPath();
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
String collName;
int slotNo;
int entityKey = -1;
@@ -62,11 +56,8 @@ public class RemoveSlotFromCollection extends PredefinedStep Logger.msg(1, "RemoveSlotFromCollection::request() - Starting.");
- checkAccessRights(agent);
-
// extract parameters
try {
- entityPath = getItemEntityPath();
String[] params = getDataList(requestData);
collName = params[0];
slotNo = params[1].length()>0?Integer.parseInt(params[1]):-1;
@@ -80,7 +71,7 @@ public class RemoveSlotFromCollection extends PredefinedStep // load collection
try {
- coll = (Collection<? extends CollectionMember>)Gateway.getStorage().get(entityPath.getSysKey(), ClusterStorage.COLLECTION+"/"+collName, null);
+ coll = (Collection<? extends CollectionMember>)Gateway.getStorage().get(itemSysKey, ClusterStorage.COLLECTION+"/"+collName, null);
} catch (ObjectNotFoundException ex) {
throw new InvalidDataException("Collection '"+collName+"' not found in this Item", "");
} catch (ClusterStorageException ex) {
@@ -109,13 +100,13 @@ public class RemoveSlotFromCollection extends PredefinedStep // Store the collection
try {
- Gateway.getStorage().put(entityPath.getSysKey(), coll, null);
+ Gateway.getStorage().put(itemSysKey, coll, null);
} catch (ClusterStorageException e) {
Logger.error(e);
throw new InvalidDataException("Error storing collection", "");
}
- sendEventStoreOutcome(transitionID, requestData, agent);
-
Logger.msg(1, "RemoveSlotFromCollection::request() - DONE.");
+ return requestData;
+
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java index 77ed919..9b7b3f0 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java @@ -1,9 +1,7 @@ package com.c2kernel.lifecycle.instance.predefined;
//Java
-import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.lifecycle.instance.CompositeActivity;
import com.c2kernel.lifecycle.instance.Workflow;
@@ -19,15 +17,12 @@ public class ReplaceDomainWorkflow extends PredefinedStep }
@Override
- public void request( AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException, InvalidTransitionException, InvalidDataException
- {
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
Workflow lifeCycle = getWf();
Logger.msg(1, "ReplaceDomainWorkflow::request() - Starting ");
- checkAccessRights(agent);
-
try
{
Logger.msg(8, "ReplaceDomainWorkflow::request() - data:" + getDataList(requestData)[0]);
@@ -36,13 +31,13 @@ public class ReplaceDomainWorkflow extends PredefinedStep domain.setName("domain");
lifeCycle.initChild(domain, true, new GraphPoint(150, 100));
// if new workflow, activate it, otherwise refresh the jobs
- if (!domain.active) lifeCycle.run(agent);
- else lifeCycle.refreshJobs();
+ if (!domain.active) lifeCycle.run(agent, itemSysKey);
+ else lifeCycle.refreshJobs(itemSysKey);
// store new wf
- Gateway.getStorage().put(getItemEntityPath().getSysKey(), lifeCycle, null);
+ Gateway.getStorage().put(itemSysKey, lifeCycle, null);
Logger.msg(1, "ReplaceDomainWorkflow::request() - DONE.");
- sendEventStoreOutcome(transitionID, requestData, agent);
+ return requestData;
}
catch (Exception ex)
{
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java index 77a0b43..1eef4f5 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java @@ -11,11 +11,8 @@ package com.c2kernel.lifecycle.instance.predefined;
-import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.EntityPath;
import com.c2kernel.process.Gateway;
import com.c2kernel.property.Property;
import com.c2kernel.utils.Logger;
@@ -37,41 +34,30 @@ public class WriteProperty extends PredefinedStep //requestdata is xmlstring
@Override
- public void request( AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
Logger.msg(1, "WriteProperty::request() - Starting.");
- checkAccessRights(agent);
- EntityPath entityPath = getItemEntityPath();
-
- if (entityPath!=null)
+ String[] params = getDataList(requestData);
+ if (params.length != 2)
+ throw new InvalidDataException("WriteProperty::request() - need 2 params - name and value", "");
+ try
{
- String[] params = getDataList(requestData);
- if (params.length != 2)
- throw new InvalidDataException("WriteProperty::request() - need 2 params - name and value", "");
- try
- {
-
- Logger.msg(5, "WriteProperty::request() - name:" + params[0] +" val:"+params[1]);
- Property newProp = new Property(params[0], params[1]);
- Gateway.getStorage().put(entityPath.getSysKey(), newProp, null );
- sendEventStoreOutcome(transitionID, requestData, agent);
- }
- catch( Exception ex )
- {
- Logger.error("WriteProperty::request() - during unmarshall.");
- Logger.error(ex);
- throw new InvalidDataException(ex.toString(), "");
- }
+ Logger.msg(5, "WriteProperty::request() - name:" + params[0] +" val:"+params[1]);
- Logger.msg(1, "WriteProperty::request() - DONE.");
+ Property newProp = new Property(params[0], params[1]);
+ Gateway.getStorage().put(itemSysKey, newProp, null );
}
- else
- throw new InvalidDataException("EntityPath is null.", "");
+ catch( Exception ex )
+ {
+ Logger.error("WriteProperty::request() - during unmarshall.");
+ Logger.error(ex);
+ throw new InvalidDataException(ex.toString(), "");
+ }
+
+ Logger.msg(1, "WriteProperty::request() - DONE.");
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java index 9ec6519..c9ec808 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java @@ -7,9 +7,7 @@ package com.c2kernel.lifecycle.instance.predefined.entitycreation;
-import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.process.Gateway;
@@ -24,23 +22,20 @@ public class CreateNewAgent extends PredefinedStep //requestdata is xmlstring
@Override
- public void request( AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
- checkAccessRights(agent);
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
String redactedRequestData;
try {
NewAgent newAgent = (NewAgent)Gateway.getMarshaller().unmarshall(requestData);
newAgent.create(agent.getSysKey());
newAgent.password = "REDACTED";
redactedRequestData = Gateway.getMarshaller().marshall(newAgent);
+ return requestData;
} catch (Exception ex) {
Logger.error(ex);
throw new InvalidDataException("Error creating agent", "");
}
- sendEventStoreOutcome(transitionID, redactedRequestData, agent);
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java index 5776a5a..2db4fe6 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java @@ -10,9 +10,7 @@ package com.c2kernel.lifecycle.instance.predefined.entitycreation; -import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.process.Gateway;
@@ -27,20 +25,16 @@ public class CreateNewItem extends PredefinedStep //requestdata is xmlstring
@Override
- public void request( AgentPath agent, int transitionID, String requestData)
- throws AccessRightsException,
- InvalidTransitionException,
- InvalidDataException
- {
- checkAccessRights(agent);
-
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
try {
NewItem item = (NewItem)Gateway.getMarshaller().unmarshall(requestData);
item.create(agent.getSysKey(), false);
+ return requestData;
} catch (Exception ex) {
Logger.error(ex);
throw new InvalidDataException("Error creating item", "");
}
- sendEventStoreOutcome(transitionID, requestData, agent);
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java index ed6fd20..dacb1a3 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java @@ -16,8 +16,7 @@ import com.c2kernel.entity.TraceableEntity; import com.c2kernel.events.Event;
import com.c2kernel.events.History;
import com.c2kernel.lifecycle.CompositeActivityDef;
-import com.c2kernel.lifecycle.instance.stateMachine.States;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
+import com.c2kernel.lifecycle.instance.stateMachine.Transition;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.EntityPath;
import com.c2kernel.persistency.ClusterStorage;
@@ -87,7 +86,7 @@ public class NewItem extends ModuleImport { try {
// find workflow def
- CompositeActivityDef compact = (CompositeActivityDef)LocalObjectLoader.getActDef(workflow, "0");
+ CompositeActivityDef compact = (CompositeActivityDef)LocalObjectLoader.getActDef(workflow, 0);
newItem.initialise(
agentId,
Gateway.getMarshaller().marshall(new PropertyArrayList(properties)),
@@ -130,7 +129,8 @@ public class NewItem extends ModuleImport { }
// write new view/outcome/event
- Event newEvent = hist.addEvent("system", "Admin", Transitions.DONE, "Import", "Import", "Import", thisOutcome.schema, thisOutcome.version, thisOutcome.viewname, States.FINISHED);
+ Transition predefDone = new Transition(0, "Done", 0, 0);
+ Event newEvent = hist.addEvent("system", "Admin", "Import", "Import", "Import", thisOutcome.schema, thisOutcome.version, "PredefinedStep", 0, predefDone, thisOutcome.viewname);
newOutcome.setID(newEvent.getID());
impView.setEventId(newEvent.getID());
try {
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java index a8431de..9ab5793 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java @@ -10,10 +10,10 @@ public class Outcome { public Outcome() {
}
- public Outcome(String schema, String version, String viewname, String path) {
+ public Outcome(String schema, int version, String viewname, String path) {
super();
this.schema = schema;
- this.version = Integer.parseInt(version);
+ this.version = version;
this.viewname = viewname;
this.path = path;
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java new file mode 100644 index 0000000..fd712f4 --- /dev/null +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java @@ -0,0 +1,60 @@ +package com.c2kernel.lifecycle.instance.stateMachine;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Set;
+
+public class State implements Serializable {
+
+ int id;
+ String name;
+ boolean finished = false; // If true, this state deactivates the current activity and the lifecycle proceeds
+
+ HashMap<Integer, Transition> possibleTransitions;
+
+ public State() {
+ possibleTransitions = new HashMap<Integer, Transition>();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String toString() {
+ return id+": "+name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public boolean isFinished() {
+ return finished;
+ }
+
+ public void setFinished(boolean finished) {
+ this.finished = finished;
+ }
+
+ public HashMap<Integer, Transition> getPossibleTransitions() {
+ return possibleTransitions;
+ }
+
+ protected void addPossibleTransition(Transition possibleTransition) {
+ possibleTransitions.put(possibleTransition.getId(), possibleTransition);
+ }
+
+ public Set<Integer> getPossibleTransitionIds() {
+ return possibleTransitions.keySet();
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java index ddfc838..c165e6f 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java @@ -1,137 +1,156 @@ package com.c2kernel.lifecycle.instance.stateMachine;
-import java.io.Serializable;
-
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.lifecycle.instance.Activity;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.utils.DescriptionObject;
import com.c2kernel.utils.Logger;
-/**
- * @version $Revision: 1.30 $ $Date: 2004/06/04 09:39:19 $
- * @author $Author: sgaspard $
- */
-/** this class represents the link between 2 successive activities */
-public class StateMachine implements Serializable
+public class StateMachine implements DescriptionObject
{
- public int state = 0;
- private Activity activity;
-
- public static final String SKIPPABLE = "Skippable";
- public static final String REPEATABLE = "Repeatable";
- public static final String IGNORABLE = "Ignorable";
-
-
- /**
- * Method StateMachine.
- * @param act
- */
- public StateMachine(Activity act)
- {
- activity = act;
+ public String name;
+ public int version;
+
+ private ArrayList<State> states;
+ private ArrayList<Transition> transitions;
+ private final HashMap<Integer, State> stateCodes;
+ private final HashMap<Integer, Transition> transitionCodes;
+
+ State initialState;
+ int initialStateCode;
+ boolean isCoherent = false;
+
+ public StateMachine() {
+ states = new ArrayList<State>();
+ transitions = new ArrayList<Transition>();
+ stateCodes = new HashMap<Integer, State>();
+ transitionCodes = new HashMap<Integer, Transition>();
}
-
- /** row : States from (WAITING,RESERVED,STARTED,SUSPENDED,FINISHED,RWAITING,RRESERVED,RSTARTED,RSUSPENDED)
- * collumn : transition (RESERVE,START,SKIP,DONE,COMPLETE,SUSPEND,REASIGN,RESUME,REPEAT,IGNORE,PROCEED)
- * cell : State that is reached (-1 if transition not allowed)
- */
- private int[][] getCurrentMachine()
- {
- int [][] returnArray =
- { /*RESERVE, START, SKIP, DONE,COMPLETE,SUSPEND,REASSIGN,RESUME, REPEAT, IGNORE, PROCEED*/
- /*0 WAITING*/ { 1,getActive()?2:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, -1, -1},/*0 WAITING*/
- /*1 RESERVED*/ { -1,getActive()?2:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, 0, -1},/*1 RESERVED*/
- /*2 STARTED*/ { -1, -1, -1, -1, 4, 3, -1, -1, -1,getIgnorable()?0:-1, -1},/*2 STARTED*/
- /*3 SUSPENDED*/ { -1, -1, -1, -1, -1, -1, 2, 2, -1,getIgnorable()?0:-1, -1},/*3 SUSPENDED*/
- /*4 FINISHED*/ { -1, -1, -1, -1, -1, -1, -1, -1,getRepeatable()?5:-1, -1,getActive()?4:-1},/*4 FINISHED*/
- /*5 RWAITING*/ { 6,getActive()?7:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, -1, -1},/*5 RWAITING*/
- /*6 RRESERVED*/ { -1,getActive()?7:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, -1, -1},/*6 RRESERVED*/
- /*7 RSTARTED*/ { -1, -1, -1, -1, 4, 8, -1, -1, -1,getIgnorable()?5:-1, -1},/*7 RSTARTED*/
- /*8 RSUSPENDED*/ { -1, -1, -1, -1, -1, -1, 8, 7, -1, -1, -1} /*8 RSUSPENDED*/
- };
- return returnArray;
+
+ public void setStates(ArrayList<State> newStates) {
+ this.states = newStates;
+ validate();
}
-
- /**
- * @see java.lang.Object#Object()
- */
- public StateMachine()
- {
+
+ public void setTransitions(ArrayList<Transition> newTransitions) {
+ this.transitions = newTransitions;
+ validate();
+ }
+
+ public void validate() {
+ stateCodes.clear();
+ transitionCodes.clear();
+ isCoherent = true;
+
+ for (State state : states) {
+ Logger.debug(6, "State "+state.id+": "+state.name);
+ stateCodes.put(state.getId(), state);
+ }
+
+ if (stateCodes.containsKey(initialStateCode))
+ initialState = stateCodes.get(initialStateCode);
+ else
+ isCoherent = false;
+
+ for (Transition trans : transitions) {
+ Logger.debug(6, "Transition "+trans.id+": "+trans.name);
+ transitionCodes.put(trans.getId(), trans);
+ isCoherent &= trans.resolveStates(stateCodes);
+ }
+
+ }
+
+ public ArrayList<State> getStates() {
+ return states;
+ }
+
+ public ArrayList<Transition> getTransitions() {
+ return transitions;
+ }
+
+ public State getInitialState() {
+ return initialState;
}
- /**
- * Method getCurrentState.
- * @return String
- */
- public int getCurrentState()
- {
- return state;
+ public void setInitialState(State initialState) {
+ this.initialState = initialState;
+ initialStateCode = initialState.getId();
}
- /**
- * Method possibleTransition.
- * @return String[]
- */
- public int[] possibleTransition()
- {
- int[] trans = new int[9];
- int cmpt = 0;
- for (int i=0; i< getCurrentMachine()[state].length;i++)
- if (getCurrentMachine()[state][i]!=-1) trans[cmpt++]=i;
+ public int getInitialStateCode() {
+ return initialStateCode;
+ }
- int [] result = new int[cmpt];
- for (int i=0;i<cmpt;i++) result[i] = trans[i];
- return result;
+ public void setInitialStateCode(int initialStateCode) {
+ this.initialStateCode = initialStateCode;
+ initialState = stateCodes.get(initialStateCode);
+ if (initialState == null) isCoherent = false;
}
- /**
- * Method traverse.
- * @param transition
- * @return boolean
- */
- public boolean traverse(int transition)
- {
- int newState = getCurrentMachine()[state][transition];
- if (newState > -1) {
- state=newState;
- return true;
- }
- Logger.msg("StateMachine.traverse() - Illegal transition "+Transitions.getTransitionName(transition)+" from "+States.getStateName(state));
- return false;
- }
- public int simulate(int transition)
- {
- return getCurrentMachine()[state][transition];
- }
- /**
- * Returns the ignorable.
- * @return boolean
- */
- public boolean getIgnorable()
- {
- return ((Boolean)activity.getProperties().get(IGNORABLE)).booleanValue();
+ @Override
+ public String getName() {
+ return name;
}
- /**
- * Returns the repeatable.
- * @return boolean
- */
- public boolean getRepeatable()
- {
- return ((Boolean)activity.getProperties().get(REPEATABLE)).booleanValue();
+ @Override
+ public int getVersion() {
+ return version;
+ }
+
+ public void setName(String name) {
+ this.name = name;
}
- /**
- * Returns the skippable.
- * @return boolean
- */
- public boolean getSkippable()
- {
- return ((Boolean)activity.getProperties().get(SKIPPABLE)).booleanValue();
+ public void setVersion(int version) {
+ this.version = version;
}
- public boolean getActive()
- {
- return activity.getActive();
- }
+ public Transition getTransition(int transitionID) {
+ return transitionCodes.get(transitionID);
+ }
+
+ public State getState(int stateID) {
+ return stateCodes.get(stateID);
+ }
+
+ public Map<Transition, String> getPossibleTransitions(Activity act, AgentPath agent) throws ObjectNotFoundException, InvalidDataException {
+ HashMap<Transition, String> returnList = new HashMap<Transition, String>();
+ State currentState = getState(act.getState());
+ for (Integer transCode : currentState.getPossibleTransitionIds()) {
+ Transition possTrans = currentState.getPossibleTransitions().get(transCode);
+ try {
+ String role = possTrans.getPerformingRole(act, agent);
+ returnList.put(possTrans, role);
+ } catch (AccessRightsException ex) {
+ if (Logger.doLog(5))
+ Logger.msg(5, "Transition '"+possTrans+"' not possible for "+agent.getAgentName()+": "+ex.getMessage());
+ }
+ }
+ return returnList;
+ }
-}
+ public State traverse(Activity act, Transition transition, AgentPath agent) throws InvalidTransitionException, AccessRightsException, ObjectNotFoundException, InvalidDataException {
+ State currentState = getState(act.getState());
+ if (transition.originState.equals(currentState)) {
+ transition.getPerformingRole(act, agent);
+ return transition.targetState;
+ }
+ else
+ throw new InvalidTransitionException("Transition '"+transition.getName()+"' not valid from state '"+currentState.getName(), "");
+
+ }
+
+ public boolean isCoherent() {
+ return isCoherent;
+ }
+
+
+}
\ No newline at end of file diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/States.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/States.java deleted file mode 100644 index b142e35..0000000 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/States.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.c2kernel.lifecycle.instance.stateMachine;
-
-
-/**
- * @author XSeb74
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
- */
-public class States
-{
- public final static int WAITING = 0;
- public final static int RESERVED = 1;
- public final static int STARTED = 2;
- public final static int SUSPENDED = 3;
- public final static int FINISHED = 4;
- public final static int RWAITING = 5;
- public final static int RRESERVED = 6;
- public final static int RSTARTED = 7;
- public final static int RSUSPENDED = 8;
-
- //everything less that this constant is NOT a repeating state
- public final static int REPEATSTATESTART = 5;
-
- public static final String[] states = { "Waiting", "Reserved", "Started", "Suspended", "Finished", "Waiting(R)", "Reserved(R)", "Started(R)", "Suspended(R)" };
-
- public static String getStateName(int state)
- {
- try
- {
- return states[state];
- }
- catch (ArrayIndexOutOfBoundsException ex)
- {
- return "Invalid State: " + state;
- }
- }
-}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java new file mode 100644 index 0000000..9922c7c --- /dev/null +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java @@ -0,0 +1,292 @@ +package com.c2kernel.lifecycle.instance.stateMachine;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.lifecycle.instance.Activity;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.RolePath;
+import com.c2kernel.persistency.outcome.Schema;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.utils.CastorHashMap;
+import com.c2kernel.utils.LocalObjectLoader;
+import com.c2kernel.utils.Logger;
+
+public class Transition implements Serializable {
+
+ int id;
+ String name;
+
+ int originStateId;
+ int targetStateId;
+ State originState;
+ State targetState;
+ String reservation;
+
+ String enabledProp; // Boolean property that permits this transition e.g. 'Skippable'
+
+ // activation properties
+ boolean requiresActive = true; // Whether the activity must be active for this transition to be available
+ boolean finishing; // whether the target state is a finishing state;
+
+ // permissions
+ String roleOverride;
+
+ TransitionOutcome outcome;
+ TransitionScript script;
+
+ public Transition() {
+ }
+
+
+ public Transition(int id, String name, int originStateId, int targetStateId) {
+ super();
+ this.id = id;
+ this.name = name;
+ this.originStateId = originStateId;
+ this.targetStateId = targetStateId;
+ }
+
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public State getOriginState() {
+ return originState;
+ }
+
+ public void setOriginState(State originState) {
+ this.originState = originState;
+ }
+
+ public State getTargetState() {
+ return targetState;
+ }
+
+ public void setTargetState(State targetState) {
+ this.targetState = targetState;
+ finishing = targetState.finished;
+ }
+
+ public String getEnabledProp() {
+ return enabledProp;
+ }
+
+ public void setEnabledProp(String enabledProp) {
+ this.enabledProp = enabledProp;
+ }
+
+ public boolean isRequiresActive() {
+ return requiresActive;
+ }
+
+ public boolean isFinishing() {
+ return finishing;
+ }
+
+ public void setRequiresActive(boolean requiresActive) {
+ this.requiresActive = requiresActive;
+ }
+
+ public String getRoleOverride() {
+ return roleOverride;
+ }
+
+ public void setRoleOverride(String roleOverride) {
+ this.roleOverride = roleOverride;
+ }
+
+ public TransitionOutcome getOutcome() {
+ return outcome;
+ }
+
+ public void setOutcome(TransitionOutcome outcome) {
+ this.outcome = outcome;
+ }
+
+ public TransitionScript getScript() {
+ return script;
+ }
+
+ public void setScript(TransitionScript script) {
+ this.script = script;
+ }
+
+ public String getReservation() {
+ return reservation;
+ }
+
+ public void setReservation(String reservation) {
+ this.reservation = reservation;
+ }
+
+ protected boolean resolveStates(HashMap<Integer, State> states) {
+ boolean allFound = true;
+ if (states.keySet().contains(originStateId)) {
+ originState = states.get(originStateId);
+ originState.addPossibleTransition(this);
+ }
+ else
+ allFound = false;
+ if (states.keySet().contains(targetStateId))
+ targetState = states.get(targetStateId);
+ else
+ allFound = false;
+ return allFound;
+ }
+
+ public int getOriginStateId() {
+ return originStateId;
+ }
+
+ public void setOriginStateId(int originStateId) {
+ this.originStateId = originStateId;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getTargetStateId() {
+ return targetStateId;
+ }
+
+ public void setTargetStateId(int targetStateId) {
+ this.targetStateId = targetStateId;
+ }
+
+ public String getPerformingRole(Activity act, AgentPath agent) throws ObjectNotFoundException, AccessRightsException {
+
+ // check available
+ if (!isEnabled(act.getProperties()))
+ throw new AccessRightsException("Transition '"+name+"' is disabled by the '"+enabledProp+"' property.", "");
+
+ // check active
+ if (isRequiresActive() && !act.getActive())
+ throw new AccessRightsException("Activity must be active to perform this transition", "");
+
+ RolePath role = null;
+ String overridingRole = resolveValue(roleOverride, act.getProperties());
+ boolean override = overridingRole != null;
+ boolean isOwner = false, isOwned = true;
+
+ // Check agent name
+ String agentName = act.getCurrentAgentName();
+ if (agentName != null && agentName.length() >0) {
+ if (agent.getAgentName().equals(agentName))
+ isOwner = true;
+ }
+ else isOwned = false;
+
+ // determine transition role
+ if (override) {
+ role = Gateway.getLDAPLookup().getRoleManager().getRolePath(overridingRole);
+ }
+ else {
+ String actRole = act.getCurrentAgentRole();
+ if (actRole != null && actRole.length() > 0)
+ role = Gateway.getLDAPLookup().getRoleManager().getRolePath(actRole);
+ }
+
+ // Decide the access
+ if (isOwned && !override && !isOwner)
+ throw new AccessRightsException("Agent '"+agent.getAgentName()
+ +"' cannot perform this transition because the activity '"+act.getName()+"' is currently owned by "+agentName, null);
+
+ if (role != null) {
+ if (agent.hasRole(role))
+ return role.getName();
+ else if (agent.hasRole("Admin"))
+ return "Admin";
+ else
+ throw new AccessRightsException("Agent '"+agent.getAgentName()
+ +"' does not hold a suitable role '"+role.getName()+"' for the activity "+act.getName(), null);
+ }
+ else
+ return null;
+ }
+
+ public String getReservation(Activity act, AgentPath agent) {
+ if (reservation == null || reservation.length() == 0)
+ reservation = targetState.finished?"clear":"set";
+
+ String reservedAgent = act.getCurrentAgentName();
+ if (reservation.equals("set"))
+ reservedAgent = agent.getAgentName();
+ else if (reservation.equals("clear"))
+ reservedAgent = "";
+ return reservedAgent;
+
+ }
+
+ private static String resolveValue(String key, CastorHashMap props) {
+ if (key==null) return null;
+ String result = key;
+ Pattern propField = Pattern.compile("\\$\\{(.+?)\\}");
+ Matcher propMatcher = propField.matcher(result);
+ while (propMatcher.find()) {
+ String propName = propMatcher.group(1);
+ Object propValue = props.get(propName);
+ Logger.debug("Replacing Property "+propName+" as "+propValue);
+ String propValString = propValue==null?"":propValue.toString();
+ result = result.replace("${"+propName+"}", propValString);
+ }
+ return result;
+ }
+
+ public boolean isEnabled(CastorHashMap props) {
+ if (enabledProp == null)
+ return true;
+ return (Boolean)props.get(enabledProp);
+ }
+
+ public boolean hasOutcome() {
+ return outcome!=null
+ && outcome.schemaName!=null && outcome.schemaName.length()>0
+ && outcome.schemaVersion!=null && outcome.schemaVersion.length()>0;
+ }
+
+ public Schema getSchema(CastorHashMap actProps) throws InvalidDataException, ObjectNotFoundException {
+ if (hasOutcome())
+ try {
+ return LocalObjectLoader.getSchema(resolveValue(outcome.schemaName, actProps),
+ Integer.parseInt(resolveValue(outcome.schemaVersion, actProps)));
+ } catch (NumberFormatException ex) {
+ throw new InvalidDataException("Bad schema version number: "+outcome.schemaVersion+" ("+resolveValue(outcome.schemaVersion, actProps), "");
+ }
+ else
+ return null;
+ }
+
+ public String getScriptName(CastorHashMap actProps) {
+ return resolveValue(script.scriptName, actProps);
+ }
+
+ public int getScriptVersion(CastorHashMap actProps) throws InvalidDataException {
+ try {
+ return Integer.parseInt(resolveValue(script.scriptVersion, actProps));
+ } catch (NumberFormatException ex) {
+ throw new InvalidDataException("Bad Script version number: "+script.scriptVersion+" ("+resolveValue(script.scriptVersion, actProps));
+ }
+ }
+
+ public boolean hasScript() {
+ return script!=null
+ && script.scriptName!=null && script.scriptName.length()>0
+ && script.scriptVersion!=null && script.scriptVersion.length()>0;
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionOutcome.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionOutcome.java new file mode 100644 index 0000000..71ba3b3 --- /dev/null +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionOutcome.java @@ -0,0 +1,36 @@ +package com.c2kernel.lifecycle.instance.stateMachine;
+
+public class TransitionOutcome extends TransitionResource {
+
+ // schema properties
+ String schemaName, schemaVersion; // Name & version of the schema of the data required for this transition.
+ boolean required = true; // If true, then the data must be supplied to perform the transition, otherwise it is optional
+
+ public TransitionOutcome() {
+ }
+
+ public String getSchemaName() {
+ return schemaName;
+ }
+
+ public void setSchemaName(String schemaName) {
+ this.schemaName = schemaName;
+ }
+
+ public String getSchemaVersion() {
+ return schemaVersion;
+ }
+
+ public void setSchemaVersion(String schemaVersion) {
+ this.schemaVersion = schemaVersion;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ public void setRequired(boolean required) {
+ this.required = required;
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionResource.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionResource.java new file mode 100644 index 0000000..f644a4c --- /dev/null +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionResource.java @@ -0,0 +1,9 @@ +package com.c2kernel.lifecycle.instance.stateMachine;
+
+public class TransitionResource {
+
+ public TransitionResource() {
+ // TODO Auto-generated constructor stub
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionScript.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionScript.java new file mode 100644 index 0000000..9585102 --- /dev/null +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionScript.java @@ -0,0 +1,27 @@ +package com.c2kernel.lifecycle.instance.stateMachine;
+
+public class TransitionScript extends TransitionResource {
+
+ // script properties
+ String scriptName, scriptVersion; // Name & version of the script to be run by the agent during this transition
+
+ public TransitionScript() {
+ }
+
+ public String getScriptName() {
+ return scriptName;
+ }
+
+ public void setScriptName(String scriptName) {
+ this.scriptName = scriptName;
+ }
+
+ public String getScriptVersion() {
+ return scriptVersion;
+ }
+
+ public void setScriptVersion(String scriptVersion) {
+ this.scriptVersion = scriptVersion;
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transitions.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transitions.java deleted file mode 100644 index 4239baa..0000000 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transitions.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.c2kernel.lifecycle.instance.stateMachine;
-
-import com.c2kernel.utils.Language;
-
-/**
- * @author XSeb74
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
- */
-public class Transitions
-{
- public final static int RESERVE = 0;
- public final static int START = 1;
- public final static int SKIP = 2;
- public final static int DONE = 3;
- public final static int COMPLETE = 4;
- public final static int SUSPEND = 5;
- public final static int REASSIGN = 6;
- public final static int RESUME = 7;
- public final static int REPEAT = 8;
- public final static int IGNORE = 9;
- public final static int PROCEED = 10;
- public final static int ACTIVATION = 11;
-
- private static String[] transitions = { "reserve", "start", "skip", "done", "complete", "suspend", "reassign", "resume", "repeat","ignore","proceed","activation" };
-
- public static String getTransitionName(int trans)
- {
- try
- {
- return Language.translate(transitions[trans]);
- }
- catch (ArrayIndexOutOfBoundsException ex)
- {
- return "Invalid Transition: " + trans;
- }
- }
-}
diff --git a/src/main/java/com/c2kernel/persistency/outcome/Outcome.java b/src/main/java/com/c2kernel/persistency/outcome/Outcome.java index 3e6cb63..b2f706b 100644 --- a/src/main/java/com/c2kernel/persistency/outcome/Outcome.java +++ b/src/main/java/com/c2kernel/persistency/outcome/Outcome.java @@ -22,7 +22,7 @@ import com.c2kernel.utils.LocalObjectLoader; import com.c2kernel.utils.Logger;
public class Outcome implements C2KLocalObject {
- int mID = -1;
+ Integer mID;
String mData;
String mSchemaType;
int mSchemaVersion;
@@ -75,25 +75,25 @@ public class Outcome implements C2KLocalObject { throw new PersistencyException("Outcome() - Outcome version was an invalid number: "+verstring, null);
}
try {
- mID = Integer.parseInt(objId);
+ mID = new Integer(objId);
} catch (NumberFormatException ex) {
- mID = -1;
+ mID = null;
}
mData = data;
}
- public void setID(int ID) {
+ public void setID(Integer ID) {
mID = ID;
}
- public int getID() {
+ public Integer getID() {
return mID;
}
@Override
public void setName(String name) {
try {
- mID = Integer.parseInt(name);
+ mID = new Integer(name);
} catch (NumberFormatException e) {
Logger.error("Invalid id set on Outcome:"+name);
}
@@ -101,7 +101,7 @@ public class Outcome implements C2KLocalObject { @Override
public String getName() {
- return String.valueOf(mID);
+ return mID.toString();
}
public void setData(String data) {
diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index 08cf2e7..b37cc8a 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -17,8 +17,7 @@ import com.c2kernel.lifecycle.instance.CompositeActivity; import com.c2kernel.lifecycle.instance.Workflow;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer;
import com.c2kernel.lifecycle.instance.predefined.ServerPredefinedStepContainer;
-import com.c2kernel.lifecycle.instance.stateMachine.States;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
+import com.c2kernel.lifecycle.instance.stateMachine.Transition;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.EntityPath;
@@ -152,7 +151,8 @@ public class Bootstrap // data was missing or doesn't match
Logger.msg("Bootstrap.verifyResource() - Writing new version "+version+" to "+getDataType(itemType)+" "+itemName);
History hist = new History(thisProxy.getSystemKey(), thisProxy);
- Event newEvent = hist.addEvent("system", "Admin", Transitions.DONE, "Bootstrap", "Bootstrap", "Bootstrap", getDataType(itemType), 0, String.valueOf(version), States.FINISHED);
+ Transition predefDone = new Transition(0, "Done", 0, 0);
+ Event newEvent = hist.addEvent("system", "Admin", "Bootstrap", "Bootstrap", "Bootstrap", getDataType(itemType), 0, "PredefinedStep", 0, predefDone, String.valueOf(version));
newOutcome.setID(newEvent.getID());
Viewpoint newLastView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), "last", 0, newEvent.getID());
Viewpoint newZeroView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), String.valueOf(version), 0, newEvent.getID());
@@ -186,7 +186,7 @@ public class Bootstrap else if (itemType.equals("OD")) wf = "ManageSchema";
else if (itemType.equals("SC")) wf = "ManageScript";
else throw new Exception("Unknown bootstrap item type: "+itemType);
- ca = (CompositeActivity) ((CompositeActivityDef)LocalObjectLoader.getActDef(wf, "last")).instantiate();
+ ca = (CompositeActivity) ((CompositeActivityDef)LocalObjectLoader.getActDef(wf, 0)).instantiate();
}
EntityPath entityPath = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
@@ -209,6 +209,8 @@ public class Bootstrap return new DomainPath("/desc/Script/");
if (type.equals("OD"))
return new DomainPath("/desc/OutcomeDesc/");
+ if (type.equals("SM"))
+ return new DomainPath("/desc/StateMachine");
throw new Exception("Unknown bootstrap item type: "+type);
}
@@ -221,6 +223,8 @@ public class Bootstrap return "Schema";
if (type.equals("SC"))
return "Script";
+ if (type.equals("SM"))
+ return "StateMachine";
throw new Exception("Unknown bootstrap item type: "+type);
}
@@ -307,7 +311,7 @@ public class Bootstrap }
public static void initServerItemWf() throws Exception {
- CompositeActivityDef serverWfCa = (CompositeActivityDef)LocalObjectLoader.getActDef("ServerItemWorkflow", "last");
+ CompositeActivityDef serverWfCa = (CompositeActivityDef)LocalObjectLoader.getActDef("ServerItemWorkflow", 0);
Workflow wf = new Workflow((CompositeActivity)serverWfCa.instantiate());
PredefinedStepContainer predef = (PredefinedStepContainer)wf.search("workflow/predefined");
wf.getChildGraphModel().removeVertex(predef);
diff --git a/src/main/java/com/c2kernel/process/UserCodeProcess.java b/src/main/java/com/c2kernel/process/UserCodeProcess.java index 0abd906..f7bbe74 100644 --- a/src/main/java/com/c2kernel/process/UserCodeProcess.java +++ b/src/main/java/com/c2kernel/process/UserCodeProcess.java @@ -11,7 +11,6 @@ import com.c2kernel.entity.agent.Job; import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.entity.proxy.EntityProxyObserver;
import com.c2kernel.entity.proxy.MemberSubscription;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.scripting.ErrorInfo;
import com.c2kernel.scripting.ScriptErrorException;
@@ -26,7 +25,14 @@ import com.c2kernel.utils.Logger; * All rights reserved.
**************************************************************************/
public class UserCodeProcess extends StandardClient implements EntityProxyObserver<Job>, Runnable {
- protected AgentProxy agent;
+
+ // Default state machine transitions
+ private static final int START = 1;
+ private static final int COMPLETE = 2;
+ private static final int SUSPEND = 3;
+ private static final int RESUME = 4;
+
+ protected AgentProxy agent;
static boolean active = true;
ArrayList<String> ignoredPaths = new ArrayList<String>();
HashMap<String, ErrorInfo> errors = new HashMap<String, ErrorInfo>();
@@ -60,13 +66,13 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv Job thisJob = null;
synchronized (jobs) {
if (jobs.size() > 0) {
- thisJob = getJob(jobs, Transitions.COMPLETE);
+ thisJob = getJob(jobs, COMPLETE);
if (thisJob == null)
- thisJob = getJob(jobs, Transitions.START);
+ thisJob = getJob(jobs, START);
if (thisJob == null)
- thisJob = getJob(jobs, Transitions.SUSPEND);
+ thisJob = getJob(jobs, SUSPEND);
if (thisJob == null)
- thisJob = getJob(jobs, Transitions.RESUME);
+ thisJob = getJob(jobs, RESUME);
if (thisJob == null) {
Logger.error("No supported jobs, but joblist is not empty! Discarding remaining jobs");
@@ -79,8 +85,9 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv if (thisJob != null) {
String jobKey = thisJob.getItemSysKey()+":"+thisJob.getStepPath();
+ int transitionId = thisJob.getTransition().getId();
try {
- if (thisJob.getPossibleTransition()==Transitions.START) {
+ if (transitionId==START) {
Logger.msg(5, "Testing start conditions");
boolean start = assessStartConditions(thisJob);
if (start) {
@@ -91,13 +98,13 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv Logger.msg(5, "Start conditions failed "+thisJob.getStepName()+" in "+thisJob.getItemSysKey());
}
}
- else if (thisJob.getPossibleTransition()==Transitions.COMPLETE) {
+ else if (transitionId==COMPLETE) {
Logger.msg(5, "Executing logic");
runUCLogic(thisJob);
if (ignoredPaths.contains(jobKey))
ignoredPaths.remove(jobKey);
}
- else if (thisJob.getPossibleTransition()==Transitions.SUSPEND) {
+ else if (transitionId==SUSPEND) {
if (ignoredPaths.contains(jobKey)) {
if (errors.containsKey(jobKey)) {
thisJob.setOutcome(Gateway.getMarshaller().marshall(errors.get(jobKey)));
@@ -106,7 +113,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv agent.execute(thisJob);
}
}
- else if (thisJob.getPossibleTransition()==Transitions.RESUME) {
+ else if (transitionId==RESUME) {
if (!ignoredPaths.contains(jobKey))
agent.execute(thisJob);
}
@@ -116,7 +123,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv } catch (InvalidTransitionException ex) {
// must have already been done by someone else - ignore
} catch (Throwable ex) {
- Logger.error("Error executing "+Transitions.getTransitionName(thisJob.getPossibleTransition())+" job:");
+ Logger.error("Error executing "+thisJob.getTransition().getName()+" job:");
Logger.error(ex);
ErrorInfo ei = new ErrorInfo();
ei.setFatal();
@@ -148,12 +155,12 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv }
}
- private static Job getJob(HashMap<String, C2KLocalObject> jobs, int transition) {
+ private static Job getJob(HashMap<String, C2KLocalObject> jobs, int transition) {
for (C2KLocalObject c2kLocalObject : jobs.values()) {
Job thisJob = (Job)c2kLocalObject;
- if (thisJob.getPossibleTransition() == transition) {
+ if (thisJob.getTransition().getId() == transition) {
Logger.msg(1,"=================================================================");
- Logger.msg(1, "Got "+Transitions.getTransitionName(transition)+" job for "+thisJob.getStepName()+" in "+thisJob.getItemSysKey());
+ Logger.msg(1, "Got "+thisJob.getTransition().getName()+" job for "+thisJob.getStepName()+" in "+thisJob.getItemSysKey());
return thisJob;
}
}
diff --git a/src/main/java/com/c2kernel/process/module/Module.java b/src/main/java/com/c2kernel/process/module/Module.java index a932361..d0a017c 100644 --- a/src/main/java/com/c2kernel/process/module/Module.java +++ b/src/main/java/com/c2kernel/process/module/Module.java @@ -67,7 +67,7 @@ public class Module { }
moduleItem.dependencyList.add(children);
// Add moduleXML
- Outcome moduleOutcome = new Outcome("Module", "0", "last", null);
+ Outcome moduleOutcome = new Outcome("Module", 0, "last", null);
moduleOutcome.data = moduleXML;
moduleItem.outcomes.add(moduleOutcome);
imports.list.add(moduleItem);
diff --git a/src/main/java/com/c2kernel/scripting/Script.java b/src/main/java/com/c2kernel/scripting/Script.java index 1a755ea..9166e2e 100644 --- a/src/main/java/com/c2kernel/scripting/Script.java +++ b/src/main/java/com/c2kernel/scripting/Script.java @@ -43,7 +43,7 @@ public class Script {
String mScript = "";
String mName;
- String mVersion;
+ Integer mVersion;
HashMap<String, Parameter> mInputParams = new HashMap<String, Parameter>();
HashMap<String, Parameter> mAllInputParams = new HashMap<String, Parameter>();
HashMap<String, Parameter> mOutputParams = new HashMap<String, Parameter>();
@@ -79,7 +79,7 @@ public class Script public Script(String scriptName, int scriptVersion) throws ScriptingEngineException
{
mName = scriptName;
- mVersion = String.valueOf(scriptVersion);
+ mVersion = scriptVersion;
if (!scriptName.equals(""))
loadScript(mName, mVersion);
}
@@ -92,7 +92,7 @@ public class Script {
mName = "<expr>";
setScriptEngine(lang);
- mVersion = "";
+ mVersion = null;
addOutput(null, returnType);
mScript = expr;
}
@@ -121,7 +121,7 @@ public class Script public Script(ItemProxy object, AgentProxy subject, Job job) throws ScriptingEngineException
{
- this(job.getActPropString("ScriptName"), job.getActPropString("ScriptVersion") == null ? -1 : Integer.parseInt(job.getActPropString("ScriptVersion")));
+ this(job.getActPropString("ScriptName"), job.getActPropString("ScriptVersion") == null ? null : Integer.parseInt(job.getActPropString("ScriptVersion").toString()));
// set environment - this needs to be well documented for script developers
if (!mInputParams.containsKey("item"))
addInputParam("item", ItemProxy.class);
@@ -183,7 +183,7 @@ public class Script engine.setContext(context);
}
- private void loadScript(String scriptName, String scriptVersion) throws ScriptingEngineException
+ private void loadScript(String scriptName, int scriptVersion) throws ScriptingEngineException
{
try
{
diff --git a/src/main/java/com/c2kernel/utils/ActDefCache.java b/src/main/java/com/c2kernel/utils/ActDefCache.java index 2ee5c7c..ab2bd90 100644 --- a/src/main/java/com/c2kernel/utils/ActDefCache.java +++ b/src/main/java/com/c2kernel/utils/ActDefCache.java @@ -5,95 +5,42 @@ package com.c2kernel.utils; import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.proxy.EntityProxyObserver;
import com.c2kernel.entity.proxy.ItemProxy;
-import com.c2kernel.entity.proxy.MemberSubscription;
import com.c2kernel.lifecycle.ActivityDef;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
-public class ActDefCache {
+public class ActDefCache extends DescriptionObjectCache<ActivityDef> {
- SoftCache<String, ActCacheEntry> actCache = new SoftCache<String, ActCacheEntry>();
-
- public ActivityDef get(String actName, String actVersion) throws ObjectNotFoundException, InvalidDataException {
+
+ @Override
+ public String getDefRoot() {
+ return "/desc/ActivityDesc";
+ }
+
+ @Override
+ public ActivityDef loadObject(String name, int version, ItemProxy proxy) throws ObjectNotFoundException, InvalidDataException {
ActivityDef thisActDef;
- synchronized(actCache) {
- ActCacheEntry thisActDefEntry = actCache.get(actName+"_"+actVersion);
- if (thisActDefEntry == null) {
- Logger.msg(6, actName+" v"+actVersion+" not found in cache. Retrieving.");
- ItemProxy actDefItem = LocalObjectLoader.loadLocalObjectDef("/desc/ActivityDesc/", actName);
- String actType = actDefItem.getProperty("Complexity");
- Viewpoint actView = (Viewpoint)actDefItem.getObject(ClusterStorage.VIEWPOINT + "/" + actType + "ActivityDef/" + actVersion);
- String marshalledAct;
- try {
- marshalledAct = actView.getOutcome().getData();
- } catch (ClusterStorageException ex) {
- Logger.error(ex);
- throw new ObjectNotFoundException("Problem loading "+actName+" v"+actVersion+": "+ex.getMessage(), "");
- }
- try {
- thisActDef = (ActivityDef)Gateway.getMarshaller().unmarshall(marshalledAct);
- } catch (Exception ex) {
- Logger.error(ex);
- throw new InvalidDataException("Could not unmarshall '"+actName+"' v"+actVersion+": "+ex.getMessage(), "");
- }
- thisActDef.setName(actName);
- thisActDef.setVersion(actVersion);
- actCache.put(actName+"_"+actVersion, new ActCacheEntry(thisActDef, actDefItem, this));
- }
- else {
- Logger.msg(6, actName+" v"+actVersion+" found in cache.");
- thisActDef = thisActDefEntry.actDef;
- }
- }
+ String actType = proxy.getProperty("Complexity");
+ Viewpoint actView = (Viewpoint)proxy.getObject(ClusterStorage.VIEWPOINT + "/" + actType + "ActivityDef/" + version);
+ String marshalledAct;
+ try {
+ marshalledAct = actView.getOutcome().getData();
+ } catch (ClusterStorageException ex) {
+ Logger.error(ex);
+ throw new ObjectNotFoundException("Problem loading "+name+" v"+version+": "+ex.getMessage(), "");
+ }
+ try {
+ thisActDef = (ActivityDef)Gateway.getMarshaller().unmarshall(marshalledAct);
+ } catch (Exception ex) {
+ Logger.error(ex);
+ throw new InvalidDataException("Could not unmarshall '"+name+"' v"+version+": "+ex.getMessage(), "");
+ }
+ thisActDef.setName(name);
+ thisActDef.setVersion(version);
return thisActDef;
}
- public void removeAct(String id) {
- synchronized(actCache) {
- if (actCache.keySet().contains(id)) {
- Logger.msg(7, "ActDefCache: Removing activity def "+id+" from cache");
- actCache.remove(id);
- }
- }
- }
-
- public class ActCacheEntry implements EntityProxyObserver<Viewpoint> {
- public String id;
- public ItemProxy actProxy;
- public ActivityDef actDef;
- public ActDefCache parent;
- public ActCacheEntry(ActivityDef actDef, ItemProxy actProxy, ActDefCache parent) {
- this.id = actDef.getName()+"_"+actDef.getVersion();
- this.actDef = actDef;
- this.parent = parent;
- this.actProxy = actProxy;
- actProxy.subscribe(new MemberSubscription<Viewpoint>(this, ClusterStorage.VIEWPOINT, false));
- }
- @Override
- public void finalize() {
- parent.removeAct(id);
- actProxy.unsubscribe(this);
- }
- @Override
- public void add(Viewpoint contents) {
- parent.removeAct(id);
- }
-
- @Override
- public void remove(String oldId) {
- parent.removeAct(oldId);
- }
-
- @Override
- public String toString() {
- return "ActDef cache entry: "+id;
- }
- @Override
- public void control(String control, String msg) {
- }
- }
}
\ No newline at end of file diff --git a/src/main/java/com/c2kernel/utils/DescriptionObject.java b/src/main/java/com/c2kernel/utils/DescriptionObject.java new file mode 100644 index 0000000..4d7d108 --- /dev/null +++ b/src/main/java/com/c2kernel/utils/DescriptionObject.java @@ -0,0 +1,8 @@ +package com.c2kernel.utils;
+
+public interface DescriptionObject {
+
+ public String getName();
+ public int getVersion();
+
+}
diff --git a/src/main/java/com/c2kernel/utils/DescriptionObjectCache.java b/src/main/java/com/c2kernel/utils/DescriptionObjectCache.java new file mode 100644 index 0000000..d5382da --- /dev/null +++ b/src/main/java/com/c2kernel/utils/DescriptionObjectCache.java @@ -0,0 +1,84 @@ +/**
+ *
+ */
+package com.c2kernel.utils;
+
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.proxy.EntityProxyObserver;
+import com.c2kernel.entity.proxy.ItemProxy;
+import com.c2kernel.entity.proxy.MemberSubscription;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.persistency.outcome.Viewpoint;
+
+public abstract class DescriptionObjectCache<D extends DescriptionObject> {
+
+ SoftCache<String, CacheEntry<D>> cache = new SoftCache<String, CacheEntry<D>>();
+
+ public D get(String name, int version) throws ObjectNotFoundException, InvalidDataException {
+ D thisDef;
+ synchronized(cache) {
+ CacheEntry<D> thisDefEntry = cache.get(name+"_"+version);
+ if (thisDefEntry == null) {
+ Logger.msg(6, name+" v"+version+" not found in cache. Retrieving.");
+ ItemProxy defItem = LocalObjectLoader.loadLocalObjectDef(getDefRoot(), name);
+ thisDef = loadObject(name, version, defItem);
+ cache.put(name+"_"+version, new CacheEntry<D>(thisDef, defItem, this));
+ }
+ else {
+ Logger.msg(6, name+" v"+version+" found in cache.");
+ thisDef = thisDefEntry.def;
+ }
+ }
+ return thisDef;
+ }
+
+ public abstract String getDefRoot();
+
+ public abstract D loadObject(String name, int version, ItemProxy proxy) throws ObjectNotFoundException, InvalidDataException;
+
+ public void removeAct(String id) {
+ synchronized(cache) {
+ if (cache.keySet().contains(id)) {
+ Logger.msg(7, "ActDefCache: Removing activity def "+id+" from cache");
+ cache.remove(id);
+ }
+ }
+ }
+
+ public class CacheEntry<E extends DescriptionObject> implements EntityProxyObserver<Viewpoint> {
+ public String id;
+ public ItemProxy proxy;
+ public E def;
+ public DescriptionObjectCache<E> parent;
+ public CacheEntry(E def, ItemProxy proxy, DescriptionObjectCache<E> parent) {
+ this.id = def.getName()+"_"+def.getVersion();
+ this.def = def;
+ this.parent = parent;
+ this.proxy = proxy;
+ proxy.subscribe(new MemberSubscription<Viewpoint>(this, ClusterStorage.VIEWPOINT, false));
+ }
+ @Override
+ public void finalize() {
+ parent.removeAct(id);
+ proxy.unsubscribe(this);
+ }
+ @Override
+ public void add(Viewpoint contents) {
+ parent.removeAct(id);
+ }
+
+ @Override
+ public void remove(String oldId) {
+ parent.removeAct(oldId);
+ }
+
+ @Override
+ public String toString() {
+ return "Cache entry: "+id;
+ }
+ @Override
+ public void control(String control, String msg) {
+ }
+ }
+}
\ No newline at end of file diff --git a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java index 63bb3c2..aef7b96 100644 --- a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java +++ b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java @@ -4,6 +4,7 @@ import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lifecycle.ActivityDef;
+import com.c2kernel.lifecycle.instance.stateMachine.StateMachine;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
@@ -13,6 +14,7 @@ import com.c2kernel.process.Gateway; public class LocalObjectLoader {
private static ActDefCache actCache = new ActDefCache();
+ private static StateMachineCache smCache = new StateMachineCache();
static public ItemProxy loadLocalObjectDef(String root, String name)
throws ObjectNotFoundException
@@ -22,7 +24,7 @@ public class LocalObjectLoader { return (ItemProxy)Gateway.getProxyManager().getProxy(defPath);
}
- static public String getScript(String scriptName, String scriptVersion) throws ObjectNotFoundException {
+ static public String getScript(String scriptName, int scriptVersion) throws ObjectNotFoundException {
Logger.msg(5, "Loading script "+scriptName+" v"+scriptVersion);
try {
ItemProxy script = loadLocalObjectDef("/desc/Script/", scriptName);
@@ -65,8 +67,13 @@ public class LocalObjectLoader { * @return ActivityDef
* @throws ObjectNotFoundException - When activity or version does not exist
*/
- static public ActivityDef getActDef(String actName, String actVersion) throws ObjectNotFoundException, InvalidDataException {
+ static public ActivityDef getActDef(String actName, int actVersion) throws ObjectNotFoundException, InvalidDataException {
Logger.msg(5, "Loading activity def "+actName+" v"+actVersion);
return actCache.get(actName, actVersion);
}
+
+ static public StateMachine getStateMachine(String smName, int smVersion) throws ObjectNotFoundException, InvalidDataException {
+ Logger.msg(5, "Loading activity def "+smName+" v"+smVersion);
+ return smCache.get(smName, smVersion);
+ }
}
diff --git a/src/main/java/com/c2kernel/utils/StateMachineCache.java b/src/main/java/com/c2kernel/utils/StateMachineCache.java new file mode 100644 index 0000000..d48d718 --- /dev/null +++ b/src/main/java/com/c2kernel/utils/StateMachineCache.java @@ -0,0 +1,46 @@ +/**
+ *
+ */
+package com.c2kernel.utils;
+
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.proxy.ItemProxy;
+import com.c2kernel.lifecycle.instance.stateMachine.StateMachine;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.persistency.ClusterStorageException;
+import com.c2kernel.persistency.outcome.Viewpoint;
+import com.c2kernel.process.Gateway;
+
+public class StateMachineCache extends DescriptionObjectCache<StateMachine> {
+
+
+ @Override
+ public String getDefRoot() {
+ return "/desc/StateMachine";
+ }
+
+ @Override
+ public StateMachine loadObject(String name, int version, ItemProxy proxy) throws ObjectNotFoundException, InvalidDataException {
+ StateMachine thisStateMachine;
+ Viewpoint smView = (Viewpoint)proxy.getObject(ClusterStorage.VIEWPOINT + "/StateMachine/" + version);
+ String marshalledSM;
+ try {
+ marshalledSM = smView.getOutcome().getData();
+ } catch (ClusterStorageException ex) {
+ Logger.error(ex);
+ throw new ObjectNotFoundException("Problem loading State Machine "+name+" v"+version+": "+ex.getMessage(), "");
+ }
+ try {
+ thisStateMachine = (StateMachine)Gateway.getMarshaller().unmarshall(marshalledSM);
+ thisStateMachine.validate();
+ } catch (Exception ex) {
+ Logger.error(ex);
+ throw new InvalidDataException("Could not unmarshall State Machine '"+name+"' v"+version+": "+ex.getMessage(), "");
+ }
+ thisStateMachine.setName(name);
+ thisStateMachine.setVersion(version);
+ return thisStateMachine;
+ }
+
+}
\ No newline at end of file |
