Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Oct 31, 2024
1 parent b97cedd commit 1f5e4dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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> processes;
Instance<Processes> 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<? extends Model> processInstance = ((AbstractProcessInstance<? extends Model>) 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<? extends Model> processInstance = ((AbstractProcessInstance<? extends Model>) instance.get());
((WorkflowProcessInstanceImpl) processInstance.internalGetProcessInstance()).internalSetError(processInstanceExecutionException);
((MutableProcessInstances) processDefinition.get().instances()).update(processInstanceId, processInstance);
return null;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<? extends Model> processInstance = ((AbstractProcessInstance<? extends Model>) 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<? extends Model> processInstance = ((AbstractProcessInstance<? extends Model>) instance.get());
((WorkflowProcessInstanceImpl) processInstance.internalGetProcessInstance()).internalSetError(processInstanceExecutionException);
((MutableProcessInstances) processDefinition.get().instances()).update(processInstanceId, processInstance);
return null;
});
}
Expand Down

0 comments on commit 1f5e4dd

Please sign in to comment.