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


##########
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(),
+                        existingCommand.getResult(), PROCESSED.getValue());
+            }
+        }
 
-        final NewCommandSourceHandler handler = findCommandHandler(wrapper);
+        final AppUser maker = context.authenticatedUser(wrapper);
+        CommandSource commandSourceResult = getInitialCommandSource(wrapper, 
command, maker, idempotencyKey);
+        initialCommandSaver.save(commandSourceResult);
 
-        final CommandProcessingResult result;
         try {
-            result = handler.processCommand(command);
+            result = findCommandHandler(wrapper).processCommand(command);
         } catch (Throwable t) {
             publishHookErrorEvent(wrapper, command, t);
             throw t;
         }
 
-        final AppUser maker = context.authenticatedUser(wrapper);
-
-        CommandSource commandSourceResult;
-        if (command.commandId() != null) {
-            commandSourceResult = 
commandSourceRepository.findById(command.commandId())
-                    .orElseThrow(() -> new 
CommandNotFoundException(command.commandId()));
-            commandSourceResult.markAsChecked(maker);
-        } else {
-            String requestIdempotencyKey = null;
-            RequestAttributes requestAttributes = 
RequestContextHolder.getRequestAttributes();
-            if (requestAttributes != null) {
-                if (requestAttributes instanceof ServletRequestAttributes) {
-                    requestIdempotencyKey = ((ServletRequestAttributes) 
requestAttributes).getRequest()
-                            
.getHeader(fineractProperties.getIdempotencyKeyHeaderName());
-                }
-            }
-
-            commandSourceResult = CommandSource.fullEntryFrom(wrapper, 
command, maker,
-                    wrapper.getIdempotencyKey() == null
-                            ? (requestIdempotencyKey == null ? 
idempotencyKeyGenerator.create() : requestIdempotencyKey)
-                            : wrapper.getIdempotencyKey());
-        }
+        
commandSourceResult.setResult(toApiJsonSerializer.serializeResult(result)); // 
TODO

Review Comment:
   just leftover



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to