use of org.cristalise.kernel.property.Property 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.property.Property in project kernel by cristal-ise.
the class ImportItem method createItemProperties.
/**
* @return
*/
protected PropertyArrayList createItemProperties() {
properties.add(new Property(NAME, name, true));
properties.add(new Property(CREATOR, "bootstrap", true));
return new PropertyArrayList(properties);
}
use of org.cristalise.kernel.property.Property in project kernel by cristal-ise.
the class Dependency method addToItemProperties.
/**
* Add Dependency specific values to ItemProperties. First checks if there is a Script to be executed,
* if no Script defined it will use the default conversion implemented for BuiltInCollections
*
* @param props the current list of ItemProperties
*/
public void addToItemProperties(PropertyArrayList props) throws InvalidDataException, ObjectNotFoundException {
Logger.msg(2, "Dependency.addToItemProperties(" + getName() + ") - Starting ...");
// convert to BuiltInCollections
BuiltInCollections builtInColl = BuiltInCollections.getValue(getName());
for (DependencyMember member : getMembers().list) {
String memberUUID = member.getChildUUID();
Integer memberVer = LocalObjectLoader.deriveVersionNumber(member.getBuiltInProperty(VERSION));
if (memberVer == null) {
throw new InvalidDataException("Version is null for Collection:" + getName() + ", MemberUUID:" + memberUUID);
}
// - or this is not a BuiltInCollection
if (convertToItemPropertyByScript(props, member) || builtInColl == null)
continue;
Logger.msg(5, "Dependency.addToItemProperties() - BuiltIn Dependency:" + getName() + " memberUUID:" + memberUUID);
// LocalObjectLoader checks if data is valid and loads object to cache
switch(builtInColl) {
// ***************************************************************************************************
case SCHEMA:
LocalObjectLoader.getSchema(memberUUID, memberVer);
props.put(new Property(SCHEMA_URN, memberUUID + ":" + memberVer));
break;
// ***************************************************************************************************
case SCRIPT:
LocalObjectLoader.getScript(memberUUID, memberVer);
props.put(new Property(SCRIPT_URN, memberUUID + ":" + memberVer));
break;
// ***************************************************************************************************
case QUERY:
LocalObjectLoader.getQuery(memberUUID, memberVer);
props.put(new Property(QUERY_URN, memberUUID + ":" + memberVer));
break;
// ***************************************************************************************************
case STATE_MACHINE:
if (Gateway.getProperties().getBoolean("Dependency.addStateMachineURN", false)) {
LocalObjectLoader.getStateMachine(memberUUID, memberVer);
props.put(new Property(STATE_MACHINE_URN, memberUUID + ":" + memberVer));
}
break;
// ***************************************************************************************************
case WORKFLOW:
if (Gateway.getProperties().getBoolean("Dependency.addWorkflowURN", false)) {
LocalObjectLoader.getCompActDef(memberUUID, memberVer);
props.put(new Property(WORKFLOW_URN, memberUUID + ":" + memberVer));
}
break;
// ***************************************************************************************************
default:
Logger.msg(8, "Dependency.addToItemProperties() - Cannot handle BuiltIn Dependency:" + getName());
break;
}
}
}
use of org.cristalise.kernel.property.Property in project kernel by cristal-ise.
the class DependencyMember method assignItem.
@Override
public void assignItem(ItemPath itemPath) throws InvalidCollectionModification {
if (itemPath != null) {
if (mClassProps == null || getProperties() == null)
throw new InvalidCollectionModification("ClassProps not yet set. Cannot check membership validity.");
// for each mandatory prop check if its in the member property and has the matching value
StringTokenizer sub = new StringTokenizer(mClassProps, ",");
while (sub.hasMoreTokens()) {
String aClassProp = sub.nextToken();
try {
String memberValue = (String) getProperties().get(aClassProp);
Property ItemProperty = (Property) Gateway.getStorage().get(itemPath, ClusterType.PROPERTY + "/" + aClassProp, null);
if (ItemProperty == null)
throw new InvalidCollectionModification("Property " + aClassProp + " does not exist for item " + itemPath);
if (!ItemProperty.getValue().equalsIgnoreCase(memberValue))
throw new InvalidCollectionModification("DependencyMember::checkProperty() Values of mandatory prop " + aClassProp + " do not match " + ItemProperty.getValue() + "!=" + memberValue);
} catch (Exception ex) {
Logger.error(ex);
throw new InvalidCollectionModification("Error checking properties");
}
}
}
mItemPath = itemPath;
mItem = null;
}
use of org.cristalise.kernel.property.Property 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);
}
}
Aggregations