summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java')
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java133
1 files changed, 80 insertions, 53 deletions
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) {