You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by GitBox <gi...@apache.org> on 2022/11/02 20:25:25 UTC

[GitHub] [fineract] ezolnbl-dpc commented on a diff in pull request #2718: FINEARCT-1744 add command execution 2 step transaction handling

ezolnbl-dpc commented on code in PR #2718:
URL: https://github.com/apache/fineract/pull/2718#discussion_r1012264824


##########
fineract-provider/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java:
##########
@@ -69,45 +76,43 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
     private final IdempotencyKeyGenerator idempotencyKeyGenerator;
     private final FineractProperties fineractProperties;
 
+    private final InitialCommandSaver initialCommandSaver;
+
     @Transactional
     @Override
     public CommandProcessingResult executeCommand(final CommandWrapper wrapper, final JsonCommand command,
             final boolean isApprovedByChecker) {
 
         final boolean rollbackTransaction = configurationDomainService.isMakerCheckerEnabledForTask(wrapper.taskPermissionName());
+        String idempotencyKey = getIdempotencyKey(wrapper);
+        CommandSource existingCommand = commandSourceRepository.findByActionNameAndEntityNameAndIdempotencyKey(wrapper.actionName(),
+                wrapper.entityName(), idempotencyKey);
+        final CommandProcessingResult result;
+        if (existingCommand != null) {
+            if (UNDER_PROCESSING.getValue().equals(existingCommand.getStatus())) {
+                throw new DuplicateCommandException(wrapper.actionName(), wrapper.entityName(), wrapper.getIdempotencyKey(),
+                        wrapper.getJson(), UNDER_PROCESSING.getValue());
+            } else if (ERROR.getValue().equals(existingCommand.getStatus())) {
+                throw new DuplicateCommandException(wrapper.actionName(), wrapper.entityName(), wrapper.getIdempotencyKey(),
+                        existingCommand.getResult(), ERROR.getValue());
+            } else if (PROCESSED.getValue().equals(existingCommand.getStatus())) {
+                throw new DuplicateCommandException(wrapper.actionName(), wrapper.entityName(), wrapper.getIdempotencyKey(),

Review Comment:
   this solution with the custom error mapper completely satisfy the specification, tested, works



##########
fineract-provider/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java:
##########
@@ -69,45 +76,43 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
     private final IdempotencyKeyGenerator idempotencyKeyGenerator;
     private final FineractProperties fineractProperties;
 
+    private final InitialCommandSaver initialCommandSaver;
+
     @Transactional
     @Override
     public CommandProcessingResult executeCommand(final CommandWrapper wrapper, final JsonCommand command,
             final boolean isApprovedByChecker) {
 
         final boolean rollbackTransaction = configurationDomainService.isMakerCheckerEnabledForTask(wrapper.taskPermissionName());
+        String idempotencyKey = getIdempotencyKey(wrapper);
+        CommandSource existingCommand = commandSourceRepository.findByActionNameAndEntityNameAndIdempotencyKey(wrapper.actionName(),
+                wrapper.entityName(), idempotencyKey);
+        final CommandProcessingResult result;
+        if (existingCommand != null) {
+            if (UNDER_PROCESSING.getValue().equals(existingCommand.getStatus())) {
+                throw new DuplicateCommandException(wrapper.actionName(), wrapper.entityName(), wrapper.getIdempotencyKey(),
+                        wrapper.getJson(), UNDER_PROCESSING.getValue());
+            } else if (ERROR.getValue().equals(existingCommand.getStatus())) {
+                throw new DuplicateCommandException(wrapper.actionName(), wrapper.entityName(), wrapper.getIdempotencyKey(),

Review Comment:
   this solution with the custom error mapper completely satisfy the specification, tested, works, but it is an open question what and how to save to the result column in case of a generic error, waiting for answer...



-- 
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-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org