summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lifecycle/instance
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/c2kernel/lifecycle/instance')
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/Activity.java689
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/AdvancementCalculator.java225
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java27
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java458
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/EventList.java19
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/EventStorage.java24
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/JobPusher.java70
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/Join.java216
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/Loop.java107
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/Next.java83
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java62
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/ParserWF.java356
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/Split.java225
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/WfVertex.java180
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/Workflow.java208
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java54
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfEdgeFactory.java35
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfGraphPanel.java59
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfVertexFactory.java92
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfVertexOutlineCreator.java52
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/gui/view/ActivityRenderer.java117
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/gui/view/FindActDefPanel.java72
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/gui/view/SplitJoinRenderer.java142
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/gui/view/TransitionPanel.java187
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/gui/view/WfDirectedEdgeRenderer.java130
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/gui/view/WfVertexRenderer.java23
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/AddC2KObject.java75
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java67
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/AddStepsFromDescription.java56
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java116
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java183
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/Erase.java85
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/Import.java71
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java156
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java61
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveC2KObject.java67
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java59
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java53
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/ServerPredefinedStepContainer.java41
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java77
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java25
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java21
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java49
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java46
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java44
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java18
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Geometry.java29
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java63
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java141
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Property.java26
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java142
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/stateMachine/States.java40
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transitions.java41
53 files changed, 5764 insertions, 0 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java
new file mode 100644
index 0000000..8a07d15
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java
@@ -0,0 +1,689 @@
+package com.c2kernel.lifecycle.instance;
+import java.util.ArrayList;
+import java.util.Vector;
+
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.GTimeStamp;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectNotFoundException;
+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.StateMachine;
+import com.c2kernel.lifecycle.instance.stateMachine.States;
+import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
+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.outcome.Outcome;
+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.Logger;
+/**
+ * @version $Revision: 1.222 $ $Date: 2005/10/05 07:39:37 $
+ * @author $Author: abranson $
+ */
+public class Activity extends WfVertex
+{
+ /**
+ * vector of errors (Strings) that is constructed each time verify() is launched
+ */
+ protected Vector<String> mErrors;
+ /** @associates a State machine engine */
+ private StateMachine machine;
+ /** true is avalaibe to be executed */
+ public boolean active = false;
+ /** used in verify() */
+ private boolean loopTested;
+ //public Vector eventIds;
+ /** Storage of eventIds thrown by the Activity */
+ public EventStorage eventIds;
+ private GTimeStamp mStartDate;
+ private GTimeStamp mActiveDate;
+ private String mType;
+ private EntityPath mEntityPath;
+ public Activity()
+ {
+ super();
+ setProperties(new WfCastorHashMap());
+ mErrors = new Vector<String>(0, 1);
+ machine = new StateMachine(this);
+ eventIds = new EventStorage();
+ 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)
+ {
+ new Next(this, (WfVertex) getParent().search(idNext));
+ }
+ /**
+ * adds a New link between the current Activity and the WfVertex passed in param
+ */
+ @Override
+ public Next addNext(WfVertex vertex)
+ {
+ return new Next(this, vertex);
+ }
+ /** return the current State of the State machine */
+ public int getCurrentState()
+ {
+ return machine.getCurrentState();
+ }
+ /** 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)
+ {
+ if (machine == null)
+ machine = new StateMachine(this);
+ machine.state = stat;
+ }
+ /** 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
+ {
+ 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();
+ }
+ /** 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 && state == States.RSTARTED)
+ setActive(false);
+ if (transitionID == Transitions.START)
+ start();
+ if ((transitionID == Transitions.SKIP && getActive())
+ || transitionID == Transitions.DONE
+ || (transitionID == Transitions.COMPLETE && state == States.STARTED)
+ || 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.");
+ }
+ 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 String getTransitions()
+ {
+ String result = "<PossibleTransitions>";
+ 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 += "</PossibleTransitions>";
+ return result;
+ }
+ /** launch the verification of the activity */
+ @Override
+ public boolean verify()
+ {
+ mErrors.removeAllElements();
+ int nbInEdgres = getInEdges().length;
+ int nbOutEdges = getOutEdges().length;
+ if (nbInEdgres == 0 && this.getID() != getParent().getChildrenGraphModel().getStartVertexId())
+ {
+ mErrors.add("Unreachable");
+ return false;
+ }
+ else if (nbInEdgres > 1)
+ {
+ mErrors.add("Bad nb of previous");
+ return false;
+ }
+ else if (nbOutEdges > 1)
+ {
+ mErrors.add("too many next");
+ return false;
+ }
+ else if (nbOutEdges == 0)
+ {
+ if (!((CompositeActivity) getParent()).hasGoodNumberOfActivity())
+ {
+ mErrors.add("too many endpoints");
+ return false;
+ }
+ }
+// else
+// {
+// Vertex[] outV = getOutGraphables();
+// Vertex[] anteVertices = GraphTraversal.getTraversal(getParent().getChildrenGraphModel(), this, GraphTraversal.kUp, false);
+// boolean errInLoop = false;
+// for (int i = 0; i < outV.length; i++)
+// {
+// for (int j = 0; j < anteVertices.length; j++)
+// if (!loop() && outV[i].getID() == anteVertices[j].getID())
+// errInLoop = true;
+// }
+// if (errInLoop)
+// {
+// mErrors.add("Error In Loop");
+// return false;
+// }
+// }
+ return true;
+ }
+ /** Used in verify() */
+ @Override
+ public boolean loop()
+ {
+ boolean loop2 = false;
+ if (!loopTested)
+ {
+ loopTested = true;
+ if (getOutGraphables().length != 0)
+ loop2 = ((WfVertex) getOutGraphables()[0]).loop();
+ }
+ loopTested = false;
+ return loop2;
+ }
+ /** sets the next activity available if possible */
+ @Override
+ public void runNext(AgentPath agent) throws ScriptingEngineException
+ {
+ setActive(false);
+ try
+ {
+ Vertex[] outVertices = getOutGraphables();
+ Vertex[] outVertices2 = getOutGraphables();
+ boolean hasNoNext = false;
+ boolean out = false;
+ while (!out)
+ if (outVertices2.length > 0)
+ {
+ if (outVertices2[0] instanceof Join)
+ outVertices2 = ((WfVertex) outVertices2[0]).getOutGraphables();
+ else
+ out = true;
+ }
+ else
+ {
+ hasNoNext = true;
+ out = true;
+ }
+ Logger.debug(8, outVertices + " " + outVertices2);
+ if (!hasNoNext)
+ ((WfVertex) outVertices[0]).run(agent);
+ else
+ {
+ if (getParent() != null && getParent().getName().equals("domain")) // workflow
+ // finished
+ setActive(true);
+ else
+ {
+ CompositeActivity parent = (CompositeActivity) getParent();
+ if (parent != null)
+ parent.runNext(agent);
+ }
+ }
+ }
+ catch (ScriptingEngineException s)
+ {
+ setActive(true);
+ throw s;
+ }
+ }
+ /** @return the only Next of the Activity */
+ public Next getNext()
+ {
+ if (getOutEdges().length > 0)
+ return (Next) getOutEdges()[0];
+ else
+ return null;
+ }
+ /** reinitialises the Activity and propagate (for Loop) */
+ @Override
+ public void reinit(int idLoop)
+ {
+ Logger.debug(7, "reinit " + getItemEntityPath().getSysKey() + " " + getPath());
+ Vertex[] outVertices = getOutGraphables();
+ machine.state = States.WAITING;
+ if (outVertices.length > 0)
+ {
+ WfVertex nextAct = (WfVertex) outVertices[0];
+ nextAct.reinit(idLoop);
+ }
+ }
+ /** return the String that identifies the errors found in th activity */
+ @Override
+ public String getErrors()
+ {
+ if (mErrors.size() == 0)
+ return "No error";
+ return mErrors.elementAt(0);
+ }
+ /**
+ * called by precedent Activity runNext() for setting the activity able to be executed
+ */
+ @Override
+ public void run(AgentPath agent) throws ScriptingEngineException
+ {
+ Logger.debug(8, getPath() + " run " + getCurrentState());
+ if (!getActive())
+ setActive(true);
+
+ if (getMachine().getCurrentState() == States.FINISHED)
+ {
+ runNext(agent);
+ }
+ else
+ {
+ DateUtility.setToNow(mActiveDate);
+ if (((Boolean) getProperties().get(StateMachine.AUTOSTART)).booleanValue() && machine.state == States.WAITING)
+ {
+ machine.traverse(Transitions.START);
+ start();
+ }
+ pushJobsToAgents();
+ }
+ }
+ /**
+ * sets the activity available to be executed on start of Workflow or composite activity (when it is the first one of the (sub)process
+ */
+ @Override
+ public void runfirst(AgentPath agent) throws ScriptingEngineException
+ {
+ Logger.debug(8, getPath() + " runfirst");
+ run(agent);
+ }
+ /** @return the current ability to be executed */
+ public boolean getActive()
+ {
+ return active;
+ }
+ /** sets the ability to be executed */
+ public void setActive(boolean acti)
+ {
+ active = acti;
+ }
+ /** @return the Description field of properties */
+ public String getDescription()
+ {
+ if (getProperties().containsKey("Description"))
+ return (String) (getProperties().get("Description"));
+ return "No description";
+ }
+ public String getCurrentAgentName()
+ {
+ return (String) getProperties().get("Agent Name");
+ }
+ public String getCurrentAgentRole()
+ {
+ return (String) getProperties().get("Agent Role");
+ }
+ /**
+ * @return an array of Steps that matches the querry
+ * @param agentID
+ * Agent concerned by the query
+ * @param agentRole
+ * Agent concerned by the query @int stateID state to test in the query, use -1 for all
+ * @param filter
+ * if tru will be filtered by agent, else won't
+ */
+ public Activity[] query(AgentPath agent, int stateID, boolean filter)
+ {
+ if (getCurrentState() == stateID || stateID == -1)
+ {
+ Activity[] steps = { this };
+ if (!filter)
+ return steps;
+ else
+ {
+ try
+ {
+ checkAccessRights(agent);
+ return steps;
+ }
+ catch (AccessRightsException e)
+ {
+ //case that agent is not allowed
+ Logger.msg(7, "Activity :: AccessRightsException in " + this.getItemEntityPath() + "/" + this.getPath());
+ }
+ }
+ }
+ return new Activity[0];
+ }
+ /**
+ * returns the lists of jobs for the activity and children (cf com.c2kernel.entity.Job)
+ */
+ public ArrayList<Job> calculateJobs(AgentPath agent, boolean recurse)
+ {
+ return calculateJobsBase(agent, false);
+ } //
+ public ArrayList<Job> calculateAllJobs(AgentPath agent, boolean recurse)
+ {
+ return calculateJobsBase(agent, true);
+ }
+ private ArrayList<Job> calculateJobsBase(AgentPath agent, boolean all)
+ {
+ Logger.msg(7, "calculateJobs - " + getPath());
+ int[] transitions = {
+ };
+ ArrayList<Job> jobs = new ArrayList<Job>();
+ try
+ {
+ String agentName = checkAccessRights(agent);
+ String currentAgentName = getCurrentAgentName();
+ boolean isCurrent = currentAgentName == null || currentAgentName.equals("") || agentName.equals(currentAgentName);
+ if ((all || getActive()) && !getName().equals("domain"))
+ transitions = machine.possibleTransition();
+ Logger.msg(7, "Activity.calculateJobs() - Got " + transitions.length + " transitions.");
+ for (int i = 0; i < transitions.length; i++)
+ {
+ Logger.msg(7, "Creating Job object for transition " + transitions[i]);
+ if ((isCurrent && !(transitions[i] == Transitions.REASSIGN && agentName.equals(currentAgentName))) || (transitions[i] == Transitions.REASSIGN && !agentName.equals(currentAgentName)))
+ jobs.add(new Job(getItemEntityPath().getSysKey(), getPath(), transitions[i], getCurrentState(), machine.simulate(transitions[i]), getName(), getProperties(), getType(), agentName));
+ }
+ }
+ catch (AccessRightsException ex)
+ {
+ Logger.msg(6, "Agent "+ agent.getAgentName() +" is not allowed to interact with "+getItemEntityPath().getSysKey()+":"+getPath());
+ } // empty joblist then
+ return jobs;
+ }
+ //
+ //methods written by kovax
+ //
+ /** Adds an event to the AuditTrail of the Item if any */
+ private Event auditEvent(int transitionID, AgentPath agent)
+ {
+ EntityPath entityPath = getItemEntityPath();
+ if (entityPath != null)
+ {
+ Event event = null;
+ History hist = null;
+ try
+ {
+ hist = (History) Gateway.getStorage().get(entityPath.getSysKey(), ClusterStorage.HISTORY, this);
+ 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)
+ {
+ EntityPath entityPath = getItemEntityPath();
+ if (entityPath != null)
+ {
+ String schemaType = (String) getProperties().get("SchemaType");
+ if (schemaType == null || schemaType.length() == 0) // no
+ // outcome
+ // required
+ return null;
+ int schemaVersion = 0;
+ String versionString = (String) getProperties().get("SchemaVersion");
+ try
+ {
+ schemaVersion = Integer.parseInt(versionString);
+ }
+ catch (Exception e)
+ {
+ Logger.error("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 */
+ public void sendEventStoreOutcome(int transitionID, String requestData, AgentPath agent)
+ {
+ int eventID = -1;
+ Event event = null;
+ event = auditEvent(transitionID, agent);
+ if (event != null)
+ eventID = event.getID();
+ if (transitionID == Transitions.DONE || transitionID == Transitions.COMPLETE)
+ storeOutcome(eventID, requestData);
+ EntityPath entityPath = getItemEntityPath();
+ TransactionManager storage = Gateway.getStorage();
+ if (entityPath != null)
+ {
+ storage.commit(this);
+ }
+ }
+ public void pushJobsToAgents()
+ {
+ String agentRole = getCurrentAgentRole();
+ if (agentRole == null || agentRole.length()==0) return;
+
+ LDAPRoleManager roleMan = Gateway.getLDAPLookup().getRoleManager();
+ RolePath myRole;
+ try {
+ myRole = roleMan.getRolePath(agentRole);
+ } catch (ObjectNotFoundException ex) { // non-existent role
+ Logger.msg(7, "Activity.pushJobsToAgents() - Activity role '"+agentRole+" not found.");
+ return;
+ }
+
+ if (myRole.hasJobList())
+ new JobPusher(this, 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)
+ {
+ mActiveDate = activeDate;
+ } /**
+ * Sets the startDate.
+ *
+ * @param startDate
+ * The startDate to set
+ */
+ public void setStartDate(GTimeStamp startDate)
+ {
+ mStartDate = startDate;
+ } /**
+ * Returns the type.
+ *
+ * @return String
+ */
+ public String getType()
+ {
+ return mType;
+ } /**
+ * Sets the type.
+ *
+ * @param type
+ * The type to set
+ */
+ public void setType(String type)
+ {
+ 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
new file mode 100644
index 0000000..6a3abe7
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/AdvancementCalculator.java
@@ -0,0 +1,225 @@
+/* Created on 11 mars 2004 */
+package com.c2kernel.lifecycle.instance;
+import java.io.Serializable;
+import java.util.Hashtable;
+
+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
+{
+ private CompositeActivity activity;
+ private Hashtable<Vertex, Serializable> isMarked;
+ private Hashtable<Vertex, Vertex> HasNextMarked;
+ public Hashtable<String, Vertex> hasprevActive;
+ private long mCurrentNbActExp = 0;
+ private long mMaximuNbActexp = 0;
+ private long mNbActpassed = 0;
+ private long mNbActpassedWithCurrent = 0;
+ private long mNbActLeftWithCurrent = 0;
+ private long mNbActLeftWithoutCurrent = 0;
+ private boolean mIsbranchActive = false;
+ private boolean mIsbranchFinished = true;
+ private boolean mHasPrevActive = false;
+ public AdvancementCalculator()
+ {
+ isMarked = new Hashtable<Vertex, Serializable>();
+ HasNextMarked = new Hashtable<Vertex, Vertex>();
+ hasprevActive = new Hashtable<String, Vertex>();
+ }
+ public void calculate(CompositeActivity act)
+ {
+// Logger.debug(0, act.getName()+" >>>>>>>>>");
+ if (act instanceof Workflow)
+ {
+ calculate((CompositeActivity) act.search("workflow/domain"));
+ return;
+ }
+ activity = act;
+ Vertex v = activity.getChildGraphModel().getStartVertex();
+ check(v, this);
+ isMarked = new Hashtable<Vertex, Serializable>();
+ calc(v, this);
+// Logger.debug(0, act.getName()+" <<<<<<<<<");
+ }
+ private void check(Vertex v, AdvancementCalculator current)
+ {
+ current.isMarked.put(v, "");
+ Vertex[] nexts = current.activity.getChildGraphModel().getOutVertices(v);
+ for (Vertex next : nexts)
+ if (current.isMarked.get(next) != null)
+ current.HasNextMarked.put(v, next);
+ else
+ check(next, current);
+ int j=0;
+ for (Vertex next : nexts)
+ if (current.HasNextMarked.get(next) != null)
+ j++;
+ if (j != 0 && j==nexts.length) current.HasNextMarked.put(v, nexts[0]);
+ }
+ private void calc(Vertex v, AdvancementCalculator current)
+ {
+ if (current.isMarked.get(v) != null && !(v instanceof Join))
+ return;
+ if (v instanceof Activity)
+ {
+ current.isMarked.put(v, current);
+ Activity act = (Activity) v;
+ if (v instanceof CompositeActivity)
+ {
+ CompositeActivity cact = (CompositeActivity) v;
+ AdvancementCalculator adv = new AdvancementCalculator();
+ adv.isMarked = current.isMarked;
+ adv.HasNextMarked = current.HasNextMarked;
+ adv.calculate(cact);
+ current.mCurrentNbActExp += adv.mCurrentNbActExp;
+ current.mMaximuNbActexp += adv.mMaximuNbActexp;
+ current.mNbActpassed += adv.mNbActpassed;
+ current.mNbActpassedWithCurrent += adv.mNbActpassedWithCurrent;
+ current.mIsbranchActive = current.mIsbranchActive || adv.mIsbranchActive||act.getActive();
+ current.mNbActLeftWithCurrent += adv.mNbActLeftWithCurrent;
+ current.mNbActLeftWithoutCurrent += adv.mNbActLeftWithoutCurrent;
+ current.mHasPrevActive = adv.mHasPrevActive||act.getActive();
+ if (adv.hasprevActive.size()!=0) current.mHasPrevActive=true;
+ }
+ else
+ {
+ current.mCurrentNbActExp += 1;
+ current.mMaximuNbActexp += 1;
+ if (act.getCurrentState() == States.FINISHED)
+ {
+ current.mNbActpassed += 1;
+ current.mNbActpassedWithCurrent += 1;
+ }
+ else if (act.getActive()&&act.getState()<States.REPEATSTATESTART)
+ {
+ current.mIsbranchActive = true;
+ current.mIsbranchFinished = false;
+ current.mHasPrevActive = true;
+// Logger.debug(0, "set HasprevActive to true " + act.getName());
+ current.mNbActpassedWithCurrent += 1;
+ current.mNbActLeftWithCurrent += 1;
+ }
+ else
+ {
+ current.mIsbranchFinished = false;
+ current.mNbActLeftWithCurrent += 1;
+ current.mNbActLeftWithoutCurrent += 1;
+ }
+ }
+ }
+ Vertex[] nexts = current.activity.getChildGraphModel().getOutVertices(v);
+ if (v instanceof Split)
+ {
+ current.isMarked.put(v, current);
+ AdvancementCalculator[] advs = new AdvancementCalculator[nexts.length];
+ for (int i = 0; i < nexts.length; i++)
+ {
+ advs[i] = new AdvancementCalculator();
+ advs[i].mHasPrevActive = current.mHasPrevActive;
+ advs[i].isMarked = current.isMarked;
+ advs[i].HasNextMarked = current.HasNextMarked;
+ advs[i].activity = current.activity;
+ if ((v instanceof Loop) && (current.HasNextMarked.get(nexts[i]) != null))
+// Logger.debug(0, v.getID() + " " + nexts[i].getID() + " HasNextMarked")
+ ;
+ else
+ calc(nexts[i], advs[i]);
+ }
+ long maximuNbActexp = 0;
+ long currentNbActExp = 0;
+ long NbActpassed = 0;
+ long NbActpassedWithCurrent = 0;
+ long NbActLeftWithCurrent = 0;
+ long NbActLeftWithoutCurrent = 0;
+ boolean hasNobranchFinished = true;
+ boolean hasNoBranchActive = true;
+ for (AdvancementCalculator adv : advs) {
+ if (adv.mIsbranchActive)
+ hasNoBranchActive = false;
+ if (adv.mIsbranchFinished)
+ hasNobranchFinished = false;
+ }
+ for (AdvancementCalculator adv : advs) {
+
+ if (maximuNbActexp < adv.mMaximuNbActexp)
+ maximuNbActexp = adv.mMaximuNbActexp;
+ if (adv.mIsbranchActive || adv.mIsbranchFinished || (hasNoBranchActive && hasNobranchFinished))
+ {
+ if (NbActpassed < adv.mNbActpassed)
+ NbActpassed = adv.mNbActpassed;
+ if (NbActpassedWithCurrent < adv.mNbActpassedWithCurrent)
+ NbActpassedWithCurrent = adv.mNbActpassedWithCurrent;
+ if (NbActLeftWithCurrent < adv.mNbActLeftWithCurrent)
+ NbActLeftWithCurrent = adv.mNbActLeftWithCurrent;
+ if (NbActLeftWithoutCurrent < adv.mNbActLeftWithoutCurrent)
+ NbActLeftWithoutCurrent += adv.mNbActLeftWithoutCurrent;
+ if (currentNbActExp < adv.mCurrentNbActExp)
+ currentNbActExp = adv.mCurrentNbActExp;
+ }
+ }
+ current.mCurrentNbActExp += currentNbActExp;
+ current.mNbActpassedWithCurrent += NbActpassedWithCurrent;
+ current.mMaximuNbActexp += maximuNbActexp;
+ current.mNbActpassed += NbActpassed;
+ current.mIsbranchActive = current.mIsbranchActive || !hasNoBranchActive;
+ current.mNbActLeftWithCurrent += NbActLeftWithCurrent;
+ current.mNbActLeftWithoutCurrent += NbActLeftWithoutCurrent;
+ return;
+ }
+ if (v instanceof Join)
+ {
+ AdvancementCalculator adv;
+ if (current.isMarked.get(v) == null)
+ {
+ adv = new AdvancementCalculator();
+ adv.isMarked = current.isMarked;
+ adv.HasNextMarked = current.HasNextMarked;
+ adv.activity = current.activity;
+ adv.mHasPrevActive = current.mHasPrevActive;
+ current.isMarked.put(v, adv);
+ if (nexts.length == 1)
+ calc(nexts[0], adv);
+ }
+ else
+ adv = (AdvancementCalculator) current.isMarked.get(v);
+ current.mCurrentNbActExp += adv.mCurrentNbActExp;
+ current.mMaximuNbActexp += adv.mMaximuNbActexp;
+ current.mNbActpassed += adv.mNbActpassed;
+ current.mNbActpassedWithCurrent += adv.mNbActpassedWithCurrent;
+ current.mIsbranchActive = current.mIsbranchActive || (current.mMaximuNbActexp == 0 && adv.mIsbranchActive);
+ if (current.mHasPrevActive)
+ hasprevActive.put(String.valueOf(v.getID()), v);
+ current.mNbActLeftWithCurrent += adv.mNbActLeftWithCurrent;
+ current.mNbActLeftWithoutCurrent += adv.mNbActLeftWithoutCurrent;
+ return;
+ }
+ if (nexts.length != 0)
+ calc(nexts[0], current);
+ }
+ public long getLongestWayInAct()
+ {
+ return mMaximuNbActexp;
+ }
+ public long getCurrentLongestWayInAct()
+ {
+ return mCurrentNbActExp;
+ }
+ public long getNbActLeftWithActive()
+ {
+ return mNbActLeftWithCurrent;
+ }
+ public long getNbActLeftWithoutActive()
+ {
+ return mNbActLeftWithoutCurrent;
+ }
+ public long getNbActPassedWithoutActive()
+ {
+ return mNbActpassed;
+ }
+ public long getNbActPassedWithActive()
+ {
+ return mNbActpassedWithCurrent;
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java b/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java
new file mode 100644
index 0000000..63b5640
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java
@@ -0,0 +1,27 @@
+package com.c2kernel.lifecycle.instance;
+import com.c2kernel.graph.model.Vertex;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.scripting.ScriptingEngineException;
+/**
+ * @version $Revision: 1.16 $ $Date: 2005/05/10 15:14:54 $
+ * @author $Author: abranson $
+ */
+public class AndSplit extends Split
+{
+ /**
+ * @see java.lang.Object#Object()
+ */
+ public AndSplit()
+ {
+ super();
+ }
+ @Override
+ public void runNext(AgentPath agent) throws ScriptingEngineException
+ {
+ AdvancementCalculator adv = new AdvancementCalculator();
+ adv.calculate((CompositeActivity) getParent());
+ Vertex[] outVertices = getOutGraphables();
+ for (Vertex outVertice : outVertices)
+ ((WfVertex) outVertice).run(agent);
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java b/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java
new file mode 100644
index 0000000..c080a37
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java
@@ -0,0 +1,458 @@
+package com.c2kernel.lifecycle.instance;
+
+import java.awt.Point;
+import java.util.ArrayList;
+import java.util.Vector;
+
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.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.gui.model.WfVertexOutlineCreator;
+import com.c2kernel.lifecycle.instance.stateMachine.StateMachine;
+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;
+
+/**
+ * @version $Revision: 1.86 $ $Date: 2005/10/05 07:39:37 $
+ * @author $Author: abranson $
+ */
+public class CompositeActivity extends Activity
+{
+ /**
+ * @see java.lang.Object#Object()
+ */
+ /*
+ * --------------------------------------------
+ * ----------------CONSTRUCTOR-----------------
+ * --------------------------------------------
+ */
+ public CompositeActivity()
+ {
+ super();
+ setChildrenGraphModel(new GraphModel(new WfVertexOutlineCreator()));
+ setIsComposite(true);
+ }
+
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#verify()
+ */
+ /*
+ * -------------------------------------------- --------------Other
+ * Functions--------------- --------------------------------------------
+ */
+ /** launch the verification of the subprocess() */
+ @Override
+ public boolean verify()
+ {
+ boolean err = super.verify();
+ GraphableVertex[] vChildren = getChildren();
+ for (int i = 0; i < vChildren.length; i++)
+ {
+ if (!((WfVertex) vChildren[i]).verify())
+ {
+ mErrors.add("error in children");
+ return false;
+ }
+ }
+ return err;
+ }
+
+ /**
+ * Method initChild.
+ *
+ * @param act
+ * @param first
+ * @param point
+ */
+ /**
+ * Create an initialize a Activity attached to the current activity
+ *
+ * @param first :
+ * if true, the activity Waiting will be one of the first
+ * launched by the parent activity
+ */
+ public void initChild(Activity act, boolean first, Point point)
+ {
+ this.addChild(act, new GraphPoint(point.x, point.y));
+ if (first)
+ {
+ getChildrenGraphModel().setStartVertexId(act.getID());
+ Logger.msg(5, "com.c2kernel.lifecycle.CompositeActivity :: " + getID() + " is first");
+ }
+ }
+
+ /**
+ * Method newChild.
+ *
+ * @param Name
+ * @param Type
+ * @param point
+ * @return WfVertex
+ */
+ public WfVertex newExistingChild(Activity child, String Name, Point point)
+ {
+ child.setName(Name);
+ addChild(child, new GraphPoint(point.x, point.y));
+ return child;
+ }
+
+ /**
+ * Method newChild.
+ *
+ * @param Name
+ * @param Type
+ * @param point
+ * @return WfVertex
+ */
+ public WfVertex newChild(String Name, String Type, Point point)
+ {
+ WfVertex v = newChild(Type, point);
+ v.setName(Name);
+ return v;
+ }
+
+ /**
+ * Method newChild.
+ *
+ * @param vertexTypeId
+ * @param point
+ * @return WfVertex
+ */
+ public WfVertex newChild(String vertexTypeId, Point point)
+ {
+ WfVertex wfVertex = null;
+ if (vertexTypeId.equals("Atomic"))
+ {
+ wfVertex = newAtomChild("False id", false, point);
+ } else if (vertexTypeId.equals("Composite"))
+ {
+ wfVertex = newCompChild("False id", false, point);
+ } else if (vertexTypeId.endsWith("Split"))
+ {
+ if (vertexTypeId.startsWith("Or"))
+ {
+ wfVertex = newSplitChild("Or", point);
+ } else if (vertexTypeId.startsWith("XOr"))
+ {
+ wfVertex = newSplitChild("XOr", point);
+ } else if (vertexTypeId.startsWith("Loop"))
+ {
+ wfVertex = newSplitChild("Loop", point);
+ } else
+ {
+ wfVertex = newSplitChild("And", point);
+ }
+ } else if (vertexTypeId.equals("Join"))
+ {
+ wfVertex = newJoinChild(point);
+ } else if (vertexTypeId.equals("Route"))
+ {
+ wfVertex = newRouteChild(point);
+ }
+ return wfVertex;
+ }
+
+ /**
+ * Method newCompChild.
+ *
+ * @param id
+ * @param first
+ * @param point
+ * @return CompositeActivity Create an initialize a composite Activity
+ * attached to the current activity
+ */
+ public CompositeActivity newCompChild(String id, boolean first, Point point)
+ {
+ CompositeActivity act = new CompositeActivity();
+ initChild(act, first, point);
+ act.setName(id);
+ return act;
+ }
+
+ /**
+ * Method newAtomChild.
+ *
+ * @param id
+ * @param first
+ * @param point
+ * @return Activity Create an initialize an Atomic Activity attached to the
+ * current activity
+ *
+ */
+ public Activity newAtomChild(String id, boolean first, Point point)
+ {
+ Activity act = new Activity();
+ initChild(act, first, point);
+ act.setName(id);
+ return act;
+ }
+
+ /**
+ * Method newSplitChild.
+ *
+ * @param Type
+ * @param point
+ * @return Split
+ */
+ public Split newSplitChild(String Type, Point point)
+ {
+ Split split;
+ if (Type.equals("Or"))
+ {
+ split = new OrSplit();
+ } else if (Type.equals("XOr"))
+ {
+ split = new XOrSplit();
+ } else if (Type.equals("Loop"))
+ {
+ split = new Loop();
+ } else
+ {
+ split = new AndSplit();
+ }
+ addChild(split, new GraphPoint(point.x, point.y));
+ return split;
+ }
+
+ /**
+ * Method newJoinChild.
+ *
+ * @param point
+ * @return Join
+ */
+ public Join newJoinChild(Point point)
+ {
+ Join join = new Join();
+ join.getProperties().put("Type", "Join");
+ addChild(join, new GraphPoint(point.x, point.y));
+ return join;
+ }
+
+ public Join newRouteChild(Point point)
+ {
+ Join join = new Join();
+ join.getProperties().put("Type", "Route");
+ addChild(join, new GraphPoint(point.x, point.y));
+ return join;
+ }
+
+ /**
+ * Method search.
+ *
+ * @param ids
+ * @return WfVertex
+ */
+ WfVertex search(int ids)
+ {
+ for (int i = 0; i < getChildren().length; i++)
+ {
+ WfVertex ver = (WfVertex) getChildren()[i];
+ if (ver instanceof Split)
+ {
+ if (ver.getID() == ids)
+ {
+ return ver;
+ }
+ }
+ if (ver instanceof Join)
+ {
+ if (ver.getID() == ids)
+ {
+ return ver;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#run()
+ */
+ @Override
+ public void run(AgentPath agent) throws ScriptingEngineException
+ {
+ super.run(agent);
+ if (getChildrenGraphModel().getStartVertex() != null && getMachine().getCurrentState() != States.FINISHED && ((Boolean) getProperties().get(StateMachine.AUTOSTART)).booleanValue())
+ {
+ WfVertex first = (WfVertex) getChildrenGraphModel().getStartVertex();
+ first.run(agent);
+ }
+ }
+
+ @Override
+ public void runNext(AgentPath agent) throws ScriptingEngineException
+ {
+ if (getMachine().state != States.FINISHED)
+ getMachine().traverse(Transitions.COMPLETE);
+ super.runNext(agent);
+ }
+
+ /**
+ * @see com.c2kernel.lifecycle.instance.Activity#query(com.c2kernel.common.AgentInfo,
+ * java.lang.String, boolean)
+ */
+ @Override
+ public Activity[] query(AgentPath agent, int stateID, boolean filter)
+ {
+ Vector<Activity[]> steps = new Vector<Activity[]>();
+ Activity[] returnArray = null;
+ for (int i = 0; i < getChildren().length; i++)
+ {
+ if (getChildren()[i] instanceof Activity)
+ steps.addElement(((Activity) getChildren()[i]).query(agent, stateID, filter));
+ }
+ int j = 0;
+ for (int i = 0; i < steps.size(); i++)
+ j += steps.elementAt(i).length;
+ Activity[] tmp = super.query(agent, stateID, filter);
+ if (tmp.length == 1)
+ {
+ returnArray = new Activity[j + 1];
+ returnArray[j] = tmp[0];
+ } else
+ returnArray = new Activity[j];
+ j = 0;
+ for (int i = 0; i < steps.size(); i++)
+ {
+ Activity[] stepArray = steps.elementAt(i);
+ for (Activity element : stepArray)
+ returnArray[j++] = element;
+ }
+ return returnArray;
+ }
+
+ /**
+ * @see com.c2kernel.lifecycle.instance.Activity#calculateJobs()
+ */
+ @Override
+ public ArrayList<Job> calculateJobs(AgentPath agent, boolean recurse)
+ {
+ ArrayList<Job> jobs = new ArrayList<Job>();
+ boolean childActive = false;
+ if (recurse)
+ for (int i = 0; i < getChildren().length; i++)
+ if (getChildren()[i] instanceof Activity)
+ {
+ Activity child = (Activity) getChildren()[i];
+ jobs.addAll(child.calculateJobs(agent, recurse));
+ childActive |= child.active;
+ }
+ if (!childActive)
+ jobs.addAll(super.calculateJobs(agent, recurse));
+ return jobs;
+ }
+
+ @Override
+ public ArrayList<Job> calculateAllJobs(AgentPath agent, boolean recurse)
+ {
+ ArrayList<Job> jobs = new ArrayList<Job>();
+ if (recurse)
+ for (int i = 0; i < getChildren().length; i++)
+ if (getChildren()[i] instanceof Activity)
+ {
+ Activity child = (Activity) getChildren()[i];
+ jobs.addAll(child.calculateAllJobs(agent, recurse));
+ }
+ jobs.addAll(super.calculateAllJobs(agent, recurse));
+ return jobs;
+ }
+
+ /**
+ * Method addNext.
+ *
+ * @param origin
+ * @param terminus
+ * @return Next
+ */
+ public Next addNext(WfVertex origin, WfVertex terminus)
+ {
+ return new Next(origin, terminus);
+ }
+
+ /**
+ * Method addNext.
+ *
+ * @param originID
+ * @param terminusID
+ * @return Next
+ */
+ public Next addNext(int originID, int terminusID)
+ {
+ Next n = new Next();
+ n.setParent(this);
+ getChildrenGraphModel().addEdgeAndCreateId(n, originID, terminusID);
+ return n;
+ }
+
+ /**
+ * Method hasGoodNumberOfActivity.
+ *
+ * @return boolean
+ */
+ public boolean hasGoodNumberOfActivity()
+ {
+ int endingAct = 0;
+ for (int i = 0; i < getChildren().length; i++)
+ {
+ WfVertex vertex = (WfVertex) getChildren()[i];
+ if (getChildrenGraphModel().getOutEdges(vertex).length == 0)
+ endingAct++;
+ }
+ if (endingAct > 1)
+ return false;
+ return true;
+ }
+
+ /**
+ * @see com.c2kernel.lifecycle.instance.Activity#getType()
+ */
+ @Override
+ public String getType()
+ {
+ if (getName().equals("domain"))
+ return "domain";
+ return super.getType();
+ }
+
+ /**
+ *
+ */
+ @Override
+ public void reinit(int idLoop)
+ {
+ super.reinit(idLoop);
+ if (getChildrenGraphModel().getStartVertex() != null && getMachine().getCurrentState() != States.FINISHED)
+ ((WfVertex) getChildrenGraphModel().getStartVertex()).reinit(idLoop);
+ }
+
+ @Override
+ public void request(AgentPath agent, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException
+ {
+ 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);
+ }
+ public void refreshJobs()
+ {
+ GraphableVertex[] children = getChildren();
+ for (GraphableVertex element : children)
+ if (element instanceof CompositeActivity)
+ ((CompositeActivity) element).refreshJobs();
+ else if (element instanceof Activity)
+ ((Activity) element).pushJobsToAgents();
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/EventList.java b/src/main/java/com/c2kernel/lifecycle/instance/EventList.java
new file mode 100644
index 0000000..be255fb
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/EventList.java
@@ -0,0 +1,19 @@
+package com.c2kernel.lifecycle.instance;
+
+import java.io.Serializable;
+
+/**
+ * @version $Revision: 1.9 $ $Date: 2005/06/08 19:47:59 $
+ * @author $Author: abranson $
+ */
+public class EventList implements Serializable {
+ private int[] dummy = new int[0];
+ public int transition=-1;
+
+ public int[] getNums() {
+ return dummy;
+ }
+
+ public void setNums(int[] nums) {
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/EventStorage.java b/src/main/java/com/c2kernel/lifecycle/instance/EventStorage.java
new file mode 100644
index 0000000..40cffaf
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/EventStorage.java
@@ -0,0 +1,24 @@
+package com.c2kernel.lifecycle.instance;
+import java.io.Serializable;
+import java.util.Hashtable;
+
+/**
+ * @version $Revision: 1.15 $ $Date: 2005/06/08 19:48:00 $
+ * @author $Author: abranson $
+ */
+public class EventStorage implements Serializable
+{
+ private Hashtable<?, ?> mLists;
+ private EventList[] dummy = new EventList[0];
+ public Integer lastTransitionStored;
+
+ public EventList[] getLists()
+ {
+ return dummy;
+ }
+
+ public void setLists(EventList[] lists)
+ {
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/JobPusher.java b/src/main/java/com/c2kernel/lifecycle/instance/JobPusher.java
new file mode 100644
index 0000000..5b8be63
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/JobPusher.java
@@ -0,0 +1,70 @@
+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.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
+
+final class JobPusher extends Thread {
+ private final Activity activity;
+ private final RolePath myRole;
+
+ JobPusher(Activity activity, RolePath role) {
+ this.activity = activity;
+ this.myRole = role;
+ }
+
+ @Override
+ public void run()
+ {
+ Thread.currentThread().setName("Agent job pusher for "+activity.getName()+" to role "+myRole);
+ for (Enumeration<AgentPath> e = myRole.getChildren(); e.hasMoreElements();)
+ {
+ AgentPath nextAgent = e.nextElement();
+ Logger.msg(7, "Activity.pushJobsToAgents() - Calculating jobs for " + nextAgent.getAgentName());
+ try
+ {
+ // get joblist for user
+ JobArrayList jobList = new JobArrayList(this.activity.calculateJobs(nextAgent, false));
+ // only transmit start, complete and resume jobs
+ for (Iterator<Job> element = jobList.list.iterator(); element.hasNext();)
+ {
+ Job thisJob = element.next();
+ if (thisJob.getPossibleTransition() != Transitions.START
+ && thisJob.getPossibleTransition() != Transitions.COMPLETE
+ && thisJob.getPossibleTransition() != Transitions.RESUME
+ && thisJob.getPossibleTransition() != Transitions.SUSPEND
+ && thisJob.getPossibleTransition() != Transitions.REASSIGN)
+ element.remove();
+ }
+ Logger.msg(7, "Activity.pushJobsToAgents() - User will receive " + jobList.list.size() + " jobs");
+ String stringJobs = CastorXMLUtility.marshall(jobList);
+ // push it to the agent
+ org.omg.CORBA.Object agentIOR = nextAgent.getIOR();
+ Agent thisAgent = AgentHelper.narrow(agentIOR);
+ Logger.debug("Calling agent "+thisAgent.getSystemKey()+" from "+activity.getPath());
+ thisAgent.refreshJobList(this.activity.getItemEntityPath().getSysKey(), activity.getPath(), stringJobs);
+ }
+ catch (Exception ex)
+ {
+ Logger.error(
+ "Agent "
+ + nextAgent.getAgentName()
+ + " of role "
+ + myRole
+ + " could not be found to be informed of a change in "
+ + this.activity.getItemEntityPath().getSysKey());
+ Logger.error(ex);
+ }
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Join.java b/src/main/java/com/c2kernel/lifecycle/instance/Join.java
new file mode 100644
index 0000000..3a4fd7d
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/Join.java
@@ -0,0 +1,216 @@
+package com.c2kernel.lifecycle.instance;
+import java.util.Vector;
+
+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 $
+ */
+public class Join extends WfVertex
+{
+ public Vector<String> mErrors;
+ /**
+ * @see java.lang.Object#Object()
+ */
+ public Join()
+ {
+ super();
+ mErrors = new Vector<String>(0, 1);
+ }
+ private boolean loopTested;
+ public int counter = 0;
+ private String mItemSystemKey = "";
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#runNext()
+ */
+ @Override
+ public void runNext(AgentPath agent) throws ScriptingEngineException
+ {
+ AdvancementCalculator adv = new AdvancementCalculator();
+ adv.calculate((CompositeActivity) getParent());
+ if (adv.hasprevActive.get(String.valueOf(getID())) == null)
+ {
+ Vertex[] outVertices = getOutGraphables();
+ if (outVertices.length > 0)
+ {
+ WfVertex nextAct = (WfVertex) outVertices[0];
+ nextAct.run(agent);
+ }
+ else
+ super.runNext(agent);
+ }
+ }
+ /**
+ * Method addNext.
+ *
+ * @param idNext
+ */
+ public void addNext(String idNext)
+ {
+ new Next(this, (WfVertex) getParent().search(idNext));
+ }
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#reinit(int)
+ */
+ @Override
+ public void reinit(int idLoop)
+ {
+ Vertex[] outVertices = getOutGraphables();
+ if (outVertices.length == 1)
+ {
+ WfVertex nextAct = (WfVertex) outVertices[0];
+ 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()
+ {
+ mErrors.removeAllElements();
+ int nbOutEdges = getOutEdges().length;
+ int nbInEdges = getInEdges().length;
+ String type = (String) getProperties().get("Type");
+ if (nbInEdges < 1)
+ {
+ mErrors.add("not enough previous");
+ return false;
+ }
+ if (type != null && type.equals("Route"))
+ {
+ if (nbInEdges > 1)
+ {
+ mErrors.add("Bad nb of previous");
+ return false;
+ }
+ }
+ if (nbOutEdges > 1)
+ {
+ mErrors.add("too many next");
+ return false;
+ }
+ if (nbOutEdges == 0)
+ {
+ if (!((CompositeActivity) getParent()).hasGoodNumberOfActivity())
+ {
+ mErrors.add("too many endpoints");
+ return false;
+ }
+ }
+ Vertex[] outV = getOutGraphables();
+ Vertex[] anteVertices = GraphTraversal.getTraversal(getParent().getChildrenGraphModel(), this, GraphTraversal.kUp, false);
+ boolean loop = false;
+ boolean errInLoop = false;
+ for (int i = 0; i < outV.length; i++)
+ {
+ for (int j = 0; j < anteVertices.length; j++)
+ if (!loop && outV[i].getID() == anteVertices[j].getID())
+ {
+ if (outV[i] instanceof Loop)
+ {
+ loop = true;
+ j = anteVertices.length;
+ i = outV.length;
+ }
+ else
+ {
+ errInLoop = true;
+ }
+ }
+ }
+ if (errInLoop && loop)
+ {
+ mErrors.add("Problem in Loop");
+ return false;
+ }
+ return true;
+ }
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#getErrors()
+ */
+ @Override
+ public String getErrors()
+ {
+ if (mErrors.size() == 0)
+ return "No error";
+ else
+ return mErrors.elementAt(0);
+ }
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#run()
+ */
+ @Override
+ public void run(AgentPath agent) throws ScriptingEngineException
+ {
+ runNext(agent);
+ }
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#addNext(com.c2kernel.lifecycle.instance.WfVertex)
+ */
+ @Override
+ public Next addNext(WfVertex vertex)
+ {
+ return new Next(this, vertex);
+ }
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#loop()
+ */
+ @Override
+ public boolean loop()
+ {
+ boolean loop2 = false;
+ if (!loopTested)
+ {
+ loopTested = true;
+ if (getOutGraphables().length != 0)
+ loop2 = ((WfVertex) getOutGraphables()[0]).loop();
+ }
+ else
+ loop2 = true;
+ loopTested = false;
+ return loop2;
+ }
+ @Override
+ public void runfirst(AgentPath agent) throws ScriptingEngineException
+ {
+ runNext(agent);
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.c2kernel.graph.model.Vertex#isJoin()
+ */
+ @Override
+ public boolean isJoin()
+ {
+ return true;
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Loop.java b/src/main/java/com/c2kernel/lifecycle/instance/Loop.java
new file mode 100644
index 0000000..8228ba9
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/Loop.java
@@ -0,0 +1,107 @@
+package com.c2kernel.lifecycle.instance;
+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 $
+ * @author $Author: abranson $
+ */
+public class Loop extends XOrSplit
+{
+ /**
+ * @see java.lang.Object#Object()
+ */
+ public Loop()
+ {
+ super();
+ }
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#loop()
+ */
+ @Override
+ public boolean loop()
+ {
+ return true;
+ }
+ @Override
+ public void followNext(Next activeNext, AgentPath agent) throws ScriptingEngineException
+ {
+ WfVertex v = activeNext.getTerminusVertex();
+ if (!isInPrev(v))
+ v.run(agent);
+ else
+ {
+ v.reinit(getID());
+ v.run(agent);
+ }
+ }
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#reinit(int)
+ */
+ @Override
+ public void reinit(int idLoop)
+ {
+ Logger.msg(8, "Loop.reinit");
+ if (idLoop == getID())
+ return;
+ else
+ {
+ Vertex[] outVertices = getOutGraphables();
+ for (int j = 0; j < outVertices.length; j++)
+ {
+ if (!isInPrev(outVertices[j]))
+ ((WfVertex) outVertices[j]).reinit(idLoop);
+ }
+ }
+ }
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#verify()
+ */
+ @Override
+ public boolean verify()
+ {
+ boolean err = super.verify();
+ Vertex[] nexts = getOutGraphables();
+ Vertex[] anteVertices = GraphTraversal.getTraversal(getParent().getChildrenGraphModel(), this, GraphTraversal.kUp, false);
+ int k = 0;
+ int l = 0;
+ Vertex[] brothers = getParent().getChildren();
+ for (Vertex brother : brothers)
+ if (brother instanceof Loop)
+ l++;
+ for (Vertex next : nexts) {
+ for (Vertex anteVertice : anteVertices)
+ if (next.getID() == anteVertice.getID())
+ k++;
+ }
+ if (k != 1 && !(l > 1))
+ {
+ mErrors.add("bad number of pointing back nexts");
+ return false;
+ }
+ // if (nexts.length>2) {
+ // mErrors.add("you must only have 2 nexts");
+ // return false;
+ // }
+ return err;
+ }
+ private boolean isInPrev(Vertex vertex)
+ {
+ int id = vertex.getID();
+ Vertex[] anteVertices = GraphTraversal.getTraversal(getParent().getChildrenGraphModel(), this, GraphTraversal.kUp, false);
+ for (Vertex anteVertice : anteVertices) {
+ if (anteVertice.getID() == id)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ @Override
+ public boolean isLoop()
+ {
+ return true;
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Next.java b/src/main/java/com/c2kernel/lifecycle/instance/Next.java
new file mode 100644
index 0000000..4df775c
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/Next.java
@@ -0,0 +1,83 @@
+package com.c2kernel.lifecycle.instance;
+
+import com.c2kernel.graph.model.GraphPoint;
+import com.c2kernel.graph.model.GraphableEdge;
+
+/**
+ * @version $Revision: 1.58 $ $Date: 2005/05/10 15:14:54 $
+ * @author $Author: abranson $
+ */
+/** this class represents the link between 2 successive activities */
+public class Next extends GraphableEdge
+{
+ /**
+ * @see java.lang.Object#Object()
+ */
+ public Next()
+ {
+ super();
+ }
+
+ /**
+ * Method Next.
+ * @param pre
+ * @param nex
+ */
+ /** create and initialize a link between an Activities */
+ public Next(WfVertex pre, WfVertex nex)
+ {
+ super(pre, nex);
+ getProperties().put("Alias","");
+ getProperties().put("Type","Straight");
+ }
+
+ /**
+ * Method verify.
+ * @return boolean
+ */
+ public boolean verify()
+ {
+ return true;
+ }
+ public WfVertex getTerminusVertex()
+ {
+ return (WfVertex)((CompositeActivity)getParent()).getWf().search(getParent().getPath()+"/"+this.getTerminusVertexId());
+ }
+ @Override
+ public boolean containsPoint(GraphPoint p)
+ {
+ GraphPoint originPoint = getOriginPoint();
+ GraphPoint terminusPoint = getTerminusPoint();
+ GraphPoint midPoint = new GraphPoint();
+
+ if (("Broken +".equals(getProperties().get("Type"))))
+ {
+ midPoint.x = (originPoint.x + terminusPoint.x) / 2;
+ midPoint.y = (originPoint.y + terminusPoint.y) / 2;
+ }
+ else if (("Broken -".equals(getProperties().get("Type"))))
+ {
+ boolean arrowOnY = !(originPoint.y - terminusPoint.y < 60 && originPoint.y - terminusPoint.y > -60);
+ midPoint.x = arrowOnY ? terminusPoint.x : (originPoint.x + terminusPoint.x) / 2;
+ midPoint.y = arrowOnY ? (originPoint.y + terminusPoint.y) / 2 : originPoint.y;
+ }
+ else if (("Broken |".equals(getProperties().get("Type"))))
+ {
+ boolean arrowOnY = !(originPoint.y - terminusPoint.y < 60 && originPoint.y - terminusPoint.y > -60);
+ midPoint.x = arrowOnY ? originPoint.x : (originPoint.x + terminusPoint.x) / 2;
+ midPoint.y = arrowOnY ? (originPoint.y + terminusPoint.y) / 2 : terminusPoint.y;
+ }
+ else
+ {
+ midPoint.x = originPoint.x + (terminusPoint.x - originPoint.x) / 2;
+ midPoint.y = originPoint.y + (terminusPoint.y - originPoint.y) / 2;
+ }
+
+ int minX = midPoint.x - 10;
+ int minY = midPoint.y - 10;
+ int maxX = midPoint.x + 10;
+ int maxY = midPoint.y + 10;
+
+ return (p.x >= minX) && (p.x <= maxX) && (p.y >= minY) && (p.y <= maxY);
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java b/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java
new file mode 100644
index 0000000..aea34b2
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java
@@ -0,0 +1,62 @@
+package com.c2kernel.lifecycle.instance;
+import java.util.StringTokenizer;
+
+import com.c2kernel.graph.model.DirectedEdge;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.scripting.ScriptingEngineException;
+import com.c2kernel.utils.Logger;
+/**
+ * @version $Revision: 1.22 $ $Date: 2005/05/10 15:14:54 $
+ * @author $Author: abranson $
+ */
+public class OrSplit extends Split
+{
+ /**
+ * @see java.lang.Object#Object()
+ */
+ public OrSplit()
+ {
+ super();
+ }
+ @Override
+ public void runNext(AgentPath agent) throws ScriptingEngineException
+ {
+ String nexts =
+ this
+ .evaluateScript((String) getProperties().get("RoutingScriptName"), (String) getProperties().get("RoutingScriptVersion"))
+ .toString();
+ StringTokenizer tok = new StringTokenizer(nexts, ",");
+ Logger.msg(7, tok.countTokens() + " nexts to activate:" + nexts);
+ int active = 0;
+ try
+ {
+ DirectedEdge[] outEdges = getOutEdges();
+ AdvancementCalculator adv = new AdvancementCalculator();
+ adv.calculate((CompositeActivity)getParent());
+ while (tok.hasMoreTokens())
+ {
+ String thisNext = tok.nextToken();
+ Logger.msg(7, "Finding next " + thisNext);
+ for (DirectedEdge outEdge : outEdges) {
+ Next nextEdge = (Next) outEdge;
+ if (thisNext != null && thisNext.equals(nextEdge.getProperties().get("Alias")))
+ {
+ WfVertex term = nextEdge.getTerminusVertex();
+ term.run(agent);
+ Logger.msg(7, "Running " + nextEdge.getProperties().get("Alias"));
+ active++;
+ }
+ }
+ }
+ // if no active nexts throw exception
+ }
+ catch (Exception e)
+ {
+ Logger.error(e);
+ }
+ if (active == 0)
+ throw new ScriptingEngineException("No nexts were activated!");
+ }
+
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/ParserWF.java b/src/main/java/com/c2kernel/lifecycle/instance/ParserWF.java
new file mode 100644
index 0000000..02a0c6d
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/ParserWF.java
@@ -0,0 +1,356 @@
+package com.c2kernel.lifecycle.instance;
+
+import java.awt.Point;
+import java.io.IOException;
+import java.util.Vector;
+
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.utils.CastorHashMap;
+import com.c2kernel.utils.Logger;
+
+/**
+ * @version $Revision: 1.26 $ $Date: 2006/03/03 13:52:21 $
+ * @author $Author: abranson $
+ */
+public class ParserWF
+{
+ static Vector<String[]> nexts;
+ static String file = "";
+ static int i;
+ static CastorHashMap mInfo = new CastorHashMap();
+
+ /**
+ * Method addStep.
+ * @param act
+ * @param xmlfile
+ * @return CompositeActivity
+ * @throws IOException
+ */
+ /**
+ * @associates <{com.c2kernel.lifecycle.instance.Workflow}>
+ * @label creates
+ */
+ public static CompositeActivity addStep(CompositeActivity act, String xmlfile, AgentPath agent) throws IOException
+ {
+ nexts = new Vector<String[]>(1, 1);
+ i = 0;
+ file = xmlfile;
+ while (i < file.length() - 5)
+ {
+ if (file.substring(i, i + 5).equals("<STEP"))
+ {
+ readStep(act);
+ }
+ else
+ {
+ i++;
+ }
+ }
+ boolean flag = false;
+ for (int j = 0; j < nexts.size(); j++)
+ {
+ for (int k = j + 1; k < nexts.size(); k++)
+ {
+ if (nexts.elementAt(j)[0].equals(nexts.elementAt(k)[0]))
+ {
+ int tmp = act.newSplitChild("And", new Point(0, 0)).getID();
+ ((WfVertex) act.search(nexts.elementAt(k)[0])).addNext(act.search(tmp));
+ ((Split) act.search(tmp)).addNext((WfVertex) act.search(nexts.elementAt(k)[1]));
+ ((Split) act.search(tmp)).addNext((WfVertex) act.search(nexts.elementAt(j)[1]));
+ nexts.removeElementAt(k--);
+ flag = true;
+ }
+ }
+ if (flag)
+ {
+ nexts.removeElementAt(j--);
+ }
+ flag = false;
+ }
+ for (int j = 0; j < nexts.size(); j++)
+ {
+ for (int k = j + 1; k < nexts.size(); k++)
+ {
+ if (nexts.elementAt(j)[1].equals(nexts.elementAt(k)[1]))
+ {
+ int tmp = act.newJoinChild(new Point(0, 0)).getID();
+ ((WfVertex) act.search(nexts.elementAt(j)[0])).addNext(act.search(tmp));
+ ((WfVertex) act.search(nexts.elementAt(k)[0])).addNext(act.search(tmp));
+ ((Join) act.search(tmp)).addNext(nexts.elementAt(j)[1]);
+ nexts.removeElementAt(k--);
+ flag = true;
+ }
+ }
+ if (flag)
+ {
+ nexts.removeElementAt(j--);
+ }
+ flag = false;
+ }
+ for (int j = 0; j < nexts.size(); j++)
+ {
+ Logger.msg(
+ 7,
+ "try to add next " + nexts.elementAt(j)[1] + " to " + nexts.elementAt(j)[0]);
+ ((Activity) act.search(nexts.elementAt(j)[0])).addNext(nexts.elementAt(j)[1]);
+ }
+ if (act instanceof Workflow)
+ try
+ {
+ act.run(agent);
+ }
+ catch (Exception ex)
+ {
+ Logger.error(ex);
+ }
+ return act;
+ }
+
+ private static void readStep(CompositeActivity parent)
+ {
+ Activity act = null;
+ String[] step = new String[15];
+ for (int j = 0; j < 15; j++)
+ {
+ step[j] = "";
+ }
+ i += 5;
+ while (!file.substring(i, i + 7).equals("</STEP>"))
+ {
+ if (file.substring(i, i + 5).equals("<STEP"))
+ {
+ Logger.msg(7, "<STEP");
+ if (!step[14].equals("done"))
+ {
+ act = parent.newCompChild(step[0], step[12].startsWith("true"), new Point(0, 0));
+ }
+ readStep((CompositeActivity) act);
+ step[14] = "done";
+ }
+ else if (file.substring(i, i + 3).equals("Id="))
+ {
+ Logger.msg(7, "Id=");
+ i += 4;
+ int j = 0;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[0] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 6).equals("Alias="))
+ {
+ Logger.msg(7, "Alias=");
+ i += 7;
+ int j = 0;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[10] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 9).equals("Resource="))
+ {
+ Logger.msg(7, "Ressource=");
+ i += 10;
+ int j = 0;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[1] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 6).equals("First="))
+ {
+ Logger.msg(7, "First=");
+ i += 7;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[12] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 3).equals("LC="))
+ {
+ Logger.msg(7, "LC=");
+ i += 4;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[2] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 3).equals("WC="))
+ {
+ Logger.msg(7, "WC=");
+ i += 4;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[3] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 6).equals("Posts="))
+ {
+ Logger.msg(7, "Posts=");
+ i += 7;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[4] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 17).equals("Preparation-Time="))
+ {
+ Logger.msg(7, "Preparation-Time=");
+ i += 18;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[5] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 12).equals("Active-Time="))
+ {
+ Logger.msg(7, "Active-Time=");
+ i += 13;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[6] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 13).equals("OP-Startdate="))
+ {
+ Logger.msg(7, "OP-Startdate=");
+ i += 14;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[7] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 11).equals("OP-Enddate="))
+ {
+ Logger.msg(7, "OP-Enddate=");
+ i += 12;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[8] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 13).equals("<DESCRIPTION>"))
+ {
+ Logger.msg(7, "<DESCRIPTION>");
+ i += 13;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '<')
+ {
+ j++;
+ }
+ step[9] = file.substring(i, i + j);
+ i += (j + 14);
+ }
+ else if (file.substring(i, i + 6).equals("<NEXT>"))
+ {
+ Logger.msg(7, "<NEXT>");
+ i += 6;
+ int j = 0;
+ ;
+ String[] tmp = new String[2];
+ while (file.charAt(i + j) != '<')
+ {
+ j++;
+ }
+ tmp[0] = step[0];
+ tmp[0] = parent.getPath() + "/" + tmp[0];
+ tmp[1] = file.substring(i, i + j);
+ tmp[1] = parent.getPath() + "/" + tmp[1];
+ nexts.addElement(tmp);
+ i += (j + 8);
+ Logger.msg(7, "</NEXT>");
+ }
+ else if (file.substring(i, i + 5).equals("Path="))
+ {
+ Logger.msg(7, "Path=");
+ i += 6;
+ int j = 0;
+ ;
+ step[11] = file.substring(i, i + j);
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ i += (j + 1);
+ }
+ else
+ {
+ i++;
+ }
+ }
+ i += 7;
+ if (!step[14].equals("done"))
+ act = parent.newAtomChild(step[0], step[12].startsWith("true"), new Point(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
new file mode 100644
index 0000000..4fe1bfc
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/Split.java
@@ -0,0 +1,225 @@
+package com.c2kernel.lifecycle.instance;
+
+import java.util.Vector;
+
+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 $
+ * @author $Author: abranson $
+ */
+public abstract class Split extends WfVertex
+{
+ public Vector<String> mErrors;
+
+ /**
+ * @see java.lang.Object#Object()
+ */
+ public Split()
+ {
+ mErrors = new Vector<String>(0, 1);
+ getProperties().put("RoutingScriptName", "");
+ getProperties().put("RoutingScriptVersion", "");
+ }
+
+ private boolean loopTested;
+
+ private int mItemSystemKey = -1;
+
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#runNext()
+ */
+ @Override
+ public abstract void runNext(AgentPath agent) throws ScriptingEngineException;
+
+ /**
+ * Method addNext.
+ *
+ * @param idNext
+ */
+ void addNext(String idNext)
+ {
+ new Next(this, (WfVertex) getParent().search(idNext));
+ }
+
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#addNext(com.c2kernel.lifecycle.instance.WfVertex)
+ */
+ @Override
+ public Next addNext(WfVertex vertex)
+ {
+ Next nxt = new Next(this, vertex);
+ int num = getOutGraphables().length;
+ try
+ {
+ num = Integer.parseInt((String) getProperties().get("LastNum"));
+ } catch (Exception e)
+ {
+ }
+ nxt.getProperties().put("Alias", String.valueOf(num));
+ getProperties().put("LastNum", String.valueOf(num + 1));
+ 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)
+ {
+ Vertex[] outVertices = getOutGraphables();
+ for (Vertex outVertice : outVertices)
+ ((WfVertex) outVertice).reinit(idLoop);
+ }
+
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#verify()
+ */
+ @Override
+ public boolean verify()
+ {
+ mErrors.removeAllElements();
+ int nbInEdgres = getParent().getChildrenGraphModel().getInEdges(this).length;
+ if (nbInEdgres == 0 && this.getID() != getParent().getChildrenGraphModel().getStartVertexId())
+ {
+ mErrors.add("not enough previous");
+ return false;
+ }
+ if (nbInEdgres > 1)
+ {
+ mErrors.add("Bad nb of previous");
+ return false;
+ }
+ if (getOutEdges().length <= 1 && !(this instanceof Loop))
+ {
+ mErrors.add("not enough next");
+ return false;
+ }
+ if (!(this instanceof Loop))
+ {
+ Vertex[] outV = getOutGraphables();
+ Vertex[] anteVertices = GraphTraversal.getTraversal(getParent().getChildrenGraphModel(), this, GraphTraversal.kUp, false);
+ boolean loop = false;
+ boolean errInLoop = true;
+ for (int i = 0; i < outV.length; i++)
+ {
+ for (int j = 0; j < anteVertices.length; j++)
+ if (!loop && outV[i].getID() == anteVertices[j].getID())
+ {
+ if (outV[i] instanceof Loop)
+ {
+ loop = true;
+ j = anteVertices.length;
+ i = outV.length;
+ } else
+ {
+ errInLoop = false;
+ }
+ }
+ }
+ if (errInLoop && loop)
+ {
+ mErrors.add("Problem in Loop");
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#getErrors()
+ */
+ @Override
+ public String getErrors()
+ {
+ if (mErrors.size() == 0)
+ return "No error";
+ else
+ return mErrors.elementAt(0);
+ }
+
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#run()
+ */
+ @Override
+ public void run(AgentPath agent) throws ScriptingEngineException
+ {
+ runNext(agent);
+ }
+
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#loop()
+ */
+ @Override
+ public boolean loop()
+ {
+ boolean loop2 = false;
+ if (!loopTested)
+ {
+ loopTested = true;
+ if (getOutGraphables().length != 0)
+ {
+ Vertex[] outVertices = getOutGraphables();
+ for (int i = 0; i < outVertices.length; i++)
+ {
+ WfVertex tmp = (WfVertex) getOutGraphables()[i];
+ loop2 = loop2 || tmp.loop();
+ }
+ }
+ }
+ loopTested = false;
+ return loop2;
+ }
+
+ public String[] nextNames()
+ {
+ Vertex[] vs = getOutGraphables();
+ String[] result = new String[vs.length];
+ for (int i = 0; i < vs.length; i++)
+ result[i] = vs[i].getName();
+ return result;
+ }
+
+ protected boolean isInTable(String test, String[] list)
+ {
+ if (test == null)
+ return false;
+ for (String element : list)
+ if (test.equals(element))
+ return true;
+ return false;
+ }
+
+ @Override
+ public void runfirst(AgentPath agent) throws ScriptingEngineException
+ {
+ runNext(agent);
+ }
+
+} \ 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
new file mode 100644
index 0000000..f6cec33
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/WfVertex.java
@@ -0,0 +1,180 @@
+package com.c2kernel.lifecycle.instance;
+
+
+
+import java.util.HashMap;
+
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.graph.model.GraphableVertex;
+import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
+import com.c2kernel.lifecycle.routingHelpers.ViewpointDataHelper;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.EntityPath;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.scripting.Script;
+import com.c2kernel.scripting.ScriptingEngineException;
+import com.c2kernel.utils.KeyValuePair;
+import com.c2kernel.utils.Logger;
+
+/**
+ * @version $Revision: 1.38 $ $Date: 2005/09/07 13:46:31 $
+ * @author $Author: abranson $
+ */
+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;
+
+ /**
+ * @see java.lang.Object#Object()
+ */
+ public WfVertex()
+ {
+ super();
+ setIsLayoutable(true);
+ setIsComposite(false);
+ }
+
+ /**
+ * Method runNext.
+ */
+ public void runNext(AgentPath agent) throws ScriptingEngineException
+ {
+ try
+ {
+ ((CompositeActivity)getParent()).request(agent, Transitions.COMPLETE, null);
+ }
+ catch (Exception e)
+ {
+ //Logger.error(e);
+ }
+
+ }
+
+ /**
+ * Method reinit.
+ * @param idLoop
+ */
+ public abstract void reinit( int idLoop );
+
+ /**
+ * Method verify.
+ * @return boolean
+ */
+ public abstract boolean verify();
+
+ /**
+ * Method getErrors.
+ * @return String
+ */
+ public abstract String getErrors();
+
+ /**
+ * Method run.
+ */
+ public abstract void run(AgentPath agent) throws ScriptingEngineException;
+
+ /**
+ * Method loop.
+ * @return boolean
+ */
+ public abstract boolean loop();
+
+ /**
+ * Method addNext.
+ * @param vertex
+ */
+ public abstract Next addNext(WfVertex vertex);
+
+ protected Object evaluateScript(String scriptName, String scriptVersion) throws ScriptingEngineException
+ {
+
+ try
+ {
+ EntityPath entity = ((CompositeActivity) getParent()).getWf().getItemEntityPath();
+ Script script = getScript(scriptName, scriptVersion);
+
+ KeyValuePair[] k = getProperties().getKeyValuePairs();
+ HashMap<?, ?> requiredInput = script.getAllInputParams();
+ for (KeyValuePair element : k) {
+ if (requiredInput.containsKey(element.getKey()))
+ {
+ String value = element.getStringValue();
+ Object inputParam = value;
+
+ if (value.startsWith("viewpoint//"))
+ {
+ value = value.substring(11);
+ if (value.startsWith("."))
+ value = entity.getSysKey() + value.substring(1);
+ try {
+ inputParam = ViewpointDataHelper.get(value)[0];
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ throw new InvalidDataException("Could not retrieve data from viewpoint: "+value, "");
+ }
+ }
+ if (value.startsWith("property//"))
+ {
+ value = value.substring(10);
+ try {
+ inputParam = Gateway.getStorage().get(entity.getSysKey(), ClusterStorage.PROPERTY+"/"+value, null);
+ } catch (ObjectNotFoundException ex) {
+ inputParam = null;
+ }
+ }
+ Logger.msg(5, "Split.evaluateScript() - Setting param " + element.getKey() + " to " + inputParam.toString());
+ script.setInputParamValue(element.getKey(), inputParam);
+ }
+ }
+
+ if (requiredInput.containsKey("item")) {
+ script.setInputParamValue("item", Gateway.getProxyManager().getProxy(entity));
+ }
+ if (requiredInput.containsKey("agent")) {
+ AgentPath systemAgent = Gateway.getLDAPLookup().getRoleManager().getAgentPath("system");
+ script.setInputParamValue("agent", Gateway.getProxyManager().getProxy(systemAgent));
+ }
+ Object retVal = script.execute();
+ Logger.msg(2, "Split.evaluateScript() - Script returned "+retVal);
+ if (retVal == null) retVal = "";
+ return retVal;
+ }
+ catch (Exception e)
+ {
+ Logger.msg(1, "Split.evaluateScript() - Error: Script " + scriptName);
+ Logger.error(e);
+ throw new ScriptingEngineException();
+ }
+ }
+
+ private static Script getScript(String name, String version) throws ScriptingEngineException
+ {
+ Script script;
+ try
+ {
+ script = new Script(name, Integer.parseInt(version));
+ }
+ catch (NumberFormatException e)
+ { // version not valid
+ int split = name.indexOf(":");
+ if (split > -1)
+ {
+ script = new Script(name.substring(0, split), name.substring(split + 1));
+ }
+ else
+ throw new ScriptingEngineException("Could not find script " + name + " v" + version);
+ }
+
+ return script;
+ }
+
+
+ public Workflow getWf()
+ {
+ return ((CompositeActivity)getParent()).getWf();
+ }
+}
+
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java
new file mode 100644
index 0000000..1d12ee6
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java
@@ -0,0 +1,208 @@
+package com.c2kernel.lifecycle.instance;
+import java.awt.Point;
+import java.util.ArrayList;
+
+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.C2KLocalObject;
+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;
+import com.c2kernel.utils.Language;
+import com.c2kernel.utils.Logger;
+/**
+ * @version $Revision: 1.64 $ $Date: 2005/09/30 07:09:48 $
+ * @author $Author: abranson $
+ */
+public class Workflow extends CompositeActivity implements C2KLocalObject
+{
+ /** TypeNameAndConstructionInfo[] variables added by Steve */
+ private final TypeNameAndConstructionInfo[] mVertexTypeNameAndConstructionInfo =
+ {
+ new TypeNameAndConstructionInfo(Language.translate("AND Split"), "AndSplit"),
+ new TypeNameAndConstructionInfo(Language.translate("OR Split"), "OrSplit"),
+ new TypeNameAndConstructionInfo(Language.translate("XOR Split"), "XOrSplit"),
+ new TypeNameAndConstructionInfo(Language.translate("Join"), "Join"),
+ new TypeNameAndConstructionInfo(Language.translate("Loop"), "LoopSplit"),
+ new TypeNameAndConstructionInfo(Language.translate("Atomic"), "Atomic"),
+ new TypeNameAndConstructionInfo(Language.translate("Composite"), "Composite")
+ };
+ private final TypeNameAndConstructionInfo[] mEdgeTypeNameAndConstructionInfo =
+ {
+ new TypeNameAndConstructionInfo(Language.translate("Next Edge"), "Next")
+ };
+ /**
+ * @see java.lang.Object#Object()
+ */
+ public Workflow()
+ {
+ getProperties().put("ItemSystemKey", null);
+ }
+
+ public Workflow(CompositeActivity domain) {
+ this();
+ domain.setName("domain");
+ initChild(domain, true, new Point(150, 100));
+ PredefinedStepContainer act = new PredefinedStepContainer();
+ addChild(act, new GraphPoint(300, 100));
+ }
+
+ /**
+ * Method getVertexTypeNameAndConstructionInfo.
+ *
+ * @return TypeNameAndConstructionInfo[]
+ */
+ /** getVertexTypeNameAndConstructionInfo() added by Steve */
+ public TypeNameAndConstructionInfo[] getVertexTypeNameAndConstructionInfo()
+ {
+ return mVertexTypeNameAndConstructionInfo;
+ }
+ /**
+ * Method getEdgeTypeNameAndConstructionInfo.
+ *
+ * @return TypeNameAndConstructionInfo[]
+ */
+ /** getVertexTypeNameAndConstructionInfo() added by Steve */
+ public TypeNameAndConstructionInfo[] getEdgeTypeNameAndConstructionInfo()
+ {
+ return mEdgeTypeNameAndConstructionInfo;
+ }
+ /**
+ * Method requestAction.
+ *
+ * @param agentInfo
+ * @param stepPath
+ * @param transitionID
+ * @param reguestData
+ * @throws ObjectNotFoundException
+ * @throws AccessRightsException
+ * @throws InvalidTransitionException
+ * @throws InvalidDataException
+ */
+ //requestData is xmlstring
+ public void requestAction(AgentPath agent, String stepPath, int transitionID, String requestData)
+ throws ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException
+ {
+ Logger.msg(3, "Action: " + Transitions.getTransitionName(transitionID) + " " + stepPath + " by " + agent.getAgentName());
+ if (search(stepPath) != null)
+ ((Activity) search(stepPath)).request(agent, transitionID, requestData);
+ else
+ throw new ObjectNotFoundException(stepPath + " not found", "");
+ }
+
+ /**
+ * @see com.c2kernel.graph.model.GraphableVertex#getPath()
+ */
+ @Override
+ public String getPath()
+ {
+ return "workflow";
+ }
+ /**
+ * @see com.c2kernel.graph.model.Vertex#getName()
+ */
+ @Override
+ public String getName()
+ {
+ return "workflow";
+ }
+ /**
+ * @see com.c2kernel.lifecycle.instance.Activity#getType()
+ */
+ @Override
+ public String getType()
+ {
+ return "workflow";
+ }
+ /**
+ * @see com.c2kernel.graph.model.Vertex#setName(java.lang.String)
+ */
+ @Override
+ public void setName(String name)
+ {
+ }
+ /**
+ * @see com.c2kernel.lifecycle.instance.WfVertex#verify()
+ */
+ @Override
+ public boolean verify()
+ {
+ for (int i = 0; i < getChildren().length; i++)
+ {
+ if (!((WfVertex) getChildren()[i]).verify())
+ {
+ mErrors.add("error in children");
+ return false;
+ }
+ }
+ return true;
+ }
+ /**
+ * @see com.c2kernel.lifecycle.instance.Activity#getWf()
+ */
+ @Override
+ public Workflow getWf()
+ {
+ return this;
+ }
+ /**
+ * Method initialise.
+ *
+ * @param systemKey
+ */
+ public void initialise(int systemKey, AgentPath agent)
+ {
+ this.getProperties().put("ItemSystemKey", new Integer(systemKey));
+ try
+ {
+ runfirst(agent);
+ }
+ catch (ScriptingEngineException ex)
+ {
+ Logger.error(ex);
+ }
+ }
+ /**
+ * 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
+ */
+ public ArrayList<Job> calculateJobs(AgentPath agent, int type)
+ {
+ ArrayList<Job> jobs = new ArrayList<Job>();
+ if (type != 1)
+ jobs.addAll(((CompositeActivity) search("workflow/domain")).calculateJobs(agent, true));
+ if (type != 0)
+ jobs.addAll(((CompositeActivity) search("workflow/predefined")).calculateJobs(agent, true));
+ return jobs;
+ }
+ /**
+ * @see com.c2kernel.lifecycle.instance.CompositeActivity#hasGoodNumberOfActivity()
+ */
+ @Override
+ public boolean hasGoodNumberOfActivity()
+ {
+ return true;
+ }
+ /**
+ * @see com.c2kernel.entity.C2KLocalObject#getClusterType()
+ */
+ @Override
+ public String getClusterType()
+ {
+ return ClusterStorage.LIFECYCLE;
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java b/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java
new file mode 100644
index 0000000..25baf0b
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java
@@ -0,0 +1,54 @@
+package com.c2kernel.lifecycle.instance;
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import com.c2kernel.graph.model.DirectedEdge;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.scripting.ScriptingEngineException;
+
+/**
+ * @version $Revision: 1.23 $ $Date: 2006/03/03 13:52:21 $
+ * @author $Author: abranson $
+ */
+public class XOrSplit extends Split
+{
+ /**
+ * @see java.lang.Object#Object()
+ */
+ public XOrSplit()
+ {
+ super();
+ }
+
+ @Override
+ public void runNext(AgentPath agent) throws ScriptingEngineException
+ {
+ ArrayList<DirectedEdge> nextsToFollow = new ArrayList<DirectedEdge>();
+ String nexts = this.evaluateScript(
+ (String) getProperties().get("RoutingScriptName"),
+ (String) getProperties().get("RoutingScriptVersion")).toString();
+
+ StringTokenizer tok = new StringTokenizer(nexts,",");
+ String[] nextsTab = new String[tok.countTokens()];
+ for (int i=0;i<nextsTab.length;i++)
+ nextsTab[i] = tok.nextToken();
+
+ DirectedEdge[] outEdges = getOutEdges();
+ for (DirectedEdge outEdge : outEdges) {
+ if (isInTable((String)((Next)outEdge).getProperties().get("Alias"), nextsTab))
+ nextsToFollow.add(outEdge);
+ }
+// Logger.debug(0, getID()+" following "+nexts);
+ if (nextsToFollow.size() != 1)
+ throw new ScriptingEngineException("not good number of active next");
+
+ followNext((Next)nextsToFollow.get(0), agent);
+
+ }
+
+ public void followNext(Next activeNext, AgentPath agent) throws ScriptingEngineException {
+ activeNext.getTerminusVertex().run(agent);
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfEdgeFactory.java b/src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfEdgeFactory.java
new file mode 100644
index 0000000..e96ef37
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfEdgeFactory.java
@@ -0,0 +1,35 @@
+package com.c2kernel.lifecycle.instance.gui.model;
+
+import com.c2kernel.graph.model.DirectedEdge;
+import com.c2kernel.graph.model.EdgeFactory;
+import com.c2kernel.graph.model.GraphModelManager;
+import com.c2kernel.graph.model.TypeNameAndConstructionInfo;
+import com.c2kernel.graph.model.Vertex;
+import com.c2kernel.lifecycle.instance.WfVertex;
+
+public class WfEdgeFactory implements EdgeFactory
+{
+ @Override
+ public void create
+ (
+ GraphModelManager graphModelManager,
+ Vertex origin,
+ Vertex terminus,
+ TypeNameAndConstructionInfo typeNameAndConstructionInfo
+ )
+ {
+ if ( validCreation( graphModelManager, origin, terminus ) )
+ ((WfVertex)origin).addNext((WfVertex)terminus);
+
+ }
+
+ private static boolean validCreation( GraphModelManager graphModelManager, Vertex origin, Vertex terminus )
+ {
+ DirectedEdge[] connectingEdgesAToB = graphModelManager.getModel().getConnectingEdges( origin.getID() , terminus.getID() );
+ DirectedEdge[] connectingEdgesBToA = graphModelManager.getModel().getConnectingEdges( terminus.getID(), origin.getID() );
+
+
+ return ( origin != terminus ) && ( connectingEdgesAToB.length == 0 ) && ( connectingEdgesBToA.length == 0 );
+ }
+}
+
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfGraphPanel.java b/src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfGraphPanel.java
new file mode 100644
index 0000000..16c8e16
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfGraphPanel.java
@@ -0,0 +1,59 @@
+/*Created on 21 nov. 2003 */
+package com.c2kernel.lifecycle.instance.gui.model;
+
+import java.awt.Graphics2D;
+
+import com.c2kernel.graph.model.DirectedEdge;
+import com.c2kernel.graph.model.GraphPoint;
+import com.c2kernel.graph.view.DirectedEdgeRenderer;
+import com.c2kernel.graph.view.GraphPanel;
+import com.c2kernel.graph.view.VertexRenderer;
+import com.c2kernel.lifecycle.instance.Next;
+
+/** @author XSeb74*/
+public class WfGraphPanel extends GraphPanel
+{
+ public WfGraphPanel(DirectedEdgeRenderer d,VertexRenderer v)
+ {
+ super(d,v);
+ }
+ // Draws the highlight of the specified edge
+ @Override
+ protected void drawEdgeHighlight(Graphics2D g2d, DirectedEdge edge)
+ {
+ GraphPoint originPoint = edge.getOriginPoint();
+ GraphPoint terminusPoint = edge.getTerminusPoint();
+ GraphPoint midPoint = new GraphPoint();
+
+ if ("Straight".equals(((Next)edge).getProperties().get("Type")) || ((Next)edge).getProperties().get("Type") == null)
+ {
+ midPoint.x = originPoint.x + (terminusPoint.x - originPoint.x) / 2;
+ midPoint.y = originPoint.y + (terminusPoint.y - originPoint.y) / 2;
+ }
+ else if (("Broken +".equals(((Next)edge).getProperties().get("Type"))))
+ {
+ midPoint.x = (originPoint.x + terminusPoint.x) / 2;
+ midPoint.y = (originPoint.y + terminusPoint.y) / 2;
+ }
+ else if (("Broken -".equals(((Next)edge).getProperties().get("Type"))))
+ {
+ boolean arrowOnY = !(originPoint.y - terminusPoint.y < 60 && originPoint.y - terminusPoint.y > -60);
+ midPoint.x = arrowOnY ? terminusPoint.x : (originPoint.x + terminusPoint.x) / 2;
+ midPoint.y = arrowOnY ? (originPoint.y + terminusPoint.y) / 2 : originPoint.y;
+ }
+ else if (("Broken |".equals(((Next)edge).getProperties().get("Type"))))
+ {
+ boolean arrowOnY = !(originPoint.y - terminusPoint.y < 60 && originPoint.y - terminusPoint.y > -60);
+ midPoint.x = arrowOnY ? originPoint.x : (originPoint.x + terminusPoint.x) / 2;
+ midPoint.y = arrowOnY ? (originPoint.y + terminusPoint.y) / 2 : terminusPoint.y;
+ }
+ int minX = midPoint.x - 10;
+ int minY = midPoint.y - 10;
+ int maxX = midPoint.x + 10;
+ int maxY = midPoint.y + 10;
+ g2d.drawLine(minX, minY, maxX, minY);
+ g2d.drawLine(maxX, minY, maxX, maxY);
+ g2d.drawLine(maxX, maxY, minX, maxY);
+ g2d.drawLine(minX, maxY, minX, minY);
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfVertexFactory.java b/src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfVertexFactory.java
new file mode 100644
index 0000000..39e7ee9
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfVertexFactory.java
@@ -0,0 +1,92 @@
+package com.c2kernel.lifecycle.instance.gui.model;
+import java.awt.Point;
+import java.io.Serializable;
+import java.util.HashMap;
+
+import javax.swing.JOptionPane;
+
+import com.c2kernel.graph.model.GraphModelManager;
+import com.c2kernel.graph.model.TypeNameAndConstructionInfo;
+import com.c2kernel.graph.model.VertexFactory;
+import com.c2kernel.lifecycle.ActivityDef;
+import com.c2kernel.lifecycle.chooser.ActivityChooser;
+import com.c2kernel.lifecycle.chooser.WorkflowDialogue;
+import com.c2kernel.lifecycle.instance.Activity;
+import com.c2kernel.lifecycle.instance.CompositeActivity;
+import com.c2kernel.utils.Language;
+import com.c2kernel.utils.LocalObjectLoader;
+import com.c2kernel.utils.Resource;
+public class WfVertexFactory implements VertexFactory, WorkflowDialogue
+{
+ protected CompositeActivity mRootAct = null;
+ @Override
+ public void create(GraphModelManager graphModelManager, Point location, TypeNameAndConstructionInfo typeNameAndConstructionInfo)
+ {
+ String vertexTypeId = null;
+ if (mRootAct != null && typeNameAndConstructionInfo.mInfo instanceof String)
+ {
+ vertexTypeId = (String) typeNameAndConstructionInfo.mInfo;
+ if (vertexTypeId.equals("Atomic") || vertexTypeId.equals("Composite"))
+ {
+ HashMap<String, Serializable> mhm = new HashMap<String, Serializable>();
+ mhm.put("P1", vertexTypeId);
+ mhm.put("P2", location);
+ //************************************************
+ ActivityChooser a =
+ new ActivityChooser(
+ Language.translate("Please enter a Type for the new activity"),
+ Language.translate("New " + vertexTypeId + " Activity"),
+ Resource.findImage("graph/newvertex_large.png").getImage(),
+ this,
+ mhm);
+ a.setVisible(true);
+ }
+ else
+ mRootAct.newChild(vertexTypeId, location);
+ }
+ }
+ @Override
+ public void setCreationContext(Object newContext)
+ {
+ if (newContext != null && newContext instanceof CompositeActivity)
+ mRootAct = (CompositeActivity) newContext;
+ }
+ @Override
+ public void loadThisWorkflow(String newName, HashMap<?, ?> hashMap)
+ {
+ String vertexTypeId = (String) hashMap.get("P1");
+ Point location = (Point) hashMap.get("P2");
+ if (newName == null)
+ return;
+
+
+ String unicName = newName;
+ while (mRootAct.search(mRootAct.getPath() + "/" + unicName) != null)
+ {
+ unicName =
+ (String) JOptionPane.showInputDialog(
+ null,
+ Language.translate("Activity name not unique. Please give another."),
+ Language.translate("New " + vertexTypeId + " Activity"),
+ JOptionPane.QUESTION_MESSAGE,
+ Resource.findImage("graph/newvertex_large.png"),
+ null,
+ null);
+ if (newName.equals(""))
+ return;
+ }
+ Activity act = null;
+ try
+ {
+ ActivityDef actD = LocalObjectLoader.getActDef(newName, "last");
+ act = (Activity)actD.instantiate(unicName);
+ }
+ catch (Exception e)
+ {
+ }
+ if (act == null)
+ mRootAct.newChild(unicName, vertexTypeId, location);
+ else
+ mRootAct.newExistingChild(act, unicName, location);
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfVertexOutlineCreator.java b/src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfVertexOutlineCreator.java
new file mode 100644
index 0000000..e8cb303
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/gui/model/WfVertexOutlineCreator.java
@@ -0,0 +1,52 @@
+package com.c2kernel.lifecycle.instance.gui.model;
+
+import java.io.Serializable;
+
+import com.c2kernel.graph.model.GraphPoint;
+import com.c2kernel.graph.model.Vertex;
+import com.c2kernel.graph.model.VertexOutlineCreator;
+import com.c2kernel.lifecycle.instance.Activity;
+
+public class WfVertexOutlineCreator implements VertexOutlineCreator,Serializable
+{
+ private final int mActivityWidth = 130;
+ private final int mActivityHeight = 60;
+ private final int mSplitJoinWidth = 60;
+ private final int mSplitJoinHeight = 25;
+
+ @Override
+ public void setOutline(Vertex vertex)
+ {
+ GraphPoint centrePoint = vertex.getCentrePoint();
+ GraphPoint[] outlinePoints = new GraphPoint[ 4 ];
+ int vertexWidth = 0;
+ int vertexHeight = 0;
+
+ if(vertex instanceof Activity)
+ {
+ vertexWidth = mActivityWidth;
+ vertexHeight = mActivityHeight;
+ }
+ else
+ {
+ vertexWidth = mSplitJoinWidth;
+ vertexHeight = mSplitJoinHeight;
+ }
+
+ outlinePoints[ 0 ] = new GraphPoint();
+ outlinePoints[ 0 ].x = centrePoint.x - vertexWidth / 2;
+ outlinePoints[ 0 ].y = centrePoint.y - vertexHeight / 2;
+ outlinePoints[ 1 ] = new GraphPoint();
+ outlinePoints[ 1 ].x = centrePoint.x + vertexWidth / 2;
+ outlinePoints[ 1 ].y = centrePoint.y - vertexHeight / 2;
+ outlinePoints[ 2 ] = new GraphPoint();
+ outlinePoints[ 2 ].x = centrePoint.x + vertexWidth / 2;
+ outlinePoints[ 2 ].y = centrePoint.y + vertexHeight / 2;
+ outlinePoints[ 3 ] = new GraphPoint();
+ outlinePoints[ 3 ].x = centrePoint.x - vertexWidth / 2;
+ outlinePoints[ 3 ].y = centrePoint.y + vertexHeight / 2;
+
+ vertex.setOutlinePoints( outlinePoints );
+ }
+}
+
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/gui/view/ActivityRenderer.java b/src/main/java/com/c2kernel/lifecycle/instance/gui/view/ActivityRenderer.java
new file mode 100644
index 0000000..046ed7c
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/gui/view/ActivityRenderer.java
@@ -0,0 +1,117 @@
+package com.c2kernel.lifecycle.instance.gui.view;
+import java.awt.Color;
+import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+import java.awt.Paint;
+import java.awt.Polygon;
+
+import com.c2kernel.common.GTimeStamp;
+import com.c2kernel.graph.model.GraphPoint;
+import com.c2kernel.graph.model.Vertex;
+import com.c2kernel.graph.view.VertexRenderer;
+import com.c2kernel.lifecycle.instance.Activity;
+import com.c2kernel.lifecycle.instance.stateMachine.States;
+import com.c2kernel.utils.DateUtility;
+import com.c2kernel.utils.Language;
+public class ActivityRenderer implements VertexRenderer
+{
+ private Paint mActivePaint = new Color(100, 255, 100);
+ private Paint mActiveCompPaint = new Color(100, 255, 255);
+ private Paint mInactivePaint = new Color(255, 255, 255);
+ private Paint mInactiveCompPaint = new Color(200, 200, 255);
+ private Paint mErrorPaint = new Color(255, 50, 0);
+ private Paint mTextPaint = Color.black;
+ @Override
+ public void draw(Graphics2D g2d, Vertex vertex)
+ {
+ Activity activity = (Activity) vertex;
+ boolean active = activity.getActive();
+ boolean hasError = !activity.verify();
+ boolean isComposite = activity.getIsComposite();
+ GraphPoint centrePoint = activity.getCentrePoint();
+ //String description = activity.getDescription();
+ String[] linesOfText = new String[3];
+ linesOfText[0] = "(" + activity.getType() + ")";
+ linesOfText[1] = activity.getName();
+ if (hasError)
+ linesOfText[2] = Language.translate(activity.getErrors());
+ else
+ {
+ int cs = activity.getCurrentState();
+ if (cs == States.WAITING && activity.getActive())
+ linesOfText[2] =
+ Language.translate(States.getStateName(cs))
+ + (((Boolean) activity.getProperties().get("Show time")).booleanValue()
+ ? " " + getWaitTime(activity.getActiveDate())
+ : "");
+ else if (cs == States.STARTED)
+ linesOfText[2] =
+ Language.translate(States.getStateName(cs))
+ + (((Boolean) activity.getProperties().get("Show time")).booleanValue()
+ ? " " + getWaitTime(activity.getStartDate())
+ : "");
+ else
+ linesOfText[2] = Language.translate(States.getStateName(cs));
+ }
+
+ FontMetrics metrics = g2d.getFontMetrics();
+ int lineWidth = 0;
+ int lineHeight = metrics.getHeight();
+ int linesHeight = lineHeight * linesOfText.length;
+ int linesStartY = centrePoint.y - linesHeight / 2 + lineHeight * 2 / 3;
+ int x = 0;
+ int y = 0;
+ int i = 0;
+ GraphPoint[] outline = vertex.getOutlinePoints();
+ Paint actColour;
+ if (hasError)
+ actColour = mErrorPaint;
+ else if (active)
+ if (isComposite)
+ actColour = mActiveCompPaint;
+ else
+ actColour = mActivePaint;
+ else if (isComposite)
+ actColour = mInactiveCompPaint;
+ else
+ actColour = mInactivePaint;
+ g2d.setPaint(actColour);
+ //g2d.fill3DRect( centrePoint.x - mSize.width / 2, centrePoint.y - mSize.height / 2, mSize.width, mSize.height, true );
+ g2d.fill(graphPointsToPolygon(outline));
+ g2d.setPaint(mTextPaint);
+ for (i = 0; i < linesOfText.length; i++)
+ {
+ lineWidth = metrics.stringWidth(linesOfText[i]);
+ x = centrePoint.x - lineWidth / 2;
+ y = linesStartY + i * lineHeight;
+ g2d.drawString(linesOfText[i], x, y);
+ }
+ }
+ private static Polygon graphPointsToPolygon(GraphPoint[] points)
+ {
+ Polygon polygon = new Polygon();
+ int i = 0;
+ for (i = 0; i < points.length; i++)
+ {
+ polygon.addPoint(points[i].x, points[i].y);
+ }
+ return polygon;
+ }
+ private static String getWaitTime(GTimeStamp date)
+ {
+ GTimeStamp now = new GTimeStamp();
+ DateUtility.setToNow(now);
+ long diff = DateUtility.diff(now, date);
+ long secondes = diff % 60;
+ long minutes = (diff / 60) % 60;
+ long hours = (diff / 3600) % 24;
+ long days = (diff / 3600 / 24);
+ if (days > 0)
+ return days + " " + Language.translate("d") + " " + hours + " " + Language.translate("h");
+ if (hours > 0)
+ return hours + " " + Language.translate("h") + " " + minutes + " " + Language.translate("min");
+ if (minutes > 0)
+ return minutes + " " + Language.translate("min");
+ return secondes + " " + Language.translate("sec");
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/gui/view/FindActDefPanel.java b/src/main/java/com/c2kernel/lifecycle/instance/gui/view/FindActDefPanel.java
new file mode 100644
index 0000000..4c1a148
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/gui/view/FindActDefPanel.java
@@ -0,0 +1,72 @@
+package com.c2kernel.lifecycle.instance.gui.view;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.graph.model.Vertex;
+import com.c2kernel.graph.view.SelectedVertexPanel;
+import com.c2kernel.gui.MainFrame;
+import com.c2kernel.lifecycle.ActivitySlotDef;
+import com.c2kernel.lookup.DomainPath;
+
+/**************************************************************************
+ *
+ * $Revision: 1.3 $
+ * $Date: 2005/12/01 14:23:15 $
+ *
+ * Copyright (C) 2003 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+public class FindActDefPanel extends SelectedVertexPanel {
+
+ JButton findButton;
+ ActivitySlotDef currentAct;
+
+ public FindActDefPanel() {
+ super();
+ findButton = new JButton("Open Definition");
+ findButton.setEnabled(false);
+ add(findButton);
+ findButton.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ try {
+ DomainPath actPath = (DomainPath)new DomainPath("/desc/ActivityDesc/").find(currentAct.getActivityDef());
+ MainFrame.treeBrowser.push(actPath);
+ } catch (ObjectNotFoundException e1) { }
+ }
+ });
+ }
+
+ /**
+ *
+ */
+
+ @Override
+ public void select(Vertex vert) {
+ if (vert instanceof ActivitySlotDef) {
+ findButton.setEnabled(true);
+ currentAct = (ActivitySlotDef)vert;
+ }
+ else
+ clear();
+
+ }
+
+ /**
+ *
+ */
+
+ @Override
+ public void clear() {
+ findButton.setEnabled(false);
+ currentAct = null;
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/gui/view/SplitJoinRenderer.java b/src/main/java/com/c2kernel/lifecycle/instance/gui/view/SplitJoinRenderer.java
new file mode 100644
index 0000000..036f79a
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/gui/view/SplitJoinRenderer.java
@@ -0,0 +1,142 @@
+package com.c2kernel.lifecycle.instance.gui.view;
+
+import java.awt.Color;
+import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+import java.awt.Paint;
+
+import com.c2kernel.graph.model.GraphPoint;
+import com.c2kernel.graph.model.Vertex;
+import com.c2kernel.graph.view.VertexRenderer;
+import com.c2kernel.lifecycle.instance.AndSplit;
+import com.c2kernel.lifecycle.instance.Join;
+import com.c2kernel.lifecycle.instance.Loop;
+import com.c2kernel.lifecycle.instance.OrSplit;
+import com.c2kernel.lifecycle.instance.WfVertex;
+import com.c2kernel.lifecycle.instance.XOrSplit;
+import com.c2kernel.utils.Language;
+
+public class SplitJoinRenderer implements VertexRenderer
+{
+ private Paint mTextPaint = Color.black;
+ private Paint mBoxPaint = new Color( 204, 204, 204 );
+ private Paint mErrorPaint = new Color( 255, 0, 0 );
+ private boolean mTextOffsetsNotInitialised = true;
+ private int mTextYOffset = 0;
+ private String mAndText = "And";
+ private int mAndTextXOffset = 0;
+ private String mOrText = "Or";
+ private int mOrTextXOffset = 0;
+ private String mLoopText = "Loop";
+ private int mLoopTextXOffset = 0;
+ private String mXOrText = "XOr";
+ private int mXOrTextXOffset = 0;
+ private String mJoinText = "Join";
+ private int mJoinTextXOffset = 0;
+ private String mRouteText = "";
+ private int mRouteTextXOffset = 0;
+ private String mXXXText = "XXX";
+ private int mXXXTextXOffset = 0;
+
+
+ @Override
+ public void draw( Graphics2D g2d, Vertex vertex)
+ {
+ GraphPoint centrePoint = vertex.getCentrePoint();
+ String text = null;
+ int textXOffset = 0;
+ int vertexHeight = vertex.getHeight();
+ int vertexWidth = vertex.getWidth();
+
+
+ if ( mTextOffsetsNotInitialised )
+ {
+ initialiseTextOffsets( g2d );
+ mTextOffsetsNotInitialised = false;
+ }
+ if ( vertex instanceof AndSplit )
+ {
+ text = Language.translate(mAndText);
+ textXOffset = mAndTextXOffset;
+ }
+ else if ( vertex instanceof OrSplit )
+ {
+ text = Language.translate(mOrText);
+ textXOffset = mOrTextXOffset;
+ }
+ else if ( vertex instanceof Loop )
+ {
+ text = Language.translate(mLoopText);
+ textXOffset = mLoopTextXOffset;
+ }
+ else if ( vertex instanceof XOrSplit )
+ {
+ text = Language.translate(mXOrText);
+ textXOffset = mXOrTextXOffset;
+ }
+ else if ( vertex instanceof Join )
+ {
+ text = Language.translate(mJoinText);
+ textXOffset = mJoinTextXOffset;
+ }
+ else if ( vertex instanceof Join)
+ {
+ String type= (String)((Join)vertex).getProperties().get("Type");
+ if (type!=null && type.equals("Route"))
+ {
+ text = mRouteText;
+ textXOffset = mRouteTextXOffset;
+ }
+ else
+ {
+ text = Language.translate(mJoinText);
+ textXOffset = mJoinTextXOffset;
+ }
+ }
+ else
+ {
+ text = mXXXText;
+ textXOffset = mXXXTextXOffset;
+ }
+
+ boolean hasErrors = ((WfVertex)vertex).verify();
+ g2d.setPaint( hasErrors ? mBoxPaint : mErrorPaint );
+ g2d.fillRect
+ (
+ centrePoint.x - vertexWidth / 2,
+ centrePoint.y - vertexHeight / 2,
+ vertexWidth,
+ vertexHeight
+ );
+ g2d.setPaint( mTextPaint );
+ g2d.drawRect
+ (
+ centrePoint.x - vertexWidth / 2,
+ centrePoint.y - vertexHeight / 2,
+ vertexWidth,
+ vertexHeight
+ );
+ g2d.drawString( text, centrePoint.x - textXOffset, centrePoint.y + mTextYOffset );
+
+ if (!hasErrors) {
+ g2d.setPaint( mErrorPaint );
+ String errors = Language.translate(((WfVertex)vertex).getErrors());
+ int errorWidth = g2d.getFontMetrics().stringWidth( errors );
+ g2d.drawString( errors, centrePoint.x - ( errorWidth / 2), centrePoint.y + vertexHeight );
+ }
+ }
+
+ private void initialiseTextOffsets( Graphics2D g2d )
+ {
+ FontMetrics metrics = g2d.getFontMetrics();
+
+
+ mTextYOffset = metrics.getHeight() / 3;
+ mAndTextXOffset = metrics.stringWidth( Language.translate(mAndText) ) / 2;
+ mOrTextXOffset = metrics.stringWidth( Language.translate(mOrText) ) / 2;
+ mXOrTextXOffset = metrics.stringWidth( Language.translate(mXOrText) ) / 2;
+ mJoinTextXOffset = metrics.stringWidth( Language.translate(mJoinText) ) / 2;
+ mLoopTextXOffset = metrics.stringWidth( Language.translate(mLoopText) ) / 2;
+ }
+}
+
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/gui/view/TransitionPanel.java b/src/main/java/com/c2kernel/lifecycle/instance/gui/view/TransitionPanel.java
new file mode 100644
index 0000000..094f900
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/gui/view/TransitionPanel.java
@@ -0,0 +1,187 @@
+package com.c2kernel.lifecycle.instance.gui.view;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.Box;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+
+import com.c2kernel.entity.agent.Job;
+import com.c2kernel.entity.proxy.ItemProxy;
+import com.c2kernel.graph.model.Vertex;
+import com.c2kernel.graph.view.SelectedVertexPanel;
+import com.c2kernel.gui.MainFrame;
+import com.c2kernel.gui.tabs.EntityTabPane;
+import com.c2kernel.gui.tabs.execution.Executor;
+import com.c2kernel.lifecycle.instance.Activity;
+import com.c2kernel.lifecycle.instance.stateMachine.StateMachine;
+import com.c2kernel.lifecycle.instance.stateMachine.States;
+import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
+import com.c2kernel.utils.Logger;
+
+/**************************************************************************
+ *
+ * $Revision: 1.8 $
+ * $Date: 2005/09/07 13:46:31 $
+ *
+ * Copyright (C) 2003 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+public class TransitionPanel extends SelectedVertexPanel implements ActionListener {
+ protected Activity mCurrentAct;
+ protected GridBagLayout gridbag;
+ protected GridBagConstraints c;
+ protected Box transBox;
+ protected JComboBox executors;
+ protected JComboBox states = new JComboBox(States.states);
+ protected JCheckBox active = new JCheckBox();
+ protected JLabel status = new JLabel();
+ protected ItemProxy mItem;
+
+ public TransitionPanel() {
+ super();
+ gridbag = new GridBagLayout();
+ setLayout(gridbag);
+ c = new GridBagConstraints();
+ c.gridx=0; c.gridy=0;
+ c.weightx=1; c.weighty=0;
+ c.fill=GridBagConstraints.HORIZONTAL;
+
+ JLabel title = new JLabel("Available Transitions");
+ title.setFont(EntityTabPane.titleFont);
+ gridbag.setConstraints(title, c);
+ add(title);
+
+ c.gridy++;
+ gridbag.setConstraints(status, c);
+ add(status);
+ c.gridy++;
+
+ transBox = Box.createHorizontalBox();
+ gridbag.setConstraints(transBox, c);
+ add(transBox);
+
+ c.weightx=0; c.gridx++;
+ executors = MainFrame.getExecutionPlugins();
+ if (executors.getItemCount() > 1) {
+ gridbag.setConstraints(executors, c);
+ add(executors);
+ }
+
+
+
+ if (MainFrame.isAdmin) {
+ c.gridx=0; c.gridy++;
+ title = new JLabel("State Hacking");
+ title.setFont(EntityTabPane.titleFont);
+ gridbag.setConstraints(title, c);
+ add(title);
+ Box hackBox = Box.createHorizontalBox();
+ hackBox.add(states);
+ hackBox.add(Box.createHorizontalGlue());
+ hackBox.add(new JLabel("Active:"));
+ hackBox.add(active);
+ c.gridy++;
+ gridbag.setConstraints(hackBox, c);
+ add(hackBox);
+ states.addActionListener(this);
+ active.addActionListener(this);
+ }
+
+ clear();
+
+ }
+ /**
+ *
+ */
+ @Override
+ public void select(Vertex vert) {
+ clear();
+ if (!(vert instanceof Activity)) return;
+ mCurrentAct = (Activity)vert;
+ states.setSelectedIndex(mCurrentAct.getCurrentState());
+ states.setEnabled(true);
+ active.setSelected(mCurrentAct.active);
+ active.setEnabled(true);
+ Logger.msg("Retrieving possible transitions for activity "+mCurrentAct.getName());
+ int[] transitions = mCurrentAct.getMachine().possibleTransition();
+ if (transitions.length == 0) {
+ status.setText("None");
+ return;
+ }
+ for (int i = 0; i < transitions.length; i++) {
+ String trans= Transitions.getTransitionName(transitions[i]);
+ if (!(transitions[i]==Transitions.DONE) && !(transitions[i]==Transitions.COMPLETE)) {
+ String buttonLabel = trans.substring(0,1).toUpperCase()+trans.substring(1);
+ JButton thisTrans = new JButton(buttonLabel);
+ thisTrans.setActionCommand("Trans:"+String.valueOf(transitions[i]));
+ thisTrans.addActionListener(this);
+ transBox.add(thisTrans);
+ transBox.add(Box.createHorizontalGlue());
+ }
+ status.setText(transitions.length+" transitions possible.");
+ }
+ revalidate();
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (e.getSource() == active && mCurrentAct != null) {
+ mCurrentAct.active = active.isSelected();
+ return;
+ }
+ if (e.getSource() == states && mCurrentAct != null) {
+ mCurrentAct.getMachine().state = states.getSelectedIndex();
+ return;
+ }
+ if (!e.getActionCommand().startsWith("Trans:")) return;
+ int transition = Integer.parseInt(e.getActionCommand().substring(6));
+ Logger.msg("Requesting transition "+transition);
+ Job thisJob = new Job(mItem.getSystemKey(),
+ mCurrentAct.getPath(),
+ transition,
+ new StateMachine(mCurrentAct).simulate(transition),
+ mCurrentAct.getCurrentState(),
+ mCurrentAct.getName(),
+ mCurrentAct.getProperties(),
+ mCurrentAct.getType(),
+ MainFrame.userAgent.getName());
+ try {
+ Executor selectedExecutor = (Executor)executors.getSelectedItem();
+ selectedExecutor.execute(thisJob, status);
+ } catch (Exception ex) {
+ String className = ex.getClass().getName();
+ className = className.substring(className.lastIndexOf('.')+1);
+ Logger.error(ex);
+ JOptionPane.showMessageDialog(null, ex.getMessage(), className, JOptionPane.ERROR_MESSAGE);
+ }
+
+ }
+
+ @Override
+ public void clear() {
+ mCurrentAct = null;
+ transBox.removeAll();
+ status.setText("No activity selected");
+ states.setSelectedIndex(0);
+ states.setEnabled(false);
+ active.setSelected(false);
+ active.setEnabled(false);
+ revalidate();
+ }
+
+
+ /**
+ * @param item The mItem to set.
+ */
+ public void setItem(ItemProxy item) {
+ mItem = item;
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/gui/view/WfDirectedEdgeRenderer.java b/src/main/java/com/c2kernel/lifecycle/instance/gui/view/WfDirectedEdgeRenderer.java
new file mode 100644
index 0000000..f39d9a6
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/gui/view/WfDirectedEdgeRenderer.java
@@ -0,0 +1,130 @@
+package com.c2kernel.lifecycle.instance.gui.view;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.GeneralPath;
+
+import com.c2kernel.graph.model.DirectedEdge;
+import com.c2kernel.graph.model.GraphPoint;
+import com.c2kernel.graph.view.DirectedEdgeRenderer;
+import com.c2kernel.lifecycle.instance.Next;
+public class WfDirectedEdgeRenderer implements DirectedEdgeRenderer
+{
+ private GeneralPath mArrowTemplate = new GeneralPath();
+ public WfDirectedEdgeRenderer()
+ {
+ mArrowTemplate.moveTo(-5, 5);
+ mArrowTemplate.lineTo(0, 0);
+ mArrowTemplate.lineTo(5, 5);
+ }
+ @Override
+ public void draw(Graphics2D g2d, DirectedEdge directedEdge)
+ {
+ GraphPoint originPoint = directedEdge.getOriginPoint();
+ GraphPoint terminusPoint = directedEdge.getTerminusPoint();
+ GraphPoint midPoint = new GraphPoint();
+ AffineTransform transform = new AffineTransform();
+ Shape arrow = null;
+ Next next = (Next) directedEdge;
+ String text = (String) next.getProperties().get("Alias");
+ g2d.setPaint(Color.black);
+ if (("Broken +".equals(next.getProperties().get("Type"))))
+ {
+ g2d.drawLine(originPoint.x, originPoint.y, originPoint.x, (originPoint.y + terminusPoint.y) / 2);
+ g2d.drawLine(originPoint.x, (originPoint.y + terminusPoint.y) / 2, terminusPoint.x, (originPoint.y + terminusPoint.y) / 2);
+ g2d.drawLine(terminusPoint.x, (originPoint.y + terminusPoint.y) / 2, terminusPoint.x, terminusPoint.y);
+ midPoint.x = (originPoint.x + terminusPoint.x) / 2;
+ midPoint.y = (originPoint.y + terminusPoint.y) / 2;
+ transform.translate(midPoint.x, midPoint.y);
+ transform.rotate(
+ calcArrowAngle(
+ originPoint.x,
+ originPoint.x - terminusPoint.x > -5
+ && originPoint.x - terminusPoint.x < 5 ? originPoint.y : (originPoint.y + terminusPoint.y) / 2,
+ terminusPoint.x,
+ originPoint.x - terminusPoint.x > -5
+ && originPoint.x - terminusPoint.x < 5 ? terminusPoint.y : (originPoint.y + terminusPoint.y) / 2));
+ }
+ else if (("Broken -".equals(next.getProperties().get("Type"))))
+ {
+ g2d.drawLine(originPoint.x, originPoint.y, terminusPoint.x, originPoint.y);
+ g2d.drawLine(terminusPoint.x, originPoint.y, terminusPoint.x, terminusPoint.y);
+ boolean arrowOnY = !(originPoint.y - terminusPoint.y < 60 && originPoint.y - terminusPoint.y > -60);
+ midPoint.x = arrowOnY ? terminusPoint.x : (originPoint.x + terminusPoint.x) / 2;
+ midPoint.y = arrowOnY ? (originPoint.y + terminusPoint.y) / 2 : originPoint.y;
+ transform.translate(midPoint.x, midPoint.y);
+ transform.rotate(
+ calcArrowAngle(
+ arrowOnY ? terminusPoint.x : originPoint.x,
+ arrowOnY ? originPoint.y : originPoint.y,
+ arrowOnY ? terminusPoint.x : terminusPoint.x,
+ arrowOnY ? terminusPoint.y : originPoint.y));
+ }
+ else if (("Broken |".equals(next.getProperties().get("Type"))))
+ {
+ g2d.drawLine(originPoint.x, originPoint.y, originPoint.x, terminusPoint.y);
+ g2d.drawLine(originPoint.x, terminusPoint.y, terminusPoint.x, terminusPoint.y);
+ boolean arrowOnY = !(originPoint.y - terminusPoint.y < 60 && originPoint.y - terminusPoint.y > -60);
+ midPoint.x = arrowOnY ? originPoint.x : (originPoint.x + terminusPoint.x) / 2;
+ midPoint.y = arrowOnY ? (originPoint.y + terminusPoint.y) / 2 : terminusPoint.y;
+ transform.translate(midPoint.x, midPoint.y);
+ transform.rotate(
+ calcArrowAngle(
+ arrowOnY ? terminusPoint.x : originPoint.x,
+ arrowOnY ? originPoint.y : originPoint.y,
+ arrowOnY ? terminusPoint.x : terminusPoint.x,
+ arrowOnY ? terminusPoint.y : originPoint.y));
+ }
+ else
+ {
+ g2d.drawLine(originPoint.x, originPoint.y, terminusPoint.x, terminusPoint.y);
+ midPoint.x = originPoint.x + (terminusPoint.x - originPoint.x) / 2;
+ midPoint.y = originPoint.y + (terminusPoint.y - originPoint.y) / 2;
+ transform.translate(midPoint.x, midPoint.y);
+ transform.rotate(calcArrowAngle(originPoint.x, originPoint.y, terminusPoint.x, terminusPoint.y));
+ }
+ arrow = mArrowTemplate.createTransformedShape(transform);
+ g2d.draw(arrow);
+ if (text != null)
+ g2d.drawString(text, midPoint.x + 10, midPoint.y);
+ }
+ private static double calcArrowAngle(int originX, int originY, int terminusX, int terminusY)
+ {
+ double width = terminusX - originX;
+ double height = terminusY - originY;
+ if ((width == 0) && (height > 0))
+ {
+ return Math.PI;
+ }
+ if ((width == 0) && (height < 0))
+ {
+ return 0;
+ }
+ if ((width > 0) && (height == 0))
+ {
+ return Math.PI / 2.0;
+ }
+ if ((width < 0) && (height == 0))
+ {
+ return -1.0 * Math.PI / 2.0;
+ }
+ if ((width > 0) && (height > 0))
+ {
+ return Math.PI / 2.0 + Math.atan(Math.abs(height) / Math.abs(width));
+ }
+ if ((width > 0) && (height < 0))
+ {
+ return Math.atan(Math.abs(width) / Math.abs(height));
+ }
+ if ((width < 0) && (height < 0))
+ {
+ return -1.0 * Math.atan(Math.abs(width) / Math.abs(height));
+ }
+ if ((width < 0) && (height > 0))
+ {
+ return -1.0 * (Math.PI / 2.0 + Math.atan(Math.abs(height) / Math.abs(width)));
+ }
+ return 0.0;
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/gui/view/WfVertexRenderer.java b/src/main/java/com/c2kernel/lifecycle/instance/gui/view/WfVertexRenderer.java
new file mode 100644
index 0000000..92a1021
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/gui/view/WfVertexRenderer.java
@@ -0,0 +1,23 @@
+package com.c2kernel.lifecycle.instance.gui.view;
+
+import java.awt.Graphics2D;
+
+import com.c2kernel.graph.model.Vertex;
+import com.c2kernel.graph.view.VertexRenderer;
+import com.c2kernel.lifecycle.instance.Activity;
+import com.c2kernel.lifecycle.instance.Join;
+import com.c2kernel.lifecycle.instance.Split;
+
+public class WfVertexRenderer implements VertexRenderer
+{
+ protected ActivityRenderer mActivityRenderer = new ActivityRenderer();
+ protected SplitJoinRenderer mSplitJoinRenderer = new SplitJoinRenderer();
+
+ @Override
+ public void draw( Graphics2D g2d, Vertex vertex)
+ {
+ if ( vertex instanceof Activity ) { mActivityRenderer.draw( g2d, vertex); }
+ else if ( ( vertex instanceof Split ) || ( vertex instanceof Join ) ) { mSplitJoinRenderer.draw( g2d, vertex ); }
+ }
+}
+
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddC2KObject.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddC2KObject.java
new file mode 100644
index 0000000..b61187c
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddC2KObject.java
@@ -0,0 +1,75 @@
+/**************************************************************************
+ * AddC2KObject
+ *
+ * $Workfile$
+ * $Revision: 1.31 $
+ * $Date: 2004/10/21 08:02:19 $
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+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.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
+
+/**************************************************************************
+ *
+ * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $
+ * @version $Revision: 1.31 $
+ **************************************************************************/
+public class AddC2KObject extends PredefinedStep
+{
+ /**************************************************************************
+ * Constructor for Castror
+ **************************************************************************/
+ public AddC2KObject()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ @Override
+ public void request( AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ InvalidDataException
+ {
+
+ Logger.msg(1, "AddC2KObject::request() - Starting.");
+
+ checkAccessRights(agent);
+ EntityPath entityPath = getItemEntityPath();
+
+ if (entityPath!=null)
+ {
+ try
+ {
+
+ Logger.msg(5, "AddC2KObject::request() - data:" + getDataList(requestData)[0]);
+
+ C2KLocalObject obj = (C2KLocalObject)CastorXMLUtility.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.");
+ }
+ else
+ throw new InvalidDataException("EntityPath is null.", "");
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java
new file mode 100644
index 0000000..2cf619e
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java
@@ -0,0 +1,67 @@
+/**************************************************************************
+ * AddDomainPath
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+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;
+import com.c2kernel.lookup.InvalidEntityPathException;
+import com.c2kernel.lookup.LDAPLookup;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.utils.Logger;
+
+public class AddDomainPath extends PredefinedStep
+{
+ public AddDomainPath()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ @Override
+ public void request( AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ 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);
+ lookupManager.add(domainPath);
+ Logger.msg(8,"AddDomainPath::request() - systemKey:" + entityPath.getSysKey() +
+ ". Adding dompath. DONE.");
+ }
+ catch (InvalidEntityPathException ex)
+ {
+ Logger.error(ex);
+ throw new InvalidDataException(ex.toString(), "");
+ }
+ catch( Exception ex )
+ {
+ Logger.error("AddDomainPath::request() - during anyHelper.extract.");
+ Logger.error(ex);
+ throw new InvalidDataException(ex.toString(), "");
+ }
+
+ sendEventStoreOutcome(transitionID, requestData, agent);
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddStepsFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddStepsFromDescription.java
new file mode 100644
index 0000000..f70c053
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddStepsFromDescription.java
@@ -0,0 +1,56 @@
+package com.c2kernel.lifecycle.instance.predefined;
+
+//Java
+import java.awt.Point;
+
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.lifecycle.CompositeActivityDef;
+import com.c2kernel.lifecycle.instance.CompositeActivity;
+import com.c2kernel.lifecycle.instance.Workflow;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
+
+public class AddStepsFromDescription extends PredefinedStep
+{
+ public AddStepsFromDescription()
+ {
+ super();
+ }
+
+ @Override
+ public void request( AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException, InvalidTransitionException, InvalidDataException
+ {
+ Workflow lifeCycle = getWf();
+
+ Logger.msg(1, "AddStepsFromDescription::request() - Starting ");
+
+ checkAccessRights(agent);
+
+ try
+ {
+
+ Logger.msg(8, "AddStepsFromDescription::request() - data:" + getDataList(requestData)[0]);
+ lifeCycle.getChildGraphModel().removeVertex(lifeCycle.search("workflow/domain"));
+ CompositeActivityDef actDef = (CompositeActivityDef) CastorXMLUtility.unmarshall(getDataList(requestData)[0]);
+ CompositeActivity domain = (CompositeActivity)actDef.instantiate();
+ lifeCycle.initChild(domain, true, new Point(150, 100));
+ domain.setName("domain");
+ domain.setType(actDef.getName());
+ lifeCycle.run(agent);
+ Gateway.getStorage().put(getItemEntityPath().getSysKey(), lifeCycle, null);
+ Logger.msg(1, "AddStepsFromDescription::request() - DONE.");
+ sendEventStoreOutcome(transitionID, requestData, agent);
+ }
+ catch (Exception ex)
+ {
+ Logger.error("AddStepsFromDescription::request() - during unmarshall.");
+ Logger.error(ex);
+ throw new InvalidDataException("AddStepsFromDescription::request() - during unmarshall.", "");
+ }
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java
new file mode 100644
index 0000000..0ad5adc
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java
@@ -0,0 +1,116 @@
+/**************************************************************************
+ * AssignItemToSlot
+ *
+ * $Workfile$
+ * $Revision: 1.8 $
+ * $Date: 2004/10/21 08:02:19 $
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+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.lookup.AgentPath;
+import com.c2kernel.lookup.EntityPath;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.persistency.ClusterStorageException;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.utils.Logger;
+
+/**************************************************************************
+ *
+ * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $
+ * @version $Revision: 1.8 $
+ **************************************************************************/
+public class AssignItemToSlot extends PredefinedStep
+{
+ /**************************************************************************
+ * Constructor for Castor
+ **************************************************************************/
+ public AssignItemToSlot()
+ {
+ super();
+ }
+
+
+ /**
+ * Params:
+ * 0 - collection name
+ * 1 - slot number
+ * 2 - target entity key
+ */
+ @Override
+ public void request(AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ InvalidDataException
+ {
+ EntityPath entityPath = getItemEntityPath();
+ String collName;
+ int slotNo;
+ int entityKey;
+ Collection<? extends CollectionMember> coll;
+
+ 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]);
+ entityKey = Integer.parseInt(params[2]);
+ } catch (Exception e) {
+ throw new InvalidDataException("Invalid parameters", "");
+ }
+
+ // load collection
+ try {
+ coll = (Collection<? extends CollectionMember>)Gateway.getStorage().get(entityPath.getSysKey(), ClusterStorage.COLLECTION+"/"+collName, null);
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new InvalidDataException("Error loading collection "+collName, "");
+ }
+
+ // find member and assign entity
+ boolean stored = false;
+ for (Object name : coll.getMembers().list) {
+ CollectionMember member = (CollectionMember)name;
+ if (member.getID() == slotNo) {
+ if (member.getEntityKey() > -1)
+ throw new InvalidDataException("Member slot not empty", "");
+ try {
+ member.assignEntity(entityKey);
+ } catch (MembershipException e) {
+ throw new InvalidDataException("Entity "+entityKey+" does not fit in this slot", "");
+ }
+ stored = true;
+ break;
+ }
+ }
+ if (!stored) {
+ throw new InvalidDataException("Member slot "+slotNo+" not found.", "");
+ }
+
+
+ try {
+ Gateway.getStorage().put(entityPath.getSysKey(), coll, null);
+ } catch (ClusterStorageException e) {
+ Logger.error(e);
+ throw new InvalidDataException("Error storing collection", "");
+ }
+ sendEventStoreOutcome(transitionID, requestData, agent);
+
+ Logger.msg(1, "AssignItemToSlot::request() - DONE.");
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java
new file mode 100644
index 0000000..8c55f3a
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java
@@ -0,0 +1,183 @@
+/**************************************************************************
+ * CreateItemFromDescription
+ *
+ * $Workfile$
+ * $Revision: 1.47 $
+ * $Date: 2005/10/13 08:13:58 $
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+package com.c2kernel.lifecycle.instance.predefined;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.c2kernel.collection.Collection;
+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;
+import com.c2kernel.lookup.LDAPLookup;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.persistency.TransactionManager;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.property.Property;
+import com.c2kernel.property.PropertyArrayList;
+import com.c2kernel.property.PropertyDescriptionList;
+import com.c2kernel.property.PropertyUtility;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.LocalObjectLoader;
+import com.c2kernel.utils.Logger;
+
+/**************************************************************************
+ *
+ * @author $Author: abranson $ $Date: 2005/10/13 08:13:58 $
+ * @version $Revision: 1.47 $
+ **************************************************************************/
+public class CreateItemFromDescription extends PredefinedStep
+{
+ public CreateItemFromDescription()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ @Override
+ public void request(AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException, InvalidTransitionException, InvalidDataException,ObjectAlreadyExistsException
+ {
+ String[] input = getDataList(requestData);
+ String newName = input[0];
+ String domPath = input[1];
+ CompositeActivityDef wfDef;
+ String wfDefName = null;
+ if (input.length > 2) // override wf
+ wfDefName = input[2];
+
+ PropertyArrayList props = new PropertyArrayList();
+ 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
+ DomainPath context = new DomainPath(new DomainPath(domPath), newName);
+ Logger.debug(8,"context "+context.getSysKey()+" "+context.getPath()+" "+context.getString());
+ if (context.getSysKey()!=-1)
+ throw new ObjectAlreadyExistsException("The item name " +newName+ " exists already.");
+
+ // get init objects
+ String[] collNames = storage.getClusterContents(myPath.getSysKey(), ClusterStorage.COLLECTION);
+ ArrayList<String> collections = new ArrayList<String>();
+
+
+ // loop through collections to instantiate
+ for (String collName : collNames) {
+ Collection<? extends CollectionMember> thisCol = (Collection<? extends CollectionMember>)storage.get(myPath.getSysKey(), ClusterStorage.COLLECTION+"/"+collName, null);
+ if (thisCol instanceof CollectionDescription) {
+ CollectionDescription<? extends CollectionMember> thisDesc = (CollectionDescription<? extends CollectionMember>)thisCol;
+ collections.add(CastorXMLUtility.marshall(thisDesc.newInstance()));
+ }
+ else if (thisCol.getName().equalsIgnoreCase("workflow") && wfDefName == null) {
+ ArrayList<? extends CollectionMember> members = thisCol.getMembers().list;
+ // get the first member from the wf collection
+ CollectionMember wfMember = members.get(0);
+ wfDefName = wfMember.resolveEntity().getName();
+ }
+ }
+
+ // load workflow def
+ if (wfDefName == null)
+ throw new InvalidDataException("No workflow given or defined", "");
+
+ try {
+ wfDef = (CompositeActivityDef)LocalObjectLoader.getActDef(wfDefName, "last");
+ } catch (ObjectNotFoundException ex) {
+ throw new InvalidDataException("Workflow def '"+wfDefName+"' item not found", "");
+ } catch (ClassCastException ex) {
+ throw new InvalidDataException("Activity def '"+wfDefName+"' was not Composite", "");
+ }
+
+
+ // copy properties -- intend to create from propdesc
+ PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(myPath.getSysKey());
+ props = pdList.instanciate();
+ // set Name prop or create if not present
+ boolean foundName = false;
+ for (Property prop : props.list) {
+ if (prop.getName().equals("Name")) {
+ foundName = true;
+ prop.setValue(newName);
+ }
+ }
+ if (!foundName) props.list.add(new Property("Name", newName));
+ props.list.add( new Property("Creator", agent.getAgentName()));
+
+ /* ITEM CREATION */
+
+ // generate new entity key
+ Logger.msg(6, "CreateItemFromDescription - Requesting new sysKey");
+ EntityPath entityPath = lookup.getNextKeyManager().generateNextEntityKey();
+
+ // resolve the item factory
+ Logger.msg(6, "CreateItemFromDescription - Resolving item factory");
+
+ // create the Item object
+ Logger.msg(3, "CreateItemFromDescription - Creating Item");
+ CorbaServer factory = Gateway.getCorbaServer();
+ if (factory == null) throw new AccessRightsException("This process cannot create new Items", "");
+ TraceableEntity newItem = (TraceableEntity)factory.createEntity(entityPath);
+ Gateway.getLDAPLookup().add(entityPath);
+
+
+ // initialise it with its properties and workflow
+
+ Logger.msg(3, "CreateItemFromDescription - Initializing Item");
+
+ newItem.initialise(
+ agent.getSysKey(),
+ CastorXMLUtility.marshall(props),
+ CastorXMLUtility.marshall(wfDef.instantiate()));
+
+ // add collections
+ if (collections.size() > 0) {
+ Logger.msg(6, "CreateItemFromDescription - Adding Collections");
+ String[] colls = new String[1];
+ for (Iterator<String> iter = collections.iterator(); iter.hasNext();) {
+ colls[0] = iter.next();
+ newItem.requestAction(agent.getSysKey(), "workflow/predefined/AddC2KObject", Transitions.COMPLETE, PredefinedStep.bundleData(colls));
+ }
+ }
+
+ // add its domain path
+ 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;
+ } 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
new file mode 100644
index 0000000..ffdb07c
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/Erase.java
@@ -0,0 +1,85 @@
+/**************************************************************************
+ * RemoveC2KObject
+ *
+ * $Workfile$
+ * $Revision: 1.10 $
+ * $Date: 2005/11/15 15:56:38 $
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+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;
+import com.c2kernel.lookup.Path;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.property.Property;
+import com.c2kernel.utils.Logger;
+
+
+/**************************************************************************
+ *
+ * @author $Author: abranson $ $Date: 2005/11/15 15:56:38 $
+ * @version $Revision: 1.10 $
+ **************************************************************************/
+public class Erase extends PredefinedStep
+{
+ public Erase()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ @Override
+ public void request(AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ InvalidDataException
+ {
+ Logger.msg(1, "Erase::request() - Starting.");
+
+ checkAccessRights(agent);
+ try
+ {
+ EntityPath entityPath = getItemEntityPath();
+
+ // find entity name
+ Property name = (Property)Gateway.getStorage().get(entityPath.getSysKey(), ClusterStorage.PROPERTY+"/Name", null);
+
+ // get all domain paths
+ Enumeration<Path> domPaths = Gateway.getLDAPLookup().search(new DomainPath(), name.getValue());
+ while (domPaths.hasMoreElements()) {
+ DomainPath path = (DomainPath)domPaths.nextElement();
+ // delete them
+ if (path.getSysKey() == entityPath.getSysKey())
+ Gateway.getLDAPLookup().delete(path);
+ }
+
+ //clear out all storages
+ Gateway.getStorage().removeCluster(entityPath.getSysKey(), "", null);
+
+ //remove domain path
+ Gateway.getLDAPLookup().delete(entityPath);
+ }
+ catch( Exception ex )
+ {
+
+ Logger.error(ex);
+ throw new InvalidDataException(ex.toString(), "");
+ }
+
+ Logger.msg(1, "Erase::request() - DONE.");
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/Import.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/Import.java
new file mode 100644
index 0000000..2f99937
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/Import.java
@@ -0,0 +1,71 @@
+/**************************************************************************
+ * AddDomainPath
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+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.utils.Logger;
+
+/**************************************************************************
+ *
+ * $Revision: 1.21 $
+ * $Date: 2005/06/02 12:17:22 $
+ *
+ * Params: Schemaname_version:Viewpoint (optional), Outcome
+ *
+ * Copyright (C) 2003 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+public class Import extends PredefinedStep
+{
+ public Import()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ @Override
+ public void request( AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ InvalidDataException
+ {
+ Logger.msg(8,"Import::request()");
+
+ Logger.msg(1,"Import::request() - Starting.");
+
+ checkAccessRights(agent);
+
+ String[] params = getDataList(requestData);
+
+
+ int split1 = params[0].indexOf('_');
+ int split2 = params[0].indexOf(':');
+
+ String schemaName = params[0].substring(0, split1);
+ String viewpoint = "last";
+ int schemaVersion;
+ if (split2 > -1) {
+ schemaVersion = Integer.parseInt(params[0].substring(split1+1, split2));
+ viewpoint = params[0].substring(split2+1);
+ }
+ else
+ schemaVersion = Integer.parseInt(params[0].substring(split1+1));
+
+ // set type & ver
+ getProperties().put("SchemaType", schemaName);
+ getProperties().put("SchemaVersion", String.valueOf(schemaVersion));
+ getProperties().put("Viewpoint", viewpoint);
+
+ requestData = params[1];
+
+ sendEventStoreOutcome(transitionID, requestData, agent);
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java
new file mode 100644
index 0000000..8aec993
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java
@@ -0,0 +1,156 @@
+package com.c2kernel.lifecycle.instance.predefined;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.xml.serialize.Method;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.InputSource;
+
+import com.c2kernel.lifecycle.instance.Activity;
+import com.c2kernel.utils.Logger;
+/***********************************************************************************************************************************************************************************************************************************************************************************************************
+ * @author $Author: sgaspard $ $Date: 2004/09/21 10:32:17 $
+ * @version $Revision: 1.14 $
+ **********************************************************************************************************************************************************************************************************************************************************************************************************/
+public 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()
+ {
+ if (isPredefined)
+ return true;
+ else
+ return super.getActive();
+ }
+ @Override
+ public String getTransitions()
+ {
+ if (isPredefined)
+ return "<PossibleTransitions>done</PossibleTransitions>";
+ else
+ return super.getTransitions();
+ }
+ @Override
+ public String getErrors()
+ {
+ if (isPredefined)
+ return getName();
+ else
+ return super.getErrors();
+ }
+ @Override
+ public boolean verify()
+ {
+ if (isPredefined)
+ return true;
+ else
+ return super.verify();
+ }
+ /**
+ * Returns the isPredefined.
+ *
+ * @return boolean
+ */
+ public boolean getIsPredefined()
+ {
+ return isPredefined;
+ }
+ /**
+ * Sets the isPredefined.
+ *
+ * @param isPredefined
+ * The isPredefined to set
+ */
+ public void setIsPredefined(boolean isPredefined)
+ {
+ this.isPredefined = isPredefined;
+ }
+ @Override
+ public String getType()
+ {
+ return getName();
+ }
+ // generic bundling of parameters
+ static public String bundleData(String[] data)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document dom = builder.newDocument();
+ Element root = dom.createElement("PredefinedStepOutcome");
+ dom.appendChild(root);
+ for (String element : data) {
+ Element param = dom.createElement("param");
+ Text t = dom.createTextNode(element);
+ param.appendChild(t);
+ root.appendChild(param);
+ }
+ // xalan method - use internal xerces one instead
+// TransformerFactory transFactory = TransformerFactory.newInstance();
+// Transformer transformer = transFactory.newTransformer();
+// StringWriter stringOut = new StringWriter();
+// transformer.transform(new DOMSource(dom), new StreamResult(stringOut));
+// return stringOut.toString();
+
+ OutputFormat format = new OutputFormat(Method.XML, null, false);
+ StringWriter stringOut = new StringWriter();
+ XMLSerializer serial = new XMLSerializer(stringOut, format);
+ serial.asDOMSerializer();
+ serial.serialize(dom);
+ return stringOut.toString();
+ }
+ catch (Exception e)
+ {
+ Logger.error(e);
+ StringBuffer xmlData = new StringBuffer().append("<PredefinedStepOutcome>");
+ for (String element : data)
+ xmlData.append("<param><![CDATA[").append(element).append("]]></param>");
+ xmlData.append("</PredefinedStepOutcome>");
+ return xmlData.toString();
+ }
+ }
+ // generic bundling of single parameter
+ static public String bundleData(String data)
+ {
+ return "<PredefinedStepOutcome><param><![CDATA[" + data + "]]></param></PredefinedStepOutcome>";
+ }
+ static public String[] getDataList(String xmlData)
+ {
+ try
+ {
+ Document scriptDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xmlData)));
+ NodeList nodeList = scriptDoc.getElementsByTagName("param");
+ String[] result = new String[nodeList.getLength()];
+ for (int i = 0; i < nodeList.getLength(); i++)
+ {
+ Node n = nodeList.item(i).getFirstChild();
+ if (n instanceof CDATASection)
+ result[i] = ((CDATASection) n).getData();
+ else if (n instanceof Text)
+ result[i] = ((Text) n).getData();
+ }
+ return result;
+ }
+ catch (Exception ex)
+ {
+ Logger.error("Exception::PredefinedStep::getDataList()");
+ Logger.error(ex);
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java
new file mode 100644
index 0000000..d065afb
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java
@@ -0,0 +1,61 @@
+package com.c2kernel.lifecycle.instance.predefined;
+import com.c2kernel.graph.model.GraphPoint;
+import com.c2kernel.lifecycle.instance.CompositeActivity;
+public class PredefinedStepContainer extends CompositeActivity
+{
+ protected int num = 0;
+
+ public PredefinedStepContainer()
+ {
+ super();
+ setName("predefined");
+ getProperties().put("Description", "Contains all predefined Steps");
+ createChildren();
+ }
+ public void createChildren()
+ {
+ predInit("CreateItemFromDescription", "Create a new item using this item as its description", new CreateItemFromDescription());
+ predInit("AddDomainPath", "Adds a new path to this entity in the LDAP domain tree", new AddDomainPath());
+ predInit("RemoveDomainPath", "Removes an existing path to this Entity from the LDAP domain tree", new RemoveDomainPath());
+ predInit("AddStepsFromDescription", "Creates the domain-specific LifeCycle from a description", new AddStepsFromDescription());
+ predInit("ReplaceDomainWorkflow", "Replaces the domain CA with the supplied one. Used by the GUI to save new Wf layout", new ReplaceDomainWorkflow());
+ predInit("AddC2KObject", "Adds a new named C2Kernel object to this Item", new AddC2KObject());
+ predInit("WriteProperty", "Writes a property to the Item", new WriteProperty());
+ predInit("RemoveC2KObject", "Removes the named C2Kernel object from this Item.", new RemoveC2KObject());
+ predInit("AssignItemToSlot", "Assigns the referenced entity to a pre-existing slot in a collection of this one", new AssignItemToSlot());
+ predInit("Erase", "Deletes all objects and domain paths for this item.", new Erase());
+ predInit("Import", "Imports an outcome into the Item, with a given schema and viewpoint", new Import());
+ }
+
+ public void predInit(String alias, String Description, PredefinedStep act)
+ {
+ act.setName(alias);
+ act.setType(alias);
+ act.getProperties().put("Description", Description);
+ act.getProperties().put("SchemaType", "PredefinedStepOutcome");
+ act.getProperties().put("SchemaVersion", "0");
+ act.setCentrePoint(new GraphPoint());
+ act.setIsPredefined(true);
+ addChild(act, new GraphPoint(100, 75 * ++num));
+ }
+ @Override
+ public boolean verify()
+ {
+ return true;
+ }
+ @Override
+ public String getErrors()
+ {
+ return "predefined";
+ }
+ @Override
+ public boolean getActive()
+ {
+ return true;
+ }
+ @Override
+ public String getTransitions()
+ {
+ return "<PossibleTransitions></PossibleTransitions>";
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveC2KObject.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveC2KObject.java
new file mode 100644
index 0000000..c9513a8
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveC2KObject.java
@@ -0,0 +1,67 @@
+/**************************************************************************
+ * RemoveC2KObject
+ *
+ * $Workfile$
+ * $Revision: 1.28 $
+ * $Date: 2005/11/15 15:56:38 $
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+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;
+
+
+/**************************************************************************
+ *
+ * @author $Author: abranson $ $Date: 2005/11/15 15:56:38 $
+ * @version $Revision: 1.28 $
+ **************************************************************************/
+public class RemoveC2KObject extends PredefinedStep
+{
+ public RemoveC2KObject()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ @Override
+ public void request(AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ 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);
+ }
+ catch( Exception ex )
+ {
+ Logger.error("RemoveC2KObject::request() - invalid data - path:"+path);
+ Logger.error(ex);
+ throw new InvalidDataException(ex.toString(), "");
+ }
+
+ Logger.msg(1, "RemoveC2KObject::request() - DONE.");
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java
new file mode 100644
index 0000000..19ff7c6
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java
@@ -0,0 +1,59 @@
+/**************************************************************************
+ * AddDomainPath
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+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;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.utils.Logger;
+
+public class RemoveDomainPath extends PredefinedStep
+{
+ public RemoveDomainPath()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ @Override
+ public void request( AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ 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.");
+
+ }
+ catch( Exception ex )
+ {
+ Logger.error("AddAlias::request() - during anyHelper.extract.");
+ Logger.error(ex);
+ throw new InvalidDataException(ex.toString(), "");
+ }
+
+ sendEventStoreOutcome(transitionID, requestData, agent);
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java
new file mode 100644
index 0000000..ba3e6c6
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java
@@ -0,0 +1,53 @@
+package com.c2kernel.lifecycle.instance.predefined;
+
+//Java
+import java.awt.Point;
+
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.lifecycle.instance.CompositeActivity;
+import com.c2kernel.lifecycle.instance.Workflow;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
+
+public class ReplaceDomainWorkflow extends PredefinedStep
+{
+ public ReplaceDomainWorkflow()
+ {
+ super();
+ }
+
+ @Override
+ public void request( AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException, InvalidTransitionException, InvalidDataException
+ {
+ Workflow lifeCycle = getWf();
+
+ Logger.msg(1, "ReplaceDomainWorkflow::request() - Starting ");
+
+ checkAccessRights(agent);
+
+ try
+ {
+
+ Logger.msg(8, "ReplaceDomainWorkflow::request() - data:" + getDataList(requestData)[0]);
+ lifeCycle.getChildGraphModel().removeVertex(lifeCycle.search("workflow/domain"));
+ CompositeActivity domain = (CompositeActivity) CastorXMLUtility.unmarshall(getDataList(requestData)[0]);
+ lifeCycle.initChild(domain, true, new Point(150, 100));
+ Gateway.getStorage().put(getItemEntityPath().getSysKey(), lifeCycle, null);
+ Logger.msg(1, "ReplaceDomainWorkflow::request() - DONE.");
+ sendEventStoreOutcome(transitionID, requestData, agent);
+ // refresh jobs
+ lifeCycle.refreshJobs();
+ }
+ catch (Exception ex)
+ {
+ Logger.error("ReplaceDomainWorkflow::request() - during unmarshall.");
+ Logger.error(ex);
+ throw new InvalidDataException("ReplaceDomainWorkflow::request() - during unmarshall.", null);
+ }
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ServerPredefinedStepContainer.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ServerPredefinedStepContainer.java
new file mode 100644
index 0000000..21eacda
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ServerPredefinedStepContainer.java
@@ -0,0 +1,41 @@
+package com.c2kernel.lifecycle.instance.predefined;
+
+import com.c2kernel.graph.model.GraphPoint;
+import com.c2kernel.lifecycle.instance.predefined.entitycreation.CreateNewAgent;
+import com.c2kernel.lifecycle.instance.predefined.entitycreation.CreateNewItem;
+
+/**************************************************************************
+ *
+ * $Revision: 1.2 $
+ * $Date: 2005/06/02 10:19:33 $
+ *
+ * Copyright (C) 2003 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+// public static final String codeRevision = "$Revision: 1.2 $ $Date: 2005/06/02 10:19:33 $ $Author: abranson $";
+public class ServerPredefinedStepContainer extends PredefinedStepContainer {
+
+
+ @Override
+ public void createChildren()
+ {
+ super.createChildren();
+ serverPredInit("CreateNewItem", "Creates a new Item in this Server without description.", new CreateNewItem(), "NewItem");
+ serverPredInit("CreateNewAgent", "Creates a new Item in this Server without description.", new CreateNewAgent(), "NewAgent");
+ }
+
+ public void serverPredInit(String alias, String Description, PredefinedStep act, String schema)
+ {
+ act.setName(alias);
+ act.setType(alias);
+ act.getProperties().put("Description", Description);
+ act.getProperties().put("SchemaType", schema);
+ act.getProperties().put("SchemaVersion", "0");
+ act.getProperties().put("AgentRole", "Admin");
+ act.setCentrePoint(new GraphPoint());
+ act.setIsPredefined(true);
+ addChild(act, new GraphPoint(100, 75 * ++num));
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java
new file mode 100644
index 0000000..77a0b43
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java
@@ -0,0 +1,77 @@
+/**************************************************************************
+ * WriteProperty
+ *
+ * $Workfile$
+ * $Revision: 1.3 $
+ * $Date: 2004/10/21 08:02:19 $
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+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;
+
+/**************************************************************************
+ *
+ * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $
+ * @version $Revision: 1.3 $
+ **************************************************************************/
+public class WriteProperty extends PredefinedStep
+{
+ /**************************************************************************
+ * Constructor for Castror
+ **************************************************************************/
+ public WriteProperty()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ @Override
+ public void request( AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ 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
+ {
+
+ 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(1, "WriteProperty::request() - DONE.");
+ }
+ else
+ throw new InvalidDataException("EntityPath is null.", "");
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java
new file mode 100644
index 0000000..2de12e0
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java
@@ -0,0 +1,25 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+import java.util.ArrayList;
+
+public class Aggregation implements java.io.Serializable {
+
+ public boolean isDescription;
+ public ArrayList<AggregationMember> aggregationMemberList;
+ public String name;
+
+ public Aggregation() {
+ super();
+ aggregationMemberList = new ArrayList<AggregationMember>();
+ }
+
+ public Aggregation(String name, boolean isDescription) {
+ this();
+ this.name = name;
+ this.isDescription = isDescription;
+ }
+
+ public com.c2kernel.collection.Aggregation create() {
+ return new com.c2kernel.collection.AggregationInstance();
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java
new file mode 100644
index 0000000..29d3cf9
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java
@@ -0,0 +1,21 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+public class AggregationMember implements java.io.Serializable {
+
+ public int slotNo;
+ public String itemDescriptionPath;
+ public String itemPath;
+ public Geometry geometry;
+
+
+ public AggregationMember() {
+ super();
+ }
+
+ public AggregationMember(int slotNo, String itemDescPath, String itemPath, Geometry geometry) {
+ this.slotNo = slotNo;
+ this.itemDescriptionPath = itemDescPath;
+ this.itemPath = itemPath;
+ this.geometry = geometry;
+ }
+}
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
new file mode 100644
index 0000000..aa30677
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java
@@ -0,0 +1,49 @@
+/**************************************************************************
+ * AddDomainPath
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+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.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
+
+public class CreateNewAgent extends PredefinedStep
+{
+ public CreateNewAgent()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ @Override
+ public void request( AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ InvalidDataException
+ {
+ checkAccessRights(agent);
+ String redactedRequestData;
+ try {
+ NewAgent newAgent = (NewAgent)CastorXMLUtility.unmarshall(requestData);
+ newAgent.create(agent.getSysKey());
+ newAgent.password = "REDACTED";
+ redactedRequestData = CastorXMLUtility.marshall(newAgent);
+ } 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
new file mode 100644
index 0000000..a66b062
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java
@@ -0,0 +1,46 @@
+/**************************************************************************
+ * CreateNewItem
+ *
+ * Copyright (C) 2005 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+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.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
+
+public class CreateNewItem extends PredefinedStep
+{
+ public CreateNewItem()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ @Override
+ public void request( AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ InvalidDataException
+ {
+ checkAccessRights(agent);
+
+ try {
+ NewItem item = (NewItem)CastorXMLUtility.unmarshall(requestData);
+ item.create(agent.getSysKey());
+ } 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/Dependency.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java
new file mode 100644
index 0000000..1124ede
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java
@@ -0,0 +1,44 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+import java.util.ArrayList;
+
+import com.c2kernel.collection.MembershipException;
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.property.PropertyUtility;
+
+public class Dependency implements java.io.Serializable {
+
+ public String name;
+ public boolean isDescription;
+ public String itemDescriptionPath;
+ public ArrayList<DependencyMember> dependencyMemberList;
+
+ public Dependency() {
+ super();
+ dependencyMemberList = new ArrayList<DependencyMember>();
+ }
+
+ public Dependency(String itemDesc) {
+ this();
+ this.itemDescriptionPath = itemDesc;
+ }
+
+ /**
+ * @return
+ */
+ public com.c2kernel.collection.Dependency create() throws MembershipException{
+ com.c2kernel.collection.Dependency newDep = isDescription?new com.c2kernel.collection.DependencyDescription(name):new com.c2kernel.collection.Dependency(name);
+ if (itemDescriptionPath != null && itemDescriptionPath.length()>0) {
+ PropertyUtility.getPropertyDescriptionOutcome(new DomainPath(itemDescriptionPath).getSysKey());
+ //TODO: set props and class identifiers
+ }
+ for (DependencyMember thisMem : dependencyMemberList) {
+ int syskey = new DomainPath(thisMem.itemPath).getSysKey();
+ if (syskey == -1)
+ throw new MembershipException("Cannot find "+thisMem.itemPath+" specified for collection.");
+ newDep.addMember(syskey);
+ }
+ return newDep;
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java
new file mode 100644
index 0000000..b70619f
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java
@@ -0,0 +1,18 @@
+
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+public class DependencyMember implements java.io.Serializable {
+
+
+ public String itemPath;
+
+ public DependencyMember() {
+ super();
+ }
+
+ public DependencyMember(String itemPath) {
+ this.itemPath = itemPath;
+
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Geometry.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Geometry.java
new file mode 100644
index 0000000..f18b6d4
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Geometry.java
@@ -0,0 +1,29 @@
+
+
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+
+
+public class Geometry implements java.io.Serializable {
+
+
+ public int x;
+
+ public int y;
+
+ public int width;
+
+ public int height;
+
+ public Geometry() {
+ super();
+ }
+
+ public Geometry(int x, int y, int width, int height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java
new file mode 100644
index 0000000..540a6fc
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java
@@ -0,0 +1,63 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+
+import com.c2kernel.common.CannotManageException;
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.agent.ActiveEntity;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.RolePath;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.property.PropertyArrayList;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
+
+public class NewAgent implements java.io.Serializable {
+
+ public String name;
+
+ public String password;
+
+ public ArrayList<String> roles;
+
+ public NewAgent() {
+ super();
+ roles = new ArrayList<String>();
+ }
+
+ public NewAgent(String name, String password) {
+ this.name = name;
+ this.password = password;
+ }
+
+ protected void create(int agentId) throws ObjectNotFoundException, ObjectCannotBeUpdated, NoSuchAlgorithmException, CannotManageException, ObjectAlreadyExistsException {
+ AgentPath newAgent = Gateway.getLDAPLookup().getNextKeyManager().generateNextAgentKey();
+ newAgent.setAgentName(name);
+ newAgent.setPassword(password);
+ ActiveEntity newAgentEnt = (ActiveEntity)Gateway.getCorbaServer().createEntity(newAgent);
+ Gateway.getLDAPLookup().add(newAgent);
+ // assemble properties
+ PropertyArrayList propList = new PropertyArrayList();
+ propList.list.add(new com.c2kernel.property.Property("Name", name));
+ propList.list.add(new com.c2kernel.property.Property("Type", "Agent"));
+ try {
+ newAgentEnt.initialise(CastorXMLUtility.marshall(propList));
+ } catch (Exception ex) {
+ Logger.error(ex);
+ throw new CannotManageException("Error initialising new agent");
+ }
+ for (String role : roles) {
+ RolePath thisRole;
+ try {
+ thisRole = Gateway.getLDAPLookup().getRoleManager().getRolePath(role);
+ } catch (ObjectNotFoundException ex) {
+ thisRole = Gateway.getLDAPLookup().getRoleManager().createRole(role, false);
+ }
+ thisRole.addAgent(newAgent);
+ }
+
+ }
+}
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
new file mode 100644
index 0000000..f155ced
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java
@@ -0,0 +1,141 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+
+import java.util.ArrayList;
+
+import com.c2kernel.collection.MembershipException;
+import com.c2kernel.common.CannotManageException;
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.TraceableEntity;
+import com.c2kernel.lifecycle.CompositeActivityDef;
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.lookup.EntityPath;
+import com.c2kernel.persistency.ClusterStorageException;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.property.PropertyArrayList;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.LocalObjectLoader;
+import com.c2kernel.utils.Logger;
+
+/**
+ * Complete Structure for new item
+ *
+ * @version $Revision: 1.8 $ $Date: 2006/03/03 13:52:21 $
+ */
+
+public class NewItem {
+
+ public String name;
+
+ /**
+ * The initial Domain Path to be created for this Item.
+ */
+ public String initialPath;
+
+ /**
+ * The name of the Composite Activity Definition to be
+ * instantiated for the workflow of this Item
+ */
+ public String workflow;
+
+ /**
+ * New Properties for the item
+ */
+ public ArrayList<Property> propertyList;
+
+ /**
+ * Field _aggregationList
+ */
+ public ArrayList<Aggregation> aggregationList;
+
+ /**
+ * Field _dependencyList
+ */
+ public ArrayList<Dependency> dependencyList;
+
+
+ public NewItem() {
+ super();
+ propertyList = new ArrayList<Property>();
+ aggregationList = new ArrayList<Aggregation>();
+ dependencyList = new ArrayList<Dependency>();
+ }
+
+ public NewItem(String name, String initialPath, String wf) {
+ this();
+ this.name = name;
+ this.initialPath = initialPath;
+ this.workflow = wf;
+ }
+
+ public void setProperty(String name, String value) {
+ for (Property prop : propertyList) {
+ if (prop.name.equals(name)) {
+ prop.value = value;
+ return;
+ }
+ }
+ propertyList.add(new Property(name, value));
+ }
+
+ protected void create(int agentId) throws ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException {
+ DomainPath domPath = new DomainPath(new DomainPath(initialPath), name);
+ if (domPath.exists())
+ throw new ObjectAlreadyExistsException(domPath+" already exists!", "");
+
+ // create item
+ EntityPath entPath = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
+ TraceableEntity newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entPath);
+ Gateway.getLDAPLookup().add(entPath);
+
+ // assemble properties
+ PropertyArrayList propList = new PropertyArrayList();
+ propList.list.add(new com.c2kernel.property.Property("Name", name));
+ for (Property element : propertyList) {
+ propList.list.add(new com.c2kernel.property.Property(element.name, element.value));
+ }
+ // init the new item
+ try {
+
+ // find workflow def
+ CompositeActivityDef compact = (CompositeActivityDef)LocalObjectLoader.getActDef(workflow, "last");
+
+ newItem.initialise(
+ agentId,
+ CastorXMLUtility.marshall(propList),
+ CastorXMLUtility.marshall(compact.instantiate()));
+ } catch (Exception ex) {
+ Logger.error("Error initialising new item");
+ Logger.error(ex);
+ throw new CannotManageException("Problem initialising new item. See server log.", "");
+ }
+
+ // create collections
+
+ for (Dependency element: dependencyList) {
+ try {
+ Gateway.getStorage().put(entPath.getSysKey(), element.create(), null);
+ } catch (ClusterStorageException ex) {
+ Logger.error(ex);
+ throw new CannotManageException("Could not create Dependency "+element.name, "");
+ } catch (MembershipException ex) {
+ Logger.error(ex);
+ throw new CannotManageException("A specified member is not of the correct type in "+element.name, "");
+ }
+ }
+
+ for (Aggregation element : aggregationList) {
+ try {
+ Gateway.getStorage().put(entPath.getSysKey(), element.create(), null);
+ } catch (ClusterStorageException ex) {
+ Logger.error(ex);
+ throw new CannotManageException("Could not create Aggregation "+element.name, "");
+ }
+ }
+ // register domain path
+ domPath.setEntity(entPath);
+ Gateway.getLDAPLookup().add(domPath);
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Property.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Property.java
new file mode 100644
index 0000000..e2d214c
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Property.java
@@ -0,0 +1,26 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+/**
+ * New Properties for the item
+ *
+ * @version $Revision: 1.1 $ $Date: 2005/04/28 13:48:26 $
+ */
+public class Property implements java.io.Serializable {
+
+ public String name;
+ public String value;
+
+
+ //----------------/
+ //- Constructors -/
+ //----------------/
+
+ public Property() {
+ super();
+ }
+
+ public Property(String name, String value) {
+ super();
+ this.name = name;
+ this.value = value;
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java
new file mode 100644
index 0000000..8159106
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java
@@ -0,0 +1,142 @@
+
+package com.c2kernel.lifecycle.instance.stateMachine;
+
+import java.io.Serializable;
+
+import com.c2kernel.lifecycle.instance.Activity;
+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 int state = 0;
+ private Activity activity;
+
+ public static final String SKIPPABLE = "Skippable";
+ public static final String REPEATABLE = "Repeatable";
+ public static final String IGNORABLE = "Ignorable";
+ public static final String AUTOSTART = "Autostart";
+
+
+ /**
+ * Method StateMachine.
+ * @param act
+ */
+ public StateMachine(Activity act)
+ {
+ activity = act;
+ }
+
+ /** 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,REASIGN,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()?!getAutoStart()?5:7:-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;
+ }
+
+ /**
+ * @see java.lang.Object#Object()
+ */
+ public StateMachine()
+ {
+ }
+
+ /**
+ * Method getCurrentState.
+ * @return String
+ */
+ public int getCurrentState()
+ {
+ return state;
+ }
+
+ /**
+ * 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;
+
+ int [] result = new int[cmpt];
+ for (int i=0;i<cmpt;i++) result[i] = trans[i];
+ return result;
+ }
+
+ /**
+ * Method traverse.
+ * @param transition
+ * @return boolean
+ */
+ public boolean traverse(int transition)
+ {
+ int newState = getCurrentMachine()[state][transition];
+ if (newState > -1) {
+ state=newState;
+ return true;
+ }
+ Logger.msg("StateMachine.traverse() - Illegal transition "+Transitions.getTransitionName(transition)+" from "+States.getStateName(state));
+ return false;
+ }
+ public int simulate(int transition)
+ {
+ return getCurrentMachine()[state][transition];
+ }
+ /**
+ * Returns the ignorable.
+ * @return boolean
+ */
+ public boolean getIgnorable()
+ {
+ return ((Boolean)activity.getProperties().get(IGNORABLE)).booleanValue();
+ }
+
+ /**
+ * Returns the repeatable.
+ * @return boolean
+ */
+ public boolean getRepeatable()
+ {
+ return ((Boolean)activity.getProperties().get(REPEATABLE)).booleanValue();
+ }
+
+ /**
+ * Returns the skippable.
+ * @return boolean
+ */
+ public boolean getSkippable()
+ {
+ return ((Boolean)activity.getProperties().get(SKIPPABLE)).booleanValue();
+ }
+
+ public boolean getAutoStart()
+ {
+ return ((Boolean)activity.getProperties().get(AUTOSTART)).booleanValue();
+ }
+ public boolean getActive()
+ {
+ return activity.getActive();
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/States.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/States.java
new file mode 100644
index 0000000..b142e35
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/States.java
@@ -0,0 +1,40 @@
+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/Transitions.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transitions.java
new file mode 100644
index 0000000..4239baa
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transitions.java
@@ -0,0 +1,41 @@
+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;
+ }
+ }
+}