From 0ed2c1124cf1b9e49a2ec1fa0126a8df09f9e758 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 7 Oct 2014 09:18:11 +0200 Subject: Repackage to org.cristalise --- .../kernel/lifecycle/instance/Activity.java | 573 +++++++++++++++++++++ .../lifecycle/instance/AdvancementCalculator.java | 243 +++++++++ .../kernel/lifecycle/instance/AndSplit.java | 49 ++ .../lifecycle/instance/CompositeActivity.java | 469 +++++++++++++++++ .../kernel/lifecycle/instance/JobPusher.java | 81 +++ .../cristalise/kernel/lifecycle/instance/Join.java | 233 +++++++++ .../cristalise/kernel/lifecycle/instance/Loop.java | 130 +++++ .../cristalise/kernel/lifecycle/instance/Next.java | 103 ++++ .../kernel/lifecycle/instance/OrSplit.java | 90 ++++ .../kernel/lifecycle/instance/Split.java | 239 +++++++++ .../kernel/lifecycle/instance/WfVertex.java | 223 ++++++++ .../lifecycle/instance/WfVertexOutlineCreator.java | 69 +++ .../kernel/lifecycle/instance/Workflow.java | 266 ++++++++++ .../kernel/lifecycle/instance/XOrSplit.java | 84 +++ .../instance/predefined/AddC2KObject.java | 67 +++ .../instance/predefined/AddDomainPath.java | 62 +++ .../instance/predefined/AddMemberToCollection.java | 105 ++++ .../predefined/AddNewCollectionDescription.java | 110 ++++ .../lifecycle/instance/predefined/AddNewSlot.java | 128 +++++ .../instance/predefined/AssignItemToSlot.java | 121 +++++ .../lifecycle/instance/predefined/ClearSlot.java | 114 ++++ .../predefined/CreateNewCollectionVersion.java | 103 ++++ .../lifecycle/instance/predefined/Import.java | 106 ++++ .../instance/predefined/PredefinedStep.java | 191 +++++++ .../predefined/PredefinedStepContainer.java | 79 +++ .../instance/predefined/RemoveC2KObject.java | 70 +++ .../instance/predefined/RemoveDomainPath.java | 73 +++ .../predefined/RemoveSlotFromCollection.java | 131 +++++ .../instance/predefined/ReplaceDomainWorkflow.java | 77 +++ .../instance/predefined/WriteProperty.java | 80 +++ .../instance/predefined/WriteViewpoint.java | 88 ++++ .../agent/AgentPredefinedStepContainer.java | 47 ++ .../agent/CreateAgentFromDescription.java | 137 +++++ .../instance/predefined/agent/RemoveAgent.java | 90 ++++ .../predefined/agent/SetAgentPassword.java | 70 +++ .../instance/predefined/agent/SetAgentRoles.java | 94 ++++ .../predefined/item/CreateItemFromDescription.java | 195 +++++++ .../lifecycle/instance/predefined/item/Erase.java | 80 +++ .../item/ItemPredefinedStepContainer.java | 45 ++ .../predefined/server/AddDomainContext.java | 67 +++ .../instance/predefined/server/CreateNewAgent.java | 68 +++ .../instance/predefined/server/CreateNewItem.java | 63 +++ .../instance/predefined/server/CreateNewRole.java | 60 +++ .../predefined/server/RemoveDomainContext.java | 65 +++ .../instance/predefined/server/RemoveRole.java | 68 +++ .../server/ServerPredefinedStepContainer.java | 62 +++ .../lifecycle/instance/stateMachine/State.java | 101 ++++ .../instance/stateMachine/StateMachine.java | 178 +++++++ .../instance/stateMachine/Transition.java | 345 +++++++++++++ .../instance/stateMachine/TransitionOutcome.java | 57 ++ .../instance/stateMachine/TransitionResource.java | 29 ++ .../instance/stateMachine/TransitionScript.java | 48 ++ 52 files changed, 6526 insertions(+) create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/Activity.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/AdvancementCalculator.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/AndSplit.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/CompositeActivity.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/JobPusher.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/Join.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/Loop.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/Next.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/OrSplit.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/Split.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/WfVertex.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/WfVertexOutlineCreator.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/Workflow.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/XOrSplit.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddC2KObject.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddDomainPath.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddMemberToCollection.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewSlot.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AssignItemToSlot.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ClearSlot.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/CreateNewCollectionVersion.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/Import.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStep.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStepContainer.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveC2KObject.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveDomainPath.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteProperty.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteViewpoint.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/AgentPredefinedStepContainer.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/RemoveAgent.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/Erase.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/AddDomainContext.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewAgent.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewItem.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewRole.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveRole.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/ServerPredefinedStepContainer.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/State.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/StateMachine.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/Transition.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/TransitionOutcome.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/TransitionResource.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/TransitionScript.java (limited to 'src/main/java/org/cristalise/kernel/lifecycle/instance') diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/Activity.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/Activity.java new file mode 100644 index 0000000..f04a7a9 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/Activity.java @@ -0,0 +1,573 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Map; +import java.util.Vector; + +import org.cristalise.kernel.common.AccessRightsException; +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.GTimeStamp; +import org.cristalise.kernel.common.InvalidCollectionModification; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.InvalidTransitionException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.agent.Job; +import org.cristalise.kernel.events.Event; +import org.cristalise.kernel.events.History; +import org.cristalise.kernel.graph.model.Vertex; +import org.cristalise.kernel.lifecycle.WfCastorHashMap; +import org.cristalise.kernel.lifecycle.instance.stateMachine.State; +import org.cristalise.kernel.lifecycle.instance.stateMachine.StateMachine; +import org.cristalise.kernel.lifecycle.instance.stateMachine.Transition; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.InvalidAgentPathException; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.lookup.Path; +import org.cristalise.kernel.lookup.RolePath; +import org.cristalise.kernel.persistency.outcome.Outcome; +import org.cristalise.kernel.persistency.outcome.Schema; +import org.cristalise.kernel.persistency.outcome.Viewpoint; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.DateUtility; +import org.cristalise.kernel.utils.LocalObjectLoader; +import org.cristalise.kernel.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 mErrors; + /** @associates a State machine engine */ + private StateMachine machine; + protected int state = -1; + /** true is available to be executed */ + public boolean active = false; + /** used in verify() */ + private boolean loopTested; + private GTimeStamp mStateDate; + private String mType; + + public Activity() + { + super(); + setProperties(new WfCastorHashMap()); + getProperties().put("StateMachineName", getDefaultSMName()); + mErrors = new Vector(0, 1); + mStateDate = new GTimeStamp(); + DateUtility.setToNow(mStateDate); + } + + protected String getDefaultSMName() { + return "Default"; + } + + /** 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); + } + + public StateMachine getStateMachine() throws InvalidDataException { + if (machine == null) { + String name = (String)getProperties().get("StateMachineName"); + int version = getVersionNumberProperty("StateMachineVersion"); + try { + machine = LocalObjectLoader.getStateMachine(name, version); + } catch (ObjectNotFoundException ex) { + if (name.equals(getDefaultSMName()) && version == 0) { // default state machine not imported yet. Fake it. + try { + String marshalledSM = Gateway.getResource().getTextResource(null, "boot/SM/"+getDefaultSMName()+".xml"); + StateMachine bootstrap = (StateMachine)Gateway.getMarshaller().unmarshall(marshalledSM); + bootstrap.validate(); + machine = bootstrap; + return bootstrap; + } catch (Exception ex2) { + Logger.error(ex2); + throw new InvalidDataException("Could not bootstrap default state machine from resources."); + } + } + Logger.error(ex); + throw new InvalidDataException("Error loading state machine '"+name+"' v"+version); + } + } + return machine; + } + + /** return the current State of the State machine (Used in Serialisation) */ + public int getState() throws InvalidDataException + { + if (state == -1) + state = getStateMachine().getInitialStateCode(); + return state; + } + public String getStateName() throws InvalidDataException + { + return getStateMachine().getState(getState()).getName(); + } + + /** Sets a new State */ + public void setState(int state) + { + this.state = state; + } + + public boolean isFinished() throws InvalidDataException { + return getStateMachine().getState(getState()).isFinished(); + } + + + /** cf Item request + * @throws ObjectNotFoundException + * @throws PersistencyException + * @throws ObjectAlreadyExistsException + * @throws ObjectCannotBeUpdated + * @throws CannotManageException + * @throws InvalidCollectionModification */ + public String request(AgentPath agent, ItemPath itemPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, InvalidCollectionModification + { + + // Find requested transition + Transition transition = getStateMachine().getTransition(transitionID); + + // Check if the transition is possible + String usedRole = transition.getPerformingRole(this, agent); + + // Verify outcome + Schema schema = null; + String viewName = null; + boolean storeOutcome = false; + if (transition.hasOutcome(getProperties())) { + schema = transition.getSchema(getProperties()); + viewName = (String)getProperties().get("Viewpoint"); + if (requestData != null && requestData.length()>0) + storeOutcome = true; + else if (transition.getOutcome().isRequired()) + throw new InvalidDataException("Transition requires outcome data, but none was given"); + } + + // Get new state + State newState = getStateMachine().traverse(this, transition, agent); + + // Run extra logic in predefined steps here + String outcome = runActivityLogic(agent, itemPath, transitionID, requestData); + + // set new state and reservation + setState(newState.getId()); + getProperties().put("Agent Name", transition.getReservation(this, agent)); + + // store new event + Event newEvent = null; + try { + History hist = getWf().getHistory(); + if (storeOutcome) + newEvent = hist.addEvent(agent, usedRole, getName(), getPath(), getType(), schema.docType, schema.docVersion, + getStateMachine().getName(), getStateMachine().getVersion(), transition, viewName); + else + newEvent = hist.addEvent(agent, usedRole, getName(), getPath(), getType(), + getStateMachine().getName(), getStateMachine().getVersion(), transition); + + Logger.msg(7, "Activity::auditEvent() - Event:" + newEvent.getName() + " was added to the AuditTrail"); + + if (storeOutcome) { + Outcome newOutcome = new Outcome(newEvent.getID(), outcome, schema.docType, schema.docVersion); + Gateway.getStorage().put(itemPath, newOutcome, getWf()); + + // update specific view if defined + if (viewName != null && !viewName.equals("")) { + Viewpoint currentView = new Viewpoint(itemPath, schema.docType, viewName, schema.docVersion, newEvent.getID()); + Gateway.getStorage().put(itemPath, currentView, getWf()); + } + // update last view + Viewpoint currentView = new Viewpoint(itemPath, schema.docType, "last", schema.docVersion, newEvent.getID()); + Gateway.getStorage().put(itemPath, currentView, getWf()); + } + Gateway.getStorage().commit(getWf()); + } catch (PersistencyException ex) { + Logger.error(ex); + Gateway.getStorage().abort(getWf()); + throw ex; + } + + if (newState.isFinished()) { + if (!getProperties().get("Breakpoint").equals(Boolean.TRUE)) + runNext(agent, itemPath); + } + + DateUtility.setToNow(mStateDate); + + //refresh all the job lists + String agentRole = getCurrentAgentRole(); + if (agentRole != null && agentRole.length()>0) { + try { + RolePath myRole = Gateway.getLookup().getRolePath(agentRole); + pushJobsToAgents(itemPath, myRole); + } catch (ObjectNotFoundException ex) { // non-existent role + Logger.msg(7, "Activity.pushJobsToAgents() - Activity role '"+agentRole+" not found."); + } + } + + + return outcome; + } + + protected String runActivityLogic(AgentPath agent, ItemPath itemPath, + int transitionID, String requestData) throws + InvalidDataException, + InvalidCollectionModification, + ObjectAlreadyExistsException, + ObjectCannotBeUpdated, + ObjectNotFoundException, + PersistencyException, + CannotManageException + { + // Overriden in predefined steps + return requestData; + } + + @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 + * @throws ObjectNotFoundException + * @throws AccessRightsException + * @throws InvalidTransitionException + * @throws PersistencyException + * @throws ObjectAlreadyExistsException + * @throws ObjectCannotBeUpdated */ + @Override + public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidDataException + { + 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, Arrays.toString(outVertices) + " " + Arrays.toString(outVertices2)); + if (!hasNoNext) + ((WfVertex) outVertices[0]).run(agent, itemPath); + else + { + if (getParent() != null && getParent().getName().equals("domain")) // workflow + // finished + setActive(true); + else + { + CompositeActivity parent = (CompositeActivity) getParent(); + if (parent != null) + parent.runNext(agent, itemPath); + } + } + } + catch (InvalidDataException 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) + * @throws InvalidDataException + * @throws ObjectNotFoundException */ + @Override + public void reinit(int idLoop) throws InvalidDataException + { + Vertex[] outVertices = getOutGraphables(); + setState(getStateMachine().getInitialState().getId()); + 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 + * @throws InvalidDataException + * @throws ObjectAlreadyExistsException + * @throws AccessRightsException + * @throws InvalidTransitionException + * @throws ObjectNotFoundException + * @throws PersistencyException + * @throws ObjectCannotBeUpdated + */ + @Override + public void run(AgentPath agent, ItemPath itemPath) throws InvalidDataException + { + Logger.debug(8, getPath() + " run " + getState()); + + if (!getActive()) setActive(true); + boolean finished = getStateMachine().getState(getState()).isFinished(); + if (finished) + { + runNext(agent, itemPath); + } + else + { + DateUtility.setToNow(mStateDate); + pushJobsToAgents(itemPath); + } + } + /** + * sets the activity available to be executed on start of Workflow or composite activity (when it is the first one of the (sub)process + * @throws InvalidDataException + * @throws ObjectAlreadyExistsException + * @throws ObjectNotFoundException + * @throws AccessRightsException + * @throws InvalidTransitionException + * @throws PersistencyException + * @throws ObjectCannotBeUpdated + */ + @Override + public void runFirst(AgentPath agent, ItemPath itemPath) throws InvalidDataException + { + Logger.debug(8, getPath() + " runfirst"); + run(agent, itemPath); + } + /** @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"); + } + + /** + * returns the lists of jobs for the activity and children (cf org.cristalise.kernel.entity.Job) + * @throws InvalidDataException + * @throws ObjectNotFoundException + * @throws InvalidAgentPathException + */ + public ArrayList calculateJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws InvalidAgentPathException, ObjectNotFoundException, InvalidDataException + { + return calculateJobsBase(agent, itemPath, false); + } // + public ArrayList calculateAllJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws InvalidAgentPathException, ObjectNotFoundException, InvalidDataException + { + return calculateJobsBase(agent, itemPath, true); + } + private ArrayList calculateJobsBase(AgentPath agent, ItemPath itemPath, boolean includeInactive) throws ObjectNotFoundException, InvalidDataException, InvalidAgentPathException + { + Logger.msg(7, "calculateJobs - " + getPath()); + ArrayList jobs = new ArrayList(); + Map transitions; + if ((includeInactive || getActive()) && !getName().equals("domain")) { + transitions = getStateMachine().getPossibleTransitions(this, agent); + Logger.msg(7, "Activity.calculateJobs() - Got " + transitions.size() + " transitions."); + for (Transition transition : transitions.keySet()) { + Logger.msg(7, "Creating Job object for transition " + transition); + jobs.add(new Job(this, itemPath, transition, agent, transitions.get(transition))); + } + } + return jobs; + } + + + public void pushJobsToAgents(ItemPath itemPath) { + String agentRole = getCurrentAgentRole(); + if (agentRole != null && agentRole.length()>0) { + try { + RolePath myRole = Gateway.getLookup().getRolePath(agentRole); + pushJobsToAgents(itemPath, myRole); + } catch (ObjectNotFoundException ex) { // non-existent role + Logger.msg(7, "Activity.pushJobsToAgents() - Activity role '"+agentRole+" not found."); + } + } + } + + public void pushJobsToAgents(ItemPath itemPath, RolePath role) + { + if (role.hasJobList()) + new JobPusher(this, itemPath, role).start(); + Iterator childRoles = role.getChildren(); + while (childRoles.hasNext()) { + RolePath childRole = (RolePath)childRoles.next(); + pushJobsToAgents(itemPath, childRole); + } + } + + /** + * Returns the startDate. + * + * @return GTimeStamp + */ + public GTimeStamp getStateDate() + { + return mStateDate; + } + public void setStateDate(GTimeStamp startDate) + { + mStateDate = startDate; + } + + @Deprecated + public void setActiveDate(GTimeStamp date) + { } + @Deprecated + public void setStartDate(GTimeStamp date) + { + setStateDate(date); + } + + /** + * 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; + } + +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/AdvancementCalculator.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/AdvancementCalculator.java new file mode 100644 index 0000000..f040181 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/AdvancementCalculator.java @@ -0,0 +1,243 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +/* Created on 11 mars 2004 */ +package org.cristalise.kernel.lifecycle.instance; +import java.util.Hashtable; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.graph.model.Vertex; + +//import org.cristalise.kernel.utils.Logger; +/** @author XSeb74 */ +public class AdvancementCalculator +{ + private CompositeActivity activity; + private Hashtable isMarked; + private Hashtable HasNextMarked; + public Hashtable 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(); + HasNextMarked = new Hashtable(); + hasprevActive = new Hashtable(); + } + public void calculate(CompositeActivity act) throws InvalidDataException + { +// 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(); + 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) throws InvalidDataException + { + 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() || adv.hasprevActive.size()!=0; + } + else + { + current.mCurrentNbActExp += 1; + current.mMaximuNbActexp += 1; + if (act.isFinished()) + { + current.mNbActpassed += 1; + current.mNbActpassedWithCurrent += 1; + } + else if (act.getActive()) + { + current.mIsbranchActive = true; + current.mIsbranchFinished = false; + current.mHasPrevActive = true; + 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/org/cristalise/kernel/lifecycle/instance/AndSplit.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/AndSplit.java new file mode 100644 index 0000000..98e9afb --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/AndSplit.java @@ -0,0 +1,49 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.graph.model.Vertex; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; + +/** + * @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, ItemPath item) throws InvalidDataException + { + AdvancementCalculator adv = new AdvancementCalculator(); + adv.calculate((CompositeActivity) getParent()); + Vertex[] outVertices = getOutGraphables(); + for (Vertex outVertice : outVertices) + ((WfVertex) outVertice).run(agent, item); + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/CompositeActivity.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/CompositeActivity.java new file mode 100644 index 0000000..1bdfbe8 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/CompositeActivity.java @@ -0,0 +1,469 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; + +import java.util.ArrayList; + +import org.cristalise.kernel.common.AccessRightsException; +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidCollectionModification; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.InvalidTransitionException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.agent.Job; +import org.cristalise.kernel.graph.model.GraphModel; +import org.cristalise.kernel.graph.model.GraphPoint; +import org.cristalise.kernel.graph.model.GraphableVertex; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.InvalidAgentPathException; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.utils.Logger; + + +/** + * @version $Revision: 1.86 $ $Date: 2005/10/05 07:39:37 $ + * @author $Author: abranson $ + */ +public class CompositeActivity extends Activity +{ + + + /* + * -------------------------------------------- + * ----------------CONSTRUCTOR----------------- + * -------------------------------------------- + */ + public CompositeActivity() + { + super(); + setChildrenGraphModel(new GraphModel(new WfVertexOutlineCreator())); + setIsComposite(true); + } + + // State machine + public static final int START = 0; + public static final int COMPLETE = 1; + @Override + protected String getDefaultSMName() { + return "CompositeActivity"; + } + + @Override + public void setChildrenGraphModel(GraphModel childrenGraph) { + super.setChildrenGraphModel(childrenGraph); + childrenGraph.setVertexOutlineCreator(new WfVertexOutlineCreator()); + } + /** + * @see org.cristalise.kernel.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, GraphPoint point) + { + this.addChild(act, new GraphPoint(point.x, point.y)); + if (first) + { + getChildrenGraphModel().setStartVertexId(act.getID()); + Logger.msg(5, "org.cristalise.kernel.lifecycle.CompositeActivity :: " + getID() + " is first"); + } + } + + /** + * Method newChild. + * + * @param Name + * @param Type + * @param point + * @return WfVertex + */ + public WfVertex newExistingChild(Activity child, String Name, GraphPoint 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, GraphPoint point) + { + WfVertex v = newChild(Type, point); + v.setName(Name); + return v; + } + + /** + * Method newChild. + * + * @param vertexTypeId + * @param point + * @return WfVertex + */ + public WfVertex newChild(String vertexTypeId, GraphPoint 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, GraphPoint 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, GraphPoint 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, GraphPoint 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(GraphPoint point) + { + Join join = new Join(); + join.getProperties().put("Type", "Join"); + addChild(join, new GraphPoint(point.x, point.y)); + return join; + } + + public Join newRouteChild(GraphPoint 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; + } + + /** + * @throws InvalidDataException + * @throws ObjectNotFoundException + * @throws AccessRightsException + * @throws InvalidTransitionException + * @throws PersistencyException + * @throws ObjectAlreadyExistsException + * @throws ObjectCannotBeUpdated + * @see org.cristalise.kernel.lifecycle.instance.WfVertex#run() + */ + @Override + public void run(AgentPath agent, ItemPath itemPath) throws InvalidDataException + { + super.run(agent, itemPath); + if (getChildrenGraphModel().getStartVertex() != null && !getStateMachine().getState(state).isFinished()) + { + WfVertex first = (WfVertex) getChildrenGraphModel().getStartVertex(); + first.run(agent, itemPath); + } + } + + @Override + public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidDataException + { + if (!getStateMachine().getState(state).isFinished()) + try { + request(agent, itemPath, CompositeActivity.COMPLETE, null); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + Logger.error(e); // current agent couldn't complete the composite, so leave it + } + super.runNext(agent, itemPath); + } + + + /** + * @throws InvalidDataException + * @throws ObjectNotFoundException + * @throws InvalidAgentPathException + * @see org.cristalise.kernel.lifecycle.instance.Activity#calculateJobs() + */ + @Override + public ArrayList calculateJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws InvalidAgentPathException, ObjectNotFoundException, InvalidDataException + { + ArrayList jobs = new ArrayList(); + 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, itemPath, recurse)); + childActive |= child.active; + } + if (!childActive) + jobs.addAll(super.calculateJobs(agent, itemPath, recurse)); + return jobs; + } + + @Override + public ArrayList calculateAllJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws InvalidAgentPathException, ObjectNotFoundException, InvalidDataException + { + ArrayList jobs = new ArrayList(); + 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, itemPath, recurse)); + } + jobs.addAll(super.calculateAllJobs(agent, itemPath, 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 org.cristalise.kernel.lifecycle.instance.Activity#getType() + */ + @Override + public String getType() + { + return super.getType(); + } + + /** + * @throws InvalidDataException + * + */ + @Override + public void reinit(int idLoop) throws InvalidDataException + { + super.reinit(idLoop); + if (getChildrenGraphModel().getStartVertex() != null && !getStateMachine().getState(state).isFinished()) + ((WfVertex) getChildrenGraphModel().getStartVertex()).reinit(idLoop); + } + + @Override + public String request(AgentPath agent, ItemPath itemPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, InvalidCollectionModification + { + if (getChildrenGraphModel().getStartVertex() != null && !getStateMachine().getState(state).isFinished() && transitionID == CompositeActivity.START) + ((WfVertex) getChildrenGraphModel().getStartVertex()).run(agent, itemPath); + + return super.request(agent, itemPath, transitionID, requestData); + } + + public void refreshJobs(ItemPath itemPath) + { + GraphableVertex[] children = getChildren(); + for (GraphableVertex element : children) + if (element instanceof CompositeActivity) + ((CompositeActivity) element).refreshJobs(itemPath); + else if (element instanceof Activity) + ((Activity) element).pushJobsToAgents(itemPath); + } +} \ No newline at end of file diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/JobPusher.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/JobPusher.java new file mode 100644 index 0000000..9aeca42 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/JobPusher.java @@ -0,0 +1,81 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; + +import java.util.Iterator; + +import org.cristalise.kernel.entity.Agent; +import org.cristalise.kernel.entity.AgentHelper; +import org.cristalise.kernel.entity.agent.JobArrayList; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.lookup.Path; +import org.cristalise.kernel.lookup.RolePath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +final class JobPusher extends Thread { + private final Activity activity; + private final RolePath myRole; + private final ItemPath itemPath; + + JobPusher(Activity activity, ItemPath itemPath, RolePath role) { + this.activity = activity; + this.itemPath = itemPath; + this.myRole = role; + } + + @Override + public void run() + { + Thread.currentThread().setName("Agent job pusher for "+itemPath+":"+activity.getName()+" to role "+myRole); + for (Iterator e = myRole.getChildren(); e.hasNext();) + { + AgentPath nextAgent = (AgentPath)e.next(); + Logger.msg(7, "Activity.pushJobsToAgents() - Calculating jobs for " + nextAgent); + try + { + // get joblist for user + JobArrayList jobList = new JobArrayList(this.activity.calculateJobs(nextAgent, itemPath, false)); + Logger.msg(7, "Activity.pushJobsToAgents() - User will receive " + jobList.list.size() + " jobs"); + String stringJobs = Gateway.getMarshaller().marshall(jobList); + // push it to the agent + org.omg.CORBA.Object agentIOR = nextAgent.getIOR(); + Agent thisAgent = AgentHelper.narrow(agentIOR); + Logger.msg(7, "Calling agent "+thisAgent.getSystemKey()+" from "+activity.getPath()); + thisAgent.refreshJobList(itemPath.getSystemKey(), activity.getPath(), stringJobs); + } + catch (Exception ex) + { + Logger.error( + "Agent " + + nextAgent + + " of role " + + myRole + + " could not be found to be informed of a change in " + + itemPath); + Logger.error(ex); + } + } + + } +} \ No newline at end of file diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/Join.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/Join.java new file mode 100644 index 0000000..2d1f05c --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/Join.java @@ -0,0 +1,233 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; +import java.util.Vector; + +import org.cristalise.kernel.common.AccessRightsException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.InvalidTransitionException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.graph.model.Vertex; +import org.cristalise.kernel.graph.traversal.GraphTraversal; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; + +/** + * @version $Revision: 1.52 $ $Date: 2005/05/10 15:14:54 $ + * @author $Author: abranson $ + */ +public class Join extends WfVertex +{ + public Vector mErrors; + /** + * @see java.lang.Object#Object() + */ + public Join() + { + super(); + mErrors = new Vector(0, 1); + } + private boolean loopTested; + public int counter = 0; + + /** + * @throws InvalidDataException + * @throws ObjectNotFoundException + * @throws AccessRightsException + * @throws InvalidTransitionException + * @throws PersistencyException + * @throws ObjectAlreadyExistsException + * @throws ObjectCannotBeUpdated + * @see org.cristalise.kernel.lifecycle.instance.WfVertex#runNext() + */ + @Override + public void runNext(AgentPath agent, ItemPath item) throws InvalidDataException + { + 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, item); + } + else + super.runNext(agent, item); + } + } + /** + * Method addNext. + * + * @param idNext + */ + public void addNext(String idNext) + { + new Next(this, (WfVertex) getParent().search(idNext)); + } + /** + * @throws InvalidDataException + * @see org.cristalise.kernel.lifecycle.instance.WfVertex#reinit(int) + */ + @Override + public void reinit(int idLoop) throws InvalidDataException + { + Vertex[] outVertices = getOutGraphables(); + if (outVertices.length == 1) + { + WfVertex nextAct = (WfVertex) outVertices[0]; + nextAct.reinit(idLoop); + } + } + + @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 org.cristalise.kernel.lifecycle.instance.WfVertex#getErrors() + */ + @Override + public String getErrors() + { + if (mErrors.size() == 0) + return "No error"; + else + return mErrors.elementAt(0); + } + /** + * @throws InvalidDataException + * @throws ObjectNotFoundException + * @throws AccessRightsException + * @throws InvalidTransitionException + * @throws PersistencyException + * @throws ObjectAlreadyExistsException + * @throws ObjectCannotBeUpdated + * @see org.cristalise.kernel.lifecycle.instance.WfVertex#run() + */ + @Override + public void run(AgentPath agent, ItemPath item) throws InvalidDataException + { + runNext(agent, item); + } + /** + * @see org.cristalise.kernel.lifecycle.instance.WfVertex#addNext(org.cristalise.kernel.lifecycle.instance.WfVertex) + */ + @Override + public Next addNext(WfVertex vertex) + { + return new Next(this, vertex); + } + /** + * @see org.cristalise.kernel.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, ItemPath item) throws InvalidDataException + { + runNext(agent, item); + } + /* + * (non-Javadoc) + * + * @see org.cristalise.kernel.graph.model.Vertex#isJoin() + */ + @Override + public boolean isJoin() + { + return true; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/Loop.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/Loop.java new file mode 100644 index 0000000..d6a660e --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/Loop.java @@ -0,0 +1,130 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.graph.model.Vertex; +import org.cristalise.kernel.graph.traversal.GraphTraversal; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.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 org.cristalise.kernel.lifecycle.instance.WfVertex#loop() + */ + @Override + public boolean loop() + { + return true; + } + @Override + public void followNext(Next activeNext, AgentPath agent, ItemPath itemPath) throws InvalidDataException + { + WfVertex v = activeNext.getTerminusVertex(); + if (!isInPrev(v)) + v.run(agent, itemPath); + else + { + v.reinit(getID()); + v.run(agent, itemPath); + } + } + /** + * @throws InvalidDataException + * @see org.cristalise.kernel.lifecycle.instance.WfVertex#reinit(int) + */ + @Override + public void reinit(int idLoop) throws InvalidDataException + { + 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 org.cristalise.kernel.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/org/cristalise/kernel/lifecycle/instance/Next.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/Next.java new file mode 100644 index 0000000..e0df1e6 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/Next.java @@ -0,0 +1,103 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; + +import org.cristalise.kernel.graph.model.GraphPoint; +import org.cristalise.kernel.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/org/cristalise/kernel/lifecycle/instance/OrSplit.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/OrSplit.java new file mode 100644 index 0000000..12c7f46 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/OrSplit.java @@ -0,0 +1,90 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; +import java.util.StringTokenizer; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.graph.model.DirectedEdge; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.scripting.ScriptingEngineException; +import org.cristalise.kernel.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, ItemPath itemPath) throws InvalidDataException + { + String nexts; + String scriptName = (String) getProperties().get("RoutingScriptName"); + Integer scriptVersion = getVersionNumberProperty("RoutingScriptVersion"); + try { + nexts = this.evaluateScript(scriptName, scriptVersion, itemPath).toString(); + } catch (ScriptingEngineException e) { + Logger.error(e); + throw new InvalidDataException("Error running routing script "+scriptName+" v"+scriptVersion); + } + 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, itemPath); + 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 InvalidDataException("No nexts were activated!"); + } + + +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/Split.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/Split.java new file mode 100644 index 0000000..ac3afbd --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/Split.java @@ -0,0 +1,239 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; + +import java.util.Vector; + +import org.cristalise.kernel.common.AccessRightsException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.InvalidTransitionException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.graph.model.Vertex; +import org.cristalise.kernel.graph.traversal.GraphTraversal; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; + + +/** + * @version $Revision: 1.47 $ $Date: 2006/05/29 13:17:45 $ + * @author $Author: abranson $ + */ +public abstract class Split extends WfVertex +{ + public Vector mErrors; + + /** + * @see java.lang.Object#Object() + */ + public Split() + { + mErrors = new Vector(0, 1); + getProperties().put("RoutingScriptName", ""); + getProperties().put("RoutingScriptVersion", ""); + } + + private boolean loopTested; + + /** + * @throws InvalidDataException + * @throws ObjectNotFoundException + * @throws AccessRightsException + * @throws InvalidTransitionException + * @throws PersistencyException + * @throws ObjectAlreadyExistsException + * @throws ObjectCannotBeUpdated + * @see org.cristalise.kernel.lifecycle.instance.WfVertex#runNext() + */ + @Override + public abstract void runNext(AgentPath agent, ItemPath itemPath) throws InvalidDataException; + + /** + * Method addNext. + * + * @param idNext + */ + void addNext(String idNext) + { + new Next(this, (WfVertex) getParent().search(idNext)); + } + + /** + * @see org.cristalise.kernel.lifecycle.instance.WfVertex#addNext(org.cristalise.kernel.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; + } + + @Override + public void reinit(int idLoop) throws InvalidDataException + { + Vertex[] outVertices = getOutGraphables(); + for (Vertex outVertice : outVertices) + ((WfVertex) outVertice).reinit(idLoop); + } + + /** + * @see org.cristalise.kernel.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 org.cristalise.kernel.lifecycle.instance.WfVertex#getErrors() + */ + @Override + public String getErrors() + { + if (mErrors.size() == 0) + return "No error"; + else + return mErrors.elementAt(0); + } + + /** + * @throws InvalidDataException + * @throws ObjectNotFoundException + * @throws AccessRightsException + * @throws InvalidTransitionException + * @throws PersistencyException + * @throws ObjectAlreadyExistsException + * @throws ObjectCannotBeUpdated + * @see org.cristalise.kernel.lifecycle.instance.WfVertex#run() + */ + @Override + public void run(AgentPath agent, ItemPath itemPath) throws InvalidDataException + { + runNext(agent, itemPath); + } + + /** + * @see org.cristalise.kernel.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, ItemPath itemPath) throws InvalidDataException + { + runNext(agent, itemPath); + } + +} \ No newline at end of file diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/WfVertex.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/WfVertex.java new file mode 100644 index 0000000..d241aca --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/WfVertex.java @@ -0,0 +1,223 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; + + + +import java.util.HashMap; + +import org.cristalise.kernel.common.AccessRightsException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.InvalidTransitionException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.graph.model.GraphableVertex; +import org.cristalise.kernel.lifecycle.routingHelpers.ViewpointDataHelper; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.scripting.Script; +import org.cristalise.kernel.scripting.ScriptingEngineException; +import org.cristalise.kernel.utils.KeyValuePair; +import org.cristalise.kernel.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 + * @throws InvalidDataException + * @throws ObjectAlreadyExistsException + * @throws ObjectNotFoundException + * @throws AccessRightsException + * @throws InvalidTransitionException + * @throws PersistencyException + * @throws ObjectCannotBeUpdated */ + public abstract void runFirst(AgentPath agent, ItemPath itemPath) throws InvalidDataException; + + /** + * @see java.lang.Object#Object() + */ + public WfVertex() + { + super(); + setIsLayoutable(true); + setIsComposite(false); + } + + /** + * Method runNext. + * @throws InvalidDataException + * @throws ObjectNotFoundException + * @throws AccessRightsException + * @throws InvalidTransitionException + * @throws PersistencyException + * @throws ObjectAlreadyExistsException + * @throws ObjectCannotBeUpdated + */ + public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidDataException + { + try + { + ((CompositeActivity)getParent()).request(agent, itemPath, CompositeActivity.COMPLETE, null); + } + catch (Exception e) + { + //Logger.error(e); + } + + } + + /** + * Method reinit. + * @param idLoop + * @throws InvalidDataException + * @throws ObjectNotFoundException + */ + public abstract void reinit( int idLoop ) throws InvalidDataException; + + /** + * Method verify. + * @return boolean + */ + public abstract boolean verify(); + + /** + * Method getErrors. + * @return String + */ + public abstract String getErrors(); + + /** + * Method run. + * @throws InvalidDataException + * @throws ObjectAlreadyExistsException + * @throws ObjectNotFoundException + * @throws AccessRightsException + * @throws InvalidTransitionException + * @throws PersistencyException + * @throws ObjectCannotBeUpdated + */ + public abstract void run(AgentPath agent, ItemPath itemPath) throws InvalidDataException; + + /** + * Method loop. + * @return boolean + */ + public abstract boolean loop(); + + /** + * Method addNext. + * @param vertex + */ + public abstract Next addNext(WfVertex vertex); + + protected Object evaluateScript(String scriptName, Integer scriptVersion, ItemPath itemPath) throws ScriptingEngineException + { + + try + { + 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 = itemPath.getUUID() + 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(itemPath, ClusterStorage.PROPERTY+"/"+value, null); + } catch (ObjectNotFoundException ex) { + inputParam = null; + } + } + Logger.msg(5, "Split.evaluateScript() - Setting param " + element.getKey() + " to " + inputParam); + script.setInputParamValue(element.getKey(), inputParam); + } + } + + //TODO: is this right? + if (requiredInput.containsKey("item")) { + script.setInputParamValue("item", Gateway.getProxyManager().getProxy(itemPath)); + } + if (requiredInput.containsKey("agent")) { + AgentPath systemAgent = Gateway.getLookup().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, Integer version) throws ScriptingEngineException + { + if (name == null || name.length() == 0) + throw new ScriptingEngineException("Script name is empty"); + Script script; + if (version!=null) { + script = new Script(name, version); + } + else { // empty version: try expression + int split = name.indexOf(":"); + script = new Script(name.substring(0, split), name.substring(split + 1)); + } + + return script; + } + + + public Workflow getWf() + { + return ((CompositeActivity)getParent()).getWf(); + } +} + diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/WfVertexOutlineCreator.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/WfVertexOutlineCreator.java new file mode 100644 index 0000000..286ba64 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/WfVertexOutlineCreator.java @@ -0,0 +1,69 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; + +import org.cristalise.kernel.graph.model.GraphPoint; +import org.cristalise.kernel.graph.model.Vertex; +import org.cristalise.kernel.graph.model.VertexOutlineCreator; + +public class WfVertexOutlineCreator implements VertexOutlineCreator +{ + private static final int mActivityWidth = 130; + private static final int mActivityHeight = 60; + private static final int mSplitJoinWidth = 60; + private static 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/org/cristalise/kernel/lifecycle/instance/Workflow.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/Workflow.java new file mode 100644 index 0000000..c2f632a --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/Workflow.java @@ -0,0 +1,266 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; +import java.util.ArrayList; + +import org.cristalise.kernel.common.AccessRightsException; +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidCollectionModification; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.InvalidTransitionException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.C2KLocalObject; +import org.cristalise.kernel.entity.agent.Job; +import org.cristalise.kernel.events.History; +import org.cristalise.kernel.graph.model.GraphPoint; +import org.cristalise.kernel.graph.model.TypeNameAndConstructionInfo; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStepContainer; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.InvalidAgentPathException; +import org.cristalise.kernel.lookup.InvalidItemPathException; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.utils.Language; +import org.cristalise.kernel.utils.Logger; + +/** + * @version $Revision: 1.64 $ $Date: 2005/09/30 07:09:48 $ + * @author $Author: abranson $ + */ +public class Workflow extends CompositeActivity implements C2KLocalObject +{ + public History history; + private ItemPath itemPath = null; + + /** 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("Activity"), "Atomic"), + new TypeNameAndConstructionInfo(Language.translate("Composite"), "Composite") + }; + private final TypeNameAndConstructionInfo[] mEdgeTypeNameAndConstructionInfo = + { + new TypeNameAndConstructionInfo(Language.translate("Next"), "Next") + }; + /** + * @see java.lang.Object#Object() + */ + public Workflow() + { + } + + public Workflow(CompositeActivity domain, PredefinedStepContainer predef) { + this(); + domain.setName("domain"); + initChild(domain, true, new GraphPoint(150, 100)); + addChild(predef, new GraphPoint(300, 100)); + } + + public History getHistory() throws InvalidDataException { + if (history == null) { + if (itemPath == null) + throw new InvalidDataException("Workflow not initialized."); + history = new History(itemPath, this); + } + return history; + } + + /** + * 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 + * @throws PersistencyException + * @throws ObjectCannotBeUpdated + * @throws CannotManageException + * @throws InvalidCollectionModification + */ + //requestData is xmlstring + public String requestAction(AgentPath agent, String stepPath, ItemPath itemPath, int transitionID, String requestData) + throws ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, PersistencyException, ObjectCannotBeUpdated, CannotManageException, InvalidCollectionModification + { + Logger.msg(3, "Action: " + transitionID + " " + stepPath + " by " + agent); + if (search(stepPath) != null) + return ((Activity) search(stepPath)).request(agent, itemPath, transitionID, requestData); + else + throw new ObjectNotFoundException(stepPath + " not found"); + } + + /** + * @see org.cristalise.kernel.graph.model.GraphableVertex#getPath() + */ + @Override + public String getPath() + { + return "workflow"; + } + /** + * @see org.cristalise.kernel.graph.model.Vertex#getName() + */ + @Override + public String getName() + { + return "workflow"; + } + /** + * @see org.cristalise.kernel.lifecycle.instance.Activity#getType() + */ + @Override + public String getType() + { + return "workflow"; + } + /** + * @see org.cristalise.kernel.graph.model.Vertex#setName(java.lang.String) + */ + @Override + public void setName(String name) + { + } + /** + * @see org.cristalise.kernel.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 org.cristalise.kernel.lifecycle.instance.Activity#getWf() + */ + @Override + public Workflow getWf() + { + return this; + } + /** + * Method initialise. + * + * @param systemKey + * @throws InvalidDataException + * @throws ObjectNotFoundException + * @throws AccessRightsException + * @throws InvalidTransitionException + * @throws ObjectAlreadyExistsException + * @throws ObjectCannotBeUpdated + */ + public void initialise(ItemPath itemPath, AgentPath agent) throws InvalidDataException + { + setItemPath(itemPath); + runFirst(agent, itemPath); + } + + public ItemPath getItemPath() { + return itemPath; + } + + public void setItemPath(ItemPath itemPath) { + this.itemPath = itemPath; + } + + public void setItemUUID( String uuid ) throws InvalidItemPathException + { + setItemPath(new ItemPath(uuid)); + } + + public String getItemUUID() { + return getItemPath().getUUID().toString(); + } + + /** + * if type = 0 only domain steps will be queried if type = 1 only predefined steps will be queried else both will be queried + * @param agent + * @param itemSysKey + * @param type + * @return + * @throws ObjectNotFoundException + * @throws InvalidDataException + * @throws InvalidAgentPathException + */ + public ArrayList calculateJobs(AgentPath agent, ItemPath itemPath, int type) throws InvalidAgentPathException, ObjectNotFoundException, InvalidDataException + { + ArrayList jobs = new ArrayList(); + if (type != 1) + jobs.addAll(((CompositeActivity) search("workflow/domain")).calculateJobs(agent, itemPath, true)); + if (type != 0) + jobs.addAll(((CompositeActivity) search("workflow/predefined")).calculateJobs(agent, itemPath, true)); + return jobs; + } + /** + * @see org.cristalise.kernel.lifecycle.instance.CompositeActivity#hasGoodNumberOfActivity() + */ + @Override + public boolean hasGoodNumberOfActivity() + { + return true; + } + /** + * @see org.cristalise.kernel.entity.C2KLocalObject#getClusterType() + */ + @Override + public String getClusterType() + { + return ClusterStorage.LIFECYCLE; + } + +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/XOrSplit.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/XOrSplit.java new file mode 100644 index 0000000..91719cd --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/XOrSplit.java @@ -0,0 +1,84 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance; + +import java.util.ArrayList; +import java.util.StringTokenizer; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.graph.model.DirectedEdge; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.scripting.ScriptingEngineException; +import org.cristalise.kernel.utils.Logger; + + +/** + * @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, ItemPath itemPath) throws InvalidDataException + { + ArrayList nextsToFollow = new ArrayList(); + String nexts; + String scriptName = (String) getProperties().get("RoutingScriptName"); + Integer scriptVersion = getVersionNumberProperty("RoutingScriptVersion"); + try { + nexts = this.evaluateScript(scriptName, scriptVersion, itemPath).toString(); + } catch (ScriptingEngineException e) { + Logger.error(e); + throw new InvalidDataException("Error running routing script "+scriptName+" v"+scriptVersion); + } + + StringTokenizer tok = new StringTokenizer(nexts,","); + String[] nextsTab = new String[tok.countTokens()]; + for (int i=0;i 2) + props = (CastorHashMap)Gateway.getMarshaller().unmarshall(params[2]); + + } catch (Exception e) { + throw new InvalidDataException("AddMemberToCollection: Invalid parameters "+Arrays.toString(params)); + } + + // load collection + C2KLocalObject collObj; + collObj = Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + if (!(collObj instanceof Dependency)) throw new InvalidDataException("AddMemberToCollection: AddMemberToCollection operates on Dependency collections only."); + dep = (Dependency)collObj; + + // find member and assign entity + if (props == null) + dep.addMember(newChild); + else + dep.addMember(newChild, props, null); + + Gateway.getStorage().put(newChild, dep, null); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java new file mode 100644 index 0000000..b230284 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java @@ -0,0 +1,110 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.AggregationDescription; +import org.cristalise.kernel.collection.CollectionDescription; +import org.cristalise.kernel.collection.DependencyDescription; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.8 $ + **************************************************************************/ +public class AddNewCollectionDescription extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castor + **************************************************************************/ + public AddNewCollectionDescription() + { + super(); + } + + + /** + * Generates a new empty collection description. Collection instances should + * be added by an Admin, who can do so using AddC2KObject. + * + * Params: + * 0 - collection name + * 1 - collection type (Aggregation, Dependency) + * @throws PersistencyException + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectAlreadyExistsException, PersistencyException { + + String collName; + String collType; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AddNewCollectionDescription: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 2) + throw new InvalidDataException("AddNewCollectionDescription: Invalid parameters "+Arrays.toString(params)); + + collName = params[0]; + collType = params[1]; + + // check if collection already exists + try { + Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + throw new ObjectAlreadyExistsException("Collection '"+collName+"' already exists"); + } catch (ObjectNotFoundException ex) { + // collection doesn't exist + } catch (PersistencyException ex) { + Logger.error(ex); + throw new PersistencyException("AddNewCollectionDescription: Error checking for collection '"+collName+"': "+ex.getMessage()); + } + + + CollectionDescription newCollDesc; + + if (collType.equals("Aggregation")) + newCollDesc = new AggregationDescription(collName); + if (collType.equals("Dependency")) + newCollDesc = new DependencyDescription(collName); + else + throw new InvalidDataException("AddNewCollectionDescription: Invalid collection type specified: '"+collType+"'. Must be Aggregation or Dependency."); + + // store it + try { + Gateway.getStorage().put(item, newCollDesc, null); + } catch (PersistencyException e) { + throw new PersistencyException("AddNewCollectionDescription: Error saving new collection '"+collName+"': "+e.getMessage()); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewSlot.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewSlot.java new file mode 100644 index 0000000..f3acdf3 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewSlot.java @@ -0,0 +1,128 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.Aggregation; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.C2KLocalObject; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.property.PropertyDescription; +import org.cristalise.kernel.property.PropertyDescriptionList; +import org.cristalise.kernel.property.PropertyUtility; +import org.cristalise.kernel.utils.CastorHashMap; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.8 $ + **************************************************************************/ +public class AddNewSlot extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castor + **************************************************************************/ + public AddNewSlot() + { + super(); + } + + + /** + * Creates a new slot in the given aggregation, that holds instances of the given item description + * + * Params: + *
  1. Collection name
  2. + *
  3. Item Description key (optional)
  4. + *
  5. Item Description version (optional)
  6. + *
+ * + * @throws InvalidDataException Then the parameters were incorrect + * @throws PersistencyException There was a problem loading or saving the collection from persistency + * @throws ObjectNotFoundException A required object, such as the collection or a PropertyDescription outcome, wasn't found + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, PersistencyException, ObjectNotFoundException { + + String collName; + ItemPath descKey = null; + String descVer = "last"; + Aggregation agg; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AddNewSlot: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + // resolve desc item path and version + try { + collName = params[0]; + if (params.length > 1 && params[1].length() > 0) descKey = new ItemPath(params[1]); + if (params.length > 2 && params[2].length() > 0) descVer = params[2]; + } catch (Exception e) { + throw new InvalidDataException("AddNewSlot: Invalid parameters "+Arrays.toString(params)); + } + + // load collection + C2KLocalObject collObj; + try { + collObj = Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + } catch (PersistencyException ex) { + Logger.error(ex); + throw new PersistencyException("AddNewSlot: Error loading collection '\"+collName+\"': "+ex.getMessage()); + } + if (!(collObj instanceof Aggregation)) throw new InvalidDataException("AddNewSlot: AddNewSlot operates on Aggregation collections only."); + agg = (Aggregation)collObj; + + // get props + CastorHashMap props = new CastorHashMap(); + StringBuffer classProps = new StringBuffer(); + if (descKey != null) { + PropertyDescriptionList propList; + propList = PropertyUtility.getPropertyDescriptionOutcome(descKey, descVer); + for (PropertyDescription pd : propList.list) { + props.put(pd.getName(), pd.getDefaultValue()); + if (pd.getIsClassIdentifier()) + classProps.append((classProps.length()>0?",":"")).append(pd.getName()); + } + } + + agg.addSlot(props, classProps.toString()); + + try { + Gateway.getStorage().put(item, agg, null); + } catch (PersistencyException e) { + Logger.error(e); + throw new PersistencyException("AddNewSlot: Error saving collection '"+collName+"': "+e.getMessage()); + } + + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AssignItemToSlot.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AssignItemToSlot.java new file mode 100644 index 0000000..c242500 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AssignItemToSlot.java @@ -0,0 +1,121 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.Aggregation; +import org.cristalise.kernel.collection.AggregationMember; +import org.cristalise.kernel.common.InvalidCollectionModification; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.C2KLocalObject; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.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 + * @throws ObjectNotFoundException + * @throws PersistencyException + * @throws ObjectCannotBeUpdated + * @throws InvalidCollectionModification + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectCannotBeUpdated, InvalidCollectionModification { + + String collName; + int slotNo; + ItemPath childItem; + Aggregation agg; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AssignItemToSlot: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + try { + collName = params[0]; + slotNo = Integer.parseInt(params[1]); + childItem = new ItemPath(params[2]); + } catch (Exception e) { + throw new InvalidDataException("AssignItemToSlot: Invalid parameters "+Arrays.toString(params)); + } + + // load collection + C2KLocalObject collObj; + try { + collObj = Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + } catch (PersistencyException ex) { + Logger.error(ex); + throw new PersistencyException("AssignItemToSlot: Error loading collection '\"+collName+\"': "+ex.getMessage()); + } + if (!(collObj instanceof Aggregation)) throw new InvalidDataException("AssignItemToSlot: AssignItemToSlot operates on Aggregation collections only."); + agg = (Aggregation)collObj; + + // find member and assign entity + boolean stored = false; + for (AggregationMember member : agg.getMembers().list) { + if (member.getID() == slotNo) { + if (member.getItemPath() != null) + throw new ObjectCannotBeUpdated("AssignItemToSlot: Member slot "+slotNo+" not empty"); + member.assignItem(childItem); + stored = true; + break; + } + } + if (!stored) { + throw new ObjectNotFoundException("AssignItemToSlot: Member slot "+slotNo+" not found."); + } + + try { + Gateway.getStorage().put(item, agg, null); + } catch (PersistencyException e) { + throw new PersistencyException("AssignItemToSlot: Error saving collection '"+collName+"': "+e.getMessage()); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ClearSlot.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ClearSlot.java new file mode 100644 index 0000000..bd0fa19 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ClearSlot.java @@ -0,0 +1,114 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.Aggregation; +import org.cristalise.kernel.collection.AggregationMember; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.8 $ + **************************************************************************/ +public class ClearSlot extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castor + **************************************************************************/ + public ClearSlot() + { + super(); + } + + + /** + * Params: + * 0 - collection name + * 1 - slot number + * @throws ObjectNotFoundException + * @throws PersistencyException + * @throws ObjectCannotBeUpdated + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectCannotBeUpdated { + + String collName; + int slotNo; + Aggregation agg; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "ClearSlot: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + try { + collName = params[0]; + slotNo = Integer.parseInt(params[1]); + } catch (Exception e) { + throw new InvalidDataException("ClearSlot: Invalid parameters "+Arrays.toString(params)); + } + + // load collection + try { + agg = (Aggregation)Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + } catch (PersistencyException ex) { + Logger.error(ex); + throw new PersistencyException("ClearSlot: Error loading collection '"+collName+"': "+ex.getMessage()); + } + + // find member and clear + boolean stored = false; + for (AggregationMember member : agg.getMembers().list) { + if (member.getID() == slotNo) { + if (member.getItemPath() != null) + throw new ObjectCannotBeUpdated("ClearSlot: Member slot "+slotNo+" already empty"); + member.clearItem(); + stored = true; + break; + } + } + if (!stored) { + throw new ObjectNotFoundException("ClearSlot: Member slot "+slotNo+" not found."); + } + + + try { + Gateway.getStorage().put(item, agg, null); + } catch (PersistencyException e) { + Logger.error(e); + throw new PersistencyException("ClearSlot: Error storing collection"); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/CreateNewCollectionVersion.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/CreateNewCollectionVersion.java new file mode 100644 index 0000000..a598044 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/CreateNewCollectionVersion.java @@ -0,0 +1,103 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.Collection; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.8 $ + **************************************************************************/ +public class CreateNewCollectionVersion extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castor + **************************************************************************/ + public CreateNewCollectionVersion() + { + super(); + } + + + /** + * Generates a new snapshot of a collection from its current state. The + * new version is given the next available number, starting at 0. + * + * Params: + * 0 - Collection name + * @throws InvalidDataException + * @throws PersistencyException + * + * @throws ObjectNotFoundException when there is no collection present with + * that name + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, PersistencyException, ObjectNotFoundException + { + String collName; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "CreateNewCollectionVersion: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) + throw new InvalidDataException("CreateNewCollectionVersion: Invalid parameters "+Arrays.toString(params)); + + collName = params[0]; + Collection coll = (Collection)Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + + // find last numbered version + int lastVer = -1; + String[] versions = Gateway.getStorage().getClusterContents(item, ClusterStorage.COLLECTION+"/"+collName); + for (String thisVerStr : versions) { + try { + int thisVer = Integer.parseInt(thisVerStr); + if (thisVer > lastVer) lastVer = thisVer; + } catch (NumberFormatException ex) { } // ignore non-integer versions + } + + // Remove it from the cache before we change it + Gateway.getStorage().clearCache(item, ClusterStorage.COLLECTION+"/"+collName+"/last"); + // Set the version + coll.setVersion(lastVer+1); + + // store it + try { + Gateway.getStorage().put(item, coll, null); + } catch (PersistencyException e) { + throw new PersistencyException("CreateNewCollectionVersion: Error saving new collection '"+collName+"': "+e.getMessage()); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/Import.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/Import.java new file mode 100644 index 0000000..26e015d --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/Import.java @@ -0,0 +1,106 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; + +import java.util.Arrays; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.events.Event; +import org.cristalise.kernel.events.History; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.TransactionManager; +import org.cristalise.kernel.persistency.outcome.Outcome; +import org.cristalise.kernel.persistency.outcome.Viewpoint; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * $Revision: 1.21 $ + * $Date: 2005/06/02 12:17:22 $ + * + * Params: Schemaname_version:Viewpoint (optional), Outcome, Timestamp (optional + * + * Copyright (C) 2003 CERN - European Organization for Nuclear Research + * All rights reserved. + **************************************************************************/ +public class Import extends PredefinedStep +{ + public Import() + { + super(); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, PersistencyException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "Import: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + int split1 = params[0].indexOf('_'); + int split2 = params[0].indexOf(':'); + + if (split1 == -1) + throw new InvalidDataException("Import: Invalid parameters "+Arrays.toString(params)); + + requestData = params[1]; + + String schemaName = params[0].substring(0, split1); + String viewpoint = null; + 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)); + + String timestamp; + if (params.length == 3) + timestamp = params[2]; + else + timestamp = Event.timeToString(Event.getGMT()); + + // write event, outcome and viewpoints to storage + + TransactionManager storage = Gateway.getStorage(); + Object locker = getWf(); + History hist = getWf().getHistory(); + Event event = hist.addEvent(agent, getCurrentAgentRole(), getName(), getPath(), getType(), schemaName, schemaVersion, getStateMachine().getName(), getStateMachine().getVersion(), getStateMachine().getTransition(transitionID), viewpoint, timestamp); + + try { + storage.put(item, new Outcome(event.getID(), requestData, schemaName, schemaVersion), locker); + storage.put(item, new Viewpoint(item, schemaName, viewpoint, schemaVersion, event.getID()), locker); + if (!"last".equals(viewpoint)) + storage.put(item, new Viewpoint(item, schemaName, "last", schemaVersion, event.getID()), locker); + } catch (PersistencyException e) { + storage.abort(locker); + throw e; + } + storage.commit(locker); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStep.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStep.java new file mode 100644 index 0000000..c8a293e --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStep.java @@ -0,0 +1,191 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; +import java.io.StringReader; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.cristalise.kernel.lifecycle.instance.Activity; +import org.cristalise.kernel.lifecycle.instance.predefined.agent.AgentPredefinedStepContainer; +import org.cristalise.kernel.lifecycle.instance.predefined.item.ItemPredefinedStepContainer; +import org.cristalise.kernel.lifecycle.instance.predefined.server.ServerPredefinedStepContainer; +import org.cristalise.kernel.persistency.outcome.Outcome; +import org.cristalise.kernel.utils.Logger; +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; + +/*********************************************************************************************************************************************************************************************************************************************************************************************************** + * @author $Author: sgaspard $ $Date: 2004/09/21 10:32:17 $ + * @version $Revision: 1.14 $ + **********************************************************************************************************************************************************************************************************************************************************************************************************/ +public abstract class PredefinedStep extends Activity +{ + /******************************************************************************************************************************************************************************************************************************************************************************************************* + * predefined Steps are always Active, and have only one transition subclasses could override this method (if necessary) + ******************************************************************************************************************************************************************************************************************************************************************************************************/ + + private boolean isPredefined = false; + public static final int DONE = 0; + public static final int AVAILABLE = 0; + + public PredefinedStep() { + super(); + getProperties().put("SchemaType", "PredefinedStepOutcome"); + getProperties().put("SchemaVersion", "0"); + } + + @Override + public boolean getActive() + { + if (isPredefined) + return true; + else + return super.getActive(); + } + + + + @Override + protected String getDefaultSMName() { + return "PredefinedStep"; + } + + @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(); + } + + static public String getPredefStepSchemaName(String stepName) { + PredefinedStepContainer[] allSteps = { new ItemPredefinedStepContainer(), new AgentPredefinedStepContainer(), new ServerPredefinedStepContainer() }; + for (PredefinedStepContainer thisContainer : allSteps) { + String stepPath = thisContainer.getName()+"/"+stepName; + Activity step = (Activity)thisContainer.search(stepPath); + if (step != null) { + return (String)step.getProperties().get("SchemaType"); + } + } + return "PredefinedStepOutcome"; // default to standard if not found - server may be a newer version + } + + // 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); + } + + return Outcome.serialize(dom, false); + + } + catch (Exception e) + { + Logger.error(e); + StringBuffer xmlData = new StringBuffer().append(""); + for (String element : data) + xmlData.append(""); + xmlData.append(""); + return xmlData.toString(); + } + } + + // generic bundling of single parameter + static public String bundleData(String data) + { + return bundleData(new String[]{ data }); + } + + public static 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/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStepContainer.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStepContainer.java new file mode 100644 index 0000000..74a86db --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStepContainer.java @@ -0,0 +1,79 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; +import org.cristalise.kernel.graph.model.GraphPoint; +import org.cristalise.kernel.lifecycle.instance.CompositeActivity; +public abstract 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("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("ReplaceDomainWorkflow", "Replaces the domain CA with the supplied one. Used by the GUI to save new Wf layout", new ReplaceDomainWorkflow()); + predInit("AddC2KObject", "Adds or overwrites a C2Kernel object for this Item", new AddC2KObject()); + predInit("RemoveC2KObject", "Removes the named C2Kernel object from this Item.", new RemoveC2KObject()); + predInit("WriteProperty", "Writes a property to the Item", new WriteProperty()); + predInit("WriteViewpoint", "Writes a viewpoint to the Item", new WriteViewpoint()); + predInit("AddNewCollectionDescription", "Creates a new collection description in this Item", new AddNewCollectionDescription()); + predInit("CreateNewCollectionVersion", "Creates a new numbered collection version in this Item from the current one.", new CreateNewCollectionVersion()); + predInit("AddNewSlot", "Creates a new slot in the given aggregation, that holds instances of the item description of the given key", new AddNewSlot()); + predInit("AssignItemToSlot", "Assigns the referenced entity to a pre-existing slot in an aggregation", new AssignItemToSlot()); + predInit("ClearSlot", "Clears an aggregation member slot, given a slot no or entity key", new ClearSlot()); + predInit("RemoveSlotFromCollection", "Removed the given slot from the aggregation", new RemoveSlotFromCollection()); + predInit("AddMemberToCollection", "Creates a new member slot for the given item in a dependency, and assigns the item", new AddMemberToCollection()); + 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.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; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveC2KObject.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveC2KObject.java new file mode 100644 index 0000000..2f86274 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveC2KObject.java @@ -0,0 +1,70 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; + + + +import java.util.Arrays; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2005/11/15 15:56:38 $ + * @version $Revision: 1.28 $ + **************************************************************************/ +public class RemoveC2KObject extends PredefinedStep +{ + public RemoveC2KObject() + { + super(); + getProperties().put("Agent Role", "Admin"); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, PersistencyException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "RemoveC2KObject: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) + throw new InvalidDataException("RemoveC2KObject: Invalid parameters "+Arrays.toString(params)); + String path = params[0]; + + try + { + Gateway.getStorage().remove( item, path, null ); + } + catch( PersistencyException ex ) + { + throw new PersistencyException("RemoveC2KObject: Error removing object '"+path+"': "+ex.getMessage()); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveDomainPath.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveDomainPath.java new file mode 100644 index 0000000..0dc24bb --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveDomainPath.java @@ -0,0 +1,73 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; + + + + +import java.util.Arrays; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.lookup.LookupManager; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class RemoveDomainPath extends PredefinedStep +{ + public RemoveDomainPath() + { + super(); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "RemoveDomainPath: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidDataException("RemoveDomainPath: Invalid parameters "+Arrays.toString(params)); + + DomainPath domainPath = new DomainPath(params[0]); + if (!domainPath.exists()) + throw new ObjectNotFoundException("RemoveDomainPath: Domain path "+domainPath.toString()+" does not exist."); + + if (domainPath.getType()!=DomainPath.ENTITY) + + try { + if (!domainPath.getItemPath().equals(item)) + throw new InvalidDataException("RemoveDomainPath: Domain path "+domainPath.toString()+" is not an alias of the current Item "+item); + } catch (ObjectNotFoundException ex) { + throw new InvalidDataException("RemoveDomainPath: Domain path "+domainPath.toString()+" is a context."); + } + + LookupManager lookupManager = Gateway.getLookupManager(); + lookupManager.delete(domainPath); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java new file mode 100644 index 0000000..6522384 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java @@ -0,0 +1,131 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.Collection; +import org.cristalise.kernel.collection.CollectionMember; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.8 $ + **************************************************************************/ +public class RemoveSlotFromCollection extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castor + **************************************************************************/ + public RemoveSlotFromCollection() + { + super(); + } + + + /** + * Params: + * 0 - collection name + * 1 - slot number OR if null: + * 2 - target entity key + * @throws ObjectNotFoundException + * @throws PersistencyException + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, PersistencyException { + + String collName; + int slotNo = -1; + ItemPath currentChild = null; + Collection coll; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "RemoveSlotFromCollection: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + try { + collName = params[0]; + if (params.length>1 && params[1].length()>0) slotNo = Integer.parseInt(params[1]); + if (params.length>2 && params[2].length()>0) currentChild = new ItemPath(params[2]); + } catch (Exception e) { + throw new InvalidDataException("RemoveSlotFromCollection: Invalid parameters "+Arrays.toString(params)); + } + + if (slotNo == -1 && currentChild == null) + throw new InvalidDataException("RemoveSlotFromCollection: Must give either slot number or entity key"); + + // load collection + try { + coll = (Collection)Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + } catch (PersistencyException ex) { + Logger.error(ex); + throw new PersistencyException("RemoveSlotFromCollection: Error loading collection '\"+collName+\"': "+ex.getMessage()); + } + + // check the slot is there if it's given by id + CollectionMember slot = null; + if (slotNo > -1) { + slot = coll.getMember(slotNo); + } + + // if both parameters are supplied, check the given item is actually in that slot + if (slot != null && currentChild != null && !slot.getItemPath().equals(currentChild)) { + throw new ObjectNotFoundException("RemoveSlotFromCollection: Item "+currentChild+" was not in slot "+slotNo); + } + + if (slotNo == -1) { // find slot from entity key + for (CollectionMember member : coll.getMembers().list) { + if (member.getItemPath().equals(currentChild)) { + slotNo = member.getID(); + break; + } + } + } + if (slotNo == -1) { + throw new ObjectNotFoundException("Could not find "+currentChild+" in collection "+coll.getName()); + } + + // Remove the slot + coll.removeMember(slotNo); + + // Store the collection + try { + Gateway.getStorage().put(item, coll, null); + } catch (PersistencyException e) { + Logger.error(e); + throw new PersistencyException("Error storing collection"); + } + + return requestData; + + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java new file mode 100644 index 0000000..5ec7510 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java @@ -0,0 +1,77 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; + +//Java +import java.util.Arrays; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.graph.model.GraphPoint; +import org.cristalise.kernel.lifecycle.instance.CompositeActivity; +import org.cristalise.kernel.lifecycle.instance.Workflow; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class ReplaceDomainWorkflow extends PredefinedStep +{ + public ReplaceDomainWorkflow() + { + super(); + getProperties().put("Agent Role", "Admin"); + } + + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, PersistencyException { + + Workflow lifeCycle = getWf(); + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AddC2KObject: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidDataException("AddC2KObject: Invalid parameters "+Arrays.toString(params)); + + lifeCycle.getChildGraphModel().removeVertex(lifeCycle.search("workflow/domain")); + CompositeActivity domain; + try { + domain = (CompositeActivity) Gateway.getMarshaller().unmarshall(params[0]); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("ReplaceDomainWorkflow: Could not unmarshall new workflow: "+e.getMessage()); + } + domain.setName("domain"); + lifeCycle.initChild(domain, true, new GraphPoint(150, 100)); + // if new workflow, activate it, otherwise refresh the jobs + if (!domain.active) lifeCycle.run(agent, item); + else lifeCycle.refreshJobs(item); + + // store new wf + try { + Gateway.getStorage().put(item, lifeCycle, null); + } catch (PersistencyException e) { + throw new PersistencyException("ReplaceDomainWorkflow: Could not write new workflow to storage: "+e.getMessage()); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteProperty.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteProperty.java new file mode 100644 index 0000000..c73bec8 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteProperty.java @@ -0,0 +1,80 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; + +import java.util.Arrays; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.property.Property; +import org.cristalise.kernel.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 + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectCannotBeUpdated, ObjectNotFoundException, PersistencyException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "WriteProperty: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + if (params.length != 2) + throw new InvalidDataException("WriteProperty: invalid parameters "+Arrays.toString(params)); + + String name = params[0]; + String newValue = params[1]; + + Property prop; + + try { + prop = (Property)Gateway.getStorage().get(item, ClusterStorage.PROPERTY+"/"+name, null); + if (!prop.isMutable() && !newValue.equals(prop.getValue())) + throw new ObjectCannotBeUpdated("WriteProperty: Property '"+name+"' is not mutable."); + prop.setValue(newValue); + Gateway.getStorage().put(item, prop, null); + } catch (ObjectNotFoundException e) { + throw new ObjectNotFoundException("WriteProperty: Property '"+name+"' not found."); + } + + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteViewpoint.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteViewpoint.java new file mode 100644 index 0000000..d617b99 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteViewpoint.java @@ -0,0 +1,88 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined; + +import java.util.Arrays; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.events.Event; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.persistency.outcome.Viewpoint; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class WriteViewpoint extends PredefinedStep { + + public WriteViewpoint() { + super(); + } + + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, PersistencyException { + + String schemaName; + String viewName; + int evId; + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "WriteViewpoint: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + // outcometype, name and evId. Event and Outcome should be checked so schema version should be discovered. + if (params.length != 3) + throw new InvalidDataException("WriteViewpoint: Invalid parameters "+Arrays.toString(params)); + + schemaName = params[0]; + viewName = params[1]; + + try { + evId = Integer.parseInt(params[2]); + } catch (NumberFormatException ex) { + throw new InvalidDataException("WriteViewpoint: Parameter 3 (EventId) must be an integer"); + } + + // Find event + + Event ev; + try { + ev = (Event)Gateway.getStorage().get(item, ClusterStorage.HISTORY+"/"+evId, null); + } catch (PersistencyException e) { + Logger.error(e); + throw new PersistencyException("WriteViewpoint: Could not load event "+evId); + } + + // Write new viewpoint + Viewpoint newView = new Viewpoint(item, schemaName, viewName, ev.getSchemaVersion(), evId); + try { + Gateway.getStorage().put(item, newView, null); + } catch (PersistencyException e) { + Logger.error(e); + throw new PersistencyException("WriteViewpoint: Could not store new viewpoint"); + } + return requestData; + } + +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/AgentPredefinedStepContainer.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/AgentPredefinedStepContainer.java new file mode 100644 index 0000000..6ff3164 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/AgentPredefinedStepContainer.java @@ -0,0 +1,47 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined.agent; + +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStepContainer; + + +/************************************************************************** + * + * $Revision: 1.2 $ + * $Date: 2005/06/02 10:19:33 $ + * + * Copyright (C) 2003 CERN - European Organization for Nuclear Research + * All rights reserved. + **************************************************************************/ + +public class AgentPredefinedStepContainer extends PredefinedStepContainer { + + + @Override + public void createChildren() + { + super.createChildren(); + predInit("CreateAgentFromDescription", "Create a new item using this item as its description", new CreateAgentFromDescription()); + predInit("RemoveAgent", "Deletes the Agent", new RemoveAgent()); + predInit("SetAgentPassword", "Changes the Agent's password", new SetAgentPassword()); + predInit("SetAgentRoles", "Sets the roles of the Agent", new SetAgentRoles()); + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java new file mode 100644 index 0000000..335fe2d --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java @@ -0,0 +1,137 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined.agent; + +import java.util.Arrays; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.CorbaServer; +import org.cristalise.kernel.entity.agent.ActiveEntity; +import org.cristalise.kernel.lifecycle.instance.predefined.item.CreateItemFromDescription; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.lookup.RolePath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.property.PropertyArrayList; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2005/10/13 08:13:58 $ + * @version $Revision: 1.47 $ + **************************************************************************/ +public class CreateAgentFromDescription extends CreateItemFromDescription +{ + public CreateAgentFromDescription() + { + super(); + } + + /** + * Params: + *
  1. New Agent name
  2. + *
  3. Description version to use
  4. + *
  5. Comma-delimited Role names to assign to the agent. Must already exist.
  6. + *
  7. Initial properties to set in the new Agent
  8. + *
