use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.
the class ItemImplementation method initialise.
@Override
public void initialise(SystemKey agentId, String propString, String initWfString, String initCollsString) throws AccessRightsException, InvalidDataException, PersistencyException {
Logger.msg(5, "Item::initialise(" + mItemPath + ") - agent:" + agentId);
Object locker = new Object();
AgentPath agentPath;
try {
agentPath = new AgentPath(agentId);
} catch (InvalidItemPathException e) {
throw new AccessRightsException("Invalid Agent Id:" + agentId);
}
// must supply properties
if (propString == null || propString.length() == 0 || propString.equals("<NULL/>")) {
throw new InvalidDataException("No properties supplied");
}
// store properties
try {
PropertyArrayList props = (PropertyArrayList) Gateway.getMarshaller().unmarshall(propString);
for (Property thisProp : props.list) mStorage.put(mItemPath, thisProp, locker);
} catch (Throwable ex) {
Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Properties were invalid: " + propString);
Logger.error(ex);
mStorage.abort(locker);
throw new InvalidDataException("Properties were invalid");
}
// Store an event and the initial properties
try {
Schema initSchema = LocalObjectLoader.getSchema("ItemInitialization", 0);
Outcome initOutcome = new Outcome(0, propString, initSchema);
History hist = new History(mItemPath, locker);
Event newEvent = hist.addEvent(new AgentPath(agentId), null, "", "Initialize", "", "", initSchema, Bootstrap.getPredefSM(), PredefinedStep.DONE, "last");
initOutcome.setID(newEvent.getID());
Viewpoint newLastView = new Viewpoint(mItemPath, initSchema, "last", newEvent.getID());
mStorage.put(mItemPath, initOutcome, locker);
mStorage.put(mItemPath, newLastView, locker);
} catch (Throwable ex) {
Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Could not store event and outcome.");
Logger.error(ex);
mStorage.abort(locker);
throw new PersistencyException("Error storing event and outcome");
}
// init collections
if (initCollsString != null && initCollsString.length() > 0 && !initCollsString.equals("<NULL/>")) {
try {
CollectionArrayList colls = (CollectionArrayList) Gateway.getMarshaller().unmarshall(initCollsString);
for (Collection<?> thisColl : colls.list) {
mStorage.put(mItemPath, thisColl, locker);
}
} catch (Throwable ex) {
Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Collections were invalid: " + initCollsString);
Logger.error(ex);
mStorage.abort(locker);
throw new InvalidDataException("Collections were invalid");
}
}
// create wf
Workflow lc = null;
try {
if (initWfString == null || initWfString.length() == 0 || initWfString.equals("<NULL/>")) {
lc = new Workflow(new CompositeActivity(), getNewPredefStepContainer());
} else {
lc = new Workflow((CompositeActivity) Gateway.getMarshaller().unmarshall(initWfString), getNewPredefStepContainer());
}
mStorage.put(mItemPath, lc, locker);
} catch (Throwable ex) {
Logger.msg(8, "ItemImplementation::initialise(" + mItemPath + ") - Workflow was invalid: " + initWfString);
Logger.error(ex);
mStorage.abort(locker);
throw new InvalidDataException("Workflow was invalid");
}
// All objects are in place, initialize the workflow to get the Item running
lc.initialise(mItemPath, agentPath, locker);
mStorage.put(mItemPath, lc, locker);
mStorage.commit(locker);
Logger.msg(3, "Initialisation of item " + mItemPath + " was successful");
}
use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.
the class Job method getOutcome.
/**
* Returns the Outcome if exists otherwise tries to read and duplicate the Outcome of 'last' ViewPoint.
* If that does not exists it tries to use an OutcomeInitiator.
*
* @return the Outcome object or null
* @throws InvalidDataException inconsistent data
* @throws ObjectNotFoundException Schema was not found
*/
public Outcome getOutcome() throws InvalidDataException, ObjectNotFoundException {
if (outcome == null && transition.hasOutcome(actProps)) {
if (getItem().checkViewpoint(getSchema().getName(), getValidViewpointName())) {
Outcome tempOutcome = getLastOutcome();
outcome = new Outcome(tempOutcome.getData(), tempOutcome.getSchema());
} else {
OutcomeInitiator ocInit = getOutcomeInitiator();
if (ocInit != null)
outcome = ocInit.initOutcomeInstance(this);
}
} else {
Logger.msg(8, "Job.getOutcome() - Job does not require Outcome job:" + this);
}
return outcome;
}
use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.
the class TransferItem method importItem.
public void importItem(File dir) throws Exception {
// check if already exists
try {
Property name = (Property) Gateway.getStorage().get(itemPath, PROPERTY + "/" + NAME, null);
throw new Exception("Item " + itemPath + " already in use as " + name.getValue());
} catch (Exception ex) {
}
// retrieve objects
ArrayList<String> objectFiles = FileStringUtility.listDir(dir.getCanonicalPath(), false, true);
ArrayList<C2KLocalObject> objects = new ArrayList<C2KLocalObject>();
for (String element : objectFiles) {
String xmlFile = FileStringUtility.file2String(element);
C2KLocalObject newObj;
String choppedPath = element.substring(dir.getCanonicalPath().length() + 1, element.length() - 4);
Logger.msg(choppedPath);
if (choppedPath.startsWith(OUTCOME.getName()))
newObj = new Outcome(choppedPath, xmlFile);
else
newObj = (C2KLocalObject) Gateway.getMarshaller().unmarshall(xmlFile);
objects.add(newObj);
}
// create item
TraceableEntity newItem = Gateway.getCorbaServer().createItem(itemPath);
Gateway.getLookupManager().add(itemPath);
PropertyArrayList props = new PropertyArrayList();
CollectionArrayList colls = new CollectionArrayList();
Workflow wf = null;
// put objects
for (C2KLocalObject obj : objects) {
if (obj instanceof Property)
props.list.add((Property) obj);
else if (obj instanceof Collection)
colls.list.add((Collection<?>) obj);
else if (obj instanceof Workflow)
wf = (Workflow) obj;
}
if (wf == null)
throw new Exception("No workflow found in import for " + itemPath);
// init item
newItem.initialise(importAgentId.getSystemKey(), Gateway.getMarshaller().marshall(props), Gateway.getMarshaller().marshall(wf.search("workflow/domain")), Gateway.getMarshaller().marshall(colls));
// store objects
importByType(ClusterType.HISTORY, objects);
importByType(ClusterType.OUTCOME, objects);
importByType(ClusterType.VIEWPOINT, objects);
Gateway.getStorage().commit(this);
// add domPaths
for (String element : domainPaths) {
DomainPath newPath = new DomainPath(element, itemPath);
Gateway.getLookupManager().add(newPath);
}
}
use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.
the class Bootstrap method verifyResource.
/**
* @param ns
* @param itemName
* @param version
* @param itemType
* @param itemPath
* @param outcomes
* @param dataLocation
* @param reset
* @return the Path of the resource either created or initialised from existing data
* @throws Exception
*/
private static DomainPath verifyResource(String ns, String itemName, int version, String itemType, ItemPath itemPath, Set<Outcome> outcomes, String dataLocation, boolean reset) throws Exception {
ResourceImportHandler typeImpHandler = Gateway.getResourceImportHandler(BuiltInResources.getValue(itemType));
Logger.msg(1, "Bootstrap.verifyResource() - Verifying " + typeImpHandler.getName() + " " + itemName + " v" + version);
// Find or create Item for Resource
ItemProxy thisProxy;
DomainPath modDomPath = typeImpHandler.getPath(itemName, ns);
if (modDomPath.exists()) {
Logger.msg(3, "Bootstrap.verifyResource() - Found " + typeImpHandler.getName() + " " + itemName + ".");
thisProxy = verifyPathAndModuleProperty(ns, itemType, itemName, itemPath, modDomPath, modDomPath);
} else {
if (itemPath == null)
itemPath = new ItemPath();
Logger.msg("Bootstrap.verifyResource() - " + typeImpHandler.getName() + " " + itemName + " not found. Creating new.");
thisProxy = createResourceItem(typeImpHandler, itemName, ns, itemPath);
}
// Verify/Import Outcomes, creating events and views as necessary
if (outcomes == null || outcomes.size() == 0) {
outcomes = typeImpHandler.getResourceOutcomes(itemName, ns, dataLocation, version);
}
if (outcomes.size() == 0)
Logger.warning("Bootstrap.verifyResource() - no Outcome found therefore nothing stored!");
for (Outcome newOutcome : outcomes) {
if (checkToStoreOutcomeVersion(thisProxy, newOutcome, version, reset)) {
// validate it, but not for kernel objects (ns == null) because those are to validate the rest
if (ns != null)
newOutcome.validateAndCheck();
storeOutcomeEventAndViews(thisProxy, newOutcome, version);
CollectionArrayList cols = typeImpHandler.getCollections(itemName, version, newOutcome);
for (Collection<?> col : cols.list) {
Gateway.getStorage().put(thisProxy.getPath(), col, thisProxy);
Gateway.getStorage().clearCache(thisProxy.getPath(), ClusterType.COLLECTION + "/" + col.getName());
col.setVersion(null);
Gateway.getStorage().put(thisProxy.getPath(), col, thisProxy);
}
}
}
Gateway.getStorage().commit(thisProxy);
return modDomPath;
}
use of org.cristalise.kernel.persistency.outcome.Outcome in project kernel by cristal-ise.
the class ViewpointDataHelper method get.
/**
* dataPath syntax is used for search : viewpoint:/xpath/to/field
*/
@Override
public String get(ItemPath itemPath, String actContext, String dataPath, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
String[] paths = dataPath.split(":");
if (paths.length != 2)
throw new InvalidDataException("Invalid path: '" + dataPath + "' should have only one colon (:)");
String viewpoint = paths[0];
String xpath = paths[1];
// Leading dot now no longer necessary - remove if present
if (viewpoint.startsWith("./")) {
Logger.warning("Removing leading dot on viewpoint data helper path at " + actContext + " in " + itemPath.getUUID().toString() + ". Definition should be migrated.");
viewpoint = viewpoint.substring(2);
}
// load Viewpoint and Outcome
Viewpoint view = (Viewpoint) Gateway.getStorage().get(itemPath, ClusterType.VIEWPOINT + "/" + viewpoint, locker);
Outcome outcome = (Outcome) view.getOutcome(locker);
// apply the XPath to its outcome
try {
return outcome.getFieldByXPath(xpath);
} catch (XPathExpressionException e) {
throw new InvalidDataException("Invalid XPath: " + xpath);
}
}
Aggregations