From 10863522fb3f015dd06478c56365f1a18dcb250a Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 1 Oct 2014 21:02:35 +0200 Subject: Store event on Item.initialize(), containing the initial properties of the new Item. --- .../com/c2kernel/entity/ItemImplementation.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/main/java') diff --git a/src/main/java/com/c2kernel/entity/ItemImplementation.java b/src/main/java/com/c2kernel/entity/ItemImplementation.java index 0346480..814ce1e 100644 --- a/src/main/java/com/c2kernel/entity/ItemImplementation.java +++ b/src/main/java/com/c2kernel/entity/ItemImplementation.java @@ -12,16 +12,21 @@ import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.common.PersistencyException; import com.c2kernel.common.SystemKey; import com.c2kernel.entity.agent.JobArrayList; +import com.c2kernel.events.Event; +import com.c2kernel.events.History; import com.c2kernel.lifecycle.instance.CompositeActivity; import com.c2kernel.lifecycle.instance.Workflow; import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer; import com.c2kernel.lifecycle.instance.predefined.item.ItemPredefinedStepContainer; +import com.c2kernel.lifecycle.instance.stateMachine.Transition; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.persistency.TransactionManager; +import com.c2kernel.persistency.outcome.Outcome; +import com.c2kernel.persistency.outcome.Viewpoint; import com.c2kernel.process.Gateway; import com.c2kernel.property.Property; import com.c2kernel.property.PropertyArrayList; @@ -80,6 +85,24 @@ public class ItemImplementation implements ItemOperations { throw new InvalidDataException("Properties were invalid", ""); } + // Store an event and the initial properties + try { + Outcome initOutcome = new Outcome(0, propString, "ItemInitialization", 0); + History hist = new History(mItemPath, locker); + Transition predefDone = new Transition(0, "Done", 0, 0); + Event newEvent = hist.addEvent(new AgentPath(agentId), "", "Initialize", "", "", initOutcome.getSchemaType(), 0, "PredefinedStep", 0, predefDone, "last"); + initOutcome.setID(newEvent.getID()); + Viewpoint newLastView = new Viewpoint(mItemPath, initOutcome.getSchemaType(), "last", 0, newEvent.getID()); + Gateway.getStorage().put(mItemPath, initOutcome, locker); + Gateway.getStorage().put(mItemPath, newLastView, locker); + } catch (Throwable ex) { + Logger.msg(8, "TraceableEntity::initialise(" + mItemPath + + ") - Could not store event and outcome."); + Logger.error(ex); + mStorage.abort(locker); + throw new PersistencyException("Error storing event and outcome", ""); + } + // create wf try { Workflow lc = null; @@ -115,6 +138,7 @@ public class ItemImplementation implements ItemOperations { throw new InvalidDataException("Collections were invalid"); } } + mStorage.commit(locker); Logger.msg(3, "Initialisation of item " + mItemPath + " was successful"); -- cgit v1.2.3