From 5f0c57b88316f1f26a6d5d4e3aa0e57a9f932152 Mon Sep 17 00:00:00 2001 From: Muhimbura Brian Mart Date: Wed, 29 Nov 2023 18:09:24 +0300 Subject: [PATCH] validate client loan request before hard policy --- .../MemberHasNoPendingLoanException.java | 31 +++++++++++++++++++ ...tionChecklistWritePlatformServiceImpl.java | 16 ++++++++++ 2 files changed, 47 insertions(+) create mode 100644 fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/exception/MemberHasNoPendingLoanException.java diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/exception/MemberHasNoPendingLoanException.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/exception/MemberHasNoPendingLoanException.java new file mode 100644 index 00000000000..7a9dc6003fd --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/exception/MemberHasNoPendingLoanException.java @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.organisation.prequalification.exception; + +import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException; + +/** + * A {@link RuntimeException} thrown when client doesn't have a pending loan request. + */ +public class MemberHasNoPendingLoanException extends AbstractPlatformResourceNotFoundException { + + public MemberHasNoPendingLoanException(String name, String dpi, String product) { + super("error.msg.client.pending.loan.request", "Client "+name+ " with dpi " + dpi + " doesnt have a pending loan request.", name, dpi, product); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistWritePlatformServiceImpl.java index bffc5cbf896..54e67936e04 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationChecklistWritePlatformServiceImpl.java @@ -57,6 +57,7 @@ import org.apache.fineract.organisation.prequalification.domain.PrequalificationType; import org.apache.fineract.organisation.prequalification.domain.ValidationChecklistResult; import org.apache.fineract.organisation.prequalification.domain.ValidationChecklistResultRepository; +import org.apache.fineract.organisation.prequalification.exception.MemberHasNoPendingLoanException; import org.apache.fineract.organisation.prequalification.exception.PrequalificationNotMappedException; import org.apache.fineract.useradministration.domain.AppUser; import org.jetbrains.annotations.NotNull; @@ -88,6 +89,9 @@ public CommandProcessingResult validatePrequalificationHardPolicies(Long prequal AppUser appUser = this.context.authenticatedUser(); PrequalificationGroup prequalificationGroup = this.prequalificationGroupRepositoryWrapper .findOneWithNotFoundDetection(prequalificationId); + + validateMemberLoanRequest(prequalificationGroup); + String blistSql = "select count(*) from m_group where prequalification_id=?"; Long attachedGroup = this.jdbcTemplate.queryForObject(blistSql, Long.class, prequalificationId); if (attachedGroup <= 0 && prequalificationGroup.getPrequalificationType().equals(PrequalificationType.GROUP.getValue())) @@ -159,6 +163,18 @@ public CommandProcessingResult validatePrequalificationHardPolicies(Long prequal return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(prequalificationId).build(); } + private void validateMemberLoanRequest(PrequalificationGroup group) { + + List members = group.getMembers(); + for (PrequalificationGroupMember member : members) { + String pendingLoanRequest = "select count(*) from m_loan ml inner join m_client mc on mc.id = ml.client_id where mc.dpi=? AND ml.loan_status_id = 100 and ml.product_id = ?"; + Long loanCount = this.jdbcTemplate.queryForObject(pendingLoanRequest, Long.class, member.getDpi(),group.getLoanProduct().getId()); + if (loanCount<=0) + throw new MemberHasNoPendingLoanException(member.getName(), member.getDpi(), group.getLoanProduct().getName()); + + } + } + static final class PolicyMapper implements RowMapper { public String schema() {