summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/entity/transfer
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2012-05-30 08:37:45 +0200
committerAndrew Branson <andrew.branson@cern.ch>2012-05-30 08:37:45 +0200
commitb086f57f56bf0eb9dab9cf321a0f69aaaae84347 (patch)
tree8e6e26e8b7eed6abad7a17b093bdbb55c5e6b1ba /source/com/c2kernel/entity/transfer
parent22088ae8d2d5ff390518dbe1c4372325ffb3a647 (diff)
Initial Maven Conversion
Diffstat (limited to 'source/com/c2kernel/entity/transfer')
-rw-r--r--source/com/c2kernel/entity/transfer/TransferItem.java133
-rw-r--r--source/com/c2kernel/entity/transfer/TransferSet.java103
2 files changed, 0 insertions, 236 deletions
diff --git a/source/com/c2kernel/entity/transfer/TransferItem.java b/source/com/c2kernel/entity/transfer/TransferItem.java
deleted file mode 100644
index 0e3b764..0000000
--- a/source/com/c2kernel/entity/transfer/TransferItem.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package com.c2kernel.entity.transfer;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Enumeration;
-
-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.DomainPath;
-import com.c2kernel.lookup.EntityPath;
-import com.c2kernel.lookup.Path;
-import com.c2kernel.persistency.ClusterStorage;
-import com.c2kernel.persistency.outcome.Outcome;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.property.Property;
-import com.c2kernel.property.PropertyArrayList;
-import com.c2kernel.utils.CastorXMLUtility;
-import com.c2kernel.utils.FileStringUtility;
-import com.c2kernel.utils.Logger;
-
-public class TransferItem {
- public ArrayList<String> domainPaths;
- public int sysKey;
- static int importAgentId;
-
- public TransferItem() throws Exception {
- try {
- importAgentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey();
- } catch (ObjectNotFoundException e) {
- Logger.error("TransferItem - System user not found!");
- throw e;
- }
- }
-
- public TransferItem(int sysKey) throws Exception {
- this.sysKey = sysKey;
- domainPaths = new ArrayList<String>();
- Property name = (Property)Gateway.getStorage().get(sysKey, ClusterStorage.PROPERTY + "/Name", null);
- Enumeration<Path> paths = Gateway.getLDAPLookup().search(new DomainPath(), name.getValue());
- while (paths.hasMoreElements()) {
- DomainPath thisPath = (DomainPath)paths.nextElement();
- domainPaths.add(thisPath.toString());
- }
- }
-
- public void exportItem(File dir, String path) throws Exception {
- Logger.msg("Path " + path + " in " + sysKey);
- String[] contents = Gateway.getStorage().getClusterContents(sysKey, path);
- if (contents.length > 0) {
- FileStringUtility.createNewDir(dir.getCanonicalPath());
- for (String content : contents) {
- exportItem(new File(dir, content), path + "/" + content);
- }
- } else { //no children, try to dump object
- try {
- C2KLocalObject obj = Gateway.getStorage().get(sysKey, path, null);
- Logger.msg("Dumping object " + path + " in " + sysKey);
- File dumpPath = new File(dir.getCanonicalPath() + ".xml");
- FileStringUtility.string2File(dumpPath, CastorXMLUtility.marshall(obj));
- return;
- } catch (ObjectNotFoundException ex) {
- } // not an object
- }
- }
-
- 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());
- } catch (Exception ex) {
- }
-
- // retrieve objects
- ArrayList<String> objectFiles = FileStringUtility.listDir(dir.getCanonicalPath(), false, true);
- ArrayList<C2KLocalObject> objects = new ArrayList<C2KLocalObject>();
- for (String element : objectFiles) {
- String xmlFile = FileStringUtility.file2String(element);
- C2KLocalObject newObj;
- String choppedPath = element.substring(dir.getCanonicalPath().length()+1, element.length()-4);
- Logger.msg(choppedPath);
- if (choppedPath.startsWith(ClusterStorage.OUTCOME))
- newObj = new Outcome(choppedPath, xmlFile);
- else
- newObj = (C2KLocalObject)CastorXMLUtility.unmarshall(xmlFile);
-
- objects.add(newObj);
- }
-
- // create item
- EntityPath entityPath = new EntityPath(sysKey);
- TraceableEntity newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entityPath);
- Gateway.getLDAPLookup().add(entityPath);
-
- PropertyArrayList props = new PropertyArrayList();
- Workflow wf = null;
- // put objects
- for (C2KLocalObject obj : objects) {
- if (obj instanceof Property)
- props.list.add((Property)obj);
- else if (obj instanceof Workflow)
- wf = (Workflow)obj;
- }
-
- if (wf == null)
- throw new Exception("No workflow found in import for "+sysKey);
-
- // init item
- newItem.initialise(importAgentId, CastorXMLUtility.marshall(props), CastorXMLUtility.marshall(wf.search("workflow/domain")));
-
- // store objects
- importByType(ClusterStorage.COLLECTION, objects);
- 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);
- Gateway.getLDAPLookup().add(newPath);
- }
- }
-
- private void importByType(String type, ArrayList<C2KLocalObject> objects) throws Exception {
- for (C2KLocalObject element : objects) {
- if (element.getClusterType().equals(type))
- Gateway.getStorage().put(sysKey, element, this);
- }
-
- }
-} \ No newline at end of file
diff --git a/source/com/c2kernel/entity/transfer/TransferSet.java b/source/com/c2kernel/entity/transfer/TransferSet.java
deleted file mode 100644
index 71a593a..0000000
--- a/source/com/c2kernel/entity/transfer/TransferSet.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package com.c2kernel.entity.transfer;
-
-import java.io.File;
-import java.util.ArrayList;
-
-import com.c2kernel.lookup.EntityPath;
-import com.c2kernel.lookup.NextKeyManager;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.utils.CastorXMLUtility;
-import com.c2kernel.utils.FileStringUtility;
-import com.c2kernel.utils.Logger;
-
-/**************************************************************************
- *
- * $Revision: 1.5 $
- * $Date: 2005/04/26 06:48:13 $
- *
- * Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
- **************************************************************************/
-
-public class TransferSet {
-
- public ArrayList<TransferItem> items;
-
- public TransferSet() {
- }
-
- public TransferSet(int[] sysKeys) {
- items = new ArrayList<TransferItem>();
- for (int sysKey : sysKeys) {
- try {
- items.add(new TransferItem(sysKey));
- } catch (Exception ex) {
- Logger.error("Could not add item "+sysKey);
- Logger.error(ex);
- }
- }
- }
-
- public void exportPackage(File dir) throws Exception {
- if (items==null || items.size() == 0)
- throw new Exception("Nothing to dump");
- FileStringUtility.createNewDir(dir.getAbsolutePath());
- for (TransferItem element : items) {
- try {
- element.exportItem(new File(dir, String.valueOf(element.sysKey)), "/");
- } catch (Exception ex) {
- Logger.error("Error dumping item "+element.sysKey);
- Logger.error(ex);
- }
- }
-
- try {
- String self = CastorXMLUtility.marshall(this);
- FileStringUtility.string2File(new File(dir, "transferSet.xml"), self);
- } catch (Exception ex) {
- Logger.error("Error writing header file");
- Logger.error(ex);
- }
- }
-
- public void importPackage(File rootDir) {
- for (TransferItem element : items) {
- Logger.msg(5, "Importing "+element.sysKey);
- try {
- element.importItem(new File(rootDir, String.valueOf(element.sysKey)));
- } catch (Exception ex) {
- Logger.error("Import of item "+element.sysKey+" failed. Rolling back");
- Logger.error(ex);
- Gateway.getStorage().abort(element);
- }
- }
- checkLastKey();
- }
-
- private void checkLastKey()
- {
- // find highest key in out import set
- int packageLastKey = 0;
- for (TransferItem element : items) {
- if (element.sysKey > packageLastKey)
- packageLastKey = element.sysKey;
- }
-
- try
- { // find the current last key
- NextKeyManager nextKeyMan = Gateway.getLDAPLookup().getNextKeyManager();
- EntityPath lastKey = nextKeyMan.getLastEntityPath();
- Logger.msg(1, "Last key imported was "+packageLastKey+". LDAP lastkey was "+lastKey.getSysKey());
-
-
- if (packageLastKey > lastKey.getSysKey()) { // set new last
- Logger.msg(1, "Updating lastKey to "+packageLastKey);
- nextKeyMan.writeLastEntityKey(packageLastKey);
- }
- }
- catch (Exception ex)
- {
- Logger.error("Exception::LoadKeys::processFile() " + ex);
- }
- }
-}