From 0ed2c1124cf1b9e49a2ec1fa0126a8df09f9e758 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 7 Oct 2014 09:18:11 +0200 Subject: Repackage to org.cristalise --- .../com/c2kernel/entity/transfer/TransferItem.java | 176 --------------------- .../com/c2kernel/entity/transfer/TransferSet.java | 93 ----------- .../com/c2kernel/entity/transfer/package-info.java | 36 ----- 3 files changed, 305 deletions(-) delete mode 100644 src/main/java/com/c2kernel/entity/transfer/TransferItem.java delete mode 100644 src/main/java/com/c2kernel/entity/transfer/TransferSet.java delete mode 100644 src/main/java/com/c2kernel/entity/transfer/package-info.java (limited to 'src/main/java/com/c2kernel/entity/transfer') diff --git a/src/main/java/com/c2kernel/entity/transfer/TransferItem.java b/src/main/java/com/c2kernel/entity/transfer/TransferItem.java deleted file mode 100644 index 0e8123b..0000000 --- a/src/main/java/com/c2kernel/entity/transfer/TransferItem.java +++ /dev/null @@ -1,176 +0,0 @@ -/** - * This file is part of the CRISTAL-iSE kernel. - * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 3 of the License, or (at - * your option) any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - * - * http://www.fsf.org/licensing/licenses/lgpl.html - */ -package com.c2kernel.entity.transfer; - -import java.io.File; -import java.util.ArrayList; -import java.util.Iterator; - -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.InvalidItemPathException; -import com.c2kernel.lookup.ItemPath; -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.FileStringUtility; -import com.c2kernel.utils.Logger; - -public class TransferItem { - private ArrayList domainPaths; - protected ItemPath itemPath; - static AgentPath importAgentId; - - public TransferItem() throws Exception { - try { - importAgentId = Gateway.getLookup().getAgentPath("system"); - } catch (ObjectNotFoundException e) { - Logger.error("TransferItem - System user not found!"); - throw e; - } - } - - public TransferItem(ItemPath itemPath) throws Exception { - this.itemPath = itemPath; - domainPaths = new ArrayList(); - 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 ) throws InvalidItemPathException - { - itemPath = new ItemPath(uuid); - } - - public String getUUID() { - return itemPath.getUUID().toString(); - } - - public void exportItem(File dir, String path) throws Exception { - 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) { - exportItem(new File(dir, content), path + "/" + content); - } - } else { //no children, try to dump object - try { - 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; - } catch (ObjectNotFoundException ex) { - } // not an object - } - } - - public void importItem(File dir) throws Exception { - // check if already exists - try { - 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) { - } - - // retrieve objects - ArrayList objectFiles = FileStringUtility.listDir(dir.getCanonicalPath(), false, true); - ArrayList objects = new ArrayList(); - 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)Gateway.getMarshaller().unmarshall(xmlFile); - - objects.add(newObj); - } - - // create item - 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 "+itemPath); - - // init item - newItem.initialise(importAgentId.getSystemKey(), - Gateway.getMarshaller().marshall(props), - Gateway.getMarshaller().marshall(wf.search("workflow/domain")), - Gateway.getMarshaller().marshall(colls)); - - // store 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, itemPath); - Gateway.getLookupManager().add(newPath); - } - } - - private void importByType(String type, ArrayList objects) throws Exception { - for (C2KLocalObject element : objects) { - if (element.getClusterType().equals(type)) - Gateway.getStorage().put(itemPath, element, this); - } - - } -} \ No newline at end of file diff --git a/src/main/java/com/c2kernel/entity/transfer/TransferSet.java b/src/main/java/com/c2kernel/entity/transfer/TransferSet.java deleted file mode 100644 index b6b4ecc..0000000 --- a/src/main/java/com/c2kernel/entity/transfer/TransferSet.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * This file is part of the CRISTAL-iSE kernel. - * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 3 of the License, or (at - * your option) any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - * - * http://www.fsf.org/licensing/licenses/lgpl.html - */ -package com.c2kernel.entity.transfer; - -import java.io.File; -import java.util.ArrayList; - -import com.c2kernel.lookup.ItemPath; -import com.c2kernel.process.Gateway; -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 items; - - public TransferSet() { - } - - public TransferSet(ItemPath[] itemPaths) { - items = new ArrayList(); - for (ItemPath item : itemPaths) { - try { - items.add(new TransferItem(item)); - } catch (Exception ex) { - Logger.error("Could not add item "+item); - 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, element.itemPath.getUUID().toString()), "/"); - } catch (Exception ex) { - Logger.error("Error dumping item "+element.itemPath); - Logger.error(ex); - } - } - - try { - String self = Gateway.getMarshaller().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.itemPath); - try { - element.importItem(new File(rootDir, element.itemPath.getUUID().toString())); - } catch (Exception ex) { - Logger.error("Import of item "+element.itemPath+" failed. Rolling back"); - Logger.error(ex); - Gateway.getStorage().abort(element); - } - } - } -} diff --git a/src/main/java/com/c2kernel/entity/transfer/package-info.java b/src/main/java/com/c2kernel/entity/transfer/package-info.java deleted file mode 100644 index 64a1846..0000000 --- a/src/main/java/com/c2kernel/entity/transfer/package-info.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * This file is part of the CRISTAL-iSE kernel. - * Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved. - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 3 of the License, or (at - * your option) any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - * - * http://www.fsf.org/licensing/licenses/lgpl.html - */ -/** - * Export and Import of Items. - * - *

{@link TransferItem} provides a mechanism for marshalling all of the - * C2KLocalObjects in an Item to XML and exporting them to disk, and then - * importing that Item on another server. {@link TransferSet} can export many - * Items at a time and preserve their domain paths. - * - *

This package is not currently used, as with the previous system key - * integer sequence it was not possible to import collections onto other servers - * but now Items are identified using UUIDs, this may now converge with the - * module mechanism. - * - */ - -package com.c2kernel.entity.transfer; \ No newline at end of file -- cgit v1.2.3