From 5a492e03db062694daa2f02f917e3774ae28555d Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Sat, 1 Dec 2012 17:09:49 +0000 Subject: [PATCH] MIFOSX-97: move gaurantor under loan account for now. --- .../platform/api/GuarantorsApiResource.java | 8 +- .../guarantor/GuarantorCommandValidator.java | 119 ------------------ .../GuarantorReadPlatformService.java | 13 -- .../GuarantorWritePlatformService.java | 17 --- ...GsonPortfolioApiJsonSerializerService.java | 2 +- .../PortfolioApiDataConversionService.java | 2 +- ...PortfolioApiDataConversionServiceImpl.java | 2 +- .../PortfolioApiJsonSerializerService.java | 2 +- .../loanaccount/api/LoansApiResource.java | 4 +- .../loanaccount/data/LoanAccountData.java | 2 +- .../gaurantor/command}/GuarantorCommand.java | 4 +- .../command/GuarantorCommandValidator.java | 78 ++++++++++++ .../gaurantor}/data/GuarantorData.java | 2 +- .../GuarantorNotFoundException.java | 2 +- .../exception}/InvalidGuarantorException.java | 2 +- .../service/GuarantorReadPlatformService.java | 13 ++ .../GuarantorReadPlatformServiceImpl.java | 15 +-- .../GuarantorWritePlatformService.java | 17 +++ .../GuarantorWritePlatformServiceImpl.java | 9 +- 19 files changed, 137 insertions(+), 176 deletions(-) delete mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorCommandValidator.java delete mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorReadPlatformService.java delete mode 100644 mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorWritePlatformService.java rename mifosng-provider/src/main/java/org/{mifosng/platform/api/commands => mifosplatform/portfolio/loanaccount/gaurantor/command}/GuarantorCommand.java (94%) create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/command/GuarantorCommandValidator.java rename mifosng-provider/src/main/java/org/{mifosng/platform/api => mifosplatform/portfolio/loanaccount/gaurantor}/data/GuarantorData.java (98%) rename mifosng-provider/src/main/java/org/{mifosng/platform/exceptions => mifosplatform/portfolio/loanaccount/gaurantor/exception}/GuarantorNotFoundException.java (86%) rename mifosng-provider/src/main/java/org/{mifosng/platform/exceptions => mifosplatform/portfolio/loanaccount/gaurantor/exception}/InvalidGuarantorException.java (89%) create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorReadPlatformService.java rename mifosng-provider/src/main/java/org/{mifosng/platform/guarantor => mifosplatform/portfolio/loanaccount/gaurantor/service}/GuarantorReadPlatformServiceImpl.java (93%) create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorWritePlatformService.java rename mifosng-provider/src/main/java/org/{mifosng/platform/guarantor => mifosplatform/portfolio/loanaccount/gaurantor/service}/GuarantorWritePlatformServiceImpl.java (95%) diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/GuarantorsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/GuarantorsApiResource.java index 956c3b532..0607be021 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/GuarantorsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/GuarantorsApiResource.java @@ -17,15 +17,15 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; -import org.mifosng.platform.api.commands.GuarantorCommand; -import org.mifosng.platform.api.data.GuarantorData; -import org.mifosng.platform.guarantor.GuarantorReadPlatformService; -import org.mifosng.platform.guarantor.GuarantorWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService; import org.mifosplatform.infrastructure.core.data.EntityIdentifier; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; +import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand; +import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData; +import org.mifosplatform.portfolio.loanaccount.gaurantor.service.GuarantorReadPlatformService; +import org.mifosplatform.portfolio.loanaccount.gaurantor.service.GuarantorWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorCommandValidator.java deleted file mode 100644 index de940b204..000000000 --- a/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorCommandValidator.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.mifosng.platform.guarantor; - -import java.util.ArrayList; -import java.util.List; - -import org.mifosng.platform.api.commands.GuarantorCommand; -import org.mifosplatform.infrastructure.core.data.ApiParameterError; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; - -public class GuarantorCommandValidator { - - private final GuarantorCommand command; - - public GuarantorCommandValidator(GuarantorCommand command) { - this.command = command; - } - - public void validateForCreate() { - - List dataValidationErrors = new ArrayList(); - - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder( - dataValidationErrors).resource("Guarantor"); - - // validate for existing Client - if (command.isExternalGuarantor() == null - || command.isExternalGuarantor() == false) { - baseDataValidator.reset().parameter("existingClientId") - .value(command.getExistingClientId()).notNull() - .integerGreaterThanZero(); - } else { - // validate for an external guarantor - baseDataValidator.reset().parameter("firstname") - .value(command.getFirstname()).notBlank() - .notExceedingLengthOf(50); - baseDataValidator.reset().parameter("lastname") - .value(command.getLastname()).notBlank() - .notExceedingLengthOf(50); - - validateNonMandatoryFieldsForMaxLength(baseDataValidator); - } - - if (!dataValidationErrors.isEmpty()) { - throw new PlatformApiDataValidationException( - "validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); - } - } - - public void validateForUpdate() { - List dataValidationErrors = new ArrayList(); - - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder( - dataValidationErrors).resource("Guarantor"); - - // validate for existing Client - if (command.isExternalGuarantor() == null - || command.isExternalGuarantor() == false) { - baseDataValidator.reset().parameter("existingClientId") - .value(command.getExistingClientId()).notNull() - .integerGreaterThanZero(); - } else { - // validate for an external guarantor - baseDataValidator.reset().parameter("firstname") - .value(command.getFirstname()).notBlank() - .notExceedingLengthOf(50); - baseDataValidator.reset().parameter("lastname") - .value(command.getLastname()).notBlank() - .notExceedingLengthOf(50); - - validateNonMandatoryFieldsForMaxLength(baseDataValidator); - } - baseDataValidator.reset().anyOfNotNull(command.getExistingClientId(), - command.getAddressLine1(), command.getAddressLine2(), - command.getCity(), command.getComment(), command.getCountry(), - command.getFirstname(), command.getHousePhoneNumber(), - command.getLastname(), command.getMobileNumber(), - command.getState(), command.getZip()); - - if (!dataValidationErrors.isEmpty()) { - throw new PlatformApiDataValidationException( - "validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); - } - } - - /** - * @param baseDataValidator - */ - private void validateNonMandatoryFieldsForMaxLength( - DataValidatorBuilder baseDataValidator) { - // validate non mandatory fields for length - baseDataValidator.reset().parameter("addressLine1") - .value(command.getAddressLine1()).ignoreIfNull() - .notExceedingLengthOf(50); - baseDataValidator.reset().parameter("addressLine2") - .value(command.getAddressLine2()).ignoreIfNull() - .notExceedingLengthOf(50); - baseDataValidator.reset().parameter("city").value(command.getCity()) - .ignoreIfNull().notExceedingLengthOf(50); - baseDataValidator.reset().parameter("state").value(command.getState()) - .ignoreIfNull().notExceedingLengthOf(50); - baseDataValidator.reset().parameter("zip").value(command.getZip()) - .ignoreIfNull().notExceedingLengthOf(50); - baseDataValidator.reset().parameter("country") - .value(command.getCountry()).ignoreIfNull() - .notExceedingLengthOf(50); - baseDataValidator.reset().parameter("mobileNumber") - .value(command.getMobileNumber()).ignoreIfNull() - .notExceedingLengthOf(20); - baseDataValidator.reset().parameter("housePhoneNumber") - .value(command.getHousePhoneNumber()).ignoreIfNull() - .notExceedingLengthOf(20); - baseDataValidator.reset().parameter("comment") - .value(command.getComment()).ignoreIfNull() - .notExceedingLengthOf(500); - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorReadPlatformService.java deleted file mode 100644 index 90bd5f7eb..000000000 --- a/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorReadPlatformService.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.mifosng.platform.guarantor; - -import org.mifosng.platform.api.data.GuarantorData; - -public interface GuarantorReadPlatformService { - - GuarantorData retrieveGuarantor(Long loanId); - - boolean existsGuarantor(Long loanId); - - GuarantorData getExternalGuarantor(Long loanId); - -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorWritePlatformService.java deleted file mode 100644 index af8b61506..000000000 --- a/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorWritePlatformService.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.mifosng.platform.guarantor; - -import org.mifosng.platform.api.commands.GuarantorCommand; -import org.springframework.security.access.prepost.PreAuthorize; - -public interface GuarantorWritePlatformService { - - @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS','PORTFOLIO_MANAGEMENT_SUPER_USER')") - void createGuarantor(final Long loanId, final GuarantorCommand command); - - @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS','PORTFOLIO_MANAGEMENT_SUPER_USER')") - void updateGuarantor(final Long loanId, final GuarantorCommand command); - - @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS','PORTFOLIO_MANAGEMENT_SUPER_USER')") - void removeGuarantor(final Long loanId); - -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/GoogleGsonPortfolioApiJsonSerializerService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/GoogleGsonPortfolioApiJsonSerializerService.java index 77c8678b2..a1e7ba9fb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/GoogleGsonPortfolioApiJsonSerializerService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/GoogleGsonPortfolioApiJsonSerializerService.java @@ -9,7 +9,6 @@ import org.mifosng.platform.api.data.DepositAccountData; import org.mifosng.platform.api.data.DepositProductData; import org.mifosng.platform.api.data.GroupAccountSummaryCollectionData; import org.mifosng.platform.api.data.GroupData; -import org.mifosng.platform.api.data.GuarantorData; import org.mifosng.platform.api.data.SavingAccountData; import org.mifosng.platform.api.data.SavingProductData; import org.mifosplatform.commands.api.data.CommandSourceData; @@ -37,6 +36,7 @@ import org.mifosplatform.portfolio.fund.data.FundData; import org.mifosplatform.portfolio.loanaccount.data.LoanAccountData; import org.mifosplatform.portfolio.loanaccount.data.LoanChargeData; import org.mifosplatform.portfolio.loanaccount.data.LoanTransactionData; +import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData; import org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanScheduleData; import org.mifosplatform.portfolio.loanproduct.data.LoanProductData; import org.springframework.beans.factory.annotation.Autowired; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/PortfolioApiDataConversionService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/PortfolioApiDataConversionService.java index 7c3771d73..873f0a831 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/PortfolioApiDataConversionService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/PortfolioApiDataConversionService.java @@ -7,7 +7,6 @@ import org.mifosng.platform.api.commands.DepositProductCommand; import org.mifosng.platform.api.commands.DepositStateTransitionApprovalCommand; import org.mifosng.platform.api.commands.DepositStateTransitionCommand; import org.mifosng.platform.api.commands.GroupCommand; -import org.mifosng.platform.api.commands.GuarantorCommand; import org.mifosng.platform.api.commands.SavingAccountCommand; import org.mifosng.platform.api.commands.SavingProductCommand; import org.mifosplatform.infrastructure.codes.command.CodeCommand; @@ -31,6 +30,7 @@ import org.mifosplatform.portfolio.loanaccount.command.LoanApplicationCommand; import org.mifosplatform.portfolio.loanaccount.command.LoanChargeCommand; import org.mifosplatform.portfolio.loanaccount.command.LoanStateTransitionCommand; import org.mifosplatform.portfolio.loanaccount.command.LoanTransactionCommand; +import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand; import org.mifosplatform.portfolio.loanproduct.command.LoanProductCommand; public interface PortfolioApiDataConversionService { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/PortfolioApiDataConversionServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/PortfolioApiDataConversionServiceImpl.java index ece2f0419..74fad5af5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/PortfolioApiDataConversionServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/PortfolioApiDataConversionServiceImpl.java @@ -24,7 +24,6 @@ import org.mifosng.platform.api.commands.DepositProductCommand; import org.mifosng.platform.api.commands.DepositStateTransitionApprovalCommand; import org.mifosng.platform.api.commands.DepositStateTransitionCommand; import org.mifosng.platform.api.commands.GroupCommand; -import org.mifosng.platform.api.commands.GuarantorCommand; import org.mifosng.platform.api.commands.SavingAccountCommand; import org.mifosng.platform.api.commands.SavingProductCommand; import org.mifosplatform.infrastructure.codes.command.CodeCommand; @@ -52,6 +51,7 @@ import org.mifosplatform.portfolio.loanaccount.command.LoanApplicationCommand; import org.mifosplatform.portfolio.loanaccount.command.LoanChargeCommand; import org.mifosplatform.portfolio.loanaccount.command.LoanStateTransitionCommand; import org.mifosplatform.portfolio.loanaccount.command.LoanTransactionCommand; +import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand; import org.mifosplatform.portfolio.loanproduct.command.LoanProductCommand; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.number.NumberFormatter; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/PortfolioApiJsonSerializerService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/PortfolioApiJsonSerializerService.java index a9d70b976..fcac8bc72 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/PortfolioApiJsonSerializerService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/PortfolioApiJsonSerializerService.java @@ -7,7 +7,6 @@ import org.mifosng.platform.api.data.DepositAccountData; import org.mifosng.platform.api.data.DepositProductData; import org.mifosng.platform.api.data.GroupAccountSummaryCollectionData; import org.mifosng.platform.api.data.GroupData; -import org.mifosng.platform.api.data.GuarantorData; import org.mifosng.platform.api.data.SavingAccountData; import org.mifosng.platform.api.data.SavingProductData; import org.mifosplatform.commands.api.data.CommandSourceData; @@ -35,6 +34,7 @@ import org.mifosplatform.portfolio.fund.data.FundData; import org.mifosplatform.portfolio.loanaccount.data.LoanAccountData; import org.mifosplatform.portfolio.loanaccount.data.LoanChargeData; import org.mifosplatform.portfolio.loanaccount.data.LoanTransactionData; +import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData; import org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanScheduleData; import org.mifosplatform.portfolio.loanproduct.data.LoanProductData; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java index dd508ab3a..34bb9181e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java @@ -20,8 +20,6 @@ import javax.ws.rs.core.UriInfo; import org.apache.commons.lang.StringUtils; import org.joda.time.LocalDate; -import org.mifosng.platform.api.data.GuarantorData; -import org.mifosng.platform.guarantor.GuarantorReadPlatformService; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.configuration.domain.MonetaryCurrency; import org.mifosplatform.infrastructure.configuration.domain.Money; @@ -56,6 +54,8 @@ import org.mifosplatform.portfolio.loanaccount.data.LoanBasicDetailsData; import org.mifosplatform.portfolio.loanaccount.data.LoanChargeData; import org.mifosplatform.portfolio.loanaccount.data.LoanPermissionData; import org.mifosplatform.portfolio.loanaccount.data.LoanTransactionData; +import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData; +import org.mifosplatform.portfolio.loanaccount.gaurantor.service.GuarantorReadPlatformService; import org.mifosplatform.portfolio.loanaccount.loanschedule.command.CalculateLoanScheduleCommand; import org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanScheduleData; import org.mifosplatform.portfolio.loanaccount.loanschedule.service.CalculationPlatformService; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/data/LoanAccountData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/data/LoanAccountData.java index 51ea3154b..8dbce066a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/data/LoanAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/data/LoanAccountData.java @@ -4,12 +4,12 @@ import java.math.BigDecimal; import java.util.Collection; import org.joda.time.LocalDate; -import org.mifosng.platform.api.data.GuarantorData; import org.mifosplatform.infrastructure.configuration.data.CurrencyData; import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.staff.data.StaffData; import org.mifosplatform.portfolio.charge.data.ChargeData; import org.mifosplatform.portfolio.fund.data.FundData; +import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData; import org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanScheduleData; import org.mifosplatform.portfolio.loanproduct.data.LoanProductData; import org.mifosplatform.portfolio.loanproduct.data.TransactionProcessingStrategyData; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/GuarantorCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/command/GuarantorCommand.java similarity index 94% rename from mifosng-provider/src/main/java/org/mifosng/platform/api/commands/GuarantorCommand.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/command/GuarantorCommand.java index 0ce078500..e3600df67 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/GuarantorCommand.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/command/GuarantorCommand.java @@ -1,4 +1,4 @@ -package org.mifosng.platform.api.commands; +package org.mifosplatform.portfolio.loanaccount.gaurantor.command; import java.util.Set; @@ -13,7 +13,7 @@ public class GuarantorCommand { private final Long existingClientId; /*** Fields for external persons serving as guarantors ***/ - // FIXME - kw - what the details for collecting guarantors change? we are using datatable approach but fixing here? + // FIXME - kw - what if the details for collecting guarantors change? we are using datatable approach but embedding a structure here? private final String firstname; private final String lastname; private final String addressLine1; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/command/GuarantorCommandValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/command/GuarantorCommandValidator.java new file mode 100644 index 000000000..2257a7bee --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/command/GuarantorCommandValidator.java @@ -0,0 +1,78 @@ +package org.mifosplatform.portfolio.loanaccount.gaurantor.command; + +import java.util.ArrayList; +import java.util.List; + +import org.mifosplatform.infrastructure.core.data.ApiParameterError; +import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; +import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; + +public class GuarantorCommandValidator { + + private final GuarantorCommand command; + + public GuarantorCommandValidator(GuarantorCommand command) { + this.command = command; + } + + public void validateForCreate() { + + List dataValidationErrors = new ArrayList(); + + DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("Guarantor"); + + // validate for existing Client + if (command.isExternalGuarantor() == null || command.isExternalGuarantor() == false) { + baseDataValidator.reset().parameter("existingClientId").value(command.getExistingClientId()).notNull().integerGreaterThanZero(); + } else { + // validate for an external guarantor + baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).notBlank().notExceedingLengthOf(50); + baseDataValidator.reset().parameter("lastname").value(command.getLastname()).notBlank().notExceedingLengthOf(50); + + validateNonMandatoryFieldsForMaxLength(baseDataValidator); + } + + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); } + } + + public void validateForUpdate() { + List dataValidationErrors = new ArrayList(); + + DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("Guarantor"); + + // validate for existing Client + if (command.isExternalGuarantor() == null || command.isExternalGuarantor() == false) { + baseDataValidator.reset().parameter("existingClientId").value(command.getExistingClientId()).notNull().integerGreaterThanZero(); + } else { + // validate for an external guarantor + baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).notBlank().notExceedingLengthOf(50); + baseDataValidator.reset().parameter("lastname").value(command.getLastname()).notBlank().notExceedingLengthOf(50); + + validateNonMandatoryFieldsForMaxLength(baseDataValidator); + } + baseDataValidator.reset().anyOfNotNull(command.getExistingClientId(), command.getAddressLine1(), command.getAddressLine2(), + command.getCity(), command.getComment(), command.getCountry(), command.getFirstname(), command.getHousePhoneNumber(), + command.getLastname(), command.getMobileNumber(), command.getState(), command.getZip()); + + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); } + } + + /** + * @param baseDataValidator + */ + private void validateNonMandatoryFieldsForMaxLength(DataValidatorBuilder baseDataValidator) { + // validate non mandatory fields for length + baseDataValidator.reset().parameter("addressLine1").value(command.getAddressLine1()).ignoreIfNull().notExceedingLengthOf(50); + baseDataValidator.reset().parameter("addressLine2").value(command.getAddressLine2()).ignoreIfNull().notExceedingLengthOf(50); + baseDataValidator.reset().parameter("city").value(command.getCity()).ignoreIfNull().notExceedingLengthOf(50); + baseDataValidator.reset().parameter("state").value(command.getState()).ignoreIfNull().notExceedingLengthOf(50); + baseDataValidator.reset().parameter("zip").value(command.getZip()).ignoreIfNull().notExceedingLengthOf(50); + baseDataValidator.reset().parameter("country").value(command.getCountry()).ignoreIfNull().notExceedingLengthOf(50); + baseDataValidator.reset().parameter("mobileNumber").value(command.getMobileNumber()).ignoreIfNull().notExceedingLengthOf(20); + baseDataValidator.reset().parameter("housePhoneNumber").value(command.getHousePhoneNumber()).ignoreIfNull() + .notExceedingLengthOf(20); + baseDataValidator.reset().parameter("comment").value(command.getComment()).ignoreIfNull().notExceedingLengthOf(500); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/GuarantorData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/data/GuarantorData.java similarity index 98% rename from mifosng-provider/src/main/java/org/mifosng/platform/api/data/GuarantorData.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/data/GuarantorData.java index 7a36337fa..647ea1cf4 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/GuarantorData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/data/GuarantorData.java @@ -1,4 +1,4 @@ -package org.mifosng.platform.api.data; +package org.mifosplatform.portfolio.loanaccount.gaurantor.data; import org.joda.time.LocalDate; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/GuarantorNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/exception/GuarantorNotFoundException.java similarity index 86% rename from mifosng-provider/src/main/java/org/mifosng/platform/exceptions/GuarantorNotFoundException.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/exception/GuarantorNotFoundException.java index fab49b8c4..24764d4eb 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/GuarantorNotFoundException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/exception/GuarantorNotFoundException.java @@ -1,4 +1,4 @@ -package org.mifosng.platform.exceptions; +package org.mifosplatform.portfolio.loanaccount.gaurantor.exception; import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/InvalidGuarantorException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/exception/InvalidGuarantorException.java similarity index 89% rename from mifosng-provider/src/main/java/org/mifosng/platform/exceptions/InvalidGuarantorException.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/exception/InvalidGuarantorException.java index 8c14be0b2..f8b8d625f 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/InvalidGuarantorException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/exception/InvalidGuarantorException.java @@ -1,4 +1,4 @@ -package org.mifosng.platform.exceptions; +package org.mifosplatform.portfolio.loanaccount.gaurantor.exception; import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorReadPlatformService.java new file mode 100644 index 000000000..e4ef2c182 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorReadPlatformService.java @@ -0,0 +1,13 @@ +package org.mifosplatform.portfolio.loanaccount.gaurantor.service; + +import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData; + +public interface GuarantorReadPlatformService { + + GuarantorData retrieveGuarantor(Long loanId); + + boolean existsGuarantor(Long loanId); + + GuarantorData getExternalGuarantor(Long loanId); + +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorReadPlatformServiceImpl.java similarity index 93% rename from mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorReadPlatformServiceImpl.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorReadPlatformServiceImpl.java index 39688a536..2ca3bdd9b 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorReadPlatformServiceImpl.java @@ -1,17 +1,17 @@ -package org.mifosng.platform.guarantor; +package org.mifosplatform.portfolio.loanaccount.gaurantor.service; import java.util.List; import org.apache.commons.lang.StringUtils; import org.joda.time.LocalDate; -import org.mifosng.platform.api.data.GuarantorData; -import org.mifosng.platform.exceptions.GuarantorNotFoundException; import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData; import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService; import org.mifosplatform.portfolio.client.domain.Client; import org.mifosplatform.portfolio.loanaccount.domain.Loan; import org.mifosplatform.portfolio.loanaccount.domain.LoanRepository; import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException; +import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData; +import org.mifosplatform.portfolio.loanaccount.gaurantor.exception.GuarantorNotFoundException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class GuarantorReadPlatformServiceImpl implements GuarantorReadPlatformSe // Table for storing external Guarantor Details public static final String EXTERNAL_GUARANTOR_TABLE_NAME = "m_guarantor_external"; - + private final LoanRepository loanRepository; private final ReadWriteNonCoreDataService readWriteNonCoreDataService; @@ -61,8 +61,9 @@ public class GuarantorReadPlatformServiceImpl implements GuarantorReadPlatformSe } private Loan retrieveLoanById(final Long loanId) { - - // FIXME - KW - On the read side of services - we would prefer not to use the repository/ORM pattern + + // FIXME - KW - On the read side of services - we would prefer not to + // use the repository/ORM pattern Loan loan = loanRepository.findOne(loanId); if (loan == null) { throw new LoanNotFoundException(loanId); } return loan; @@ -70,7 +71,7 @@ public class GuarantorReadPlatformServiceImpl implements GuarantorReadPlatformSe @Override public GuarantorData getExternalGuarantor(final Long loanId) { - + GenericResultsetData genericResultDataSet = readWriteNonCoreDataService.retrieveDataTableGenericResultSet( EXTERNAL_GUARANTOR_TABLE_NAME, loanId, null, null); if (genericResultDataSet.getData().size() == 1) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorWritePlatformService.java new file mode 100644 index 000000000..8f5c64f76 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorWritePlatformService.java @@ -0,0 +1,17 @@ +package org.mifosplatform.portfolio.loanaccount.gaurantor.service; + +import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand; +import org.springframework.security.access.prepost.PreAuthorize; + +public interface GuarantorWritePlatformService { + + @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS','PORTFOLIO_MANAGEMENT_SUPER_USER')") + void createGuarantor(final Long loanId, final GuarantorCommand command); + + @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS','PORTFOLIO_MANAGEMENT_SUPER_USER')") + void updateGuarantor(final Long loanId, final GuarantorCommand command); + + @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS','PORTFOLIO_MANAGEMENT_SUPER_USER')") + void removeGuarantor(final Long loanId); + +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorWritePlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorWritePlatformServiceImpl.java similarity index 95% rename from mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorWritePlatformServiceImpl.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorWritePlatformServiceImpl.java index c6752098d..d6aa59b0e 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/guarantor/GuarantorWritePlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/service/GuarantorWritePlatformServiceImpl.java @@ -1,4 +1,4 @@ -package org.mifosng.platform.guarantor; +package org.mifosplatform.portfolio.loanaccount.gaurantor.service; import java.lang.reflect.Method; import java.util.ArrayList; @@ -8,8 +8,6 @@ import java.util.Map; import java.util.Set; import org.apache.commons.lang.StringUtils; -import org.mifosng.platform.api.commands.GuarantorCommand; -import org.mifosng.platform.exceptions.InvalidGuarantorException; import org.mifosplatform.infrastructure.core.data.ApiParameterError; import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService; @@ -19,6 +17,9 @@ import org.mifosplatform.portfolio.client.exception.ClientNotFoundException; import org.mifosplatform.portfolio.loanaccount.domain.Loan; import org.mifosplatform.portfolio.loanaccount.domain.LoanRepository; import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException; +import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand; +import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommandValidator; +import org.mifosplatform.portfolio.loanaccount.gaurantor.exception.InvalidGuarantorException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -90,7 +91,7 @@ public class GuarantorWritePlatformServiceImpl implements GuarantorWritePlatform else { Set modifiedParameters = command.getModifiedParameters(); Map modifiedParametersMap = new HashMap(); - + /*** * TODO Vishwas: Check with JW/KW if using reflection here is a good * idea