From d43164830403245353080f5d6f838ed9f56d9a35 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Mon, 18 Nov 2013 09:48:03 +0100 Subject: 3.0-SNAPSHOT (Will be first open source version) New StateMachine desc IssueID #28 --- .../com/c2kernel/lifecycle/instance/Activity.java | 616 +++++++-------------- .../lifecycle/instance/AdvancementCalculator.java | 17 +- .../com/c2kernel/lifecycle/instance/AndSplit.java | 10 +- .../lifecycle/instance/CompositeActivity.java | 117 ++-- .../com/c2kernel/lifecycle/instance/JobPusher.java | 26 +- .../java/com/c2kernel/lifecycle/instance/Join.java | 63 +-- .../java/com/c2kernel/lifecycle/instance/Loop.java | 15 +- .../com/c2kernel/lifecycle/instance/OrSplit.java | 20 +- .../com/c2kernel/lifecycle/instance/ParserWF.java | 356 ------------ .../com/c2kernel/lifecycle/instance/Split.java | 56 +- .../com/c2kernel/lifecycle/instance/WfVertex.java | 64 ++- .../com/c2kernel/lifecycle/instance/Workflow.java | 46 +- .../com/c2kernel/lifecycle/instance/XOrSplit.java | 28 +- .../instance/predefined/AddC2KObject.java | 46 +- .../instance/predefined/AddDomainPath.java | 18 +- .../instance/predefined/AddMemberToCollection.java | 21 +- .../lifecycle/instance/predefined/AddNewSlot.java | 21 +- .../predefined/AddStepsFromDescription.java | 20 +- .../instance/predefined/AssignItemToSlot.java | 21 +- .../lifecycle/instance/predefined/ClearSlot.java | 22 +- .../predefined/CreateItemFromDescription.java | 40 +- .../lifecycle/instance/predefined/Erase.java | 23 +- .../lifecycle/instance/predefined/Import.java | 25 +- .../instance/predefined/PredefinedStep.java | 15 +- .../predefined/PredefinedStepContainer.java | 5 - .../instance/predefined/RemoveC2KObject.java | 17 +- .../instance/predefined/RemoveDomainPath.java | 15 +- .../predefined/RemoveSlotFromCollection.java | 23 +- .../instance/predefined/ReplaceDomainWorkflow.java | 17 +- .../instance/predefined/WriteProperty.java | 50 +- .../predefined/entitycreation/CreateNewAgent.java | 13 +- .../predefined/entitycreation/CreateNewItem.java | 14 +- .../predefined/entitycreation/NewItem.java | 8 +- .../predefined/entitycreation/Outcome.java | 4 +- .../lifecycle/instance/stateMachine/State.java | 60 ++ .../instance/stateMachine/StateMachine.java | 247 +++++---- .../lifecycle/instance/stateMachine/States.java | 40 -- .../instance/stateMachine/Transition.java | 292 ++++++++++ .../instance/stateMachine/TransitionOutcome.java | 36 ++ .../instance/stateMachine/TransitionResource.java | 9 + .../instance/stateMachine/TransitionScript.java | 27 + .../instance/stateMachine/Transitions.java | 41 -- 42 files changed, 1141 insertions(+), 1483 deletions(-) delete mode 100644 src/main/java/com/c2kernel/lifecycle/instance/ParserWF.java create mode 100644 src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java delete mode 100644 src/main/java/com/c2kernel/lifecycle/instance/stateMachine/States.java create mode 100644 src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java create mode 100644 src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionOutcome.java create mode 100644 src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionResource.java create mode 100644 src/main/java/com/c2kernel/lifecycle/instance/stateMachine/TransitionScript.java delete mode 100644 src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transitions.java (limited to 'src/main/java/com/c2kernel/lifecycle/instance') 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 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(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 = ""; - 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 += ""; - 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 calculateJobs(AgentPath agent, boolean recurse) + public ArrayList calculateJobs(AgentPath agent, int itemSysKey, boolean recurse) throws ObjectNotFoundException, InvalidDataException { - 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) throws ObjectNotFoundException, InvalidDataException { - 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) throws ObjectNotFoundException, InvalidDataException { 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; } - - - /** 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(); hasprevActive = new Hashtable(); } - 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() 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; + 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 calculateJobs(AgentPath agent, boolean recurse) + public ArrayList calculateJobs(AgentPath agent, int itemSysKey, boolean recurse) throws ObjectNotFoundException, InvalidDataException { ArrayList jobs = new ArrayList(); 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 calculateAllJobs(AgentPath agent, boolean recurse) + public ArrayList calculateAllJobs(AgentPath agent, int itemSysKey, boolean recurse) throws ObjectNotFoundException, InvalidDataException { ArrayList jobs = new ArrayList(); 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 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 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 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(1, 1); - i = 0; - file = xmlfile; - while (i < file.length() - 5) - { - if (file.substring(i, i + 5).equals("")) - { - if (file.substring(i, i + 5).equals("")) - { - Logger.msg(7, ""); - 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("")) - { - Logger.msg(7, ""); - 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, ""); - } - 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 calculateJobs(AgentPath agent, int type) + public ArrayList calculateJobs(AgentPath agent, int itemSysKey, int type) throws ObjectNotFoundException, InvalidDataException { 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..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 nextsToFollow = new ArrayList(); - 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 collections = new ArrayList(); // loop through collections to instantiate for (String collName : collNames) { - Collection thisCol = (Collection)storage.get(myPath.getSysKey(), ClusterStorage.COLLECTION+"/"+collName, null); + Collection thisCol = (Collection)storage.get(itemSysKey, ClusterStorage.COLLECTION+"/"+collName, null); if (thisCol instanceof CollectionDescription) { CollectionDescription thisDesc = (CollectionDescription)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 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 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 "done"; - 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 ""; - } } 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)Gateway.getStorage().get(entityPath.getSysKey(), ClusterStorage.COLLECTION+"/"+collName, null); + coll = (Collection)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 possibleTransitions; + + public State() { + possibleTransitions = new HashMap(); + } + + 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 getPossibleTransitions() { + return possibleTransitions; + } + + protected void addPossibleTransition(Transition possibleTransition) { + possibleTransitions.put(possibleTransition.getId(), possibleTransition); + } + + public Set 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 states; + private ArrayList transitions; + private final HashMap stateCodes; + private final HashMap transitionCodes; + + State initialState; + int initialStateCode; + boolean isCoherent = false; + + public StateMachine() { + states = new ArrayList(); + transitions = new ArrayList(); + stateCodes = new HashMap(); + transitionCodes = new HashMap(); } - - /** 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 newStates) { + this.states = newStates; + validate(); } - - /** - * @see java.lang.Object#Object() - */ - public StateMachine() - { + + public void setTransitions(ArrayList 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 getStates() { + return states; + } + + public ArrayList 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 -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 getPossibleTransitions(Activity act, AgentPath agent) throws ObjectNotFoundException, InvalidDataException { + HashMap returnList = new HashMap(); + 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 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; - } - } -} -- cgit v1.2.3