marta-jankovics commented on code in PR #3471: URL: https://github.com/apache/fineract/pull/3471#discussion_r1336851239
########## fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java: ########## @@ -88,92 +90,91 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer public CommandProcessingResult executeCommand(final CommandWrapper wrapper, final JsonCommand command, final boolean isApprovedByChecker) { // Do not store the idempotency key because of the exception handling - setIdempotencyKeyStoreFlag(false); + // setIdempotencyKeyStoreFlag(false); - final boolean rollbackTransaction = configurationDomainService.isMakerCheckerEnabledForTask(wrapper.taskPermissionName()); - String idempotencyKey = idempotencyKeyResolver.resolve(wrapper); - exceptionWhenTheRequestAlreadyProcessed(wrapper, idempotencyKey); + Long commandId = (Long) fineractRequestContextHolder.getAttribute(COMMAND_SOURCE_ID, null); + boolean isRetry = commandId != null; - // Store idempotency key to the request attribute - CommandSource savedCommandSource; - if (BatchRequestContextHolder.getEnclosingTransaction().isPresent()) { - savedCommandSource = commandSourceService.saveInitialNoTransaction(wrapper, command, context.authenticatedUser(wrapper), - idempotencyKey); + CommandSource commandSource = null; + String idempotencyKey; + if (isRetry) { + commandSource = commandSourceService.getCommandSource(commandId); + idempotencyKey = commandSource.getIdempotencyKey(); } else { - savedCommandSource = commandSourceService.saveInitial(wrapper, command, context.authenticatedUser(wrapper), idempotencyKey); + idempotencyKey = idempotencyKeyResolver.resolve(wrapper); } - storeCommandToIdempotentFilter(savedCommandSource); - setIdempotencyKeyStoreFlag(true); + exceptionWhenTheRequestAlreadyProcessed(wrapper, idempotencyKey, isRetry); + + if (commandSource == null) { + commandSource = commandSourceService.saveInitial(wrapper, command, context.authenticatedUser(wrapper), idempotencyKey); + storeCommandIdInContext(commandSource); // Store command id as a request attribute + } + // setIdempotencyKeyStoreFlag(true); final CommandProcessingResult result; try { result = findCommandHandler(wrapper).processCommand(command); } catch (Throwable t) { // NOSONAR - CommandSource source = commandSourceService.findCommandSource(wrapper, idempotencyKey); - commandSourceService.saveFailed(source); - publishHookErrorEvent(wrapper, command, t); + ErrorInfo errorInfo = commandSourceService.generateErrorInfo(t); + commandSource.setResultStatusCode(errorInfo.getStatusCode()); + commandSource.setResult(errorInfo.getMessage()); + commandSourceService.saveFailed(commandSource); + publishHookErrorEvent(wrapper, command, errorInfo); throw t; } - CommandSource initialCommandSource = commandSourceService.findCommandSource(wrapper, idempotencyKey); - initialCommandSource.setResult(toApiJsonSerializer.serializeResult(result)); - initialCommandSource.updateResourceId(result.getResourceId()); - initialCommandSource.updateForAudit(result); + commandSource.updateForAudit(result); + commandSource.setResult(toApiJsonSerializer.serializeResult(result)); + commandSource.setResultStatusCode(SC_OK); - boolean rollBack = (rollbackTransaction || result.isRollbackTransaction()) && !isApprovedByChecker; - if (result.hasChanges() && !rollBack) { - initialCommandSource.setCommandJson(toApiJsonSerializer.serializeResult(result.getChanges())); - } + boolean isRollback = !isApprovedByChecker && (result.isRollbackTransaction() Review Comment: Probably I will separate this anyway, because it needs a community agreement. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@fineract.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org