summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2012-07-06 11:00:24 +0200
committerAndrew Branson <andrew.branson@cern.ch>2012-07-06 11:00:24 +0200
commit24314dc1699c7e73048fa24e33729f1aa1ec0e86 (patch)
treec97af82997783b860c36f4410973b23caff0d42e /src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation
parentcc79e98c4763affba4fa2e17dfe5a412f9de66c3 (diff)
Modules serialize with Castor. Just about to remove the parsing.
CastorXMLUtility is now a static member of gateway. Domain specific instances can be used by domain applications, but the maps do not interfere with the kernel.
Diffstat (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation')
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java25
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java29
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java11
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java4
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java39
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java23
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java42
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java133
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java18
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Property.java26
10 files changed, 238 insertions, 112 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java
index b99e898..88d9249 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Aggregation.java
@@ -2,6 +2,9 @@ package com.c2kernel.lifecycle.instance.predefined.entitycreation;
import java.util.ArrayList;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
import com.c2kernel.collection.MembershipException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.graph.model.GraphPoint;
@@ -9,17 +12,15 @@ import com.c2kernel.lookup.DomainPath;
import com.c2kernel.property.PropertyDescription;
import com.c2kernel.property.PropertyDescriptionList;
import com.c2kernel.property.PropertyUtility;
-import com.c2kernel.utils.CastorHashMap;
public class Aggregation implements java.io.Serializable {
public boolean isDescription;
- public ArrayList<AggregationMember> aggregationMemberList;
+ public ArrayList<AggregationMember> aggregationMemberList = new ArrayList<AggregationMember>();
public String name;
public Aggregation() {
super();
- aggregationMemberList = new ArrayList<AggregationMember>();
}
public Aggregation(String name, boolean isDescription) {
@@ -28,16 +29,26 @@ public class Aggregation implements java.io.Serializable {
this.isDescription = isDescription;
}
- public com.c2kernel.collection.Aggregation create() throws MembershipException, ObjectNotFoundException {
+ public Aggregation(Element agg) {
+ name = agg.getAttribute("name");
+ isDescription = agg.getAttribute("isDescription").equals("true");
+ NodeList depmemnl = agg.getElementsByTagName("AggregationMember");
+ for (int k=0; k<depmemnl.getLength(); k++) {
+ Element memElem = (Element)depmemnl.item(k);
+ AggregationMember newAggMem = new AggregationMember(memElem);
+ aggregationMemberList.add(newAggMem);
+ }
+ }
+
+ public com.c2kernel.collection.Aggregation create() throws MembershipException, ObjectNotFoundException {
com.c2kernel.collection.Aggregation newAgg = isDescription?new com.c2kernel.collection.AggregationDescription(name):new com.c2kernel.collection.AggregationInstance(name);
newAgg.setName(name);
for (AggregationMember thisMem : aggregationMemberList) {
- CastorHashMap props = new CastorHashMap();
StringBuffer classProps = new StringBuffer();
if (thisMem.itemDescriptionPath != null && thisMem.itemDescriptionPath.length()>0) {
PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(new DomainPath(thisMem.itemDescriptionPath).getSysKey());
for (PropertyDescription pd : propList.list) {
- props.put(pd.getName(), pd.getDefaultValue());
+ thisMem.props.put(pd.getName(), pd.getDefaultValue());
if (pd.getIsClassIdentifier())
classProps.append((classProps.length()>0?",":"")).append(pd.getName());
}
@@ -46,7 +57,7 @@ public class Aggregation implements java.io.Serializable {
int syskey = new DomainPath(thisMem.itemPath).getSysKey();
if (syskey == -1)
throw new MembershipException("Cannot find "+thisMem.itemPath+" specified for collection.");
- newAgg.addMember(syskey, props, classProps.toString(), new GraphPoint(thisMem.geometry.x, thisMem.geometry.y), thisMem.geometry.width, thisMem.geometry.height);
+ newAgg.addMember(syskey, thisMem.props, classProps.toString(), new GraphPoint(thisMem.geometry.x, thisMem.geometry.y), thisMem.geometry.width, thisMem.geometry.height);
}
}
return newAgg;
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java
index 29d3cf9..64215da 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/AggregationMember.java
@@ -1,11 +1,19 @@
package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+import com.c2kernel.utils.CastorHashMap;
+import com.c2kernel.utils.KeyValuePair;
+
public class AggregationMember implements java.io.Serializable {
public int slotNo;
public String itemDescriptionPath;
public String itemPath;
public Geometry geometry;
+ public CastorHashMap props = new CastorHashMap();
public AggregationMember() {
@@ -18,4 +26,25 @@ public class AggregationMember implements java.io.Serializable {
this.itemPath = itemPath;
this.geometry = geometry;
}
+
+ public AggregationMember(Element memElem) {
+ Element geom = (Element)memElem.getElementsByTagName("Geometry").item(0);
+ this.slotNo = Integer.parseInt(memElem.getAttribute("slotNo"));
+ this.itemDescriptionPath = memElem.getAttribute("itemDescriptionPath");
+ this.itemPath = memElem.getAttribute("itemPath");
+ this.geometry = new Geometry(Integer.parseInt(geom.getAttribute("x")), Integer.parseInt(geom.getAttribute("y")),
+ Integer.parseInt(geom.getAttribute("width")), Integer.parseInt(geom.getAttribute("height")));
+ NodeList cmpnl = memElem.getElementsByTagName("MemberProperty");
+ for (int l=0; l<cmpnl.getLength(); l++) {
+ Element p = (Element)cmpnl.item(l);
+ props.put(p.getAttribute("name"), ((Text)p.getFirstChild()).getData());
+ }
+ }
+ public KeyValuePair[] getKeyValuePairs() {
+ return props.getKeyValuePairs();
+ }
+
+ public void setKeyValuePairs(KeyValuePair[] pairs) {
+ props.setKeyValuePairs(pairs);
+ }
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java
index aa30677..9ec6519 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java
@@ -1,5 +1,5 @@
/**************************************************************************
- * AddDomainPath
+ * CreateNewAgent.java
*
* Copyright (C) 2001 CERN - European Organization for Nuclear Research
* All rights reserved.
@@ -7,15 +7,12 @@
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.process.Gateway;
import com.c2kernel.utils.Logger;
public class CreateNewAgent extends PredefinedStep
@@ -35,10 +32,10 @@ public class CreateNewAgent extends PredefinedStep
checkAccessRights(agent);
String redactedRequestData;
try {
- NewAgent newAgent = (NewAgent)CastorXMLUtility.unmarshall(requestData);
+ NewAgent newAgent = (NewAgent)Gateway.getMarshaller().unmarshall(requestData);
newAgent.create(agent.getSysKey());
newAgent.password = "REDACTED";
- redactedRequestData = CastorXMLUtility.marshall(newAgent);
+ redactedRequestData = Gateway.getMarshaller().marshall(newAgent);
} catch (Exception ex) {
Logger.error(ex);
throw new InvalidDataException("Error creating agent", "");
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java
index a66b062..824ca4f 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewItem.java
@@ -15,7 +15,7 @@ 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.process.Gateway;
import com.c2kernel.utils.Logger;
public class CreateNewItem extends PredefinedStep
@@ -35,7 +35,7 @@ public class CreateNewItem extends PredefinedStep
checkAccessRights(agent);
try {
- NewItem item = (NewItem)CastorXMLUtility.unmarshall(requestData);
+ NewItem item = (NewItem)Gateway.getMarshaller().unmarshall(requestData);
item.create(agent.getSysKey());
} catch (Exception ex) {
Logger.error(ex);
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java
index 5993f62..a0d7a1e 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Dependency.java
@@ -2,6 +2,10 @@ package com.c2kernel.lifecycle.instance.predefined.entitycreation;
import java.util.ArrayList;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
import com.c2kernel.collection.MembershipException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.lookup.DomainPath;
@@ -9,17 +13,19 @@ import com.c2kernel.property.PropertyDescription;
import com.c2kernel.property.PropertyDescriptionList;
import com.c2kernel.property.PropertyUtility;
import com.c2kernel.utils.CastorHashMap;
+import com.c2kernel.utils.KeyValuePair;
public class Dependency implements java.io.Serializable {
public String name;
public boolean isDescription;
public String itemDescriptionPath;
- public ArrayList<DependencyMember> dependencyMemberList;
+ public ArrayList<DependencyMember> dependencyMemberList = new ArrayList<DependencyMember>();
+ public CastorHashMap props = new CastorHashMap();
+ Element elem;
public Dependency() {
super();
- dependencyMemberList = new ArrayList<DependencyMember>();
}
public Dependency(String itemDesc) {
@@ -27,14 +33,36 @@ public class Dependency implements java.io.Serializable {
this.itemDescriptionPath = itemDesc;
}
- /**
+ public Dependency(Element dep) {
+ elem = dep;
+ name = dep.getAttribute("name");
+ isDescription = dep.getAttribute("isDescription").equals("true");
+ NodeList cpnl = dep.getElementsByTagName("CollectionProperty");
+ for (int k=0; k<cpnl.getLength(); k++) {
+ Element p = (Element)cpnl.item(k);
+ props.put(p.getAttribute("name"), ((Text)p.getFirstChild()).getData());
+ }
+ NodeList depmemnl = dep.getElementsByTagName("DependencyMember");
+ for (int k=0; k<depmemnl.getLength(); k++) {
+ Element p = (Element)depmemnl.item(k);
+ dependencyMemberList.add(new DependencyMember(p));
+ }
+ }
+ public KeyValuePair[] getKeyValuePairs() {
+ return props.getKeyValuePairs();
+ }
+
+ public void setKeyValuePairs(KeyValuePair[] pairs) {
+ props.setKeyValuePairs(pairs);
+ }
+
+ /**
* @return
*/
public com.c2kernel.collection.Dependency create() throws MembershipException, ObjectNotFoundException {
com.c2kernel.collection.Dependency newDep = isDescription?new com.c2kernel.collection.DependencyDescription(name):new com.c2kernel.collection.Dependency(name);
if (itemDescriptionPath != null && itemDescriptionPath.length()>0) {
PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(new DomainPath(itemDescriptionPath).getSysKey());
- CastorHashMap props = new CastorHashMap();
StringBuffer classProps = new StringBuffer();
for (PropertyDescription pd : propList.list) {
props.put(pd.getName(), pd.getDefaultValue());
@@ -49,7 +77,8 @@ public class Dependency implements java.io.Serializable {
int syskey = new DomainPath(thisMem.itemPath).getSysKey();
if (syskey == -1)
throw new MembershipException("Cannot find "+thisMem.itemPath+" specified for collection.");
- newDep.addMember(syskey);
+ com.c2kernel.collection.DependencyMember newDepMem = newDep.addMember(syskey);
+ newDepMem.getProperties().putAll(thisMem.props);
}
return newDep;
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java
index b70619f..e20fe8b 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/DependencyMember.java
@@ -1,10 +1,18 @@
package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+import com.c2kernel.utils.CastorHashMap;
+import com.c2kernel.utils.KeyValuePair;
+
public class DependencyMember implements java.io.Serializable {
public String itemPath;
+ public CastorHashMap props = new CastorHashMap();
public DependencyMember() {
super();
@@ -15,4 +23,19 @@ public class DependencyMember implements java.io.Serializable {
}
+ public DependencyMember(Element elem) {
+ itemPath = elem.getAttribute("itemPath");
+ NodeList cmpnl = elem.getElementsByTagName("MemberProperty");
+ for (int l=0; l<cmpnl.getLength(); l++) {
+ Element p = (Element)cmpnl.item(l);
+ props.put(p.getAttribute("name"), ((Text)p.getFirstChild()).getData());
+ }
+ }
+ public KeyValuePair[] getKeyValuePairs() {
+ return props.getKeyValuePairs();
+ }
+
+ public void setKeyValuePairs(KeyValuePair[] pairs) {
+ props.setKeyValuePairs(pairs);
+ }
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java
index 540a6fc..07d2250 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewAgent.java
@@ -3,6 +3,10 @@ package com.c2kernel.lifecycle.instance.predefined.entitycreation;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
import com.c2kernel.common.CannotManageException;
import com.c2kernel.common.ObjectAlreadyExistsException;
import com.c2kernel.common.ObjectCannotBeUpdated;
@@ -11,40 +15,54 @@ import com.c2kernel.entity.agent.ActiveEntity;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.RolePath;
import com.c2kernel.process.Gateway;
+import com.c2kernel.process.module.Module;
+import com.c2kernel.process.module.ModuleImport;
+import com.c2kernel.property.Property;
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 class NewAgent extends ModuleImport implements java.io.Serializable {
public String password;
- public ArrayList<String> roles;
+ public ArrayList<String> roles = new ArrayList<String>();
+ public ArrayList<Property> properties = new ArrayList<Property>();
public NewAgent() {
- super();
- roles = new ArrayList<String>();
+ super(null);
}
public NewAgent(String name, String password) {
+ super(null);
this.name = name;
this.password = password;
}
- protected void create(int agentId) throws ObjectNotFoundException, ObjectCannotBeUpdated, NoSuchAlgorithmException, CannotManageException, ObjectAlreadyExistsException {
+ public NewAgent(Element imp) {
+ super(imp);
+ password = imp.getAttribute("password");
+ NodeList rolenl = imp.getElementsByTagName("Role");
+ for (int j=0; j<rolenl.getLength(); j++) {
+ roles.add(((Text)rolenl.item(j).getFirstChild()).getData());
+ }
+ NodeList pnl = imp.getElementsByTagName("Property");
+ for (int j=0; j<pnl.getLength(); j++) {
+ Element p = (Element)pnl.item(j);
+ properties.add(Module.newProperty(p));
+ }
+ }
+
+ public 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"));
+ properties.add(new com.c2kernel.property.Property("Name", name));
+ properties.add(new com.c2kernel.property.Property("Type", "Agent"));
try {
- newAgentEnt.initialise(CastorXMLUtility.marshall(propList));
+ newAgentEnt.initialise(Gateway.getMarshaller().marshall(new PropertyArrayList(properties)));
} catch (Exception ex) {
Logger.error(ex);
throw new CannotManageException("Error initialising new agent");
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 16f6cbf..050615f 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
@@ -3,21 +3,33 @@ package com.c2kernel.lifecycle.instance.predefined.entitycreation;
import java.util.ArrayList;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
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.events.Event;
+import com.c2kernel.events.History;
import com.c2kernel.lifecycle.CompositeActivityDef;
+import com.c2kernel.lifecycle.instance.stateMachine.States;
+import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.EntityPath;
import com.c2kernel.persistency.ClusterStorageException;
+import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
+import com.c2kernel.process.module.Module;
+import com.c2kernel.process.module.ModuleImport;
+import com.c2kernel.property.Property;
import com.c2kernel.property.PropertyArrayList;
-import com.c2kernel.utils.CastorXMLUtility;
import com.c2kernel.utils.LocalObjectLoader;
import com.c2kernel.utils.Logger;
+import com.c2kernel.utils.Resource;
/**
* Complete Structure for new item
@@ -25,42 +37,18 @@ import com.c2kernel.utils.Logger;
* @version $Revision: 1.8 $ $Date: 2006/03/03 13:52:21 $
*/
-public class NewItem {
-
- public String name;
+public class NewItem extends ModuleImport {
- /**
- * 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<Property> propertyList;
-
- /**
- * Field _aggregationList
- */
- public ArrayList<Aggregation> aggregationList;
-
- /**
- * Field _dependencyList
- */
- public ArrayList<Dependency> dependencyList;
-
+ public ArrayList<Property> properties = new ArrayList<Property>();
+ public ArrayList<Aggregation> aggregationList = new ArrayList<Aggregation>();
+ public ArrayList<Dependency> dependencyList = new ArrayList<Dependency>();
+ public ArrayList<Outcome> outcomes = new ArrayList<Outcome>();
+ public String ns;
public NewItem() {
- super();
- propertyList = new ArrayList<Property>();
- aggregationList = new ArrayList<Aggregation>();
- dependencyList = new ArrayList<Dependency>();
+ super(null);
}
public NewItem(String name, String initialPath, String wf) {
@@ -70,17 +58,44 @@ public class NewItem {
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 {
+ public NewItem(String ns, Element elem) {
+ super(elem);
+ this.ns = ns;
+ workflow = elem.getAttribute("workflow");
+ if (elem.hasAttribute("initialPath"))
+ initialPath = elem.getAttribute("initialPath");
+ else
+ initialPath = "/desc/"+ns;
+ NodeList pnl = elem.getElementsByTagName("Property");
+ for (int j=0; j<pnl.getLength(); j++) {
+ Element p = (Element)pnl.item(j);
+ properties.add(Module.newProperty(p));
+ }
+ NodeList ocnl = elem.getElementsByTagName("Outcome");
+ for (int j=0; j<ocnl.getLength(); j++) {
+ Element oc = (Element)ocnl.item(j);
+ outcomes.add(new Outcome(oc.getAttribute("schema"), oc.getAttribute("version"), oc.getAttribute("viewname"), ((Text)oc.getFirstChild()).getData()));
+ }
+
+ NodeList depnl = elem.getElementsByTagName("Dependency");
+ for (int j=0; j<depnl.getLength(); j++) {
+ Element dep = (Element)depnl.item(j);
+ Dependency newDep = new Dependency(dep);
+ dependencyList.add(newDep);
+ }
+ NodeList aggnl = elem.getElementsByTagName("Aggregation");
+ for (int j=0; j<aggnl.getLength(); j++) {
+ Element agg = (Element)aggnl.item(j);
+ Aggregation newAgg = new Aggregation(agg);
+ aggregationList.add(newAgg);
+ }
+ }
+
+ public void setNs(String ns) {
+ this.ns = ns;
+ }
+
+ public 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!", "");
@@ -90,28 +105,40 @@ public class NewItem {
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));
- }
+ // set the name property
+ properties.add(new Property("Name", name));
+
// init the new item
try {
// find workflow def
- CompositeActivityDef compact = (CompositeActivityDef)LocalObjectLoader.getActDef(workflow, "last");
-
+ CompositeActivityDef compact = (CompositeActivityDef)LocalObjectLoader.getActDef(workflow, "0");
newItem.initialise(
agentId,
- CastorXMLUtility.marshall(propList),
- CastorXMLUtility.marshall(compact.instantiate()));
+ Gateway.getMarshaller().marshall(new PropertyArrayList(properties)),
+ Gateway.getMarshaller().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.", "");
}
+ // import outcomes
+
+ History hist = new History(entPath.getSysKey(), null);
+ for (Outcome thisOutcome : outcomes) {
+ String data = Resource.getTextResource(ns, thisOutcome.path);
+ Event newEvent = hist.addEvent("system", "Admin", Transitions.DONE, "Import", "Import", "Import", States.FINISHED);
+ com.c2kernel.persistency.outcome.Outcome newOutcome = new com.c2kernel.persistency.outcome.Outcome(newEvent.getID(), data, thisOutcome.schema, thisOutcome.version);
+ Viewpoint newLastView = new Viewpoint(entPath.getSysKey(), thisOutcome.schema, thisOutcome.viewname, thisOutcome.version, newEvent.getID());
+ try {
+ Gateway.getStorage().put(entPath.getSysKey(), newOutcome, null);
+ Gateway.getStorage().put(entPath.getSysKey(), newLastView, null);
+ } catch (ClusterStorageException e) {
+ throw new ObjectCannotBeUpdated("Could not store data for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name);
+ }
+ }
+
// create collections
for (Dependency element: dependencyList) {
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java
new file mode 100644
index 0000000..c0e62ec
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Outcome.java
@@ -0,0 +1,18 @@
+package com.c2kernel.lifecycle.instance.predefined.entitycreation;
+
+public class Outcome {
+ public String schema, viewname, path;
+ public int version;
+
+ public Outcome() {
+ }
+
+ public Outcome(String schema, String version, String viewname, String path) {
+ super();
+ this.schema = schema;
+ this.version = Integer.parseInt(version);
+ this.viewname = viewname;
+ this.path = path;
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Property.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Property.java
deleted file mode 100644
index e2d214c..0000000
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/Property.java
+++ /dev/null
@@ -1,26 +0,0 @@
-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;
- }
-}