Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public LoanRepaymentImportHandler(final PortfolioCommandSourceWritePlatformServi
public Count process(final Workbook workbook, final String locale, final String dateFormat) {

List<LoanTransactionData> loanRepayments = readExcelFile(workbook, locale, dateFormat);
return importEntity(workbook, loanRepayments, dateFormat);
return importEntity(workbook, loanRepayments, dateFormat, locale);
}

private List<LoanTransactionData> readExcelFile(final Workbook workbook, final String locale, final String dateFormat) {
Expand Down Expand Up @@ -110,13 +110,14 @@ private LoanTransactionData readLoanRepayment(final Workbook workbook, Long loan
receiptNumber, bankNumber, loanAccountId, EMPTY_STR, row.getRowNum(), locale, dateFormat);
}

private Count importEntity(final Workbook workbook, final List<LoanTransactionData> loanRepayments, final String dateFormat) {
private Count importEntity(final Workbook workbook, final List<LoanTransactionData> loanRepayments, final String dateFormat,
final String locale) {
Sheet loanRepaymentSheet = workbook.getSheet(TemplatePopulateImportConstants.LOAN_REPAYMENT_SHEET_NAME);
int successCount = 0;
int errorCount = 0;
String errorMessage;
GsonBuilder gsonBuilder = GoogleGsonSerializerHelper.createGsonBuilder();
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat));
gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat, locale));

for (LoanTransactionData loanRepayment : loanRepayments) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void validate(final String json, final boolean fromNewClient) {

supportedParameters.add("locale");
supportedParameters.add("dateFormat");
supportedParameters.add("street");
supportedParameters.add(fromNewClient ? "addressTypeId" : "addressId");

this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void validateForCreate(final String json) {

if (this.configurationReadPlatformService.retrieveGlobalConfiguration(GlobalConfigurationConstants.ENABLE_ADDRESS).isEnabled()) {
final JsonArray address = this.fromApiJsonHelper.extractJsonArrayNamed(ClientApiConstants.address, element);
baseDataValidator.reset().parameter(ClientApiConstants.address).value(address).notNull().jsonArrayNotEmpty();
baseDataValidator.reset().parameter(ClientApiConstants.address).value(address).ignoreIfNull().jsonArrayNotEmpty();
}

List<ApiParameterError> dataValidationErrorsForClientNonPerson = getDataValidationErrorsForCreateOnClientNonPerson(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
*/
package org.apache.fineract.portfolio.client.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonElement;
import jakarta.persistence.PersistenceException;
import java.time.LocalDate;
Expand Down Expand Up @@ -315,7 +319,10 @@ public CommandProcessingResult createClient(final JsonCommand command) {
extractAndCreateClientNonPerson(newClient, command);
}

if (isAddressEnabled) {
ObjectMapper mapper = new ObjectMapper();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks incorrect to me...

Map<String, Object> map = mapper.readValue(command.getJsonCommand(), new TypeReference<Map<String, Object>>() {});

if (map.get("address") != null) {
this.addressWritePlatformService.addNewClientAddress(newClient, command);
}

Expand Down Expand Up @@ -354,6 +361,10 @@ public CommandProcessingResult createClient(final JsonCommand command) {
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
handleDataIntegrityIssues(command, throwable, dve);
return CommandProcessingResult.empty();
} catch (JsonMappingException e) {
throw new RuntimeException(e);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ private void validatePaymentTransaction(String json) {

final Set<String> transactionParameters = new HashSet<>(
Arrays.asList("transactionDate", "transactionAmount", "externalId", "note", "locale", "dateFormat", "paymentTypeId",
"accountNumber", "checkNumber", "routingCode", "receiptNumber", "bankNumber", "loanId"));
"accountNumber", "checkNumber", "routingCode", "receiptNumber", "bankNumber", "loanId", "numberOfRepayments"));

final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, transactionParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public void validateForSubmit(final String json) {

if (lockinPeriodFrequency != null) {
final Integer lockinPeriodFrequencyType = this.fromApiJsonHelper
.extractIntegerSansLocaleNamed(lockinPeriodFrequencyTypeParamName, element);
baseDataValidator.reset().parameter(lockinPeriodFrequencyTypeParamName).value(lockinPeriodFrequencyType).ignoreIfNull()
.extractIntegerSansLocaleNamed(lockinPeriodFrequencyParamName, element);
baseDataValidator.reset().parameter(lockinPeriodFrequencyParamName).value(lockinPeriodFrequencyType).notNull()
.inMinMaxRange(0, 3);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1851,13 +1851,13 @@ private void validateLockinDetails(final DataValidatorBuilder baseDataValidator)
.inMinMaxRange(0, 3);

if (this.lockinPeriodFrequencyType != null) {
baseDataValidator.reset().parameter(lockinPeriodFrequencyParamName).value(this.lockinPeriodFrequency).notNull()
baseDataValidator.reset().parameter(lockinPeriodFrequencyParamName).value(this.lockinPeriodFrequency).ignoreIfNull()
.integerZeroOrGreater();
}
} else {
baseDataValidator.reset().parameter(lockinPeriodFrequencyParamName).value(this.lockinPeriodFrequencyType)
.integerZeroOrGreater();
baseDataValidator.reset().parameter(lockinPeriodFrequencyTypeParamName).value(this.lockinPeriodFrequencyType).notNull()
baseDataValidator.reset().parameter(lockinPeriodFrequencyTypeParamName).value(this.lockinPeriodFrequencyType).ignoreIfNull()
.inMinMaxRange(0, 3);
}
}
Expand Down
Loading