From 34fc1a2cc59016fbade85db58f3f7925ff678ad5 Mon Sep 17 00:00:00 2001 From: Mohamed Magdy <14momagdi@gmail.com> Date: Sat, 12 Aug 2023 12:17:38 +0300 Subject: [PATCH] Add custom AutoConfiguration class for tax service (FINERACT-1932) --- .../portfolio/tax/service/TaxAssembler.java | 13 +--- .../service/TaxReadPlatformServiceImpl.java | 12 +--- .../service/TaxWritePlatformServiceImpl.java | 17 +---- .../tax/starter/TaxConfiguration.java | 64 +++++++++++++++++++ 4 files changed, 70 insertions(+), 36 deletions(-) create mode 100644 fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/starter/TaxConfiguration.java diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxAssembler.java index 7e226838e..ac1c1e5d7 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxAssembler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxAssembler.java @@ -28,6 +28,7 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; +import lombok.RequiredArgsConstructor; import org.apache.fineract.accounting.glaccount.domain.GLAccount; import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper; import org.apache.fineract.accounting.glaccount.domain.GLAccountType; @@ -42,24 +43,14 @@ import org.apache.fineract.portfolio.tax.domain.TaxComponent; import org.apache.fineract.portfolio.tax.domain.TaxComponentRepositoryWrapper; import org.apache.fineract.portfolio.tax.domain.TaxGroup; import org.apache.fineract.portfolio.tax.domain.TaxGroupMappings; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -@Component +@RequiredArgsConstructor public class TaxAssembler { private final FromJsonHelper fromApiJsonHelper; private final GLAccountRepositoryWrapper glAccountRepositoryWrapper; private final TaxComponentRepositoryWrapper taxComponentRepositoryWrapper; - @Autowired - public TaxAssembler(final FromJsonHelper fromApiJsonHelper, final GLAccountRepositoryWrapper glAccountRepositoryWrapper, - final TaxComponentRepositoryWrapper taxComponentRepositoryWrapper) { - this.fromApiJsonHelper = fromApiJsonHelper; - this.glAccountRepositoryWrapper = glAccountRepositoryWrapper; - this.taxComponentRepositoryWrapper = taxComponentRepositoryWrapper; - } - public TaxComponent assembleTaxComponentFrom(final JsonCommand command) { final JsonElement element = command.parsedJson(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxReadPlatformServiceImpl.java index 721d18663..67bedc00a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxReadPlatformServiceImpl.java @@ -24,6 +24,7 @@ import java.sql.SQLException; import java.time.LocalDate; import java.util.ArrayList; import java.util.Collection; +import lombok.RequiredArgsConstructor; import org.apache.fineract.accounting.common.AccountingDropdownReadPlatformService; import org.apache.fineract.accounting.common.AccountingEnumerations; import org.apache.fineract.accounting.glaccount.data.GLAccountData; @@ -33,12 +34,10 @@ import org.apache.fineract.portfolio.tax.data.TaxComponentData; import org.apache.fineract.portfolio.tax.data.TaxComponentHistoryData; import org.apache.fineract.portfolio.tax.data.TaxGroupData; import org.apache.fineract.portfolio.tax.data.TaxGroupMappingsData; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Service; -@Service +@RequiredArgsConstructor public class TaxReadPlatformServiceImpl implements TaxReadPlatformService { private static final TaxComponentMapper TAX_COMPONENT_MAPPER = new TaxComponentMapper(); @@ -49,13 +48,6 @@ public class TaxReadPlatformServiceImpl implements TaxReadPlatformService { private final JdbcTemplate jdbcTemplate; private final AccountingDropdownReadPlatformService accountingDropdownReadPlatformService; - @Autowired - public TaxReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate, - final AccountingDropdownReadPlatformService accountingDropdownReadPlatformService) { - this.jdbcTemplate = jdbcTemplate; - this.accountingDropdownReadPlatformService = accountingDropdownReadPlatformService; - } - @Override public Collection retrieveAllTaxComponents() { String sql = "select " + TAX_COMPONENT_MAPPER.getSchema(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxWritePlatformServiceImpl.java index 6ccdcf5a1..633f869fb 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/service/TaxWritePlatformServiceImpl.java @@ -20,6 +20,7 @@ package org.apache.fineract.portfolio.tax.service; import java.util.Map; import java.util.Set; +import lombok.RequiredArgsConstructor; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; @@ -31,10 +32,8 @@ import org.apache.fineract.portfolio.tax.domain.TaxGroupMappings; import org.apache.fineract.portfolio.tax.domain.TaxGroupRepository; import org.apache.fineract.portfolio.tax.domain.TaxGroupRepositoryWrapper; import org.apache.fineract.portfolio.tax.serialization.TaxValidator; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -@Service +@RequiredArgsConstructor public class TaxWritePlatformServiceImpl implements TaxWritePlatformService { private final TaxValidator validator; @@ -44,18 +43,6 @@ public class TaxWritePlatformServiceImpl implements TaxWritePlatformService { private final TaxGroupRepository taxGroupRepository; private final TaxGroupRepositoryWrapper taxGroupRepositoryWrapper; - @Autowired - public TaxWritePlatformServiceImpl(final TaxValidator validator, final TaxAssembler taxAssembler, - final TaxComponentRepository taxComponentRepository, final TaxGroupRepository taxGroupRepository, - final TaxComponentRepositoryWrapper taxComponentRepositoryWrapper, final TaxGroupRepositoryWrapper taxGroupRepositoryWrapper) { - this.validator = validator; - this.taxAssembler = taxAssembler; - this.taxComponentRepository = taxComponentRepository; - this.taxGroupRepository = taxGroupRepository; - this.taxComponentRepositoryWrapper = taxComponentRepositoryWrapper; - this.taxGroupRepositoryWrapper = taxGroupRepositoryWrapper; - } - @Override public CommandProcessingResult createTaxComponent(final JsonCommand command) { this.validator.validateForTaxComponentCreate(command.json()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/starter/TaxConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/starter/TaxConfiguration.java new file mode 100644 index 000000000..4c1effb1e --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/tax/starter/TaxConfiguration.java @@ -0,0 +1,64 @@ +/** + * 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.tax.starter; + +import org.apache.fineract.accounting.common.AccountingDropdownReadPlatformService; +import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper; +import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; +import org.apache.fineract.portfolio.tax.domain.TaxComponentRepository; +import org.apache.fineract.portfolio.tax.domain.TaxComponentRepositoryWrapper; +import org.apache.fineract.portfolio.tax.domain.TaxGroupRepository; +import org.apache.fineract.portfolio.tax.domain.TaxGroupRepositoryWrapper; +import org.apache.fineract.portfolio.tax.serialization.TaxValidator; +import org.apache.fineract.portfolio.tax.service.TaxAssembler; +import org.apache.fineract.portfolio.tax.service.TaxReadPlatformService; +import org.apache.fineract.portfolio.tax.service.TaxReadPlatformServiceImpl; +import org.apache.fineract.portfolio.tax.service.TaxWritePlatformService; +import org.apache.fineract.portfolio.tax.service.TaxWritePlatformServiceImpl; +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 TaxConfiguration { + + @Bean + @ConditionalOnMissingBean(TaxAssembler.class) + public TaxAssembler taxAssembler(FromJsonHelper fromApiJsonHelper, GLAccountRepositoryWrapper glAccountRepositoryWrapper, + TaxComponentRepositoryWrapper taxComponentRepositoryWrapper) { + return new TaxAssembler(fromApiJsonHelper, glAccountRepositoryWrapper, taxComponentRepositoryWrapper); + } + + @Bean + @ConditionalOnMissingBean(TaxReadPlatformService.class) + public TaxReadPlatformService taxReadPlatformService(JdbcTemplate jdbcTemplate, + AccountingDropdownReadPlatformService accountingDropdownReadPlatformService) { + return new TaxReadPlatformServiceImpl(jdbcTemplate, accountingDropdownReadPlatformService); + } + + @Bean + @ConditionalOnMissingBean(TaxWritePlatformService.class) + public TaxWritePlatformService taxWritePlatformService(TaxValidator validator, TaxAssembler taxAssembler, + TaxComponentRepository taxComponentRepository, TaxGroupRepository taxGroupRepository, + TaxComponentRepositoryWrapper taxComponentRepositoryWrapper, TaxGroupRepositoryWrapper taxGroupRepositoryWrapper) { + return new TaxWritePlatformServiceImpl(validator, taxAssembler, taxComponentRepository, taxComponentRepositoryWrapper, + taxGroupRepository, taxGroupRepositoryWrapper); + } +}