From e99ed30f6cae36c5f3fa03007d991e67894a01bb Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 23 Jul 2013 09:41:43 +0200 Subject: More --- .../com/c2kernel/lifecycle/instance/Activity.java | 145 +++++++-------------- .../com/c2kernel/lifecycle/instance/AndSplit.java | 6 +- .../lifecycle/instance/CompositeActivity.java | 74 +++-------- .../com/c2kernel/lifecycle/instance/JobPusher.java | 26 +--- .../java/com/c2kernel/lifecycle/instance/Join.java | 19 +-- .../java/com/c2kernel/lifecycle/instance/Loop.java | 8 +- .../com/c2kernel/lifecycle/instance/OrSplit.java | 20 ++- .../com/c2kernel/lifecycle/instance/Split.java | 14 +- .../com/c2kernel/lifecycle/instance/WfVertex.java | 23 ++-- .../com/c2kernel/lifecycle/instance/Workflow.java | 24 ++-- .../com/c2kernel/lifecycle/instance/XOrSplit.java | 24 ++-- .../instance/predefined/ReplaceDomainWorkflow.java | 4 +- .../lifecycle/instance/stateMachine/State.java | 10 +- .../instance/stateMachine/Transition.java | 12 +- .../instance/stateMachine/TransitionScript.java | 6 +- 15 files changed, 180 insertions(+), 235 deletions(-) (limited to 'src/main/java/com/c2kernel/lifecycle') diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java index 1fc0c14..71909a5 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; @@ -26,7 +27,6 @@ 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; @@ -42,7 +42,7 @@ public class Activity extends WfVertex protected Vector mErrors; /** @associates a State machine engine */ private StateMachine machine; - private int state = -1; + protected int state = -1; /** true is available to be executed */ public boolean active = false; /** used in verify() */ @@ -76,11 +76,16 @@ public class Activity extends WfVertex return new Next(this, vertex); } - private StateMachine getStateMachine() throws ObjectNotFoundException, InvalidDataException { + protected StateMachine getStateMachine() throws InvalidDataException { if (machine == null) { String name = (String)getProperties().get("StateMachineName"); String version = (String)getProperties().get("StateMachineVersion"); - machine = LocalObjectLoader.getStateMachine(name, version); + try { + machine = LocalObjectLoader.getStateMachine(name, version); + } catch (ObjectNotFoundException ex) { + Logger.error(ex); + throw new InvalidDataException("Error loading state machine '"+name+"' v"+version); + } } return machine; } @@ -100,7 +105,7 @@ public class Activity extends WfVertex /** cf Item request * @throws ObjectNotFoundException * @throws PersistencyException */ - public final void request(AgentPath agent, int itemSysKey, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, ObjectNotFoundException, PersistencyException + public void request(AgentPath agent, int itemSysKey, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, ObjectNotFoundException, PersistencyException { // Find requested transition @@ -162,21 +167,14 @@ public class Activity extends WfVertex throw new PersistencyException("Exception storing event data"); } - if (newState.isProceeds()) { - setActive(false); + if (newState.isFinished()) if (!getProperties().get("Breakpoint").equals(Boolean.TRUE)) - try { - runNext(agent); - } catch (ScriptingEngineException ex) { - Logger.error("Error calculating next actvity in lifecycle of "+itemSysKey); - Logger.error(ex); - } - } - else - DateUtility.setToNow(mStartDate); + runNext(agent, itemSysKey); + else + DateUtility.setToNow(mStartDate); //refresh all the job lists - pushJobsToAgents(); + pushJobsToAgents(itemSysKey); } protected String runActivityLogic(AgentPath agent, int itemSysKey, @@ -249,7 +247,7 @@ public class Activity extends WfVertex } /** sets the next activity available if possible */ @Override - public void runNext(AgentPath agent) throws ScriptingEngineException + public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException { setActive(false); try @@ -273,7 +271,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 @@ -283,11 +281,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; @@ -301,12 +299,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) { Vertex[] outVertices = getOutGraphables(); - state = getStateMachine().getInitialState(); + state = getStateMachine().getInitialState().getId(); if (outVertices.length > 0) { WfVertex nextAct = (WfVertex) outVertices[0]; @@ -323,32 +323,35 @@ public class Activity extends WfVertex } /** * called by precedent Activity runNext() for setting the activity able to be executed + * @throws InvalidDataException + * @throws ObjectNotFoundException */ @Override - public void run(AgentPath agent) throws ScriptingEngineException + public void run(AgentPath agent, int itemSysKey) throws InvalidDataException { Logger.debug(8, getPath() + " run " + getState()); - if (!getActive()) - setActive(true); - - if (getMachine().getCurrentState() == States.FINISHED) + + if (!getActive()) setActive(true); + boolean finished = getStateMachine().getState(state).isFinished(); + if (finished) { - runNext(agent); + runNext(agent, itemSysKey); } else { DateUtility.setToNow(mActiveDate); - pushJobsToAgents(); + 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 */ @Override - public void runfirst(AgentPath agent) throws ScriptingEngineException + public void runFirst(AgentPath agent, int itemSysKey) throws InvalidDataException { Logger.debug(8, getPath() + " runfirst"); - run(agent); + run(agent, itemSysKey); } /** @return the current ability to be executed */ public boolean getActive() @@ -375,78 +378,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 calculateJobs(AgentPath agent, boolean recurse) + public ArrayList calculateJobs(AgentPath agent, int itemSysKey, boolean recurse) { - return calculateJobsBase(agent, false); + return calculateJobsBase(agent, itemSysKey, false); } // - public ArrayList calculateAllJobs(AgentPath agent, boolean recurse) + public ArrayList calculateAllJobs(AgentPath agent, int itemSysKey, boolean recurse) { - return calculateJobsBase(agent, true); + return calculateJobsBase(agent, itemSysKey, true); } - private ArrayList calculateJobsBase(AgentPath agent, boolean all) + private ArrayList calculateJobsBase(AgentPath agent, int itemSysKey, boolean includeInactive) { Logger.msg(7, "calculateJobs - " + getPath()); - int[] transitions = { - }; ArrayList jobs = new ArrayList(); - 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 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; } - public void pushJobsToAgents() + public void pushJobsToAgents(int itemSysKey) { String agentRole = getCurrentAgentRole(); if (agentRole == null || agentRole.length()==0) return; @@ -461,7 +421,7 @@ public class Activity extends WfVertex } if (myRole.hasJobList()) - new JobPusher(this, myRole).start(); + new JobPusher(this, itemSysKey, myRole).start(); } @@ -517,10 +477,5 @@ public class Activity extends WfVertex { mType = type; } - private void start() - { - Logger.debug(8, getPath() + " start"); - - } } diff --git a/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java b/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java index 63b5640..3e9ef3c 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java @@ -1,7 +1,7 @@ package com.c2kernel.lifecycle.instance; +import com.c2kernel.common.InvalidDataException; 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 +16,12 @@ public class AndSplit extends Split super(); } @Override - public void runNext(AgentPath agent) throws ScriptingEngineException + public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException { 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 7ab9825..689fbb8 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java @@ -1,7 +1,6 @@ package com.c2kernel.lifecycle.instance; import java.util.ArrayList; -import java.util.Vector; import com.c2kernel.common.AccessRightsException; import com.c2kernel.common.InvalidDataException; @@ -274,66 +273,34 @@ public class CompositeActivity extends Activity } /** + * @throws InvalidDataException * @see com.c2kernel.lifecycle.instance.WfVertex#run() */ @Override - public void run(AgentPath agent) throws ScriptingEngineException + public void run(AgentPath agent, int itemSysKey) throws InvalidDataException { - 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 + public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException { - if (getMachine().state != States.FINISHED) + if (!getStateMachine().getState(state).isFinished()) 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) - { - Vector steps = new Vector(); - 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; + super.runNext(agent, itemSysKey); } + /** * @see com.c2kernel.lifecycle.instance.Activity#calculateJobs() */ @Override - public ArrayList calculateJobs(AgentPath agent, boolean recurse) + public ArrayList calculateJobs(AgentPath agent, int itemSysKey, boolean recurse) { ArrayList jobs = new ArrayList(); boolean childActive = false; @@ -342,16 +309,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 calculateAllJobs(AgentPath agent, boolean recurse) + public ArrayList calculateAllJobs(AgentPath agent, int itemSysKey, boolean recurse) { ArrayList jobs = new ArrayList(); if (recurse) @@ -359,9 +326,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; } @@ -429,14 +396,14 @@ public class CompositeActivity extends Activity public void reinit(int idLoop) { 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 itemSysKey, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException { - if (getChildrenGraphModel().getStartVertex() != null && getMachine().getCurrentState() != States.FINISHED && transitionID == Transitions.START) + if (getChildrenGraphModel().getStartVertex() != null && !getStateMachine().getState(state).isFinished() && transitionID == Transitions.START) try { ((WfVertex) getChildrenGraphModel().getStartVertex()).run(agent); @@ -446,13 +413,14 @@ public class CompositeActivity extends Activity } 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 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 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 94f3086..b643ff8 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Join.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Join.java @@ -1,10 +1,10 @@ package com.c2kernel.lifecycle.instance; import java.util.Vector; +import com.c2kernel.common.InvalidDataException; 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 $ @@ -24,10 +24,11 @@ public class Join extends WfVertex public int counter = 0; /** + * @throws InvalidDataException * @see com.c2kernel.lifecycle.instance.WfVertex#runNext() */ @Override - public void runNext(AgentPath agent) throws ScriptingEngineException + public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException { AdvancementCalculator adv = new AdvancementCalculator(); adv.calculate((CompositeActivity) getParent()); @@ -37,10 +38,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,6 +54,7 @@ public class Join extends WfVertex new Next(this, (WfVertex) getParent().search(idNext)); } /** + * @throws InvalidDataException * @see com.c2kernel.lifecycle.instance.WfVertex#reinit(int) */ @Override @@ -139,12 +141,13 @@ public class Join extends WfVertex return mErrors.elementAt(0); } /** + * @throws InvalidDataException * @see com.c2kernel.lifecycle.instance.WfVertex#run() */ @Override - public void run(AgentPath agent) throws ScriptingEngineException + public void run(AgentPath agent, int itemSysKey) throws InvalidDataException { - runNext(agent); + runNext(agent, itemSysKey); } /** * @see com.c2kernel.lifecycle.instance.WfVertex#addNext(com.c2kernel.lifecycle.instance.WfVertex) @@ -173,9 +176,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 { - 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..76ad7d5 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Loop.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Loop.java @@ -1,8 +1,8 @@ package com.c2kernel.lifecycle.instance; +import com.c2kernel.common.InvalidDataException; 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,15 +26,15 @@ 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 { 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); } } /** diff --git a/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java b/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java index aea34b2..cadf3a0 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"); + String scriptVersion = (String) getProperties().get("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/Split.java b/src/main/java/com/c2kernel/lifecycle/instance/Split.java index e6dab3b..7ba9db3 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Split.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Split.java @@ -2,10 +2,10 @@ package com.c2kernel.lifecycle.instance; import java.util.Vector; +import com.c2kernel.common.InvalidDataException; 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 $ @@ -28,10 +28,11 @@ public abstract class Split extends WfVertex private boolean loopTested; /** + * @throws InvalidDataException * @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; /** * Method addNext. @@ -137,12 +138,13 @@ public abstract class Split extends WfVertex } /** + * @throws InvalidDataException * @see com.c2kernel.lifecycle.instance.WfVertex#run() */ @Override - public void run(AgentPath agent) throws ScriptingEngineException + public void run(AgentPath agent, int itemSysKey) throws InvalidDataException { - runNext(agent); + runNext(agent, itemSysKey); } /** @@ -189,9 +191,9 @@ public abstract class Split extends WfVertex } @Override - public void runfirst(AgentPath agent) throws ScriptingEngineException + public void runFirst(AgentPath agent, int itemSysKey) throws InvalidDataException { - 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..fba00b3 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/WfVertex.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/WfVertex.java @@ -7,7 +7,6 @@ import java.util.HashMap; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectNotFoundException; 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 +24,9 @@ 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 */ + public abstract void runFirst(AgentPath agent, int itemSysKey) throws ScriptingEngineException, InvalidDataException; /** * @see java.lang.Object#Object() @@ -40,8 +40,9 @@ public abstract class WfVertex extends GraphableVertex /** * Method runNext. + * @throws InvalidDataException */ - public void runNext(AgentPath agent) throws ScriptingEngineException + public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException { try { @@ -57,6 +58,8 @@ public abstract class WfVertex extends GraphableVertex /** * Method reinit. * @param idLoop + * @throws InvalidDataException + * @throws ObjectNotFoundException */ public abstract void reinit( int idLoop ); @@ -74,8 +77,9 @@ public abstract class WfVertex extends GraphableVertex /** * Method run. + * @throws InvalidDataException */ - public abstract void run(AgentPath agent) throws ScriptingEngineException; + public abstract void run(AgentPath agent, int itemSysKey) throws InvalidDataException; /** * Method loop. @@ -89,12 +93,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, String scriptVersion, int itemSysKey) throws ScriptingEngineException { try { - EntityPath entity = ((CompositeActivity) getParent()).getWf().getItemEntityPath(); Script script = getScript(scriptName, scriptVersion); KeyValuePair[] k = getProperties().getKeyValuePairs(); @@ -109,7 +112,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 +123,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 +134,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"); diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java index 083de73..0ead50d 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java @@ -6,6 +6,7 @@ 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.graph.model.GraphPoint; @@ -13,7 +14,6 @@ import com.c2kernel.graph.model.TypeNameAndConstructionInfo; import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer; 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; /** @@ -83,14 +83,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", ""); } @@ -154,14 +155,15 @@ public class Workflow extends CompositeActivity implements C2KLocalObject * Method initialise. * * @param systemKey + * @throws InvalidDataException */ - public void initialise(int systemKey, AgentPath agent) + public void initialise(int systemKey, AgentPath agent) throws InvalidDataException { try { - runfirst(agent); + runFirst(agent, systemKey); } - catch (ScriptingEngineException ex) + catch (InvalidDataException ex) { Logger.error(ex); } @@ -175,13 +177,13 @@ public class Workflow extends CompositeActivity implements C2KLocalObject /** * if type = 0 only domain steps will be queried if type = 1 only predefined steps will be queried else both will be queried */ - public ArrayList calculateJobs(AgentPath agent, int type) + public ArrayList calculateJobs(AgentPath agent, int itemSysKey, int type) { ArrayList jobs = new ArrayList(); 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..6c11e92 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java @@ -3,9 +3,11 @@ package com.c2kernel.lifecycle.instance; import java.util.ArrayList; 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; +import com.c2kernel.utils.Logger; /** * @version $Revision: 1.23 $ $Date: 2006/03/03 13:52:21 $ @@ -22,12 +24,18 @@ public class XOrSplit extends Split } @Override - public void runNext(AgentPath agent) throws ScriptingEngineException + public void runNext(AgentPath agent, int itemSysKey) throws InvalidDataException { ArrayList nextsToFollow = new ArrayList(); - String nexts = this.evaluateScript( - (String) getProperties().get("RoutingScriptName"), - (String) getProperties().get("RoutingScriptVersion")).toString(); + String nexts; + String scriptName = (String) getProperties().get("RoutingScriptName"); + String scriptVersion = (String) getProperties().get("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,","); String[] nextsTab = new String[tok.countTokens()]; @@ -41,14 +49,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 { + activeNext.getTerminusVertex().run(agent, itemSysKey); } } 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 e2f9840..9b7b3f0 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java @@ -31,8 +31,8 @@ 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(itemSysKey, lifeCycle, null); diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java index 8ad53bb..0325656 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java @@ -8,7 +8,7 @@ public class State implements Serializable { int id; String name; - boolean proceeds = false; // If true, this state deactivates the current activity and the lifecycle proceeds + boolean finished = false; // If true, this state deactivates the current activity and the lifecycle proceeds HashMap possibleTransitions; @@ -33,12 +33,12 @@ public class State implements Serializable { this.id = id; } - public boolean isProceeds() { - return proceeds; + public boolean isFinished() { + return finished; } - public void setProceeds(boolean proceeds) { - this.proceeds = proceeds; + public void setFinished(boolean finished) { + this.finished = finished; } public HashMap getPossibleTransitions() { diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java index 471e72c..b88ddab 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java @@ -29,6 +29,7 @@ public class Transition implements Serializable { // activation properties boolean requiresActive = true; // Whether the activity must be active for this transition to be available + boolean finishing; // whether the terminal state is a finishing state; // permissions String roleOverride; @@ -61,6 +62,7 @@ public class Transition implements Serializable { public void setTerminalState(State terminalState) { this.terminalState = terminalState; + finishing = terminalState.finished; } public String getEnabledProp() { @@ -74,6 +76,10 @@ public class Transition implements Serializable { public boolean isRequiresActive() { return requiresActive; } + + public boolean isFinishing() { + return finishing; + } public void setRequiresActive(boolean requiresActive) { this.requiresActive = requiresActive; @@ -203,7 +209,7 @@ public class Transition implements Serializable { public String getReservation(Activity act, AgentPath agent) { if (reservation == null || reservation.length() == 0) - reservation = terminalState.proceeds?"clear":"set"; + reservation = terminalState.finished?"clear":"set"; String reservedAgent = act.getCurrentAgentName(); if (reservation.equals("set")) @@ -242,4 +248,8 @@ public class Transition implements Serializable { else return null; } + + public boolean hasScript() { + return script!=null && script.getScriptName() != null; + } } diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionScript.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionScript.java index 80a122a..9585102 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionScript.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionScript.java @@ -5,6 +5,9 @@ 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; } @@ -21,7 +24,4 @@ public class TransitionScript extends TransitionResource { this.scriptVersion = scriptVersion; } - public TransitionScript() { - } - } -- cgit v1.2.3