You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ar...@apache.org on 2022/11/24 14:41:28 UTC

[fineract] branch develop updated: Fix datatable put call with resource id

This is an automated email from the ASF dual-hosted git repository.

arnold pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 729316e4a Fix datatable put call with resource id
729316e4a is described below

commit 729316e4a0db784a0757e3e47f3b086a27dedfd4
Author: Jose Alberto Hernandez <al...@MacBook-Pro.local>
AuthorDate: Thu Nov 17 07:26:42 2022 -0600

    Fix datatable put call with resource id
---
 ...pdateOneToManyDatatableEntryCommandHandler.java | 15 ++------
 .../service/ReadWriteNonCoreDataServiceImpl.java   | 12 ++++---
 .../integrationtests/DatatableIntegrationTest.java | 40 +++++++++++++---------
 .../common/system/DatatableHelper.java             | 11 ++++++
 4 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/handler/UpdateOneToManyDatatableEntryCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/handler/UpdateOneToManyDatatableEntryCommandHandler.java
index d7da9877b..cc4955ab6 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/handler/UpdateOneToManyDatatableEntryCommandHandler.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/handler/UpdateOneToManyDatatableEntryCommandHandler.java
@@ -21,7 +21,6 @@ package org.apache.fineract.infrastructure.dataqueries.handler;
 import org.apache.fineract.commands.handler.NewCommandSourceHandler;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
-import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
 import org.apache.fineract.infrastructure.dataqueries.service.ReadWriteNonCoreDataService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -41,18 +40,8 @@ public class UpdateOneToManyDatatableEntryCommandHandler implements NewCommandSo
     @Override
     public CommandProcessingResult processCommand(final JsonCommand command) {
 
-        final CommandProcessingResult commandProcessingResult = this.writePlatformService
-                .updateDatatableEntryOneToMany(command.entityName(), command.entityId(), command.subentityId(), command);
+        return this.writePlatformService.updateDatatableEntryOneToMany(command.entityName(), command.entityId(), command.subentityId(),
+                command);
 
-        return new CommandProcessingResultBuilder() //
-                .withCommandId(command.commandId()) //
-                .withEntityId(command.entityId()) //
-                .withOfficeId(commandProcessingResult.getOfficeId()) //
-                .withGroupId(commandProcessingResult.getGroupId()) //
-                .withClientId(commandProcessingResult.getClientId()) //
-                .withSavingsId(commandProcessingResult.getSavingsId()) //
-                .withLoanId(commandProcessingResult.getLoanId()) //
-                .with(commandProcessingResult.getChanges()) //
-                .build();
     }
 }
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java
index 698fd8123..b1cb16292 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java
@@ -1415,14 +1415,14 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
             }
         }
 
-        return new CommandProcessingResultBuilder() //
+        return new CommandProcessingResultBuilder().withCommandId(command.commandId()) //
+                .withEntityId(datatableId != null ? command.subentityId() : command.entityId()) //
                 .withOfficeId(commandProcessingResult.getOfficeId()) //
                 .withGroupId(commandProcessingResult.getGroupId()) //
                 .withClientId(commandProcessingResult.getClientId()) //
                 .withSavingsId(commandProcessingResult.getSavingsId()) //
                 .withLoanId(commandProcessingResult.getLoanId()) //
-                .with(changes) //
-                .build();
+                .with(changes).build();
     }
 
     @Transactional
@@ -1477,7 +1477,8 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
         SQLInjectionValidator.validateSQLInput(whereClause);
         String sql = "select * from " + sqlGenerator.escape(dataTableName) + " where " + whereClause;
 
-        // id only used for reading a specific entry that belongs to appTableId (in a one to many datatable)
+        // id only used for reading a specific entry that belongs to appTableId (in a
+        // one to many datatable)
         if (multiRow && id != null) {
             sql = sql + " and id = " + id;
         }
@@ -1503,7 +1504,8 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
         SQLInjectionValidator.validateSQLInput(whereClause);
         String sql = "select * from " + sqlGenerator.escape(dataTableName) + " where " + whereClause;
 
-        // id only used for reading a specific entry that belongs to appTableId (in a one to many datatable)
+        // id only used for reading a specific entry that belongs to appTableId (in a
+        // one to many datatable)
         if (multiRow && id != null) {
             sql = sql + " and id = " + id;
         }
diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/DatatableIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/DatatableIntegrationTest.java
index eed138d0e..14b221b2e 100644
--- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/DatatableIntegrationTest.java
+++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/DatatableIntegrationTest.java
@@ -41,6 +41,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import org.apache.fineract.client.models.PutDataTablesAppTableIdDatatableIdResponse;
 import org.apache.fineract.client.util.Calls;
 import org.apache.fineract.integrationtests.client.IntegrationTest;
 import org.apache.fineract.integrationtests.common.ClientHelper;
