FINERACT-2068: Loan Status Change History
This commit is contained in:
committed by
Peter Bagrij
parent
bb0c7eba7a
commit
c34f2b4f59
+94
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* 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.portfolio.loanaccount.service;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.apache.fineract.infrastructure.event.business.BusinessEventListener;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanStatusChangedBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanStatusChangeHistory;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanStatusChangeHistoryRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class LoanStatusChangeHistoryListener {
|
||||
|
||||
private final Set<LoanStatus> loanStatuses = new HashSet<>();
|
||||
|
||||
private final BusinessEventNotifierService businessEventNotifierService;
|
||||
private final LoanStatusChangeHistoryRepository loanStatusChangeHistoryRepository;
|
||||
private final FineractProperties fineractProperties;
|
||||
|
||||
@PostConstruct
|
||||
public void addListeners() {
|
||||
loanStatuses.addAll(getLoanStatuses(fineractProperties.getLoan().getStatusChangeHistoryStatuses()));
|
||||
if (loanStatuses.size() > 0) {
|
||||
businessEventNotifierService.addPostBusinessEventListener(LoanStatusChangedBusinessEvent.class,
|
||||
new LoanStatusChangedListener());
|
||||
}
|
||||
}
|
||||
|
||||
Set<LoanStatus> getLoanStatuses(String str) {
|
||||
Set<LoanStatus> result = new HashSet<>();
|
||||
if ("NONE".equals(StringUtils.trim(str))) {
|
||||
return result;
|
||||
} else if ("ALL".equals(StringUtils.trim(str))) {
|
||||
return Arrays.stream(LoanStatus.values()).collect(Collectors.toSet());
|
||||
} else {
|
||||
List<String> split = Splitter.on(",").trimResults().omitEmptyStrings().splitToList(str);
|
||||
for (int i = 0; i < split.size(); i++) {
|
||||
try {
|
||||
result.add(Enum.valueOf(LoanStatus.class, split.get(i)));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
throw new RuntimeException("Invalid loan status: " + split.get(i), iae);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected final class LoanStatusChangedListener implements BusinessEventListener<LoanStatusChangedBusinessEvent> {
|
||||
|
||||
@Override
|
||||
public void onBusinessEvent(LoanStatusChangedBusinessEvent event) {
|
||||
final Loan loan = event.get();
|
||||
log.debug("Loan Status change for loan {} with status {}", loan.getId(), loan.getStatus());
|
||||
if (loanStatuses.contains(loan.getStatus())) {
|
||||
LoanStatusChangeHistory loanStatusChangeHistory = new LoanStatusChangeHistory(loan, loan.getStatus(),
|
||||
DateUtils.getBusinessLocalDate());
|
||||
loanStatusChangeHistoryRepository.saveAndFlush(loanStatusChangeHistory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,6 +142,10 @@ fineract.loan.transactionprocessor.due-penalty-interest-principal-fee-in-advance
|
||||
fineract.loan.transactionprocessor.advanced-payment-strategy.enabled=${FINERACT_LOAN_TRANSACTIONPROCESSOR_ADVANCED_PAYMENT_STRATEGY_ENABLED:true}
|
||||
fineract.loan.transactionprocessor.error-not-found-fail=${FINERACT_LOAN_TRANSACTIONPROCESSOR_ERROR_NOT_FOUND_FAIL:true}
|
||||
|
||||
# Comma separated list of loan statuses which will be recorded on change. There are two extra values: "NONE" and "ALL".
|
||||
# "NONE" disables the feature and no entries will be created, "ALL" enables the feature for all loan statuses.
|
||||
fineract.loan.status-change-history-statuses=${FINERACT_LOAN_STATUS_CHANGE_HISTORY_STATUSES:NONE}
|
||||
|
||||
fineract.content.regex-whitelist-enabled=${FINERACT_CONTENT_REGEX_WHITELIST_ENABLED:true}
|
||||
fineract.content.regex-whitelist=${FINERACT_CONTENT_REGEX_WHITELIST:.*\\.pdf$,.*\\.doc,.*\\.docx,.*\\.xls,.*\\.xlsx,.*\\.jpg,.*\\.jpeg,.*\\.png}
|
||||
fineract.content.mime-whitelist-enabled=${FINERACT_CONTENT_MIME_WHITELIST_ENABLED:true}
|
||||
|
||||
Reference in New Issue
Block a user