Skip to content

Commit

Permalink
Merge pull request #307 from fiterlatam/feature/FBR-464
Browse files Browse the repository at this point in the history
validate client loan request before hard policy
  • Loading branch information
BrianMuhimbura authored Dec 1, 2023
2 parents d018414 + 5f0c57b commit e0671e2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -159,6 +163,18 @@ public CommandProcessingResult validatePrequalificationHardPolicies(Long prequal
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(prequalificationId).build();
}

private void validateMemberLoanRequest(PrequalificationGroup group) {

List<PrequalificationGroupMember> 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<PolicyData> {

public String schema() {
Expand Down

0 comments on commit e0671e2

Please sign in to comment.