use of org.cristalise.kernel.collection.CollectionArrayList 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.collection.CollectionArrayList in project kernel by cristal-ise.
the class ActivityDef method makeDescCollections.
@Override
public CollectionArrayList makeDescCollections() throws InvalidDataException, ObjectNotFoundException {
CollectionArrayList retArr = new CollectionArrayList();
retArr.put(makeDescCollection(SCHEMA, getSchema()));
retArr.put(makeDescCollection(SCRIPT, getScript()));
retArr.put(makeDescCollection(QUERY, getQuery()));
retArr.put(makeDescCollection(STATE_MACHINE, getStateMachine()));
return retArr;
}
use of org.cristalise.kernel.collection.CollectionArrayList 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.collection.CollectionArrayList 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.collection.CollectionArrayList in project kernel by cristal-ise.
the class CompositeActivityDef method makeDescCollections.
@Override
public CollectionArrayList makeDescCollections() throws InvalidDataException, ObjectNotFoundException {
CollectionArrayList retArr = super.makeDescCollections();
retArr.put(makeActDefCollection());
return retArr;
}
Aggregations