For same loan same guarantor can be associate more than once(fixed)
This commit is contained in:
+4
@@ -177,4 +177,8 @@ public class GuarantorCommand {
|
|||||||
public Long getClientRelationshipTypeId() {
|
public Long getClientRelationshipTypeId() {
|
||||||
return this.clientRelationshipTypeId;
|
return this.clientRelationshipTypeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getEntityId() {
|
||||||
|
return this.entityId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+3
@@ -5,6 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.portfolio.loanaccount.guarantor.domain;
|
package org.mifosplatform.portfolio.loanaccount.guarantor.domain;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
|
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
@@ -12,4 +14,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|||||||
public interface GuarantorRepository extends JpaRepository<Guarantor, Long>, JpaSpecificationExecutor<Guarantor> {
|
public interface GuarantorRepository extends JpaRepository<Guarantor, Long>, JpaSpecificationExecutor<Guarantor> {
|
||||||
|
|
||||||
Guarantor findByLoanAndId(Loan loan, Long id);
|
Guarantor findByLoanAndId(Loan loan, Long id);
|
||||||
|
List<Guarantor> findByLoan(Loan loan);
|
||||||
}
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package org.mifosplatform.portfolio.loanaccount.guarantor.exception;
|
||||||
|
|
||||||
|
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||||
|
|
||||||
|
|
||||||
|
public class DuplicateGuarantorException extends AbstractPlatformDomainRuleException {
|
||||||
|
|
||||||
|
public DuplicateGuarantorException(final String action, String postFix, String defaultUserMessage, Object... defaultUserMessageArgs) {
|
||||||
|
super("error.msg." + action + "." + postFix, defaultUserMessage, defaultUserMessageArgs);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
-4
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.portfolio.loanaccount.guarantor.service;
|
package org.mifosplatform.portfolio.loanaccount.guarantor.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.codes.domain.CodeValue;
|
import org.mifosplatform.infrastructure.codes.domain.CodeValue;
|
||||||
@@ -22,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.command.GuarantorCommand;
|
||||||
import org.mifosplatform.portfolio.loanaccount.guarantor.domain.Guarantor;
|
import org.mifosplatform.portfolio.loanaccount.guarantor.domain.Guarantor;
|
||||||
import org.mifosplatform.portfolio.loanaccount.guarantor.domain.GuarantorRepository;
|
import org.mifosplatform.portfolio.loanaccount.guarantor.domain.GuarantorRepository;
|
||||||
|
import org.mifosplatform.portfolio.loanaccount.guarantor.exception.DuplicateGuarantorException;
|
||||||
import org.mifosplatform.portfolio.loanaccount.guarantor.exception.GuarantorNotFoundException;
|
import org.mifosplatform.portfolio.loanaccount.guarantor.exception.GuarantorNotFoundException;
|
||||||
import org.mifosplatform.portfolio.loanaccount.guarantor.exception.InvalidGuarantorException;
|
import org.mifosplatform.portfolio.loanaccount.guarantor.exception.InvalidGuarantorException;
|
||||||
import org.mifosplatform.portfolio.loanaccount.guarantor.serialization.GuarantorCommandFromApiJsonDeserializer;
|
import org.mifosplatform.portfolio.loanaccount.guarantor.serialization.GuarantorCommandFromApiJsonDeserializer;
|
||||||
@@ -73,7 +75,19 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto
|
|||||||
clientRelationshipType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection(
|
clientRelationshipType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection(
|
||||||
GuarantorConstants.GUARANTOR_RELATIONSHIP_CODE_NAME, clientRelationshipId);
|
GuarantorConstants.GUARANTOR_RELATIONSHIP_CODE_NAME, clientRelationshipId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Guarantor> existGuarantorList = this.guarantorRepository.findByLoan(loan);
|
||||||
|
Long entityId = guarantorCommand.getEntityId();
|
||||||
|
|
||||||
|
for (Guarantor guarantor : existGuarantorList) {
|
||||||
|
if (guarantor.getLoanId() == loanId && guarantor.getEntityId() == entityId) {
|
||||||
|
String defaultUserMessage = this.clientRepositoryWrapper.findOneWithNotFoundDetection(entityId).getDisplayName();
|
||||||
|
defaultUserMessage = defaultUserMessage + " is already exist as a guarantor for this loan";
|
||||||
|
String action = loan.client() != null ? "client.guarantor" : "group.guarantor";
|
||||||
|
throw new DuplicateGuarantorException(action, "is.already.exist.same.loan", defaultUserMessage, entityId, loanId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Guarantor guarantor = null;
|
Guarantor guarantor = null;
|
||||||
guarantor = Guarantor.fromJson(loan, clientRelationshipType, command);
|
guarantor = Guarantor.fromJson(loan, clientRelationshipType, command);
|
||||||
|
|
||||||
@@ -111,12 +125,24 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto
|
|||||||
}
|
}
|
||||||
guarantorForUpdate.setClientRelationshipType(clientRelationshipType);
|
guarantorForUpdate.setClientRelationshipType(clientRelationshipType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Guarantor> existGuarantorList = this.guarantorRepository.findByLoan(loan);
|
||||||
|
Long entityId = guarantorCommand.getEntityId();
|
||||||
|
|
||||||
|
for (Guarantor guarantor : existGuarantorList) {
|
||||||
|
if (guarantor.getLoanId() == loanId && guarantor.getEntityId() == entityId) {
|
||||||
|
String defaultUserMessage = this.clientRepositoryWrapper.findOneWithNotFoundDetection(entityId).getDisplayName();
|
||||||
|
defaultUserMessage = defaultUserMessage + " is already exist as a guarantor for this loan";
|
||||||
|
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)
|
if (changesOnly.containsKey(GUARANTOR_JSON_INPUT_PARAMS.ENTITY_ID)
|
||||||
|| changesOnly.containsKey(GUARANTOR_JSON_INPUT_PARAMS.GUARANTOR_TYPE_ID)) {
|
|| changesOnly.containsKey(GUARANTOR_JSON_INPUT_PARAMS.GUARANTOR_TYPE_ID)) {
|
||||||
validateGuarantorBusinessRules(guarantorForUpdate);
|
validateGuarantorBusinessRules(guarantorForUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!changesOnly.isEmpty()) {
|
if (!changesOnly.isEmpty()) {
|
||||||
this.guarantorRepository.saveAndFlush(guarantorForUpdate);
|
this.guarantorRepository.saveAndFlush(guarantorForUpdate);
|
||||||
}
|
}
|
||||||
@@ -148,9 +174,11 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto
|
|||||||
// check client exists
|
// check client exists
|
||||||
clientRepositoryWrapper.findOneWithNotFoundDetection(guarantor.getEntityId());
|
clientRepositoryWrapper.findOneWithNotFoundDetection(guarantor.getEntityId());
|
||||||
// validate that the client is not set as a self guarantor
|
// validate that the client is not set as a self guarantor
|
||||||
if (guarantor.getClientId().equals(guarantor.getEntityId())) {
|
if (guarantor.getClientId() != null) {
|
||||||
//
|
if (guarantor.getClientId().equals(guarantor.getEntityId())) {
|
||||||
throw new InvalidGuarantorException(guarantor.getEntityId(), guarantor.getLoanId());
|
//
|
||||||
|
throw new InvalidGuarantorException(guarantor.getEntityId(), guarantor.getLoanId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (guarantor.isExistingEmployee()) {
|
} else if (guarantor.isExistingEmployee()) {
|
||||||
staffRepositoryWrapper.findOneWithNotFoundDetection(guarantor.getEntityId());
|
staffRepositoryWrapper.findOneWithNotFoundDetection(guarantor.getEntityId());
|
||||||
|
|||||||
Reference in New Issue
Block a user