diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2014-10-07 09:18:11 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2014-10-07 09:18:11 +0200 |
| commit | 0ed2c1124cf1b9e49a2ec1fa0126a8df09f9e758 (patch) | |
| tree | e3a56cee83865f8c703deb790c15d3e79e871a82 /src/main/java/org/cristalise/kernel/entity/imports | |
| parent | 50aa8aaab42fa62267aa1ae6a6070013096f5082 (diff) | |
Repackage to org.cristalise
Diffstat (limited to 'src/main/java/org/cristalise/kernel/entity/imports')
9 files changed, 870 insertions, 0 deletions
diff --git a/src/main/java/org/cristalise/kernel/entity/imports/Geometry.java b/src/main/java/org/cristalise/kernel/entity/imports/Geometry.java new file mode 100644 index 0000000..3680053 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/entity/imports/Geometry.java @@ -0,0 +1,48 @@ +/**
+ * 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.entity.imports;
+
+
+
+public class Geometry {
+
+
+ public int x;
+
+ public int y;
+
+ public int width;
+
+ public int height;
+
+ public Geometry() {
+ super();
+ }
+
+ public Geometry(int x, int y, int width, int height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+
+}
diff --git a/src/main/java/org/cristalise/kernel/entity/imports/ImportAgent.java b/src/main/java/org/cristalise/kernel/entity/imports/ImportAgent.java new file mode 100644 index 0000000..08c13d1 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/entity/imports/ImportAgent.java @@ -0,0 +1,118 @@ +/**
+ * 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.entity.imports;
+
+import java.util.ArrayList;
+
+import org.cristalise.kernel.common.CannotManageException;
+import org.cristalise.kernel.common.ObjectAlreadyExistsException;
+import org.cristalise.kernel.common.ObjectCannotBeUpdated;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.entity.agent.ActiveEntity;
+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.process.module.ModuleImport;
+import org.cristalise.kernel.property.Property;
+import org.cristalise.kernel.property.PropertyArrayList;
+import org.cristalise.kernel.utils.Logger;
+
+
+public class ImportAgent extends ModuleImport {
+
+ private String password;
+ private ArrayList<Property> properties = new ArrayList<Property>();
+ private ArrayList<String> roles = new ArrayList<String>();
+
+ public ImportAgent() {
+ }
+
+ public ImportAgent(String name, String password) {
+ this.name = name;
+ this.password = password;
+ }
+
+ @Override
+ public void create(AgentPath agentPath, boolean reset) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException {
+ AgentPath newAgent = new AgentPath(getItemPath(), name);
+ newAgent.setPassword(password);
+ ActiveEntity newAgentEnt = Gateway.getCorbaServer().createAgent(newAgent);
+ Gateway.getLookupManager().add(newAgent);
+ // assemble properties
+ properties.add(new Property("Name", name, true));
+ properties.add(new Property("Type", "Agent", false));
+ try {
+ newAgentEnt.initialise(agentPath.getSystemKey(), Gateway.getMarshaller().marshall(new PropertyArrayList(properties)), null, null);
+ } catch (Exception ex) {
+ Logger.error(ex);
+ throw new CannotManageException("Error initialising new agent");
+ }
+ for (String role : roles) {
+ RolePath thisRole;
+ try {
+ thisRole = Gateway.getLookup().getRolePath(role);
+ } catch (ObjectNotFoundException ex) {
+ throw new ObjectNotFoundException("Role "+role+" does not exist.");
+ }
+ Gateway.getLookupManager().addRole(newAgent, thisRole);
+ }
+
+ }
+
+ @Override
+ public ItemPath getItemPath() {
+ if (itemPath == null) { // try to find agent if it already exists
+ try {
+ AgentPath existAgent = Gateway.getLookup().getAgentPath(name);
+ itemPath = existAgent;
+ } catch (ObjectNotFoundException ex) {
+ itemPath = new AgentPath(new ItemPath(), name);
+ }
+ }
+ return itemPath;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public ArrayList<String> getRoles() {
+ return roles;
+ }
+
+ public void setRoles(ArrayList<String> roles) {
+ this.roles = roles;
+ }
+
+ public ArrayList<Property> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(ArrayList<Property> properties) {
+ this.properties = properties;
+ }
+
+}
diff --git a/src/main/java/org/cristalise/kernel/entity/imports/ImportAggregation.java b/src/main/java/org/cristalise/kernel/entity/imports/ImportAggregation.java new file mode 100644 index 0000000..22a9b78 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/entity/imports/ImportAggregation.java @@ -0,0 +1,91 @@ +/**
+ * 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.entity.imports;
+
+import java.util.ArrayList;
+
+import org.cristalise.kernel.collection.Aggregation;
+import org.cristalise.kernel.collection.AggregationDescription;
+import org.cristalise.kernel.collection.AggregationInstance;
+import org.cristalise.kernel.common.InvalidCollectionModification;
+import org.cristalise.kernel.common.ObjectAlreadyExistsException;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.graph.model.GraphPoint;
+import org.cristalise.kernel.lookup.DomainPath;
+import org.cristalise.kernel.lookup.InvalidItemPathException;
+import org.cristalise.kernel.lookup.ItemPath;
+import org.cristalise.kernel.property.PropertyDescription;
+import org.cristalise.kernel.property.PropertyDescriptionList;
+import org.cristalise.kernel.property.PropertyUtility;
+
+
+public class ImportAggregation {
+
+ public boolean isDescription;
+ public Integer version;
+ public ArrayList<ImportAggregationMember> aggregationMemberList = new ArrayList<ImportAggregationMember>();
+ public String name;
+
+ public ImportAggregation() {
+ super();
+ }
+
+ public ImportAggregation(String name, boolean isDescription) {
+ this();
+ this.name = name;
+ this.isDescription = isDescription;
+ }
+
+ public org.cristalise.kernel.collection.Aggregation create() throws InvalidCollectionModification, ObjectNotFoundException, ObjectAlreadyExistsException {
+ Aggregation newAgg = isDescription?new AggregationDescription(name):new AggregationInstance(name);
+ if (version!= null) newAgg.setVersion(version);
+ for (ImportAggregationMember thisMem : aggregationMemberList) {
+ StringBuffer classProps = new StringBuffer();
+ if (thisMem.itemDescriptionPath != null && thisMem.itemDescriptionPath.length()>0) {
+ ItemPath itemPath;
+ try {
+ itemPath = new ItemPath(thisMem.itemDescriptionPath);
+ } catch (InvalidItemPathException ex) {
+ itemPath = new DomainPath(thisMem.itemDescriptionPath).getItemPath();
+ }
+
+ String descVer = thisMem.itemDescriptionVersion==null?"last":thisMem.itemDescriptionVersion;
+ PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer);
+ for (PropertyDescription pd : propList.list) {
+ thisMem.props.put(pd.getName(), pd.getDefaultValue());
+ if (pd.getIsClassIdentifier())
+ classProps.append((classProps.length()>0?",":"")).append(pd.getName());
+ }
+ }
+ ItemPath itemPath = null;
+ if (thisMem.itemPath != null && thisMem.itemPath.length()>0) {
+
+ try {
+ itemPath = new ItemPath(thisMem.itemPath);
+ } catch (InvalidItemPathException ex) {
+ itemPath = new DomainPath(thisMem.itemPath).getItemPath();
+ }
+ }
+ newAgg.addMember(itemPath, thisMem.props, classProps.toString(), new GraphPoint(thisMem.geometry.x, thisMem.geometry.y), thisMem.geometry.width, thisMem.geometry.height);
+ }
+ return newAgg;
+ }
+}
diff --git a/src/main/java/org/cristalise/kernel/entity/imports/ImportAggregationMember.java b/src/main/java/org/cristalise/kernel/entity/imports/ImportAggregationMember.java new file mode 100644 index 0000000..53b74b8 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/entity/imports/ImportAggregationMember.java @@ -0,0 +1,55 @@ +/**
+ * 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.entity.imports;
+
+import org.cristalise.kernel.utils.CastorHashMap;
+import org.cristalise.kernel.utils.KeyValuePair;
+
+public class ImportAggregationMember {
+
+ public int slotNo;
+ public String itemDescriptionPath;
+ public String itemDescriptionVersion = null;
+ public String itemPath;
+ public Geometry geometry;
+ public CastorHashMap props = new CastorHashMap();
+
+
+ public ImportAggregationMember() {
+ super();
+ }
+
+ public ImportAggregationMember(int slotNo, String itemDescPath, String itemDescVersion, String itemPath, Geometry geometry) {
+ this.slotNo = slotNo;
+ this.itemDescriptionPath = itemDescPath;
+ this.itemDescriptionVersion = itemDescVersion;
+ this.itemPath = itemPath;
+ this.geometry = geometry;
+ }
+
+ public KeyValuePair[] getKeyValuePairs() {
+ return props.getKeyValuePairs();
+ }
+
+ public void setKeyValuePairs(KeyValuePair[] pairs) {
+ props.setKeyValuePairs(pairs);
+ }
+}
diff --git a/src/main/java/org/cristalise/kernel/entity/imports/ImportDependency.java b/src/main/java/org/cristalise/kernel/entity/imports/ImportDependency.java new file mode 100644 index 0000000..f94cab0 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/entity/imports/ImportDependency.java @@ -0,0 +1,107 @@ +/**
+ * 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.entity.imports;
+
+import java.util.ArrayList;
+
+import org.cristalise.kernel.collection.Dependency;
+import org.cristalise.kernel.collection.DependencyDescription;
+import org.cristalise.kernel.common.InvalidCollectionModification;
+import org.cristalise.kernel.common.ObjectAlreadyExistsException;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.lookup.DomainPath;
+import org.cristalise.kernel.lookup.InvalidItemPathException;
+import org.cristalise.kernel.lookup.ItemPath;
+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.KeyValuePair;
+
+
+public class ImportDependency {
+
+ public String name;
+ public Integer version;
+ public boolean isDescription;
+ public String itemDescriptionPath;
+ public String itemDescriptionVersion = null;
+ public ArrayList<ImportDependencyMember> dependencyMemberList = new ArrayList<ImportDependencyMember>();
+ public CastorHashMap props = new CastorHashMap();
+
+ public ImportDependency() {
+ super();
+ }
+
+ public ImportDependency(String name) {
+ this();
+ this.name = name;
+ }
+
+ public KeyValuePair[] getKeyValuePairs() {
+ return props.getKeyValuePairs();
+ }
+
+ public void setKeyValuePairs(KeyValuePair[] pairs) {
+ props.setKeyValuePairs(pairs);
+ }
+
+ /**
+ * @return
+ * @throws ObjectAlreadyExistsException
+ */
+ public org.cristalise.kernel.collection.Dependency create() throws InvalidCollectionModification, ObjectNotFoundException, ObjectAlreadyExistsException {
+ Dependency newDep = isDescription?new DependencyDescription(name):new Dependency(name);
+ if (version!= null) newDep.setVersion(version);
+ if (itemDescriptionPath != null && itemDescriptionPath.length()>0) {
+ ItemPath itemPath;
+ try {
+ itemPath = new ItemPath(itemDescriptionPath);
+ } catch (InvalidItemPathException ex) {
+ itemPath = new DomainPath(itemDescriptionPath).getItemPath();
+ }
+ String descVer = itemDescriptionVersion==null?"last":itemDescriptionVersion;
+ PropertyDescriptionList propList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer);
+ StringBuffer classProps = new StringBuffer();
+ for (PropertyDescription pd : propList.list) {
+ props.put(pd.getName(), pd.getDefaultValue());
+ if (pd.getIsClassIdentifier())
+ classProps.append((classProps.length()>0?",":"")).append(pd.getName());
+ }
+ newDep.setProperties(props);
+ newDep.setClassProps(classProps.toString());
+ }
+
+ for (ImportDependencyMember thisMem : dependencyMemberList) {
+ ItemPath itemPath;
+ try {
+ itemPath = new ItemPath(thisMem.itemPath);
+ } catch (InvalidItemPathException ex) {
+ itemPath = new DomainPath(thisMem.itemPath).getItemPath();
+ }
+
+ org.cristalise.kernel.collection.DependencyMember newDepMem = newDep.addMember(itemPath);
+ newDepMem.getProperties().putAll(thisMem.props);
+ }
+ return newDep;
+ }
+
+}
diff --git a/src/main/java/org/cristalise/kernel/entity/imports/ImportDependencyMember.java b/src/main/java/org/cristalise/kernel/entity/imports/ImportDependencyMember.java new file mode 100644 index 0000000..5a5d6cd --- /dev/null +++ b/src/main/java/org/cristalise/kernel/entity/imports/ImportDependencyMember.java @@ -0,0 +1,48 @@ +/**
+ * 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.entity.imports;
+
+import org.cristalise.kernel.utils.CastorHashMap;
+import org.cristalise.kernel.utils.KeyValuePair;
+
+public class ImportDependencyMember {
+
+
+ public String itemPath;
+ public CastorHashMap props = new CastorHashMap();
+
+ public ImportDependencyMember() {
+ super();
+ }
+
+ public ImportDependencyMember(String itemPath) {
+ this.itemPath = itemPath;
+
+ }
+
+ public KeyValuePair[] getKeyValuePairs() {
+ return props.getKeyValuePairs();
+ }
+
+ public void setKeyValuePairs(KeyValuePair[] pairs) {
+ props.setKeyValuePairs(pairs);
+ }
+}
diff --git a/src/main/java/org/cristalise/kernel/entity/imports/ImportItem.java b/src/main/java/org/cristalise/kernel/entity/imports/ImportItem.java new file mode 100644 index 0000000..2a259bd --- /dev/null +++ b/src/main/java/org/cristalise/kernel/entity/imports/ImportItem.java @@ -0,0 +1,280 @@ +/**
+ * 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.entity.imports;
+
+
+import java.util.ArrayList;
+
+import org.cristalise.kernel.collection.Aggregation;
+import org.cristalise.kernel.collection.CollectionArrayList;
+import org.cristalise.kernel.collection.Dependency;
+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.common.PersistencyException;
+import org.cristalise.kernel.entity.TraceableEntity;
+import org.cristalise.kernel.events.Event;
+import org.cristalise.kernel.events.History;
+import org.cristalise.kernel.lifecycle.CompositeActivityDef;
+import org.cristalise.kernel.lifecycle.instance.stateMachine.Transition;
+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.persistency.outcome.Outcome;
+import org.cristalise.kernel.persistency.outcome.Viewpoint;
+import org.cristalise.kernel.process.Gateway;
+import org.cristalise.kernel.process.module.ModuleImport;
+import org.cristalise.kernel.property.Property;
+import org.cristalise.kernel.property.PropertyArrayList;
+import org.cristalise.kernel.utils.LocalObjectLoader;
+import org.cristalise.kernel.utils.Logger;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
+
+
+/**
+ * Complete Structure for new item
+ *
+ * @version $Revision: 1.8 $ $Date: 2006/03/03 13:52:21 $
+ */
+
+public class ImportItem extends ModuleImport {
+
+ protected String initialPath;
+ protected String workflow;
+ protected Integer workflowVer;
+ protected ArrayList<Property> properties = new ArrayList<Property>();
+ protected ArrayList<ImportAggregation> aggregationList = new ArrayList<ImportAggregation>();
+ protected ArrayList<ImportDependency> dependencyList = new ArrayList<ImportDependency>();
+ protected ArrayList<ImportOutcome> outcomes = new ArrayList<ImportOutcome>();
+
+ public ImportItem() {
+ }
+
+ public ImportItem(String ns, String name, String initialPath, ItemPath itemPath, String wf, int wfVer) {
+ this();
+ setNamespace(ns);
+ setName(name);
+ setItemPath(itemPath);
+ setInitialPath(initialPath);
+ setWorkflow(wf);
+ setWorkflowVer(wfVer);
+ }
+
+ @Override
+ public ItemPath getItemPath() {
+ if (itemPath == null) { // try to find item if it already exists
+ DomainPath existingItem = new DomainPath(initialPath+"/"+name);
+ if (existingItem.exists()) {
+ try {
+ itemPath = existingItem.getItemPath();
+ } catch (ObjectNotFoundException ex) { }
+ }
+ }
+ if (itemPath == null) itemPath = new ItemPath();
+ return itemPath;
+ }
+
+ @Override
+ public void setNamespace(String ns) {
+ super.setNamespace(ns);
+ if (initialPath == null) initialPath = "/desc/"+ns;
+ }
+
+ @Override
+ public void setName(String name) {
+ super.setName(name);
+ }
+
+ @Override
+ public void create(AgentPath agentPath, boolean reset) throws ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException, InvalidCollectionModification {
+ DomainPath domPath = new DomainPath(new DomainPath(initialPath), name);
+ if (domPath.exists()) {
+ ItemPath domItem = domPath.getItemPath();
+ if (!getItemPath().equals(domItem))
+ throw new CannotManageException("Item "+domPath+" was found with the wrong itemPath ("+domPath.getItemPath()+" vs "+getItemPath()+")");
+ }
+
+ TraceableEntity newItem;
+ if (getItemPath().exists()) {
+ Logger.msg(1, "ImportItem.create() - Verifying module item "+getItemPath()+" at "+domPath);
+ newItem = Gateway.getCorbaServer().getItem(getItemPath());
+ }
+ else {
+ Logger.msg(1, "ImportItem.create() - Creating module item "+getItemPath()+" at "+domPath);
+ newItem = Gateway.getCorbaServer().createItem(getItemPath());
+ Gateway.getLookupManager().add(getItemPath());
+ }
+
+ // set the name property
+ properties.add(new Property("Name", name, true));
+
+ // find workflow def
+ CompositeActivityDef compact;
+ // default workflow version is 0 if not given
+ int usedWfVer;
+ if (workflowVer == null) usedWfVer = 0;
+ else usedWfVer = workflowVer.intValue();
+ try {
+ compact = (CompositeActivityDef)LocalObjectLoader.getActDef(workflow, usedWfVer);
+ } catch (ObjectNotFoundException ex) {
+ throw new CannotManageException("Could not find workflow "+workflow+"v"+usedWfVer+" for item "+domPath);
+ } catch (InvalidDataException e) {
+ throw new CannotManageException("Workflow def "+workflow+" v"+usedWfVer+" for item "+domPath+" was not valid");
+ }
+
+ // create collections
+ CollectionArrayList colls = new CollectionArrayList();
+ for (ImportDependency element: dependencyList) {
+ Dependency newDep = element.create();
+ colls.put(newDep);
+ }
+
+ for (ImportAggregation element : aggregationList) {
+ Aggregation newAgg = element.create();
+ colls.put(newAgg);
+ }
+
+ // (re)initialise the new item with properties, workflow and collections
+ try {
+ newItem.initialise(
+ agentPath.getSystemKey(),
+ Gateway.getMarshaller().marshall(new PropertyArrayList(properties)),
+ Gateway.getMarshaller().marshall(compact.instantiate()),
+ Gateway.getMarshaller().marshall(colls));
+ } catch (Exception ex) {
+ Logger.error("Error initialising new item "+name );
+ Logger.error(ex);
+ throw new CannotManageException("Problem initialising new item. See server log.");
+ }
+
+ // import outcomes
+ XMLUnit.setIgnoreWhitespace(true);
+ XMLUnit.setIgnoreComments(true);
+ History hist = new History(getItemPath(), null);
+ for (ImportOutcome thisOutcome : outcomes) {
+ Outcome newOutcome = new Outcome(-1, thisOutcome.getData(ns), thisOutcome.schema, thisOutcome.version);
+ Viewpoint impView;
+ try {
+ impView = (Viewpoint)Gateway.getStorage().get(getItemPath(), ClusterStorage.VIEWPOINT+"/"+thisOutcome.schema+"/"+thisOutcome.viewname, null);
+
+ Diff xmlDiff = new Diff(newOutcome.getDOM(), impView.getOutcome().getDOM());
+ if (xmlDiff.identical()) {
+ Logger.msg(5, "NewItem.create() - View "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name+" identical, no update required");
+ continue;
+ }
+ else {
+ Logger.msg("NewItem.create() - Difference found in view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name+": "+xmlDiff.toString());
+ if (!reset && !impView.getEvent().getStepPath().equals("Import")) {
+ Logger.msg("Last edit was not done by import, and reset not requested. Not overwriting.");
+ continue;
+ }
+ }
+ } catch (ObjectNotFoundException ex) {
+ Logger.msg(3, "View "+thisOutcome.schema+"/"+thisOutcome.viewname+" not found in "+name+". Creating.");
+ impView = new Viewpoint(getItemPath(), thisOutcome.schema, thisOutcome.viewname, thisOutcome.version, -1);
+ } catch (PersistencyException e) {
+ throw new ObjectCannotBeUpdated("Could not check data for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name);
+ } catch (InvalidDataException e) {
+ throw new ObjectCannotBeUpdated("Could not check previous event for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name);
+ }
+
+ // write new view/outcome/event
+ Transition predefDone = new Transition(0, "Done", 0, 0);
+ Event newEvent = hist.addEvent(agentPath, "Admin", "Import", "Import", "Import", thisOutcome.schema, thisOutcome.version, "PredefinedStep", 0, predefDone, thisOutcome.viewname);
+ newOutcome.setID(newEvent.getID());
+ impView.setEventId(newEvent.getID());
+ try {
+ Gateway.getStorage().put(getItemPath(), newOutcome, null);
+ Gateway.getStorage().put(getItemPath(), impView, null);
+ } catch (PersistencyException e) {
+ throw new ObjectCannotBeUpdated("Could not store data for view "+thisOutcome.schema+"/"+thisOutcome.viewname+" in "+name);
+ }
+ }
+
+ // register domain path (before collections in case of recursive collections)
+ if (!domPath.exists()) {
+ domPath.setItemPath(getItemPath());
+ Gateway.getLookupManager().add(domPath);
+ }
+ }
+
+ public String getInitialPath() {
+ return initialPath;
+ }
+
+ public void setInitialPath(String initialPath) {
+ this.initialPath = initialPath;
+ }
+
+ public String getWorkflow() {
+ return workflow;
+ }
+
+ public void setWorkflow(String workflow) {
+ this.workflow = workflow;
+ }
+
+ public Integer getWorkflowVer() {
+ return workflowVer;
+ }
+
+ public void setWorkflowVer(Integer workflowVer) {
+ this.workflowVer = workflowVer;
+ }
+
+ public ArrayList<Property> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(ArrayList<Property> properties) {
+ this.properties = properties;
+ }
+
+ public ArrayList<ImportAggregation> getAggregationList() {
+ return aggregationList;
+ }
+
+ public void setAggregationList(ArrayList<ImportAggregation> aggregationList) {
+ this.aggregationList = aggregationList;
+ }
+
+ public ArrayList<ImportDependency> getDependencyList() {
+ return dependencyList;
+ }
+
+ public void setDependencyList(ArrayList<ImportDependency> dependencyList) {
+ this.dependencyList = dependencyList;
+ }
+
+ public ArrayList<ImportOutcome> getOutcomes() {
+ return outcomes;
+ }
+
+ public void setOutcomes(ArrayList<ImportOutcome> outcomes) {
+ this.outcomes = outcomes;
+ }
+
+}
diff --git a/src/main/java/org/cristalise/kernel/entity/imports/ImportOutcome.java b/src/main/java/org/cristalise/kernel/entity/imports/ImportOutcome.java new file mode 100644 index 0000000..b3be323 --- /dev/null +++ b/src/main/java/org/cristalise/kernel/entity/imports/ImportOutcome.java @@ -0,0 +1,48 @@ +/**
+ * 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.entity.imports;
+
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.process.Gateway;
+
+
+public class ImportOutcome {
+ public String schema, viewname, path, data;
+ public int version;
+
+ public ImportOutcome() {
+ }
+
+ public ImportOutcome(String schema, int version, String viewname, String path) {
+ super();
+ this.schema = schema;
+ this.version = version;
+ this.viewname = viewname;
+ this.path = path;
+ }
+
+ public String getData(String ns) throws ObjectNotFoundException {
+ if (data == null)
+ data = Gateway.getResource().getTextResource(ns, path);
+ return data;
+ }
+
+}
diff --git a/src/main/java/org/cristalise/kernel/entity/imports/ImportRole.java b/src/main/java/org/cristalise/kernel/entity/imports/ImportRole.java new file mode 100644 index 0000000..daf1b4c --- /dev/null +++ b/src/main/java/org/cristalise/kernel/entity/imports/ImportRole.java @@ -0,0 +1,75 @@ +/**
+ * 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.entity.imports;
+
+import java.util.Iterator;
+
+import org.cristalise.kernel.common.CannotManageException;
+import org.cristalise.kernel.common.ObjectAlreadyExistsException;
+import org.cristalise.kernel.common.ObjectCannotBeUpdated;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.lookup.AgentPath;
+import org.cristalise.kernel.lookup.Path;
+import org.cristalise.kernel.lookup.RolePath;
+import org.cristalise.kernel.process.Gateway;
+import org.cristalise.kernel.process.module.ModuleImport;
+
+
+public class ImportRole extends ModuleImport {
+
+ private boolean jobList;
+
+ public ImportRole() {
+ }
+
+ @Override
+ public void create(AgentPath agentPath, boolean reset) throws ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, ObjectNotFoundException {
+ RolePath parent = new RolePath();
+ if (name.indexOf('/') > -1) {
+ String[] roleComp = name.split("/");
+ for (int i=0; i<roleComp.length-1; i++) {
+ Iterator<Path> childIter = parent.getChildren();
+ boolean found = false;
+ while (childIter.hasNext()) {
+ RolePath childRole = (RolePath)childIter.next();
+ if (childRole.getName().equals(roleComp[i])) {
+ parent = childRole;
+ found = true;
+ break;
+ }
+ }
+ if (!found) throw new ObjectNotFoundException("Parent role "+roleComp[i]+" was not found");
+ }
+ name = roleComp[roleComp.length-1];
+ }
+ RolePath newRole = new RolePath(parent, name, jobList);
+ if (!newRole.exists()) Gateway.getLookupManager().createRole(newRole);
+ }
+
+ public boolean hasJobList() {
+ return jobList;
+ }
+
+ public void setJobList(boolean jobList) {
+ this.jobList = jobList;
+ }
+
+}
|
