avikganguly01 commented on a change in pull request #1466:
URL: https://github.com/apache/fineract/pull/1466#discussion_r512773604



##########
File path: 
fineract-provider/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java
##########
@@ -205,18 +225,80 @@ public boolean validateCommand(final CommandWrapper 
commandWrapper, final AppUse
         return rollbackTransaction;
     }
 
-    private void publishEvent(final String entityName, final String 
actionName, final CommandProcessingResult result) {
+    private void publishErrorEvent(CommandWrapper wrapper, JsonCommand 
command, Throwable t) {
+
+        ErrorInfo ex;
+        if (t instanceof RuntimeException) {
+            final RuntimeException e = (RuntimeException) t;
+            ex = ErrorHandler.handler(e);
+        } else {
+            ex = new ErrorInfo(500, 9999, "{\"Exception\": " + t.toString() + 
"}");
+        }
+
+        publishEvent(wrapper.entityName(), wrapper.actionName(), command, ex);
+    }
+
+    private void publishEvent(final String entityName, final String 
actionName, JsonCommand command, final Object result) {
+        Gson gson = new Gson();
+        try {
+            final String authToken = ThreadLocalContextUtil.getAuthToken();
+            final String tenantIdentifier = 
ThreadLocalContextUtil.getTenant().getTenantIdentifier();
+            final AppUser appUser = 
this.context.authenticatedUser(CommandWrapper.wrap(actionName, entityName, 
null, null));
+
+            final HookEventSource hookEventSource = new 
HookEventSource(entityName, actionName);
 
-        final String authToken = ThreadLocalContextUtil.getAuthToken();
-        final String tenantIdentifier = 
ThreadLocalContextUtil.getTenant().getTenantIdentifier();
-        final AppUser appUser = 
this.context.authenticatedUser(CommandWrapper.wrap(actionName, entityName, 
null, null));
+            // TODO: Add support for publishing array events
+            if (command.json() != null && command.json().startsWith("{")) {
+                Type type = new TypeToken<Map<String, Object>>() {}.getType();
+                Map<String, Object> myMap = gson.fromJson(command.json(), 
type);
 
-        final HookEventSource hookEventSource = new 
HookEventSource(entityName, actionName);
+                Map<String, Object> reqmap = new HashMap<>();
+                reqmap.put("entityName", entityName);
+                reqmap.put("actionName", actionName);
+                reqmap.put("createdBy", context.authenticatedUser().getId());
+                reqmap.put("createdByName", 
context.authenticatedUser().getUsername());
+                reqmap.put("createdByFullName", 
context.authenticatedUser().getDisplayName());
 
-        final String serializedResult = 
this.toApiResultJsonSerializer.serialize(result);
+                reqmap.put("request", myMap);
+                if (result instanceof CommandProcessingResult) {
+                    CommandProcessingResult resultCopy = 
CommandProcessingResult
+                            
.fromCommandProcessingResult((CommandProcessingResult) result);
+                    if (resultCopy.hasChanges() && 
resultCopy.getChanges().containsKey("receipt")
+                            && resultCopy.getChanges().get("receipt") 
instanceof String) {
+                        String receipt = (String) 
resultCopy.getChanges().get("receipt");
+                        if (receipt.startsWith("{")) {
+                            try {
+                                resultCopy.getChanges().put("receiptObj", 
gson.fromJson(receipt, JsonObject.class));

Review comment:
       Don't think this receiptObj exists in any APIs.




----------------------------------------------------------------
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.

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


Reply via email to