FINERACT-1926: Fineract Asset Externalization events
- [x] Change events - [x] Create data enricher - [x] Core changes - [x] Remove AbstractBusinessEventSerializer - [x] BusinessEventSerializer.toAvroDto added and change the event serializers
This commit is contained in:
+2
@@ -50,6 +50,7 @@ import org.apache.fineract.investor.data.ExternalTransferData;
|
||||
import org.apache.fineract.investor.data.ExternalTransferResponseData;
|
||||
import org.apache.fineract.investor.service.ExternalAssetOwnersReadService;
|
||||
import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformServiceCommon;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -57,6 +58,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@Tag(name = "External Asset Owners", description = "External Asset Owners")
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(value = "fineract.module.external-asset-owner.enabled", havingValue = "true")
|
||||
public class ExternalAssetOwnersApiResource {
|
||||
|
||||
private final PlatformUserRightsContext platformUserRightsContext;
|
||||
|
||||
+6
@@ -41,6 +41,12 @@ public interface ExternalAssetOwnerTransferRepository
|
||||
@Query("select e from ExternalAssetOwnerTransfer e where e.loanId = :loanId and e.id = (select max(ex.id) from ExternalAssetOwnerTransfer ex where ex.loanId = :loanId)")
|
||||
Optional<ExternalAssetOwnerTransfer> findLatestByLoanId(@Param("loanId") Long loanId);
|
||||
|
||||
@Query("select m.ownerTransfer from ExternalAssetOwnerTransferLoanMapping m inner join fetch m.ownerTransfer o where m.loanId = :loanId")
|
||||
Optional<ExternalAssetOwnerTransfer> findActiveByLoanId(@Param("loanId") Long loanId);
|
||||
|
||||
@Query("select m.ownerTransfer.owner from ExternalAssetOwnerTransferLoanMapping m where m.loanId = :loanId")
|
||||
Optional<ExternalAssetOwner> findActiveOwnerByLoanId(@Param("loanId") Long loanId);
|
||||
|
||||
@Query("SELECT t FROM ExternalAssetOwnerTransfer t WHERE t.loanId = :loanId AND t.effectiveDateTo > :effectiveDate")
|
||||
List<ExternalAssetOwnerTransfer> findEffectiveTransfers(@Param("loanId") Long loanId, @Param("effectiveDate") LocalDate effectiveDate);
|
||||
}
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 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.investor.enricher;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.avro.loan.v1.LoanAccountDataV1;
|
||||
import org.apache.fineract.infrastructure.core.domain.ExternalId;
|
||||
import org.apache.fineract.infrastructure.core.service.DataEnricher;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.support.AvroDateTimeMapper;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.support.ExternalIdMapper;
|
||||
import org.apache.fineract.investor.domain.ExternalAssetOwnerTransferRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class LoanAccountDataV1Enricher implements DataEnricher<LoanAccountDataV1> {
|
||||
|
||||
private final ExternalAssetOwnerTransferRepository externalAssetOwnerTransferRepository;
|
||||
private final ExternalIdMapper externalIdMapper;
|
||||
private final AvroDateTimeMapper avroDateTimeMapper;
|
||||
|
||||
@Override
|
||||
public boolean isDataTypeSupported(Class<LoanAccountDataV1> dataType) {
|
||||
return dataType.isAssignableFrom(LoanAccountDataV1.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enrich(LoanAccountDataV1 data) {
|
||||
externalAssetOwnerTransferRepository.findActiveByLoanId(data.getId()).ifPresent(transfer -> {
|
||||
ExternalId transferOwnerExternalId = transfer.getOwner().getExternalId();
|
||||
data.setExternalOwnerId(externalIdMapper.mapExternalId(transferOwnerExternalId));
|
||||
data.setSettlementDate(avroDateTimeMapper.mapLocalDate(transfer.getSettlementDate()));
|
||||
data.setPurchasePriceRatio(transfer.getPurchasePriceRatio());
|
||||
if (data.getCharges() != null) {
|
||||
data.getCharges().forEach(charge -> charge.setExternalOwnerId(externalIdMapper.mapExternalId(transferOwnerExternalId)));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 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.investor.enricher;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.avro.loan.v1.LoanChargeDataV1;
|
||||
import org.apache.fineract.infrastructure.core.service.DataEnricher;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.support.ExternalIdMapper;
|
||||
import org.apache.fineract.investor.domain.ExternalAssetOwnerTransferRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class LoanChargeDataV1Enricher implements DataEnricher<LoanChargeDataV1> {
|
||||
|
||||
private final ExternalAssetOwnerTransferRepository externalAssetOwnerTransferRepository;
|
||||
private final ExternalIdMapper externalIdMapper;
|
||||
|
||||
@Override
|
||||
public boolean isDataTypeSupported(Class<LoanChargeDataV1> dataType) {
|
||||
return dataType.isAssignableFrom(LoanChargeDataV1.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enrich(LoanChargeDataV1 data) {
|
||||
externalAssetOwnerTransferRepository.findActiveOwnerByLoanId(data.getLoanId())
|
||||
.ifPresent(owner -> data.setExternalOwnerId(externalIdMapper.mapExternalId(owner.getExternalId())));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user