From 9c5d6e82b5ce733cf23e4317e3bafaa42c2221ba Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 1 Oct 2014 21:09:06 +0200 Subject: Collection version support, stored as a new final component of the Collection path. Null version implies "last". --- .../predefined/item/CreateItemFromDescription.java | 52 ++++++++++------------ 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/item') 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 92b56f2..c8c7aa6 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 @@ -11,8 +11,6 @@ package com.c2kernel.lifecycle.instance.predefined.item; -import java.util.ArrayList; - import com.c2kernel.collection.Collection; import com.c2kernel.collection.CollectionArrayList; import com.c2kernel.collection.CollectionDescription; @@ -59,8 +57,9 @@ public class CreateItemFromDescription extends PredefinedStep String[] input = getDataList(requestData); String newName = input[0]; String domPath = input[1]; + String descVer = input.length > 2 ? input[2]:"last"; PropertyArrayList initProps = - input.length > 2?getInitProperties(input[2]):new PropertyArrayList(); + input.length > 3?getInitProperties(input[3]):new PropertyArrayList(); Logger.msg(1, "CreateItemFromDescription - Starting."); @@ -96,9 +95,9 @@ public class CreateItemFromDescription extends PredefinedStep newItem.initialise( agent.getSystemKey(), - Gateway.getMarshaller().marshall(getNewProperties(itemPath, initProps, newName, agent)), - Gateway.getMarshaller().marshall(getNewWorkflow(itemPath)), - Gateway.getMarshaller().marshall(getNewCollections(itemPath)) + 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 @@ -122,9 +121,9 @@ public class CreateItemFromDescription extends PredefinedStep } } - protected PropertyArrayList getNewProperties(ItemPath itemPath, PropertyArrayList initProps, String newName, AgentPath agent) throws ObjectNotFoundException, InvalidDataException { + protected PropertyArrayList getNewProperties(ItemPath itemPath, String descVer, PropertyArrayList initProps, String newName, AgentPath agent) throws ObjectNotFoundException, InvalidDataException { // copy properties -- intend to create from propdesc - PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(itemPath); + PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer); PropertyArrayList props = pdList.instantiate(initProps); // set Name prop or create if not present boolean foundName = false; @@ -139,25 +138,20 @@ public class CreateItemFromDescription extends PredefinedStep return props; } - protected CompositeActivity getNewWorkflow(ItemPath itemPath) throws ClusterStorageException, ObjectNotFoundException, InvalidDataException { - // loop through collections, collecting instantiated descriptions and finding the default workflow def - String[] collNames = Gateway.getStorage().getClusterContents(itemPath, ClusterStorage.COLLECTION); + protected CompositeActivity getNewWorkflow(ItemPath itemPath, String descVer) throws ClusterStorageException, ObjectNotFoundException, InvalidDataException { + // find the workflow def for the given description version + String wfDefName = null; Integer wfDefVer = null; - for (String collName : collNames) { - if (collName.equalsIgnoreCase("workflow")) { - Collection thisCol = (Collection)Gateway.getStorage().get(itemPath, ClusterStorage.COLLECTION+"/"+collName, null); - ArrayList members = thisCol.getMembers().list; - // get the first member from the wf collection - CollectionMember wfMember = members.get(0); - wfDefName = wfMember.resolveItem().getName(); - Object wfVerObj = wfMember.getProperties().get("Version"); - try { - wfDefVer = Integer.parseInt(wfVerObj.toString()); - } catch (NumberFormatException ex) { - throw new InvalidDataException("Invalid workflow version number: "+wfVerObj.toString(), ""); - } - } - } + + Collection thisCol = (Collection)Gateway.getStorage().get(itemPath, ClusterStorage.COLLECTION+"/workflow/"+descVer, null); + CollectionMember wfMember = thisCol.getMembers().list.get(0); + wfDefName = wfMember.resolveItem().getName(); + Object wfVerObj = wfMember.getProperties().get("Version"); + try { + wfDefVer = Integer.parseInt(wfVerObj.toString()); + } catch (NumberFormatException ex) { + throw new InvalidDataException("Invalid workflow version number: "+wfVerObj.toString(), ""); + } // load workflow def if (wfDefName == null) @@ -175,14 +169,14 @@ public class CreateItemFromDescription extends PredefinedStep } } - protected CollectionArrayList getNewCollections(ItemPath itemPath) throws ClusterStorageException, ObjectNotFoundException { + protected CollectionArrayList getNewCollections(ItemPath itemPath, String descVer) throws ClusterStorageException, ObjectNotFoundException { // loop through collections, collecting instantiated descriptions and finding the default workflow def CollectionArrayList colls = new CollectionArrayList(); String[] collNames = Gateway.getStorage().getClusterContents(itemPath, ClusterStorage.COLLECTION); for (String collName : collNames) { - Collection thisCol = (Collection)Gateway.getStorage().get(itemPath, ClusterStorage.COLLECTION+"/"+collName, null); + Collection thisCol = (Collection)Gateway.getStorage().get(itemPath, ClusterStorage.COLLECTION+"/"+collName+"/"+descVer, null); if (thisCol instanceof CollectionDescription) { - CollectionDescription thisDesc = (CollectionDescription)thisCol; + CollectionDescription thisDesc = (CollectionDescription)thisCol; colls.put(thisDesc.newInstance()); } } -- cgit v1.2.3