summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/entity/imports/ImportItem.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-09-09 12:13:21 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-09-09 12:13:21 +0200
commitda731d2bb81666b9c697d9099da632e7dfcdc0f7 (patch)
tree567693c3c48f3d15ecbb2dac4f9db03bb6e58c72 /src/main/java/com/c2kernel/entity/imports/ImportItem.java
parentae1e79e33fd30e3d8bcedbef8891a14a048276d7 (diff)
Replaced int sysKey Item identifier with UUID, which is now portable.
ItemPath objects are now used to identify Items throughout the kernel, replacing ints and Integers.
Diffstat (limited to 'src/main/java/com/c2kernel/entity/imports/ImportItem.java')
-rw-r--r--src/main/java/com/c2kernel/entity/imports/ImportItem.java143
1 files changed, 109 insertions, 34 deletions
diff --git a/src/main/java/com/c2kernel/entity/imports/ImportItem.java b/src/main/java/com/c2kernel/entity/imports/ImportItem.java
index 3847fbf..c1562b2 100644
--- a/src/main/java/com/c2kernel/entity/imports/ImportItem.java
+++ b/src/main/java/com/c2kernel/entity/imports/ImportItem.java
@@ -18,6 +18,7 @@ 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.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
@@ -38,48 +39,64 @@ import com.c2kernel.utils.Logger;
public class ImportItem extends ModuleImport {
- public String initialPath;
- public String workflow;
- public Integer workflowVer;
- public ArrayList<Property> properties = new ArrayList<Property>();
- public ArrayList<ImportAggregation> aggregationList = new ArrayList<ImportAggregation>();
- public ArrayList<ImportDependency> dependencyList = new ArrayList<ImportDependency>();
- public ArrayList<ImportOutcome> outcomes = new ArrayList<ImportOutcome>();
- private String ns;
+ protected String initialPath;
+ protected String workflow;
+ protected Integer workflowVer;
+ protected ArrayList<Property> properties = new ArrayList<Property>();
+ protected ArrayList<ImportAggregation> aggregationList = new ArrayList<ImportAggregation>();
+ protected ArrayList<ImportDependency> dependencyList = new ArrayList<ImportDependency>();
+ protected ArrayList<ImportOutcome> outcomes = new ArrayList<ImportOutcome>();
public ImportItem() {
}
- public ImportItem(String name, String initialPath, String wf, int wfVer) {
+ public ImportItem(String ns, String name, String initialPath, ItemPath itemPath, String wf, int wfVer) {
this();
- this.name = name;
- this.initialPath = initialPath;
- this.workflow = wf;
- this.workflowVer = wfVer;
+ setNamespace(ns);
+ setName(name);
+ setInitialPath(initialPath);
+ setWorkflow(wf);
+ setWorkflowVer(wfVer);
+ }
+
+ @Override
+ public ItemPath getItemPath() {
+ if (itemPath == null) { // try to find item if it already exists
+ DomainPath existingItem = new DomainPath(initialPath+"/"+name);
+ if (existingItem.exists()) {
+ try {
+ itemPath = existingItem.getItemPath();
+ } catch (ObjectNotFoundException ex) { }
+ }
+ }
+ if (itemPath == null) itemPath = new ItemPath();
+ return itemPath;
}
+ @Override
public void setNamespace(String ns) {
- this.ns = ns;
+ super.setNamespace(ns);
if (initialPath == null) initialPath = "/desc/"+ns;
+ itemPath = null;
}
-
- public String getNamespace() {
- return ns;
+
+ @Override
+ public void setName(String name) {
+ super.setName(name);
+ itemPath = null;
}
- public void create(int agentId, boolean reset) throws ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException {
+ @Override
+ public void create(AgentPath agentPath, 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());
+ TraceableEntity newItem;
+ if (getItemPath().exists()) {
+ newItem = Gateway.getCorbaServer().getItem(getItemPath());
}
else {
- // create item
- entPath = Gateway.getNextKeyManager().generateNextEntityKey();
- newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entPath);
- Gateway.getLookupManager().add(entPath);
+ newItem = Gateway.getCorbaServer().createItem(getItemPath());
+ Gateway.getLookupManager().add(getItemPath());
}
// set the name property
@@ -124,7 +141,7 @@ public class ImportItem extends ModuleImport {
// (re)initialise the new item with properties, workflow and collections
try {
newItem.initialise(
- agentId,
+ agentPath.getSystemKey(),
Gateway.getMarshaller().marshall(new PropertyArrayList(properties)),
Gateway.getMarshaller().marshall(compact.instantiate()),
Gateway.getMarshaller().marshall(colls));
@@ -137,12 +154,12 @@ public class ImportItem extends ModuleImport {
// import outcomes
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
- History hist = new History(entPath.getSysKey(), null);
+ History hist = new History(getItemPath(), null);
for (ImportOutcome 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);
+ impView = (Viewpoint)Gateway.getStorage().get(getItemPath(), ClusterStorage.VIEWPOINT+"/"+thisOutcome.schema+"/"+thisOutcome.viewname, null);
Diff xmlDiff = new Diff(newOutcome.getDOM(), impView.getOutcome().getDOM());
if (xmlDiff.identical()) {
@@ -158,7 +175,7 @@ public class ImportItem extends ModuleImport {
}
} 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);
+ impView = new Viewpoint(getItemPath(), 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) {
@@ -167,12 +184,12 @@ public class ImportItem extends ModuleImport {
// 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);
+ Event newEvent = hist.addEvent(agentPath, "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);
+ Gateway.getStorage().put(getItemPath(), newOutcome, null);
+ Gateway.getStorage().put(getItemPath(), impView, null);
} catch (ClusterStorageException e) {
throw new ObjectCannotBeUpdated("Could not store data for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name);
}
@@ -180,8 +197,66 @@ public class ImportItem extends ModuleImport {
// register domain path (before collections in case of recursive collections)
if (!domPath.exists()) {
- domPath.setEntity(entPath);
+ domPath.setEntity(getItemPath());
Gateway.getLookupManager().add(domPath);
}
}
+
+ public String getInitialPath() {
+ return initialPath;
+ }
+
+ public void setInitialPath(String initialPath) {
+ this.initialPath = initialPath;
+ itemPath = null;
+ }
+
+ public String getWorkflow() {
+ return workflow;
+ }
+
+ public void setWorkflow(String workflow) {
+ this.workflow = workflow;
+ }
+
+ public Integer getWorkflowVer() {
+ return workflowVer;
+ }
+
+ public void setWorkflowVer(Integer workflowVer) {
+ this.workflowVer = workflowVer;
+ }
+
+ public ArrayList<Property> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(ArrayList<Property> properties) {
+ this.properties = properties;
+ }
+
+ public ArrayList<ImportAggregation> getAggregationList() {
+ return aggregationList;
+ }
+
+ public void setAggregationList(ArrayList<ImportAggregation> aggregationList) {
+ this.aggregationList = aggregationList;
+ }
+
+ public ArrayList<ImportDependency> getDependencyList() {
+ return dependencyList;
+ }
+
+ public void setDependencyList(ArrayList<ImportDependency> dependencyList) {
+ this.dependencyList = dependencyList;
+ }
+
+ public ArrayList<ImportOutcome> getOutcomes() {
+ return outcomes;
+ }
+
+ public void setOutcomes(ArrayList<ImportOutcome> outcomes) {
+ this.outcomes = outcomes;
+ }
+
}