From 4466bfb51367afefec57bae9ca8f571eef17cfd9 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 4 Apr 2014 12:54:29 +0200 Subject: Removed resource type enumeration, because we allow domain-defined types now. Refs #178 --- src/main/resources/boot/OD/Module.xsd | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'src/main/resources/boot/OD/Module.xsd') diff --git a/src/main/resources/boot/OD/Module.xsd b/src/main/resources/boot/OD/Module.xsd index 2b8fefd..882b374 100644 --- a/src/main/resources/boot/OD/Module.xsd +++ b/src/main/resources/boot/OD/Module.xsd @@ -56,16 +56,7 @@ - - - - - - - - - - + -- cgit v1.2.3 From 11e7a9aaed7c22ec93a791ea752e159b4b120e4e Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 4 Apr 2014 17:26:10 +0200 Subject: Module XML now supports a workflowVer attribute for the Item element. If not given, it assumed version 0, as per the previous behaviour. Fixes #180 --- .../predefined/entitycreation/NewItem.java | 23 +++++++++++++++++----- src/main/java/com/c2kernel/process/Bootstrap.java | 2 +- .../java/com/c2kernel/process/module/Module.java | 2 +- src/main/resources/boot/OD/Module.xsd | 4 +++- src/main/resources/mapFiles/NewEntityMap.xml | 3 +++ 5 files changed, 26 insertions(+), 8 deletions(-) (limited to 'src/main/resources/boot/OD/Module.xsd') diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java index 5f8cf12..07b8462 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java @@ -39,6 +39,7 @@ public class NewItem extends ModuleImport { public String initialPath; public String workflow; + public Integer workflowVer; public ArrayList properties = new ArrayList(); public ArrayList aggregationList = new ArrayList(); public ArrayList dependencyList = new ArrayList(); @@ -48,11 +49,12 @@ public class NewItem extends ModuleImport { public NewItem() { } - public NewItem(String name, String initialPath, String wf) { + public NewItem(String name, String initialPath, String wf, int wfVer) { this(); this.name = name; this.initialPath = initialPath; this.workflow = wf; + this.workflowVer = wfVer; } public void setNamespace(String ns) { @@ -82,11 +84,22 @@ public class NewItem extends ModuleImport { // set the name property properties.add(new Property("Name", name, true)); - // init the new item + // find workflow def + CompositeActivityDef compact; + // default workflow version is 0 if not given + int usedWfVer; + if (workflowVer == null) usedWfVer = 0; + else usedWfVer = workflowVer.intValue(); try { - - // find workflow def - CompositeActivityDef compact = (CompositeActivityDef)LocalObjectLoader.getActDef(workflow, 0); + compact = (CompositeActivityDef)LocalObjectLoader.getActDef(workflow, usedWfVer); + } catch (ObjectNotFoundException ex) { + throw new CannotManageException("Could not find workflow "+workflow+"v"+usedWfVer+" for item "+domPath, ""); + } catch (InvalidDataException e) { + throw new CannotManageException("Workflow def "+workflow+" v"+usedWfVer+" for item "+domPath+" was not valid", ""); + } + + try { + // initialise the new item with workflow and properties newItem.initialise( agentId, Gateway.getMarshaller().marshall(new PropertyArrayList(properties)), diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index df8ced7..a750b3f 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -183,7 +183,7 @@ public class Bootstrap } // data was missing or doesn't match - Logger.msg("Bootstrap.verifyResource() - Writing new "+newOutcome.getSchemaType()+"version "+version+" to "+typeImpHandler.getName()+" "+itemName); + Logger.msg("Bootstrap.verifyResource() - Writing new "+newOutcome.getSchemaType()+" v"+version+" to "+typeImpHandler.getName()+" "+itemName); History hist = new History(thisProxy.getSystemKey(), thisProxy); Transition predefDone = new Transition(0, "Done", 0, 0); Event newEvent = hist.addEvent("system", "Admin", "Bootstrap", "Bootstrap", "Bootstrap", newOutcome.getSchemaType(), 0, "PredefinedStep", 0, predefDone, String.valueOf(version)); diff --git a/src/main/java/com/c2kernel/process/module/Module.java b/src/main/java/com/c2kernel/process/module/Module.java index a7c707e..3e8ab2a 100644 --- a/src/main/java/com/c2kernel/process/module/Module.java +++ b/src/main/java/com/c2kernel/process/module/Module.java @@ -51,7 +51,7 @@ public class Module { } public void addModuleItem(String moduleXML) { - NewItem moduleItem = new NewItem(name, "/desc/modules/", "ModuleWorkflow"); + NewItem moduleItem = new NewItem(name, "/desc/modules/", "ModuleWorkflow", 0); // Module properties moduleItem.properties.add(new com.c2kernel.property.Property("Namespace", ns, false)); moduleItem.properties.add(new com.c2kernel.property.Property("Name", name, false)); diff --git a/src/main/resources/boot/OD/Module.xsd b/src/main/resources/boot/OD/Module.xsd index 882b374..d25352e 100644 --- a/src/main/resources/boot/OD/Module.xsd +++ b/src/main/resources/boot/OD/Module.xsd @@ -150,7 +150,9 @@ + use="required" /> + diff --git a/src/main/resources/mapFiles/NewEntityMap.xml b/src/main/resources/mapFiles/NewEntityMap.xml index 239fa21..84c4ce7 100644 --- a/src/main/resources/mapFiles/NewEntityMap.xml +++ b/src/main/resources/mapFiles/NewEntityMap.xml @@ -11,6 +11,9 @@ + + + -- cgit v1.2.3 From 8e8185210f5bd87cb5dcda3a458fe059f811aafc Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 15 May 2014 15:10:13 +0200 Subject: Introduced 'Layer' attribute to allow overriding of descriptions. Desc with the same name in the same description tree will be ranked by LocalObjectLoader according to this number, and the highest one chosen for instantiation. Fixes #188 --- src/main/java/com/c2kernel/process/Bootstrap.java | 25 +++++++++++++++---- .../java/com/c2kernel/process/module/Module.java | 3 ++- .../com/c2kernel/process/module/ModuleInfo.java | 1 + .../java/com/c2kernel/utils/LocalObjectLoader.java | 28 ++++++++++++++++++++-- src/main/resources/boot/OD/Module.xsd | 1 + src/main/resources/boot/property/CAProp.xml | 1 + src/main/resources/boot/property/EAProp.xml | 1 + src/main/resources/boot/property/ODProp.xml | 1 + src/main/resources/boot/property/SCProp.xml | 1 + src/main/resources/boot/property/SMProp.xml | 1 + src/main/resources/mapFiles/ModuleMap.xml | 3 +++ 11 files changed, 58 insertions(+), 8 deletions(-) (limited to 'src/main/resources/boot/OD/Module.xsd') diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index e2ad24e..f273c5d 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -103,7 +103,7 @@ public class Bootstrap String itemName = thisItem.substring(delim+1); try { String location = "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml"); - verifyResource(ns, itemName, 0, itemType, location, reset); + verifyResource(ns, itemName, 0, itemType, location, 0, reset); } catch (Exception e) { Logger.error(e); Logger.die("Error importing bootstrap items. Unsafe to continue."); @@ -112,7 +112,7 @@ public class Bootstrap } - public static DomainPath verifyResource(String ns, String itemName, Integer version, String itemType, String dataLocation, boolean reset) throws Exception { + public static DomainPath verifyResource(String ns, String itemName, Integer version, String itemType, String dataLocation, int layer, boolean reset) throws Exception { if (version == null) version = 0; ResourceImportHandler typeImpHandler = getHandler(itemType); Logger.msg(1, "Bootstrap.verifyResource() - Verifying version "+version+" of "+typeImpHandler.getName()+" "+itemName); @@ -123,7 +123,7 @@ public class Bootstrap Enumeration en = Gateway.getLDAPLookup().search(typeImpHandler.getTypeRoot(), itemName); if (!en.hasMoreElements()) { Logger.msg("Bootstrap.verifyResource() - "+typeImpHandler.getName()+" "+itemName+" not found. Creating new."); - thisProxy = createResourceItem(typeImpHandler, itemName, ns); + thisProxy = createResourceItem(typeImpHandler, itemName, layer, ns); } else { DomainPath path = (DomainPath)en.nextElement(); @@ -147,6 +147,15 @@ public class Bootstrap Gateway.getStorage().put(thisProxy.getSystemKey(), new Property("Module", moduleName, false), thisProxy); } + // overwrite layer if different + int currentLayer = -1; + try { + String layerProp = thisProxy.getProperty("Layer"); + currentLayer = Integer.parseInt(layerProp); + } catch (Exception e) { } + if (currentLayer != layer) + Gateway.getStorage().put(thisProxy.getSystemKey(), new Property("Layer", String.valueOf(layer), false), thisProxy); + if (!modDomPath.equals(path)) { // move item to module subtree Logger.msg("Module item "+itemName+" found with path "+path.toString()+". Moving to "+modDomPath.toString()); modDomPath.setEntity(new ItemPath(thisProxy.getSystemKey())); @@ -224,16 +233,22 @@ public class Bootstrap /** * @param itemType * @param itemName + * @param layer * @param data */ - private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, String ns) throws Exception { + private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, int layer, String ns) throws Exception { // create props PropertyDescriptionList pdList = impHandler.getPropDesc(); PropertyArrayList props = new PropertyArrayList(); for (int i = 0; i < pdList.list.size(); i++) { PropertyDescription pd = pdList.list.get(i); String propName = pd.getName(); - String propVal = propName.equals("Name")?itemName:pd.getDefaultValue(); + String propVal; + if (propName.equals("Name")) + propVal = itemName; + else if (propName.equals("Layer")) + propVal = String.valueOf(layer); + else propVal = pd.getDefaultValue(); props.list.add(new Property(propName, propVal, pd.getIsMutable())); } diff --git a/src/main/java/com/c2kernel/process/module/Module.java b/src/main/java/com/c2kernel/process/module/Module.java index 32a5997..2c182ea 100644 --- a/src/main/java/com/c2kernel/process/module/Module.java +++ b/src/main/java/com/c2kernel/process/module/Module.java @@ -56,6 +56,7 @@ public class Module { moduleItem.properties.add(new com.c2kernel.property.Property("Namespace", ns, false)); moduleItem.properties.add(new com.c2kernel.property.Property("Name", name, false)); moduleItem.properties.add(new com.c2kernel.property.Property("Type", "Module", false)); + moduleItem.properties.add(new com.c2kernel.property.Property("Layer", String.valueOf(info.layer), true)); moduleItem.properties.add(new com.c2kernel.property.Property("Version", info.version, true)); // Add dependency for all children Dependency children = new Dependency("Contents"); @@ -79,7 +80,7 @@ public class Module { for (ModuleResource thisRes : imports.getResources()) { try { thisRes.path = Bootstrap.verifyResource(ns, thisRes.name, thisRes.version, - thisRes.resourceType, thisRes.resourceLocation, reset); + thisRes.resourceType, thisRes.resourceLocation, info.layer, reset); } catch (Exception ex) { Logger.error(ex); } diff --git a/src/main/java/com/c2kernel/process/module/ModuleInfo.java b/src/main/java/com/c2kernel/process/module/ModuleInfo.java index 55e02c9..646a915 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleInfo.java +++ b/src/main/java/com/c2kernel/process/module/ModuleInfo.java @@ -6,6 +6,7 @@ public class ModuleInfo { public String desc; public String version; + public int layer = 0; public ArrayList dependency = new ArrayList(); public ModuleInfo() { diff --git a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java index 05f8aba..307cd97 100644 --- a/src/main/java/com/c2kernel/utils/LocalObjectLoader.java +++ b/src/main/java/com/c2kernel/utils/LocalObjectLoader.java @@ -1,11 +1,14 @@ package com.c2kernel.utils; +import java.util.Enumeration; + import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.proxy.ItemProxy; import com.c2kernel.lifecycle.ActivityDef; import com.c2kernel.lifecycle.instance.stateMachine.StateMachine; import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.Path; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.persistency.outcome.Schema; @@ -20,8 +23,29 @@ public class LocalObjectLoader { throws ObjectNotFoundException { DomainPath defRoot = new DomainPath(root); - DomainPath defPath = (DomainPath)defRoot.find(name); - return Gateway.getProxyManager().getProxy(defPath); + Enumeration e = Gateway.getLDAPLookup().search(defRoot, name); + ItemProxy defProxy = null; int currentLayer = -1; + while (e.hasMoreElements()) { + DomainPath defPath = (DomainPath)e.nextElement(); + ItemProxy thisProxy = Gateway.getProxyManager().getProxy(defPath); + int thisLayer; + try { + String thisLayerProp = thisProxy.getProperty("Layer"); + thisLayer = Integer.parseInt(thisLayerProp); + } catch (Exception ex) { + thisLayer = 0; + } + if (thisLayer > currentLayer) { + currentLayer = thisLayer; + defProxy = thisProxy; + } + else if (thisLayer == currentLayer) { + throw new ObjectNotFoundException("Duplicate definition for "+name+" in "+root+" found in Layer "+thisLayer, ""); + } + } + if (defProxy == null) + throw new ObjectNotFoundException("No match for "+name+" in "+root, ""); + return defProxy; } static public String getScript(String scriptName, int scriptVersion) throws ObjectNotFoundException { diff --git a/src/main/resources/boot/OD/Module.xsd b/src/main/resources/boot/OD/Module.xsd index d25352e..c768e3f 100644 --- a/src/main/resources/boot/OD/Module.xsd +++ b/src/main/resources/boot/OD/Module.xsd @@ -9,6 +9,7 @@ + diff --git a/src/main/resources/boot/property/CAProp.xml b/src/main/resources/boot/property/CAProp.xml index ac37ae7..b29884a 100644 --- a/src/main/resources/boot/property/CAProp.xml +++ b/src/main/resources/boot/property/CAProp.xml @@ -2,5 +2,6 @@ + diff --git a/src/main/resources/boot/property/EAProp.xml b/src/main/resources/boot/property/EAProp.xml index a345695..2477c93 100644 --- a/src/main/resources/boot/property/EAProp.xml +++ b/src/main/resources/boot/property/EAProp.xml @@ -2,5 +2,6 @@ + diff --git a/src/main/resources/boot/property/ODProp.xml b/src/main/resources/boot/property/ODProp.xml index 894a6ee..f4d7b15 100644 --- a/src/main/resources/boot/property/ODProp.xml +++ b/src/main/resources/boot/property/ODProp.xml @@ -1,5 +1,6 @@ + diff --git a/src/main/resources/boot/property/SCProp.xml b/src/main/resources/boot/property/SCProp.xml index f5de23c..9ff0366 100644 --- a/src/main/resources/boot/property/SCProp.xml +++ b/src/main/resources/boot/property/SCProp.xml @@ -1,5 +1,6 @@ + diff --git a/src/main/resources/boot/property/SMProp.xml b/src/main/resources/boot/property/SMProp.xml index 8581e74..f43d0b5 100644 --- a/src/main/resources/boot/property/SMProp.xml +++ b/src/main/resources/boot/property/SMProp.xml @@ -1,5 +1,6 @@ + diff --git a/src/main/resources/mapFiles/ModuleMap.xml b/src/main/resources/mapFiles/ModuleMap.xml index 45f6cbe..440b852 100644 --- a/src/main/resources/mapFiles/ModuleMap.xml +++ b/src/main/resources/mapFiles/ModuleMap.xml @@ -38,6 +38,9 @@ + + + -- cgit v1.2.3