From c5932ec7a5404c5cc1e66096cd0fbecd32570443 Mon Sep 17 00:00:00 2001 From: Mohamed Magdi-Abdelmonem Date: Sat, 14 Oct 2023 18:59:28 +0300 Subject: [PATCH] FINERACT-1932: Add starter Configuration class for portfolio.fund module --- .../service/FundReadPlatformServiceImpl.java | 11 +---- ...WritePlatformServiceJpaRepositoryImpl.java | 21 ++------ .../fund/starter/FundConfiguration.java | 48 +++++++++++++++++++ 3 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/starter/FundConfiguration.java diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/service/FundReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/service/FundReadPlatformServiceImpl.java index 3d50ea52a..e99c6e49f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/service/FundReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/service/FundReadPlatformServiceImpl.java @@ -21,28 +21,21 @@ package org.apache.fineract.portfolio.fund.service; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; +import lombok.RequiredArgsConstructor; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.portfolio.fund.data.FundData; import org.apache.fineract.portfolio.fund.exception.FundNotFoundException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Service; -@Service +@RequiredArgsConstructor public class FundReadPlatformServiceImpl implements FundReadPlatformService { private final JdbcTemplate jdbcTemplate; private final PlatformSecurityContext context; - @Autowired - public FundReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate) { - this.context = context; - this.jdbcTemplate = jdbcTemplate; - } - private static final class FundMapper implements RowMapper { public String schema() { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/service/FundWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/service/FundWritePlatformServiceJpaRepositoryImpl.java index 20bab2f4c..8750d70aa 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/service/FundWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/service/FundWritePlatformServiceJpaRepositoryImpl.java @@ -20,6 +20,8 @@ package org.apache.fineract.portfolio.fund.service; import jakarta.persistence.PersistenceException; import java.util.Map; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; @@ -30,32 +32,19 @@ import org.apache.fineract.portfolio.fund.domain.Fund; import org.apache.fineract.portfolio.fund.domain.FundRepository; import org.apache.fineract.portfolio.fund.exception.FundNotFoundException; import org.apache.fineract.portfolio.fund.serialization.FundCommandFromApiJsonDeserializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.orm.jpa.JpaSystemException; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service +@Slf4j +@RequiredArgsConstructor public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatformService { - private static final Logger LOG = LoggerFactory.getLogger(FundWritePlatformServiceJpaRepositoryImpl.class); - private final PlatformSecurityContext context; private final FundCommandFromApiJsonDeserializer fromApiJsonDeserializer; private final FundRepository fundRepository; - @Autowired - public FundWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, - final FundCommandFromApiJsonDeserializer fromApiJsonDeserializer, final FundRepository fundRepository) { - this.context = context; - this.fromApiJsonDeserializer = fromApiJsonDeserializer; - this.fundRepository = fundRepository; - } - @Transactional @Override @CacheEvict(value = "funds", key = "T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('fn')") @@ -123,7 +112,7 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf "name", name); } - LOG.error("Error occured.", dve); + log.error("Error occured.", dve); throw new PlatformDataIntegrityException("error.msg.fund.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + realCause.getMessage()); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/starter/FundConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/starter/FundConfiguration.java new file mode 100644 index 000000000..dfc9dae3a --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/starter/FundConfiguration.java @@ -0,0 +1,48 @@ +/** + * 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.portfolio.fund.starter; + +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.apache.fineract.portfolio.fund.domain.FundRepository; +import org.apache.fineract.portfolio.fund.serialization.FundCommandFromApiJsonDeserializer; +import org.apache.fineract.portfolio.fund.service.FundReadPlatformService; +import org.apache.fineract.portfolio.fund.service.FundReadPlatformServiceImpl; +import org.apache.fineract.portfolio.fund.service.FundWritePlatformService; +import org.apache.fineract.portfolio.fund.service.FundWritePlatformServiceJpaRepositoryImpl; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.core.JdbcTemplate; + +@Configuration +public class FundConfiguration { + + @Bean + @ConditionalOnMissingBean(FundReadPlatformService.class) + public FundReadPlatformService fundReadPlatformService(JdbcTemplate jdbcTemplate, PlatformSecurityContext context) { + return new FundReadPlatformServiceImpl(jdbcTemplate, context); + } + + @Bean + @ConditionalOnMissingBean(FundWritePlatformService.class) + public FundWritePlatformService fundWritePlatformService(PlatformSecurityContext context, + FundCommandFromApiJsonDeserializer fromApiJsonDeserializer, FundRepository fundRepository) { + return new FundWritePlatformServiceJpaRepositoryImpl(context, fromApiJsonDeserializer, fundRepository); + } +}