diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2014-05-07 17:33:13 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2014-05-08 16:37:39 +0200 |
| commit | a1f0ecbb6a2bea6aa214322c412af2f3c5ce124b (patch) | |
| tree | 4d74229b6dd9cfd7ce054e06bf740b9a63a578d6 /src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java | |
| parent | 6dfa1bbe05a712174e937af89d5223e98d9d7d06 (diff) | |
Agent now extends Item, so they can have workflows. All traces of the
old 'Entity' superclasses should be removed, including proxies and
paths. Very large change, breaks API compatibility with CRISTAL 2.x.
Fixes #135
Diffstat (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java')
| -rw-r--r-- | src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java | 73 |
1 files changed, 28 insertions, 45 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java index 588b2fc..52a214e 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
+import com.c2kernel.collection.CollectionArrayList;
import com.c2kernel.collection.MembershipException;
import com.c2kernel.common.CannotManageException;
import com.c2kernel.common.InvalidDataException;
@@ -18,7 +19,7 @@ import com.c2kernel.events.History; import com.c2kernel.lifecycle.CompositeActivityDef;
import com.c2kernel.lifecycle.instance.stateMachine.Transition;
import com.c2kernel.lookup.DomainPath;
-import com.c2kernel.lookup.EntityPath;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.outcome.Viewpoint;
@@ -69,7 +70,7 @@ public class NewItem extends ModuleImport { public void create(int agentId, boolean reset) throws ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException {
DomainPath domPath = new DomainPath(new DomainPath(initialPath), name);
- EntityPath entPath; TraceableEntity newItem;
+ ItemPath entPath; TraceableEntity newItem;
if (domPath.exists()) {
entPath = domPath.getEntity();
newItem = Gateway.getCorbaServer().getItem(entPath.getSysKey());
@@ -98,12 +99,35 @@ public class NewItem extends ModuleImport { throw new CannotManageException("Workflow def "+workflow+" v"+usedWfVer+" for item "+domPath+" was not valid", "");
}
+ // create collections
+ CollectionArrayList colls = new CollectionArrayList();
+ for (Dependency element: dependencyList) {
+ try {
+ com.c2kernel.collection.Dependency newDep = element.create();
+ colls.put(newDep);
+ } catch (MembershipException ex) {
+ Logger.error(ex);
+ throw new CannotManageException("A specified member is not of the correct type in "+element.name, "");
+ }
+ }
+
+ for (Aggregation element : aggregationList) {
+ try {
+ com.c2kernel.collection.Aggregation newAgg = element.create();
+ colls.put(newAgg);
+ } catch (MembershipException ex) {
+ Logger.error(ex);
+ throw new CannotManageException("A specified member is not of the correct type in "+element.name, "");
+ }
+ }
+
+ // (re)initialise the new item with properties, workflow and collections
try {
- // initialise the new item with workflow and properties
newItem.initialise(
agentId,
Gateway.getMarshaller().marshall(new PropertyArrayList(properties)),
- Gateway.getMarshaller().marshall(compact.instantiate()));
+ Gateway.getMarshaller().marshall(compact.instantiate()),
+ Gateway.getMarshaller().marshall(colls));
} catch (Exception ex) {
Logger.error("Error initialising new item "+name );
Logger.error(ex);
@@ -159,46 +183,5 @@ public class NewItem extends ModuleImport { domPath.setEntity(entPath);
Gateway.getLDAPLookup().add(domPath);
}
-
- // create collections
- for (Dependency element: dependencyList) {
- try {
- com.c2kernel.collection.Dependency newDep = element.create();
- if (!reset) {
- try {
- Gateway.getStorage().get(entPath.getSysKey(), ClusterStorage.COLLECTION+"/"+newDep.getName(), null);
- Logger.msg("Not overwriting dependency "+newDep.getName());
- continue; // TODO: a proper compare here
- } catch (ObjectNotFoundException ex) { } // doesn't exist, ok to create
- }
- Gateway.getStorage().put(entPath.getSysKey(), element.create(), null);
- } catch (ClusterStorageException ex) {
- Logger.error(ex);
- throw new CannotManageException("Could not create Dependency "+element.name, "");
- } catch (MembershipException ex) {
- Logger.error(ex);
- throw new CannotManageException("A specified member is not of the correct type in "+element.name, "");
- }
- }
-
- for (Aggregation element : aggregationList) {
- try {
- com.c2kernel.collection.Aggregation newAgg = element.create();
- if (!reset) {
- try {
- Gateway.getStorage().get(entPath.getSysKey(), ClusterStorage.COLLECTION+"/"+newAgg.getName(), null);
- Logger.msg("Not overwriting aggregation "+newAgg.getName());
- continue; // TODO: a proper compare here
- } catch (ObjectNotFoundException ex) { } // doesn't exist, ok to create
- }
- Gateway.getStorage().put(entPath.getSysKey(), newAgg, null);
- } catch (ClusterStorageException ex) {
- Logger.error(ex);
- throw new CannotManageException("Could not create Aggregation "+element.name, "");
- } catch (MembershipException ex) {
- Logger.error(ex);
- throw new CannotManageException("A specified member is not of the correct type in "+element.name, "");
- }
- }
}
}
|
