You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by "galovics (via GitHub)" <gi...@apache.org> on 2023/05/31 07:00:21 UTC

[GitHub] [fineract] galovics commented on a diff in pull request #3206: FINERACT-1926: Fineract Asset Externalization - events

galovics commented on code in PR #3206:
URL: https://github.com/apache/fineract/pull/3206#discussion_r1211166185


##########
fineract-investor/src/main/java/org/apache/fineract/investor/api/ExternalAssetOwnersApiResource.java:
##########
@@ -52,12 +52,14 @@
 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.stereotype.Component;
 
 @Path("/v1/external-asset-owners")
 @Component
 @Tag(name = "External Asset Owners", description = "External Asset Owners")
 @RequiredArgsConstructor
+@ConditionalOnProperty(value = "fineract.module.external-asset-owner.enabled", havingValue = "true")

Review Comment:
   Not necessary to change it now but I think this should be a tiny bit differently solved.
   
   For fineract-provider, have the existig configuration do a component scan only for the packages inside the provider module. 
   Have a configuration for the investor module which scans components for the investor module packages and tie the configuration to this property value. That way the whole investor module is switchable.



##########
fineract-investor/src/main/java/org/apache/fineract/investor/enricher/LoanAccountDataV1Enricher.java:
##########
@@ -0,0 +1,56 @@
+/**
+ * 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.avro.loan.v1.LoanChargeDataV1;
+import org.apache.fineract.infrastructure.core.domain.ExternalId;
+import org.apache.fineract.infrastructure.core.service.PartialDataEnricher;
+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 PartialDataEnricher<LoanAccountDataV1> {
+
+    private final ExternalAssetOwnerTransferRepository externalAssetOwnerTransferRepository;
+    private final ExternalIdMapper externalIdMapper;
+    private final AvroDateTimeMapper avroDateTimeMapper;
+
+    @Override
+    public boolean isDataTypeSupported(Class<?> dataType) {

Review Comment:
   Btw I think we should change the signature on the interface to enforce Class<T> instead of Class<?> here, that way we can prevent such errors.



##########
fineract-investor/src/main/java/org/apache/fineract/investor/enricher/LoanAccountDataV1Enricher.java:
##########
@@ -0,0 +1,56 @@
+/**
+ * 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.avro.loan.v1.LoanChargeDataV1;
+import org.apache.fineract.infrastructure.core.domain.ExternalId;
+import org.apache.fineract.infrastructure.core.service.PartialDataEnricher;
+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 PartialDataEnricher<LoanAccountDataV1> {
+
+    private final ExternalAssetOwnerTransferRepository externalAssetOwnerTransferRepository;
+    private final ExternalIdMapper externalIdMapper;
+    private final AvroDateTimeMapper avroDateTimeMapper;
+
+    @Override
+    public boolean isDataTypeSupported(Class<?> dataType) {
+        return dataType.isAssignableFrom(LoanChargeDataV1.class);
+    }
+
+    @Override
+    public void enrich(LoanAccountDataV1 data) {
+        externalAssetOwnerTransferRepository.findActiveByLoanId(data.getId()).ifPresent(transfer -> {

Review Comment:
   This would be much efficient if the data was fetched through a join instead of executing 2 queries (1 to get the transfer and then 1 to get the owner corresponding to the transfer)



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/mapper/loan/PartialEnricherSupport.java:
##########
@@ -0,0 +1,32 @@
+/**
+ * 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.mapper.loan;
+
+import org.apache.fineract.infrastructure.core.service.PartialDataEnricherProcessor;
+import org.mapstruct.AfterMapping;
+import org.mapstruct.Context;
+import org.mapstruct.MappingTarget;
+
+public interface PartialEnricherSupport {
+
+    @AfterMapping
+    default <T> void enrich(@MappingTarget final T target, @Context PartialDataEnricherProcessor processor) {

Review Comment:
   I'm not sure I'm a fan of wiring this into the mapstruct mapping cause the serializers don't enforce the usage of mapstruct.
   
   I think we should hook this up directly in the event serializers.



##########
fineract-investor/src/main/java/org/apache/fineract/investor/enricher/LoanDataChargeV1Enricher.java:
##########
@@ -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.PartialDataEnricher;
+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 LoanDataChargeV1Enricher implements PartialDataEnricher<LoanChargeDataV1> {

Review Comment:
   Inconsistent naming. Should be LoanChargeDataV1Enricher.



##########
fineract-investor/src/main/java/org/apache/fineract/investor/enricher/LoanAccountDataV1Enricher.java:
##########
@@ -0,0 +1,56 @@
+/**
+ * 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.avro.loan.v1.LoanChargeDataV1;
+import org.apache.fineract.infrastructure.core.domain.ExternalId;
+import org.apache.fineract.infrastructure.core.service.PartialDataEnricher;
+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 PartialDataEnricher<LoanAccountDataV1> {
+
+    private final ExternalAssetOwnerTransferRepository externalAssetOwnerTransferRepository;
+    private final ExternalIdMapper externalIdMapper;
+    private final AvroDateTimeMapper avroDateTimeMapper;
+
+    @Override
+    public boolean isDataTypeSupported(Class<?> dataType) {
+        return dataType.isAssignableFrom(LoanChargeDataV1.class);

Review Comment:
   Wrong data type supported.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org