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 --- .../instance/predefined/AddC2KObject.java | 67 +++++++ .../instance/predefined/AddDomainPath.java | 62 +++++++ .../instance/predefined/AddMemberToCollection.java | 105 +++++++++++ .../predefined/AddNewCollectionDescription.java | 110 ++++++++++++ .../lifecycle/instance/predefined/AddNewSlot.java | 128 ++++++++++++++ .../instance/predefined/AssignItemToSlot.java | 121 +++++++++++++ .../lifecycle/instance/predefined/ClearSlot.java | 114 ++++++++++++ .../predefined/CreateNewCollectionVersion.java | 103 +++++++++++ .../lifecycle/instance/predefined/Import.java | 106 +++++++++++ .../instance/predefined/PredefinedStep.java | 191 ++++++++++++++++++++ .../predefined/PredefinedStepContainer.java | 79 +++++++++ .../instance/predefined/RemoveC2KObject.java | 70 ++++++++ .../instance/predefined/RemoveDomainPath.java | 73 ++++++++ .../predefined/RemoveSlotFromCollection.java | 131 ++++++++++++++ .../instance/predefined/ReplaceDomainWorkflow.java | 77 ++++++++ .../instance/predefined/WriteProperty.java | 80 +++++++++ .../instance/predefined/WriteViewpoint.java | 88 ++++++++++ .../agent/AgentPredefinedStepContainer.java | 47 +++++ .../agent/CreateAgentFromDescription.java | 137 +++++++++++++++ .../instance/predefined/agent/RemoveAgent.java | 90 ++++++++++ .../predefined/agent/SetAgentPassword.java | 70 ++++++++ .../instance/predefined/agent/SetAgentRoles.java | 94 ++++++++++ .../predefined/item/CreateItemFromDescription.java | 195 +++++++++++++++++++++ .../lifecycle/instance/predefined/item/Erase.java | 80 +++++++++ .../item/ItemPredefinedStepContainer.java | 45 +++++ .../predefined/server/AddDomainContext.java | 67 +++++++ .../instance/predefined/server/CreateNewAgent.java | 68 +++++++ .../instance/predefined/server/CreateNewItem.java | 63 +++++++ .../instance/predefined/server/CreateNewRole.java | 60 +++++++ .../predefined/server/RemoveDomainContext.java | 65 +++++++ .../instance/predefined/server/RemoveRole.java | 68 +++++++ .../server/ServerPredefinedStepContainer.java | 62 +++++++ 32 files changed, 2916 insertions(+) create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddC2KObject.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddDomainPath.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddMemberToCollection.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewSlot.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AssignItemToSlot.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ClearSlot.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/CreateNewCollectionVersion.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/Import.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStep.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStepContainer.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveC2KObject.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveDomainPath.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteProperty.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteViewpoint.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/AgentPredefinedStepContainer.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/RemoveAgent.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/Erase.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/AddDomainContext.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewAgent.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewItem.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewRole.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveRole.java create mode 100644 src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/ServerPredefinedStepContainer.java (limited to 'src/main/java/org/cristalise/kernel/lifecycle/instance/predefined') diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddC2KObject.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddC2KObject.java new file mode 100644 index 0000000..20abbad --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddC2KObject.java @@ -0,0 +1,67 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + +import java.util.Arrays; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.C2KLocalObject; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.31 $ + **************************************************************************/ +public class AddC2KObject extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castror + **************************************************************************/ + public AddC2KObject() + { + super(); + getProperties().put("Agent Role", "Admin"); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, PersistencyException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AddC2KObject: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidDataException("AddC2KObject: Invalid parameters "+Arrays.toString(params)); + C2KLocalObject obj; + try { + obj = (C2KLocalObject)Gateway.getMarshaller().unmarshall(params[0]); + } catch (Exception e) { + throw new InvalidDataException("AddC2KObject: Could not unmarshall new object: "+params[0]); + } + Gateway.getStorage().put(item, obj, null ); + return requestData; + } +} \ No newline at end of file diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddDomainPath.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddDomainPath.java new file mode 100644 index 0000000..8f68d22 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddDomainPath.java @@ -0,0 +1,62 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + + + + +import java.util.Arrays; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.lookup.LookupManager; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class AddDomainPath extends PredefinedStep +{ + public AddDomainPath() + { + super(); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectCannotBeUpdated, ObjectAlreadyExistsException, CannotManageException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AddDomainPath: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidDataException("AddDomainPath: Invalid parameters "+Arrays.toString(params)); + + LookupManager lookupManager = Gateway.getLookupManager(); + + DomainPath domainPath = new DomainPath(params[0], item); + lookupManager.add(domainPath); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddMemberToCollection.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddMemberToCollection.java new file mode 100644 index 0000000..ac6004c --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddMemberToCollection.java @@ -0,0 +1,105 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.Dependency; +import org.cristalise.kernel.common.InvalidCollectionModification; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.C2KLocalObject; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.CastorHashMap; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.8 $ + **************************************************************************/ +public class AddMemberToCollection extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castor + **************************************************************************/ + public AddMemberToCollection() + { + super(); + } + + + /** + * Generates a new slot in a Dependency for the given item + * + * Params: + * 0 - collection name + * 1 - target entity key + * @throws ObjectAlreadyExistsException + * @throws PersistencyException + * @throws ObjectNotFoundException + * @throws InvalidCollectionModification + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectAlreadyExistsException, PersistencyException, ObjectNotFoundException, InvalidCollectionModification { + + String collName; + ItemPath newChild; + Dependency dep; + CastorHashMap props = null; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AddMemberToCollection: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + try { + collName = params[0]; + newChild = new ItemPath(params[1]); + if (params.length > 2) + props = (CastorHashMap)Gateway.getMarshaller().unmarshall(params[2]); + + } catch (Exception e) { + throw new InvalidDataException("AddMemberToCollection: Invalid parameters "+Arrays.toString(params)); + } + + // load collection + C2KLocalObject collObj; + collObj = Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + if (!(collObj instanceof Dependency)) throw new InvalidDataException("AddMemberToCollection: AddMemberToCollection operates on Dependency collections only."); + dep = (Dependency)collObj; + + // find member and assign entity + if (props == null) + dep.addMember(newChild); + else + dep.addMember(newChild, props, null); + + Gateway.getStorage().put(newChild, dep, null); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java new file mode 100644 index 0000000..b230284 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewCollectionDescription.java @@ -0,0 +1,110 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.AggregationDescription; +import org.cristalise.kernel.collection.CollectionDescription; +import org.cristalise.kernel.collection.DependencyDescription; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.8 $ + **************************************************************************/ +public class AddNewCollectionDescription extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castor + **************************************************************************/ + public AddNewCollectionDescription() + { + super(); + } + + + /** + * Generates a new empty collection description. Collection instances should + * be added by an Admin, who can do so using AddC2KObject. + * + * Params: + * 0 - collection name + * 1 - collection type (Aggregation, Dependency) + * @throws PersistencyException + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectAlreadyExistsException, PersistencyException { + + String collName; + String collType; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AddNewCollectionDescription: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 2) + throw new InvalidDataException("AddNewCollectionDescription: Invalid parameters "+Arrays.toString(params)); + + collName = params[0]; + collType = params[1]; + + // check if collection already exists + try { + Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + throw new ObjectAlreadyExistsException("Collection '"+collName+"' already exists"); + } catch (ObjectNotFoundException ex) { + // collection doesn't exist + } catch (PersistencyException ex) { + Logger.error(ex); + throw new PersistencyException("AddNewCollectionDescription: Error checking for collection '"+collName+"': "+ex.getMessage()); + } + + + CollectionDescription newCollDesc; + + if (collType.equals("Aggregation")) + newCollDesc = new AggregationDescription(collName); + if (collType.equals("Dependency")) + newCollDesc = new DependencyDescription(collName); + else + throw new InvalidDataException("AddNewCollectionDescription: Invalid collection type specified: '"+collType+"'. Must be Aggregation or Dependency."); + + // store it + try { + Gateway.getStorage().put(item, newCollDesc, null); + } catch (PersistencyException e) { + throw new PersistencyException("AddNewCollectionDescription: Error saving new collection '"+collName+"': "+e.getMessage()); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewSlot.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewSlot.java new file mode 100644 index 0000000..f3acdf3 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AddNewSlot.java @@ -0,0 +1,128 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.Aggregation; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.C2KLocalObject; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.property.PropertyDescription; +import org.cristalise.kernel.property.PropertyDescriptionList; +import org.cristalise.kernel.property.PropertyUtility; +import org.cristalise.kernel.utils.CastorHashMap; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.8 $ + **************************************************************************/ +public class AddNewSlot extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castor + **************************************************************************/ + public AddNewSlot() + { + super(); + } + + + /** + * Creates a new slot in the given aggregation, that holds instances of the given item description + * + * Params: + *
  1. Collection name
  2. + *
  3. Item Description key (optional)
  4. + *
  5. Item Description version (optional)
  6. + *
+ * + * @throws InvalidDataException Then the parameters were incorrect + * @throws PersistencyException There was a problem loading or saving the collection from persistency + * @throws ObjectNotFoundException A required object, such as the collection or a PropertyDescription outcome, wasn't found + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, PersistencyException, ObjectNotFoundException { + + String collName; + ItemPath descKey = null; + String descVer = "last"; + Aggregation agg; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AddNewSlot: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + // resolve desc item path and version + try { + collName = params[0]; + if (params.length > 1 && params[1].length() > 0) descKey = new ItemPath(params[1]); + if (params.length > 2 && params[2].length() > 0) descVer = params[2]; + } catch (Exception e) { + throw new InvalidDataException("AddNewSlot: Invalid parameters "+Arrays.toString(params)); + } + + // load collection + C2KLocalObject collObj; + try { + collObj = Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + } catch (PersistencyException ex) { + Logger.error(ex); + throw new PersistencyException("AddNewSlot: Error loading collection '\"+collName+\"': "+ex.getMessage()); + } + if (!(collObj instanceof Aggregation)) throw new InvalidDataException("AddNewSlot: AddNewSlot operates on Aggregation collections only."); + agg = (Aggregation)collObj; + + // get props + CastorHashMap props = new CastorHashMap(); + StringBuffer classProps = new StringBuffer(); + if (descKey != null) { + PropertyDescriptionList propList; + propList = PropertyUtility.getPropertyDescriptionOutcome(descKey, descVer); + for (PropertyDescription pd : propList.list) { + props.put(pd.getName(), pd.getDefaultValue()); + if (pd.getIsClassIdentifier()) + classProps.append((classProps.length()>0?",":"")).append(pd.getName()); + } + } + + agg.addSlot(props, classProps.toString()); + + try { + Gateway.getStorage().put(item, agg, null); + } catch (PersistencyException e) { + Logger.error(e); + throw new PersistencyException("AddNewSlot: Error saving collection '"+collName+"': "+e.getMessage()); + } + + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AssignItemToSlot.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AssignItemToSlot.java new file mode 100644 index 0000000..c242500 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/AssignItemToSlot.java @@ -0,0 +1,121 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.Aggregation; +import org.cristalise.kernel.collection.AggregationMember; +import org.cristalise.kernel.common.InvalidCollectionModification; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.C2KLocalObject; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.8 $ + **************************************************************************/ +public class AssignItemToSlot extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castor + **************************************************************************/ + public AssignItemToSlot() + { + super(); + } + + + /** + * Params: + * 0 - collection name + * 1 - slot number + * 2 - target entity key + * @throws ObjectNotFoundException + * @throws PersistencyException + * @throws ObjectCannotBeUpdated + * @throws InvalidCollectionModification + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectCannotBeUpdated, InvalidCollectionModification { + + String collName; + int slotNo; + ItemPath childItem; + Aggregation agg; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AssignItemToSlot: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + try { + collName = params[0]; + slotNo = Integer.parseInt(params[1]); + childItem = new ItemPath(params[2]); + } catch (Exception e) { + throw new InvalidDataException("AssignItemToSlot: Invalid parameters "+Arrays.toString(params)); + } + + // load collection + C2KLocalObject collObj; + try { + collObj = Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + } catch (PersistencyException ex) { + Logger.error(ex); + throw new PersistencyException("AssignItemToSlot: Error loading collection '\"+collName+\"': "+ex.getMessage()); + } + if (!(collObj instanceof Aggregation)) throw new InvalidDataException("AssignItemToSlot: AssignItemToSlot operates on Aggregation collections only."); + agg = (Aggregation)collObj; + + // find member and assign entity + boolean stored = false; + for (AggregationMember member : agg.getMembers().list) { + if (member.getID() == slotNo) { + if (member.getItemPath() != null) + throw new ObjectCannotBeUpdated("AssignItemToSlot: Member slot "+slotNo+" not empty"); + member.assignItem(childItem); + stored = true; + break; + } + } + if (!stored) { + throw new ObjectNotFoundException("AssignItemToSlot: Member slot "+slotNo+" not found."); + } + + try { + Gateway.getStorage().put(item, agg, null); + } catch (PersistencyException e) { + throw new PersistencyException("AssignItemToSlot: Error saving collection '"+collName+"': "+e.getMessage()); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ClearSlot.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ClearSlot.java new file mode 100644 index 0000000..bd0fa19 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ClearSlot.java @@ -0,0 +1,114 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.Aggregation; +import org.cristalise.kernel.collection.AggregationMember; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.8 $ + **************************************************************************/ +public class ClearSlot extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castor + **************************************************************************/ + public ClearSlot() + { + super(); + } + + + /** + * Params: + * 0 - collection name + * 1 - slot number + * @throws ObjectNotFoundException + * @throws PersistencyException + * @throws ObjectCannotBeUpdated + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectCannotBeUpdated { + + String collName; + int slotNo; + Aggregation agg; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "ClearSlot: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + try { + collName = params[0]; + slotNo = Integer.parseInt(params[1]); + } catch (Exception e) { + throw new InvalidDataException("ClearSlot: Invalid parameters "+Arrays.toString(params)); + } + + // load collection + try { + agg = (Aggregation)Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + } catch (PersistencyException ex) { + Logger.error(ex); + throw new PersistencyException("ClearSlot: Error loading collection '"+collName+"': "+ex.getMessage()); + } + + // find member and clear + boolean stored = false; + for (AggregationMember member : agg.getMembers().list) { + if (member.getID() == slotNo) { + if (member.getItemPath() != null) + throw new ObjectCannotBeUpdated("ClearSlot: Member slot "+slotNo+" already empty"); + member.clearItem(); + stored = true; + break; + } + } + if (!stored) { + throw new ObjectNotFoundException("ClearSlot: Member slot "+slotNo+" not found."); + } + + + try { + Gateway.getStorage().put(item, agg, null); + } catch (PersistencyException e) { + Logger.error(e); + throw new PersistencyException("ClearSlot: Error storing collection"); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/CreateNewCollectionVersion.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/CreateNewCollectionVersion.java new file mode 100644 index 0000000..a598044 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/CreateNewCollectionVersion.java @@ -0,0 +1,103 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.Collection; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.8 $ + **************************************************************************/ +public class CreateNewCollectionVersion extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castor + **************************************************************************/ + public CreateNewCollectionVersion() + { + super(); + } + + + /** + * Generates a new snapshot of a collection from its current state. The + * new version is given the next available number, starting at 0. + * + * Params: + * 0 - Collection name + * @throws InvalidDataException + * @throws PersistencyException + * + * @throws ObjectNotFoundException when there is no collection present with + * that name + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, PersistencyException, ObjectNotFoundException + { + String collName; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "CreateNewCollectionVersion: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) + throw new InvalidDataException("CreateNewCollectionVersion: Invalid parameters "+Arrays.toString(params)); + + collName = params[0]; + Collection coll = (Collection)Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + + // find last numbered version + int lastVer = -1; + String[] versions = Gateway.getStorage().getClusterContents(item, ClusterStorage.COLLECTION+"/"+collName); + for (String thisVerStr : versions) { + try { + int thisVer = Integer.parseInt(thisVerStr); + if (thisVer > lastVer) lastVer = thisVer; + } catch (NumberFormatException ex) { } // ignore non-integer versions + } + + // Remove it from the cache before we change it + Gateway.getStorage().clearCache(item, ClusterStorage.COLLECTION+"/"+collName+"/last"); + // Set the version + coll.setVersion(lastVer+1); + + // store it + try { + Gateway.getStorage().put(item, coll, null); + } catch (PersistencyException e) { + throw new PersistencyException("CreateNewCollectionVersion: Error saving new collection '"+collName+"': "+e.getMessage()); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/Import.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/Import.java new file mode 100644 index 0000000..26e015d --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/Import.java @@ -0,0 +1,106 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + +import java.util.Arrays; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.events.Event; +import org.cristalise.kernel.events.History; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.TransactionManager; +import org.cristalise.kernel.persistency.outcome.Outcome; +import org.cristalise.kernel.persistency.outcome.Viewpoint; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * $Revision: 1.21 $ + * $Date: 2005/06/02 12:17:22 $ + * + * Params: Schemaname_version:Viewpoint (optional), Outcome, Timestamp (optional + * + * Copyright (C) 2003 CERN - European Organization for Nuclear Research + * All rights reserved. + **************************************************************************/ +public class Import extends PredefinedStep +{ + public Import() + { + super(); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, PersistencyException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "Import: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + int split1 = params[0].indexOf('_'); + int split2 = params[0].indexOf(':'); + + if (split1 == -1) + throw new InvalidDataException("Import: Invalid parameters "+Arrays.toString(params)); + + requestData = params[1]; + + String schemaName = params[0].substring(0, split1); + String viewpoint = null; + int schemaVersion; + if (split2 > -1) { + schemaVersion = Integer.parseInt(params[0].substring(split1+1, split2)); + viewpoint = params[0].substring(split2+1); + } + else + schemaVersion = Integer.parseInt(params[0].substring(split1+1)); + + String timestamp; + if (params.length == 3) + timestamp = params[2]; + else + timestamp = Event.timeToString(Event.getGMT()); + + // write event, outcome and viewpoints to storage + + TransactionManager storage = Gateway.getStorage(); + Object locker = getWf(); + History hist = getWf().getHistory(); + Event event = hist.addEvent(agent, getCurrentAgentRole(), getName(), getPath(), getType(), schemaName, schemaVersion, getStateMachine().getName(), getStateMachine().getVersion(), getStateMachine().getTransition(transitionID), viewpoint, timestamp); + + try { + storage.put(item, new Outcome(event.getID(), requestData, schemaName, schemaVersion), locker); + storage.put(item, new Viewpoint(item, schemaName, viewpoint, schemaVersion, event.getID()), locker); + if (!"last".equals(viewpoint)) + storage.put(item, new Viewpoint(item, schemaName, "last", schemaVersion, event.getID()), locker); + } catch (PersistencyException e) { + storage.abort(locker); + throw e; + } + storage.commit(locker); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStep.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStep.java new file mode 100644 index 0000000..c8a293e --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStep.java @@ -0,0 +1,191 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; +import java.io.StringReader; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.cristalise.kernel.lifecycle.instance.Activity; +import org.cristalise.kernel.lifecycle.instance.predefined.agent.AgentPredefinedStepContainer; +import org.cristalise.kernel.lifecycle.instance.predefined.item.ItemPredefinedStepContainer; +import org.cristalise.kernel.lifecycle.instance.predefined.server.ServerPredefinedStepContainer; +import org.cristalise.kernel.persistency.outcome.Outcome; +import org.cristalise.kernel.utils.Logger; +import org.w3c.dom.CDATASection; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; +import org.xml.sax.InputSource; + +/*********************************************************************************************************************************************************************************************************************************************************************************************************** + * @author $Author: sgaspard $ $Date: 2004/09/21 10:32:17 $ + * @version $Revision: 1.14 $ + **********************************************************************************************************************************************************************************************************************************************************************************************************/ +public abstract class PredefinedStep extends Activity +{ + /******************************************************************************************************************************************************************************************************************************************************************************************************* + * predefined Steps are always Active, and have only one transition subclasses could override this method (if necessary) + ******************************************************************************************************************************************************************************************************************************************************************************************************/ + + private boolean isPredefined = false; + public static final int DONE = 0; + public static final int AVAILABLE = 0; + + public PredefinedStep() { + super(); + getProperties().put("SchemaType", "PredefinedStepOutcome"); + getProperties().put("SchemaVersion", "0"); + } + + @Override + public boolean getActive() + { + if (isPredefined) + return true; + else + return super.getActive(); + } + + + + @Override + protected String getDefaultSMName() { + return "PredefinedStep"; + } + + @Override + public String getErrors() + { + if (isPredefined) + return getName(); + else + return super.getErrors(); + } + @Override + public boolean verify() + { + if (isPredefined) + return true; + else + return super.verify(); + } + /** + * Returns the isPredefined. + * + * @return boolean + */ + public boolean getIsPredefined() + { + return isPredefined; + } + /** + * Sets the isPredefined. + * + * @param isPredefined + * The isPredefined to set + */ + public void setIsPredefined(boolean isPredefined) + { + this.isPredefined = isPredefined; + } + @Override + public String getType() + { + return getName(); + } + + static public String getPredefStepSchemaName(String stepName) { + PredefinedStepContainer[] allSteps = { new ItemPredefinedStepContainer(), new AgentPredefinedStepContainer(), new ServerPredefinedStepContainer() }; + for (PredefinedStepContainer thisContainer : allSteps) { + String stepPath = thisContainer.getName()+"/"+stepName; + Activity step = (Activity)thisContainer.search(stepPath); + if (step != null) { + return (String)step.getProperties().get("SchemaType"); + } + } + return "PredefinedStepOutcome"; // default to standard if not found - server may be a newer version + } + + // generic bundling of parameters + static public String bundleData(String[] data) + { + try + { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document dom = builder.newDocument(); + Element root = dom.createElement("PredefinedStepOutcome"); + dom.appendChild(root); + for (String element : data) { + Element param = dom.createElement("param"); + Text t = dom.createTextNode(element); + param.appendChild(t); + root.appendChild(param); + } + + return Outcome.serialize(dom, false); + + } + catch (Exception e) + { + Logger.error(e); + StringBuffer xmlData = new StringBuffer().append(""); + for (String element : data) + xmlData.append(""); + xmlData.append(""); + return xmlData.toString(); + } + } + + // generic bundling of single parameter + static public String bundleData(String data) + { + return bundleData(new String[]{ data }); + } + + public static String[] getDataList(String xmlData) + { + try + { + Document scriptDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xmlData))); + NodeList nodeList = scriptDoc.getElementsByTagName("param"); + String[] result = new String[nodeList.getLength()]; + for (int i = 0; i < nodeList.getLength(); i++) + { + Node n = nodeList.item(i).getFirstChild(); + if (n instanceof CDATASection) + result[i] = ((CDATASection) n).getData(); + else if (n instanceof Text) + result[i] = ((Text) n).getData(); + } + return result; + } + catch (Exception ex) + { + Logger.error("Exception::PredefinedStep::getDataList()"); + Logger.error(ex); + } + return null; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStepContainer.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStepContainer.java new file mode 100644 index 0000000..74a86db --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/PredefinedStepContainer.java @@ -0,0 +1,79 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; +import org.cristalise.kernel.graph.model.GraphPoint; +import org.cristalise.kernel.lifecycle.instance.CompositeActivity; +public abstract class PredefinedStepContainer extends CompositeActivity +{ + protected int num = 0; + + public PredefinedStepContainer() + { + super(); + setName("predefined"); + getProperties().put("Description", "Contains all predefined Steps"); + createChildren(); + } + public void createChildren() + { + predInit("AddDomainPath", "Adds a new path to this entity in the LDAP domain tree", new AddDomainPath()); + predInit("RemoveDomainPath", "Removes an existing path to this Entity from the LDAP domain tree", new RemoveDomainPath()); + predInit("ReplaceDomainWorkflow", "Replaces the domain CA with the supplied one. Used by the GUI to save new Wf layout", new ReplaceDomainWorkflow()); + predInit("AddC2KObject", "Adds or overwrites a C2Kernel object for this Item", new AddC2KObject()); + predInit("RemoveC2KObject", "Removes the named C2Kernel object from this Item.", new RemoveC2KObject()); + predInit("WriteProperty", "Writes a property to the Item", new WriteProperty()); + predInit("WriteViewpoint", "Writes a viewpoint to the Item", new WriteViewpoint()); + predInit("AddNewCollectionDescription", "Creates a new collection description in this Item", new AddNewCollectionDescription()); + predInit("CreateNewCollectionVersion", "Creates a new numbered collection version in this Item from the current one.", new CreateNewCollectionVersion()); + predInit("AddNewSlot", "Creates a new slot in the given aggregation, that holds instances of the item description of the given key", new AddNewSlot()); + predInit("AssignItemToSlot", "Assigns the referenced entity to a pre-existing slot in an aggregation", new AssignItemToSlot()); + predInit("ClearSlot", "Clears an aggregation member slot, given a slot no or entity key", new ClearSlot()); + predInit("RemoveSlotFromCollection", "Removed the given slot from the aggregation", new RemoveSlotFromCollection()); + predInit("AddMemberToCollection", "Creates a new member slot for the given item in a dependency, and assigns the item", new AddMemberToCollection()); + predInit("Import", "Imports an outcome into the Item, with a given schema and viewpoint", new Import()); + + } + + public void predInit(String alias, String Description, PredefinedStep act) + { + act.setName(alias); + act.setType(alias); + act.getProperties().put("Description", Description); + act.setCentrePoint(new GraphPoint()); + act.setIsPredefined(true); + addChild(act, new GraphPoint(100, 75 * ++num)); + } + @Override + public boolean verify() + { + return true; + } + @Override + public String getErrors() + { + return "predefined"; + } + @Override + public boolean getActive() + { + return true; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveC2KObject.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveC2KObject.java new file mode 100644 index 0000000..2f86274 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveC2KObject.java @@ -0,0 +1,70 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + + + +import java.util.Arrays; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2005/11/15 15:56:38 $ + * @version $Revision: 1.28 $ + **************************************************************************/ +public class RemoveC2KObject extends PredefinedStep +{ + public RemoveC2KObject() + { + super(); + getProperties().put("Agent Role", "Admin"); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, PersistencyException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "RemoveC2KObject: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) + throw new InvalidDataException("RemoveC2KObject: Invalid parameters "+Arrays.toString(params)); + String path = params[0]; + + try + { + Gateway.getStorage().remove( item, path, null ); + } + catch( PersistencyException ex ) + { + throw new PersistencyException("RemoveC2KObject: Error removing object '"+path+"': "+ex.getMessage()); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveDomainPath.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveDomainPath.java new file mode 100644 index 0000000..0dc24bb --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveDomainPath.java @@ -0,0 +1,73 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + + + + +import java.util.Arrays; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.lookup.LookupManager; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class RemoveDomainPath extends PredefinedStep +{ + public RemoveDomainPath() + { + super(); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "RemoveDomainPath: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidDataException("RemoveDomainPath: Invalid parameters "+Arrays.toString(params)); + + DomainPath domainPath = new DomainPath(params[0]); + if (!domainPath.exists()) + throw new ObjectNotFoundException("RemoveDomainPath: Domain path "+domainPath.toString()+" does not exist."); + + if (domainPath.getType()!=DomainPath.ENTITY) + + try { + if (!domainPath.getItemPath().equals(item)) + throw new InvalidDataException("RemoveDomainPath: Domain path "+domainPath.toString()+" is not an alias of the current Item "+item); + } catch (ObjectNotFoundException ex) { + throw new InvalidDataException("RemoveDomainPath: Domain path "+domainPath.toString()+" is a context."); + } + + LookupManager lookupManager = Gateway.getLookupManager(); + lookupManager.delete(domainPath); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java new file mode 100644 index 0000000..6522384 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/RemoveSlotFromCollection.java @@ -0,0 +1,131 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + + +import java.util.Arrays; + +import org.cristalise.kernel.collection.Collection; +import org.cristalise.kernel.collection.CollectionMember; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.8 $ + **************************************************************************/ +public class RemoveSlotFromCollection extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castor + **************************************************************************/ + public RemoveSlotFromCollection() + { + super(); + } + + + /** + * Params: + * 0 - collection name + * 1 - slot number OR if null: + * 2 - target entity key + * @throws ObjectNotFoundException + * @throws PersistencyException + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, PersistencyException { + + String collName; + int slotNo = -1; + ItemPath currentChild = null; + Collection coll; + + // extract parameters + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "RemoveSlotFromCollection: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + try { + collName = params[0]; + if (params.length>1 && params[1].length()>0) slotNo = Integer.parseInt(params[1]); + if (params.length>2 && params[2].length()>0) currentChild = new ItemPath(params[2]); + } catch (Exception e) { + throw new InvalidDataException("RemoveSlotFromCollection: Invalid parameters "+Arrays.toString(params)); + } + + if (slotNo == -1 && currentChild == null) + throw new InvalidDataException("RemoveSlotFromCollection: Must give either slot number or entity key"); + + // load collection + try { + coll = (Collection)Gateway.getStorage().get(item, ClusterStorage.COLLECTION+"/"+collName+"/last", null); + } catch (PersistencyException ex) { + Logger.error(ex); + throw new PersistencyException("RemoveSlotFromCollection: Error loading collection '\"+collName+\"': "+ex.getMessage()); + } + + // check the slot is there if it's given by id + CollectionMember slot = null; + if (slotNo > -1) { + slot = coll.getMember(slotNo); + } + + // if both parameters are supplied, check the given item is actually in that slot + if (slot != null && currentChild != null && !slot.getItemPath().equals(currentChild)) { + throw new ObjectNotFoundException("RemoveSlotFromCollection: Item "+currentChild+" was not in slot "+slotNo); + } + + if (slotNo == -1) { // find slot from entity key + for (CollectionMember member : coll.getMembers().list) { + if (member.getItemPath().equals(currentChild)) { + slotNo = member.getID(); + break; + } + } + } + if (slotNo == -1) { + throw new ObjectNotFoundException("Could not find "+currentChild+" in collection "+coll.getName()); + } + + // Remove the slot + coll.removeMember(slotNo); + + // Store the collection + try { + Gateway.getStorage().put(item, coll, null); + } catch (PersistencyException e) { + Logger.error(e); + throw new PersistencyException("Error storing collection"); + } + + return requestData; + + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java new file mode 100644 index 0000000..5ec7510 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/ReplaceDomainWorkflow.java @@ -0,0 +1,77 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + +//Java +import java.util.Arrays; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.graph.model.GraphPoint; +import org.cristalise.kernel.lifecycle.instance.CompositeActivity; +import org.cristalise.kernel.lifecycle.instance.Workflow; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class ReplaceDomainWorkflow extends PredefinedStep +{ + public ReplaceDomainWorkflow() + { + super(); + getProperties().put("Agent Role", "Admin"); + } + + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, PersistencyException { + + Workflow lifeCycle = getWf(); + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AddC2KObject: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidDataException("AddC2KObject: Invalid parameters "+Arrays.toString(params)); + + lifeCycle.getChildGraphModel().removeVertex(lifeCycle.search("workflow/domain")); + CompositeActivity domain; + try { + domain = (CompositeActivity) Gateway.getMarshaller().unmarshall(params[0]); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("ReplaceDomainWorkflow: Could not unmarshall new workflow: "+e.getMessage()); + } + domain.setName("domain"); + lifeCycle.initChild(domain, true, new GraphPoint(150, 100)); + // if new workflow, activate it, otherwise refresh the jobs + if (!domain.active) lifeCycle.run(agent, item); + else lifeCycle.refreshJobs(item); + + // store new wf + try { + Gateway.getStorage().put(item, lifeCycle, null); + } catch (PersistencyException e) { + throw new PersistencyException("ReplaceDomainWorkflow: Could not write new workflow to storage: "+e.getMessage()); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteProperty.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteProperty.java new file mode 100644 index 0000000..c73bec8 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteProperty.java @@ -0,0 +1,80 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + +import java.util.Arrays; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.property.Property; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2004/10/21 08:02:19 $ + * @version $Revision: 1.3 $ + **************************************************************************/ +public class WriteProperty extends PredefinedStep +{ + /************************************************************************** + * Constructor for Castror + **************************************************************************/ + public WriteProperty() + { + super(); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectCannotBeUpdated, ObjectNotFoundException, PersistencyException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "WriteProperty: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + if (params.length != 2) + throw new InvalidDataException("WriteProperty: invalid parameters "+Arrays.toString(params)); + + String name = params[0]; + String newValue = params[1]; + + Property prop; + + try { + prop = (Property)Gateway.getStorage().get(item, ClusterStorage.PROPERTY+"/"+name, null); + if (!prop.isMutable() && !newValue.equals(prop.getValue())) + throw new ObjectCannotBeUpdated("WriteProperty: Property '"+name+"' is not mutable."); + prop.setValue(newValue); + Gateway.getStorage().put(item, prop, null); + } catch (ObjectNotFoundException e) { + throw new ObjectNotFoundException("WriteProperty: Property '"+name+"' not found."); + } + + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteViewpoint.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteViewpoint.java new file mode 100644 index 0000000..d617b99 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/WriteViewpoint.java @@ -0,0 +1,88 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined; + +import java.util.Arrays; + +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.events.Event; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.persistency.outcome.Viewpoint; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class WriteViewpoint extends PredefinedStep { + + public WriteViewpoint() { + super(); + } + + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, PersistencyException { + + String schemaName; + String viewName; + int evId; + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "WriteViewpoint: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + + // outcometype, name and evId. Event and Outcome should be checked so schema version should be discovered. + if (params.length != 3) + throw new InvalidDataException("WriteViewpoint: Invalid parameters "+Arrays.toString(params)); + + schemaName = params[0]; + viewName = params[1]; + + try { + evId = Integer.parseInt(params[2]); + } catch (NumberFormatException ex) { + throw new InvalidDataException("WriteViewpoint: Parameter 3 (EventId) must be an integer"); + } + + // Find event + + Event ev; + try { + ev = (Event)Gateway.getStorage().get(item, ClusterStorage.HISTORY+"/"+evId, null); + } catch (PersistencyException e) { + Logger.error(e); + throw new PersistencyException("WriteViewpoint: Could not load event "+evId); + } + + // Write new viewpoint + Viewpoint newView = new Viewpoint(item, schemaName, viewName, ev.getSchemaVersion(), evId); + try { + Gateway.getStorage().put(item, newView, null); + } catch (PersistencyException e) { + Logger.error(e); + throw new PersistencyException("WriteViewpoint: Could not store new viewpoint"); + } + return requestData; + } + +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/AgentPredefinedStepContainer.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/AgentPredefinedStepContainer.java new file mode 100644 index 0000000..6ff3164 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/AgentPredefinedStepContainer.java @@ -0,0 +1,47 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined.agent; + +import org.cristalise.kernel.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 AgentPredefinedStepContainer extends PredefinedStepContainer { + + + @Override + public void createChildren() + { + super.createChildren(); + predInit("CreateAgentFromDescription", "Create a new item using this item as its description", new CreateAgentFromDescription()); + predInit("RemoveAgent", "Deletes the Agent", new RemoveAgent()); + predInit("SetAgentPassword", "Changes the Agent's password", new SetAgentPassword()); + predInit("SetAgentRoles", "Sets the roles of the Agent", new SetAgentRoles()); + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java new file mode 100644 index 0000000..335fe2d --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java @@ -0,0 +1,137 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined.agent; + +import java.util.Arrays; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.CorbaServer; +import org.cristalise.kernel.entity.agent.ActiveEntity; +import org.cristalise.kernel.lifecycle.instance.predefined.item.CreateItemFromDescription; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.lookup.RolePath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.property.PropertyArrayList; +import org.cristalise.kernel.utils.Logger; + + +/************************************************************************** + * + * @author $Author: abranson $ $Date: 2005/10/13 08:13:58 $ + * @version $Revision: 1.47 $ + **************************************************************************/ +public class CreateAgentFromDescription extends CreateItemFromDescription +{ + public CreateAgentFromDescription() + { + super(); + } + + /** + * Params: + *
  1. New Agent name
  2. + *
  3. Description version to use
  4. + *
  5. Comma-delimited Role names to assign to the agent. Must already exist.
  6. + *
  7. Initial properties to set in the new Agent
  8. + *
+ * @throws ObjectNotFoundException + * @throws InvalidDataException The input parameters were incorrect + * @throws ObjectAlreadyExistsException The Agent already exists + * @throws CannotManageException The Agent could not be created + * @throws ObjectCannotBeUpdated The addition of the new entries into the LookupManager failed + * @see org.cristalise.kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(org.cristalise.kernel.lookup.AgentPath, int, int, java.lang.String) + */ + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws ObjectNotFoundException, InvalidDataException, ObjectAlreadyExistsException, CannotManageException, ObjectCannotBeUpdated { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "CreateAgentFromDescription: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length < 3 || params.length > 4) + throw new InvalidDataException("CreateAgentFromDescription: Invalid parameters "+Arrays.toString(params)); + + String newName = params[0]; + String descVer = params[1]; + String roles = params[2]; + PropertyArrayList initProps = + params.length > 3 ? getInitProperties(params[3]):new PropertyArrayList(); + + Logger.msg(1, "CreateAgentFromDescription::request() - Starting."); + + // check if given roles exist + String[] roleArr = roles.split(","); + for(int i=0; i requestedRoles = new ArrayList(); + for (int i=0; i rolesToRemove = new ArrayList(); + for (RolePath existingRole : currentRoles) { // + if (requestedRoles.contains(existingRole)) // if we have it, and it's requested, then it will be kept + requestedRoles.remove(existingRole); // so remove it from request - this will be left with roles to be added + else + rolesToRemove.add(existingRole); // else this role will be removed + } + + // remove roles not in new list + for (RolePath roleToRemove : rolesToRemove) + try { + Gateway.getLookupManager().removeRole(targetAgent, roleToRemove); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("Error removing role "+roleToRemove.getName()); + } + + // add requested roles we don't already have + for (RolePath roleToAdd : requestedRoles) + try { + Gateway.getLookupManager().addRole(targetAgent, roleToAdd); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("Error adding role "+roleToAdd.getName()); + } + + return requestData; + } + +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java new file mode 100644 index 0000000..53e545e --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java @@ -0,0 +1,195 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined.item; + +import org.cristalise.kernel.collection.Collection; +import org.cristalise.kernel.collection.CollectionArrayList; +import org.cristalise.kernel.collection.CollectionDescription; +import org.cristalise.kernel.collection.CollectionMember; +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.entity.CorbaServer; +import org.cristalise.kernel.entity.TraceableEntity; +import org.cristalise.kernel.lifecycle.CompositeActivityDef; +import org.cristalise.kernel.lifecycle.instance.CompositeActivity; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.persistency.ClusterStorage; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.property.Property; +import org.cristalise.kernel.property.PropertyArrayList; +import org.cristalise.kernel.property.PropertyDescriptionList; +import org.cristalise.kernel.property.PropertyUtility; +import org.cristalise.kernel.utils.LocalObjectLoader; +import org.cristalise.kernel.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/org/cristalise/kernel/lifecycle/instance/predefined/item/Erase.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/Erase.java new file mode 100644 index 0000000..50a1bfd --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/Erase.java @@ -0,0 +1,80 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined.item; + + + +import java.util.Iterator; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.common.PersistencyException; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.lookup.Path; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.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/org/cristalise/kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java new file mode 100644 index 0000000..46a6feb --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java @@ -0,0 +1,45 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined.item; + +import org.cristalise.kernel.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()); + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/AddDomainContext.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/AddDomainContext.java new file mode 100644 index 0000000..b225978 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/AddDomainContext.java @@ -0,0 +1,67 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined.server; + +import java.util.Arrays; +import java.util.Stack; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class AddDomainContext extends PredefinedStep { + + public AddDomainContext() { + super(); + } + + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectCannotBeUpdated, ObjectAlreadyExistsException, CannotManageException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "AddDomainContext: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidDataException("AddDomainContext: Invalid parameters "+Arrays.toString(params)); + + DomainPath pathToAdd = new DomainPath(params); + if (pathToAdd.exists()) + throw new ObjectAlreadyExistsException("Context "+pathToAdd+" already exists"); + // collect parent paths if they don't exist + Stack pathsToAdd = new Stack(); + while(pathToAdd!= null && !pathToAdd.exists()) { + pathsToAdd.push(pathToAdd); + pathToAdd = pathToAdd.getParent(); + } + while(!pathsToAdd.empty()) { + pathToAdd = pathsToAdd.pop(); + Gateway.getLookupManager().add(pathToAdd); + } + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewAgent.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewAgent.java new file mode 100644 index 0000000..65e56b5 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewAgent.java @@ -0,0 +1,68 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined.server; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.entity.imports.ImportAgent; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class CreateNewAgent extends PredefinedStep +{ + public CreateNewAgent() + { + super(); + getProperties().put("SchemaType", "Agent"); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException { + + String redactedRequestData; + + ImportAgent newAgent; + try { + newAgent = (ImportAgent)Gateway.getMarshaller().unmarshall(requestData); + } catch (Exception e1) { + Logger.error(e1); + throw new InvalidDataException("CreateNewAgent: Couldn't unmarshall new Agent: "+requestData); + } + newAgent.create(agent, true); + newAgent.setPassword("REDACTED"); + try { + redactedRequestData = Gateway.getMarshaller().marshall(newAgent); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("CreateNewAgent: Couldn't marshall new Agent for outcome: "+newAgent); + } + return redactedRequestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewItem.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewItem.java new file mode 100644 index 0000000..acd1fd1 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewItem.java @@ -0,0 +1,63 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined.server; + + + + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidCollectionModification; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.entity.imports.ImportItem; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class CreateNewItem extends PredefinedStep +{ + public CreateNewItem() + { + super(); + getProperties().put("SchemaType", "Item"); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException, InvalidCollectionModification { + + ImportItem newItem; + try { + newItem = (ImportItem)Gateway.getMarshaller().unmarshall(requestData); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("CreateNewAgent: Couldn't unmarshall new Agent: "+requestData); + } + newItem.create(agent, false); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewRole.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewRole.java new file mode 100644 index 0000000..3771a7e --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/CreateNewRole.java @@ -0,0 +1,60 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined.server; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectAlreadyExistsException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.entity.imports.ImportRole; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class CreateNewRole extends PredefinedStep +{ + public CreateNewRole() + { + super(); + getProperties().put("SchemaType", "Role"); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, ObjectNotFoundException { + + + ImportRole newRole; + try { + newRole = (ImportRole)Gateway.getMarshaller().unmarshall(requestData); + } catch (Exception e) { + Logger.error(e); + throw new InvalidDataException("CreateNewAgent: Couldn't unmarshall new Agent: "+requestData); + } + newRole.create(agent, true); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java new file mode 100644 index 0000000..bc1ed5c --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java @@ -0,0 +1,65 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined.server; + +import java.util.Arrays; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.DomainPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class RemoveDomainContext extends PredefinedStep { + public RemoveDomainContext() { + super(); + } + + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "RemoveDomainContext: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidDataException("RemoveDomainContext: Invalid parameters "+Arrays.toString(params)); + + DomainPath pathToDelete = new DomainPath(params[0]); + if (!pathToDelete.exists()) + throw new ObjectNotFoundException("Context "+pathToDelete+" does not exist"); + + try { + pathToDelete.getItemPath(); + throw new InvalidDataException("Path "+pathToDelete+" is an Entity. Use its own Erase step instead, or RemoveAgent."); + } catch (ObjectNotFoundException ex) { } + + if (Gateway.getLookup().getChildren(pathToDelete).hasNext()) + throw new ObjectCannotBeUpdated("Context "+pathToDelete+" is not empty. Cannot delete."); + + Gateway.getLookupManager().delete(pathToDelete); + return requestData; + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveRole.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveRole.java new file mode 100644 index 0000000..6136cac --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/RemoveRole.java @@ -0,0 +1,68 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined.server; + +import java.util.Arrays; + +import org.cristalise.kernel.common.CannotManageException; +import org.cristalise.kernel.common.InvalidDataException; +import org.cristalise.kernel.common.ObjectCannotBeUpdated; +import org.cristalise.kernel.common.ObjectNotFoundException; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.lookup.AgentPath; +import org.cristalise.kernel.lookup.ItemPath; +import org.cristalise.kernel.lookup.LookupManager; +import org.cristalise.kernel.lookup.RolePath; +import org.cristalise.kernel.process.Gateway; +import org.cristalise.kernel.utils.Logger; + + +public class RemoveRole extends PredefinedStep +{ + public RemoveRole() + { + super(); + } + + //requestdata is xmlstring + @Override + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws InvalidDataException, CannotManageException, ObjectNotFoundException, ObjectCannotBeUpdated { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "RemoveRole: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length != 1) throw new InvalidDataException("RemoveRole: Invalid parameters "+Arrays.toString(params)); + + LookupManager lookup = Gateway.getLookupManager(); + + RolePath thisRole; AgentPath[] agents; + thisRole = lookup.getRolePath(params[0]); + agents = Gateway.getLookup().getAgents(thisRole); + + if (agents.length > 0) + throw new ObjectCannotBeUpdated("Cannot remove role. "+agents.length+" agents still hold it."); + + lookup.delete(thisRole); + + return requestData; + + } +} diff --git a/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/ServerPredefinedStepContainer.java b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/ServerPredefinedStepContainer.java new file mode 100644 index 0000000..0fdc34c --- /dev/null +++ b/src/main/java/org/cristalise/kernel/lifecycle/instance/predefined/server/ServerPredefinedStepContainer.java @@ -0,0 +1,62 @@ +/** + * 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 org.cristalise.kernel.lifecycle.instance.predefined.server; + +import org.cristalise.kernel.graph.model.GraphPoint; +import org.cristalise.kernel.lifecycle.instance.predefined.PredefinedStep; +import org.cristalise.kernel.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 ServerPredefinedStepContainer extends PredefinedStepContainer { + + + @Override + public void createChildren() + { + super.createChildren(); + serverPredInit("CreateNewItem", "Creates a new Item in this Server without description.", new CreateNewItem()); + serverPredInit("CreateNewAgent", "Creates a new Agent in this Server without description.", new CreateNewAgent()); + serverPredInit("CreateNewRole", "Creates a new Role in this Server.", new CreateNewRole()); + serverPredInit("RemoveRole", "Removes a Role from this Server.", new RemoveRole()); + serverPredInit("RemoveDomainContext", "Deletes an existing context in the domain tree, but only if empty", new RemoveDomainContext()); + serverPredInit("AddDomainContext", "Creates an empty domain context in the tree", new AddDomainContext()); + } + + public void serverPredInit(String alias, String Description, PredefinedStep act) + { + act.setName(alias); + act.setType(alias); + act.getProperties().put("Description", Description); + act.getProperties().put("Agent Role", "Admin"); + act.setCentrePoint(new GraphPoint()); + act.setIsPredefined(true); + addChild(act, new GraphPoint(100, 75 * ++num)); + } + +} -- cgit v1.2.3