From 0bb38e90ac6e88cb406facbc075983384a2e164f Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Sat, 20 Jul 2013 11:56:53 +0200 Subject: ActivityDef is a DescriptionObject --- .../java/com/c2kernel/lifecycle/ActivityDef.java | 3 +- .../com/c2kernel/lifecycle/WfCastorHashMap.java | 7 +- .../com/c2kernel/lifecycle/instance/Activity.java | 390 ++++++--------------- .../lifecycle/instance/CompositeActivity.java | 6 +- .../java/com/c2kernel/lifecycle/instance/Join.java | 30 +- .../com/c2kernel/lifecycle/instance/Split.java | 28 -- .../com/c2kernel/lifecycle/instance/Workflow.java | 3 - .../instance/predefined/AddC2KObject.java | 46 +-- .../instance/predefined/AddDomainPath.java | 18 +- .../instance/predefined/AddMemberToCollection.java | 21 +- .../lifecycle/instance/predefined/AddNewSlot.java | 21 +- .../predefined/AddStepsFromDescription.java | 18 +- .../instance/predefined/AssignItemToSlot.java | 21 +- .../lifecycle/instance/predefined/ClearSlot.java | 22 +- .../predefined/CreateItemFromDescription.java | 21 +- .../lifecycle/instance/predefined/Erase.java | 23 +- .../lifecycle/instance/predefined/Import.java | 25 +- .../instance/predefined/PredefinedStep.java | 9 +- .../predefined/PredefinedStepContainer.java | 5 - .../instance/predefined/RemoveC2KObject.java | 17 +- .../instance/predefined/RemoveDomainPath.java | 15 +- .../predefined/RemoveSlotFromCollection.java | 23 +- .../instance/predefined/ReplaceDomainWorkflow.java | 13 +- .../instance/predefined/WriteProperty.java | 50 +-- .../predefined/entitycreation/CreateNewAgent.java | 13 +- .../predefined/entitycreation/CreateNewItem.java | 14 +- .../predefined/entitycreation/NewItem.java | 2 - .../com/c2kernel/persistency/outcome/Outcome.java | 14 +- 28 files changed, 249 insertions(+), 629 deletions(-) (limited to 'src/main/java/com/c2kernel') diff --git a/src/main/java/com/c2kernel/lifecycle/ActivityDef.java b/src/main/java/com/c2kernel/lifecycle/ActivityDef.java index 40d1f8a..4b8fe9e 100644 --- a/src/main/java/com/c2kernel/lifecycle/ActivityDef.java +++ b/src/main/java/com/c2kernel/lifecycle/ActivityDef.java @@ -6,12 +6,13 @@ import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.lifecycle.instance.Activity; import com.c2kernel.lifecycle.instance.WfVertex; +import com.c2kernel.utils.DescriptionObject; import com.c2kernel.utils.FileStringUtility; /** * @version $Revision: 1.45 $ $Date: 2005/10/05 07:39:36 $ * @author $Author: abranson $ */ -public class ActivityDef extends WfVertexDef implements C2KLocalObject +public class ActivityDef extends WfVertexDef implements C2KLocalObject, DescriptionObject { private int mId = -1; private String mName = ""; diff --git a/src/main/java/com/c2kernel/lifecycle/WfCastorHashMap.java b/src/main/java/com/c2kernel/lifecycle/WfCastorHashMap.java index eb9aa2a..e47fdc6 100644 --- a/src/main/java/com/c2kernel/lifecycle/WfCastorHashMap.java +++ b/src/main/java/com/c2kernel/lifecycle/WfCastorHashMap.java @@ -1,5 +1,4 @@ package com.c2kernel.lifecycle; -import com.c2kernel.lifecycle.instance.stateMachine.StateMachine; import com.c2kernel.utils.CastorHashMap; /** * @version $Revision: 1.29 $ $Date: 2005/05/20 13:07:13 $ @@ -12,10 +11,6 @@ public class WfCastorHashMap extends CastorHashMap */ public WfCastorHashMap() { - //put(StateMachine.AUTOSTART, new Boolean(false)); - put(StateMachine.SKIPPABLE, new Boolean(false)); - put(StateMachine.REPEATABLE, new Boolean(false)); - put(StateMachine.IGNORABLE, new Boolean(false)); put("Show time", new Boolean(true)); put("Breakpoint", new Boolean(false)); put("Description", ""); @@ -25,6 +20,8 @@ public class WfCastorHashMap extends CastorHashMap put("SchemaVersion", ""); put("ScriptName", ""); put("ScriptVersion", ""); + put("StateMachineName", "Default"); + put("StateMachineVersion", "0"); put("Viewpoint", ""); } } diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java index 2384dc3..1fc0c14 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java @@ -8,26 +8,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.ClusterStorage; -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; /** * @version $Revision: 1.222 $ $Date: 2005/10/05 07:39:37 $ @@ -41,54 +42,26 @@ public class Activity extends WfVertex protected Vector mErrors; /** @associates a State machine engine */ private StateMachine machine; - /** true is avalaibe to be executed */ + private 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 String mType; - private EntityPath mEntityPath; + public Activity() { super(); setProperties(new WfCastorHashMap()); 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; - } - /** sets the StateMachine (Only for Serialisation) */ - public void setMachine(StateMachine sm) - { - machine = sm; - } + /** add the activity which id is idNext as next of the current one */ void addNext(String idNext) { @@ -102,153 +75,116 @@ public class Activity extends WfVertex { return new Next(this, vertex); } - /** return the current State of the State machine */ - public int getCurrentState() - { - return machine.getCurrentState(); + + private StateMachine getStateMachine() throws ObjectNotFoundException, InvalidDataException { + if (machine == null) { + String name = (String)getProperties().get("StateMachineName"); + String version = (String)getProperties().get("StateMachineVersion"); + machine = LocalObjectLoader.getStateMachine(name, 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(); + return state; } - /** Sets a new State in a State machine */ - public void setState(int stat) + /** Sets a new State */ + public void setState(int state) { - if (machine == null) - machine = new StateMachine(this); - machine.state = stat; + this.state = 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 + + + /** cf Item request + * @throws ObjectNotFoundException + * @throws PersistencyException */ + public final void request(AgentPath agent, int itemSysKey, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, ObjectNotFoundException, PersistencyException { - String agentID = getCurrentAgentName(); - boolean authorised = agentID.equals(agent.getAgentName()); - String actRole = getCurrentAgentRole(); - if (!authorised) - { - authorised = actRole == null || actRole.equals("") || actRole.equals("all"); + + // 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); } - 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"); + + // 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 = (History) Gateway.getStorage().get(itemSysKey, ClusterStorage.HISTORY, this); + if (storeOutcome) + newEvent = hist.addEvent(agent.getAgentName(), usedRole, transitionID, getName(), getPath(), getType(), schema.docType, schema.docVersion, viewName, state); + else + newEvent = hist.addEvent(agent.getAgentName(), usedRole, transitionID, getName(), getPath(), getType(), state); + + 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"); } - if (!authorised) - throw new AccessRightsException("Activity::checkAccessRights() - Agent does not hold the correct role."); - return agent.getAgentName(); - } - /** cf Item request */ - public void request(AgentPath agent, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException - { - 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 - { + + if (newState.isProceeds()) { + setActive(false); + if (!getProperties().get("Breakpoint").equals(Boolean.TRUE)) + try { runNext(agent); + } catch (ScriptingEngineException ex) { + Logger.error("Error calculating next actvity in lifecycle of "+itemSysKey); + Logger.error(ex); } - 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."); - } - 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); + DateUtility.setToNow(mStartDate); + + //refresh all the job lists + pushJobsToAgents(); } - public String getTransitions() - { - String result = ""; - int i; - for (i = 0; i < machine.possibleTransition().length; i++) - { - result += machine.possibleTransition()[i] + ","; - } - //cuts out the last comma(',') if required - if (i > 0) - { - result = result.substring(0, result.length() - 1); - } - result += ""; - return result; + + protected String runActivityLogic(AgentPath agent, int itemSysKey, + int transitionID, String requestData) throws InvalidDataException { + // Overriden in predefined steps + return requestData; } - /** launch the verification of the activity */ + @Override public boolean verify() { @@ -369,9 +305,8 @@ public class Activity extends WfVertex @Override public void reinit(int idLoop) { - Logger.debug(7, "reinit " + getItemEntityPath().getSysKey() + " " + getPath()); Vertex[] outVertices = getOutGraphables(); - machine.state = States.WAITING; + state = getStateMachine().getInitialState(); if (outVertices.length > 0) { WfVertex nextAct = (WfVertex) outVertices[0]; @@ -392,7 +327,7 @@ public class Activity extends WfVertex @Override public void run(AgentPath agent) throws ScriptingEngineException { - Logger.debug(8, getPath() + " run " + getCurrentState()); + Logger.debug(8, getPath() + " run " + getState()); if (!getActive()) setActive(true); @@ -509,118 +444,7 @@ public class Activity extends WfVertex 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 = (History) Gateway.getStorage().get(entityPath.getSysKey(), ClusterStorage.HISTORY, this); - 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 - { - Outcome newOutcome = new Outcome(eventID, requestData, schemaType, schemaVersion); - Gateway.getStorage().put(entityPath.getSysKey(), newOutcome, this); - // 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, this); - } // update last view - Viewpoint currentView = new Viewpoint(entityPath.getSysKey(), schemaType, "last", schemaVersion, eventID); - Gateway.getStorage().put(entityPath.getSysKey(), currentView, this); - 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; - 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(this); - } - } + } public void pushJobsToAgents() { @@ -696,7 +520,7 @@ public class Activity extends WfVertex private void start() { Logger.debug(8, getPath() + " start"); - DateUtility.setToNow(mStartDate); + } } diff --git a/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java b/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java index f3f5a81..7ab9825 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java @@ -11,8 +11,6 @@ import com.c2kernel.entity.agent.Job; import com.c2kernel.graph.model.GraphModel; import com.c2kernel.graph.model.GraphPoint; import com.c2kernel.graph.model.GraphableVertex; -import com.c2kernel.lifecycle.instance.stateMachine.States; -import com.c2kernel.lifecycle.instance.stateMachine.Transitions; import com.c2kernel.lookup.AgentPath; import com.c2kernel.scripting.ScriptingEngineException; import com.c2kernel.utils.Logger; @@ -436,7 +434,7 @@ public class CompositeActivity extends Activity } @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, ObjectAlreadyExistsException { if (getChildrenGraphModel().getStartVertex() != null && getMachine().getCurrentState() != States.FINISHED && transitionID == Transitions.START) try @@ -446,7 +444,7 @@ public class CompositeActivity extends Activity { Logger.error(e); } - super.request(agent, transitionID, requestData); + super.request(agent, itemSysKey, transitionID, requestData); } public void refreshJobs() { diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Join.java b/src/main/java/com/c2kernel/lifecycle/instance/Join.java index 3a4fd7d..94f3086 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Join.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Join.java @@ -22,7 +22,7 @@ public class Join extends WfVertex } private boolean loopTested; public int counter = 0; - private String mItemSystemKey = ""; + /** * @see com.c2kernel.lifecycle.instance.WfVertex#runNext() */ @@ -65,33 +65,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() { diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Split.java b/src/main/java/com/c2kernel/lifecycle/instance/Split.java index 4fe1bfc..e6dab3b 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Split.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Split.java @@ -27,8 +27,6 @@ public abstract class Split extends WfVertex private boolean loopTested; - private int mItemSystemKey = -1; - /** * @see com.c2kernel.lifecycle.instance.WfVertex#runNext() */ @@ -64,32 +62,6 @@ 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) { diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java index 321e53e..083de73 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java @@ -11,7 +11,6 @@ import com.c2kernel.entity.agent.Job; 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; @@ -43,7 +42,6 @@ public class Workflow extends CompositeActivity implements C2KLocalObject */ public Workflow() { - getProperties().put("ItemSystemKey", null); } public Workflow(CompositeActivity domain) { @@ -159,7 +157,6 @@ public class Workflow extends CompositeActivity implements C2KLocalObject */ public void initialise(int systemKey, AgentPath agent) { - this.getProperties().put("ItemSystemKey", new Integer(systemKey)); try { runfirst(agent); 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..8d5ba4a 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]); @@ -40,9 +36,9 @@ public class AddStepsFromDescription extends PredefinedStep domain.setName("domain"); domain.setType(actDef.getName()); lifeCycle.run(agent); - Gateway.getStorage().put(getItemEntityPath().getSysKey(), lifeCycle, null); + 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..2e4b313 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,10 +52,10 @@ 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; @@ -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())); @@ -117,7 +113,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,6 +158,7 @@ public class CreateItemFromDescription extends PredefinedStep String[] colls = new String[1]; for (Iterator iter = collections.iterator(); iter.hasNext();) { colls[0] = iter.next(); + // TODO: initialize newItem.requestAction(agent.getSysKey(), "workflow/predefined/AddC2KObject", Transitions.DONE, PredefinedStep.bundleData(colls)); } } @@ -170,6 +167,7 @@ public class CreateItemFromDescription extends PredefinedStep Logger.msg(3, "CreateItemFromDescription - Creating "+context); context.setEntity(entityPath); Gateway.getLDAPLookup().add(context); + return requestData; } catch (ObjectAlreadyExistsException e) { Logger.error(e); throw e; @@ -181,6 +179,5 @@ public class CreateItemFromDescription extends PredefinedStep 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 8bcaa45..44ab041 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(); - History hist = new History(syskey, this); - Event event = hist.addEvent(agent.getAgentName(), getCurrentAgentRole(), transitionID, getName(), getPath(), getType(), schemaName, schemaVersion, viewpoint, getCurrentState(), timestamp); + History hist = new History(itemSysKey, this); + Event event = hist.addEvent(agent.getAgentName(), getCurrentAgentRole(), transitionID, getName(), getPath(), getType(), schemaName, schemaVersion, viewpoint, getState(), timestamp); try { - storage.put(syskey, new Outcome(event.getID(), requestData, schemaName, schemaVersion), this); - storage.put(syskey, new Viewpoint(syskey, schemaName, viewpoint, schemaVersion, event.getID()), this); + 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()), this); + storage.put(itemSysKey, new Viewpoint(itemSysKey, schemaName, "last", schemaVersion, event.getID()), this); } catch (ClusterStorageException e) { Logger.error(e); storage.abort(this); throw new InvalidDataException("Could not store imported outcome. Rolled back."); } 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..a9776ed 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java @@ -33,14 +33,7 @@ public class PredefinedStep extends Activity else return super.getActive(); } - @Override - public String getTransitions() - { - if (isPredefined) - return "done"; - else - return super.getTransitions(); - } + @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..e2f9840 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]); @@ -40,9 +35,9 @@ public class ReplaceDomainWorkflow extends PredefinedStep else lifeCycle.refreshJobs(); // 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..c3334d6 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,6 @@ 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.lookup.DomainPath; import com.c2kernel.lookup.EntityPath; import com.c2kernel.persistency.ClusterStorage; diff --git a/src/main/java/com/c2kernel/persistency/outcome/Outcome.java b/src/main/java/com/c2kernel/persistency/outcome/Outcome.java index 3e6cb63..b2f706b 100644 --- a/src/main/java/com/c2kernel/persistency/outcome/Outcome.java +++ b/src/main/java/com/c2kernel/persistency/outcome/Outcome.java @@ -22,7 +22,7 @@ import com.c2kernel.utils.LocalObjectLoader; import com.c2kernel.utils.Logger; public class Outcome implements C2KLocalObject { - int mID = -1; + Integer mID; String mData; String mSchemaType; int mSchemaVersion; @@ -75,25 +75,25 @@ public class Outcome implements C2KLocalObject { throw new PersistencyException("Outcome() - Outcome version was an invalid number: "+verstring, null); } try { - mID = Integer.parseInt(objId); + mID = new Integer(objId); } catch (NumberFormatException ex) { - mID = -1; + mID = null; } mData = data; } - public void setID(int ID) { + public void setID(Integer ID) { mID = ID; } - public int getID() { + public Integer getID() { return mID; } @Override public void setName(String name) { try { - mID = Integer.parseInt(name); + mID = new Integer(name); } catch (NumberFormatException e) { Logger.error("Invalid id set on Outcome:"+name); } @@ -101,7 +101,7 @@ public class Outcome implements C2KLocalObject { @Override public String getName() { - return String.valueOf(mID); + return mID.toString(); } public void setData(String data) { -- cgit v1.2.3