Skip to content

Commit

Permalink
Merge pull request #202 from fiterlatam/feature/PrequalificationLogs
Browse files Browse the repository at this point in the history
Add logs to prequalification
  • Loading branch information
BrianMuhimbura authored Sep 28, 2023
2 parents 76da735 + 8fb2c2e commit a24d9d3
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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<PrequalificationStatusLog, Long>, JpaSpecificationExecutor<PrequalificationStatusLog> {
// no behaviour
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,20 +45,23 @@ 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;

public BureauValidationWritePlatformServiceImpl(PlatformSecurityContext context,
final PreQualificationMemberRepository preQualificationMemberRepository,
PrequalificationGroupRepositoryWrapper prequalificationGroupRepositoryWrapper,
final PreQualificationStatusLogRepository preQualificationStatusLogRepository,
ValidationChecklistResultRepository validationChecklistResultRepository, PlatformSecurityContext platformSecurityContext,
JdbcTemplate jdbcTemplate) {
this.context = context;
this.prequalificationGroupRepositoryWrapper = prequalificationGroupRepositoryWrapper;
this.validationChecklistResultRepository = validationChecklistResultRepository;
this.platformSecurityContext = platformSecurityContext;
this.preQualificationMemberRepository = preQualificationMemberRepository;
this.preQualificationStatusLogRepository = preQualificationStatusLogRepository;
this.jdbcTemplate = jdbcTemplate;
}

Expand All @@ -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<PrequalificationGroupMember> members = this.preQualificationMemberRepository
.findAllByPrequalificationGroup(prequalificationGroup);
Expand All @@ -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()) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -64,27 +66,33 @@ 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;
}

@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<ValidationChecklistResult> validationChecklistResults = new ArrayList<>();
CheckCategoryMapper checkCategoryMapper = new CheckCategoryMapper();
List<HardPolicyCategoryData> groupPolicies = this.jdbcTemplate.query(checkCategoryMapper.schema(), checkCategoryMapper, productId,
Expand Down Expand Up @@ -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();
}

Expand Down
Loading

0 comments on commit a24d9d3

Please sign in to comment.