package com.c2kernel.lifecycle.instance; import java.util.ArrayList; import com.c2kernel.common.AccessRightsException; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.InvalidTransitionException; import com.c2kernel.common.ObjectAlreadyExistsException; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.agent.Job; import com.c2kernel.events.History; import com.c2kernel.graph.model.GraphPoint; import com.c2kernel.graph.model.TypeNameAndConstructionInfo; import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer; import com.c2kernel.lookup.AgentPath; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.utils.Language; import com.c2kernel.utils.Logger; /** * @version $Revision: 1.64 $ $Date: 2005/09/30 07:09:48 $ * @author $Author: abranson $ */ public class Workflow extends CompositeActivity implements C2KLocalObject { public History history; private Integer itemSysKey = 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) { this(); domain.setName("domain"); initChild(domain, true, new GraphPoint(150, 100)); PredefinedStepContainer act = new PredefinedStepContainer(); addChild(act, new GraphPoint(300, 100)); } public History getHistory() throws InvalidDataException { if (history == null) { if (itemSysKey == null) throw new InvalidDataException("Workflow not initialized.", ""); history = new History(itemSysKey, 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 */ //requestData is xmlstring public void requestAction(AgentPath agent, String stepPath, int itemSysKey, int transitionID, String requestData) throws ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, PersistencyException { Logger.msg(3, "Action: " + transitionID + " " + stepPath + " by " + agent.getAgentName()); if (search(stepPath) != null) ((Activity) search(stepPath)).request(agent, itemSysKey, transitionID, requestData); else throw new ObjectNotFoundException(stepPath + " not found", ""); } /** * @see com.c2kernel.graph.model.GraphableVertex#getPath() */ @Override public String getPath() { return "workflow"; } /** * @see com.c2kernel.graph.model.Vertex#getName() */ @Override public String getName() { return "workflow"; } /** * @see com.c2kernel.lifecycle.instance.Activity#getType() */ @Override public String getType() { return "workflow"; } /** * @see com.c2kernel.graph.model.Vertex#setName(java.lang.String) */ @Override public void setName(String name) { } /** * @see com.c2kernel.lifecycle.instance.WfVertex#verify() */ @Override public boolean verify() { for (int i = 0; i < getChildren().length; i++) { if (!((WfVertex) getChildren()[i]).verify()) { mErrors.add("error in children"); return false; } } return true; } /** * @see com.c2kernel.lifecycle.instance.Activity#getWf() */ @Override public Workflow getWf() { return this; } /** * Method initialise. * * @param systemKey * @throws InvalidDataException * @throws ObjectNotFoundException * @throws AccessRightsException * @throws InvalidTransitionException */ public void initialise(int systemKey, AgentPath agent) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException { itemSysKey = systemKey; try { runFirst(agent, systemKey); } catch (InvalidDataException ex) { Logger.error(ex); } catch (PersistencyException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public Integer getItemSysKey() { return itemSysKey; } public void setItemSysKey(Integer itemSysKey) { this.itemSysKey = itemSysKey; } /** * if type = 0 only domain steps will be queried if type = 1 only predefined steps will be queried else both will be queried * @param agent * @param itemSysKey * @param type * @return * @throws ObjectNotFoundException * @throws InvalidDataException */ public ArrayList calculateJobs(AgentPath agent, int itemSysKey, int type) throws ObjectNotFoundException, InvalidDataException { ArrayList jobs = new ArrayList(); if (type != 1) jobs.addAll(((CompositeActivity) search("workflow/domain")).calculateJobs(agent, itemSysKey, true)); if (type != 0) jobs.addAll(((CompositeActivity) search("workflow/predefined")).calculateJobs(agent, itemSysKey, true)); return jobs; } /** * @see com.c2kernel.lifecycle.instance.CompositeActivity#hasGoodNumberOfActivity() */ @Override public boolean hasGoodNumberOfActivity() { return true; } /** * @see com.c2kernel.entity.C2KLocalObject#getClusterType() */ @Override public String getClusterType() { return ClusterStorage.LIFECYCLE; } }