summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-06-05 16:47:41 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-06-05 16:47:41 +0200
commite73468fd08cc27aa31f76a27c916e45d5987c628 (patch)
tree36e5683c7e79f21d4f610c956a3267179da64983 /src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java
parent8dbf947eb6e84ec6a3c6e9ba421c682d847a8b00 (diff)
Moved old entitycreation package from the predefined step package to a
new 'imports' package under entity. Renamed most classed with an 'Import' prefix to avoid clashes with other API classes. Fixes #194
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.java187
1 files changed, 0 insertions, 187 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
deleted file mode 100644
index b1ef0e4..0000000
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java
+++ /dev/null
@@ -1,187 +0,0 @@
-package com.c2kernel.lifecycle.instance.predefined.entitycreation;
-
-
-import java.util.ArrayList;
-
-import org.custommonkey.xmlunit.Diff;
-import org.custommonkey.xmlunit.XMLUnit;
-
-import com.c2kernel.collection.CollectionArrayList;
-import com.c2kernel.collection.MembershipException;
-import com.c2kernel.common.CannotManageException;
-import com.c2kernel.common.InvalidDataException;
-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.Transition;
-import com.c2kernel.lookup.DomainPath;
-import com.c2kernel.lookup.ItemPath;
-import com.c2kernel.persistency.ClusterStorage;
-import com.c2kernel.persistency.ClusterStorageException;
-import com.c2kernel.persistency.outcome.Viewpoint;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.process.module.ModuleImport;
-import com.c2kernel.property.Property;
-import com.c2kernel.property.PropertyArrayList;
-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 extends ModuleImport {
-
- public String initialPath;
- public String workflow;
- public Integer workflowVer;
- 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>();
- private String ns;
-
- public NewItem() {
- }
-
- public NewItem(String name, String initialPath, String wf, int wfVer) {
- this();
- this.name = name;
- this.initialPath = initialPath;
- this.workflow = wf;
- this.workflowVer = wfVer;
- }
-
- public void setNamespace(String ns) {
- this.ns = ns;
- if (initialPath == null) initialPath = "/desc/"+ns;
- }
-
- public String getNamespace() {
- return ns;
- }
-
- public void create(int agentId, boolean reset) throws ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException {
- DomainPath domPath = new DomainPath(new DomainPath(initialPath), name);
-
- ItemPath entPath; TraceableEntity newItem;
- if (domPath.exists()) {
- entPath = domPath.getEntity();
- newItem = Gateway.getCorbaServer().getItem(entPath.getSysKey());
- }
- else {
- // create item
- entPath = Gateway.getNextKeyManager().generateNextEntityKey();
- newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entPath);
- Gateway.getLookup().add(entPath);
- }
-
- // set the name property
- properties.add(new Property("Name", name, true));
-
- // find workflow def
- CompositeActivityDef compact;
- // default workflow version is 0 if not given
- int usedWfVer;
- if (workflowVer == null) usedWfVer = 0;
- else usedWfVer = workflowVer.intValue();
- try {
- compact = (CompositeActivityDef)LocalObjectLoader.getActDef(workflow, usedWfVer);
- } catch (ObjectNotFoundException ex) {
- throw new CannotManageException("Could not find workflow "+workflow+"v"+usedWfVer+" for item "+domPath, "");
- } catch (InvalidDataException e) {
- throw new CannotManageException("Workflow def "+workflow+" v"+usedWfVer+" for item "+domPath+" was not valid", "");
- }
-
- // create collections
- CollectionArrayList colls = new CollectionArrayList();
- for (Dependency element: dependencyList) {
- try {
- com.c2kernel.collection.Dependency newDep = element.create();
- colls.put(newDep);
- } 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 {
- com.c2kernel.collection.Aggregation newAgg = element.create();
- colls.put(newAgg);
- } catch (MembershipException ex) {
- Logger.error(ex);
- throw new CannotManageException("A specified member is not of the correct type in "+element.name, "");
- }
- }
-
- // (re)initialise the new item with properties, workflow and collections
- try {
- newItem.initialise(
- agentId,
- Gateway.getMarshaller().marshall(new PropertyArrayList(properties)),
- Gateway.getMarshaller().marshall(compact.instantiate()),
- Gateway.getMarshaller().marshall(colls));
- } catch (Exception ex) {
- Logger.error("Error initialising new item "+name );
- Logger.error(ex);
- throw new CannotManageException("Problem initialising new item. See server log.", "");
- }
-
- // import outcomes
- XMLUnit.setIgnoreWhitespace(true);
- XMLUnit.setIgnoreComments(true);
- History hist = new History(entPath.getSysKey(), null);
- for (Outcome thisOutcome : outcomes) {
- com.c2kernel.persistency.outcome.Outcome newOutcome = new com.c2kernel.persistency.outcome.Outcome(-1, thisOutcome.getData(ns), thisOutcome.schema, thisOutcome.version);
- Viewpoint impView;
- try {
- impView = (Viewpoint)Gateway.getStorage().get(entPath.getSysKey(), ClusterStorage.VIEWPOINT+"/"+thisOutcome.schema+"/"+thisOutcome.viewname, null);
-
- Diff xmlDiff = new Diff(newOutcome.getDOM(), impView.getOutcome().getDOM());
- if (xmlDiff.identical()) {
- Logger.msg(5, "NewItem.create() - View "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name+" identical, no update required");
- continue;
- }
- else {
- Logger.msg("NewItem.create() - Difference found in view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name+": "+xmlDiff.toString());
- if (!reset && !impView.getEvent().getStepPath().equals("Import")) {
- Logger.msg("Last edit was not done by import, and reset not requested. Not overwriting.");
- continue;
- }
- }
- } catch (ObjectNotFoundException ex) {
- Logger.msg(3, "View "+thisOutcome.schema+"/"+thisOutcome.viewname+" not found in "+name+". Creating.");
- impView = new Viewpoint(entPath.getSysKey(), thisOutcome.schema, thisOutcome.viewname, thisOutcome.version, -1);
- } catch (ClusterStorageException e) {
- throw new ObjectCannotBeUpdated("Could not check data for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name);
- } catch (InvalidDataException e) {
- throw new ObjectCannotBeUpdated("Could not check previous event for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name);
- }
-
- // write new view/outcome/event
- Transition predefDone = new Transition(0, "Done", 0, 0);
- Event newEvent = hist.addEvent("system", "Admin", "Import", "Import", "Import", thisOutcome.schema, thisOutcome.version, "PredefinedStep", 0, predefDone, thisOutcome.viewname);
- newOutcome.setID(newEvent.getID());
- impView.setEventId(newEvent.getID());
- try {
- Gateway.getStorage().put(entPath.getSysKey(), newOutcome, null);
- Gateway.getStorage().put(entPath.getSysKey(), impView, null);
- } catch (ClusterStorageException e) {
- throw new ObjectCannotBeUpdated("Could not store data for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name);
- }
- }
-
- // register domain path (before collections in case of recursive collections)
- if (!domPath.exists()) {
- domPath.setEntity(entPath);
- Gateway.getLookup().add(domPath);
- }
- }
-}