Search in sources :

Example 1 with NotAuthorizedException

use of org.kie.kogito.process.workitem.NotAuthorizedException in project kogito-runtimes by kiegroup.

the class LightWorkItemManager method abortWorkItem.

@Override
public void abortWorkItem(String id, Policy<?>... policies) {
    KogitoWorkItemImpl workItem = (KogitoWorkItemImpl) 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)");
        }
        KogitoProcessInstance processInstance = processInstanceManager.getProcessInstance(workItem.getProcessInstanceStringId());
        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 : KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) NotAuthorizedException(org.kie.kogito.process.workitem.NotAuthorizedException)

Example 2 with NotAuthorizedException

use of org.kie.kogito.process.workitem.NotAuthorizedException in project kogito-runtimes by kiegroup.

the class BaseHumanTaskLifeCycle method transitionTo.

@Override
public Map<String, Object> transitionTo(KogitoWorkItem workItem, KogitoWorkItemManager manager, Transition<Map<String, Object>> transition) {
    logger.debug("Transition method invoked for work item {} to transition to {}, currently in phase {} and status {}", workItem.getStringId(), 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.getStringId());
    }
    humanTaskWorkItem.setPhaseId(targetPhase.id());
    humanTaskWorkItem.setPhaseStatus(targetPhase.status());
    targetPhase.apply(humanTaskWorkItem, transition);
    if (transition.data() != null) {
        logger.debug("Updating data for phase {} and work item {}", targetPhase.id(), humanTaskWorkItem.getStringId());
        humanTaskWorkItem.getResults().putAll(transition.data());
    }
    logger.debug("Transition for work item {} to {} done, currently in phase {} and status {}", workItem.getStringId(), transition.phase(), workItem.getPhaseId(), workItem.getPhaseStatus());
    if (targetPhase.isTerminating()) {
        logger.debug("Target life cycle phase '{}' is terminiating, completing work item {}", targetPhase.id(), humanTaskWorkItem.getStringId());
        // since target life cycle phase is terminating completing work item
        ((InternalKogitoWorkItemManager) manager).internalCompleteWorkItem(humanTaskWorkItem);
    }
    return data(humanTaskWorkItem);
}
Also used : InvalidTransitionException(org.kie.kogito.process.workitem.InvalidTransitionException) Policy(org.kie.kogito.process.workitem.Policy) InvalidLifeCyclePhaseException(org.kie.kogito.process.workitem.InvalidLifeCyclePhaseException) InternalKogitoWorkItemManager(org.kie.kogito.process.workitems.InternalKogitoWorkItemManager) NotAuthorizedException(org.kie.kogito.process.workitem.NotAuthorizedException) LifeCyclePhase(org.kie.kogito.process.workitem.LifeCyclePhase)

Example 3 with NotAuthorizedException

use of org.kie.kogito.process.workitem.NotAuthorizedException in project kogito-runtimes by kiegroup.

the class BaseExceptionHandlerTest method testMapNotAuthorizedException.

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

Example 4 with NotAuthorizedException

use of org.kie.kogito.process.workitem.NotAuthorizedException in project kogito-runtimes by kiegroup.

the class LightWorkItemManager method updateWorkItem.

@Override
public <T> T updateWorkItem(String id, Function<org.kie.kogito.internal.process.runtime.KogitoWorkItem, T> updater, Policy<?>... policies) {
    InternalKogitoWorkItem workItem = workItems.get(id);
    if (workItem != null) {
        if (!workItem.enforce(policies)) {
            throw new NotAuthorizedException("User is not authorized to access task instance with id " + id);
        }
        T results = updater.apply(workItem);
        eventSupport.fireAfterWorkItemTransition(processInstanceManager.getProcessInstance(workItem.getProcessInstanceStringId()), workItem, null, null);
        return results;
    } else {
        throw new WorkItemNotFoundException(id);
    }
}
Also used : InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) WorkItemNotFoundException(org.kie.kogito.internal.process.runtime.WorkItemNotFoundException) NotAuthorizedException(org.kie.kogito.process.workitem.NotAuthorizedException)

Aggregations

NotAuthorizedException (org.kie.kogito.process.workitem.NotAuthorizedException)4 Test (org.junit.jupiter.api.Test)1 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)1 WorkItemNotFoundException (org.kie.kogito.internal.process.runtime.WorkItemNotFoundException)1 InvalidLifeCyclePhaseException (org.kie.kogito.process.workitem.InvalidLifeCyclePhaseException)1 InvalidTransitionException (org.kie.kogito.process.workitem.InvalidTransitionException)1 LifeCyclePhase (org.kie.kogito.process.workitem.LifeCyclePhase)1 Policy (org.kie.kogito.process.workitem.Policy)1 InternalKogitoWorkItem (org.kie.kogito.process.workitems.InternalKogitoWorkItem)1 InternalKogitoWorkItemManager (org.kie.kogito.process.workitems.InternalKogitoWorkItemManager)1 KogitoWorkItemImpl (org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl)1