FINERACT-2181: Add customData field to LoanAccountDelinquencyRangeBusinessEvent
This commit is contained in:
committed by
Adam Saghy
parent
2eca91eb98
commit
6a65bc6592
@@ -61,6 +61,17 @@
|
||||
"items": "org.apache.fineract.avro.loan.v1.LoanInstallmentDelinquencyBucketDataV1"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"default": null,
|
||||
"name": "customData",
|
||||
"type": [
|
||||
"null",
|
||||
{
|
||||
"values": "bytes",
|
||||
"type": "map"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+12
-3
@@ -36,7 +36,8 @@ import org.apache.fineract.infrastructure.event.external.service.serialization.m
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanChargeDataMapper;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanDelinquencyRangeDataMapper;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.support.AvroDateTimeMapper;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.AbstractBusinessEventWithCustomDataSerializer;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.ExternalEventCustomDataSerializer;
|
||||
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
|
||||
import org.apache.fineract.portfolio.delinquency.service.DelinquencyReadPlatformService;
|
||||
import org.apache.fineract.portfolio.loanaccount.data.CollectionData;
|
||||
@@ -52,7 +53,8 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Order(Ordered.LOWEST_PRECEDENCE - 1)
|
||||
public class LoanDelinquencyRangeChangeBusinessEventSerializer implements BusinessEventSerializer {
|
||||
public class LoanDelinquencyRangeChangeBusinessEventSerializer
|
||||
extends AbstractBusinessEventWithCustomDataSerializer<LoanDelinquencyRangeChangeBusinessEvent> {
|
||||
|
||||
private final LoanReadPlatformService service;
|
||||
|
||||
@@ -67,6 +69,7 @@ public class LoanDelinquencyRangeChangeBusinessEventSerializer implements Busine
|
||||
private final CurrencyDataMapper currencyMapper;
|
||||
private final AvroDateTimeMapper dataTimeMapper;
|
||||
private final LoanInstallmentLevelDelinquencyEventProducer installmentLevelDelinquencyEventProducer;
|
||||
private final List<ExternalEventCustomDataSerializer<LoanDelinquencyRangeChangeBusinessEvent>> externalEventCustomDataSerializers;
|
||||
|
||||
@Override
|
||||
public <T> ByteBufferSerializable toAvroDTO(BusinessEvent<T> rawEvent) {
|
||||
@@ -111,7 +114,8 @@ public class LoanDelinquencyRangeChangeBusinessEventSerializer implements Busine
|
||||
.setAmount(amount)//
|
||||
.setCurrency(currencyMapper.map(data.getCurrency()))//
|
||||
.setDelinquentDate(delinquentDate)//
|
||||
.setInstallmentDelinquencyBuckets(installmentsDelinquencyData).build();
|
||||
.setInstallmentDelinquencyBuckets(installmentsDelinquencyData)//
|
||||
.setCustomData(collectCustomData(event)).build();
|
||||
}
|
||||
|
||||
private BigDecimal calculateDataSummary(Loan loan, BiFunction<Loan, LoanRepaymentScheduleInstallment, BigDecimal> mapper) {
|
||||
@@ -129,4 +133,9 @@ public class LoanDelinquencyRangeChangeBusinessEventSerializer implements Busine
|
||||
public Class<? extends GenericContainer> getSupportedSchema() {
|
||||
return LoanAccountDelinquencyRangeDataV1.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ExternalEventCustomDataSerializer<LoanDelinquencyRangeChangeBusinessEvent>> getExternalEventCustomDataSerializers() {
|
||||
return externalEventCustomDataSerializers;
|
||||
}
|
||||
}
|
||||
|
||||
+57
-2
@@ -18,7 +18,9 @@
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.event.external.service.serialization.serializer.loan;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
@@ -31,6 +33,7 @@ import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
@@ -55,6 +58,7 @@ import org.apache.fineract.infrastructure.event.external.service.serialization.m
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanChargeDataMapperImpl;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanDelinquencyRangeDataMapperImpl;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.support.AvroDateTimeMapper;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.ExternalEventCustomDataSerializer;
|
||||
import org.apache.fineract.organisation.monetary.data.CurrencyData;
|
||||
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
|
||||
import org.apache.fineract.organisation.monetary.domain.Money;
|
||||
@@ -119,6 +123,8 @@ public class LoanAccountDelinquencyRangeEventSerializerTest {
|
||||
|
||||
private MockedStatic<MoneyHelper> moneyHelper = Mockito.mockStatic(MoneyHelper.class);
|
||||
|
||||
private static final String CUSTOM_DATA_PREFIX = "test_data_loan_delinquency_range_business_event";
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
moneyHelper.when(MoneyHelper::getMathContext).thenReturn(new MathContext(12, RoundingMode.UP));
|
||||
@@ -141,7 +147,8 @@ public class LoanAccountDelinquencyRangeEventSerializerTest {
|
||||
LoanDelinquencyRangeChangeBusinessEventSerializer serializer = new LoanDelinquencyRangeChangeBusinessEventSerializer(
|
||||
loanReadPlatformService, new LoanDelinquencyRangeDataMapperImpl(), loanChargeReadPlatformService,
|
||||
delinquencyReadPlatformService, new LoanChargeDataMapperImpl(null, null, null), new CurrencyDataMapperImpl(), mapper,
|
||||
new LoanInstallmentLevelDelinquencyEventProducer(delinquencyReadPlatformService, new CurrencyDataMapperImpl()));
|
||||
new LoanInstallmentLevelDelinquencyEventProducer(delinquencyReadPlatformService, new CurrencyDataMapperImpl()),
|
||||
createCustomDataForEvents());
|
||||
|
||||
Loan loanForProcessing = Mockito.mock(Loan.class);
|
||||
LoanAccountData loanAccountData = mock(LoanAccountData.class);
|
||||
@@ -193,6 +200,11 @@ public class LoanAccountDelinquencyRangeEventSerializerTest {
|
||||
assertEquals(0, data.getAmount().getFeeAmount().compareTo(new BigDecimal("5.0")));
|
||||
assertEquals(0, data.getAmount().getPenaltyAmount().compareTo(new BigDecimal("50.0")));
|
||||
assertEquals(delinquentDateAsStr, data.getDelinquentDate());
|
||||
|
||||
assertNotNull(data.getCustomData());
|
||||
final Map<String, ByteBuffer> customData = data.getCustomData();
|
||||
assertEquals(CUSTOM_DATA_PREFIX + "_1", new String(customData.get("test_key_1").array(), UTF_8));
|
||||
assertEquals(CUSTOM_DATA_PREFIX + "_2", new String(customData.get("test_key_2").array(), UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -201,7 +213,8 @@ public class LoanAccountDelinquencyRangeEventSerializerTest {
|
||||
LoanDelinquencyRangeChangeBusinessEventSerializer serializer = new LoanDelinquencyRangeChangeBusinessEventSerializer(
|
||||
loanReadPlatformService, new LoanDelinquencyRangeDataMapperImpl(), loanChargeReadPlatformService,
|
||||
delinquencyReadPlatformService, new LoanChargeDataMapperImpl(null, null, null), new CurrencyDataMapperImpl(), mapper,
|
||||
new LoanInstallmentLevelDelinquencyEventProducer(delinquencyReadPlatformService, new CurrencyDataMapperImpl()));
|
||||
new LoanInstallmentLevelDelinquencyEventProducer(delinquencyReadPlatformService, new CurrencyDataMapperImpl()),
|
||||
createCustomDataForEvents());
|
||||
|
||||
Loan loanForProcessing = Mockito.mock(Loan.class);
|
||||
LoanAccountData loanAccountData = mock(LoanAccountData.class);
|
||||
@@ -284,6 +297,11 @@ public class LoanAccountDelinquencyRangeEventSerializerTest {
|
||||
assertEquals(0, data.getAmount().getPenaltyAmount().compareTo(new BigDecimal("20.0")));
|
||||
assertEquals(delinquentDateAsStr, data.getDelinquentDate());
|
||||
|
||||
assertNotNull(data.getCustomData());
|
||||
final Map<String, ByteBuffer> customData = data.getCustomData();
|
||||
assertEquals(CUSTOM_DATA_PREFIX + "_1", new String(customData.get("test_key_1").array(), UTF_8));
|
||||
assertEquals(CUSTOM_DATA_PREFIX + "_2", new String(customData.get("test_key_2").array(), UTF_8));
|
||||
|
||||
// check installment delinquency data
|
||||
assertEquals(2, data.getInstallmentDelinquencyBuckets().size());
|
||||
|
||||
@@ -414,4 +432,41 @@ public class LoanAccountDelinquencyRangeEventSerializerTest {
|
||||
ReflectionTestUtils.setField(loanCharge, "id", 1L);
|
||||
return loanCharge;
|
||||
}
|
||||
|
||||
private List<ExternalEventCustomDataSerializer<LoanDelinquencyRangeChangeBusinessEvent>> createCustomDataForEvents() {
|
||||
return List.of(new ExternalEventCustomDataSerializer<>() {
|
||||
|
||||
@Override
|
||||
public ByteBuffer serialize(final LoanDelinquencyRangeChangeBusinessEvent event) {
|
||||
return ByteBuffer.wrap(CUSTOM_DATA_PREFIX.getBytes(UTF_8));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return "test_key_1";
|
||||
}
|
||||
}, new ExternalEventCustomDataSerializer<>() {
|
||||
|
||||
@Override
|
||||
public ByteBuffer serialize(final LoanDelinquencyRangeChangeBusinessEvent event) {
|
||||
return ByteBuffer.wrap((CUSTOM_DATA_PREFIX + "_1").getBytes(UTF_8));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return "test_key_1";
|
||||
}
|
||||
}, new ExternalEventCustomDataSerializer<>() {
|
||||
|
||||
@Override
|
||||
public ByteBuffer serialize(final LoanDelinquencyRangeChangeBusinessEvent event) {
|
||||
return ByteBuffer.wrap((CUSTOM_DATA_PREFIX + "_2").getBytes(UTF_8));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return "test_key_2";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user