@@ -419,10 +420,10 @@ public class DatatableIntegrationTest extends IntegrationTest {
         assertNull(((List) ((Map) ((List) items.get("data")).get(1)).get("row")).get(8));
         assertNull(((List) ((Map) ((List) items.get("data")).get(1)).get("row")).get(9));
 
-        HashMap<String, Object> updatedDatatableEntryResponse = this.datatableHelper.updateDatatableEntry(datatableName, loanID, 1, false,
-                datatableEntryRequestJsonString);
-
-        assertEquals(null, updatedDatatableEntryResponse.get("changes"));
+        PutDataTablesAppTableIdDatatableIdResponse updatedDatatableEntryResponse = this.datatableHelper.updateDatatableEntry(datatableName,
+                loanID, 1, datatableEntryRequestJsonString);
+        assertNotNull(updatedDatatableEntryResponse);
+        assertEquals(0, updatedDatatableEntryResponse.getChanges().size());
     }
 
     @Test
@@ -591,20 +592,25 @@ public class DatatableIntegrationTest extends IntegrationTest {
         datatabelEntryRequestJsonString = new GsonBuilder().serializeNulls().create().toJson(datatableEntryMap);
         LOG.info("map : {}", datatabelEntryRequestJsonString);
 
-        HashMap<String, Object> updatedDatatableEntryResponse = this.datatableHelper.updateDatatableEntry(datatableName, loanID, 1, false,
+        PutDataTablesAppTableIdDatatableIdResponse updatedDatatableEntryResponse = this.datatableHelper.updateDatatableEntry(datatableName,
+                loanID, 1, datatabelEntryRequestJsonString);
+        assertNotNull(updatedDatatableEntryResponse);
+        assertEquals(1L, updatedDatatableEntryResponse.getResourceId());
+        updatedDatatableEntryResponse = this.datatableHelper.updateDatatableEntry(datatableName, loanID, 2,
                 datatabelEntryRequestJsonString);
-        this.datatableHelper.updateDatatableEntry(datatableName, loanID, 2, false, datatabelEntryRequestJsonString);
-
-        assertEquals(loanID, updatedDatatableEntryResponse.get("loanId"));
-
-        assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsABoolean"));
-        assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsADate"));
-        assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsADecimal"));
-        assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsADatetime"));
-        assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get(tst_tst_tst + "_cd_itsADropdown"));
-        assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsANumber"));
-        assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsAString"));
-        assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsAText"));
+        assertNotNull(updatedDatatableEntryResponse);
+        assertEquals(2L, updatedDatatableEntryResponse.getResourceId());
+
+        assertEquals(Long.valueOf(loanID), updatedDatatableEntryResponse.getLoanId());
+
+        assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsABoolean"));
+        assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsADate"));
+        assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsADecimal"));
+        assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsADatetime"));
+        assertEquals(null, updatedDatatableEntryResponse.getChanges().get(tst_tst_tst + "_cd_itsADropdown"));
+        assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsANumber"));
+        assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsAString"));
+        assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsAText"));
 
         items = this.datatableHelper.readDatatableEntry(datatableName, loanID, genericResultSet, null, "");
         assertNotNull(items);
diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/system/DatatableHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/system/DatatableHelper.java
index d3c426335..a47ae6ed5 100644
--- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/system/DatatableHelper.java
+++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/system/DatatableHelper.java
@@ -30,12 +30,16 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Objects;
+import org.apache.fineract.client.models.PutDataTablesAppTableIdDatatableIdResponse;
+import org.apache.fineract.client.util.JSON;
 import org.apache.fineract.integrationtests.common.Utils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class DatatableHelper {
 
+    private static final Gson GSON = new JSON().getGson();
+
     private static final Logger LOG = LoggerFactory.getLogger(DatatableHelper.class);
     private final RequestSpecification requestSpec;
     private final ResponseSpecification responseSpec;
@@ -75,6 +79,13 @@ public class DatatableHelper {
                 + entryId + "?genericResultSet=" + genericResultSet + "&" + Utils.TENANT_IDENTIFIER, json, "");
     }
 
+    public PutDataTablesAppTableIdDatatableIdResponse updateDatatableEntry(final String datatableName, final Integer apptableId,
+            final Integer entryId, final String json) {
+        final String response = Utils.performServerPut(this.requestSpec, this.responseSpec, DATATABLE_URL + "/" + datatableName + "/"
+                + apptableId + "/" + entryId + "?genericResultSet=false&" + Utils.TENANT_IDENTIFIER, json, null);
+        return GSON.fromJson(response, PutDataTablesAppTableIdDatatableIdResponse.class);
+    }
+
     public Integer createDatatableEntry(final String apptableName, final String datatableName, final Integer apptableId,
             final boolean genericResultSet, final String dateFormat, final String jsonAttributeToGetBack) {
         return Utils.performServerPost(