FINERACT-1932: Add custom Configuration class for shareaccounts services

This commit is contained in:
Mohamed Magdi-Abdelmonem
2023-10-27 17:32:28 +02:00
committed by Aleksandar Vidakovic
parent 311eb875b3
commit f11808eba7
8 changed files with 137 additions and 93 deletions
@@ -23,24 +23,18 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.Collection;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountTransactionData;
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 PurchasedSharesReadPlatformServiceImpl implements PurchasedSharesReadPlatformService {
private final JdbcTemplate jdbcTemplate;
@Autowired
public PurchasedSharesReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public Collection<ShareAccountTransactionData> retrievePurchasedShares(Long accountId) {
PurchasedSharesDataRowMapper mapper = new PurchasedSharesDataRowMapper();
@@ -22,27 +22,21 @@ import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.portfolio.charge.data.ChargeData;
import org.apache.fineract.portfolio.charge.service.ChargeEnumerations;
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountChargeData;
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 ShareAccountChargeReadPlatformServiceImpl implements ShareAccountChargeReadPlatformService {
private final JdbcTemplate jdbcTemplate;
@Autowired
public ShareAccountChargeReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public Collection<ShareAccountChargeData> retrieveAccountCharges(Long accountId, String status) {
final ShareAccountChargeMapper rm = new ShareAccountChargeMapper();
@@ -19,29 +19,21 @@
package org.apache.fineract.portfolio.shareaccounts.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.accounts.constants.ShareAccountApiConstants;
import org.apache.fineract.portfolio.accounts.service.AccountsCommandsService;
import org.apache.fineract.portfolio.shareaccounts.serialization.ShareAccountDataSerializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service(value = "SHAREACCOUNT_COMMANDSERVICE")
@RequiredArgsConstructor
public class ShareAccountCommandsServiceImpl implements AccountsCommandsService {
private final FromJsonHelper fromApiJsonHelper;
private final ShareAccountDataSerializer shareAccountDataSerializer;
@Autowired
public ShareAccountCommandsServiceImpl(final FromJsonHelper fromApiJsonHelper,
final ShareAccountDataSerializer shareAccountDataSerializer) {
this.fromApiJsonHelper = fromApiJsonHelper;
this.shareAccountDataSerializer = shareAccountDataSerializer;
}
@Override
public Object handleCommand(Long accountId, String command, String jsonBody) {
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(jsonBody);
@@ -24,6 +24,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
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;
@@ -35,12 +36,10 @@ import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountData;
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountDividendData;
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountDividendStatusType;
import org.apache.fineract.portfolio.shareproducts.domain.ShareProductDividendStatusType;
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 ShareAccountDividendReadPlatformServiceImpl implements ShareAccountDividendReadPlatformService {
private final JdbcTemplate jdbcTemplate;
@@ -48,15 +47,6 @@ public class ShareAccountDividendReadPlatformServiceImpl implements ShareAccount
private final PaginationHelper paginationHelper;
private final DatabaseSpecificSQLGenerator sqlGenerator;
@Autowired
public ShareAccountDividendReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate, final ColumnValidator columnValidator,
DatabaseSpecificSQLGenerator sqlGenerator, PaginationHelper paginationHelper) {
this.jdbcTemplate = jdbcTemplate;
this.columnValidator = columnValidator;
this.paginationHelper = paginationHelper;
this.sqlGenerator = sqlGenerator;
}
@Override
public List<Map<String, Object>> retriveDividendDetailsForPostDividents() {
StringBuilder sb = new StringBuilder();
@@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
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.DateUtils;
@@ -36,7 +37,6 @@ import org.apache.fineract.infrastructure.core.service.PaginationHelper;
import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.portfolio.accountdetails.data.ShareAccountSummaryData;
import org.apache.fineract.portfolio.accounts.constants.AccountsApiConstants;
import org.apache.fineract.portfolio.accounts.constants.ShareAccountApiConstants;
import org.apache.fineract.portfolio.accounts.data.AccountData;
import org.apache.fineract.portfolio.accounts.exceptions.ShareAccountNotFoundException;
@@ -62,14 +62,12 @@ import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountStatusType
import org.apache.fineract.portfolio.shareproducts.data.ShareProductData;
import org.apache.fineract.portfolio.shareproducts.data.ShareProductMarketPriceData;
import org.apache.fineract.portfolio.shareproducts.service.ShareProductDropdownReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
@Service(value = "share" + AccountsApiConstants.READPLATFORM_NAME)
@RequiredArgsConstructor
public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlatformService {
private final ApplicationContext applicationContext;
@@ -84,27 +82,6 @@ public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlat
private final PaginationHelper shareAccountDataPaginationHelper;
private final DatabaseSpecificSQLGenerator sqlGenerator;
@Autowired
public ShareAccountReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate, final ApplicationContext applicationContext,
final ChargeReadPlatformService chargeReadPlatformService,
final ShareProductDropdownReadPlatformService shareProductDropdownReadPlatformService,
final SavingsAccountReadPlatformService savingsAccountReadPlatformService,
final ClientReadPlatformService clientReadPlatformService,
final ShareAccountChargeReadPlatformService shareAccountChargeReadPlatformService,
final PurchasedSharesReadPlatformService purchasedSharesReadPlatformService, DatabaseSpecificSQLGenerator sqlGenerator,
PaginationHelper paginationHelper) {
this.jdbcTemplate = jdbcTemplate;
this.applicationContext = applicationContext;
this.chargeReadPlatformService = chargeReadPlatformService;
this.shareProductDropdownReadPlatformService = shareProductDropdownReadPlatformService;
this.savingsAccountReadPlatformService = savingsAccountReadPlatformService;
this.clientReadPlatformService = clientReadPlatformService;
this.shareAccountChargeReadPlatformService = shareAccountChargeReadPlatformService;
this.purchasedSharesReadPlatformService = purchasedSharesReadPlatformService;
this.shareAccountDataPaginationHelper = paginationHelper;
this.sqlGenerator = sqlGenerator;
}
@Override
public ShareAccountData retrieveTemplate(Long clientId, Long productId) {
ShareAccountData toReturn = null;
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.portfolio.shareaccounts.service;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
import org.apache.fineract.portfolio.savings.domain.SavingsAccountAssembler;
@@ -26,25 +27,15 @@ import org.apache.fineract.portfolio.savings.domain.SavingsAccountTransaction;
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountDividendDetails;
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountDividendRepository;
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountDividendStatusType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
public class ShareAccountSchedularServiceImpl implements ShareAccountSchedularService {
private final ShareAccountDividendRepository shareAccountDividendRepository;
private final SavingsAccountDomainService savingsAccountDomainService;
private final SavingsAccountAssembler savingsAccountAssembler;
@Autowired
public ShareAccountSchedularServiceImpl(final ShareAccountDividendRepository shareAccountDividendRepository,
final SavingsAccountDomainService savingsAccountDomainService, final SavingsAccountAssembler savingsAccountAssembler) {
this.shareAccountDividendRepository = shareAccountDividendRepository;
this.savingsAccountDomainService = savingsAccountDomainService;
this.savingsAccountAssembler = savingsAccountAssembler;
}
@Override
@Transactional
public void postDividend(final Long dividendDetailId, final Long savingsId) {
@@ -27,6 +27,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService;
@@ -53,12 +54,10 @@ import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountTransactio
import org.apache.fineract.portfolio.shareaccounts.serialization.ShareAccountDataSerializer;
import org.apache.fineract.portfolio.shareproducts.domain.ShareProduct;
import org.apache.fineract.portfolio.shareproducts.domain.ShareProductRepositoryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareAccountWritePlatformService {
private final ShareAccountDataSerializer accountDataSerializer;
@@ -77,22 +76,6 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA
private final BusinessEventNotifierService businessEventNotifierService;
@Autowired
public ShareAccountWritePlatformServiceJpaRepositoryImpl(final ShareAccountDataSerializer accountDataSerializer,
final ShareAccountRepositoryWrapper shareAccountRepository, final ShareProductRepositoryWrapper shareProductRepository,
final AccountNumberGenerator accountNumberGenerator, final AccountNumberFormatRepositoryWrapper accountNumberFormatRepository,
final JournalEntryWritePlatformService journalEntryWritePlatformService, final NoteRepository noteRepository,
final BusinessEventNotifierService businessEventNotifierService) {
this.accountDataSerializer = accountDataSerializer;
this.shareAccountRepository = shareAccountRepository;
this.shareProductRepository = shareProductRepository;
this.accountNumberGenerator = accountNumberGenerator;
this.accountNumberFormatRepository = accountNumberFormatRepository;
this.journalEntryWritePlatformService = journalEntryWritePlatformService;
this.noteRepository = noteRepository;
this.businessEventNotifierService = businessEventNotifierService;
}
@Override
public CommandProcessingResult createShareAccount(JsonCommand jsonCommand) {
try {
@@ -0,0 +1,123 @@
/**
* 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.shareaccounts.start;
import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService;
import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatRepositoryWrapper;
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.portfolio.accounts.constants.AccountsApiConstants;
import org.apache.fineract.portfolio.accounts.service.AccountsCommandsService;
import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformService;
import org.apache.fineract.portfolio.client.domain.AccountNumberGenerator;
import org.apache.fineract.portfolio.client.service.ClientReadPlatformService;
import org.apache.fineract.portfolio.note.domain.NoteRepository;
import org.apache.fineract.portfolio.savings.domain.SavingsAccountAssembler;
import org.apache.fineract.portfolio.savings.domain.SavingsAccountDomainService;
import org.apache.fineract.portfolio.savings.service.SavingsAccountReadPlatformService;
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountDividendRepository;
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountRepositoryWrapper;
import org.apache.fineract.portfolio.shareaccounts.serialization.ShareAccountDataSerializer;
import org.apache.fineract.portfolio.shareaccounts.service.PurchasedSharesReadPlatformService;
import org.apache.fineract.portfolio.shareaccounts.service.PurchasedSharesReadPlatformServiceImpl;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountChargeReadPlatformService;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountChargeReadPlatformServiceImpl;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountCommandsServiceImpl;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountDividendReadPlatformService;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountDividendReadPlatformServiceImpl;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountReadPlatformService;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountReadPlatformServiceImpl;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountSchedularService;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountSchedularServiceImpl;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountWritePlatformService;
import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountWritePlatformServiceJpaRepositoryImpl;
import org.apache.fineract.portfolio.shareproducts.domain.ShareProductRepositoryWrapper;
import org.apache.fineract.portfolio.shareproducts.service.ShareProductDropdownReadPlatformService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
@Configuration
public class ShareAccountsConfiguration {
@Bean
@ConditionalOnMissingBean(PurchasedSharesReadPlatformService.class)
public PurchasedSharesReadPlatformService purchasedSharesReadPlatformService(JdbcTemplate jdbcTemplate) {
return new PurchasedSharesReadPlatformServiceImpl(jdbcTemplate);
}
@Bean
@ConditionalOnMissingBean(ShareAccountChargeReadPlatformService.class)
public ShareAccountChargeReadPlatformService shareAccountChargeReadPlatformService(JdbcTemplate jdbcTemplate) {
return new ShareAccountChargeReadPlatformServiceImpl(jdbcTemplate);
}
@Bean(value = "SHAREACCOUNT_COMMANDSERVICE")
@ConditionalOnMissingBean(AccountsCommandsService.class)
public AccountsCommandsService accountsCommandsService(FromJsonHelper fromApiJsonHelper,
ShareAccountDataSerializer shareAccountDataSerializer) {
return new ShareAccountCommandsServiceImpl(fromApiJsonHelper, shareAccountDataSerializer);
}
@Bean
@ConditionalOnMissingBean(ShareAccountDividendReadPlatformService.class)
public ShareAccountDividendReadPlatformService shareAccountDividendReadPlatformService(JdbcTemplate jdbcTemplate,
ColumnValidator columnValidator, PaginationHelper paginationHelper, DatabaseSpecificSQLGenerator sqlGenerator) {
return new ShareAccountDividendReadPlatformServiceImpl(jdbcTemplate, columnValidator, paginationHelper, sqlGenerator);
}
@Bean(value = "share" + AccountsApiConstants.READPLATFORM_NAME)
@ConditionalOnMissingBean(ShareAccountReadPlatformService.class)
public ShareAccountReadPlatformService shareAccountReadPlatformService(ApplicationContext applicationContext,
ChargeReadPlatformService chargeReadPlatformService,
ShareProductDropdownReadPlatformService shareProductDropdownReadPlatformService,
SavingsAccountReadPlatformService savingsAccountReadPlatformService, ClientReadPlatformService clientReadPlatformService,
ShareAccountChargeReadPlatformService shareAccountChargeReadPlatformService,
PurchasedSharesReadPlatformService purchasedSharesReadPlatformService, JdbcTemplate jdbcTemplate,
PaginationHelper paginationHelper, DatabaseSpecificSQLGenerator sqlGenerator) {
return new ShareAccountReadPlatformServiceImpl(applicationContext, chargeReadPlatformService,
shareProductDropdownReadPlatformService, savingsAccountReadPlatformService, clientReadPlatformService,
shareAccountChargeReadPlatformService, purchasedSharesReadPlatformService, jdbcTemplate, paginationHelper, sqlGenerator);
}
@Bean
@ConditionalOnMissingBean(ShareAccountSchedularService.class)
public ShareAccountSchedularService shareAccountSchedularService(ShareAccountDividendRepository shareAccountDividendRepository,
SavingsAccountDomainService savingsAccountDomainService, SavingsAccountAssembler savingsAccountAssembler) {
return new ShareAccountSchedularServiceImpl(shareAccountDividendRepository, savingsAccountDomainService, savingsAccountAssembler);
}
@Bean
@ConditionalOnMissingBean(ShareAccountWritePlatformService.class)
public ShareAccountWritePlatformService shareAccountWritePlatformService(ShareAccountDataSerializer accountDataSerializer,
ShareAccountRepositoryWrapper shareAccountRepository, ShareProductRepositoryWrapper shareProductRepository,
AccountNumberGenerator accountNumberGenerator, AccountNumberFormatRepositoryWrapper accountNumberFormatRepository,
JournalEntryWritePlatformService journalEntryWritePlatformService, NoteRepository noteRepository,
BusinessEventNotifierService businessEventNotifierService) {
return new ShareAccountWritePlatformServiceJpaRepositoryImpl(accountDataSerializer, shareAccountRepository, shareProductRepository,
accountNumberGenerator, accountNumberFormatRepository, journalEntryWritePlatformService, noteRepository,
businessEventNotifierService);
}
}