Search in sources :

Example 6 with History

use of org.cristalise.kernel.events.History 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)

Aggregations

History (org.cristalise.kernel.events.History)6 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)6 PersistencyException (org.cristalise.kernel.common.PersistencyException)5 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)4 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)4 Schema (org.cristalise.kernel.persistency.outcome.Schema)4 Event (org.cristalise.kernel.events.Event)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)2 AgentPath (org.cristalise.kernel.lookup.AgentPath)2 StringTokenizer (java.util.StringTokenizer)1 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)1 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)1 CannotManageException (org.cristalise.kernel.common.CannotManageException)1 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)1 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)1 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)1 JobList (org.cristalise.kernel.entity.agent.JobList)1 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)1 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)1 State (org.cristalise.kernel.lifecycle.instance.stateMachine.State)1