diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/exception/LoanCollateralNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/exception/LoanCollateralNotFoundException.java deleted file mode 100644 index 3abc4e755..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/exception/LoanCollateralNotFoundException.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.charge.exception; - -import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException; -import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException; - -/** - * {@link AbstractPlatformDomainRuleException} thrown when loan collateral does - * not exist. - */ -public class LoanCollateralNotFoundException extends AbstractPlatformResourceNotFoundException { - - public LoanCollateralNotFoundException(final Long id) { - super("error.msg.loanCollateral.id.invalid", "Loan collateral with identifier " + id + " does not exist", id); - } - - public LoanCollateralNotFoundException(final Long id, final Long loanId) { - super("error.msg.loanCollateral.id.invalid.for.given.loan", "Loan collateral with identifier " + id + " does not exist for loan " - + loanId, id, loanId); - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collateral/exception/CollateralNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collateral/exception/CollateralNotFoundException.java index badf7716f..a0b1ded9c 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collateral/exception/CollateralNotFoundException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collateral/exception/CollateralNotFoundException.java @@ -16,4 +16,8 @@ public class CollateralNotFoundException extends AbstractPlatformResourceNotFoun super("error.msg.loan.collateral.", "Collateral with Id " + collateralId + " does not exist for loan with Id " + loanId, loanId, collateralId); } + + public CollateralNotFoundException(final Long id) { + super("error.msg.loan.collateral.id.invalid", "Loan collateral with identifier " + id + " does not exist", id); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collateral/service/CollateralAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collateral/service/CollateralAssembler.java index d0400df21..e325c23f1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collateral/service/CollateralAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collateral/service/CollateralAssembler.java @@ -13,9 +13,9 @@ import java.util.Set; import org.mifosplatform.infrastructure.codes.domain.CodeValue; import org.mifosplatform.infrastructure.codes.domain.CodeValueRepositoryWrapper; import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; -import org.mifosplatform.portfolio.charge.exception.LoanCollateralNotFoundException; import org.mifosplatform.portfolio.collateral.domain.LoanCollateral; import org.mifosplatform.portfolio.collateral.domain.LoanCollateralRepository; +import org.mifosplatform.portfolio.collateral.exception.CollateralNotFoundException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -62,7 +62,7 @@ public class CollateralAssembler { collateralItems.add(LoanCollateral.from(collateralType, value, description)); } else { LoanCollateral loanCollateralItem = this.loanCollateralRepository.findOne(id); - if (loanCollateralItem == null) { throw new LoanCollateralNotFoundException(id); } + if (loanCollateralItem == null) { throw new CollateralNotFoundException(id); } loanCollateralItem.assembleFrom(collateralType, value, description); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java index be516ef32..5f0b6c380 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java @@ -213,7 +213,7 @@ public final class LoanApplicationCommandFromApiJsonHelper { final Long calendarId = fromApiJsonHelper.extractLongNamed(calendarIdParameterName, element); baseDataValidator.reset().parameter(calendarIdParameterName).value(calendarId).ignoreIfNull().integerGreaterThanZero(); } - + // charges final String chargesParameterName = "charges"; if (element.isJsonObject() && fromApiJsonHelper.parameterExists(chargesParameterName, element)) { @@ -250,10 +250,11 @@ public final class LoanApplicationCommandFromApiJsonHelper { final String collateralParameterName = "collateral"; if (element.isJsonObject() && fromApiJsonHelper.parameterExists(collateralParameterName, element)) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); + final Locale locale = fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); if (topLevelJsonElement.get("collateral").isJsonArray()) { final Type collateralParameterTypeOfMap = new TypeToken>() {}.getType(); - final Set supportedParameters = new HashSet(Arrays.asList("id", "type", "description")); + final Set supportedParameters = new HashSet(Arrays.asList("id", "type", "value", "description")); final JsonArray array = topLevelJsonElement.get("collateral").getAsJsonArray(); for (int i = 1; i <= array.size(); i++) { final JsonObject collateralItemElement = array.get(i - 1).getAsJsonObject(); @@ -265,6 +266,10 @@ public final class LoanApplicationCommandFromApiJsonHelper { baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("type", i).value(collateralTypeId).notNull() .integerGreaterThanZero(); + final BigDecimal collateralValue = fromApiJsonHelper.extractBigDecimalNamed("value", collateralItemElement, locale); + baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("value", i).value(collateralValue) + .ignoreIfNull().positiveAmount(); + final String description = fromApiJsonHelper.extractStringNamed("description", collateralItemElement); baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("description", i).value(description).notBlank() .notExceedingLengthOf(500); @@ -527,10 +532,11 @@ public final class LoanApplicationCommandFromApiJsonHelper { final String collateralParameterName = "collateral"; if (element.isJsonObject() && fromApiJsonHelper.parameterExists(collateralParameterName, element)) { final JsonObject topLevelJsonElement = element.getAsJsonObject(); + final Locale locale = fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); if (topLevelJsonElement.get("collateral").isJsonArray()) { final Type collateralParameterTypeOfMap = new TypeToken>() {}.getType(); - final Set supportedParameters = new HashSet(Arrays.asList("id", "type", "description")); + final Set supportedParameters = new HashSet(Arrays.asList("id", "type", "value", "description")); final JsonArray array = topLevelJsonElement.get("collateral").getAsJsonArray(); for (int i = 1; i <= array.size(); i++) { final JsonObject collateralItemElement = array.get(i - 1).getAsJsonObject(); @@ -542,6 +548,10 @@ public final class LoanApplicationCommandFromApiJsonHelper { baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("type", i).value(collateralTypeId).notNull() .integerGreaterThanZero(); + final BigDecimal collateralValue = fromApiJsonHelper.extractBigDecimalNamed("value", collateralItemElement, locale); + baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("value", i).value(collateralValue) + .ignoreIfNull().positiveAmount(); + final String description = fromApiJsonHelper.extractStringNamed("description", collateralItemElement); baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("description", i).value(description).notBlank() .notExceedingLengthOf(500);