Search in sources :

Example 1 with TaskException

use of org.kie.internal.task.exception.TaskException in project jbpm by kiegroup.

the class TaskTransactionInterceptor method execute.

@Override
public synchronized RequestContext execute(Executable executable, RequestContext ctx) {
    boolean transactionOwner = false;
    try {
        transactionOwner = txm.begin();
        tpm.beginCommandScopedEntityManager();
        TransactionManagerHelper.registerTransactionSyncInContainer(this.txm, new TaskSynchronizationImpl(this));
        if (txm != null) {
            ObjectMarshallingStrategy[] strategies = (ObjectMarshallingStrategy[]) environment.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES);
            if (strategies != null) {
                for (ObjectMarshallingStrategy strategy : strategies) {
                    if (strategy instanceof TransactionAware) {
                        ((TransactionAware) strategy).onStart(txm);
                    }
                }
            }
        }
        RequestContext context = createContext();
        executeNext(executable, context);
        ctx.setResult(context.getResult());
        postInit(ctx.getResult());
        txm.commit(transactionOwner);
        return ctx;
    } catch (TaskException e) {
        // if transaction is owned by other component like process engine
        if (transactionOwner) {
            rollbackTransaction(e, transactionOwner);
            e.setRecoverable(false);
            throw e;
        } else {
            throw e;
        }
    } catch (RuntimeException re) {
        rollbackTransaction(re, transactionOwner);
        throw re;
    } catch (Exception t1) {
        rollbackTransaction(t1, transactionOwner);
        throw new RuntimeException("Wrapped exception see cause", t1);
    }
}
Also used : TaskException(org.kie.internal.task.exception.TaskException) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) TransactionAware(org.drools.persistence.api.TransactionAware) RequestContext(org.kie.api.runtime.RequestContext) TaskException(org.kie.internal.task.exception.TaskException)

Example 2 with TaskException

use of org.kie.internal.task.exception.TaskException in project jbpm by kiegroup.

the class LocalHTWorkItemHandler method executeWorkItem.

@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
    RuntimeEngine runtime = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(workItem.getProcessInstanceId()));
    KieSession ksessionById = runtime.getKieSession();
    Task task = createTaskBasedOnWorkItemParams(ksessionById, workItem);
    // ContentData content = createTaskContentBasedOnWorkItemParams(ksessionById, workItem);
    Map<String, Object> content = createTaskDataBasedOnWorkItemParams(ksessionById, workItem);
    try {
        long taskId = ((InternalTaskService) runtime.getTaskService()).addTask(task, content);
        if (isAutoClaim(ksessionById, workItem, task)) {
            try {
                runtime.getTaskService().claim(taskId, (String) workItem.getParameter("SwimlaneActorId"));
            } catch (PermissionDeniedException e) {
                logger.warn("User {} is not allowed to auto claim task due to permission violation", workItem.getParameter("SwimlaneActorId"));
            }
        }
    } catch (Exception e) {
        if (action.equals(OnErrorAction.ABORT)) {
            manager.abortWorkItem(workItem.getId());
        } else if (action.equals(OnErrorAction.RETHROW)) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else {
                throw new RuntimeException(e);
            }
        } else if (action.equals(OnErrorAction.LOG)) {
            StringBuilder logMsg = new StringBuilder();
            logMsg.append(new Date()).append(": Error when creating task on task server for work item id ").append(workItem.getId());
            logMsg.append(". Error reported by task server: ").append(e.getMessage());
            logger.error(logMsg.toString(), e);
            // rethrow to cancel processing if the exception is not recoverable
            if (!(e instanceof TaskException) || ((e instanceof TaskException) && !((TaskException) e).isRecoverable())) {
                if (e instanceof RuntimeException) {
                    throw (RuntimeException) e;
                } else {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) Task(org.kie.api.task.model.Task) InternalTaskService(org.kie.internal.task.api.InternalTaskService) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskException(org.kie.internal.task.exception.TaskException) Date(java.util.Date) TaskException(org.kie.internal.task.exception.TaskException) KieSession(org.kie.api.runtime.KieSession) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException)

Example 3 with TaskException

use of org.kie.internal.task.exception.TaskException in project jbpm by kiegroup.

the class TaskExecutionErrorFilter method filter.

@Override
public ExecutionError filter(ExecutionErrorContext errorContext) {
    if (isCausedBy(errorContext.getCause(), PermissionDeniedException.class)) {
        return null;
    }
    Builder taskErrorBuilder = ExecutionError.builder().type(TYPE).initActivityId(getInitActivityId(errorContext));
    TaskException exception = extract(errorContext.getCause(), TaskException.class);
    String stacktrace = getStackTrace(exception);
    Task task = errorContext.getLastExecutedTask();
    if (task != null) {
        taskErrorBuilder.deploymentId(task.getTaskData().getDeploymentId()).processInstanceId(task.getTaskData().getProcessInstanceId()).processId(task.getTaskData().getProcessId()).activityId(task.getId()).activityName(task.getName());
    }
    return taskErrorBuilder.message(exception.getMessage()).error(stacktrace).errorDate(new Date()).build();
}
Also used : Task(org.kie.api.task.model.Task) TaskException(org.kie.internal.task.exception.TaskException) Builder(org.kie.internal.runtime.error.ExecutionError.Builder) Date(java.util.Date)

Aggregations

TaskException (org.kie.internal.task.exception.TaskException)3 Date (java.util.Date)2 Task (org.kie.api.task.model.Task)2 TransactionAware (org.drools.persistence.api.TransactionAware)1 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)1 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)1 KieSession (org.kie.api.runtime.KieSession)1 RequestContext (org.kie.api.runtime.RequestContext)1 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1 Builder (org.kie.internal.runtime.error.ExecutionError.Builder)1 InternalTaskService (org.kie.internal.task.api.InternalTaskService)1