From 66b9f0bd1415a17a3db8801f5231248414712be5 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 9 Oct 2014 22:35:09 +0200 Subject: Predefined step testing and tweaking --- .../instance/predefined/AddMemberToCollection.java | 8 +++++- .../predefined/AddNewCollectionDescription.java | 4 +-- .../lifecycle/instance/predefined/AddNewSlot.java | 10 ++++++- .../instance/predefined/AssignItemToSlot.java | 9 ++++++- .../lifecycle/instance/predefined/ClearSlot.java | 2 +- .../predefined/RemoveSlotFromCollection.java | 10 ++++++- .../instance/predefined/agent/SetAgentRoles.java | 4 +-- src/test/resources/NewServerPredefStepTest.js | 31 +++++++++++++++++++--- 8 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddMemberToCollection.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddMemberToCollection.java index a065b1d..00b16ef 100644 --- a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddMemberToCollection.java +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddMemberToCollection.java @@ -31,6 +31,8 @@ import org.cristalise.kernel.common.ObjectNotFoundException; import org.cristalise.kernel.common.PersistencyException; import org.cristalise.kernel.entity.C2KLocalObject; import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.InvalidItemPathException; import org.cristalise.kernel.lookup.ItemPath; import org.cristalise.kernel.persistency.ClusterStorage; import org.cristalise.kernel.process.Gateway; @@ -80,7 +82,11 @@ public class AddMemberToCollection extends PredefinedStep if (Logger.doLog(3)) Logger.msg(3, "AddMemberToCollection: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); try { collName = params[0]; - newChild = new ItemPath(params[1]); + try { + newChild = new ItemPath(params[1]); + } catch (InvalidItemPathException e) { + newChild = new DomainPath(params[1]).getItemPath(); + } if (params.length > 2) props = (CastorHashMap)Gateway.getMarshaller().unmarshall(params[2]); diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java index b230284..eabf07a 100644 --- a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java @@ -92,9 +92,9 @@ public class AddNewCollectionDescription extends PredefinedStep CollectionDescription newCollDesc; - if (collType.equals("Aggregation")) + if (collType.equalsIgnoreCase("Aggregation")) newCollDesc = new AggregationDescription(collName); - if (collType.equals("Dependency")) + else if (collType.equalsIgnoreCase("Dependency")) newCollDesc = new DependencyDescription(collName); else throw new InvalidDataException("AddNewCollectionDescription: Invalid collection type specified: '"+collType+"'. Must be Aggregation or Dependency."); diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewSlot.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewSlot.java index f3acdf3..0088091 100644 --- a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewSlot.java +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewSlot.java @@ -29,6 +29,8 @@ import org.cristalise.kernel.common.ObjectNotFoundException; import org.cristalise.kernel.common.PersistencyException; import org.cristalise.kernel.entity.C2KLocalObject; import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.InvalidItemPathException; import org.cristalise.kernel.lookup.ItemPath; import org.cristalise.kernel.persistency.ClusterStorage; import org.cristalise.kernel.process.Gateway; @@ -84,7 +86,13 @@ public class AddNewSlot extends PredefinedStep // resolve desc item path and version try { collName = params[0]; - if (params.length > 1 && params[1].length() > 0) descKey = new ItemPath(params[1]); + if (params.length > 1 && params[1].length() > 0) { + try { + descKey = new ItemPath(params[1]); + } catch (InvalidItemPathException e) { + descKey = new DomainPath(params[1]).getItemPath(); + } + } if (params.length > 2 && params[2].length() > 0) descVer = params[2]; } catch (Exception e) { throw new InvalidDataException("AddNewSlot: Invalid parameters "+Arrays.toString(params)); diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AssignItemToSlot.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AssignItemToSlot.java index c242500..416d85d 100644 --- a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AssignItemToSlot.java +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AssignItemToSlot.java @@ -32,6 +32,8 @@ import org.cristalise.kernel.common.ObjectNotFoundException; import org.cristalise.kernel.common.PersistencyException; import org.cristalise.kernel.entity.C2KLocalObject; import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.InvalidItemPathException; import org.cristalise.kernel.lookup.ItemPath; import org.cristalise.kernel.persistency.ClusterStorage; import org.cristalise.kernel.process.Gateway; @@ -80,8 +82,13 @@ public class AssignItemToSlot extends PredefinedStep try { collName = params[0]; slotNo = Integer.parseInt(params[1]); - childItem = new ItemPath(params[2]); + try { + childItem = new ItemPath(params[2]); + } catch (InvalidItemPathException e) { + childItem = new DomainPath(params[2]).getItemPath(); + } } catch (Exception e) { + Logger.error(e); throw new InvalidDataException("AssignItemToSlot: Invalid parameters "+Arrays.toString(params)); } diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ClearSlot.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ClearSlot.java index bd0fa19..7e9831a 100644 --- a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ClearSlot.java +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ClearSlot.java @@ -91,7 +91,7 @@ public class ClearSlot extends PredefinedStep boolean stored = false; for (AggregationMember member : agg.getMembers().list) { if (member.getID() == slotNo) { - if (member.getItemPath() != null) + if (member.getItemPath() == null) throw new ObjectCannotBeUpdated("ClearSlot: Member slot "+slotNo+" already empty"); member.clearItem(); stored = true; diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java index 6522384..8bca2ca 100644 --- a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java @@ -29,6 +29,8 @@ import org.cristalise.kernel.common.InvalidDataException; import org.cristalise.kernel.common.ObjectNotFoundException; import org.cristalise.kernel.common.PersistencyException; import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.InvalidItemPathException; import org.cristalise.kernel.lookup.ItemPath; import org.cristalise.kernel.persistency.ClusterStorage; import org.cristalise.kernel.process.Gateway; @@ -75,7 +77,13 @@ public class RemoveSlotFromCollection extends PredefinedStep try { collName = params[0]; if (params.length>1 && params[1].length()>0) slotNo = Integer.parseInt(params[1]); - if (params.length>2 && params[2].length()>0) currentChild = new ItemPath(params[2]); + if (params.length>2 && params[2].length()>0) { + try { + currentChild = new ItemPath(params[2]); + } catch (InvalidItemPathException e) { + currentChild = new DomainPath(params[2]).getItemPath(); + } + } } catch (Exception e) { throw new InvalidDataException("RemoveSlotFromCollection: Invalid parameters "+Arrays.toString(params)); } diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java index e267034..831997a 100644 --- a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java @@ -21,6 +21,7 @@ package org.cristalise.kernel.lifecycle.instance.predefined.agent; import java.util.ArrayList; +import java.util.Arrays; import org.cristalise.kernel.common.InvalidDataException; import org.cristalise.kernel.common.ObjectNotFoundException; @@ -43,9 +44,8 @@ public class SetAgentRoles extends PredefinedStep { protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData) throws InvalidDataException { - Logger.msg(1, "SetAgentRoles::request() - Starting."); - String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AddC2KObject: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); AgentPath targetAgent; try { targetAgent = new AgentPath(item); diff --git a/src/test/resources/NewServerPredefStepTest.js b/src/test/resources/NewServerPredefStepTest.js index 6d6f7c7..b5553b7 100644 --- a/src/test/resources/NewServerPredefStepTest.js +++ b/src/test/resources/NewServerPredefStepTest.js @@ -28,6 +28,31 @@ params[0] = "/test"; agent.execute(serverItem, predef, params); var predef = "SetAgentPassword"; params = Array(1); params[0] = "hunter2"; agent.execute(agent, predef, params); org.cristalise.kernel.process.Gateway.login("dev", "hunter2"); var predef = "SetAgentRoles"; agent.execute(serverItem, predef, params); //Role shouldn't exist -params = Array(3); params[0] = "dev"; params[1] = "Admin"; params[2] = "UserCode"; agent.execute(serverItem, predef, params); -params = Array(2); params[0] = "dev"; params[1] = "Admin"; agent.execute(serverItem, predef, params); -var predef = "RemoveAgent"; var params = new Array(1); params[0] = "dev"; agent.execute(serverItem, predef, params); +params = Array(2); params[0] = "Admin"; params[1] = "User"; agent.execute(agent, predef, params); +params = Array(1); params[0] = "Admin"; agent.execute(agent, predef, params); +var predef = "RemoveAgent"; var params = new Array(0); agent.execute(agent, predef, params); + +var predef = "AddNewCollectionDescription"; var params = new Array(2); +params[0] = "TestAgg"; params[1] = "Aggregation"; agent.execute(serverItem, predef, params); +params[0] = "TestDep"; params[1] = "Dependency"; agent.execute(serverItem, predef, params); + +var predef = "CreateNewCollectionVersion"; var params = new Array(1); +params[0] = "TestAgg"; agent.execute(serverItem, predef, params); + +var predef = "AddNewSlot"; var params = new Array(2); +params[0] = "TestAgg"; params[1] = "/desc/dev/ScriptFactory"; agent.execute(serverItem, predef, params); + +var predef = "AddMemberToCollection"; var params = new Array(2); +params[0] = "TestDep"; params[1] = "/desc/dev/ScriptFactory"; agent.execute(serverItem, predef, params); + +var predef = "AssignItemToSlot"; var params = new Array(3); +params[0] = "TestAgg"; params[1] = "0"; params[2] = "/desc/Script/system/dev/CreateNewNumberedVersionFromLast"; agent.execute(serverItem, predef, params); + +var predef = "ClearSlot"; var params = new Array(2); +params[0] = "TestAgg"; params[1] = "0"; agent.execute(serverItem, predef, params); + +var predef="RemoveSlotFromCollection"; var params = new Array(2); +params[0] = "TestAgg"; params[1] = "0"; agent.execute(serverItem, predef, params); + +var params = new Array(2); params[0] = "TestDep"; params[1] = "-1"; params[2] = "/desc/dev/ScriptFactory"; +agent.execute(serverItem, predef, params); \ No newline at end of file -- cgit v1.2.3