Search in sources :

Example 1 with NotAuthorizedException

use of io.automatiko.engine.api.workflow.workitem.NotAuthorizedException in project automatiko-engine by automatiko-io.

the class BaseHumanTaskLifeCycle method transitionTo.

@Override
public Map<String, Object> transitionTo(WorkItem workItem, WorkItemManager manager, Transition<Map<String, Object>> transition) {
    logger.debug("Transition method invoked for work item {} to transition to {}, currently in phase {} and status {}", workItem.getId(), transition.phase(), workItem.getPhaseId(), workItem.getPhaseStatus());
    HumanTaskWorkItemImpl humanTaskWorkItem = (HumanTaskWorkItemImpl) workItem;
    LifeCyclePhase targetPhase = phases.get(transition.phase());
    if (targetPhase == null) {
        logger.debug("Target life cycle phase '{}' does not exist in {}", transition.phase(), this.getClass().getSimpleName());
        throw new InvalidLifeCyclePhaseException(transition.phase());
    }
    LifeCyclePhase currentPhase = phases.get(humanTaskWorkItem.getPhaseId());
    if (!targetPhase.canTransition(currentPhase)) {
        logger.debug("Target life cycle phase '{}' cannot transition from current state '{}'", targetPhase.id(), currentPhase.id());
        throw new InvalidTransitionException("Cannot transition from " + humanTaskWorkItem.getPhaseId() + " to " + targetPhase.id());
    }
    if (!targetPhase.id().equals(Active.ID) && !targetPhase.id().equals(Abort.ID) && !humanTaskWorkItem.enforce(transition.policies().toArray(new Policy[transition.policies().size()]))) {
        throw new NotAuthorizedException("User is not authorized to access task instance with id " + humanTaskWorkItem.getId());
    }
    humanTaskWorkItem.setPhaseId(targetPhase.id());
    humanTaskWorkItem.setPhaseStatus(targetPhase.status());
    targetPhase.apply(humanTaskWorkItem, transition);
    if (transition.data() != null) {
        logger.debug("Updating data for work item {}", targetPhase.id(), humanTaskWorkItem.getId());
        humanTaskWorkItem.getResults().putAll(transition.data());
    }
    logger.debug("Transition for work item {} to {} done, currently in phase {} and status {}", workItem.getId(), transition.phase(), workItem.getPhaseId(), workItem.getPhaseStatus());
    if (targetPhase.isCompleting()) {
        logger.debug("Target life cycle phase '{}' is completing, completing work item {}", targetPhase.id(), humanTaskWorkItem.getId());
        // since target life cycle phase is terminating completing work item
        ((DefaultWorkItemManager) manager).internalCompleteWorkItem(humanTaskWorkItem);
    } else if (targetPhase.isTerminating()) {
        logger.debug("Target life cycle phase '{}' is terminating, aborting work item {}", targetPhase.id(), humanTaskWorkItem.getId());
        ((DefaultWorkItemManager) manager).internalAbortWorkItem(humanTaskWorkItem);
    }
    return data(humanTaskWorkItem);
}
Also used : InvalidTransitionException(io.automatiko.engine.api.workflow.workitem.InvalidTransitionException) Policy(io.automatiko.engine.api.workflow.workitem.Policy) DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) InvalidLifeCyclePhaseException(io.automatiko.engine.api.workflow.workitem.InvalidLifeCyclePhaseException) NotAuthorizedException(io.automatiko.engine.api.workflow.workitem.NotAuthorizedException) LifeCyclePhase(io.automatiko.engine.api.workflow.workitem.LifeCyclePhase)

Example 2 with NotAuthorizedException

use of io.automatiko.engine.api.workflow.workitem.NotAuthorizedException in project automatiko-engine by automatiko-io.

the class LightWorkItemManager method abortWorkItem.

public void abortWorkItem(String id, Policy<?>... policies) {
    WorkItemImpl workItem = (WorkItemImpl) workItems.get(id);
    // work item may have been aborted
    if (workItem != null) {
        if (!workItem.enforce(policies)) {
            throw new NotAuthorizedException("Work item can be aborted as it does not fulfil policies (e.g. security)");
        }
        ProcessInstance processInstance = workItem.getProcessInstance();
        Transition<?> transition = new TransitionToAbort(Arrays.asList(policies));
        eventSupport.fireBeforeWorkItemTransition(processInstance, workItem, transition, null);
        workItem.setState(ABORTED);
        abortPhase.apply(workItem, transition);
        // process instance may have finished already
        if (processInstance != null) {
            processInstance.signalEvent("workItemAborted", workItem);
        }
        workItem.setPhaseId(ID);
        workItem.setPhaseStatus(STATUS);
        eventSupport.fireAfterWorkItemTransition(processInstance, workItem, transition, null);
        workItems.remove(id);
    }
}
Also used : WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) NotAuthorizedException(io.automatiko.engine.api.workflow.workitem.NotAuthorizedException)

Example 3 with NotAuthorizedException

use of io.automatiko.engine.api.workflow.workitem.NotAuthorizedException in project automatiko-engine by automatiko-io.

the class BaseExceptionHandlerTest method testMapNotAuthorizedException.

@Test
void testMapNotAuthorizedException() {
    Object response = tested.mapException(new NotAuthorizedException("message"));
    assertThat(response).isEqualTo(forbiddenResponse);
}
Also used : NotAuthorizedException(io.automatiko.engine.api.workflow.workitem.NotAuthorizedException) Test(org.junit.jupiter.api.Test)

Aggregations

NotAuthorizedException (io.automatiko.engine.api.workflow.workitem.NotAuthorizedException)3 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)1 InvalidLifeCyclePhaseException (io.automatiko.engine.api.workflow.workitem.InvalidLifeCyclePhaseException)1 InvalidTransitionException (io.automatiko.engine.api.workflow.workitem.InvalidTransitionException)1 LifeCyclePhase (io.automatiko.engine.api.workflow.workitem.LifeCyclePhase)1 Policy (io.automatiko.engine.api.workflow.workitem.Policy)1 DefaultWorkItemManager (io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager)1 WorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl)1 Test (org.junit.jupiter.api.Test)1