From 367896ccf24d1bf94257edecfd62fcbafb33cc99 Mon Sep 17 00:00:00 2001 From: "Sinha, Abhinav" Date: Fri, 25 Aug 2023 10:53:12 -0400 Subject: [PATCH] Add custom Configuration class for charge module (FINERACT-1932) --- ...ChargeDropdownReadPlatformServiceImpl.java | 2 - .../ChargeReadPlatformServiceImpl.java | 27 +------ ...WritePlatformServiceJpaRepositoryImpl.java | 31 ++------ .../charge/starter/ChargeConfiguration.java | 77 +++++++++++++++++++ 4 files changed, 87 insertions(+), 50 deletions(-) create mode 100644 fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/starter/ChargeConfiguration.java diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeDropdownReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeDropdownReadPlatformServiceImpl.java index d694fb68b..f7706093c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeDropdownReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeDropdownReadPlatformServiceImpl.java @@ -30,9 +30,7 @@ import org.apache.fineract.portfolio.charge.domain.ChargeAppliesTo; import org.apache.fineract.portfolio.charge.domain.ChargeCalculationType; import org.apache.fineract.portfolio.charge.domain.ChargePaymentMode; import org.apache.fineract.portfolio.charge.domain.ChargeTimeType; -import org.springframework.stereotype.Service; -@Service public class ChargeDropdownReadPlatformServiceImpl implements ChargeDropdownReadPlatformService { @Override diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeReadPlatformServiceImpl.java index 1aa993e91..ca0e7df46 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeReadPlatformServiceImpl.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import lombok.RequiredArgsConstructor; import org.apache.fineract.accounting.common.AccountingDropdownReadPlatformService; import org.apache.fineract.accounting.glaccount.data.GLAccountData; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainServiceJpa; @@ -45,48 +46,28 @@ import org.apache.fineract.portfolio.common.service.DropdownReadPlatformService; import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData; import org.apache.fineract.portfolio.tax.data.TaxGroupData; import org.apache.fineract.portfolio.tax.service.TaxReadPlatformService; -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.jdbc.core.namedparam.NamedParameterJdbcTemplate; -import org.springframework.stereotype.Service; /** * @author vishwas * */ -@Service +@RequiredArgsConstructor public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService { - private final JdbcTemplate jdbcTemplate; private final CurrencyReadPlatformService currencyReadPlatformService; private final ChargeDropdownReadPlatformService chargeDropdownReadPlatformService; + private final JdbcTemplate jdbcTemplate; private final DropdownReadPlatformService dropdownReadPlatformService; private final FineractEntityAccessUtil fineractEntityAccessUtil; private final AccountingDropdownReadPlatformService accountingDropdownReadPlatformService; - private final NamedParameterJdbcTemplate namedParameterJdbcTemplate; private final TaxReadPlatformService taxReadPlatformService; private final ConfigurationDomainServiceJpa configurationDomainServiceJpa; - - @Autowired - public ChargeReadPlatformServiceImpl(final CurrencyReadPlatformService currencyReadPlatformService, - final ChargeDropdownReadPlatformService chargeDropdownReadPlatformService, final JdbcTemplate jdbcTemplate, - final DropdownReadPlatformService dropdownReadPlatformService, final FineractEntityAccessUtil fineractEntityAccessUtil, - final AccountingDropdownReadPlatformService accountingDropdownReadPlatformService, - final TaxReadPlatformService taxReadPlatformService, final ConfigurationDomainServiceJpa configurationDomainServiceJpa, - final NamedParameterJdbcTemplate namedParameterJdbcTemplate) { - this.chargeDropdownReadPlatformService = chargeDropdownReadPlatformService; - this.jdbcTemplate = jdbcTemplate; - this.currencyReadPlatformService = currencyReadPlatformService; - this.dropdownReadPlatformService = dropdownReadPlatformService; - this.fineractEntityAccessUtil = fineractEntityAccessUtil; - this.accountingDropdownReadPlatformService = accountingDropdownReadPlatformService; - this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; - this.taxReadPlatformService = taxReadPlatformService; - this.configurationDomainServiceJpa = configurationDomainServiceJpa; - } + private final NamedParameterJdbcTemplate namedParameterJdbcTemplate; @Override @Cacheable(value = "charges", key = "T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('ch')") diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeWritePlatformServiceJpaRepositoryImpl.java index fd648c4b4..19170d6d8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeWritePlatformServiceJpaRepositoryImpl.java @@ -21,6 +21,8 @@ package org.apache.fineract.portfolio.charge.service; import jakarta.persistence.PersistenceException; import java.util.Collection; import java.util.Map; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.fineract.accounting.glaccount.domain.GLAccount; import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper; @@ -45,47 +47,26 @@ import org.apache.fineract.portfolio.paymenttype.domain.PaymentType; import org.apache.fineract.portfolio.paymenttype.domain.PaymentTypeRepositoryWrapper; import org.apache.fineract.portfolio.tax.domain.TaxGroup; import org.apache.fineract.portfolio.tax.domain.TaxGroupRepositoryWrapper; -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.jdbc.core.JdbcTemplate; import org.springframework.orm.jpa.JpaSystemException; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service +@Slf4j +@RequiredArgsConstructor public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWritePlatformService { - private static final Logger LOG = LoggerFactory.getLogger(ChargeWritePlatformServiceJpaRepositoryImpl.class); private final PlatformSecurityContext context; private final ChargeDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer; - private final JdbcTemplate jdbcTemplate; private final ChargeRepository chargeRepository; private final LoanProductRepository loanProductRepository; + private final JdbcTemplate jdbcTemplate; private final FineractEntityAccessUtil fineractEntityAccessUtil; private final GLAccountRepositoryWrapper glAccountRepository; private final TaxGroupRepositoryWrapper taxGroupRepository; private final PaymentTypeRepositoryWrapper paymentTyperepositoryWrapper; - @Autowired - public ChargeWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, - final ChargeDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer, final ChargeRepository chargeRepository, - final LoanProductRepository loanProductRepository, final JdbcTemplate jdbcTemplate, - final FineractEntityAccessUtil fineractEntityAccessUtil, final GLAccountRepositoryWrapper glAccountRepository, - final TaxGroupRepositoryWrapper taxGroupRepository, final PaymentTypeRepositoryWrapper paymentTyperepositoryWrapper) { - this.context = context; - this.fromApiJsonDeserializer = fromApiJsonDeserializer; - this.jdbcTemplate = jdbcTemplate; - this.chargeRepository = chargeRepository; - this.loanProductRepository = loanProductRepository; - this.fineractEntityAccessUtil = fineractEntityAccessUtil; - this.glAccountRepository = glAccountRepository; - this.taxGroupRepository = taxGroupRepository; - this.paymentTyperepositoryWrapper = paymentTyperepositoryWrapper; - } - @Transactional @Override @CacheEvict(value = "charges", key = "T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('ch')") @@ -263,7 +244,7 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP "name", name); } - LOG.error("Error occured.", dve); + log.error("Error occured.", dve); throw new PlatformDataIntegrityException("error.msg.charge.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + realCause.getMessage()); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/starter/ChargeConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/starter/ChargeConfiguration.java new file mode 100644 index 000000000..ca1185f2c --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/starter/ChargeConfiguration.java @@ -0,0 +1,77 @@ +/** + * 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.charge.starter; + +import org.apache.fineract.accounting.common.AccountingDropdownReadPlatformService; +import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper; +import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainServiceJpa; +import org.apache.fineract.infrastructure.entityaccess.service.FineractEntityAccessUtil; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.apache.fineract.organisation.monetary.service.CurrencyReadPlatformService; +import org.apache.fineract.portfolio.charge.domain.ChargeRepository; +import org.apache.fineract.portfolio.charge.serialization.ChargeDefinitionCommandFromApiJsonDeserializer; +import org.apache.fineract.portfolio.charge.service.ChargeDropdownReadPlatformService; +import org.apache.fineract.portfolio.charge.service.ChargeDropdownReadPlatformServiceImpl; +import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformService; +import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformServiceImpl; +import org.apache.fineract.portfolio.charge.service.ChargeWritePlatformService; +import org.apache.fineract.portfolio.charge.service.ChargeWritePlatformServiceJpaRepositoryImpl; +import org.apache.fineract.portfolio.common.service.DropdownReadPlatformService; +import org.apache.fineract.portfolio.loanproduct.domain.LoanProductRepository; +import org.apache.fineract.portfolio.paymenttype.domain.PaymentTypeRepositoryWrapper; +import org.apache.fineract.portfolio.tax.domain.TaxGroupRepositoryWrapper; +import org.apache.fineract.portfolio.tax.service.TaxReadPlatformService; +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; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; + +@Configuration +public class ChargeConfiguration { + + @Bean + @ConditionalOnMissingBean(ChargeDropdownReadPlatformService.class) + public ChargeDropdownReadPlatformService chargeDropdownReadPlatformService() { + return new ChargeDropdownReadPlatformServiceImpl(); + } + + @Bean + @ConditionalOnMissingBean(ChargeReadPlatformService.class) + public ChargeReadPlatformService chargeReadPlatformService(CurrencyReadPlatformService currencyReadPlatformService, + ChargeDropdownReadPlatformService chargeDropdownReadPlatformService, JdbcTemplate jdbcTemplate, + DropdownReadPlatformService dropdownReadPlatformService, FineractEntityAccessUtil fineractEntityAccessUtil, + AccountingDropdownReadPlatformService accountingDropdownReadPlatformService, TaxReadPlatformService taxReadPlatformService, + ConfigurationDomainServiceJpa configurationDomainServiceJpa, NamedParameterJdbcTemplate namedParameterJdbcTemplate) { + return new ChargeReadPlatformServiceImpl(currencyReadPlatformService, chargeDropdownReadPlatformService, jdbcTemplate, + dropdownReadPlatformService, fineractEntityAccessUtil, accountingDropdownReadPlatformService, taxReadPlatformService, + configurationDomainServiceJpa, namedParameterJdbcTemplate); + } + + @Bean + @ConditionalOnMissingBean(ChargeWritePlatformService.class) + public ChargeWritePlatformService chargeWritePlatformService(PlatformSecurityContext context, + ChargeDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer, ChargeRepository chargeRepository, + LoanProductRepository loanProductRepository, JdbcTemplate jdbcTemplate, FineractEntityAccessUtil fineractEntityAccessUtil, + GLAccountRepositoryWrapper glAccountRepository, TaxGroupRepositoryWrapper taxGroupRepository, + PaymentTypeRepositoryWrapper paymentTyperepositoryWrapper) { + return new ChargeWritePlatformServiceJpaRepositoryImpl(context, fromApiJsonDeserializer, chargeRepository, loanProductRepository, + jdbcTemplate, fineractEntityAccessUtil, glAccountRepository, taxGroupRepository, paymentTyperepositoryWrapper); + } +}