From da731d2bb81666b9c697d9099da632e7dfcdc0f7 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 9 Sep 2014 12:13:21 +0200 Subject: 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. --- .../com/c2kernel/entity/imports/ImportItem.java | 143 ++++++++++++++++----- 1 file changed, 109 insertions(+), 34 deletions(-) (limited to 'src/main/java/com/c2kernel/entity/imports/ImportItem.java') 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 properties = new ArrayList(); - public ArrayList aggregationList = new ArrayList(); - public ArrayList dependencyList = new ArrayList(); - public ArrayList outcomes = new ArrayList(); - private String ns; + protected String initialPath; + protected String workflow; + protected Integer workflowVer; + protected ArrayList properties = new ArrayList(); + protected ArrayList aggregationList = new ArrayList(); + protected ArrayList dependencyList = new ArrayList(); + protected ArrayList outcomes = new ArrayList(); 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 getProperties() { + return properties; + } + + public void setProperties(ArrayList properties) { + this.properties = properties; + } + + public ArrayList getAggregationList() { + return aggregationList; + } + + public void setAggregationList(ArrayList aggregationList) { + this.aggregationList = aggregationList; + } + + public ArrayList getDependencyList() { + return dependencyList; + } + + public void setDependencyList(ArrayList dependencyList) { + this.dependencyList = dependencyList; + } + + public ArrayList getOutcomes() { + return outcomes; + } + + public void setOutcomes(ArrayList outcomes) { + this.outcomes = outcomes; + } + } -- cgit v1.2.3