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);
}
}
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);
}
}
}
}
}
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();
}
Aggregations