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 +++++++-------------- 1 file changed, 50 insertions(+), 95 deletions(-) (limited to 'src/main/java/com/c2kernel/lifecycle/instance/Activity.java') 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"); - - } } -- cgit v1.2.3