diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/ExceptionHandlerTransactionQuarkusTemplate.java b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/ExceptionHandlerTransactionQuarkusTemplate.java index e68ba7b19e5..3230f0d71bc 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/ExceptionHandlerTransactionQuarkusTemplate.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/ExceptionHandlerTransactionQuarkusTemplate.java @@ -39,38 +39,36 @@ @ApplicationScoped public class ExceptionHandlerTransaction implements ExceptionHandler { - private static final Logger LOG = LoggerFactory.getLogger(QuarkusExceptionHandler.class); + private static final Logger LOG = LoggerFactory.getLogger(ExceptionHandlerTransaction.class); @Inject UnitOfWorkManager unitOfWorkManager; @Inject - Instance processes; + Instance processesContainer; @Override @Transactional(value = TxType.REQUIRES_NEW) public void handle(Exception th) { - if (!processes.isResolvable()) { + if (processesContainer.isResolvable()) { return; } + + Processes processes = processesContainer.get(); if (th instanceof ProcessInstanceExecutionException) { ProcessInstanceExecutionException processInstanceExecutionException = (ProcessInstanceExecutionException) th; LOG.info("handling exception {} by the handler {}", th, this.getClass().getName()); UnitOfWorkExecutor.executeInUnitOfWork(unitOfWorkManager, () -> { String processInstanceId = processInstanceExecutionException.getProcessInstanceId(); - var processDefinition = processes.get().processByProcessInstanceId(processInstanceId); - if (processDefinition.isEmpty()) { - return null; - } + processes.processByProcessInstanceId(processInstanceId).ifPresent(processDefinition -> { + processDefinition.instances().findById(processInstanceId).ifPresent(instance -> { + AbstractProcessInstance processInstance = ((AbstractProcessInstance) instance); + ((WorkflowProcessInstanceImpl) processInstance.internalGetProcessInstance()).internalSetError(processInstanceExecutionException); + ((MutableProcessInstances) processDefinition.instances()).update(processInstanceId, processInstance); + }); - var instance = processDefinition.get().instances().findById(processInstanceId); - if (instance.isEmpty()) { - return null; - } + }); - AbstractProcessInstance processInstance = ((AbstractProcessInstance) instance.get()); - ((WorkflowProcessInstanceImpl) processInstance.internalGetProcessInstance()).internalSetError(processInstanceExecutionException); - ((MutableProcessInstances) processDefinition.get().instances()).update(processInstanceId, processInstance); return null; }); } diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/ExceptionHandlerTransactionSpringTemplate.java b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/ExceptionHandlerTransactionSpringTemplate.java index 02283d115a1..d9996d62f16 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/ExceptionHandlerTransactionSpringTemplate.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/ExceptionHandlerTransactionSpringTemplate.java @@ -37,7 +37,7 @@ @Component public class ExceptionHandlerTransaction implements ExceptionHandler { - private static final Logger LOG = LoggerFactory.getLogger(SpringbootExceptionHandler.class); + private static final Logger LOG = LoggerFactory.getLogger(ExceptionHandlerTransaction.class); @Autowired UnitOfWorkManager unitOfWorkManager; @@ -56,19 +56,15 @@ public void handle(Exception th) { LOG.info("handling exception {} by the handler {}", th, this.getClass().getName()); UnitOfWorkExecutor.executeInUnitOfWork(unitOfWorkManager, () -> { String processInstanceId = processInstanceExecutionException.getProcessInstanceId(); - var processDefinition = processes.processByProcessInstanceId(processInstanceId); - if (processDefinition.isEmpty()) { - return null; - } + processes.processByProcessInstanceId(processInstanceId).ifPresent(processDefinition -> { + processDefinition.instances().findById(processInstanceId).ifPresent(instance -> { + AbstractProcessInstance processInstance = ((AbstractProcessInstance) instance); + ((WorkflowProcessInstanceImpl) processInstance.internalGetProcessInstance()).internalSetError(processInstanceExecutionException); + ((MutableProcessInstances) processDefinition.instances()).update(processInstanceId, processInstance); + }); - var instance = processDefinition.get().instances().findById(processInstanceId); - if (instance.isEmpty()) { - return null; - } + }); - AbstractProcessInstance processInstance = ((AbstractProcessInstance) instance.get()); - ((WorkflowProcessInstanceImpl) processInstance.internalGetProcessInstance()).internalSetError(processInstanceExecutionException); - ((MutableProcessInstances) processDefinition.get().instances()).update(processInstanceId, processInstance); return null; }); }