Merge pull request #449 from mifoscontributer/MIFOSX-526
Restricting existing guarantor as new guarantor for same loan
This commit is contained in:
+6
-6
@@ -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()) {
|
||||
|
||||
+6
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
+4
@@ -302,4 +302,8 @@ public class Guarantor extends AbstractPersistable<Long> {
|
||||
private void updateExistingEntityToNull() {
|
||||
this.entityId = null;
|
||||
}
|
||||
|
||||
public Integer getGurantorType() {
|
||||
return this.gurantorType;
|
||||
}
|
||||
}
|
||||
+8
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
@@ -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<Guarantor> 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);
|
||||
|
||||
Reference in New Issue
Block a user