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/transfer/TransferItem.java | 68 ++++++++++++++-------- 1 file changed, 45 insertions(+), 23 deletions(-) (limited to 'src/main/java/com/c2kernel/entity/transfer/TransferItem.java') diff --git a/src/main/java/com/c2kernel/entity/transfer/TransferItem.java b/src/main/java/com/c2kernel/entity/transfer/TransferItem.java index 9852555..bcbbe65 100644 --- a/src/main/java/com/c2kernel/entity/transfer/TransferItem.java +++ b/src/main/java/com/c2kernel/entity/transfer/TransferItem.java @@ -3,11 +3,15 @@ package com.c2kernel.entity.transfer; import java.io.File; import java.util.ArrayList; import java.util.Iterator; +import java.util.UUID; +import com.c2kernel.collection.Collection; +import com.c2kernel.collection.CollectionArrayList; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.TraceableEntity; import com.c2kernel.lifecycle.instance.Workflow; +import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; import com.c2kernel.lookup.ItemPath; import com.c2kernel.lookup.Path; @@ -20,33 +24,49 @@ import com.c2kernel.utils.FileStringUtility; import com.c2kernel.utils.Logger; public class TransferItem { - public ArrayList domainPaths; - public int sysKey; - static int importAgentId; + private ArrayList domainPaths; + protected ItemPath itemPath; + static AgentPath importAgentId; public TransferItem() throws Exception { try { - importAgentId = Gateway.getLookup().getAgentPath("system").getSysKey(); + importAgentId = Gateway.getLookup().getAgentPath("system"); } catch (ObjectNotFoundException e) { Logger.error("TransferItem - System user not found!"); throw e; } } - public TransferItem(int sysKey) throws Exception { - this.sysKey = sysKey; + public TransferItem(ItemPath itemPath) throws Exception { + this.itemPath = itemPath; domainPaths = new ArrayList(); - Property name = (Property)Gateway.getStorage().get(sysKey, ClusterStorage.PROPERTY + "/Name", null); - Iterator paths = Gateway.getLookup().search(new DomainPath(), name.getValue()); + Iterator paths = Gateway.getLookup().searchAliases(itemPath); while (paths.hasNext()) { DomainPath thisPath = (DomainPath)paths.next(); domainPaths.add(thisPath.toString()); } } - + + public ArrayList getDomainPaths() { + return domainPaths; + } + + public void setDomainPaths(ArrayList domainPaths) { + this.domainPaths = domainPaths; + } + + public void setUUID( String uuid ) + { + itemPath = new ItemPath(UUID.fromString(uuid)); + } + + public String getUUID() { + return itemPath.getUUID().toString(); + } + public void exportItem(File dir, String path) throws Exception { - Logger.msg("Path " + path + " in " + sysKey); - String[] contents = Gateway.getStorage().getClusterContents(sysKey, path); + Logger.msg("Path " + path + " in " + itemPath); + String[] contents = Gateway.getStorage().getClusterContents(itemPath, path); if (contents.length > 0) { FileStringUtility.createNewDir(dir.getCanonicalPath()); for (String content : contents) { @@ -54,8 +74,8 @@ public class TransferItem { } } else { //no children, try to dump object try { - C2KLocalObject obj = Gateway.getStorage().get(sysKey, path, null); - Logger.msg("Dumping object " + path + " in " + sysKey); + C2KLocalObject obj = Gateway.getStorage().get(itemPath, path, null); + Logger.msg("Dumping object " + path + " in " + itemPath); File dumpPath = new File(dir.getCanonicalPath() + ".xml"); FileStringUtility.string2File(dumpPath, Gateway.getMarshaller().marshall(obj)); return; @@ -67,8 +87,8 @@ public class TransferItem { public void importItem(File dir) throws Exception { // check if already exists try { - Property name = (Property)Gateway.getStorage().get(sysKey, ClusterStorage.PROPERTY + "/Name", null); - throw new Exception("Syskey " + sysKey + " already in use as " + name.getValue()); + Property name = (Property)Gateway.getStorage().get(itemPath, ClusterStorage.PROPERTY + "/Name", null); + throw new Exception("Entity " + itemPath + " already in use as " + name.getValue()); } catch (Exception ex) { } @@ -89,38 +109,40 @@ public class TransferItem { } // create item - ItemPath entityPath = new ItemPath(sysKey); - TraceableEntity newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entityPath); - Gateway.getLookupManager().add(entityPath); + TraceableEntity newItem = Gateway.getCorbaServer().createItem(itemPath); + Gateway.getLookupManager().add(itemPath); PropertyArrayList props = new PropertyArrayList(); + CollectionArrayList colls = new CollectionArrayList(); Workflow wf = null; // put objects for (C2KLocalObject obj : objects) { if (obj instanceof Property) props.list.add((Property)obj); + else if (obj instanceof Collection) + colls.list.add((Collection)obj); else if (obj instanceof Workflow) wf = (Workflow)obj; } if (wf == null) - throw new Exception("No workflow found in import for "+sysKey); + throw new Exception("No workflow found in import for "+itemPath); // init item - newItem.initialise(importAgentId, + newItem.initialise(importAgentId.getSystemKey(), Gateway.getMarshaller().marshall(props), Gateway.getMarshaller().marshall(wf.search("workflow/domain")), null); // store objects - importByType(ClusterStorage.COLLECTION, objects); + importByType(ClusterStorage.COLLECTION, objects); //TODO: move this to initialise importByType(ClusterStorage.HISTORY, objects); importByType(ClusterStorage.OUTCOME, objects); importByType(ClusterStorage.VIEWPOINT, objects); Gateway.getStorage().commit(this); // add domPaths for (String element : domainPaths) { - DomainPath newPath = new DomainPath(element, entityPath); + DomainPath newPath = new DomainPath(element, itemPath); Gateway.getLookupManager().add(newPath); } } @@ -128,7 +150,7 @@ public class TransferItem { private void importByType(String type, ArrayList objects) throws Exception { for (C2KLocalObject element : objects) { if (element.getClusterType().equals(type)) - Gateway.getStorage().put(sysKey, element, this); + Gateway.getStorage().put(itemPath, element, this); } } -- cgit v1.2.3