diff options
Diffstat (limited to 'src/main/java/com/c2kernel/lifecycle/instance')
41 files changed, 788 insertions, 672 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java index a0fe6a0..70b991d 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java @@ -26,11 +26,14 @@ import java.util.Map; import java.util.Vector;
import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.CannotManage;
import com.c2kernel.common.GTimeStamp;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
-import com.c2kernel.common.ObjectAlreadyExistsException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.InvalidTransition;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.events.Event;
@@ -45,7 +48,6 @@ import com.c2kernel.lookup.InvalidAgentPathException; import com.c2kernel.lookup.ItemPath;
import com.c2kernel.lookup.Path;
import com.c2kernel.lookup.RolePath;
-import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.persistency.outcome.Schema;
import com.c2kernel.persistency.outcome.Viewpoint;
@@ -101,13 +103,13 @@ public class Activity extends WfVertex return new Next(this, vertex);
}
- public StateMachine getStateMachine() throws InvalidDataException {
+ public StateMachine getStateMachine() throws InvalidData {
if (machine == null) {
String name = (String)getProperties().get("StateMachineName");
int version = getVersionNumberProperty("StateMachineVersion");
try {
machine = LocalObjectLoader.getStateMachine(name, version);
- } catch (ObjectNotFoundException ex) {
+ } catch (ObjectNotFound 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");
@@ -117,24 +119,24 @@ public class Activity extends WfVertex return bootstrap;
} catch (Exception ex2) {
Logger.error(ex2);
- throw new InvalidDataException("Could not bootstrap default state machine from resources.", "");
+ throw new InvalidData("Could not bootstrap default state machine from resources.");
}
}
Logger.error(ex);
- throw new InvalidDataException("Error loading state machine '"+name+"' v"+version, "");
+ throw new InvalidData("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
+ public int getState() throws InvalidData
{
if (state == -1)
state = getStateMachine().getInitialStateCode();
return state;
}
- public String getStateName() throws InvalidDataException
+ public String getStateName() throws InvalidData
{
return getStateMachine().getState(getState()).getName();
}
@@ -145,15 +147,19 @@ public class Activity extends WfVertex this.state = state;
}
- public boolean isFinished() throws InvalidDataException {
+ public boolean isFinished() throws InvalidData {
return getStateMachine().getState(getState()).isFinished();
}
/** cf Item request
- * @throws ObjectNotFoundException
- * @throws PersistencyException */
- public String request(AgentPath agent, ItemPath itemPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException
+ * @throws ObjectNotFound
+ * @throws PersistencyException
+ * @throws ObjectAlreadyExists
+ * @throws ObjectCannotBeUpdated
+ * @throws CannotManage
+ * @throws InvalidCollectionModification */
+ public String request(AgentPath agent, ItemPath itemPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransition, InvalidData, ObjectNotFound, PersistencyException, ObjectAlreadyExists, ObjectCannotBeUpdated, CannotManage, InvalidCollectionModification
{
// Find requested transition
@@ -172,7 +178,7 @@ public class Activity extends WfVertex if (requestData != null && requestData.length()>0)
storeOutcome = true;
else if (transition.getOutcome().isRequired())
- throw new InvalidDataException("Transition requires outcome data, but none was given", "");
+ throw new InvalidData("Transition requires outcome data, but none was given");
}
// Get new state
@@ -212,10 +218,10 @@ public class Activity extends WfVertex Gateway.getStorage().put(itemPath, currentView, getWf());
}
Gateway.getStorage().commit(getWf());
- } catch (ClusterStorageException ex) {
+ } catch (PersistencyException ex) {
Logger.error(ex);
Gateway.getStorage().abort(getWf());
- throw new PersistencyException("Exception storing event data");
+ throw ex;
}
if (newState.isFinished()) {
@@ -231,7 +237,7 @@ public class Activity extends WfVertex try {
RolePath myRole = Gateway.getLookup().getRolePath(agentRole);
pushJobsToAgents(itemPath, myRole);
- } catch (ObjectNotFoundException ex) { // non-existent role
+ } catch (ObjectNotFound ex) { // non-existent role
Logger.msg(7, "Activity.pushJobsToAgents() - Activity role '"+agentRole+" not found.");
}
}
@@ -241,7 +247,15 @@ public class Activity extends WfVertex }
protected String runActivityLogic(AgentPath agent, ItemPath itemPath,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws
+ InvalidData,
+ InvalidCollectionModification,
+ ObjectAlreadyExists,
+ ObjectCannotBeUpdated,
+ ObjectNotFound,
+ PersistencyException,
+ CannotManage
+ {
// Overriden in predefined steps
return requestData;
}
@@ -309,13 +323,14 @@ public class Activity extends WfVertex return loop2;
}
/** sets the next activity available if possible
- * @throws ObjectNotFoundException
+ * @throws ObjectNotFound
* @throws AccessRightsException
- * @throws InvalidTransitionException
+ * @throws InvalidTransition
* @throws PersistencyException
- * @throws ObjectAlreadyExistsException */
+ * @throws ObjectAlreadyExists
+ * @throws ObjectCannotBeUpdated */
@Override
- public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidData
{
setActive(false);
try
@@ -353,7 +368,7 @@ public class Activity extends WfVertex }
}
}
- catch (InvalidDataException s)
+ catch (InvalidData s)
{
setActive(true);
throw s;
@@ -368,10 +383,10 @@ public class Activity extends WfVertex return null;
}
/** reinitialises the Activity and propagate (for Loop)
- * @throws InvalidDataException
- * @throws ObjectNotFoundException */
+ * @throws InvalidData
+ * @throws ObjectNotFound */
@Override
- public void reinit(int idLoop) throws InvalidDataException
+ public void reinit(int idLoop) throws InvalidData
{
Vertex[] outVertices = getOutGraphables();
setState(getStateMachine().getInitialState().getId());
@@ -391,15 +406,16 @@ public class Activity extends WfVertex }
/**
* called by precedent Activity runNext() for setting the activity able to be executed
- * @throws InvalidDataException
- * @throws ObjectAlreadyExistsException
+ * @throws InvalidData
+ * @throws ObjectAlreadyExists
* @throws AccessRightsException
- * @throws InvalidTransitionException
- * @throws ObjectNotFoundException
+ * @throws InvalidTransition
+ * @throws ObjectNotFound
* @throws PersistencyException
+ * @throws ObjectCannotBeUpdated
*/
@Override
- public void run(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void run(AgentPath agent, ItemPath itemPath) throws InvalidData
{
Logger.debug(8, getPath() + " run " + getState());
@@ -417,15 +433,16 @@ public class Activity extends WfVertex }
/**
* 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 InvalidData
+ * @throws ObjectAlreadyExists
+ * @throws ObjectNotFound
* @throws AccessRightsException
- * @throws InvalidTransitionException
+ * @throws InvalidTransition
* @throws PersistencyException
+ * @throws ObjectCannotBeUpdated
*/
@Override
- public void runFirst(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void runFirst(AgentPath agent, ItemPath itemPath) throws InvalidData
{
Logger.debug(8, getPath() + " runfirst");
run(agent, itemPath);
@@ -458,17 +475,19 @@ public class Activity extends WfVertex /**
* returns the lists of jobs for the activity and children (cf com.c2kernel.entity.Job)
+ * @throws InvalidData
+ * @throws ObjectNotFound
* @throws InvalidAgentPathException
*/
- public ArrayList<Job> calculateJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws ObjectNotFoundException, InvalidDataException, InvalidAgentPathException
+ public ArrayList<Job> calculateJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws InvalidAgentPathException, ObjectNotFound, InvalidData
{
return calculateJobsBase(agent, itemPath, false);
} //
- public ArrayList<Job> calculateAllJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws ObjectNotFoundException, InvalidDataException, InvalidAgentPathException
+ public ArrayList<Job> calculateAllJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws InvalidAgentPathException, ObjectNotFound, InvalidData
{
return calculateJobsBase(agent, itemPath, true);
}
- private ArrayList<Job> calculateJobsBase(AgentPath agent, ItemPath itemPath, boolean includeInactive) throws ObjectNotFoundException, InvalidDataException, InvalidAgentPathException
+ private ArrayList<Job> calculateJobsBase(AgentPath agent, ItemPath itemPath, boolean includeInactive) throws ObjectNotFound, InvalidData, InvalidAgentPathException
{
Logger.msg(7, "calculateJobs - " + getPath());
ArrayList<Job> jobs = new ArrayList<Job>();
@@ -491,7 +510,7 @@ public class Activity extends WfVertex try {
RolePath myRole = Gateway.getLookup().getRolePath(agentRole);
pushJobsToAgents(itemPath, myRole);
- } catch (ObjectNotFoundException ex) { // non-existent role
+ } catch (ObjectNotFound ex) { // non-existent role
Logger.msg(7, "Activity.pushJobsToAgents() - Activity role '"+agentRole+" not found.");
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/AdvancementCalculator.java b/src/main/java/com/c2kernel/lifecycle/instance/AdvancementCalculator.java index 6f2c9ce..6f5da3a 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/AdvancementCalculator.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/AdvancementCalculator.java @@ -22,7 +22,7 @@ package com.c2kernel.lifecycle.instance;
import java.util.Hashtable;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidData;
import com.c2kernel.graph.model.Vertex;
//import com.c2kernel.utils.Logger;
/** @author XSeb74 */
@@ -47,7 +47,7 @@ public class AdvancementCalculator HasNextMarked = new Hashtable<Vertex, Vertex>();
hasprevActive = new Hashtable<String, Vertex>();
}
- public void calculate(CompositeActivity act) throws InvalidDataException
+ public void calculate(CompositeActivity act) throws InvalidData
{
// Logger.debug(0, act.getName()+" >>>>>>>>>");
if (act instanceof Workflow)
@@ -77,7 +77,7 @@ public class AdvancementCalculator j++;
if (j != 0 && j==nexts.length) current.HasNextMarked.put(v, nexts[0]);
}
- private void calc(Vertex v, AdvancementCalculator current) throws InvalidDataException
+ private void calc(Vertex v, AdvancementCalculator current) throws InvalidData
{
if (current.isMarked.get(v) != null && !(v instanceof Join))
return;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java b/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java index 6503751..c888d7a 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/AndSplit.java @@ -19,11 +19,7 @@ * http://www.fsf.org/licensing/licenses/lgpl.html
*/
package com.c2kernel.lifecycle.instance;
-import com.c2kernel.common.AccessRightsException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.common.PersistencyException;
+import com.c2kernel.common.InvalidData;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
@@ -41,7 +37,7 @@ public class AndSplit extends Split super();
}
@Override
- public void runNext(AgentPath agent, ItemPath item) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void runNext(AgentPath agent, ItemPath item) throws InvalidData
{
AdvancementCalculator adv = new AdvancementCalculator();
adv.calculate((CompositeActivity) getParent());
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java b/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java index 6299633..8e08f99 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java @@ -23,9 +23,13 @@ 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.ObjectNotFoundException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.InvalidTransition;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.graph.model.GraphModel;
@@ -302,15 +306,17 @@ public class CompositeActivity extends Activity }
/**
- * @throws InvalidDataException
- * @throws ObjectNotFoundException
+ * @throws InvalidData
+ * @throws ObjectNotFound
* @throws AccessRightsException
- * @throws InvalidTransitionException
+ * @throws InvalidTransition
* @throws PersistencyException
+ * @throws ObjectAlreadyExists
+ * @throws ObjectCannotBeUpdated
* @see com.c2kernel.lifecycle.instance.WfVertex#run()
*/
@Override
- public void run(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void run(AgentPath agent, ItemPath itemPath) throws InvalidData
{
super.run(agent, itemPath);
if (getChildrenGraphModel().getStartVertex() != null && !getStateMachine().getState(state).isFinished())
@@ -321,22 +327,28 @@ public class CompositeActivity extends Activity }
@Override
- public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidDataException, AccessRightsException, InvalidTransitionException, ObjectNotFoundException, PersistencyException
+ public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidData
{
if (!getStateMachine().getState(state).isFinished())
- request(agent, itemPath, CompositeActivity.COMPLETE, null);
+ 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 InvalidData
+ * @throws ObjectNotFound
* @throws InvalidAgentPathException
* @see com.c2kernel.lifecycle.instance.Activity#calculateJobs()
*/
@Override
- public ArrayList<Job> calculateJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws ObjectNotFoundException, InvalidDataException, InvalidAgentPathException
+ public ArrayList<Job> calculateJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws InvalidAgentPathException, ObjectNotFound, InvalidData
{
ArrayList<Job> jobs = new ArrayList<Job>();
boolean childActive = false;
@@ -354,7 +366,7 @@ public class CompositeActivity extends Activity }
@Override
- public ArrayList<Job> calculateAllJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws ObjectNotFoundException, InvalidDataException, InvalidAgentPathException
+ public ArrayList<Job> calculateAllJobs(AgentPath agent, ItemPath itemPath, boolean recurse) throws InvalidAgentPathException, ObjectNotFound, InvalidData
{
ArrayList<Job> jobs = new ArrayList<Job>();
if (recurse)
@@ -424,11 +436,11 @@ public class CompositeActivity extends Activity }
/**
- * @throws InvalidDataException
+ * @throws InvalidData
*
*/
@Override
- public void reinit(int idLoop) throws InvalidDataException
+ public void reinit(int idLoop) throws InvalidData
{
super.reinit(idLoop);
if (getChildrenGraphModel().getStartVertex() != null && !getStateMachine().getState(state).isFinished())
@@ -436,7 +448,7 @@ public class CompositeActivity extends Activity }
@Override
- public String request(AgentPath agent, ItemPath itemPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException
+ public String request(AgentPath agent, ItemPath itemPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransition, InvalidData, ObjectNotFound, PersistencyException, ObjectAlreadyExists, ObjectCannotBeUpdated, CannotManage, InvalidCollectionModification
{
if (getChildrenGraphModel().getStartVertex() != null && !getStateMachine().getState(state).isFinished() && transitionID == CompositeActivity.START)
((WfVertex) getChildrenGraphModel().getStartVertex()).run(agent, itemPath);
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Join.java b/src/main/java/com/c2kernel/lifecycle/instance/Join.java index 5151aba..2482f49 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Join.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Join.java @@ -22,9 +22,11 @@ package com.c2kernel.lifecycle.instance; import java.util.Vector;
import com.c2kernel.common.AccessRightsException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.InvalidTransition;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.common.PersistencyException;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.graph.traversal.GraphTraversal;
@@ -49,15 +51,17 @@ public class Join extends WfVertex public int counter = 0;
/**
- * @throws InvalidDataException
- * @throws ObjectNotFoundException
+ * @throws InvalidData
+ * @throws ObjectNotFound
* @throws AccessRightsException
- * @throws InvalidTransitionException
+ * @throws InvalidTransition
* @throws PersistencyException
+ * @throws ObjectAlreadyExists
+ * @throws ObjectCannotBeUpdated
* @see com.c2kernel.lifecycle.instance.WfVertex#runNext()
*/
@Override
- public void runNext(AgentPath agent, ItemPath item) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void runNext(AgentPath agent, ItemPath item) throws InvalidData
{
AdvancementCalculator adv = new AdvancementCalculator();
adv.calculate((CompositeActivity) getParent());
@@ -83,11 +87,11 @@ public class Join extends WfVertex new Next(this, (WfVertex) getParent().search(idNext));
}
/**
- * @throws InvalidDataException
+ * @throws InvalidData
* @see com.c2kernel.lifecycle.instance.WfVertex#reinit(int)
*/
@Override
- public void reinit(int idLoop) throws InvalidDataException
+ public void reinit(int idLoop) throws InvalidData
{
Vertex[] outVertices = getOutGraphables();
if (outVertices.length == 1)
@@ -170,15 +174,17 @@ public class Join extends WfVertex return mErrors.elementAt(0);
}
/**
- * @throws InvalidDataException
- * @throws ObjectNotFoundException
+ * @throws InvalidData
+ * @throws ObjectNotFound
* @throws AccessRightsException
- * @throws InvalidTransitionException
+ * @throws InvalidTransition
* @throws PersistencyException
+ * @throws ObjectAlreadyExists
+ * @throws ObjectCannotBeUpdated
* @see com.c2kernel.lifecycle.instance.WfVertex#run()
*/
@Override
- public void run(AgentPath agent, ItemPath item) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void run(AgentPath agent, ItemPath item) throws InvalidData
{
runNext(agent, item);
}
@@ -209,7 +215,7 @@ public class Join extends WfVertex return loop2;
}
@Override
- public void runFirst(AgentPath agent, ItemPath item) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void runFirst(AgentPath agent, ItemPath item) throws InvalidData
{
runNext(agent, item);
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Loop.java b/src/main/java/com/c2kernel/lifecycle/instance/Loop.java index 0ff1ec8..30e1bb7 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Loop.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Loop.java @@ -19,11 +19,7 @@ * http://www.fsf.org/licensing/licenses/lgpl.html
*/
package com.c2kernel.lifecycle.instance;
-import com.c2kernel.common.AccessRightsException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.common.PersistencyException;
+import com.c2kernel.common.InvalidData;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.graph.traversal.GraphTraversal;
import com.c2kernel.lookup.AgentPath;
@@ -51,7 +47,7 @@ public class Loop extends XOrSplit return true;
}
@Override
- public void followNext(Next activeNext, AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void followNext(Next activeNext, AgentPath agent, ItemPath itemPath) throws InvalidData
{
WfVertex v = activeNext.getTerminusVertex();
if (!isInPrev(v))
@@ -63,11 +59,11 @@ public class Loop extends XOrSplit }
}
/**
- * @throws InvalidDataException
+ * @throws InvalidData
* @see com.c2kernel.lifecycle.instance.WfVertex#reinit(int)
*/
@Override
- public void reinit(int idLoop) throws InvalidDataException
+ public void reinit(int idLoop) throws InvalidData
{
Logger.msg(8, "Loop.reinit");
if (idLoop == getID())
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java b/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java index cb4ec45..eabf46a 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/OrSplit.java @@ -21,7 +21,7 @@ package com.c2kernel.lifecycle.instance;
import java.util.StringTokenizer;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidData;
import com.c2kernel.graph.model.DirectedEdge;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
@@ -41,7 +41,7 @@ public class OrSplit extends Split super();
}
@Override
- public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidDataException
+ public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidData
{
String nexts;
String scriptName = (String) getProperties().get("RoutingScriptName");
@@ -50,7 +50,7 @@ public class OrSplit extends Split nexts = this.evaluateScript(scriptName, scriptVersion, itemPath).toString();
} catch (ScriptingEngineException e) {
Logger.error(e);
- throw new InvalidDataException("Error running routing script "+scriptName+" v"+scriptVersion, null);
+ throw new InvalidData("Error running routing script "+scriptName+" v"+scriptVersion);
}
StringTokenizer tok = new StringTokenizer(nexts, ",");
Logger.msg(7, tok.countTokens() + " nexts to activate:" + nexts);
@@ -82,7 +82,7 @@ public class OrSplit extends Split Logger.error(e);
}
if (active == 0)
- throw new InvalidDataException("No nexts were activated!", null);
+ throw new InvalidData("No nexts were activated!");
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Split.java b/src/main/java/com/c2kernel/lifecycle/instance/Split.java index 76fee48..e4bbb09 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Split.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Split.java @@ -23,9 +23,11 @@ package com.c2kernel.lifecycle.instance; import java.util.Vector;
import com.c2kernel.common.AccessRightsException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.InvalidTransition;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.common.PersistencyException;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.graph.traversal.GraphTraversal;
@@ -53,15 +55,17 @@ public abstract class Split extends WfVertex private boolean loopTested;
/**
- * @throws InvalidDataException
- * @throws ObjectNotFoundException
+ * @throws InvalidData
+ * @throws ObjectNotFound
* @throws AccessRightsException
- * @throws InvalidTransitionException
+ * @throws InvalidTransition
* @throws PersistencyException
+ * @throws ObjectAlreadyExists
+ * @throws ObjectCannotBeUpdated
* @see com.c2kernel.lifecycle.instance.WfVertex#runNext()
*/
@Override
- public abstract void runNext(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException;
+ public abstract void runNext(AgentPath agent, ItemPath itemPath) throws InvalidData;
/**
* Method addNext.
@@ -93,7 +97,7 @@ public abstract class Split extends WfVertex }
@Override
- public void reinit(int idLoop) throws InvalidDataException
+ public void reinit(int idLoop) throws InvalidData
{
Vertex[] outVertices = getOutGraphables();
for (Vertex outVertice : outVertices)
@@ -167,15 +171,17 @@ public abstract class Split extends WfVertex }
/**
- * @throws InvalidDataException
- * @throws ObjectNotFoundException
+ * @throws InvalidData
+ * @throws ObjectNotFound
* @throws AccessRightsException
- * @throws InvalidTransitionException
+ * @throws InvalidTransition
* @throws PersistencyException
+ * @throws ObjectAlreadyExists
+ * @throws ObjectCannotBeUpdated
* @see com.c2kernel.lifecycle.instance.WfVertex#run()
*/
@Override
- public void run(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void run(AgentPath agent, ItemPath itemPath) throws InvalidData
{
runNext(agent, itemPath);
}
@@ -224,7 +230,7 @@ public abstract class Split extends WfVertex }
@Override
- public void runFirst(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void runFirst(AgentPath agent, ItemPath itemPath) throws InvalidData
{
runNext(agent, itemPath);
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/WfVertex.java b/src/main/java/com/c2kernel/lifecycle/instance/WfVertex.java index 12cfa4e..7eb61a6 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/WfVertex.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/WfVertex.java @@ -25,10 +25,11 @@ package com.c2kernel.lifecycle.instance; import java.util.HashMap;
import com.c2kernel.common.AccessRightsException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
-import com.c2kernel.common.ObjectAlreadyExistsException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.InvalidTransition;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.common.PersistencyException;
import com.c2kernel.graph.model.GraphableVertex;
import com.c2kernel.lifecycle.routingHelpers.ViewpointDataHelper;
@@ -49,13 +50,14 @@ 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 InvalidData
+ * @throws ObjectAlreadyExists
+ * @throws ObjectNotFound
* @throws AccessRightsException
- * @throws InvalidTransitionException
- * @throws PersistencyException */
- public abstract void runFirst(AgentPath agent, ItemPath itemPath) throws ScriptingEngineException, InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, ObjectAlreadyExistsException, PersistencyException;
+ * @throws InvalidTransition
+ * @throws PersistencyException
+ * @throws ObjectCannotBeUpdated */
+ public abstract void runFirst(AgentPath agent, ItemPath itemPath) throws InvalidData;
/**
* @see java.lang.Object#Object()
@@ -69,14 +71,15 @@ public abstract class WfVertex extends GraphableVertex /**
* Method runNext.
- * @throws InvalidDataException
- * @throws ObjectNotFoundException
+ * @throws InvalidData
+ * @throws ObjectNotFound
* @throws AccessRightsException
- * @throws InvalidTransitionException
+ * @throws InvalidTransition
* @throws PersistencyException
- * @throws ObjectAlreadyExistsException
+ * @throws ObjectAlreadyExists
+ * @throws ObjectCannotBeUpdated
*/
- public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidData
{
try
{
@@ -92,10 +95,10 @@ public abstract class WfVertex extends GraphableVertex /**
* Method reinit.
* @param idLoop
- * @throws InvalidDataException
- * @throws ObjectNotFoundException
+ * @throws InvalidData
+ * @throws ObjectNotFound
*/
- public abstract void reinit( int idLoop ) throws InvalidDataException;
+ public abstract void reinit( int idLoop ) throws InvalidData;
/**
* Method verify.
@@ -111,14 +114,15 @@ public abstract class WfVertex extends GraphableVertex /**
* Method run.
- * @throws InvalidDataException
- * @throws ObjectAlreadyExistsException
- * @throws ObjectNotFoundException
+ * @throws InvalidData
+ * @throws ObjectAlreadyExists
+ * @throws ObjectNotFound
* @throws AccessRightsException
- * @throws InvalidTransitionException
+ * @throws InvalidTransition
* @throws PersistencyException
+ * @throws ObjectCannotBeUpdated
*/
- public abstract void run(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException;
+ public abstract void run(AgentPath agent, ItemPath itemPath) throws InvalidData;
/**
* Method loop.
@@ -155,7 +159,7 @@ public abstract class WfVertex extends GraphableVertex try {
inputParam = ViewpointDataHelper.get(value)[0];
} catch (ArrayIndexOutOfBoundsException ex) {
- throw new InvalidDataException("Could not retrieve data from viewpoint: "+value, "");
+ throw new InvalidData("Could not retrieve data from viewpoint: "+value);
}
}
if (value.startsWith("property//"))
@@ -163,7 +167,7 @@ public abstract class WfVertex extends GraphableVertex value = value.substring(10);
try {
inputParam = Gateway.getStorage().get(itemPath, ClusterStorage.PROPERTY+"/"+value, null);
- } catch (ObjectNotFoundException ex) {
+ } catch (ObjectNotFound ex) {
inputParam = null;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java index abb38cf..f1719f6 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java @@ -22,10 +22,13 @@ 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.CannotManage;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.InvalidTransition;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.entity.agent.Job;
@@ -78,10 +81,10 @@ public class Workflow extends CompositeActivity implements C2KLocalObject addChild(predef, new GraphPoint(300, 100));
}
- public History getHistory() throws InvalidDataException {
+ public History getHistory() throws InvalidData {
if (history == null) {
if (itemPath == null)
- throw new InvalidDataException("Workflow not initialized.", "");
+ throw new InvalidData("Workflow not initialized.");
history = new History(itemPath, this);
}
return history;
@@ -114,21 +117,24 @@ public class Workflow extends CompositeActivity implements C2KLocalObject * @param stepPath
* @param transitionID
* @param reguestData
- * @throws ObjectNotFoundException
+ * @throws ObjectNotFound
* @throws AccessRightsException
- * @throws InvalidTransitionException
- * @throws InvalidDataException
+ * @throws InvalidTransition
+ * @throws InvalidData
* @throws PersistencyException
+ * @throws ObjectCannotBeUpdated
+ * @throws CannotManage
+ * @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
+ throws ObjectNotFound, AccessRightsException, InvalidTransition, InvalidData, ObjectAlreadyExists, PersistencyException, ObjectCannotBeUpdated, CannotManage, 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", "");
+ throw new ObjectNotFound(stepPath + " not found");
}
/**
@@ -190,25 +196,17 @@ public class Workflow extends CompositeActivity implements C2KLocalObject * Method initialise.
*
* @param systemKey
- * @throws InvalidDataException
- * @throws ObjectNotFoundException
+ * @throws InvalidData
+ * @throws ObjectNotFound
* @throws AccessRightsException
- * @throws InvalidTransitionException
+ * @throws InvalidTransition
+ * @throws ObjectAlreadyExists
+ * @throws ObjectCannotBeUpdated
*/
- public void initialise(ItemPath itemPath, AgentPath agent) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException
+ public void initialise(ItemPath itemPath, AgentPath agent) throws InvalidData
{
setItemPath(itemPath);
- try
- {
- runFirst(agent, itemPath);
- }
- catch (InvalidDataException ex)
- {
- Logger.error(ex);
- } catch (PersistencyException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ runFirst(agent, itemPath);
}
public ItemPath getItemPath() {
@@ -234,11 +232,11 @@ public class Workflow extends CompositeActivity implements C2KLocalObject * @param itemSysKey
* @param type
* @return
- * @throws ObjectNotFoundException
- * @throws InvalidDataException
+ * @throws ObjectNotFound
+ * @throws InvalidData
* @throws InvalidAgentPathException
*/
- public ArrayList<Job> calculateJobs(AgentPath agent, ItemPath itemPath, int type) throws ObjectNotFoundException, InvalidDataException, InvalidAgentPathException
+ public ArrayList<Job> calculateJobs(AgentPath agent, ItemPath itemPath, int type) throws InvalidAgentPathException, ObjectNotFound, InvalidData
{
ArrayList<Job> jobs = new ArrayList<Job>();
if (type != 1)
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java b/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java index 28896af..e5b91d3 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/XOrSplit.java @@ -23,11 +23,7 @@ package com.c2kernel.lifecycle.instance; import java.util.ArrayList;
import java.util.StringTokenizer;
-import com.c2kernel.common.AccessRightsException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.common.PersistencyException;
+import com.c2kernel.common.InvalidData;
import com.c2kernel.graph.model.DirectedEdge;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
@@ -49,7 +45,7 @@ public class XOrSplit extends Split }
@Override
- public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException
+ public void runNext(AgentPath agent, ItemPath itemPath) throws InvalidData
{
ArrayList<DirectedEdge> nextsToFollow = new ArrayList<DirectedEdge>();
String nexts;
@@ -59,7 +55,7 @@ public class XOrSplit extends Split nexts = this.evaluateScript(scriptName, scriptVersion, itemPath).toString();
} catch (ScriptingEngineException e) {
Logger.error(e);
- throw new InvalidDataException("Error running routing script "+scriptName+" v"+scriptVersion, "");
+ throw new InvalidData("Error running routing script "+scriptName+" v"+scriptVersion);
}
StringTokenizer tok = new StringTokenizer(nexts,",");
@@ -74,13 +70,13 @@ public class XOrSplit extends Split }
// Logger.debug(0, getID()+" following "+nexts);
if (nextsToFollow.size() != 1)
- throw new InvalidDataException("not good number of active next", null);
+ throw new InvalidData("not good number of active next");
followNext((Next)nextsToFollow.get(0), agent, itemPath);
}
- public void followNext(Next activeNext, AgentPath agent, ItemPath itemPath) throws InvalidDataException, InvalidTransitionException, AccessRightsException, ObjectNotFoundException, PersistencyException {
+ public void followNext(Next activeNext, AgentPath agent, ItemPath itemPath) throws InvalidData {
activeNext.getTerminusVertex().run(agent, itemPath);
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddC2KObject.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddC2KObject.java index db1e85a..8c078aa 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddC2KObject.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddC2KObject.java @@ -22,7 +22,8 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
@@ -48,19 +49,18 @@ public class AddC2KObject extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, PersistencyException {
String[] params = getDataList(requestData);
if (Logger.doLog(3)) Logger.msg(3, "AddC2KObject: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params));
- try
- {
- C2KLocalObject obj = (C2KLocalObject)Gateway.getMarshaller().unmarshall(params[0]);
- Gateway.getStorage().put(item, obj, null );
- return requestData;
- }
- catch( Exception ex )
- {
- throw unknownException(ex);
- }
+ if (params.length != 1) throw new InvalidData("AddC2KObject: Invalid parameters "+Arrays.toString(params));
+ C2KLocalObject obj;
+ try {
+ obj = (C2KLocalObject)Gateway.getMarshaller().unmarshall(params[0]);
+ } catch (Exception e) {
+ throw new InvalidData("AddC2KObject: Could not unmarshall new object: "+params[0]);
+ }
+ Gateway.getStorage().put(item, obj, null );
+ return requestData;
}
}
\ No newline at end of file diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java index d838aa7..1067911 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java @@ -25,7 +25,10 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.ItemPath;
@@ -43,22 +46,16 @@ public class AddDomainPath extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectCannotBeUpdated, ObjectAlreadyExists, CannotManage {
String[] params = getDataList(requestData);
if (Logger.doLog(3)) Logger.msg(3, "AddDomainPath: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params));
+ if (params.length != 1) throw new InvalidData("AddDomainPath: Invalid parameters "+Arrays.toString(params));
- try
- {
- LookupManager lookupManager = Gateway.getLookupManager();
- DomainPath domainPath = new DomainPath(params[0], item);
- lookupManager.add(domainPath);
- return requestData;
- }
- catch( Exception ex )
- {
- throw unknownException(ex);
- }
+ LookupManager lookupManager = Gateway.getLookupManager();
+ DomainPath domainPath = new DomainPath(params[0], item);
+ lookupManager.add(domainPath);
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java index cbe812e..43316b2 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddMemberToCollection.java @@ -24,14 +24,15 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays;
import com.c2kernel.collection.Dependency;
-import com.c2kernel.collection.MembershipException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
-import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.CastorHashMap;
import com.c2kernel.utils.Logger;
@@ -58,10 +59,14 @@ public class AddMemberToCollection extends PredefinedStep * Params:
* 0 - collection name
* 1 - target entity key
+ * @throws ObjectAlreadyExists
+ * @throws PersistencyException
+ * @throws ObjectNotFound
+ * @throws InvalidCollectionModification
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectAlreadyExists, PersistencyException, ObjectNotFound, InvalidCollectionModification {
String collName;
ItemPath newChild;
@@ -78,37 +83,22 @@ public class AddMemberToCollection extends PredefinedStep props = (CastorHashMap)Gateway.getMarshaller().unmarshall(params[2]);
} catch (Exception e) {
- throw new InvalidDataException("AddMemberToCollection: Invalid parameters "+Arrays.toString(params), "");
+ throw new InvalidData("AddMemberToCollection: Invalid parameters "+Arrays.toString(params));
}
// load collection
C2KLocalObject collObj;
- try {
- collObj = Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null);
- } catch (ObjectNotFoundException ex) {
- throw new InvalidDataException("AddMemberToCollection: Collection '"+collName+"' not found in this Item", "");
- } catch (ClusterStorageException ex) {
- Logger.error(ex);
- throw new InvalidDataException("AddMemberToCollection: Error loading collection '\"+collName+\"': "+ex.getMessage(), "");
- }
- if (!(collObj instanceof Dependency)) throw new InvalidDataException("AddMemberToCollection: AddMemberToCollection operates on Dependency collections only.", "");
+ collObj = Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null);
+ if (!(collObj instanceof Dependency)) throw new InvalidData("AddMemberToCollection: AddMemberToCollection operates on Dependency collections only.");
dep = (Dependency)collObj;
-
+
// find member and assign entity
- try {
- if (props == null)
- dep.addMember(newChild);
- else
- dep.addMember(newChild, props, null);
- } catch (MembershipException e) {
- throw new InvalidDataException("AddMemberToCollection: Item "+newChild+" is the wrong type for this collection", "");
- }
+ if (props == null)
+ dep.addMember(newChild);
+ else
+ dep.addMember(newChild, props, null);
- try {
- Gateway.getStorage().put(newChild, dep, null);
- } catch (ClusterStorageException e) {
- throw unknownException(e);
- }
+ Gateway.getStorage().put(newChild, dep, null);
return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java new file mode 100644 index 0000000..6eb69f3 --- /dev/null +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java @@ -0,0 +1,109 @@ +/**
+ * 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 com.c2kernel.lifecycle.instance.predefined;
+
+
+import java.util.Arrays;
+
+import com.c2kernel.collection.AggregationDescription;
+import com.c2kernel.collection.CollectionDescription;
+import com.c2kernel.collection.DependencyDescription;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.ItemPath;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.utils.Logger;
+
+/**************************************************************************
+ *
+ * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $
+ * @version $Revision: 1.8 $
+ **************************************************************************/
+public class 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 InvalidData, ObjectAlreadyExists, 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 InvalidData("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 ObjectAlreadyExists("Collection '"+collName+"' already exists");
+ } catch (ObjectNotFound 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 InvalidData("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/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java index 87cbda0..19ef2ae 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java @@ -24,13 +24,13 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays;
import com.c2kernel.collection.Aggregation;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
-import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
import com.c2kernel.property.PropertyDescription;
import com.c2kernel.property.PropertyDescriptionList;
@@ -62,10 +62,14 @@ public class AddNewSlot extends PredefinedStep * <li>Item Description key (optional)</li>
* <li>Item Description version (optional)</li>
* </ol>
+ *
+ * @throws InvalidData Then the parameters were incorrect
+ * @throws PersistencyException There was a problem loading or saving the collection from persistency
+ * @throws ObjectNotFound 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 {
+ int transitionID, String requestData) throws InvalidData, PersistencyException, ObjectNotFound {
String collName;
ItemPath descKey = null;
@@ -82,20 +86,18 @@ public class AddNewSlot extends PredefinedStep 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), "");
+ throw new InvalidData("AddNewSlot: Invalid parameters "+Arrays.toString(params));
}
// load collection
C2KLocalObject collObj;
try {
collObj = Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null);
- } catch (ObjectNotFoundException ex) {
- throw new InvalidDataException("AddNewSlot: Collection '"+collName+"' not found in this Item", "");
- } catch (ClusterStorageException ex) {
+ } catch (PersistencyException ex) {
Logger.error(ex);
- throw new InvalidDataException("AddNewSlot: Error loading collection '\"+collName+\"': "+ex.getMessage(), "");
+ throw new PersistencyException("AddNewSlot: Error loading collection '\"+collName+\"': "+ex.getMessage());
}
- if (!(collObj instanceof Aggregation)) throw new InvalidDataException("AddNewSlot: AddNewSlot operates on Aggregation collections only.", "");
+ if (!(collObj instanceof Aggregation)) throw new InvalidData("AddNewSlot: AddNewSlot operates on Aggregation collections only.");
agg = (Aggregation)collObj;
// get props
@@ -103,11 +105,7 @@ public class AddNewSlot extends PredefinedStep StringBuffer classProps = new StringBuffer();
if (descKey != null) {
PropertyDescriptionList propList;
- try {
- propList = PropertyUtility.getPropertyDescriptionOutcome(descKey, descVer);
- } catch (ObjectNotFoundException e) {
- throw new InvalidDataException("AddNewSlot: Item "+descKey+" does not contain a PropertyDescription outcome to define a slot", "");
- }
+ propList = PropertyUtility.getPropertyDescriptionOutcome(descKey, descVer);
for (PropertyDescription pd : propList.list) {
props.put(pd.getName(), pd.getDefaultValue());
if (pd.getIsClassIdentifier())
@@ -119,9 +117,9 @@ public class AddNewSlot extends PredefinedStep try {
Gateway.getStorage().put(item, agg, null);
- } catch (ClusterStorageException e) {
+ } catch (PersistencyException e) {
Logger.error(e);
- throw new InvalidDataException("AddNewSlot: Error storing collection", "");
+ throw new PersistencyException("AddNewSlot: Error saving collection '"+collName+"': "+e.getMessage());
}
return requestData;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java index 054b2da..fdf852f 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AssignItemToSlot.java @@ -25,14 +25,15 @@ import java.util.Arrays; import com.c2kernel.collection.Aggregation;
import com.c2kernel.collection.AggregationMember;
-import com.c2kernel.collection.MembershipException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
-import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -57,10 +58,14 @@ public class AssignItemToSlot extends PredefinedStep * 0 - collection name
* 1 - slot number
* 2 - target entity key
+ * @throws ObjectNotFound
+ * @throws PersistencyException
+ * @throws ObjectCannotBeUpdated
+ * @throws InvalidCollectionModification
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, PersistencyException, ObjectCannotBeUpdated, InvalidCollectionModification {
String collName;
int slotNo;
@@ -76,20 +81,18 @@ public class AssignItemToSlot extends PredefinedStep slotNo = Integer.parseInt(params[1]);
childItem = new ItemPath(params[2]);
} catch (Exception e) {
- throw new InvalidDataException("AssignItemToSlot: Invalid parameters "+Arrays.toString(params), "");
+ throw new InvalidData("AssignItemToSlot: Invalid parameters "+Arrays.toString(params));
}
// load collection
C2KLocalObject collObj;
try {
collObj = Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null);
- } catch (ObjectNotFoundException ex) {
- throw new InvalidDataException("AssignItemToSlot: Collection '"+collName+"' not found in this Item", "");
- } catch (ClusterStorageException ex) {
+ } catch (PersistencyException ex) {
Logger.error(ex);
- throw new InvalidDataException("AssignItemToSlot: Error loading collection '\"+collName+\"': "+ex.getMessage(), "");
+ throw new PersistencyException("AssignItemToSlot: Error loading collection '\"+collName+\"': "+ex.getMessage());
}
- if (!(collObj instanceof Aggregation)) throw new InvalidDataException("AssignItemToSlot: AssignItemToSlot operates on Aggregation collections only.", "");
+ if (!(collObj instanceof Aggregation)) throw new InvalidData("AssignItemToSlot: AssignItemToSlot operates on Aggregation collections only.");
agg = (Aggregation)collObj;
// find member and assign entity
@@ -97,25 +100,20 @@ public class AssignItemToSlot extends PredefinedStep for (AggregationMember member : agg.getMembers().list) {
if (member.getID() == slotNo) {
if (member.getItemPath() != null)
- throw new InvalidDataException("AssignItemToSlot: Member slot "+slotNo+" not empty", "");
- try {
- member.assignItem(childItem);
- } catch (MembershipException e) {
- throw new InvalidDataException("AssignItemToSlot: Item "+childItem+" does not fit in slot "+slotNo, "");
- }
+ throw new ObjectCannotBeUpdated("AssignItemToSlot: Member slot "+slotNo+" not empty");
+ member.assignItem(childItem);
stored = true;
break;
}
}
if (!stored) {
- throw new InvalidDataException("AssignItemToSlot: Member slot "+slotNo+" not found.", "");
+ throw new ObjectNotFound("AssignItemToSlot: Member slot "+slotNo+" not found.");
}
-
try {
Gateway.getStorage().put(item, agg, null);
- } catch (ClusterStorageException e) {
- unknownException(e);
+ } catch (PersistencyException e) {
+ throw new PersistencyException("AssignItemToSlot: Error saving collection '"+collName+"': "+e.getMessage());
}
return requestData;
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java index acba2cb..a15b98f 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ClearSlot.java @@ -25,12 +25,13 @@ import java.util.Arrays; import com.c2kernel.collection.Aggregation;
import com.c2kernel.collection.AggregationMember;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
-import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -54,10 +55,13 @@ public class ClearSlot extends PredefinedStep * Params:
* 0 - collection name
* 1 - slot number
+ * @throws ObjectNotFound
+ * @throws PersistencyException
+ * @throws ObjectCannotBeUpdated
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, PersistencyException, ObjectCannotBeUpdated {
String collName;
int slotNo;
@@ -71,17 +75,15 @@ public class ClearSlot extends PredefinedStep collName = params[0];
slotNo = Integer.parseInt(params[1]);
} catch (Exception e) {
- throw new InvalidDataException("ClearSlot: Invalid parameters "+Arrays.toString(params), "");
+ throw new InvalidData("ClearSlot: Invalid parameters "+Arrays.toString(params));
}
// load collection
try {
agg = (Aggregation)Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null);
- } catch (ObjectNotFoundException ex) {
- throw new InvalidDataException("ClearSlot: Collection '"+collName+"' not found in this Item", "");
- } catch (ClusterStorageException ex) {
+ } catch (PersistencyException ex) {
Logger.error(ex);
- throw new InvalidDataException("ClearSlot: Error loading collection '"+collName+"': "+ex.getMessage(), "");
+ throw new PersistencyException("ClearSlot: Error loading collection '"+collName+"': "+ex.getMessage());
}
// find member and clear
@@ -89,22 +91,22 @@ public class ClearSlot extends PredefinedStep for (AggregationMember member : agg.getMembers().list) {
if (member.getID() == slotNo) {
if (member.getItemPath() != null)
- throw new InvalidDataException("ClearSlot: Member slot "+slotNo+" already empty", "");
+ throw new ObjectCannotBeUpdated("ClearSlot: Member slot "+slotNo+" already empty");
member.clearItem();
stored = true;
break;
}
}
if (!stored) {
- throw new InvalidDataException("Member slot "+slotNo+" not found.", "");
+ throw new ObjectNotFound("ClearSlot: Member slot "+slotNo+" not found.");
}
try {
Gateway.getStorage().put(item, agg, null);
- } catch (ClusterStorageException e) {
+ } catch (PersistencyException e) {
Logger.error(e);
- throw new InvalidDataException("Error storing collection", "");
+ throw new PersistencyException("ClearSlot: Error storing collection");
}
return requestData;
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/Import.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/Import.java index 0210fe3..e17919d 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/Import.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/Import.java @@ -22,12 +22,12 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.events.Event;
import com.c2kernel.events.History;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
-import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.TransactionManager;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.persistency.outcome.Viewpoint;
@@ -54,7 +54,7 @@ public class Import extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, PersistencyException {
String[] params = getDataList(requestData);
if (Logger.doLog(3)) Logger.msg(3, "Import: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params));
@@ -63,7 +63,7 @@ public class Import extends PredefinedStep int split2 = params[0].indexOf(':');
if (split1 == -1)
- throw new InvalidDataException("Import: Invalid parameters "+Arrays.toString(params));
+ throw new InvalidData("Import: Invalid parameters "+Arrays.toString(params));
requestData = params[1];
@@ -95,10 +95,9 @@ public class Import extends PredefinedStep 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 (ClusterStorageException e) {
- Logger.error(e);
+ } catch (PersistencyException e) {
storage.abort(locker);
- throw new InvalidDataException("Import: Could not store imported outcome. Rolled back.", "");
+ throw e;
}
storage.commit(locker);
return requestData;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java index 1d4476f..9b6d6c4 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStep.java @@ -32,7 +32,6 @@ import org.w3c.dom.NodeList; import org.w3c.dom.Text;
import org.xml.sax.InputSource;
-import com.c2kernel.common.InvalidDataException;
import com.c2kernel.lifecycle.instance.Activity;
import com.c2kernel.lifecycle.instance.predefined.agent.AgentPredefinedStepContainer;
import com.c2kernel.lifecycle.instance.predefined.item.ItemPredefinedStepContainer;
@@ -158,12 +157,6 @@ public abstract class PredefinedStep extends Activity return xmlData.toString();
}
}
- public InvalidDataException unknownException(Exception ex) {
- String stepName = this.getClass().getSimpleName();
- Logger.error(stepName+": Exception:");
- Logger.error(ex);
- return new InvalidDataException(stepName+": "+ex.getClass().getSimpleName()+". See log.", "");
- }
// generic bundling of single parameter
static public String bundleData(String data)
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java index 4e53f39..abf625c 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java @@ -41,6 +41,7 @@ public abstract class PredefinedStepContainer extends CompositeActivity 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("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());
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveC2KObject.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveC2KObject.java index 1b9b6f7..a88e000 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveC2KObject.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveC2KObject.java @@ -24,7 +24,8 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.process.Gateway;
@@ -47,19 +48,21 @@ public class RemoveC2KObject extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, 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 InvalidData("RemoveC2KObject: Invalid parameters "+Arrays.toString(params));
+ String path = params[0];
+
try
{
- String path = params[0];
Gateway.getStorage().remove( item, path, null );
}
- catch( Exception ex )
+ catch( PersistencyException ex )
{
- throw unknownException(ex);
+ throw new PersistencyException("RemoveC2KObject: Error removing object '"+path+"': "+ex.getMessage());
}
return requestData;
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java index 3181249..0248650 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java @@ -25,8 +25,10 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.ItemPath;
@@ -44,29 +46,27 @@ public class RemoveDomainPath extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, ObjectCannotBeUpdated, CannotManage {
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 InvalidData("RemoveDomainPath: Invalid parameters "+Arrays.toString(params));
+
DomainPath domainPath = new DomainPath(params[0]);
if (!domainPath.exists())
- throw new InvalidDataException("RemoveDomainPath: Domain path "+domainPath.toString()+" does not exist.", "");
+ throw new ObjectNotFound("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.", "");
- }
- try {
- LookupManager lookupManager = Gateway.getLookupManager();
- lookupManager.delete(domainPath);
- return requestData;
- } catch (Exception ex) {
- throw unknownException(ex);
+ throw new InvalidData("RemoveDomainPath: Domain path "+domainPath.toString()+" is not an alias of the current Item "+item);
+ } catch (ObjectNotFound ex) {
+ throw new InvalidData("RemoveDomainPath: Domain path "+domainPath.toString()+" is a context.");
}
+
+ LookupManager lookupManager = Gateway.getLookupManager();
+ lookupManager.delete(domainPath);
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java index e228688..061202d 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java @@ -25,13 +25,12 @@ import java.util.Arrays; import com.c2kernel.collection.Collection;
import com.c2kernel.collection.CollectionMember;
-import com.c2kernel.collection.MembershipException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
-import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -56,10 +55,12 @@ public class RemoveSlotFromCollection extends PredefinedStep * 0 - collection name
* 1 - slot number OR if null:
* 2 - target entity key
+ * @throws ObjectNotFound
+ * @throws PersistencyException
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, PersistencyException {
String collName;
int slotNo = -1;
@@ -75,35 +76,29 @@ public class RemoveSlotFromCollection extends PredefinedStep 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), "");
+ throw new InvalidData("RemoveSlotFromCollection: Invalid parameters "+Arrays.toString(params));
}
if (slotNo == -1 && currentChild == null)
- throw new InvalidDataException("RemoveSlotFromCollection: Must give either slot number or entity key", "");
+ throw new InvalidData("RemoveSlotFromCollection: Must give either slot number or entity key");
// load collection
try {
coll = (Collection<? extends CollectionMember>)Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null);
- } catch (ObjectNotFoundException ex) {
- throw new InvalidDataException("RemoveSlotFromCollection: Collection '"+collName+"' not found in this Item", "");
- } catch (ClusterStorageException ex) {
+ } catch (PersistencyException ex) {
Logger.error(ex);
- throw new InvalidDataException("RemoveSlotFromCollection: Error loading collection '\"+collName+\"': "+ex.getMessage(), "");
+ 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) {
- try {
- slot = coll.getMember(slotNo);
- } catch (ObjectNotFoundException e) {
- throw new InvalidDataException("RemoveSlotFromCollection: Slot "+slotNo+" not found in this collection", "");
- }
+ 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 InvalidDataException("RemoveSlotFromCollection: Item "+currentChild+" was not in slot "+slotNo, "");
+ throw new ObjectNotFound("RemoveSlotFromCollection: Item "+currentChild+" was not in slot "+slotNo);
}
if (slotNo == -1) { // find slot from entity key
@@ -115,22 +110,18 @@ public class RemoveSlotFromCollection extends PredefinedStep }
}
if (slotNo == -1) {
- throw new InvalidDataException("No match", "");
+ throw new ObjectNotFound("Could not find "+currentChild+" in collection "+coll.getName());
}
// Remove the slot
- try {
- coll.removeMember(slotNo);
- } catch (MembershipException e) {
- throw new InvalidDataException(e.getMessage(), "");
- }
+ coll.removeMember(slotNo);
// Store the collection
try {
Gateway.getStorage().put(item, coll, null);
- } catch (ClusterStorageException e) {
+ } catch (PersistencyException e) {
Logger.error(e);
- throw new InvalidDataException("Error storing collection", "");
+ throw new PersistencyException("Error storing collection");
}
return requestData;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java index 14c6488..ddb89ba 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java @@ -23,7 +23,8 @@ package com.c2kernel.lifecycle.instance.predefined; //Java
import java.util.Arrays;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.lifecycle.instance.CompositeActivity;
import com.c2kernel.lifecycle.instance.Workflow;
@@ -42,30 +43,34 @@ public class ReplaceDomainWorkflow extends PredefinedStep @Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, 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));
-
- try
- {
- lifeCycle.getChildGraphModel().removeVertex(lifeCycle.search("workflow/domain"));
- CompositeActivity domain = (CompositeActivity) Gateway.getMarshaller().unmarshall(params[0]);
- 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
- Gateway.getStorage().put(item, lifeCycle, null);
- return requestData;
+ if (params.length != 1) throw new InvalidData("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 InvalidData("ReplaceDomainWorkflow: Could not unmarshall new workflow: "+e.getMessage());
}
- catch (Exception ex)
- {
- throw unknownException(ex);
+ 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/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java index 6dd7e0a..e41411b 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java @@ -22,12 +22,13 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
-import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
import com.c2kernel.property.Property;
import com.c2kernel.utils.Logger;
@@ -50,13 +51,13 @@ public class WriteProperty extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectCannotBeUpdated, ObjectNotFound, 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), "");
+ throw new InvalidData("WriteProperty: invalid parameters "+Arrays.toString(params));
String name = params[0];
String newValue = params[1];
@@ -66,13 +67,11 @@ public class WriteProperty extends PredefinedStep try {
prop = (Property)Gateway.getStorage().get(item, ClusterStorage.PROPERTY+"/"+name, null);
if (!prop.isMutable() && !newValue.equals(prop.getValue()))
- throw new InvalidDataException("WriteProperty: Property '"+name+"' is not mutable.", "");
+ throw new ObjectCannotBeUpdated("WriteProperty: Property '"+name+"' is not mutable.");
prop.setValue(newValue);
Gateway.getStorage().put(item, prop, null);
- } catch (ObjectNotFoundException e) {
- throw new InvalidDataException("WriteProperty: Property '"+name+"' not found.", "");
- } catch (ClusterStorageException e) {
- throw unknownException(e);
+ } catch (ObjectNotFound e) {
+ throw new ObjectNotFound("WriteProperty: Property '"+name+"' not found.");
}
return requestData;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteViewpoint.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteViewpoint.java index 349e34c..efe6a5f 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteViewpoint.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteViewpoint.java @@ -22,13 +22,13 @@ package com.c2kernel.lifecycle.instance.predefined; import java.util.Arrays;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.events.Event;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
-import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -41,7 +41,7 @@ public class WriteViewpoint extends PredefinedStep { @Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, PersistencyException {
String schemaName;
String viewName;
@@ -52,7 +52,7 @@ public class WriteViewpoint extends PredefinedStep { // 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), "");
+ throw new InvalidData("WriteViewpoint: Invalid parameters "+Arrays.toString(params));
schemaName = params[0];
viewName = params[1];
@@ -60,7 +60,7 @@ public class WriteViewpoint extends PredefinedStep { try {
evId = Integer.parseInt(params[2]);
} catch (NumberFormatException ex) {
- throw new InvalidDataException("WriteViewpoint: Parameter 3 (EventId) must be an integer", "");
+ throw new InvalidData("WriteViewpoint: Parameter 3 (EventId) must be an integer");
}
// Find event
@@ -68,21 +68,18 @@ public class WriteViewpoint extends PredefinedStep { Event ev;
try {
ev = (Event)Gateway.getStorage().get(item, ClusterStorage.HISTORY+"/"+evId, null);
- } catch (ObjectNotFoundException e) {
+ } catch (PersistencyException e) {
Logger.error(e);
- throw new InvalidDataException("WriteViewpoint: Event "+evId+" not found", "");
- } catch (ClusterStorageException e) {
- Logger.error(e);
- throw new InvalidDataException("WriteViewpoint: Exception loading event", "");
+ 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 (ClusterStorageException e) {
+ } catch (PersistencyException e) {
Logger.error(e);
- throw new InvalidDataException("WriteViewpoint: Could not store new viewpoint", "");
+ throw new PersistencyException("WriteViewpoint: Could not store new viewpoint");
}
return requestData;
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java index 0ce7c67..564c5db 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java @@ -20,10 +20,14 @@ */
package com.c2kernel.lifecycle.instance.predefined.agent;
-import com.c2kernel.common.AccessRightsException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectAlreadyExistsException;
-import com.c2kernel.common.ObjectNotFoundException;
+import java.util.Arrays;
+
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.CorbaServer;
import com.c2kernel.entity.agent.ActiveEntity;
import com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription;
@@ -53,71 +57,80 @@ public class CreateAgentFromDescription extends CreateItemFromDescription * <li>Comma-delimited Role names to assign to the agent. Must already exist.</li>
* <li>Initial properties to set in the new Agent</li>
* </ol>
+ * @throws ObjectNotFound
+ * @throws InvalidData The input parameters were incorrect
+ * @throws ObjectAlreadyExists The Agent already exists
+ * @throws CannotManage The Agent could not be created
+ * @throws ObjectCannotBeUpdated The addition of the new entries into the LookupManager failed
* @see com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(com.c2kernel.lookup.AgentPath, int, int, java.lang.String)
*/
@Override
- protected String runActivityLogic(AgentPath agent, ItemPath itemPath,
- int transitionID, String requestData) throws InvalidDataException {
+ protected String runActivityLogic(AgentPath agent, ItemPath item,
+ int transitionID, String requestData) throws ObjectNotFound, InvalidData, ObjectAlreadyExists, CannotManage, 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 InvalidData("CreateAgentFromDescription: Invalid parameters "+Arrays.toString(params));
- String[] input = getDataList(requestData);
- String newName = input[0];
- String descVer = input[1];
- String roles = input[2];
+ String newName = params[0];
+ String descVer = params[1];
+ String roles = params[2];
PropertyArrayList initProps =
- input.length > 3 ? getInitProperties(input[3]):new PropertyArrayList();
+ params.length > 3 ? getInitProperties(params[3]):new PropertyArrayList();
Logger.msg(1, "CreateAgentFromDescription::request() - Starting.");
- try {
-
- // check if given roles exist
- String[] roleArr = roles.split(",");
- for(int i=0; i<roleArr.length; i++) {
- RolePath thisRole = Gateway.getLookup().getRolePath(roleArr[i]);
- if (!thisRole.exists()) throw new InvalidDataException("Role "+roleArr[i]+" does not exist");
- }
-
- // check if the path is already taken
- try {
- Gateway.getLookup().getAgentPath(newName);
- throw new ObjectAlreadyExistsException("The agent name " +newName+ " exists already.", "");
- } catch (ObjectNotFoundException ex) { }
-
- // generate new entity key
- Logger.msg(6, "CreateItemFromDescription - Requesting new agent path");
- AgentPath newAgentPath = new AgentPath(new ItemPath(), newName);
+ // check if given roles exist
+ String[] roleArr = roles.split(",");
+ for(int i=0; i<roleArr.length; i++) {
+ RolePath thisRole = Gateway.getLookup().getRolePath(roleArr[i]);
+ }
+
+ // check if the path is already taken
+ try {
+ Gateway.getLookup().getAgentPath(newName);
+ throw new ObjectAlreadyExists("The agent name " +newName+ " exists already.");
+ } catch (ObjectNotFound ex) { }
- // resolve the item factory
- Logger.msg(6, "CreateItemFromDescription - Resolving item factory");
+ // generate new entity key
+ Logger.msg(6, "CreateItemFromDescription - Requesting new agent path");
+ AgentPath newAgentPath = new AgentPath(new ItemPath(), newName);
- // create the Item object
- Logger.msg(3, "CreateItemFromDescription - Creating Item");
- CorbaServer factory = Gateway.getCorbaServer();
- if (factory == null) throw new AccessRightsException("This process cannot create new Items", "");
- ActiveEntity newAgent = factory.createAgent(newAgentPath);
- Gateway.getLookupManager().add(newAgentPath);
+ // resolve the item factory
+ Logger.msg(6, "CreateItemFromDescription - Resolving item factory");
- // initialise it with its properties and workflow
+ // create the Item object
+ Logger.msg(3, "CreateItemFromDescription - Creating Item");
+ CorbaServer factory = Gateway.getCorbaServer();
+ if (factory == null) throw new CannotManage("This process cannot create new Items");
+ ActiveEntity newAgent = factory.createAgent(newAgentPath);
+ Gateway.getLookupManager().add(newAgentPath);
- Logger.msg(3, "CreateItemFromDescription - Initializing Item");
+ // initialise it with its properties and workflow
- newAgent.initialise(
- agent.getSystemKey(),
- Gateway.getMarshaller().marshall(getNewProperties(itemPath, descVer, initProps, newName, agent)),
- Gateway.getMarshaller().marshall(getNewWorkflow(itemPath, descVer)),
- Gateway.getMarshaller().marshall(getNewCollections(itemPath, descVer))
- );
-
- // add roles if given
-
- for(int i=1; i<input.length; i++) {
- newAgent.addRole(input[i]);
- }
+ Logger.msg(3, "CreateItemFromDescription - Initializing Item");
- return requestData;
- } catch (Exception e) {
- Logger.error(e);
- throw new InvalidDataException(e.getMessage(), "");
+ try {
+ newAgent.initialise(
+ agent.getSystemKey(),
+ Gateway.getMarshaller().marshall(getNewProperties(item, descVer, initProps, newName, agent)),
+ Gateway.getMarshaller().marshall(getNewWorkflow(item, descVer)),
+ Gateway.getMarshaller().marshall(getNewCollections(item, descVer))
+ );
+ } catch (PersistencyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e) {
+ throw new InvalidData("CreateAgentFromDescription: Problem initializing new Agent. See log: "+e.getMessage());
+ }
+
+ // add roles if given
+
+ for(int i=1; i<roleArr.length; i++) {
+ newAgent.addRole(roleArr[i]);
}
+
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java index ca1a8e4..65608c7 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java @@ -20,16 +20,16 @@ */
package com.c2kernel.lifecycle.instance.predefined.agent;
-import com.c2kernel.common.CannotManageException;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.InvalidAgentPathException;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.lookup.RolePath;
-import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -41,7 +41,7 @@ public class RemoveAgent extends PredefinedStep { @Override
protected String runActivityLogic(AgentPath agent, ItemPath itemPath,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData {
Logger.msg(1, "RemoveAgent::request() - Starting.");
@@ -49,7 +49,7 @@ public class RemoveAgent extends PredefinedStep { try {
targetAgent = new AgentPath(itemPath);
} catch (InvalidAgentPathException ex) {
- throw new InvalidDataException("Could not resolve "+itemPath+" as an Agent.");
+ throw new InvalidData("Could not resolve "+itemPath+" as an Agent.");
}
String agentName = targetAgent.getAgentName();
@@ -59,28 +59,28 @@ public class RemoveAgent extends PredefinedStep { Gateway.getLookupManager().removeRole(targetAgent, role);
} catch (ObjectCannotBeUpdated e) {
Logger.error(e);
- throw new InvalidDataException("Error removing "+agentName+" from Role "+role.getName(), "");
- } catch (ObjectNotFoundException e) {
+ throw new InvalidData("Error removing "+agentName+" from Role "+role.getName());
+ } catch (ObjectNotFound e) {
Logger.error(e);
- throw new InvalidDataException("Tried to remove "+agentName+" from Role "+role.getName()+" that doesn't exist.", "");
- } catch (CannotManageException e) {
- throw new InvalidDataException("Tried to alter roles in a non-server process.", "");
+ throw new InvalidData("Tried to remove "+agentName+" from Role "+role.getName()+" that doesn't exist.");
+ } catch (CannotManage e) {
+ throw new InvalidData("Tried to alter roles in a non-server process.");
}
}
//clear out all storages
try {
Gateway.getStorage().removeCluster(targetAgent, "", null);
- } catch (ClusterStorageException e) {
+ } catch (PersistencyException e) {
Logger.error(e);
- throw new InvalidDataException("Error deleting storage for "+agentName, "");
+ throw new InvalidData("Error deleting storage for "+agentName);
}
//remove entity path
try {
Gateway.getLookupManager().delete(targetAgent);
} catch (Exception e) {
- throw new InvalidDataException("Error deleting AgentPath for "+agentName, "");
+ throw new InvalidData("Error deleting AgentPath for "+agentName);
}
return requestData;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java index 8a7062c..5285662 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java @@ -21,11 +21,12 @@ package com.c2kernel.lifecycle.instance.predefined.agent;
import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
-import com.c2kernel.common.CannotManageException;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.InvalidItemPathException;
@@ -41,36 +42,26 @@ public class SetAgentPassword extends PredefinedStep { @Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
-
- Logger.msg(1, "SetAgentPassword::request() - Starting.");
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, ObjectCannotBeUpdated, CannotManage {
+
+ String[] params = getDataList(requestData);
+ if (Logger.doLog(3)) Logger.msg(3, "SetAgentPassword: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params));
+ if (params.length != 1) throw new InvalidData("SetAgentPassword: Invalid parameters "+Arrays.toString(params));
AgentPath targetAgent;
try {
targetAgent = new AgentPath(item);
} catch (InvalidItemPathException ex) {
- throw new InvalidDataException("Could not resolve syskey "+item+" as an Agent.");
+ throw new InvalidData("Can only set password on an Agent. "+item+" is an Item.");
}
String agentName = targetAgent.getAgentName();
- String[] params = getDataList(requestData);
- if (params.length!=1)
- throw new InvalidDataException("Requires 1 param: new password", "");
-
try {
Gateway.getLookupManager().setAgentPassword(targetAgent, params[0]);
- } catch (ObjectNotFoundException e) {
- Logger.error(e);
- throw new InvalidDataException("Agent "+agentName+" not found.", "");
- } catch (ObjectCannotBeUpdated e) {
- Logger.error(e);
- throw new InvalidDataException("Error updating LDAP entry.", "");
} catch (NoSuchAlgorithmException e) {
Logger.error(e);
- throw new InvalidDataException("Cryptographic libraries for password hashing not found.", "");
- } catch (CannotManageException e) {
- throw new InvalidDataException("Cannot set agent password in a non-server process.", "");
- }
+ throw new InvalidData("Cryptographic libraries for password hashing not found.");
+ }
params[1] = "REDACTED"; // censor user's password from outcome
return bundleData(params);
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java index 8c009e3..02cc49e 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java @@ -22,8 +22,8 @@ package com.c2kernel.lifecycle.instance.predefined.agent; import java.util.ArrayList;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.InvalidItemPathException;
@@ -40,7 +40,7 @@ public class SetAgentRoles extends PredefinedStep { @Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData {
Logger.msg(1, "SetAgentRoles::request() - Starting.");
@@ -49,7 +49,7 @@ public class SetAgentRoles extends PredefinedStep { try {
targetAgent = new AgentPath(item);
} catch (InvalidItemPathException ex) {
- throw new InvalidDataException("Could not resolve syskey "+item+" as an Agent.");
+ throw new InvalidData("Could not resolve syskey "+item+" as an Agent.");
}
RolePath[] currentRoles = targetAgent.getRoles();
@@ -57,8 +57,8 @@ public class SetAgentRoles extends PredefinedStep { for (int i=0; i<params.length; i++)
try {
requestedRoles.add(Gateway.getLookup().getRolePath(params[i]));
- } catch (ObjectNotFoundException e) {
- throw new InvalidDataException("Role "+params[i]+" not found", "");
+ } catch (ObjectNotFound e) {
+ throw new InvalidData("Role "+params[i]+" not found");
}
ArrayList<RolePath> rolesToRemove = new ArrayList<RolePath>();
@@ -75,7 +75,7 @@ public class SetAgentRoles extends PredefinedStep { Gateway.getLookupManager().removeRole(targetAgent, roleToRemove);
} catch (Exception e) {
Logger.error(e);
- throw new InvalidDataException("Error removing role "+roleToRemove.getName(), "");
+ throw new InvalidData("Error removing role "+roleToRemove.getName());
}
// add requested roles we don't already have
@@ -84,7 +84,7 @@ public class SetAgentRoles extends PredefinedStep { Gateway.getLookupManager().addRole(targetAgent, roleToAdd);
} catch (Exception e) {
Logger.error(e);
- throw new InvalidDataException("Error adding role "+roleToAdd.getName(), "");
+ throw new InvalidData("Error adding role "+roleToAdd.getName());
}
return requestData;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java index d2c48ff..02ea642 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java @@ -24,10 +24,12 @@ import com.c2kernel.collection.Collection; import com.c2kernel.collection.CollectionArrayList;
import com.c2kernel.collection.CollectionDescription;
import com.c2kernel.collection.CollectionMember;
-import com.c2kernel.common.AccessRightsException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectAlreadyExistsException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.CorbaServer;
import com.c2kernel.entity.TraceableEntity;
import com.c2kernel.lifecycle.CompositeActivityDef;
@@ -37,7 +39,6 @@ import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
-import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
import com.c2kernel.property.Property;
import com.c2kernel.property.PropertyArrayList;
@@ -61,7 +62,7 @@ public class CreateItemFromDescription extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath itemPath,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, ObjectAlreadyExists, CannotManage, ObjectCannotBeUpdated, PersistencyException {
String[] input = getDataList(requestData);
String newName = input[0];
@@ -72,65 +73,64 @@ public class CreateItemFromDescription extends PredefinedStep Logger.msg(1, "CreateItemFromDescription - Starting.");
- try {
- // 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 AccessRightsException("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");
-
- 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))
- );
-
- // add its domain path
- Logger.msg(3, "CreateItemFromDescription - Creating "+context);
- context.setItemPath(newItemPath);
- Gateway.getLookupManager().add(context);
- return requestData;
- } catch (Exception e) {
- Logger.error(e);
- throw new InvalidDataException(e.getMessage(), "");
- }
+ // 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 ObjectAlreadyExists("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 CannotManage("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 InvalidData("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 {
+ protected PropertyArrayList getInitProperties(String input) throws InvalidData {
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, "");
+ throw new InvalidData("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 {
+ protected PropertyArrayList getNewProperties(ItemPath itemPath, String descVer, PropertyArrayList initProps, String newName, AgentPath agent) throws ObjectNotFound, InvalidData {
// copy properties -- intend to create from propdesc
PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer);
PropertyArrayList props = pdList.instantiate(initProps);
@@ -147,7 +147,7 @@ public class CreateItemFromDescription extends PredefinedStep return props;
}
- protected CompositeActivity getNewWorkflow(ItemPath itemPath, String descVer) throws ClusterStorageException, ObjectNotFoundException, InvalidDataException {
+ protected CompositeActivity getNewWorkflow(ItemPath itemPath, String descVer) throws ObjectNotFound, InvalidData, PersistencyException {
// find the workflow def for the given description version
String wfDefName = null; Integer wfDefVer = null;
@@ -159,26 +159,26 @@ public class CreateItemFromDescription extends PredefinedStep try {
wfDefVer = Integer.parseInt(wfVerObj.toString());
} catch (NumberFormatException ex) {
- throw new InvalidDataException("Invalid workflow version number: "+wfVerObj.toString(), "");
+ throw new InvalidData("Invalid workflow version number: "+wfVerObj.toString());
}
// load workflow def
if (wfDefName == null)
- throw new InvalidDataException("No workflow given or defined", "");
+ throw new InvalidData("No workflow given or defined");
if (wfDefVer == null)
- throw new InvalidDataException("No workflow def version given","");
+ throw new InvalidData("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 (ObjectNotFound ex) {
+ throw new InvalidData("Workflow def '"+wfDefName+"'v"+wfDefVer+" not found");
} catch (ClassCastException ex) {
- throw new InvalidDataException("Activity def '"+wfDefName+"' was not Composite", "");
+ throw new InvalidData("Activity def '"+wfDefName+"' was not Composite");
}
}
- protected CollectionArrayList getNewCollections(ItemPath itemPath, String descVer) throws ClusterStorageException, ObjectNotFoundException {
+ protected CollectionArrayList getNewCollections(ItemPath itemPath, String descVer) throws ObjectNotFound, 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);
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java index 8245c4a..f96bc08 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java @@ -24,7 +24,11 @@ package com.c2kernel.lifecycle.instance.predefined.item; import java.util.Iterator;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
@@ -50,33 +54,23 @@ public class Erase extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, ObjectCannotBeUpdated, CannotManage, PersistencyException {
Logger.msg(1, "Erase::request() - Starting.");
- try
- {
- // get all domain paths
- Iterator<Path> 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);
+ Iterator<Path> domPaths = Gateway.getLookup().searchAliases(item);
+ while (domPaths.hasNext()) {
+ DomainPath path = (DomainPath)domPaths.next();
+ // delete them
+ if (path.getItemPath().equals(item))
+ Gateway.getLookupManager().delete(path);
}
- catch( Exception ex )
- {
- Logger.error(ex);
- throw new InvalidDataException(ex.toString(), "");
- }
+ //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/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java index 3cb2182..57de2a1 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java @@ -20,11 +20,12 @@ */
package com.c2kernel.lifecycle.instance.predefined.server;
+import java.util.Arrays;
import java.util.Stack;
-import com.c2kernel.common.CannotManageException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
import com.c2kernel.common.ObjectCannotBeUpdated;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
@@ -41,13 +42,15 @@ public class AddDomainContext extends PredefinedStep { @Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectCannotBeUpdated, ObjectAlreadyExists, CannotManage {
- Logger.msg(1, "AddDomainContext::request() - Starting.");
+ 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 InvalidData("AddDomainContext: Invalid parameters "+Arrays.toString(params));
- DomainPath pathToAdd = new DomainPath(getDataList(requestData)[0]);
+ DomainPath pathToAdd = new DomainPath(params);
if (pathToAdd.exists())
- throw new InvalidDataException("Context "+pathToAdd+" already exists", "");
+ throw new ObjectAlreadyExists("Context "+pathToAdd+" already exists");
// collect parent paths if they don't exist
Stack<DomainPath> pathsToAdd = new Stack<DomainPath>();
while(pathToAdd!= null && !pathToAdd.exists()) {
@@ -56,16 +59,7 @@ public class AddDomainContext extends PredefinedStep { }
while(!pathsToAdd.empty()) {
pathToAdd = pathsToAdd.pop();
- try {
- Gateway.getLookupManager().add(pathToAdd);
- } catch (ObjectAlreadyExistsException e) {
- Logger.error("Context "+pathToAdd+" inconsistently exists.");
- } catch (ObjectCannotBeUpdated e) {
- Logger.error(e);
- throw new InvalidDataException("Exception adding path "+pathToAdd+": "+e.getMessage(), "");
- } catch (CannotManageException e) {
- throw new InvalidDataException("Cannot alter directory in a non-server process", "");
- }
+ Gateway.getLookupManager().add(pathToAdd);
}
return requestData;
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewAgent.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewAgent.java index 6caf25e..ffe8950 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewAgent.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewAgent.java @@ -20,7 +20,11 @@ */
package com.c2kernel.lifecycle.instance.predefined.server;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.entity.imports.ImportAgent;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
@@ -39,19 +43,25 @@ public class CreateNewAgent extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, ObjectCannotBeUpdated, CannotManage, ObjectAlreadyExists {
String redactedRequestData;
- try {
- ImportAgent newAgent = (ImportAgent)Gateway.getMarshaller().unmarshall(requestData);
- newAgent.create(agent, true);
- newAgent.setPassword("REDACTED");
- redactedRequestData = Gateway.getMarshaller().marshall(newAgent);
- return redactedRequestData;
- } catch (Exception ex) {
- Logger.error(ex);
- throw new InvalidDataException("Error creating agent", "");
- }
+ ImportAgent newAgent;
+ try {
+ newAgent = (ImportAgent)Gateway.getMarshaller().unmarshall(requestData);
+ } catch (Exception e1) {
+ Logger.error(e1);
+ throw new InvalidData("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 InvalidData("CreateNewAgent: Couldn't marshall new Agent for outcome: "+newAgent);
+ }
+ return redactedRequestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewItem.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewItem.java index 139bc55..5e0505e 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewItem.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewItem.java @@ -23,7 +23,12 @@ package com.c2kernel.lifecycle.instance.predefined.server; -import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidCollectionModification;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.entity.imports.ImportItem;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
@@ -42,15 +47,16 @@ public class CreateNewItem extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectCannotBeUpdated, ObjectNotFound, CannotManage, ObjectAlreadyExists, InvalidCollectionModification {
- try {
- ImportItem newItem = (ImportItem)Gateway.getMarshaller().unmarshall(requestData);
- newItem.create(agent, false);
- return requestData;
- } catch (Exception ex) {
- Logger.error(ex);
- throw new InvalidDataException("Error creating item", "");
- }
+ ImportItem newItem;
+ try {
+ newItem = (ImportItem)Gateway.getMarshaller().unmarshall(requestData);
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new InvalidData("CreateNewAgent: Couldn't unmarshall new Agent: "+requestData);
+ }
+ newItem.create(agent, false);
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewRole.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewRole.java index 49231ea..de05dec 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewRole.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/CreateNewRole.java @@ -20,7 +20,11 @@ */
package com.c2kernel.lifecycle.instance.predefined.server;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.entity.imports.ImportRole;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
@@ -39,16 +43,17 @@ public class CreateNewRole extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectAlreadyExists, ObjectCannotBeUpdated, CannotManage, ObjectNotFound {
- try {
- ImportRole newRole = (ImportRole)Gateway.getMarshaller().unmarshall(requestData);
- newRole.create(agent, true);
- return requestData;
- } catch (Exception ex) {
- Logger.error(ex);
- throw new InvalidDataException("Error creating role", "");
- }
+ ImportRole newRole;
+ try {
+ newRole = (ImportRole)Gateway.getMarshaller().unmarshall(requestData);
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new InvalidData("CreateNewAgent: Couldn't unmarshall new Agent: "+requestData);
+ }
+ newRole.create(agent, true);
+ return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java index d90f163..2d78e69 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java @@ -20,10 +20,12 @@ */
package com.c2kernel.lifecycle.instance.predefined.server;
-import com.c2kernel.common.CannotManageException;
-import com.c2kernel.common.InvalidDataException;
+import java.util.Arrays;
+
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
@@ -38,28 +40,25 @@ public class RemoveDomainContext extends PredefinedStep { @Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, ObjectNotFound, ObjectCannotBeUpdated, CannotManage {
- Logger.msg(1, "RemoveDomainContext::request() - Starting.");
-
- DomainPath pathToDelete = new DomainPath(getDataList(requestData)[0]);
+ 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 InvalidData("RemoveDomainContext: Invalid parameters "+Arrays.toString(params));
+
+ DomainPath pathToDelete = new DomainPath(params[0]);
if (!pathToDelete.exists())
- throw new InvalidDataException("Context "+pathToDelete+" does not exist", "");
+ throw new ObjectNotFound("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) { }
+ throw new InvalidData("Path "+pathToDelete+" is an Entity. Use its own Erase step instead, or RemoveAgent.");
+ } catch (ObjectNotFound ex) { }
+
if (Gateway.getLookup().getChildren(pathToDelete).hasNext())
- throw new InvalidDataException("Context "+pathToDelete+" is not empty. Cannot delete.", "");
+ throw new ObjectCannotBeUpdated("Context "+pathToDelete+" is not empty. Cannot delete.");
- try {
- Gateway.getLookupManager().delete(pathToDelete);
- } catch (ObjectCannotBeUpdated e) {
- Logger.error(e);
- throw new InvalidDataException("Exception deleting path"+pathToDelete+": "+e.getMessage(), "");
- } catch (CannotManageException e) {
- throw new InvalidDataException("Cannot alter directory in a non-server process", "");
- }
+ Gateway.getLookupManager().delete(pathToDelete);
return requestData;
}
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java index a467ee0..7aeda55 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java @@ -22,10 +22,10 @@ package com.c2kernel.lifecycle.instance.predefined.server; import java.util.Arrays;
-import com.c2kernel.common.CannotManageException;
-import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
@@ -44,33 +44,22 @@ public class RemoveRole extends PredefinedStep //requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item,
- int transitionID, String requestData) throws InvalidDataException {
+ int transitionID, String requestData) throws InvalidData, CannotManage, ObjectNotFound, ObjectCannotBeUpdated {
- String[] params = getDataList(requestData);
- if (Logger.doLog(3)) Logger.msg(3, "AddC2KObject: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params));
- LookupManager lookup;
- try {
- lookup = Gateway.getLookupManager();
- } catch (CannotManageException e) {
- throw new InvalidDataException(e.getMessage(), "");
- }
-
- RolePath thisRole; AgentPath[] agents;
- try {
- thisRole = lookup.getRolePath(params[0]);
- agents = Gateway.getLookup().getAgents(thisRole);
- } catch (ObjectNotFoundException e) {
- throw new InvalidDataException("Role "+params[0]+" not found.", "");
- }
+ 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 InvalidData("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 InvalidDataException("Cannot remove role. "+agents.length+" agents still hold it.", "");
- try {
- lookup.delete(thisRole);
- } catch (ObjectCannotBeUpdated e) {
- Logger.error(e);
- throw new InvalidDataException("Role "+params[0]+" could not be removed.", "");
- }
+ throw new ObjectCannotBeUpdated("Cannot remove role. "+agents.length+" agents still hold it.");
+
+ lookup.delete(thisRole);
return requestData;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java index efa5667..54a7267 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java @@ -25,9 +25,9 @@ import java.util.HashMap; import java.util.Map;
import com.c2kernel.common.AccessRightsException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.InvalidTransitionException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.InvalidTransition;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.lifecycle.instance.Activity;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.utils.DescriptionObject;
@@ -142,7 +142,7 @@ public class StateMachine implements DescriptionObject return stateCodes.get(stateID);
}
- public Map<Transition, String> getPossibleTransitions(Activity act, AgentPath agent) throws ObjectNotFoundException, InvalidDataException {
+ public Map<Transition, String> getPossibleTransitions(Activity act, AgentPath agent) throws ObjectNotFound, InvalidData {
HashMap<Transition, String> returnList = new HashMap<Transition, String>();
State currentState = getState(act.getState());
for (Integer transCode : currentState.getPossibleTransitionIds()) {
@@ -158,14 +158,14 @@ public class StateMachine implements DescriptionObject return returnList;
}
- public State traverse(Activity act, Transition transition, AgentPath agent) throws InvalidTransitionException, AccessRightsException, ObjectNotFoundException, InvalidDataException {
+ public State traverse(Activity act, Transition transition, AgentPath agent) throws InvalidTransition, AccessRightsException, ObjectNotFound, InvalidData {
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(), "");
+ throw new InvalidTransition("Transition '"+transition.getName()+"' not valid from state '"+currentState.getName());
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java index 8c6502f..78786da 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java @@ -25,8 +25,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern;
import com.c2kernel.common.AccessRightsException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.lifecycle.instance.Activity;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.RolePath;
@@ -188,15 +188,15 @@ public class Transition { this.targetStateId = targetStateId;
}
- public String getPerformingRole(Activity act, AgentPath agent) throws ObjectNotFoundException, AccessRightsException {
+ public String getPerformingRole(Activity act, AgentPath agent) throws ObjectNotFound, AccessRightsException {
// check available
if (!isEnabled(act.getProperties()))
- throw new AccessRightsException("Transition '"+name+"' is disabled by the '"+enabledProp+"' property.", "");
+ 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", "");
+ throw new AccessRightsException("Activity must be active to perform this transition");
RolePath role = null;
String overridingRole = resolveValue(roleOverride, act.getProperties());
@@ -224,7 +224,7 @@ public class Transition { // 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, "");
+ +"' cannot perform this transition because the activity '"+act.getName()+"' is currently owned by "+agentName);
if (role != null) {
if (agent.hasRole(role))
@@ -233,7 +233,7 @@ public class Transition { return "Admin";
else
throw new AccessRightsException("Agent '"+agent.getAgentName()
- +"' does not hold a suitable role '"+role.getName()+"' for the activity "+act.getName(), "");
+ +"' does not hold a suitable role '"+role.getName()+"' for the activity "+act.getName());
}
else
return null;
@@ -284,13 +284,13 @@ public class Transition { return true;
}
- public Schema getSchema(CastorHashMap actProps) throws InvalidDataException, ObjectNotFoundException {
+ public Schema getSchema(CastorHashMap actProps) throws InvalidData, ObjectNotFound {
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)+")", "");
+ throw new InvalidData("Bad schema version number: "+outcome.schemaVersion+" ("+resolveValue(outcome.schemaVersion, actProps)+")");
}
else
return null;
@@ -300,11 +300,11 @@ public class Transition { return resolveValue(script.scriptName, actProps);
}
- public int getScriptVersion(CastorHashMap actProps) throws InvalidDataException {
+ public int getScriptVersion(CastorHashMap actProps) throws InvalidData {
try {
return Integer.parseInt(resolveValue(script.scriptVersion, actProps));
} catch (NumberFormatException ex) {
- throw new InvalidDataException("Bad Script version number: "+script.scriptVersion+" ("+resolveValue(script.scriptVersion, actProps)+")", "");
+ throw new InvalidData("Bad Script version number: "+script.scriptVersion+" ("+resolveValue(script.scriptVersion, actProps)+")");
}
}
|