+ * @throws ObjectNotFoundException + * @throws InvalidDataException The input parameters were incorrect + * @throws ObjectAlreadyExistsException The Agent already exists + * @throws CannotManageException The Agent could not be created + * @throws ObjectCannotBeUpdated The addition of the new entries into the LookupManager failed + * @see org.cristalise.kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(org.cristalise.kernel.lookup.AgentPath, int, int, java.lang.String) + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws ObjectNotFoundException, InvalidDataException, ObjectAlreadyExistsException, CannotManageException, ObjectCannotBeUpdated { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "CreateAgentFromDescription: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length < 3 || params.length > 4) + throw new InvalidDataException("CreateAgentFromDescription: Invalid parameters "+Arrays.toString(params)); + + String newName = params[0]; + String descVer = params[1]; + String roles = params[2]; + PropertyArrayList initProps = + params.length > 3 ? getInitProperties(params[3]):new PropertyArrayList(); + + Logger.msg(1, "CreateAgentFromDescription::request() - Starting."); + + // check if given roles exist + String[] roleArr = roles.split(","); + for(int i=0; i requestedRoles = new ArrayList(); + for (int i=0; i rolesToRemove = new ArrayList(); + for (RolePath existingRole : currentRoles) { // + if (requestedRoles.contains(existingRole)) // if we have it, and it's requested, then it will be kept + requestedRoles.remove(existingRole); // so remove it from request - this will be left with roles to be added + else + rolesToRemove.add(existingRole); // else this role will be removed + } + + // remove roles not in new list + for (RolePath roleToRemove : rolesToRemove) + try { + Gateway.getLookupManager().removeRole(targetAgent, roleToRemove); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("Error removing role "+roleToRemove.getName()); + } + + // add requested roles we don't already have + for (RolePath roleToAdd : requestedRoles) + try { + Gateway.getLookupManager().addRole(targetAgent, roleToAdd); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("Error adding role "+roleToAdd.getName()); + } + + return requestData; + } + +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java new file mode 100644 index 0000000..53e545e --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java @@ -0,0 +1,195 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined.item; + +import org.cristalise.kernel.collection.Collection; +import org.cristalise.kernel.collection.CollectionArrayList; +import org.cristalise.kernel.collection.CollectionDescription; +import org.cristalise.kernel.collection.CollectionMember; +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.CorbaServer; +import org.cristalise.kernel.entity.TraceableEntity; +import org.cristalise.kernel.lifecycle.CompositeActivityDef; +import org.cristalise.kernel.lifecycle.instance.CompositeActivity; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.property.Property; +import org.cristalise.kernel.property.PropertyArrayList; +import org.cristalise.kernel.property.PropertyDescriptionList; +import org.cristalise.kernel.property.PropertyUtility; +import org.cristalise.kernel.utils.LocalObjectLoader; +import org.cristalise.kernel.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 + protected String runActivityLogic(AgentPath agent, ItemPath itemPath, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, ObjectAlreadyExistsException, CannotManageException, ObjectCannotBeUpdated, PersistencyException { + + String[] input = getDataList(requestData); + String newName = input[0]; + String domPath = input[1]; + String descVer = input.length > 2 ? input[2]:"last"; + PropertyArrayList initProps = + input.length > 3?getInitProperties(input[3]):new PropertyArrayList(); + + Logger.msg(1, "CreateItemFromDescription - Starting."); + + // check if the path is already taken + DomainPath context = new DomainPath(new DomainPath(domPath), newName); + //Logger.debug(8,"context "+context.getItemPath()+" "+context.getPath()+" "+context.getString()); + if (context.exists()) + throw new ObjectAlreadyExistsException("The path " +context+ " exists already."); + + // get init objects + + /* ITEM CREATION */ + + // generate new entity key + Logger.msg(6, "CreateItemFromDescription - Requesting new item path"); + ItemPath newItemPath = new ItemPath(); + + // 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 CannotManageException("This process cannot create new Items"); + TraceableEntity newItem = factory.createItem(newItemPath); + Gateway.getLookupManager().add(newItemPath); + + + // initialise it with its properties and workflow + + Logger.msg(3, "CreateItemFromDescription - Initializing Item"); + + try { + newItem.initialise( + agent.getSystemKey(), + Gateway.getMarshaller().marshall(getNewProperties(itemPath, descVer, initProps, newName, agent)), + Gateway.getMarshaller().marshall(getNewWorkflow(itemPath, descVer)), + Gateway.getMarshaller().marshall(getNewCollections(itemPath, descVer)) + ); + } catch (PersistencyException e) { + throw e; + } catch (Exception e) { + throw new InvalidDataException("CreateAgentFromDescription: Problem initializing new Agent. See log: "+e.getMessage()); + } + // add its domain path + Logger.msg(3, "CreateItemFromDescription - Creating "+context); + context.setItemPath(newItemPath); + Gateway.getLookupManager().add(context); + return requestData; + } + + protected PropertyArrayList getInitProperties(String input) throws InvalidDataException { + try { + return (PropertyArrayList)Gateway.getMarshaller().unmarshall(input); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("Initial property parameter was not a marshalled PropertyArrayList: "+input); + } + } + + protected PropertyArrayList getNewProperties(ItemPath itemPath, String descVer, PropertyArrayList initProps, String newName, AgentPath agent) throws ObjectNotFoundException, InvalidDataException { + // copy properties -- intend to create from propdesc + PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer); + PropertyArrayList props = pdList.instantiate(initProps); + // 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, true)); + props.list.add( new Property("Creator", agent.getAgentName(), false)); + return props; + } + + protected CompositeActivity getNewWorkflow(ItemPath itemPath, String descVer) throws ObjectNotFoundException, InvalidDataException, PersistencyException { + // find the workflow def for the given description version + + String wfDefName = null; Integer wfDefVer = null; + + Collection thisCol = (Collection)Gateway.getStorage().get(itemPath, ClusterStorage.COLLECTION+"/workflow/"+descVer, null); + CollectionMember wfMember = thisCol.getMembers().list.get(0); + wfDefName = wfMember.resolveItem().getName(); + Object wfVerObj = wfMember.getProperties().get("Version"); + try { + wfDefVer = Integer.parseInt(wfVerObj.toString()); + } catch (NumberFormatException ex) { + throw new InvalidDataException("Invalid workflow version number: "+wfVerObj.toString()); + } + + // load workflow def + if (wfDefName == null) + throw new InvalidDataException("No workflow given or defined"); + if (wfDefVer == null) + throw new InvalidDataException("No workflow def version given"); + + try { + CompositeActivityDef wfDef = (CompositeActivityDef)LocalObjectLoader.getActDef(wfDefName, wfDefVer); + return (CompositeActivity)wfDef.instantiate(); + } catch (ObjectNotFoundException ex) { + throw new InvalidDataException("Workflow def '"+wfDefName+"'v"+wfDefVer+" not found"); + } catch (ClassCastException ex) { + throw new InvalidDataException("Activity def '"+wfDefName+"' was not Composite"); + } + } + + protected CollectionArrayList getNewCollections(ItemPath itemPath, String descVer) throws ObjectNotFoundException, PersistencyException { + // loop through collections, collecting instantiated descriptions and finding the default workflow def + CollectionArrayList colls = new CollectionArrayList(); + String[] collNames = Gateway.getStorage().getClusterContents(itemPath, ClusterStorage.COLLECTION); + for (String collName : collNames) { + Collection thisCol = (Collection)Gateway.getStorage().get(itemPath, ClusterStorage.COLLECTION+"/"+collName+"/"+descVer, null); + if (thisCol instanceof CollectionDescription) { + CollectionDescription thisDesc = (CollectionDescription)thisCol; + colls.put(thisDesc.newInstance()); + } + } + return colls; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/Erase.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/Erase.java new file mode 100644 index 0000000..50a1bfd --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/Erase.java @@ -0,0 +1,80 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined.item; + + + +import java.util.Iterator; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.lookup.Path; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2005/11/15 15:56:38 $ + * @version $Revision: 1.10 $ + **************************************************************************/ +public class Erase extends PredefinedStep +{ + public Erase() + { + super(); + getProperties().put("Agent Role", "Admin"); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, PersistencyException { + + Logger.msg(1, "Erase::request() - Starting."); + + Iterator domPaths = Gateway.getLookup().searchAliases(item); + while (domPaths.hasNext()) { + DomainPath path = (DomainPath)domPaths.next(); + // delete them + if (path.getItemPath().equals(item)) + Gateway.getLookupManager().delete(path); + } + + //clear out all storages + Gateway.getStorage().removeCluster(item, "", null); + + //remove entity path + Gateway.getLookupManager().delete(item); + + Logger.msg(1, "Erase::request() - DONE."); + return requestData; + } + +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java new file mode 100644 index 0000000..46a6feb --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java @@ -0,0 +1,45 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined.item; + +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStepContainer; + + +/************************************************************************** + * + * $Revision: 1.2 $ + * $Date: 2005/06/02 10:19:33 $ + * + * Copyright (C) 2003 CERN - European Organization for Nuclear Research + * All rights reserved. + **************************************************************************/ + +public class ItemPredefinedStepContainer extends PredefinedStepContainer { + + + @Override + public void createChildren() + { + super.createChildren(); + predInit("CreateItemFromDescription", "Create a new item using this item as its description", new CreateItemFromDescription()); + predInit("Erase", "Deletes all objects and domain paths for this item.", new Erase()); + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/AddDomainContext.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/AddDomainContext.java new file mode 100644 index 0000000..b225978 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/AddDomainContext.java @@ -0,0 +1,67 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined.server; + +import java.util.Arrays; +import java.util.Stack; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class AddDomainContext extends PredefinedStep { + + public AddDomainContext() { + super(); + } + + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectCannotBeUpdated, ObjectAlreadyExistsException, CannotManageException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AddDomainContext: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidDataException("AddDomainContext: Invalid parameters "+Arrays.toString(params)); + + DomainPath pathToAdd = new DomainPath(params); + if (pathToAdd.exists()) + throw new ObjectAlreadyExistsException("Context "+pathToAdd+" already exists"); + // collect parent paths if they don't exist + Stack pathsToAdd = new Stack(); + while(pathToAdd!= null && !pathToAdd.exists()) { + pathsToAdd.push(pathToAdd); + pathToAdd = pathToAdd.getParent(); + } + while(!pathsToAdd.empty()) { + pathToAdd = pathsToAdd.pop(); + Gateway.getLookupManager().add(pathToAdd); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewAgent.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewAgent.java new file mode 100644 index 0000000..65e56b5 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewAgent.java @@ -0,0 +1,68 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined.server; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.entity.imports.ImportAgent; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class CreateNewAgent extends PredefinedStep +{ + public CreateNewAgent() + { + super(); + getProperties().put("SchemaType", "Agent"); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException { + + String redactedRequestData; + + ImportAgent newAgent; + try { + newAgent = (ImportAgent)Gateway.getMarshaller().unmarshall(requestData); + } catch (Exception e1) { + Logger.error(e1); + throw new InvalidDataException("CreateNewAgent: Couldn't unmarshall new Agent: "+requestData); + } + newAgent.create(agent, true); + newAgent.setPassword("REDACTED"); + try { + redactedRequestData = Gateway.getMarshaller().marshall(newAgent); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("CreateNewAgent: Couldn't marshall new Agent for outcome: "+newAgent); + } + return redactedRequestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewItem.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewItem.java new file mode 100644 index 0000000..acd1fd1 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewItem.java @@ -0,0 +1,63 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined.server; + + + + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidCollectionModification; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.entity.imports.ImportItem; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class CreateNewItem extends PredefinedStep +{ + public CreateNewItem() + { + super(); + getProperties().put("SchemaType", "Item"); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException, InvalidCollectionModification { + + ImportItem newItem; + try { + newItem = (ImportItem)Gateway.getMarshaller().unmarshall(requestData); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("CreateNewAgent: Couldn't unmarshall new Agent: "+requestData); + } + newItem.create(agent, false); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewRole.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewRole.java new file mode 100644 index 0000000..3771a7e --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewRole.java @@ -0,0 +1,60 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined.server; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.entity.imports.ImportRole; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class CreateNewRole extends PredefinedStep +{ + public CreateNewRole() + { + super(); + getProperties().put("SchemaType", "Role"); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, ObjectNotFoundException { + + + ImportRole newRole; + try { + newRole = (ImportRole)Gateway.getMarshaller().unmarshall(requestData); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("CreateNewAgent: Couldn't unmarshall new Agent: "+requestData); + } + newRole.create(agent, true); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java new file mode 100644 index 0000000..bc1ed5c --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java @@ -0,0 +1,65 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined.server; + +import java.util.Arrays; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class RemoveDomainContext extends PredefinedStep { + public RemoveDomainContext() { + super(); + } + + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "RemoveDomainContext: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidDataException("RemoveDomainContext: Invalid parameters "+Arrays.toString(params)); + + DomainPath pathToDelete = new DomainPath(params[0]); + if (!pathToDelete.exists()) + throw new ObjectNotFoundException("Context "+pathToDelete+" does not exist"); + + try { + pathToDelete.getItemPath(); + throw new InvalidDataException("Path "+pathToDelete+" is an Entity. Use its own Erase step instead, or RemoveAgent."); + } catch (ObjectNotFoundException ex) { } + + if (Gateway.getLookup().getChildren(pathToDelete).hasNext()) + throw new ObjectCannotBeUpdated("Context "+pathToDelete+" is not empty. Cannot delete."); + + Gateway.getLookupManager().delete(pathToDelete); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveRole.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveRole.java new file mode 100644 index 0000000..6136cac --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveRole.java @@ -0,0 +1,68 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined.server; + +import java.util.Arrays; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.lookup.LookupManager; +import org.cristalise.kernel.lookup.RolePath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class RemoveRole extends PredefinedStep +{ + public RemoveRole() + { + super(); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, CannotManageException, ObjectNotFoundException, ObjectCannotBeUpdated { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "RemoveRole: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidDataException("RemoveRole: Invalid parameters "+Arrays.toString(params)); + + LookupManager lookup = Gateway.getLookupManager(); + + RolePath thisRole; AgentPath[] agents; + thisRole = lookup.getRolePath(params[0]); + agents = Gateway.getLookup().getAgents(thisRole); + + if (agents.length > 0) + throw new ObjectCannotBeUpdated("Cannot remove role. "+agents.length+" agents still hold it."); + + lookup.delete(thisRole); + + return requestData; + + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/ServerPredefinedStepContainer.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/ServerPredefinedStepContainer.java new file mode 100644 index 0000000..0fdc34c --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/ServerPredefinedStepContainer.java @@ -0,0 +1,62 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.predefined.server; + +import org.cristalise.kernel.graph.model.GraphPoint; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStepContainer; + +/************************************************************************** + * + * $Revision: 1.2 $ + * $Date: 2005/06/02 10:19:33 $ + * + * Copyright (C) 2003 CERN - European Organization for Nuclear Research + * All rights reserved. + **************************************************************************/ + +public class ServerPredefinedStepContainer extends PredefinedStepContainer { + + + @Override + public void createChildren() + { + super.createChildren(); + serverPredInit("CreateNewItem", "Creates a new Item in this Server without description.", new CreateNewItem()); + serverPredInit("CreateNewAgent", "Creates a new Agent in this Server without description.", new CreateNewAgent()); + serverPredInit("CreateNewRole", "Creates a new Role in this Server.", new CreateNewRole()); + serverPredInit("RemoveRole", "Removes a Role from this Server.", new RemoveRole()); + serverPredInit("RemoveDomainContext", "Deletes an existing context in the domain tree, but only if empty", new RemoveDomainContext()); + serverPredInit("AddDomainContext", "Creates an empty domain context in the tree", new AddDomainContext()); + } + + public void serverPredInit(String alias, String Description, PredefinedStep act) + { + act.setName(alias); + act.setType(alias); + act.getProperties().put("Description", Description); + act.getProperties().put("Agent Role", "Admin"); + act.setCentrePoint(new GraphPoint()); + act.setIsPredefined(true); + addChild(act, new GraphPoint(100, 75 * ++num)); + } + +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/State.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/State.java new file mode 100644 index 0000000..d78bb4e --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/State.java @@ -0,0 +1,101 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.stateMachine; + +import java.util.HashMap; +import java.util.Set; + +public class State { + + int id; + String name; + boolean finished = false; // If true, this state deactivates the current activity and the lifecycle proceeds + + HashMap possibleTransitions; + + public State() { + possibleTransitions = new HashMap(); + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return id+": "+name; + } + + public void setName(String name) { + this.name = name; + } + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public boolean isFinished() { + return finished; + } + + public void setFinished(boolean finished) { + this.finished = finished; + } + + public HashMap getPossibleTransitions() { + return possibleTransitions; + } + + protected void addPossibleTransition(Transition possibleTransition) { + possibleTransitions.put(possibleTransition.getId(), possibleTransition); + } + + public Set getPossibleTransitionIds() { + return possibleTransitions.keySet(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + State other = (State) obj; + if (id != other.id) + return false; + return true; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/StateMachine.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/StateMachine.java new file mode 100644 index 0000000..975dee1 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/StateMachine.java @@ -0,0 +1,178 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.stateMachine; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.cristalise.kernel.common.AccessRightsException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.InvalidTransitionException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.lifecycle.instance.Activity; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.utils.DescriptionObject; +import org.cristalise.kernel.utils.Logger; + + +public class StateMachine implements DescriptionObject +{ + public String name; + public int version; + + private ArrayList states; + private ArrayList transitions; + private final HashMap stateCodes; + private final HashMap transitionCodes; + + State initialState; + int initialStateCode; + boolean isCoherent = false; + + public StateMachine() { + states = new ArrayList(); + transitions = new ArrayList(); + stateCodes = new HashMap(); + transitionCodes = new HashMap(); + } + + public void setStates(ArrayList newStates) { + this.states = newStates; + validate(); + } + + public void setTransitions(ArrayList newTransitions) { + this.transitions = newTransitions; + validate(); + } + + public void validate() { + stateCodes.clear(); + transitionCodes.clear(); + isCoherent = true; + + for (State state : states) { + Logger.debug(6, "State "+state.id+": "+state.name); + stateCodes.put(state.getId(), state); + } + + if (stateCodes.containsKey(initialStateCode)) + initialState = stateCodes.get(initialStateCode); + else + isCoherent = false; + + for (Transition trans : transitions) { + Logger.debug(6, "Transition "+trans.id+": "+trans.name); + transitionCodes.put(trans.getId(), trans); + isCoherent = isCoherent && trans.resolveStates(stateCodes); + } + + } + + public ArrayList getStates() { + return states; + } + + public ArrayList getTransitions() { + return transitions; + } + + public State getInitialState() { + return initialState; + } + + public void setInitialState(State initialState) { + this.initialState = initialState; + initialStateCode = initialState.getId(); + } + + public int getInitialStateCode() { + return initialStateCode; + } + + public void setInitialStateCode(int initialStateCode) { + this.initialStateCode = initialStateCode; + initialState = stateCodes.get(initialStateCode); + if (initialState == null) isCoherent = false; + } + + @Override + public String getName() { + return name; + } + + @Override + public int getVersion() { + return version; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public void setVersion(int version) { + this.version = version; + } + + public Transition getTransition(int transitionID) { + return transitionCodes.get(transitionID); + } + + public State getState(int stateID) { + return stateCodes.get(stateID); + } + + public Map getPossibleTransitions(Activity act, AgentPath agent) throws ObjectNotFoundException, InvalidDataException { + HashMap returnList = new HashMap(); + State currentState = getState(act.getState()); + for (Integer transCode : currentState.getPossibleTransitionIds()) { + Transition possTrans = currentState.getPossibleTransitions().get(transCode); + try { + String role = possTrans.getPerformingRole(act, agent); + returnList.put(possTrans, role); + } catch (AccessRightsException ex) { + if (Logger.doLog(5)) + Logger.msg(5, "Transition '"+possTrans+"' not possible for "+agent.getAgentName()+": "+ex.getMessage()); + } + } + return returnList; + } + + public State traverse(Activity act, Transition transition, AgentPath agent) throws InvalidTransitionException, AccessRightsException, ObjectNotFoundException, InvalidDataException { + State currentState = getState(act.getState()); + if (transition.originState.equals(currentState)) { + transition.getPerformingRole(act, agent); + return transition.targetState; + } + else + throw new InvalidTransitionException("Transition '"+transition.getName()+"' not valid from state '"+currentState.getName()); + + } + + public boolean isCoherent() { + return isCoherent; + } + + +} \ No newline at end of file diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/Transition.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/Transition.java new file mode 100644 index 0000000..845b489 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/Transition.java @@ -0,0 +1,345 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.stateMachine; + +import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.cristalise.kernel.common.AccessRightsException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.lifecycle.instance.Activity; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.RolePath; +import org.cristalise.kernel.persistency.outcome.Schema; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.CastorHashMap; +import org.cristalise.kernel.utils.LocalObjectLoader; +import org.cristalise.kernel.utils.Logger; + + +public class Transition { + + int id; + String name; + + int originStateId; + int targetStateId; + State originState; + State targetState; + String reservation; + + String enabledProp; // Boolean property that permits this transition e.g. 'Skippable' + + // activation properties + boolean requiresActive = true; // Whether the activity must be active for this transition to be available + boolean finishing; // whether the target state is a finishing state; + + // permissions + String roleOverride; + + TransitionOutcome outcome; + TransitionScript script; + + public Transition() { + } + + + public Transition(int id, String name, int originStateId, int targetStateId) { + super(); + this.id = id; + this.name = name; + this.originStateId = originStateId; + this.targetStateId = targetStateId; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public State getOriginState() { + return originState; + } + + public void setOriginState(State originState) { + this.originState = originState; + } + + public State getTargetState() { + return targetState; + } + + public void setTargetState(State targetState) { + this.targetState = targetState; + finishing = targetState.finished; + } + + public String getEnabledProp() { + return enabledProp; + } + + public void setEnabledProp(String enabledProp) { + this.enabledProp = enabledProp; + } + + public boolean isRequiresActive() { + return requiresActive; + } + + public boolean isFinishing() { + return finishing; + } + + public void setRequiresActive(boolean requiresActive) { + this.requiresActive = requiresActive; + } + + public String getRoleOverride() { + return roleOverride; + } + + public void setRoleOverride(String roleOverride) { + this.roleOverride = roleOverride; + } + + public TransitionOutcome getOutcome() { + return outcome; + } + + public void setOutcome(TransitionOutcome outcome) { + this.outcome = outcome; + } + + public TransitionScript getScript() { + return script; + } + + public void setScript(TransitionScript script) { + this.script = script; + } + + public String getReservation() { + return reservation; + } + + public void setReservation(String reservation) { + this.reservation = reservation; + } + + protected boolean resolveStates(HashMap states) { + boolean allFound = true; + if (states.keySet().contains(originStateId)) { + originState = states.get(originStateId); + originState.addPossibleTransition(this); + } + else + allFound = false; + if (states.keySet().contains(targetStateId)) + targetState = states.get(targetStateId); + else + allFound = false; + return allFound; + } + + public int getOriginStateId() { + return originStateId; + } + + public void setOriginStateId(int originStateId) { + this.originStateId = originStateId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getTargetStateId() { + return targetStateId; + } + + public void setTargetStateId(int targetStateId) { + this.targetStateId = targetStateId; + } + + public String getPerformingRole(Activity act, AgentPath agent) throws ObjectNotFoundException, AccessRightsException { + + // check available + if (!isEnabled(act.getProperties())) + throw new AccessRightsException("Transition '"+name+"' is disabled by the '"+enabledProp+"' property."); + + // check active + if (isRequiresActive() && !act.getActive()) + throw new AccessRightsException("Activity must be active to perform this transition"); + + RolePath role = null; + String overridingRole = resolveValue(roleOverride, act.getProperties()); + boolean override = overridingRole != null; + boolean isOwner = false, isOwned = true; + + // Check agent name + String agentName = act.getCurrentAgentName(); + if (agentName != null && agentName.length() >0) { + if (agent.getAgentName().equals(agentName)) + isOwner = true; + } + else isOwned = false; + + // determine transition role + if (override) { + role = Gateway.getLookup().getRolePath(overridingRole); + } + else { + String actRole = act.getCurrentAgentRole(); + if (actRole != null && actRole.length() > 0) + role = Gateway.getLookup().getRolePath(actRole); + } + + // Decide the access + if (isOwned && !override && !isOwner) + throw new AccessRightsException("Agent '"+agent.getAgentName() + +"' cannot perform this transition because the activity '"+act.getName()+"' is currently owned by "+agentName); + + if (role != null) { + if (agent.hasRole(role)) + return role.getName(); + else if (agent.hasRole("Admin")) + return "Admin"; + else + throw new AccessRightsException("Agent '"+agent.getAgentName() + +"' does not hold a suitable role '"+role.getName()+"' for the activity "+act.getName()); + } + else + return null; + } + + public String getReservation(Activity act, AgentPath agent) { + if (reservation == null || reservation.length() == 0) + reservation = targetState.finished?"clear":"set"; + + String reservedAgent = act.getCurrentAgentName(); + if (reservation.equals("set")) + reservedAgent = agent.getAgentName(); + else if (reservation.equals("clear")) + reservedAgent = ""; + return reservedAgent; + + } + + private static String resolveValue(String key, CastorHashMap props) { + if (key==null) return null; + String result = key; + Pattern propField = Pattern.compile("\\$\\{(.+?)\\}"); + Matcher propMatcher = propField.matcher(result); + while (propMatcher.find()) { + String propName = propMatcher.group(1); + Object propValue = props.get(propName); + Logger.msg(8, "Replacing Property "+propName+" as "+propValue); + String propValString = propValue==null?"":propValue.toString(); + result = result.replace("${"+propName+"}", propValString); + } + return result; + } + + public boolean isEnabled(CastorHashMap props) { + if (enabledProp == null) + return true; + return (Boolean)props.get(enabledProp); + } + + public boolean hasOutcome(CastorHashMap actProps) { + if (outcome == null || actProps == null) return false; + String outcomeName = resolveValue(outcome.schemaName, actProps); + if (outcomeName == null || outcomeName.length() == 0) + return false; + String outcomeVersion = resolveValue(outcome.schemaVersion, actProps); + if (outcomeVersion == null || outcomeVersion.length() == 0) + return false; + return true; + } + + public Schema getSchema(CastorHashMap actProps) throws InvalidDataException, ObjectNotFoundException { + if (hasOutcome(actProps)) + try { + return LocalObjectLoader.getSchema(resolveValue(outcome.schemaName, actProps), + Integer.parseInt(resolveValue(outcome.schemaVersion, actProps))); + } catch (NumberFormatException ex) { + throw new InvalidDataException("Bad schema version number: "+outcome.schemaVersion+" ("+resolveValue(outcome.schemaVersion, actProps)+")"); + } + else + return null; + } + + public String getScriptName(CastorHashMap actProps) { + return resolveValue(script.scriptName, actProps); + } + + public int getScriptVersion(CastorHashMap actProps) throws InvalidDataException { + try { + return Integer.parseInt(resolveValue(script.scriptVersion, actProps)); + } catch (NumberFormatException ex) { + throw new InvalidDataException("Bad Script version number: "+script.scriptVersion+" ("+resolveValue(script.scriptVersion, actProps)+")"); + } + } + + public boolean hasScript(CastorHashMap actProps) { + if (script == null || actProps == null) return false; + String scriptName = getScriptName(actProps); + if (scriptName == null || scriptName.length() == 0) + return false; + String scriptVersion = resolveValue(script.scriptVersion, actProps); + if (scriptVersion == null || scriptVersion.length() == 0) + return false; + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + return result; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Transition other = (Transition) obj; + if (id != other.id) + return false; + return true; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/TransitionOutcome.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/TransitionOutcome.java new file mode 100644 index 0000000..7575359 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/TransitionOutcome.java @@ -0,0 +1,57 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.stateMachine; + + +public class TransitionOutcome extends TransitionResource { + + // schema properties + String schemaName, schemaVersion; // Name & version of the schema of the data required for this transition. + boolean required = true; // If true, then the data must be supplied to perform the transition, otherwise it is optional + + public TransitionOutcome() { + } + + public String getSchemaName() { + return schemaName; + } + + public void setSchemaName(String schemaName) { + this.schemaName = schemaName; + } + + public String getSchemaVersion() { + return schemaVersion; + } + + public void setSchemaVersion(String schemaVersion) { + this.schemaVersion = schemaVersion; + } + + public boolean isRequired() { + return required; + } + + public void setRequired(boolean required) { + this.required = required; + } + +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/TransitionResource.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/TransitionResource.java new file mode 100644 index 0000000..e220447 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/TransitionResource.java @@ -0,0 +1,29 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.stateMachine; + +public class TransitionResource { + + public TransitionResource() { + // TODO Auto-generated constructor stub + } + +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/TransitionScript.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/TransitionScript.java new file mode 100644 index 0000000..a41ec2c --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/stateMachine/TransitionScript.java @@ -0,0 +1,48 @@ +/** + * This file is part of the CRISTAL-iSE kernel. + * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * http://www.fsf.org/licensing/licenses/lgpl.html + */ +package org.cristalise.kernel.lifecycle.instance.stateMachine; + + +public class TransitionScript extends TransitionResource { + + // script properties + String scriptName, scriptVersion; // Name & version of the script to be run by the agent during this transition + + public TransitionScript() { + } + + public String getScriptName() { + return scriptName; + } + + public void setScriptName(String scriptName) { + this.scriptName = scriptName; + } + + public String getScriptVersion() { + return scriptVersion; + } + + public void setScriptVersion(String scriptVersion) { + this.scriptVersion = scriptVersion; + } + +} -- cgit v1.2.3