use of org.cristalise.kernel.lifecycle.instance.CompositeActivity in project kernel by cristal-ise.
the class CreateItemFromDescription method instantiateWorkflow.
/**
* Retrieve the Workflow dependency for the given description version, instantiate the loaded CompositeActivityDef
*
* @param descItemPath
* @param descVer
* @param locker
* @return the Workflow instance
* @throws ObjectNotFoundException
* @throws InvalidDataException
* @throws PersistencyException
*/
protected CompositeActivity instantiateWorkflow(ItemPath descItemPath, String descVer, Object locker) throws ObjectNotFoundException, InvalidDataException, PersistencyException {
@SuppressWarnings("unchecked") Collection<? extends CollectionMember> thisCol = (Collection<? extends CollectionMember>) Gateway.getStorage().get(descItemPath, ClusterType.COLLECTION + "/" + WORKFLOW + "/" + descVer, locker);
CollectionMember wfMember = thisCol.getMembers().list.get(0);
String wfDefName = wfMember.resolveItem().getName();
Object wfVerObj = wfMember.getProperties().getBuiltInProperty(VERSION);
if (wfVerObj == null || String.valueOf(wfVerObj).length() == 0) {
throw new InvalidDataException("Workflow version number not set");
}
try {
Integer wfDefVer = Integer.parseInt(wfVerObj.toString());
if (wfDefName == null)
throw new InvalidDataException("No workflow given or defined");
// load workflow def
CompositeActivityDef wfDef = (CompositeActivityDef) LocalObjectLoader.getActDef(wfDefName, wfDefVer);
return (CompositeActivity) wfDef.instantiate();
} catch (NumberFormatException ex) {
throw new InvalidDataException("Invalid workflow version number: " + wfVerObj.toString());
} catch (ClassCastException ex) {
Logger.error(ex);
throw new InvalidDataException("Activity def '" + wfDefName + "' was not Composite");
}
}
use of org.cristalise.kernel.lifecycle.instance.CompositeActivity in project kernel by cristal-ise.
the class CreateItemFromDescription method initialiseItem.
/**
* @param agent
* @param descItemPath
* @param locker
* @param input
* @param newName
* @param descVer
* @param context
* @param newItemPath
* @param newItem
* @throws ObjectCannotBeUpdated
* @throws CannotManageException
* @throws InvalidDataException
* @throws ObjectAlreadyExistsException
* @throws PersistencyException
* @throws ObjectNotFoundException
*/
protected void initialiseItem(ItemOperations newItem, AgentPath agent, ItemPath descItemPath, PropertyArrayList initProps, String newName, String descVer, DomainPath context, ItemPath newItemPath, Object locker) throws ObjectCannotBeUpdated, CannotManageException, InvalidDataException, ObjectAlreadyExistsException, PersistencyException, ObjectNotFoundException {
// initialise it with its properties and workflow
Logger.msg(3, "CreateItemFromDescription.initialiseItem() - Initializing Item:" + newName);
try {
PropertyArrayList newProps = instantiateProperties(descItemPath, descVer, initProps, newName, agent, locker);
CollectionArrayList newColls = instantiateCollections(descItemPath, descVer, newProps, locker);
CompositeActivity newWorkflow = instantiateWorkflow(descItemPath, descVer, locker);
newItem.initialise(agent.getSystemKey(), Gateway.getMarshaller().marshall(newProps), Gateway.getMarshaller().marshall(newWorkflow), Gateway.getMarshaller().marshall(newColls));
} catch (MarshalException | ValidationException | AccessRightsException | IOException | MappingException | InvalidCollectionModification e) {
Logger.error(e);
Gateway.getLookupManager().delete(newItemPath);
throw new InvalidDataException("CreateItemFromDescription: Problem initializing new Item. See log: " + e.getMessage());
} catch (InvalidDataException | ObjectNotFoundException | PersistencyException e) {
Logger.error(e);
Gateway.getLookupManager().delete(newItemPath);
throw e;
}
// add its domain path
Logger.msg(3, "CreateItemFromDescription - Creating " + context);
context.setItemPath(newItemPath);
Gateway.getLookupManager().add(context);
}
Aggregations