summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/lifecycle/instance/predefined/entitycreation
diff options
context:
space:
mode:
authorAndrew Branson <andrew@andrewbranson.net>2011-06-21 15:46:02 +0200
committerAndrew Branson <andrew@andrewbranson.net>2011-06-21 15:46:02 +0200
commit254ee6f47eebfc00462c10756a92066e82cc1a96 (patch)
tree8273ff95c704e6faa3f92b4711253427b9ba0481 /source/com/c2kernel/lifecycle/instance/predefined/entitycreation
Initial commit2.2
Diffstat (limited to 'source/com/c2kernel/lifecycle/instance/predefined/entitycreation')
-rwxr-xr-xsource/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java26
-rwxr-xr-xsource/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java21
-rwxr-xr-xsource/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java46
-rwxr-xr-xsource/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java45
-rwxr-xr-xsource/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java46
-rwxr-xr-xsource/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java18
-rwxr-xr-xsource/com/c2kernel/lifecycle/instance/predefined/entitycreation/Geometry.java29
-rwxr-xr-xsource/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java65
-rwxr-xr-xsource/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java145
-rwxr-xr-xsource/com/c2kernel/lifecycle/instance/predefined/entitycreation/Property.java26
10 files changed, 467 insertions, 0 deletions
diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java
new file mode 100755
index 0000000..4abb0e6
--- /dev/null
+++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java
@@ -0,0 +1,26 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+import java.util.ArrayList;
+
+public class Aggregation implements java.io.Serializable {
+
+ public boolean isDescription;
+ public ArrayList aggregationMemberList;
+ public String name;
+
+ public Aggregation() {
+ super();
+ aggregationMemberList = new ArrayList();
+ }
+
+ public Aggregation(String name, boolean isDescription) {
+ this();
+ this.name = name;
+ this.isDescription = isDescription;
+ }
+
+ public com.c2kernel.collection.Aggregation create() {
+ // TODO: create aggregation
+ return new com.c2kernel.collection.AggregationInstance();
+ }
+}
diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java
new file mode 100755
index 0000000..87baa1d
--- /dev/null
+++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java
@@ -0,0 +1,21 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+public class AggregationMember implements java.io.Serializable {
+
+ public int slotNo;
+ public String itemDescriptionPath;
+ public String itemPath;
+ public Geometry geometry;
+
+
+ public AggregationMember() {
+ super();
+ }
+
+ public AggregationMember(int slotNo, String itemDescPath, String itemPath, Geometry geometry) {
+ this.slotNo = slotNo;
+ this.itemDescriptionPath = itemDescPath;
+ this.itemPath = itemPath;
+ this.geometry = geometry;
+ }
+}
diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java
new file mode 100755
index 0000000..b0eaaec
--- /dev/null
+++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java
@@ -0,0 +1,46 @@
+/**************************************************************************
+ * AddDomainPath
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+
+
+
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
+
+public class CreateNewAgent extends PredefinedStep
+{
+ public CreateNewAgent()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ public void request( AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ InvalidDataException
+ {
+ checkAccessRights(agent);
+
+ try {
+ NewAgent newAgent = (NewAgent)CastorXMLUtility.unmarshall(requestData);
+ newAgent.create(agent.getSysKey());
+ } catch (Exception ex) {
+ Logger.error(ex);
+ throw new InvalidDataException("Error creating agent", "");
+ }
+
+ sendEventStoreOutcome(transitionID, requestData, agent);
+ }
+}
diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java
new file mode 100755
index 0000000..49f8ada
--- /dev/null
+++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java
@@ -0,0 +1,45 @@
+/**************************************************************************
+ * CreateNewItem
+ *
+ * Copyright (C) 2005 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+
+
+
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.InvalidTransitionException;
+import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
+
+public class CreateNewItem extends PredefinedStep
+{
+ public CreateNewItem()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ public void request( AgentPath agent, int transitionID, String requestData)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ InvalidDataException
+ {
+ checkAccessRights(agent);
+
+ try {
+ NewItem item = (NewItem)CastorXMLUtility.unmarshall(requestData);
+ item.create(agent.getSysKey());
+ } catch (Exception ex) {
+ Logger.error(ex);
+ throw new InvalidDataException("Error creating item", "");
+ }
+ sendEventStoreOutcome(transitionID, requestData, agent);
+ }
+}
diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java
new file mode 100755
index 0000000..0896534
--- /dev/null
+++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java
@@ -0,0 +1,46 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.c2kernel.collection.MembershipException;
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.property.PropertyUtility;
+
+public class Dependency implements java.io.Serializable {
+
+ public String name;
+ public boolean isDescription;
+ public String itemDescriptionPath;
+ public ArrayList dependencyMemberList;
+
+ public Dependency() {
+ super();
+ dependencyMemberList = new ArrayList();
+ }
+
+ public Dependency(String itemDesc) {
+ this();
+ this.itemDescriptionPath = itemDesc;
+ }
+
+ /**
+ * @return
+ */
+ public com.c2kernel.collection.Dependency create() throws MembershipException{
+ com.c2kernel.collection.Dependency newDep = new com.c2kernel.collection.Dependency(name);
+ if (itemDescriptionPath != null) {
+ PropertyUtility.getPropertyDescriptionOutcome(new DomainPath(itemDescriptionPath).getSysKey());
+ //TODO: set props and class identifiers
+ }
+ for (Iterator mems = dependencyMemberList.iterator(); mems.hasNext();) {
+ DependencyMember thisMem = (DependencyMember) mems.next();
+ int syskey = new DomainPath(thisMem.itemPath).getSysKey();
+ if (syskey == -1)
+ throw new MembershipException("Cannot find "+thisMem.itemPath+" specified for collection.");
+ newDep.addMember(syskey);
+ }
+ return newDep;
+ }
+
+}
diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java
new file mode 100755
index 0000000..00ac445
--- /dev/null
+++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java
@@ -0,0 +1,18 @@
+
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+public class DependencyMember implements java.io.Serializable {
+
+
+ public String itemPath;
+
+ public DependencyMember() {
+ super();
+ }
+
+ public DependencyMember(String itemPath) {
+ this.itemPath = itemPath;
+
+ }
+
+}
diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/Geometry.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/Geometry.java
new file mode 100755
index 0000000..25a1455
--- /dev/null
+++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/Geometry.java
@@ -0,0 +1,29 @@
+
+
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+
+
+public class Geometry implements java.io.Serializable {
+
+
+ public int x;
+
+ public int y;
+
+ public int width;
+
+ public int height;
+
+ public Geometry() {
+ super();
+ }
+
+ public Geometry(int x, int y, int width, int height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+
+}
diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java
new file mode 100755
index 0000000..fa575a3
--- /dev/null
+++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java
@@ -0,0 +1,65 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.c2kernel.common.CannotManageException;
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.agent.ActiveEntity;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.RolePath;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.property.PropertyArrayList;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
+
+public class NewAgent implements java.io.Serializable {
+
+ public String name;
+
+ public String password;
+
+ public ArrayList roles;
+
+ public NewAgent() {
+ super();
+ roles = new ArrayList();
+ }
+
+ public NewAgent(String name, String password) {
+ this.name = name;
+ this.password = password;
+ }
+
+ protected void create(int agentId) throws ObjectNotFoundException, ObjectCannotBeUpdated, NoSuchAlgorithmException, CannotManageException, ObjectAlreadyExistsException {
+ AgentPath newAgent = Gateway.getLDAPLookup().getNextKeyManager().generateNextAgentKey();
+ newAgent.setAgentName(name);
+ newAgent.setPassword(password);
+ ActiveEntity newAgentEnt = (ActiveEntity)Gateway.getCorbaServer().createEntity(newAgent);
+ Gateway.getLDAPLookup().add(newAgent);
+ // assemble properties
+ PropertyArrayList propList = new PropertyArrayList();
+ propList.list.add(new com.c2kernel.property.Property("Name", name));
+ propList.list.add(new com.c2kernel.property.Property("Type", "Agent"));
+ try {
+ newAgentEnt.initialise(CastorXMLUtility.marshall(propList));
+ } catch (Exception ex) {
+ Logger.error(ex);
+ throw new CannotManageException("Error initialising new agent");
+ }
+ for (Iterator iter = roles.iterator(); iter.hasNext();) {
+ String role = (String) iter.next();
+ RolePath thisRole;
+ try {
+ thisRole = Gateway.getLDAPLookup().getRoleManager().getRolePath(role);
+ } catch (ObjectNotFoundException ex) {
+ thisRole = Gateway.getLDAPLookup().getRoleManager().createRole(role, false);
+ }
+ thisRole.addAgent(newAgent);
+ }
+
+ }
+}
diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java
new file mode 100755
index 0000000..4988700
--- /dev/null
+++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java
@@ -0,0 +1,145 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+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 (Iterator iter = propertyList.iterator(); iter.hasNext();) {
+ Property prop = (Property) iter.next();
+ 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 (Iterator iter = propertyList.iterator(); iter.hasNext();) {
+ Property element = (Property) iter.next();
+ 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 (Iterator iter = dependencyList.iterator(); iter.hasNext();) {
+ Dependency element = (Dependency) iter.next();
+ 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 (Iterator iter = aggregationList.iterator(); iter.hasNext();) {
+ Aggregation element = (Aggregation) iter.next();
+ 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);
+ }
+}
diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/Property.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/Property.java
new file mode 100755
index 0000000..d99a3e3
--- /dev/null
+++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/Property.java
@@ -0,0 +1,26 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+/**
+ * New Properties for the item
+ *
+ * @version $Revision: 1.1 $ $Date: 2005/04/28 13:48:26 $
+ */
+public class Property implements java.io.Serializable {
+
+ public String name;
+ public String value;
+
+
+ //----------------/
+ //- Constructors -/
+ //----------------/
+
+ public Property() {
+ super();
+ }
+
+ public Property(String name, String value) {
+ super();
+ this.name = name;
+ this.value = value;
+ }
+}