From b086f57f56bf0eb9dab9cf321a0f69aaaae84347 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 30 May 2012 08:37:45 +0200 Subject: Initial Maven Conversion --- .../predefined/entitycreation/NewItem.java | 141 +++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java') 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 new file mode 100644 index 0000000..f155ced --- /dev/null +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java @@ -0,0 +1,141 @@ +package com.c2kernel.lifecycle.instance.predefined.entitycreation; + + +import java.util.ArrayList; + +import com.c2kernel.collection.MembershipException; +import com.c2kernel.common.CannotManageException; +import com.c2kernel.common.ObjectAlreadyExistsException; +import com.c2kernel.common.ObjectCannotBeUpdated; +import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.entity.TraceableEntity; +import com.c2kernel.lifecycle.CompositeActivityDef; +import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.EntityPath; +import com.c2kernel.persistency.ClusterStorageException; +import com.c2kernel.process.Gateway; +import com.c2kernel.property.PropertyArrayList; +import com.c2kernel.utils.CastorXMLUtility; +import com.c2kernel.utils.LocalObjectLoader; +import com.c2kernel.utils.Logger; + +/** + * Complete Structure for new item + * + * @version $Revision: 1.8 $ $Date: 2006/03/03 13:52:21 $ + */ + +public class NewItem { + + public String name; + + /** + * The initial Domain Path to be created for this Item. + */ + public String initialPath; + + /** + * The name of the Composite Activity Definition to be + * instantiated for the workflow of this Item + */ + public String workflow; + + /** + * New Properties for the item + */ + public ArrayList propertyList; + + /** + * Field _aggregationList + */ + public ArrayList aggregationList; + + /** + * Field _dependencyList + */ + public ArrayList dependencyList; + + + public NewItem() { + super(); + propertyList = new ArrayList(); + aggregationList = new ArrayList(); + dependencyList = new ArrayList(); + } + + public NewItem(String name, String initialPath, String wf) { + this(); + this.name = name; + this.initialPath = initialPath; + this.workflow = wf; + } + + public void setProperty(String name, String value) { + for (Property prop : propertyList) { + if (prop.name.equals(name)) { + prop.value = value; + return; + } + } + propertyList.add(new Property(name, value)); + } + + protected void create(int agentId) throws ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException { + DomainPath domPath = new DomainPath(new DomainPath(initialPath), name); + if (domPath.exists()) + throw new ObjectAlreadyExistsException(domPath+" already exists!", ""); + + // create item + EntityPath entPath = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey(); + TraceableEntity newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entPath); + Gateway.getLDAPLookup().add(entPath); + + // assemble properties + PropertyArrayList propList = new PropertyArrayList(); + propList.list.add(new com.c2kernel.property.Property("Name", name)); + for (Property element : propertyList) { + propList.list.add(new com.c2kernel.property.Property(element.name, element.value)); + } + // init the new item + try { + + // find workflow def + CompositeActivityDef compact = (CompositeActivityDef)LocalObjectLoader.getActDef(workflow, "last"); + + newItem.initialise( + agentId, + CastorXMLUtility.marshall(propList), + CastorXMLUtility.marshall(compact.instantiate())); + } catch (Exception ex) { + Logger.error("Error initialising new item"); + Logger.error(ex); + throw new CannotManageException("Problem initialising new item. See server log.", ""); + } + + // create collections + + for (Dependency element: dependencyList) { + try { + Gateway.getStorage().put(entPath.getSysKey(), element.create(), null); + } catch (ClusterStorageException ex) { + Logger.error(ex); + throw new CannotManageException("Could not create Dependency "+element.name, ""); + } catch (MembershipException ex) { + Logger.error(ex); + throw new CannotManageException("A specified member is not of the correct type in "+element.name, ""); + } + } + + for (Aggregation element : aggregationList) { + try { + Gateway.getStorage().put(entPath.getSysKey(), element.create(), null); + } catch (ClusterStorageException ex) { + Logger.error(ex); + throw new CannotManageException("Could not create Aggregation "+element.name, ""); + } + } + // register domain path + domPath.setEntity(entPath); + Gateway.getLDAPLookup().add(domPath); + } +} -- cgit v1.2.3