summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java
diff options
context:
space:
mode:
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.java73
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, "");
- }
- }
}
}