Search in sources :

Example 6 with CompositeActivity

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");
    }
}
Also used : CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) CollectionMember(org.cristalise.kernel.collection.CollectionMember) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Collection(org.cristalise.kernel.collection.Collection) CompositeActivityDef(org.cristalise.kernel.lifecycle.CompositeActivityDef)

Example 7 with CompositeActivity

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);
}
Also used : MarshalException(org.exolab.castor.xml.MarshalException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) ValidationException(org.exolab.castor.xml.ValidationException) InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) IOException(java.io.IOException) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) MappingException(org.exolab.castor.mapping.MappingException) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Aggregations

CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)7 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)5 PersistencyException (org.cristalise.kernel.common.PersistencyException)4 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)3 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)3 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)3 IOException (java.io.IOException)2 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)2 CompositeActivityDef (org.cristalise.kernel.lifecycle.CompositeActivityDef)2 AgentPath (org.cristalise.kernel.lookup.AgentPath)2 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)2 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)2 Property (org.cristalise.kernel.property.Property)2 MappingException (org.exolab.castor.mapping.MappingException)2 MarshalException (org.exolab.castor.xml.MarshalException)2 ValidationException (org.exolab.castor.xml.ValidationException)2 Collection (org.cristalise.kernel.collection.Collection)1 CollectionMember (org.cristalise.kernel.collection.CollectionMember)1 CannotManageException (org.cristalise.kernel.common.CannotManageException)1