From 0ec8481c10cd8277d84c7c1a785483a0a739e5a0 Mon Sep 17 00:00:00 2001 From: abranson Date: Thu, 4 Aug 2011 00:42:34 +0200 Subject: More code cleanup: Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class --- .../predefined/CreateItemFromDescription.java | 67 +++++++++++----------- 1 file changed, 34 insertions(+), 33 deletions(-) (limited to 'source/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java') diff --git a/source/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java b/source/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java index 7bedc81..ad92052 100644 --- a/source/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java +++ b/source/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java @@ -55,6 +55,7 @@ public class CreateItemFromDescription extends PredefinedStep } //requestdata is xmlstring + @Override public void request(AgentPath agent, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException,ObjectAlreadyExistsException { @@ -65,66 +66,66 @@ public class CreateItemFromDescription extends PredefinedStep String wfDefName = null; if (input.length > 2) // override wf wfDefName = input[2]; - + PropertyArrayList props = new PropertyArrayList(); Logger.msg(1, "AddNewItem::request() - Starting."); TransactionManager storage = Gateway.getStorage(); LDAPLookup lookup = Gateway.getLDAPLookup(); EntityPath myPath = getItemEntityPath(); checkAccessRights(agent); - + try { - // check if the path is already taken + // check if the path is already taken DomainPath context = new DomainPath(new DomainPath(domPath), newName); Logger.debug(8,"context "+context.getSysKey()+" "+context.getPath()+" "+context.getString()); - if (context.getSysKey()!=-1) - throw new ObjectAlreadyExistsException("The item name " +newName+ " exists already."); - + if (context.getSysKey()!=-1) + throw new ObjectAlreadyExistsException("The item name " +newName+ " exists already."); + // get init objects String[] collNames = storage.getClusterContents(myPath.getSysKey(), ClusterStorage.COLLECTION); ArrayList collections = new ArrayList(); - - + + // loop through collections to instantiate - for (int i = 0; i < collNames.length; i++) { - Collection thisCol = (Collection)storage.get(myPath.getSysKey(), ClusterStorage.COLLECTION+"/"+collNames[i], null); + for (String collName : collNames) { + Collection thisCol = (Collection)storage.get(myPath.getSysKey(), ClusterStorage.COLLECTION+"/"+collName, null); if (thisCol instanceof CollectionDescription) { - CollectionDescription thisDesc = (CollectionDescription)thisCol; - collections.add(CastorXMLUtility.marshall(thisDesc.newInstance())); + CollectionDescription thisDesc = (CollectionDescription)thisCol; + collections.add(CastorXMLUtility.marshall(thisDesc.newInstance())); } else if (thisCol.getName().equals("Workflow") && wfDefName == null) { - ArrayList members = thisCol.getMembers().list; + ArrayList members = thisCol.getMembers().list; // get the first member from the wf collection CollectionMember wfMember = (CollectionMember)members.get(0); wfDefName = wfMember.resolveEntity().getName(); } } - + // load workflow def if (wfDefName == null) throw new InvalidDataException("No workflow given or defined", ""); - + try { wfDef = (CompositeActivityDef)LocalObjectLoader.getActDef(wfDefName, "last"); } catch (ObjectNotFoundException ex) { - throw new InvalidDataException("Workflow def '"+wfDefName+"' item not found", ""); + throw new InvalidDataException("Workflow def '"+wfDefName+"' item not found", ""); } catch (ClassCastException ex) { throw new InvalidDataException("Activity def '"+wfDefName+"' was not Composite", ""); } - - + + // copy properties -- intend to create from propdesc PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(myPath.getSysKey()); for (int i = 0; i < pdList.list.size(); i++) { - PropertyDescription pd = (PropertyDescription) pdList.list.get(i); + PropertyDescription pd = pdList.list.get(i); String propName = pd.getName(); - String propVal = pd.getDefaultValue(); + String propVal = pd.getDefaultValue(); if (propName.equals("Name")) propVal = newName; - props.list.add( new Property(propName, propVal)); + props.list.add( new Property(propName, propVal)); } props.list.add( new Property("Creator", agent.getAgentName())); - + /* ITEM CREATION */ // generate new entity key @@ -132,8 +133,8 @@ public class CreateItemFromDescription extends PredefinedStep EntityPath entityPath = lookup.getNextKeyManager().generateNextEntityKey(); // resolve the item factory - Logger.msg(6, "CreateItemFromDescription - Resolving item factory"); - + Logger.msg(6, "CreateItemFromDescription - Resolving item factory"); + // create the Item object Logger.msg(3, "CreateItemFromDescription - Creating Item"); CorbaServer factory = Gateway.getCorbaServer(); @@ -141,26 +142,26 @@ public class CreateItemFromDescription extends PredefinedStep TraceableEntity newItem = (TraceableEntity)factory.createEntity(entityPath); Gateway.getLDAPLookup().add(entityPath); - + // initialise it with its properties and workflow - + Logger.msg(3, "CreateItemFromDescription - Initializing Item"); - + newItem.initialise( agent.getSysKey(), CastorXMLUtility.marshall(props), CastorXMLUtility.marshall(wfDef.instantiate())); - + // add collections if (collections.size() > 0) { Logger.msg(6, "CreateItemFromDescription - Adding Collections"); String[] colls = new String[1]; - for (Iterator iter = collections.iterator(); iter.hasNext();) { - colls[0] = (String)iter.next(); - newItem.requestAction(agent.getSysKey(), "workflow/predefined/AddC2KObject", Transitions.COMPLETE, PredefinedStep.bundleData(colls)); + for (Iterator iter = collections.iterator(); iter.hasNext();) { + colls[0] = iter.next(); + newItem.requestAction(agent.getSysKey(), "workflow/predefined/AddC2KObject", Transitions.COMPLETE, PredefinedStep.bundleData(colls)); } - } - + } + // add its domain path Logger.msg(3, "CreateItemFromDescription - Creating "+context); context.setEntity(entityPath); -- cgit v1.2.3