Skip to content

Commit

Permalink
Merge pull request #199 from fiterlatam/feature/FBR-312
Browse files Browse the repository at this point in the history
Feature/fbr 312
  • Loading branch information
BrianMuhimbura authored Sep 27, 2023
2 parents c41e091 + b7aba34 commit 2fd9f9f
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3902,4 +3902,12 @@ public CommandWrapperBuilder requestUpdatePrequalification(Long prequalification
this.href = "/prequalification/checklist/" + prequalificationId;
return this;
}

public CommandWrapperBuilder sendGroupForAnalysis(Long prequalificationId) {
this.actionName = "REQUESTANALYSIS";
this.entityName = "PREQUALIFICATIONS";
this.entityId = prequalificationId;
this.href = "/prequalification/checklist/" + prequalificationId;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public PrequalificationChecklistApiResource(final ApiRequestParameterHelper apiR
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveHardPolicyValidationResults(@QueryParam("prequalificationId") final Integer prequalificationId,
public String retrieveHardPolicyValidationResults(@QueryParam("prequalificationId") final Long prequalificationId,
@QueryParam("groupId") final Integer groupId, @QueryParam("clientId") final Long clientId, @Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
Expand Down Expand Up @@ -111,14 +111,15 @@ public String validateHardPolicyChecklist(@PathParam("prequalificationId") final
if (is(commandParam, "validateprequalification")) {
final CommandWrapper validateCommandRequest = builder.validatePrequalificationHardPolicies(prequalificationId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(validateCommandRequest);
}
if (is(commandParam, "bureauValidation")) {
} else if (is(commandParam, "bureauValidation")) {
final CommandWrapper validateCommandRequest = builder.bureauValidationProcessing(prequalificationId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(validateCommandRequest);
}
if (is(commandParam, "requestUpdates")) {
} else if (is(commandParam, "requestUpdates")) {
final CommandWrapper validateCommandRequest = builder.requestUpdatePrequalification(prequalificationId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(validateCommandRequest);
} else if (is(commandParam, "sendToAnalysis")) {
final CommandWrapper validateCommandRequest = builder.sendGroupForAnalysis(prequalificationId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(validateCommandRequest);
} else {
final CommandWrapper commandRequest = builder.validatePrequalificationHardPolicies(prequalificationId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public static EnumOptionData status(final PrequalificationStatus status) {
case PREQUALIFICATION_UPDATE_REQUESTED -> new EnumOptionData(
PrequalificationStatus.PREQUALIFICATION_UPDATE_REQUESTED.getValue().longValue(),
PrequalificationStatus.PREQUALIFICATION_UPDATE_REQUESTED.getCode(), "PREQUALIFICATION_UPDATE_REQUESTED");
case AGENCY_LEAD_PENDING_APPROVAL_WITH_EXCEPTIONS -> new EnumOptionData(
PrequalificationStatus.AGENCY_LEAD_PENDING_APPROVAL_WITH_EXCEPTIONS.getValue().longValue(),
PrequalificationStatus.AGENCY_LEAD_PENDING_APPROVAL_WITH_EXCEPTIONS.getCode(),
"AGENCY_LEAD_PENDING_APPROVAL_WITH_EXCEPTIONS");
default -> new EnumOptionData(PrequalificationStatus.INVALID.getValue().longValue(), PrequalificationStatus.INVALID.getCode(),
"INVALID");
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public enum PrequalificationStatus {
800, "prequalification.status.expired"), COMPLETED(900, "prequalification.status.completed"), CONSENT_ADDED(901,
"prequalification.status.concent.added"), AGENCY_LEAD_PENDING_APPROVAL(902,
"prequalification.status.pending.approval"), PREQUALIFICATION_UPDATE_REQUESTED(903,
"prequalification.status.update.requested"), INVALID(0, "prequalification.status.invalid");
"prequalification.status.update.requested"), AGENCY_LEAD_PENDING_APPROVAL_WITH_EXCEPTIONS(904,
"prequalification.status.pending.approval.exceptions"), INVALID(0,
"prequalification.status.invalid");

private final Integer value;
private final String code;
Expand Down Expand Up @@ -79,6 +81,9 @@ public static PrequalificationStatus fromInt(final Integer statusValue) {
case 903:
enumeration = PrequalificationStatus.PREQUALIFICATION_UPDATE_REQUESTED;
break;
case 904:
enumeration = PrequalificationStatus.AGENCY_LEAD_PENDING_APPROVAL_WITH_EXCEPTIONS;
break;
}
return enumeration;
}
Expand Down Expand Up @@ -120,6 +125,8 @@ public static PrequalificationStatus fromString(String status) {
clientStatus = PrequalificationStatus.AGENCY_LEAD_PENDING_APPROVAL;
} else if (status.equalsIgnoreCase(PrequalificationStatus.PREQUALIFICATION_UPDATE_REQUESTED.toString())) {
clientStatus = PrequalificationStatus.PREQUALIFICATION_UPDATE_REQUESTED;
} else if (status.equalsIgnoreCase(PrequalificationStatus.AGENCY_LEAD_PENDING_APPROVAL_WITH_EXCEPTIONS.toString())) {
clientStatus = PrequalificationStatus.AGENCY_LEAD_PENDING_APPROVAL_WITH_EXCEPTIONS;
}

return clientStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* 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.handler;

import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.organisation.prequalification.service.PrequalificationWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@CommandType(entity = "PREQUALIFICATIONS", action = "REQUESTANALYSIS")
public class SendPrequalificationToAnalysisCommandHandler implements NewCommandSourceHandler {

private final PrequalificationWritePlatformService prequalificationWritePlatformService;

@Autowired
public SendPrequalificationToAnalysisCommandHandler(final PrequalificationWritePlatformService prequalificationWritePlatformService) {
this.prequalificationWritePlatformService = prequalificationWritePlatformService;
}

@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {

return this.prequalificationWritePlatformService.sendForAnalysis(command.entityId(), command);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public interface PrequalificationChecklistReadPlatformService {

PrequalificationChecklistData retrieveHardPolicyValidationResults(final Integer prequalificationId);
PrequalificationChecklistData retrieveHardPolicyValidationResults(final Long prequalificationId);

GenericValidationResultSet retrieveClientHardPolicyDetails(Long clientId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public PrequalificationChecklistReadPlatformServiceImpl(JdbcTemplate jdbcTemplat
}

@Override
public PrequalificationChecklistData retrieveHardPolicyValidationResults(final Integer prequalificationId) {
public PrequalificationChecklistData retrieveHardPolicyValidationResults(final Long prequalificationId) {
PrequalificationGroup prequalificationGroup = this.prequalificationGroupRepositoryWrapper
.findOneWithNotFoundDetection(Long.valueOf(prequalificationId));
.findOneWithNotFoundDetection(prequalificationId);
final Long productId = prequalificationGroup.getLoanProduct().getId();
final PrequalificationChecklistWritePlatformServiceImpl.CheckCategoryMapper checkCategoryMapper = new PrequalificationChecklistWritePlatformServiceImpl.CheckCategoryMapper();
final List<HardPolicyCategoryData> groupPolicies = this.jdbcTemplate.query(checkCategoryMapper.schema(), checkCategoryMapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ public interface PrequalificationWritePlatformService {
void disableExpiredPrequalifications() throws JobExecutionException;

CommandProcessingResult requestUpdates(Long entityId, JsonCommand command);

CommandProcessingResult sendForAnalysis(Long entityId, JsonCommand command);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService;
Expand All @@ -45,13 +46,14 @@
import org.apache.fineract.organisation.agency.domain.AgencyRepositoryWrapper;
import org.apache.fineract.organisation.prequalification.command.PrequalificationDataValidator;
import org.apache.fineract.organisation.prequalification.command.PrequalificatoinApiConstants;
import org.apache.fineract.organisation.prequalification.data.GenericValidationResultSet;
import org.apache.fineract.organisation.prequalification.data.PrequalificationChecklistData;
import org.apache.fineract.organisation.prequalification.domain.PreQualificationMemberRepository;
import org.apache.fineract.organisation.prequalification.domain.PrequalificationGroup;
import org.apache.fineract.organisation.prequalification.domain.PrequalificationGroupMember;
import org.apache.fineract.organisation.prequalification.domain.PrequalificationGroupRepositoryWrapper;
import org.apache.fineract.organisation.prequalification.domain.PrequalificationMemberIndication;
import org.apache.fineract.organisation.prequalification.domain.PrequalificationStatus;
import org.apache.fineract.organisation.prequalification.exception.GroupPreQualificationNotFound;
import org.apache.fineract.organisation.prequalification.serialization.PrequalificationMemberCommandFromApiJsonDeserializer;
import org.apache.fineract.portfolio.blacklist.domain.BlacklistStatus;
import org.apache.fineract.portfolio.client.service.ClientChargeWritePlatformServiceJpaRepositoryImpl;
Expand Down Expand Up @@ -83,6 +85,7 @@ public class PrequalificationWritePlatformServiceImpl implements Prequalificatio
private final ClientReadPlatformService clientReadPlatformService;
private final CodeValueReadPlatformService codeValueReadPlatformService;
private final PrequalificationGroupRepositoryWrapper prequalificationGroupRepositoryWrapper;
private final PrequalificationChecklistReadPlatformService prequalificationChecklistReadPlatformService;
private final PreQualificationMemberRepository preQualificationMemberRepository;
private final GroupRepositoryWrapper groupRepositoryWrapper;
private final AppUserRepository appUserRepository;
Expand All @@ -97,6 +100,7 @@ public PrequalificationWritePlatformServiceImpl(final PlatformSecurityContext co
final ClientReadPlatformService clientReadPlatformService, final AgencyRepositoryWrapper agencyRepositoryWrapper,
final PrequalificationMemberCommandFromApiJsonDeserializer apiJsonDeserializer,
final PreQualificationMemberRepository preQualificationMemberRepository,
final PrequalificationChecklistReadPlatformService prequalificationChecklistReadPlatformService,
final CodeValueReadPlatformService codeValueReadPlatformService, final JdbcTemplate jdbcTemplate,
final PrequalificationGroupRepositoryWrapper prequalificationGroupRepositoryWrapper) {
this.context = context;
Expand All @@ -110,6 +114,7 @@ public PrequalificationWritePlatformServiceImpl(final PlatformSecurityContext co
this.agencyRepositoryWrapper = agencyRepositoryWrapper;
this.apiJsonDeserializer = apiJsonDeserializer;
this.preQualificationMemberRepository = preQualificationMemberRepository;
this.prequalificationChecklistReadPlatformService = prequalificationChecklistReadPlatformService;
this.jdbcTemplate = jdbcTemplate;
}

Expand Down Expand Up @@ -573,13 +578,36 @@ public CommandProcessingResult requestUpdates(Long entityId, JsonCommand command
this.context.authenticatedUser();
final PrequalificationGroup prequalificationGroup = this.prequalificationGroupRepositoryWrapper
.findOneWithNotFoundDetection(entityId);
if (prequalificationGroup == null) {
throw new GroupPreQualificationNotFound(entityId);
}
prequalificationGroup.updateStatus(PrequalificationStatus.PREQUALIFICATION_UPDATE_REQUESTED);
prequalificationGroup.updateComments(command.stringValueOfParameterNamed("comments"));
this.prequalificationGroupRepositoryWrapper.save(prequalificationGroup);

return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(prequalificationGroup.getId()).build();
}

@Override
public CommandProcessingResult sendForAnalysis(Long entityId, JsonCommand command) {
final PrequalificationGroup prequalificationGroup = this.prequalificationGroupRepositoryWrapper
.findOneWithNotFoundDetection(entityId);

PrequalificationChecklistData prequalificationChecklistData = this.prequalificationChecklistReadPlatformService
.retrieveHardPolicyValidationResults(entityId);
GenericValidationResultSet prequalification = prequalificationChecklistData.getPrequalification();

List<String> exceptionsList = List.of("ORANGE", "RED", "YELLOW");
List<List<String>> rows = prequalification.getRows();
AtomicReference<PrequalificationStatus> status = new AtomicReference<>(PrequalificationStatus.AGENCY_LEAD_PENDING_APPROVAL);
for (List<String> innerList : rows) {
innerList.forEach(item -> {
if (exceptionsList.contains(item)) {
status.set(PrequalificationStatus.AGENCY_LEAD_PENDING_APPROVAL_WITH_EXCEPTIONS);
}
});
}

prequalificationGroup.updateStatus(status.get());
prequalificationGroupRepositoryWrapper.save(prequalificationGroup);

return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(prequalificationGroup.getId()).build();
}
}
Loading

0 comments on commit 2fd9f9f

Please sign in to comment.