Search in sources :

Example 71 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException 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 72 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException 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)

Example 73 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class CreateNewItem method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectCannotBeUpdated, ObjectNotFoundException, CannotManageException, ObjectAlreadyExistsException, InvalidCollectionModification {
    try {
        ImportItem newItem = (ImportItem) Gateway.getMarshaller().unmarshall(requestData);
        newItem.create(agent, false);
        return requestData;
    } catch (MarshalException | ValidationException | IOException | MappingException e) {
        Logger.error(e);
        throw new InvalidDataException("CreateNewItem: Couldn't unmarshall new Item: " + requestData);
    } catch (PersistencyException e) {
        Logger.error(e);
        throw new InvalidDataException("CreateNewItem: " + e.getMessage());
    }
}
Also used : ImportItem(org.cristalise.kernel.entity.imports.ImportItem) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) IOException(java.io.IOException) MappingException(org.exolab.castor.mapping.MappingException)

Example 74 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class Activity method request.

public String request(AgentPath agent, AgentPath delegate, ItemPath itemPath, int transitionID, String requestData, Object locker) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, InvalidCollectionModification {
    // Find requested transition
    Transition transition = getStateMachine().getTransition(transitionID);
    // Check if the transition is possible
    String usedRole = transition.getPerformingRole(this, agent);
    // Verify outcome
    boolean storeOutcome = false;
    if (transition.hasOutcome(getProperties())) {
        if (StringUtils.isNotBlank(requestData))
            storeOutcome = true;
        else if (transition.getOutcome().isRequired())
            throw new InvalidDataException("Transition requires outcome data, but none was given");
    }
    // Get new state
    State oldState = getStateMachine().getState(this.state);
    State newState = getStateMachine().traverse(this, transition, agent);
    // Run extra logic in predefined steps here
    String outcome = runActivityLogic(agent, itemPath, transitionID, requestData, locker);
    // set new state and reservation
    setState(newState.getId());
    setBuiltInProperty(AGENT_NAME, transition.getReservation(this, agent));
    try {
        History hist = getWf().getHistory(locker);
        if (storeOutcome) {
            Schema schema = transition.getSchema(getProperties());
            Outcome newOutcome = new Outcome(-1, outcome, schema);
            // TODO: if we were ever going to validate outcomes on storage, it would be here.
            // newOutcome.validateAndCheck();
            String viewpoint = resolveViewpointName(newOutcome);
            int eventID = hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(), schema, getStateMachine(), transitionID, viewpoint).getID();
            newOutcome.setID(eventID);
            Gateway.getStorage().put(itemPath, newOutcome, locker);
            // update specific view if defined
            if (!viewpoint.equals("last")) {
                Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, viewpoint, eventID), locker);
            }
            // update the default "last" view
            Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, "last", eventID), locker);
            updateItemProperties(itemPath, newOutcome, locker);
        } else {
            hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(), getStateMachine(), transitionID);
        }
    } catch (PersistencyException ex) {
        Logger.error(ex);
        throw ex;
    }
    if (newState.isFinished() && !(getBuiltInProperty(BREAKPOINT).equals(Boolean.TRUE) && !oldState.isFinished())) {
        runNext(agent, itemPath, locker);
    }
    DateUtility.setToNow(mStateDate);
    pushJobsToAgents(itemPath);
    return outcome;
}
Also used : State(org.cristalise.kernel.lifecycle.instance.stateMachine.State) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) Schema(org.cristalise.kernel.persistency.outcome.Schema) Transition(org.cristalise.kernel.lifecycle.instance.stateMachine.Transition) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) History(org.cristalise.kernel.events.History) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint)

Example 75 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class Activity method pushJobsToAgents.

/**
 * Collects all Role names which are associated with this Activity and the Transitions of the current State,
 * and ....
 *
 * @param itemPath
 */
protected void pushJobsToAgents(ItemPath itemPath) {
    // Shall contain a set of unique role names
    Set<String> roleNames = new TreeSet<String>();
    String role = getCurrentAgentRole();
    if (StringUtils.isNotBlank(role)) {
        for (String r : role.split(",")) roleNames.add(r);
    }
    try {
        for (Transition trans : getStateMachine().getState(getState()).getPossibleTransitions().values()) {
            role = trans.getRoleOverride(getProperties());
            if (StringUtils.isNotBlank(role))
                roleNames.add(role);
        }
        Logger.msg(7, "Activity.pushJobsToAgents() - Pushing jobs to " + roleNames.size() + " roles");
        for (String roleName : roleNames) {
            pushJobsToAgents(itemPath, Gateway.getLookup().getRolePath(roleName));
        }
    } catch (InvalidDataException ex) {
        Logger.warning("Activity.pushJobsToAgents() - " + ex.getMessage());
    } catch (ObjectNotFoundException e) {
        Logger.warning("Activity.pushJobsToAgents() - Activity role '" + role + "' not found.");
    }
}
Also used : TreeSet(java.util.TreeSet) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Transition(org.cristalise.kernel.lifecycle.instance.stateMachine.Transition) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Aggregations

InvalidDataException (org.cristalise.kernel.common.InvalidDataException)91 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)40 PersistencyException (org.cristalise.kernel.common.PersistencyException)33 IOException (java.io.IOException)14 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)11 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)11 DomainPath (org.cristalise.kernel.lookup.DomainPath)10 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)9 CannotManageException (org.cristalise.kernel.common.CannotManageException)8 AgentPath (org.cristalise.kernel.lookup.AgentPath)8 Schema (org.cristalise.kernel.persistency.outcome.Schema)8 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)7 ItemPath (org.cristalise.kernel.lookup.ItemPath)7 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)6 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)6 MappingException (org.exolab.castor.mapping.MappingException)6 MarshalException (org.exolab.castor.xml.MarshalException)6 ValidationException (org.exolab.castor.xml.ValidationException)6 ArrayList (java.util.ArrayList)5 XPathExpressionException (javax.xml.xpath.XPathExpressionException)5