From 6a14031ac3b7d48114860d68d119a59b5b3b92eb Mon Sep 17 00:00:00 2001 From: Vishwas Babu A J Date: Wed, 2 Jul 2014 14:46:25 -0700 Subject: [PATCH] cleaning up MIFOSX-1399 --- ...antorWritePlatformServiceJpaRepositoryIImpl.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 207023db3..7bd50ff31 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 @@ -79,10 +79,19 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto final List existGuarantorList = this.guarantorRepository.findByLoan(loan); final Long entityId = guarantorCommand.getEntityId(); + final Integer guarantorTypeId = guarantorCommand.getGuarantorTypeId(); for (final Guarantor guarantor : existGuarantorList) { - if (guarantor.getLoanId() == loanId && entityId !=null && guarantor.getEntityId() == entityId) { - String defaultUserMessage = this.clientRepositoryWrapper.findOneWithNotFoundDetection(entityId).getDisplayName(); + if (guarantor.getLoanId() == loanId && entityId != null && guarantor.getEntityId() == entityId + && guarantor.getGurantorType() == guarantorTypeId) { + /** Get the right guarantor based on guarantorType **/ + String defaultUserMessage = null; + if (guarantorTypeId == GuarantorType.STAFF.getValue()) { + defaultUserMessage = this.staffRepositoryWrapper.findOneWithNotFoundDetection(entityId).displayName(); + } else { + 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);