FINERACT-1932: Add custom Configuration class for shareproduct services

This commit is contained in:
Mohamed Magdi-Abdelmonem
2023-10-30 10:58:05 +01:00
committed by Aleksandar Vidakovic
parent ecca18d0f7
commit 0b1ca2dced
7 changed files with 116 additions and 36 deletions
@@ -19,24 +19,18 @@
package org.apache.fineract.portfolio.shareproducts.service;
import com.google.gson.JsonElement;
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.serialization.FromJsonHelper;
import org.apache.fineract.portfolio.products.service.ProductCommandsService;
import org.apache.fineract.portfolio.shareproducts.constants.ShareProductApiConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service(value = "SHAREPRODUCT_COMMANDSERVICE")
@RequiredArgsConstructor
public class ShareProductCommandsServiceImpl implements ProductCommandsService {
private final FromJsonHelper fromApiJsonHelper;
@Autowired
public ShareProductCommandsServiceImpl(final FromJsonHelper fromApiJsonHelper) {
this.fromApiJsonHelper = fromApiJsonHelper;
}
public CommandProcessingResult postDividends(Long productId, JsonCommand jsonCommand) {
return null;
}
@@ -24,6 +24,7 @@ import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
import org.apache.fineract.organisation.monetary.domain.Money;
@@ -36,22 +37,13 @@ import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountReadPlatf
import org.apache.fineract.portfolio.shareproducts.data.ShareProductData;
import org.apache.fineract.portfolio.shareproducts.domain.ShareProductDividendPayOutDetails;
import org.apache.fineract.portfolio.shareproducts.exception.ShareAccountsNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class ShareProductDividendAssembler {
private final ShareProductReadPlatformService shareProductReadPlatformService;
private final ShareAccountReadPlatformService shareAccountReadPlatformService;
@Autowired
public ShareProductDividendAssembler(final ShareProductReadPlatformService shareProductReadPlatformService,
final ShareAccountReadPlatformService shareAccountReadPlatformService) {
this.shareProductReadPlatformService = shareProductReadPlatformService;
this.shareAccountReadPlatformService = shareAccountReadPlatformService;
}
public ShareProductDividendPayOutDetails calculateDividends(final Long productId, final BigDecimal amount,
final LocalDate dividendPeriodStartDate, final LocalDate dividendPeriodEndDate) {
@@ -25,6 +25,7 @@ import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.infrastructure.core.service.Page;
@@ -36,12 +37,10 @@ import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountDividendData
import org.apache.fineract.portfolio.shareaccounts.service.SharesEnumerations;
import org.apache.fineract.portfolio.shareproducts.data.ShareProductData;
import org.apache.fineract.portfolio.shareproducts.data.ShareProductDividendPayOutData;
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 ShareProductDividendReadPlatformServiceImpl implements ShareProductDividendReadPlatformService {
private final JdbcTemplate jdbcTemplate;
@@ -49,15 +48,6 @@ public class ShareProductDividendReadPlatformServiceImpl implements ShareProduct
private final PaginationHelper paginationHelper;
private final DatabaseSpecificSQLGenerator sqlGenerator;
@Autowired
public ShareProductDividendReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate, final ColumnValidator columnValidator,
DatabaseSpecificSQLGenerator sqlGenerator, PaginationHelper paginationHelper) {
this.jdbcTemplate = jdbcTemplate;
this.columnValidator = columnValidator;
this.paginationHelper = paginationHelper;
this.sqlGenerator = sqlGenerator;
}
@Override
public Page<ShareProductDividendPayOutData> retriveAll(final Long productId, final Integer status,
final SearchParameters searchParameters) {
@@ -21,12 +21,12 @@ package org.apache.fineract.portfolio.shareproducts.service;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import lombok.NoArgsConstructor;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.portfolio.shareaccounts.service.SharesEnumerations;
import org.apache.fineract.portfolio.shareproducts.SharePeriodFrequencyType;
import org.springframework.stereotype.Service;
@Service
@NoArgsConstructor
public class ShareProductDropdownReadPlatformServiceImpl implements ShareProductDropdownReadPlatformService {
@Override
@@ -52,9 +52,7 @@ import org.apache.fineract.portfolio.shareproducts.data.ShareProductMarketPriceD
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
@Service(value = "shareReadPlatformService")
@RequiredArgsConstructor
public class ShareProductReadPlatformServiceImpl implements ShareProductReadPlatformService {
@@ -43,9 +43,7 @@ import org.apache.fineract.portfolio.shareproducts.exception.DividentProcessingE
import org.apache.fineract.portfolio.shareproducts.serialization.ShareProductDataSerializer;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;
@Service
@Slf4j
@RequiredArgsConstructor
public class ShareProductWritePlatformServiceJpaRepositoryImpl implements ShareProductWritePlatformService {
@@ -0,0 +1,108 @@
/**
* 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.shareproducts.starter;
import org.apache.fineract.accounting.common.AccountingDropdownReadPlatformService;
import org.apache.fineract.accounting.producttoaccountmapping.service.ProductToGLAccountMappingReadPlatformService;
import org.apache.fineract.accounting.producttoaccountmapping.service.ProductToGLAccountMappingWritePlatformService;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.core.service.PaginationHelper;
import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
import org.apache.fineract.infrastructure.security.utils.ColumnValidator;
import org.apache.fineract.organisation.monetary.service.CurrencyReadPlatformService;
import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformService;
import org.apache.fineract.portfolio.products.service.ShareProductReadPlatformService;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountReadPlatformService;
import org.apache.fineract.portfolio.shareproducts.domain.ShareProductDividentPayOutDetailsRepositoryWrapper;
import org.apache.fineract.portfolio.shareproducts.domain.ShareProductRepositoryWrapper;
import org.apache.fineract.portfolio.shareproducts.serialization.ShareProductDataSerializer;
import org.apache.fineract.portfolio.shareproducts.service.ShareProductCommandsServiceImpl;
import org.apache.fineract.portfolio.shareproducts.service.ShareProductDividendAssembler;
import org.apache.fineract.portfolio.shareproducts.service.ShareProductDividendReadPlatformService;
import org.apache.fineract.portfolio.shareproducts.service.ShareProductDividendReadPlatformServiceImpl;
import org.apache.fineract.portfolio.shareproducts.service.ShareProductDropdownReadPlatformService;
import org.apache.fineract.portfolio.shareproducts.service.ShareProductDropdownReadPlatformServiceImpl;
import org.apache.fineract.portfolio.shareproducts.service.ShareProductReadPlatformServiceImpl;
import org.apache.fineract.portfolio.shareproducts.service.ShareProductWritePlatformService;
import org.apache.fineract.portfolio.shareproducts.service.ShareProductWritePlatformServiceJpaRepositoryImpl;
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 ShareProductsConfiguration {
@Bean(value = "SHAREPRODUCT_COMMANDSERVICE")
@ConditionalOnMissingBean(ShareProductCommandsServiceImpl.class)
public ShareProductCommandsServiceImpl shareProductCommandsService(FromJsonHelper fromApiJsonHelper) {
return new ShareProductCommandsServiceImpl(fromApiJsonHelper);
}
@Bean
@ConditionalOnMissingBean(ShareProductDividendAssembler.class)
public ShareProductDividendAssembler shareProductDividendAssembler(ShareProductReadPlatformService shareProductReadPlatformService,
ShareAccountReadPlatformService shareAccountReadPlatformService) {
return new ShareProductDividendAssembler(shareProductReadPlatformService, shareAccountReadPlatformService);
}
@Bean
@ConditionalOnMissingBean(ShareProductDividendReadPlatformService.class)
public ShareProductDividendReadPlatformService shareProductDividendReadPlatformService(JdbcTemplate jdbcTemplate,
ColumnValidator columnValidator, PaginationHelper paginationHelper, DatabaseSpecificSQLGenerator sqlGenerator) {
return new ShareProductDividendReadPlatformServiceImpl(jdbcTemplate, columnValidator, paginationHelper, sqlGenerator);
}
@Bean
@ConditionalOnMissingBean(ShareProductDropdownReadPlatformService.class)
public ShareProductDropdownReadPlatformService shareProductDropdownReadPlatformService() {
return new ShareProductDropdownReadPlatformServiceImpl();
}
@Bean(value = "shareReadPlatformService")
@ConditionalOnMissingBean(ShareProductReadPlatformService.class)
public ShareProductReadPlatformService shareProductReadPlatformService(JdbcTemplate jdbcTemplate,
CurrencyReadPlatformService currencyReadPlatformService, ChargeReadPlatformService chargeReadPlatformService,
ShareProductDropdownReadPlatformService shareProductDropdownReadPlatformService,
AccountingDropdownReadPlatformService accountingDropdownReadPlatformService,
ProductToGLAccountMappingReadPlatformService accountMappingReadPlatformService,
PaginationHelper shareProductDataPaginationHelper, DatabaseSpecificSQLGenerator sqlGenerator) {
return new ShareProductReadPlatformServiceImpl(jdbcTemplate, currencyReadPlatformService, chargeReadPlatformService,
shareProductDropdownReadPlatformService, accountingDropdownReadPlatformService, accountMappingReadPlatformService,
shareProductDataPaginationHelper, sqlGenerator);
}
@Bean
@ConditionalOnMissingBean(ShareProductWritePlatformService.class)
public ShareProductWritePlatformService shareProductWritePlatformService(ShareProductRepositoryWrapper repository,
ShareProductDataSerializer serializer, FromJsonHelper fromApiJsonHelper,
ShareProductDividentPayOutDetailsRepositoryWrapper shareProductDividentPayOutDetailsRepository,
ShareProductDividendAssembler shareProductDividendAssembler,
ProductToGLAccountMappingWritePlatformService accountMappingWritePlatformService,
BusinessEventNotifierService businessEventNotifierService) {
return new ShareProductWritePlatformServiceJpaRepositoryImpl(repository, serializer, fromApiJsonHelper,
shareProductDividentPayOutDetailsRepository, shareProductDividendAssembler, accountMappingWritePlatformService,
businessEventNotifierService);
}
}