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 --- .../predefined/item/CreateItemFromDescription.java | 194 --------------------- .../lifecycle/instance/predefined/item/Erase.java | 79 --------- .../item/ItemPredefinedStepContainer.java | 45 ----- 3 files changed, 318 deletions(-) delete mode 100644 src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java delete mode 100644 src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java delete mode 100644 src/main/java/com/c2kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/item') diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java deleted file mode 100644 index 140f68c..0000000 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java +++ /dev/null @@ -1,194 +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.lifecycle.instance.predefined.item; - -import com.c2kernel.collection.Collection; -import com.c2kernel.collection.CollectionArrayList; -import com.c2kernel.collection.CollectionDescription; -import com.c2kernel.collection.CollectionMember; -import com.c2kernel.common.CannotManageException; -import com.c2kernel.common.InvalidDataException; -import com.c2kernel.common.ObjectAlreadyExistsException; -import com.c2kernel.common.ObjectCannotBeUpdated; -import com.c2kernel.common.ObjectNotFoundException; -import com.c2kernel.common.PersistencyException; -import com.c2kernel.entity.CorbaServer; -import com.c2kernel.entity.TraceableEntity; -import com.c2kernel.lifecycle.CompositeActivityDef; -import com.c2kernel.lifecycle.instance.CompositeActivity; -import com.c2kernel.lifecycle.instance.predefined.PredefinedStep; -import com.c2kernel.lookup.AgentPath; -import com.c2kernel.lookup.DomainPath; -import com.c2kernel.lookup.ItemPath; -import com.c2kernel.persistency.ClusterStorage; -import com.c2kernel.process.Gateway; -import com.c2kernel.property.Property; -import com.c2kernel.property.PropertyArrayList; -import com.c2kernel.property.PropertyDescriptionList; -import com.c2kernel.property.PropertyUtility; -import com.c2kernel.utils.LocalObjectLoader; -import com.c2kernel.utils.Logger; - -/************************************************************************** - * - * @author $Author: abranson $ $Date: 2005/10/13 08:13:58 $ - * @version $Revision: 1.47 $ - **************************************************************************/ -public class CreateItemFromDescription extends PredefinedStep -{ - public CreateItemFromDescription() - { - super(); - } - - //requestdata is xmlstring - @Override - protected String runActivityLogic(AgentPath agent, ItemPath itemPath, - int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, ObjectAlreadyExistsException, CannotManageException, ObjectCannotBeUpdated, PersistencyException { - - String[] input = getDataList(requestData); - String newName = input[0]; - String domPath = input[1]; - String descVer = input.length > 2 ? input[2]:"last"; - PropertyArrayList initProps = - input.length > 3?getInitProperties(input[3]):new PropertyArrayList(); - - Logger.msg(1, "CreateItemFromDescription - Starting."); - - // check if the path is already taken - DomainPath context = new DomainPath(new DomainPath(domPath), newName); - //Logger.debug(8,"context "+context.getItemPath()+" "+context.getPath()+" "+context.getString()); - if (context.exists()) - throw new ObjectAlreadyExistsException("The path " +context+ " exists already."); - - // get init objects - - /* ITEM CREATION */ - - // generate new entity key - Logger.msg(6, "CreateItemFromDescription - Requesting new item path"); - ItemPath newItemPath = new ItemPath(); - - // resolve the item factory - Logger.msg(6, "CreateItemFromDescription - Resolving item factory"); - - // create the Item object - Logger.msg(3, "CreateItemFromDescription - Creating Item"); - CorbaServer factory = Gateway.getCorbaServer(); - if (factory == null) throw new CannotManageException("This process cannot create new Items"); - TraceableEntity newItem = factory.createItem(newItemPath); - Gateway.getLookupManager().add(newItemPath); - - - // initialise it with its properties and workflow - - Logger.msg(3, "CreateItemFromDescription - Initializing Item"); - - try { - newItem.initialise( - agent.getSystemKey(), - Gateway.getMarshaller().marshall(getNewProperties(itemPath, descVer, initProps, newName, agent)), - Gateway.getMarshaller().marshall(getNewWorkflow(itemPath, descVer)), - Gateway.getMarshaller().marshall(getNewCollections(itemPath, descVer)) - ); - } catch (PersistencyException e) { - throw e; - } catch (Exception e) { - throw new InvalidDataException("CreateAgentFromDescription: Problem initializing new Agent. See log: "+e.getMessage()); - } - // add its domain path - Logger.msg(3, "CreateItemFromDescription - Creating "+context); - context.setItemPath(newItemPath); - Gateway.getLookupManager().add(context); - return requestData; - } - - protected PropertyArrayList getInitProperties(String input) throws InvalidDataException { - try { - return (PropertyArrayList)Gateway.getMarshaller().unmarshall(input); - } catch (Exception e) { - Logger.error(e); - throw new InvalidDataException("Initial property parameter was not a marshalled PropertyArrayList: "+input); - } - } - - protected PropertyArrayList getNewProperties(ItemPath itemPath, String descVer, PropertyArrayList initProps, String newName, AgentPath agent) throws ObjectNotFoundException, InvalidDataException { - // copy properties -- intend to create from propdesc - PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer); - PropertyArrayList props = pdList.instantiate(initProps); - // set Name prop or create if not present - boolean foundName = false; - for (Property prop : props.list) { - if (prop.getName().equals("Name")) { - foundName = true; - prop.setValue(newName); - } - } - if (!foundName) props.list.add(new Property("Name", newName, true)); - props.list.add( new Property("Creator", agent.getAgentName(), false)); - return props; - } - - protected CompositeActivity getNewWorkflow(ItemPath itemPath, String descVer) throws ObjectNotFoundException, InvalidDataException, PersistencyException { - // find the workflow def for the given description version - - String wfDefName = null; Integer wfDefVer = null; - - Collection thisCol = (Collection)Gateway.getStorage().get(itemPath, ClusterStorage.COLLECTION+"/workflow/"+descVer, null); - CollectionMember wfMember = thisCol.getMembers().list.get(0); - wfDefName = wfMember.resolveItem().getName(); - Object wfVerObj = wfMember.getProperties().get("Version"); - try { - wfDefVer = Integer.parseInt(wfVerObj.toString()); - } catch (NumberFormatException ex) { - throw new InvalidDataException("Invalid workflow version number: "+wfVerObj.toString()); - } - - // load workflow def - if (wfDefName == null) - throw new InvalidDataException("No workflow given or defined"); - if (wfDefVer == null) - throw new InvalidDataException("No workflow def version given"); - - try { - CompositeActivityDef wfDef = (CompositeActivityDef)LocalObjectLoader.getActDef(wfDefName, wfDefVer); - return (CompositeActivity)wfDef.instantiate(); - } catch (ObjectNotFoundException ex) { - throw new InvalidDataException("Workflow def '"+wfDefName+"'v"+wfDefVer+" not found"); - } catch (ClassCastException ex) { - throw new InvalidDataException("Activity def '"+wfDefName+"' was not Composite"); - } - } - - protected CollectionArrayList getNewCollections(ItemPath itemPath, String descVer) throws ObjectNotFoundException, PersistencyException { - // loop through collections, collecting instantiated descriptions and finding the default workflow def - CollectionArrayList colls = new CollectionArrayList(); - String[] collNames = Gateway.getStorage().getClusterContents(itemPath, ClusterStorage.COLLECTION); - for (String collName : collNames) { - Collection thisCol = (Collection)Gateway.getStorage().get(itemPath, ClusterStorage.COLLECTION+"/"+collName+"/"+descVer, null); - if (thisCol instanceof CollectionDescription) { - CollectionDescription thisDesc = (CollectionDescription)thisCol; - colls.put(thisDesc.newInstance()); - } - } - return colls; - } -} diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java deleted file mode 100644 index a34b202..0000000 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java +++ /dev/null @@ -1,79 +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.lifecycle.instance.predefined.item; - - - -import java.util.Iterator; - -import com.c2kernel.common.CannotManageException; -import com.c2kernel.common.InvalidDataException; -import com.c2kernel.common.ObjectCannotBeUpdated; -import com.c2kernel.common.ObjectNotFoundException; -import com.c2kernel.common.PersistencyException; -import com.c2kernel.lifecycle.instance.predefined.PredefinedStep; -import com.c2kernel.lookup.AgentPath; -import com.c2kernel.lookup.DomainPath; -import com.c2kernel.lookup.ItemPath; -import com.c2kernel.lookup.Path; -import com.c2kernel.process.Gateway; -import com.c2kernel.utils.Logger; - - -/************************************************************************** - * - * @author $Author: abranson $ $Date: 2005/11/15 15:56:38 $ - * @version $Revision: 1.10 $ - **************************************************************************/ -public class Erase extends PredefinedStep -{ - public Erase() - { - super(); - getProperties().put("Agent Role", "Admin"); - } - - //requestdata is xmlstring - @Override - protected String runActivityLogic(AgentPath agent, ItemPath item, - int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, PersistencyException { - - Logger.msg(1, "Erase::request() - Starting."); - - Iterator domPaths = Gateway.getLookup().searchAliases(item); - while (domPaths.hasNext()) { - DomainPath path = (DomainPath)domPaths.next(); - // delete them - if (path.getItemPath().equals(item)) - Gateway.getLookupManager().delete(path); - } - - //clear out all storages - Gateway.getStorage().removeCluster(item, "", null); - - //remove entity path - Gateway.getLookupManager().delete(item); - - Logger.msg(1, "Erase::request() - DONE."); - return requestData; - } - -} diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java deleted file mode 100644 index 57aefa3..0000000 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java +++ /dev/null @@ -1,45 +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.lifecycle.instance.predefined.item; - -import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer; - - -/************************************************************************** - * - * $Revision: 1.2 $ - * $Date: 2005/06/02 10:19:33 $ - * - * Copyright (C) 2003 CERN - European Organization for Nuclear Research - * All rights reserved. - **************************************************************************/ - -public class ItemPredefinedStepContainer extends PredefinedStepContainer { - - - @Override - public void createChildren() - { - super.createChildren(); - predInit("CreateItemFromDescription", "Create a new item using this item as its description", new CreateItemFromDescription()); - predInit("Erase", "Deletes all objects and domain paths for this item.", new Erase()); - } -} -- cgit v1.2.3