diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/DataValidatorBuilder.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/DataValidatorBuilder.java index ed6a28724..9f914c8f8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/DataValidatorBuilder.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/DataValidatorBuilder.java @@ -626,12 +626,12 @@ public class DataValidatorBuilder { public DataValidatorBuilder validatePhoneNumber() { if (this.value == null && this.ignoreNullValue) { return this; } boolean validationErr = true; - String regex = "^\\+?[0-9. ()-]{0,25}$"; // supports numbers, - // parentheses(), hyphens and - // may contain + sign in the - // beginning and can contain - // whitespaces in between and - // length allowed is 0-25 chars. + /* + * supports numbers, parentheses(), hyphens and may contain + sign in + * the beginning and can contain whitespaces in between and length + * allowed is 0-25 chars. + */ + String regex = "^\\+?[0-9. ()-]{0,25}$"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(this.value.toString()); if (matcher.matches()) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/command/GuarantorCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/command/GuarantorCommand.java index afbfdd149..12b4b108e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/command/GuarantorCommand.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/command/GuarantorCommand.java @@ -146,9 +146,9 @@ public class GuarantorCommand { private void validateNonMandatoryFieldsForMaxLength(DataValidatorBuilder baseDataValidator) { // validate non mandatory fields for length baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.ADDRESS_LINE_1.getValue()).value(this.addressLine1).ignoreIfNull() - .notExceedingLengthOf(50); + .notExceedingLengthOf(500); baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.ADDRESS_LINE_2.getValue()).value(this.addressLine2).ignoreIfNull() - .notExceedingLengthOf(50); + .notExceedingLengthOf(500); baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.CITY.getValue()).value(this.city).ignoreIfNull() .notExceedingLengthOf(50); baseDataValidator.reset().parameter(GUARANTOR_JSON_INPUT_PARAMS.STATE.getValue()).value(this.state).ignoreIfNull() @@ -181,4 +181,8 @@ public class GuarantorCommand { public Long getEntityId() { return this.entityId; } + + public Integer getGuarantorTypeId() { + return this.guarantorTypeId; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/domain/Guarantor.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/domain/Guarantor.java index a752dbf61..04c680560 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/domain/Guarantor.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/domain/Guarantor.java @@ -302,4 +302,8 @@ public class Guarantor extends AbstractPersistable { private void updateExistingEntityToNull() { this.entityId = null; } + + public Integer getGurantorType() { + return this.gurantorType; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/domain/GuarantorType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/domain/GuarantorType.java index 151fc96e6..8eb65782e 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/domain/GuarantorType.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/domain/GuarantorType.java @@ -65,4 +65,12 @@ public enum GuarantorType { return name().toString(); } + public boolean isCustomer() { + return this.value.equals(GuarantorType.CUSTOMER.getValue()); + } + + public boolean isStaff() { + return this.value.equals(GuarantorType.STAFF.getValue()); + } + } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/service/GuarantorWritePlatformServiceJpaRepositoryIImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/service/GuarantorWritePlatformServiceJpaRepositoryIImpl.java index a863e918c..fa16c6f38 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/service/GuarantorWritePlatformServiceJpaRepositoryIImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/guarantor/service/GuarantorWritePlatformServiceJpaRepositoryIImpl.java @@ -23,6 +23,7 @@ import org.mifosplatform.portfolio.loanaccount.guarantor.GuarantorConstants.GUAR import org.mifosplatform.portfolio.loanaccount.guarantor.command.GuarantorCommand; import org.mifosplatform.portfolio.loanaccount.guarantor.domain.Guarantor; import org.mifosplatform.portfolio.loanaccount.guarantor.domain.GuarantorRepository; +import org.mifosplatform.portfolio.loanaccount.guarantor.domain.GuarantorType; import org.mifosplatform.portfolio.loanaccount.guarantor.exception.DuplicateGuarantorException; import org.mifosplatform.portfolio.loanaccount.guarantor.exception.GuarantorNotFoundException; import org.mifosplatform.portfolio.loanaccount.guarantor.exception.InvalidGuarantorException; @@ -126,6 +127,22 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto guarantorForUpdate.updateClientRelationshipType(clientRelationshipType); } + final List existGuarantorList = this.guarantorRepository.findByLoan(loan); + final Integer guarantorTypeId = guarantorCommand.getGuarantorTypeId(); + final GuarantorType guarantorType = GuarantorType.fromInt(guarantorTypeId); + if (guarantorType.isCustomer() || guarantorType.isStaff()) { + final Long entityId = guarantorCommand.getEntityId(); + for (final Guarantor guarantor : existGuarantorList) { + if (guarantor.getLoanId() == loanId && guarantor.getEntityId() == entityId + && guarantor.getGurantorType() == guarantorTypeId && !guarantorForUpdate.getId().equals(guarantor.getId())) { + String defaultUserMessage = this.clientRepositoryWrapper.findOneWithNotFoundDetection(entityId).getDisplayName(); + defaultUserMessage = defaultUserMessage + " is already exist as a guarantor for this loan"; + final String action = loan.client() != null ? "client.guarantor" : "group.guarantor"; + throw new DuplicateGuarantorException(action, "is.already.exist.same.loan", defaultUserMessage, entityId, loanId); + } + } + } + if (changesOnly.containsKey(GUARANTOR_JSON_INPUT_PARAMS.ENTITY_ID) || changesOnly.containsKey(GUARANTOR_JSON_INPUT_PARAMS.GUARANTOR_TYPE_ID)) { validateGuarantorBusinessRules(guarantorForUpdate);