Fix datatable put call with resource id

This commit is contained in:
Jose Alberto Hernandez
2022-11-24 15:41:22 +01:00
committed by Arnold Gálovics
parent a1a6435283
commit 729316e4a0
4 changed files with 41 additions and 33 deletions
@@ -21,7 +21,6 @@ package org.apache.fineract.infrastructure.dataqueries.handler;
import org.apache.fineract.commands.handler.NewCommandSourceHandler; import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; 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.apache.fineract.infrastructure.dataqueries.service.ReadWriteNonCoreDataService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -41,18 +40,8 @@ public class UpdateOneToManyDatatableEntryCommandHandler implements NewCommandSo
@Override @Override
public CommandProcessingResult processCommand(final JsonCommand command) { public CommandProcessingResult processCommand(final JsonCommand command) {
final CommandProcessingResult commandProcessingResult = this.writePlatformService return this.writePlatformService.updateDatatableEntryOneToMany(command.entityName(), command.entityId(), command.subentityId(),
.updateDatatableEntryOneToMany(command.entityName(), command.entityId(), command.subentityId(), command); 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();
} }
} }
@@ -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()) // .withOfficeId(commandProcessingResult.getOfficeId()) //
.withGroupId(commandProcessingResult.getGroupId()) // .withGroupId(commandProcessingResult.getGroupId()) //
.withClientId(commandProcessingResult.getClientId()) // .withClientId(commandProcessingResult.getClientId()) //
.withSavingsId(commandProcessingResult.getSavingsId()) // .withSavingsId(commandProcessingResult.getSavingsId()) //
.withLoanId(commandProcessingResult.getLoanId()) // .withLoanId(commandProcessingResult.getLoanId()) //
.with(changes) // .with(changes).build();
.build();
} }
@Transactional @Transactional
@@ -1477,7 +1477,8 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
SQLInjectionValidator.validateSQLInput(whereClause); SQLInjectionValidator.validateSQLInput(whereClause);
String sql = "select * from " + sqlGenerator.escape(dataTableName) + " where " + 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) { if (multiRow && id != null) {
sql = sql + " and id = " + id; sql = sql + " and id = " + id;
} }
@@ -1503,7 +1504,8 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
SQLInjectionValidator.validateSQLInput(whereClause); SQLInjectionValidator.validateSQLInput(whereClause);
String sql = "select * from " + sqlGenerator.escape(dataTableName) + " where " + 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) { if (multiRow && id != null) {
sql = sql + " and id = " + id; sql = sql + " and id = " + id;
} }
@@ -41,6 +41,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.fineract.client.models.PutDataTablesAppTableIdDatatableIdResponse;
import org.apache.fineract.client.util.Calls; import org.apache.fineract.client.util.Calls;
import org.apache.fineract.integrationtests.client.IntegrationTest; import org.apache.fineract.integrationtests.client.IntegrationTest;
import org.apache.fineract.integrationtests.common.ClientHelper; 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(8));
assertNull(((List) ((Map) ((List) items.get("data")).get(1)).get("row")).get(9)); assertNull(((List) ((Map) ((List) items.get("data")).get(1)).get("row")).get(9));
HashMap<String, Object> updatedDatatableEntryResponse = this.datatableHelper.updateDatatableEntry(datatableName, loanID, 1, false, PutDataTablesAppTableIdDatatableIdResponse updatedDatatableEntryResponse = this.datatableHelper.updateDatatableEntry(datatableName,
datatableEntryRequestJsonString); loanID, 1, datatableEntryRequestJsonString);
assertNotNull(updatedDatatableEntryResponse);
assertEquals(null, updatedDatatableEntryResponse.get("changes")); assertEquals(0, updatedDatatableEntryResponse.getChanges().size());
} }
@Test @Test
@@ -591,20 +592,25 @@ public class DatatableIntegrationTest extends IntegrationTest {
datatabelEntryRequestJsonString = new GsonBuilder().serializeNulls().create().toJson(datatableEntryMap); datatabelEntryRequestJsonString = new GsonBuilder().serializeNulls().create().toJson(datatableEntryMap);
LOG.info("map : {}", datatabelEntryRequestJsonString); 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); datatabelEntryRequestJsonString);
this.datatableHelper.updateDatatableEntry(datatableName, loanID, 2, false, datatabelEntryRequestJsonString); assertNotNull(updatedDatatableEntryResponse);
assertEquals(2L, updatedDatatableEntryResponse.getResourceId());
assertEquals(loanID, updatedDatatableEntryResponse.get("loanId")); assertEquals(Long.valueOf(loanID), updatedDatatableEntryResponse.getLoanId());
assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsABoolean")); assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsABoolean"));
assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsADate")); assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsADate"));
assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsADecimal")); assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsADecimal"));
assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsADatetime")); assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsADatetime"));
assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get(tst_tst_tst + "_cd_itsADropdown")); assertEquals(null, updatedDatatableEntryResponse.getChanges().get(tst_tst_tst + "_cd_itsADropdown"));
assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsANumber")); assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsANumber"));
assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsAString")); assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsAString"));
assertEquals(null, ((Map) updatedDatatableEntryResponse.get("changes")).get("itsAText")); assertEquals(null, updatedDatatableEntryResponse.getChanges().get("itsAText"));
items = this.datatableHelper.readDatatableEntry(datatableName, loanID, genericResultSet, null, ""); items = this.datatableHelper.readDatatableEntry(datatableName, loanID, genericResultSet, null, "");
assertNotNull(items); assertNotNull(items);
@@ -30,12 +30,16 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Objects; 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.apache.fineract.integrationtests.common.Utils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class DatatableHelper { public class DatatableHelper {
private static final Gson GSON = new JSON().getGson();
private static final Logger LOG = LoggerFactory.getLogger(DatatableHelper.class); private static final Logger LOG = LoggerFactory.getLogger(DatatableHelper.class);
private final RequestSpecification requestSpec; private final RequestSpecification requestSpec;
private final ResponseSpecification responseSpec; private final ResponseSpecification responseSpec;
@@ -75,6 +79,13 @@ public class DatatableHelper {
+ entryId + "?genericResultSet=" + genericResultSet + "&" + Utils.TENANT_IDENTIFIER, json, ""); + 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, public Integer createDatatableEntry(final String apptableName, final String datatableName, final Integer apptableId,
final boolean genericResultSet, final String dateFormat, final String jsonAttributeToGetBack) { final boolean genericResultSet, final String dateFormat, final String jsonAttributeToGetBack) {
return Utils.performServerPost( return Utils.performServerPost(