Search in sources :

Example 1 with InvalidTransitionException

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

the class ItemImplementation method delegatedAction.

@Override
public String delegatedAction(SystemKey agentId, SystemKey delegateId, String stepPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, ObjectNotFoundException, InvalidDataException, PersistencyException, ObjectAlreadyExistsException, InvalidCollectionModification {
    Workflow lifeCycle = null;
    try {
        AgentPath agent = new AgentPath(agentId);
        AgentPath delegate = delegateId == null ? null : new AgentPath(delegateId);
        Logger.msg(1, "ItemImplementation::request(" + mItemPath + ") - Transition " + transitionID + " on " + stepPath + " by " + (delegate == null ? "" : delegate + " on behalf of ") + agent);
        // TODO: check if delegate is allowed valid for agent
        lifeCycle = (Workflow) mStorage.get(mItemPath, ClusterType.LIFECYCLE + "/workflow", null);
        String finalOutcome = lifeCycle.requestAction(agent, delegate, stepPath, mItemPath, transitionID, requestData);
        // store the workflow if we've changed the state of the domain wf
        if (!(stepPath.startsWith("workflow/predefined")))
            mStorage.put(mItemPath, lifeCycle, lifeCycle);
        // remove entity path if transaction was successful
        if (stepPath.equals("workflow/predefined/Erase")) {
            Logger.msg("Erasing item path " + mItemPath.toString());
            Gateway.getLookupManager().delete(mItemPath);
        }
        mStorage.commit(lifeCycle);
        return finalOutcome;
    } catch (AccessRightsException | InvalidTransitionException | ObjectNotFoundException | PersistencyException | InvalidDataException | ObjectAlreadyExistsException | InvalidCollectionModification ex) {
        if (Logger.doLog(8))
            Logger.error(ex);
        String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
        if (StringUtils.isBlank(errorOutcome)) {
            mStorage.abort(lifeCycle);
            throw ex;
        } else {
            mStorage.commit(lifeCycle);
            return errorOutcome;
        }
    } catch (InvalidAgentPathException | ObjectCannotBeUpdated | CannotManageException ex) {
        if (Logger.doLog(8))
            Logger.error(ex);
        String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
        if (StringUtils.isBlank(errorOutcome)) {
            mStorage.abort(lifeCycle);
            throw new InvalidDataException(ex.getClass().getName() + " - " + ex.getMessage());
        } else {
            mStorage.commit(lifeCycle);
            return errorOutcome;
        }
    } catch (Exception ex) {
        // non-CORBA exception hasn't been caught!
        Logger.error("Unknown Error: requestAction on " + mItemPath + " by " + agentId + " executing " + stepPath);
        Logger.error(ex);
        String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex);
        if (StringUtils.isBlank(errorOutcome)) {
            mStorage.abort(lifeCycle);
            throw new InvalidDataException("Extraordinary Exception during execution:" + ex.getClass().getName() + " - " + ex.getMessage());
        } else {
            mStorage.commit(lifeCycle);
            return errorOutcome;
        }
    }
}
Also used : InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow) InvalidCollectionModification(org.cristalise.kernel.common.InvalidCollectionModification) MappingException(org.exolab.castor.mapping.MappingException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) MarshalException(org.exolab.castor.xml.MarshalException) InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) IOException(java.io.IOException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException)

Example 2 with InvalidTransitionException

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

the class CompositeActivity method request.

@Override
public String request(AgentPath agent, AgentPath delegator, ItemPath itemPath, int transitionID, String requestData, Object locker) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException, ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException, InvalidCollectionModification {
    Transition trans = getStateMachine().getTransition(transitionID);
    if (trans.isFinishing() && hasActive()) {
        if ((Boolean) getBuiltInProperty(ABORTABLE))
            abort();
        else
            throw new InvalidTransitionException("Attempted to finish a composite activity that had active children but was not Abortable");
    }
    if (getStateMachine().getTransition(transitionID).reinitializes()) {
        int preserveState = state;
        reinit(getID());
        setState(preserveState);
    }
    if (getChildrenGraphModel().getStartVertex() != null && (getStateMachine().getState(state).equals(getStateMachine().getInitialState()) || getStateMachine().getTransition(transitionID).reinitializes())) {
        ((WfVertex) getChildrenGraphModel().getStartVertex()).run(agent, itemPath, locker);
    }
    return super.request(agent, delegator, itemPath, transitionID, requestData, locker);
}
Also used : InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) Transition(org.cristalise.kernel.lifecycle.instance.stateMachine.Transition) GraphPoint(org.cristalise.kernel.graph.model.GraphPoint)

Example 3 with InvalidTransitionException

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

the class UserCodeProcess method run.

@Override
public void run() {
    Thread.currentThread().setName("Usercode Process");
    // subscribe to job list - this will initialise the jobs using the ProxyObserver interface as callback
    agent.subscribe(new MemberSubscription<Job>(this, ClusterType.JOB.getName(), true));
    while (active) {
        Job thisJob = getActualJob();
        if (thisJob != null) {
            String jobKey = thisJob.getItemPath() + ":" + thisJob.getStepPath();
            int transitionId = thisJob.getTransition().getId();
            try {
                if (transitionId == START)
                    start(thisJob, jobKey);
                else if (transitionId == COMPLETE)
                    complete(thisJob, jobKey);
            } catch (InvalidTransitionException ex) {
            // must have already been done by someone else - ignore
            } catch (Exception ex) {
                Logger.error("Error executing job:" + thisJob);
                Logger.error(ex);
            }
        }
        try {
            synchronized (jobs) {
                if (jobs.size() == 0) {
                    Logger.msg("UserCodeProcess.run() - Sleeping");
                    while (active && jobs.size() == 0) jobs.wait(2000);
                }
            }
        } catch (InterruptedException ex) {
        }
    }
    // shut down
    try {
        Gateway.close();
    } catch (Exception ex) {
        Logger.error(ex);
    }
}
Also used : InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) Job(org.cristalise.kernel.entity.agent.Job) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ScriptErrorException(org.cristalise.kernel.scripting.ScriptErrorException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException)

Aggregations

InvalidTransitionException (org.cristalise.kernel.common.InvalidTransitionException)3 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)2 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)2 PersistencyException (org.cristalise.kernel.common.PersistencyException)2 IOException (java.io.IOException)1 CannotManageException (org.cristalise.kernel.common.CannotManageException)1 InvalidCollectionModification (org.cristalise.kernel.common.InvalidCollectionModification)1 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)1 Job (org.cristalise.kernel.entity.agent.Job)1 GraphPoint (org.cristalise.kernel.graph.model.GraphPoint)1 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)1 Transition (org.cristalise.kernel.lifecycle.instance.stateMachine.Transition)1 AgentPath (org.cristalise.kernel.lookup.AgentPath)1 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)1 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)1 ScriptErrorException (org.cristalise.kernel.scripting.ScriptErrorException)1 MappingException (org.exolab.castor.mapping.MappingException)1 MarshalException (org.exolab.castor.xml.MarshalException)1