FINEREACT-2181: Ignore null values in customData field

This commit is contained in:
Adam Saghy
2025-03-26 10:09:35 +01:00
parent 79c08ed7c9
commit f47b2b3fc2
4 changed files with 50 additions and 17 deletions
@@ -0,0 +1,41 @@
/**
* 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.nio.ByteBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.fineract.infrastructure.event.business.domain.BusinessEvent;
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.BusinessEventSerializer;
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.ExternalEventCustomDataSerializer;
public abstract class AbstractLoanBusinessEventSerializer<T extends BusinessEvent<?>> implements BusinessEventSerializer {
protected Map<String, ByteBuffer> collectCustomData(final T event) {
return getExternalEventCustomDataSerializers().stream().collect(HashMap::new, (map, serializer) -> {
ByteBuffer buffer = serializer.serialize(event);
if (buffer != null) {
map.put(serializer.key(), buffer);
}
}, HashMap::putAll);
}
protected abstract List<ExternalEventCustomDataSerializer<T>> getExternalEventCustomDataSerializers();
}
@@ -18,11 +18,8 @@
*/
package org.apache.fineract.infrastructure.event.external.service.serialization.serializer.loan;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.apache.avro.generic.GenericContainer;
import org.apache.commons.collections4.CollectionUtils;
@@ -50,7 +47,7 @@ import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class LoanBusinessEventSerializer implements BusinessEventSerializer {
public class LoanBusinessEventSerializer extends AbstractLoanBusinessEventSerializer<LoanBusinessEvent> implements BusinessEventSerializer {
private final LoanReadPlatformService service;
private final LoanAccountDataMapper mapper;
@@ -116,9 +113,8 @@ public class LoanBusinessEventSerializer implements BusinessEventSerializer {
return LoanAccountDataV1.class;
}
private Map<String, ByteBuffer> collectCustomData(final LoanBusinessEvent event) {
return externalEventCustomDataSerializers.stream().collect(Collectors.toMap(ExternalEventCustomDataSerializer::key,
serializer -> serializer.serialize(event), (existing, replacement) -> replacement));
@Override
protected List<ExternalEventCustomDataSerializer<LoanBusinessEvent>> getExternalEventCustomDataSerializers() {
return externalEventCustomDataSerializers;
}
}
@@ -62,7 +62,6 @@ public class LoanChargeOffBusinessEventSerializer extends LoanTransactionBusines
LoanTransactionBusinessEvent event = (LoanTransactionBusinessEvent) rawEvent;
List<UnpaidChargeData> unpaidChargeDataList = loanTransactionRepository.fetchTotalUnpaidChargesForLoan(event.get().getLoan());
transactionDataV1.setUnpaidCharges(unpaidChargeDataMapper.map(unpaidChargeDataList));
transactionDataV1.setCustomData(collectCustomData(event));
return transactionDataV1;
}
@@ -18,10 +18,7 @@
*/
package org.apache.fineract.infrastructure.event.external.service.serialization.serializer.loan;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.apache.avro.generic.GenericContainer;
import org.apache.fineract.avro.generator.ByteBufferSerializable;
@@ -38,7 +35,8 @@ import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class LoanTransactionBusinessEventSerializer implements BusinessEventSerializer {
public class LoanTransactionBusinessEventSerializer extends AbstractLoanBusinessEventSerializer<LoanTransactionBusinessEvent>
implements BusinessEventSerializer {
private final LoanReadPlatformService service;
private final LoanTransactionDataMapper loanTransactionMapper;
@@ -69,9 +67,8 @@ public class LoanTransactionBusinessEventSerializer implements BusinessEventSeri
return LoanTransactionDataV1.class;
}
protected Map<String, ByteBuffer> collectCustomData(final LoanTransactionBusinessEvent event) {
return externalEventCustomDataSerializers.stream().collect(Collectors.toMap(ExternalEventCustomDataSerializer::key,
serializer -> serializer.serialize(event), (existing, replacement) -> replacement));
@Override
protected List<ExternalEventCustomDataSerializer<LoanTransactionBusinessEvent>> getExternalEventCustomDataSerializers() {
return externalEventCustomDataSerializers;
}
}