diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/PreQualificationStatusLogRepository.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/PreQualificationStatusLogRepository.java new file mode 100644 index 00000000000..5d47aeef40d --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/PreQualificationStatusLogRepository.java @@ -0,0 +1,27 @@ +/** + * 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.domain; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +public interface PreQualificationStatusLogRepository + extends JpaRepository, JpaSpecificationExecutor { + // no behaviour +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/PrequalificationStatusLog.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/PrequalificationStatusLog.java new file mode 100644 index 00000000000..64d3241ab89 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/PrequalificationStatusLog.java @@ -0,0 +1,76 @@ +/** + * 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.domain; + +import lombok.Getter; +import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; +import org.apache.fineract.infrastructure.core.service.DateUtils; +import org.apache.fineract.useradministration.domain.AppUser; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import java.time.LocalDate; + +@Entity +@Table(name = "m_prequalification_status_log") +@Getter +public class PrequalificationStatusLog extends AbstractPersistableCustom { + + @ManyToOne + @JoinColumn(name = "prequalification_id") + private PrequalificationGroup prequalificationGroup; + + @ManyToOne + @JoinColumn(name = "updatedby_id", nullable = false) + private AppUser addedBy; + + @Column(name = "from_status", nullable = false) + private Integer fromStatus; + + @Column(name = "to_status", nullable = false) + private Integer toStatus; + + @Column(name = "date_created", nullable = false) + private LocalDate dateCreated; + + @Column(name = "comments", nullable = false) + private String comments; + + protected PrequalificationStatusLog() { + // + } + + private PrequalificationStatusLog(final AppUser appUser, final Integer fromStatus, final Integer toStatus, final String comments, + final PrequalificationGroup group) { + this.dateCreated = DateUtils.getLocalDateOfTenant(); + this.fromStatus = fromStatus; + this.toStatus = toStatus; + this.prequalificationGroup = group; + this.comments = comments; + this.addedBy = appUser; + } + + public static PrequalificationStatusLog fromJson(final AppUser appUser, final Integer fromStatus, final Integer toStatus, final String comments, + final PrequalificationGroup group) { + return new PrequalificationStatusLog(appUser, fromStatus, toStatus, comments, group); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/BureauValidationWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/BureauValidationWritePlatformServiceImpl.java index 168e5c77b69..d463ee86978 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/BureauValidationWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/BureauValidationWritePlatformServiceImpl.java @@ -24,12 +24,15 @@ import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.organisation.prequalification.domain.PreQualificationMemberRepository; +import org.apache.fineract.organisation.prequalification.domain.PreQualificationStatusLogRepository; 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.domain.PrequalificationStatusLog; import org.apache.fineract.organisation.prequalification.domain.ValidationChecklistResultRepository; +import org.apache.fineract.useradministration.domain.AppUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.jdbc.core.JdbcTemplate; @@ -42,6 +45,7 @@ public class BureauValidationWritePlatformServiceImpl implements BureauValidatio private final PlatformSecurityContext context; private final PrequalificationGroupRepositoryWrapper prequalificationGroupRepositoryWrapper; private final PreQualificationMemberRepository preQualificationMemberRepository; + private final PreQualificationStatusLogRepository preQualificationStatusLogRepository; private final ValidationChecklistResultRepository validationChecklistResultRepository; private final PlatformSecurityContext platformSecurityContext; private final JdbcTemplate jdbcTemplate; @@ -49,6 +53,7 @@ public class BureauValidationWritePlatformServiceImpl implements BureauValidatio public BureauValidationWritePlatformServiceImpl(PlatformSecurityContext context, final PreQualificationMemberRepository preQualificationMemberRepository, PrequalificationGroupRepositoryWrapper prequalificationGroupRepositoryWrapper, + final PreQualificationStatusLogRepository preQualificationStatusLogRepository, ValidationChecklistResultRepository validationChecklistResultRepository, PlatformSecurityContext platformSecurityContext, JdbcTemplate jdbcTemplate) { this.context = context; @@ -56,6 +61,7 @@ public BureauValidationWritePlatformServiceImpl(PlatformSecurityContext context, this.validationChecklistResultRepository = validationChecklistResultRepository; this.platformSecurityContext = platformSecurityContext; this.preQualificationMemberRepository = preQualificationMemberRepository; + this.preQualificationStatusLogRepository = preQualificationStatusLogRepository; this.jdbcTemplate = jdbcTemplate; } @@ -65,6 +71,9 @@ public CommandProcessingResult validatePrequalificationWithBureau(Long prequalif PrequalificationGroup prequalificationGroup = this.prequalificationGroupRepositoryWrapper .findOneWithNotFoundDetection(prequalificationId); + Integer fromStatus = prequalificationGroup.getStatus(); + AppUser addedBy = this.context.getAuthenticatedUserIfPresent(); + // TODO --PROCESS THE PREQUALIFICATION GROUP WITH THE BUREAU AND UPDATE MEMBERS WITH THE RESULTS List members = this.preQualificationMemberRepository .findAllByPrequalificationGroup(prequalificationGroup); @@ -77,6 +86,11 @@ public CommandProcessingResult validatePrequalificationWithBureau(Long prequalif prequalificationGroup.updateStatus(PrequalificationStatus.BURO_CHECKED); this.prequalificationGroupRepositoryWrapper.save(prequalificationGroup); + PrequalificationStatusLog statusLog = PrequalificationStatusLog.fromJson(addedBy, fromStatus, + prequalificationGroup.getStatus(), null, prequalificationGroup); + + this.preQualificationStatusLogRepository.saveAndFlush(statusLog); + return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withResourceIdAsString(prequalificationGroup.getId().toString()) // 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 d9821287c8d..c8bf96df2d5 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 @@ -42,10 +42,12 @@ import org.apache.fineract.organisation.prequalification.data.HardPolicyCategoryData; import org.apache.fineract.organisation.prequalification.domain.CheckValidationColor; import org.apache.fineract.organisation.prequalification.domain.HardPolicyCategory; +import org.apache.fineract.organisation.prequalification.domain.PreQualificationStatusLogRepository; 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.PrequalificationStatus; +import org.apache.fineract.organisation.prequalification.domain.PrequalificationStatusLog; import org.apache.fineract.organisation.prequalification.domain.PrequalificationType; import org.apache.fineract.organisation.prequalification.domain.ValidationChecklistResult; import org.apache.fineract.organisation.prequalification.domain.ValidationChecklistResultRepository; @@ -64,16 +66,19 @@ public class PrequalificationChecklistWritePlatformServiceImpl implements Prequa private final PlatformSecurityContext context; private final PrequalificationGroupRepositoryWrapper prequalificationGroupRepositoryWrapper; private final ValidationChecklistResultRepository validationChecklistResultRepository; + private final PreQualificationStatusLogRepository preQualificationStatusLogRepository; private final PlatformSecurityContext platformSecurityContext; private final JdbcTemplate jdbcTemplate; public PrequalificationChecklistWritePlatformServiceImpl(PlatformSecurityContext context, PrequalificationGroupRepositoryWrapper prequalificationGroupRepositoryWrapper, + final PreQualificationStatusLogRepository preQualificationStatusLogRepository, ValidationChecklistResultRepository validationChecklistResultRepository, PlatformSecurityContext platformSecurityContext, JdbcTemplate jdbcTemplate) { this.context = context; this.prequalificationGroupRepositoryWrapper = prequalificationGroupRepositoryWrapper; this.validationChecklistResultRepository = validationChecklistResultRepository; + this.preQualificationStatusLogRepository = preQualificationStatusLogRepository; this.platformSecurityContext = platformSecurityContext; this.jdbcTemplate = jdbcTemplate; } @@ -81,10 +86,13 @@ public PrequalificationChecklistWritePlatformServiceImpl(PlatformSecurityContext @Override @Transactional public CommandProcessingResult validatePrequalificationHardPolicies(Long prequalificationId, JsonCommand command) { - this.context.authenticatedUser(); + AppUser appUser = this.context.authenticatedUser(); PrequalificationGroup prequalificationGroup = this.prequalificationGroupRepositoryWrapper .findOneWithNotFoundDetection(prequalificationId); final Long productId = prequalificationGroup.getLoanProduct().getId(); + + Integer fromStatus = prequalificationGroup.getStatus(); + List validationChecklistResults = new ArrayList<>(); CheckCategoryMapper checkCategoryMapper = new CheckCategoryMapper(); List groupPolicies = this.jdbcTemplate.query(checkCategoryMapper.schema(), checkCategoryMapper, productId, @@ -138,6 +146,12 @@ public CommandProcessingResult validatePrequalificationHardPolicies(Long prequal prequalificationGroup.updateStatus(PrequalificationStatus.HARD_POLICY_CHECKED); prequalificationGroupRepositoryWrapper.saveAndFlush(prequalificationGroup); this.validationChecklistResultRepository.saveAll(validationChecklistResults); + + PrequalificationStatusLog statusLog = PrequalificationStatusLog.fromJson(appUser, fromStatus, + prequalificationGroup.getStatus(), null, prequalificationGroup); + + this.preQualificationStatusLogRepository.saveAndFlush(statusLog); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(prequalificationId).build(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationWritePlatformServiceImpl.java index beb472f171f..21b2d30c23e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationWritePlatformServiceImpl.java @@ -49,11 +49,13 @@ 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.PreQualificationStatusLogRepository; 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.domain.PrequalificationStatusLog; import org.apache.fineract.organisation.prequalification.serialization.PrequalificationMemberCommandFromApiJsonDeserializer; import org.apache.fineract.portfolio.blacklist.domain.BlacklistStatus; import org.apache.fineract.portfolio.client.service.ClientChargeWritePlatformServiceJpaRepositoryImpl; @@ -73,6 +75,8 @@ import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; +import javax.transaction.Transactional; + @Service @Slf4j public class PrequalificationWritePlatformServiceImpl implements PrequalificationWritePlatformService { @@ -85,6 +89,7 @@ public class PrequalificationWritePlatformServiceImpl implements Prequalificatio private final ClientReadPlatformService clientReadPlatformService; private final CodeValueReadPlatformService codeValueReadPlatformService; private final PrequalificationGroupRepositoryWrapper prequalificationGroupRepositoryWrapper; + private final PreQualificationStatusLogRepository preQualificationLogRepository; private final PrequalificationChecklistReadPlatformService prequalificationChecklistReadPlatformService; private final PreQualificationMemberRepository preQualificationMemberRepository; private final GroupRepositoryWrapper groupRepositoryWrapper; @@ -100,6 +105,7 @@ public PrequalificationWritePlatformServiceImpl(final PlatformSecurityContext co final ClientReadPlatformService clientReadPlatformService, final AgencyRepositoryWrapper agencyRepositoryWrapper, final PrequalificationMemberCommandFromApiJsonDeserializer apiJsonDeserializer, final PreQualificationMemberRepository preQualificationMemberRepository, + final PreQualificationStatusLogRepository preQualificationLogRepository, final PrequalificationChecklistReadPlatformService prequalificationChecklistReadPlatformService, final CodeValueReadPlatformService codeValueReadPlatformService, final JdbcTemplate jdbcTemplate, final PrequalificationGroupRepositoryWrapper prequalificationGroupRepositoryWrapper) { @@ -115,9 +121,11 @@ public PrequalificationWritePlatformServiceImpl(final PlatformSecurityContext co this.apiJsonDeserializer = apiJsonDeserializer; this.preQualificationMemberRepository = preQualificationMemberRepository; this.prequalificationChecklistReadPlatformService = prequalificationChecklistReadPlatformService; + this.preQualificationLogRepository = preQualificationLogRepository; this.jdbcTemplate = jdbcTemplate; } + @Transactional @Override public CommandProcessingResult processPrequalification(JsonCommand command) { @@ -170,6 +178,11 @@ public CommandProcessingResult processPrequalification(JsonCommand command) { prequalificationGroup.updateMembers(members); this.prequalificationGroupRepositoryWrapper.saveAndFlush(prequalificationGroup); + PrequalificationStatusLog statusLog = PrequalificationStatusLog.fromJson(addedBy, PrequalificationStatus.PENDING.getValue(), + prequalificationGroup.getStatus(), null, prequalificationGroup); + + this.preQualificationLogRepository.saveAndFlush(statusLog); + return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withResourceIdAsString(prequalificationGroup.getId().toString()) // @@ -295,8 +308,13 @@ private List assembNewMembers(JsonCommand command, public Long addCommentsToPrequalification(Long groupId, String comment) { PrequalificationGroup prequalificationGroup = this.prequalificationGroupRepositoryWrapper.findOneWithNotFoundDetection(groupId); prequalificationGroup.updateComments(comment); + Integer fromStatus = prequalificationGroup.getStatus(); prequalificationGroup.updateStatus(PrequalificationStatus.CONSENT_ADDED); this.prequalificationGroupRepositoryWrapper.saveAndFlush(prequalificationGroup); + AppUser addedBy = this.context.getAuthenticatedUserIfPresent(); + PrequalificationStatusLog statusLog = PrequalificationStatusLog.fromJson(addedBy, + fromStatus, prequalificationGroup.getStatus(), comment, prequalificationGroup); + this.preQualificationLogRepository.saveAndFlush(statusLog); return groupId; } @@ -575,13 +593,19 @@ public void disableExpiredPrequalifications() throws JobExecutionException { @Override public CommandProcessingResult requestUpdates(Long entityId, JsonCommand command) { - this.context.authenticatedUser(); + AppUser addedBy = this.context.authenticatedUser(); final PrequalificationGroup prequalificationGroup = this.prequalificationGroupRepositoryWrapper .findOneWithNotFoundDetection(entityId); + Integer fromStatus = prequalificationGroup.getStatus(); prequalificationGroup.updateStatus(PrequalificationStatus.PREQUALIFICATION_UPDATE_REQUESTED); - prequalificationGroup.updateComments(command.stringValueOfParameterNamed("comments")); + String comments = command.stringValueOfParameterNamed("comments"); + prequalificationGroup.updateComments(comments); this.prequalificationGroupRepositoryWrapper.save(prequalificationGroup); + PrequalificationStatusLog statusLog = PrequalificationStatusLog.fromJson(addedBy, fromStatus, + prequalificationGroup.getStatus(),comments , prequalificationGroup); + + this.preQualificationLogRepository.saveAndFlush(statusLog); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(prequalificationGroup.getId()).build(); } @@ -590,10 +614,11 @@ public CommandProcessingResult sendForAnalysis(Long entityId, JsonCommand comman final PrequalificationGroup prequalificationGroup = this.prequalificationGroupRepositoryWrapper .findOneWithNotFoundDetection(entityId); + AppUser appUser = this.context.authenticatedUser(); PrequalificationChecklistData prequalificationChecklistData = this.prequalificationChecklistReadPlatformService .retrieveHardPolicyValidationResults(entityId); GenericValidationResultSet prequalification = prequalificationChecklistData.getPrequalification(); - + Integer fromStatus = prequalificationGroup.getStatus(); List exceptionsList = List.of("ORANGE", "RED", "YELLOW"); List> rows = prequalification.getRows(); AtomicReference status = new AtomicReference<>(PrequalificationStatus.AGENCY_LEAD_PENDING_APPROVAL); @@ -608,6 +633,13 @@ public CommandProcessingResult sendForAnalysis(Long entityId, JsonCommand comman prequalificationGroup.updateStatus(status.get()); prequalificationGroupRepositoryWrapper.save(prequalificationGroup); + this.prequalificationGroupRepositoryWrapper.save(prequalificationGroup); + + PrequalificationStatusLog statusLog = PrequalificationStatusLog.fromJson(appUser, fromStatus, + prequalificationGroup.getStatus(),null , prequalificationGroup); + + this.preQualificationLogRepository.saveAndFlush(statusLog); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(prequalificationGroup.getId()).build(); } } diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml index d2c6fdd21b6..41d30ed4527 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml +++ b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml @@ -106,4 +106,5 @@ + diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0090_FBR_313_Add_Prequalificatioin_Checklist_log.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0090_FBR_313_Add_Prequalificatioin_Checklist_log.xml new file mode 100644 index 00000000000..65fe8666791 --- /dev/null +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0090_FBR_313_Add_Prequalificatioin_Checklist_log.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +