FINERACT-1734-Repayment-Due-Events-Payload-Extension
This commit is contained in:
committed by
Arnold Gálovics
parent
4c597b61fb
commit
856c47398d
+2
-2
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanRepaymentDueBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.repayment.LoanRepaymentDueBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
||||
@@ -44,7 +44,7 @@ public class CheckLoanRepaymentDueBusinessStep implements LoanCOBBusinessStep {
|
||||
for (LoanRepaymentScheduleInstallment repaymentSchedule : loanRepaymentScheduleInstallments) {
|
||||
LocalDate repaymentDate = repaymentSchedule.getDueDate();
|
||||
if (repaymentDate.minusDays(numberOfDaysBeforeDueDateToRaiseEvent).equals(currentDate)) {
|
||||
businessEventNotifierService.notifyPostBusinessEvent(new LoanRepaymentDueBusinessEvent(loan));
|
||||
businessEventNotifierService.notifyPostBusinessEvent(new LoanRepaymentDueBusinessEvent(repaymentSchedule));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanRepaymentOverdueBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.repayment.LoanRepaymentOverdueBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
||||
@@ -45,7 +45,7 @@ public class CheckLoanRepaymentOverdueBusinessStep implements LoanCOBBusinessSte
|
||||
if (!repaymentSchedule.isObligationsMet()) {
|
||||
LocalDate installmentDueDate = repaymentSchedule.getDueDate();
|
||||
if (installmentDueDate.plusDays(numberOfDaysAfterDueDateToRaiseEvent).equals(currentDate)) {
|
||||
businessEventNotifierService.notifyPostBusinessEvent(new LoanRepaymentOverdueBusinessEvent(loan));
|
||||
businessEventNotifierService.notifyPostBusinessEvent(new LoanRepaymentOverdueBusinessEvent(repaymentSchedule));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 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.infrastructure.event.business.domain.loan.repayment;
|
||||
|
||||
import org.apache.fineract.infrastructure.event.business.domain.AbstractBusinessEvent;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
||||
|
||||
public abstract class LoanRepaymentBusinessEvent extends AbstractBusinessEvent<LoanRepaymentScheduleInstallment> {
|
||||
|
||||
private static final String CATEGORY = "Loan";
|
||||
|
||||
public LoanRepaymentBusinessEvent(LoanRepaymentScheduleInstallment value) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return CATEGORY;
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -16,15 +16,15 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.event.business.domain.loan;
|
||||
package org.apache.fineract.infrastructure.event.business.domain.loan.repayment;
|
||||
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
||||
|
||||
public class LoanRepaymentDueBusinessEvent extends LoanBusinessEvent {
|
||||
public class LoanRepaymentDueBusinessEvent extends LoanRepaymentBusinessEvent {
|
||||
|
||||
private static final String TYPE = "LoanRepaymentDueBusinessEvent";
|
||||
|
||||
public LoanRepaymentDueBusinessEvent(Loan value) {
|
||||
public LoanRepaymentDueBusinessEvent(LoanRepaymentScheduleInstallment value) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
+4
-4
@@ -16,15 +16,15 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.event.business.domain.loan;
|
||||
package org.apache.fineract.infrastructure.event.business.domain.loan.repayment;
|
||||
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
||||
|
||||
public class LoanRepaymentOverdueBusinessEvent extends LoanBusinessEvent {
|
||||
public class LoanRepaymentOverdueBusinessEvent extends LoanRepaymentBusinessEvent {
|
||||
|
||||
private static final String TYPE = "LoanRepaymentOverdueBusinessEvent";
|
||||
|
||||
public LoanRepaymentOverdueBusinessEvent(Loan value) {
|
||||
public LoanRepaymentOverdueBusinessEvent(LoanRepaymentScheduleInstallment value) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* 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.infrastructure.event.external.service.serialization.serializer.loan;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.avro.generic.GenericContainer;
|
||||
import org.apache.fineract.avro.generator.ByteBufferSerializable;
|
||||
import org.apache.fineract.avro.generic.v1.CurrencyDataV1;
|
||||
import org.apache.fineract.avro.loan.v1.LoanRepaymentDueDataV1;
|
||||
import org.apache.fineract.avro.loan.v1.RepaymentDueDataV1;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.BusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.repayment.LoanRepaymentBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.support.AvroDateTimeMapper;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.AbstractBusinessEventSerializer;
|
||||
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class LoanRepaymentBusinessEventSerializer extends AbstractBusinessEventSerializer {
|
||||
|
||||
private final AvroDateTimeMapper dataTimeMapper;
|
||||
|
||||
@Override
|
||||
protected <T> ByteBufferSerializable toAvroDTO(BusinessEvent<T> rawEvent) {
|
||||
|
||||
LoanRepaymentBusinessEvent event = (LoanRepaymentBusinessEvent) rawEvent;
|
||||
LoanRepaymentScheduleInstallment repaymentInstallment = event.get();
|
||||
Loan loan = repaymentInstallment.getLoan();
|
||||
Long id = loan.getId();
|
||||
String accountNo = loan.getAccountNumber();
|
||||
String externalId = loan.getExternalId();
|
||||
String dueDate = dataTimeMapper.mapLocalDate(repaymentInstallment.getDueDate());
|
||||
MonetaryCurrency loanCurrency = loan.getCurrency();
|
||||
CurrencyDataV1 currency = CurrencyDataV1.newBuilder().setCode(loanCurrency.getCode())
|
||||
.setDecimalPlaces(loanCurrency.getDigitsAfterDecimal()).setInMultiplesOf(loanCurrency.getCurrencyInMultiplesOf()).build();
|
||||
BigDecimal totalLoanAmountDue = loan.getLoanSummary().getTotalOutstanding();
|
||||
|
||||
Integer installmentNumber = repaymentInstallment.getInstallmentNumber();
|
||||
BigDecimal principalAmountDue = repaymentInstallment.getPrincipalOutstanding(loanCurrency).getAmount();
|
||||
BigDecimal interestAmountDue = repaymentInstallment.getInterestOutstanding(loanCurrency).getAmount();
|
||||
BigDecimal feeChargeAmountDue = repaymentInstallment.getFeeChargesOutstanding(loanCurrency).getAmount();
|
||||
BigDecimal penaltyChargeAmountDue = repaymentInstallment.getPenaltyChargesOutstanding(loanCurrency).getAmount();
|
||||
BigDecimal totalAmountDue = repaymentInstallment.getTotalOutstanding(loanCurrency).getAmount();
|
||||
|
||||
RepaymentDueDataV1 repaymentDue = new RepaymentDueDataV1(installmentNumber, principalAmountDue, interestAmountDue,
|
||||
feeChargeAmountDue, penaltyChargeAmountDue, totalAmountDue);
|
||||
return new LoanRepaymentDueDataV1(id, accountNo, externalId, dueDate, currency, totalLoanAmountDue, repaymentDue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean canSerialize(BusinessEvent<T> event) {
|
||||
return event instanceof LoanRepaymentBusinessEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends GenericContainer> getSupportedSchema() {
|
||||
return LoanRepaymentDueDataV1.class;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user