FINERACT-1932: Add custom Configuration class for self-account module

This commit is contained in:
Mohamed Magdi-Abdelmonem
2023-10-02 15:15:27 +02:00
committed by Arnold Gálovics
parent c422d2611e
commit 2272174c24
4 changed files with 68 additions and 31 deletions
@@ -21,23 +21,17 @@ package org.apache.fineract.portfolio.self.account.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.portfolio.self.account.data.SelfAccountTemplateData;
import org.apache.fineract.useradministration.domain.AppUser;
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 SelfAccountTransferReadServiceImpl implements SelfAccountTransferReadService {
private final JdbcTemplate jdbcTemplate;
@Autowired
public SelfAccountTransferReadServiceImpl(final JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public Collection<SelfAccountTemplateData> retrieveSelfAccountTemplateData(AppUser user) {
SelfAccountTemplateMapper mapper = new SelfAccountTemplateMapper();
@@ -28,12 +28,9 @@ import org.apache.fineract.portfolio.account.service.AccountTransferEnumerations
import org.apache.fineract.portfolio.self.account.data.SelfAccountTemplateData;
import org.apache.fineract.portfolio.self.account.data.SelfBeneficiariesTPTData;
import org.apache.fineract.useradministration.domain.AppUser;
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
public class SelfBeneficiariesTPTReadPlatformServiceImpl implements SelfBeneficiariesTPTReadPlatformService {
private final PlatformSecurityContext context;
@@ -41,7 +38,6 @@ public class SelfBeneficiariesTPTReadPlatformServiceImpl implements SelfBenefici
private final BeneficiaryMapper mapper;
private final AccountTemplateMapper accountTemplateMapper;
@Autowired
public SelfBeneficiariesTPTReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate) {
this.context = context;
this.jdbcTemplate = jdbcTemplate;
@@ -26,6 +26,8 @@ import static org.apache.fineract.portfolio.self.account.api.SelfBeneficiariesTP
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
@@ -42,35 +44,19 @@ import org.apache.fineract.portfolio.self.account.domain.SelfBeneficiariesTPTRep
import org.apache.fineract.portfolio.self.account.exception.InvalidAccountInformationException;
import org.apache.fineract.portfolio.self.account.exception.InvalidBeneficiaryException;
import org.apache.fineract.useradministration.domain.AppUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@Slf4j
public class SelfBeneficiariesTPTWritePlatformServiceImpl implements SelfBeneficiariesTPTWritePlatformService {
private static final Logger LOG = LoggerFactory.getLogger(SelfBeneficiariesTPTWritePlatformServiceImpl.class);
private final PlatformSecurityContext context;
private final SelfBeneficiariesTPTRepository repository;
private final SelfBeneficiariesTPTDataValidator validator;
private final LoanRepositoryWrapper loanRepositoryWrapper;
private final SavingsAccountRepositoryWrapper savingRepositoryWrapper;
@Autowired
public SelfBeneficiariesTPTWritePlatformServiceImpl(final PlatformSecurityContext context,
final SelfBeneficiariesTPTRepository repository, final SelfBeneficiariesTPTDataValidator validator,
final LoanRepositoryWrapper loanRepositoryWrapper, final SavingsAccountRepositoryWrapper savingRepositoryWrapper) {
this.context = context;
this.repository = repository;
this.validator = validator;
this.loanRepositoryWrapper = loanRepositoryWrapper;
this.savingRepositoryWrapper = savingRepositoryWrapper;
}
@Transactional
@Override
public CommandProcessingResult add(JsonCommand command) {
@@ -178,7 +164,7 @@ public class SelfBeneficiariesTPTWritePlatformServiceImpl implements SelfBenefic
"Beneficiary with name `" + name + "` already exists", NAME_PARAM_NAME, name);
}
LOG.error("Error occured.", dae);
log.error("Error occured.", dae);
throw new PlatformDataIntegrityException("error.msg.beneficiary.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.");
}
@@ -0,0 +1,61 @@
/**
* 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.self.account.starter;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepositoryWrapper;
import org.apache.fineract.portfolio.self.account.data.SelfBeneficiariesTPTDataValidator;
import org.apache.fineract.portfolio.self.account.domain.SelfBeneficiariesTPTRepository;
import org.apache.fineract.portfolio.self.account.service.SelfAccountTransferReadService;
import org.apache.fineract.portfolio.self.account.service.SelfAccountTransferReadServiceImpl;
import org.apache.fineract.portfolio.self.account.service.SelfBeneficiariesTPTReadPlatformService;
import org.apache.fineract.portfolio.self.account.service.SelfBeneficiariesTPTReadPlatformServiceImpl;
import org.apache.fineract.portfolio.self.account.service.SelfBeneficiariesTPTWritePlatformService;
import org.apache.fineract.portfolio.self.account.service.SelfBeneficiariesTPTWritePlatformServiceImpl;
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 SelfAccountConfiguration {
@Bean
@ConditionalOnMissingBean(SelfAccountTransferReadService.class)
public SelfAccountTransferReadService selfAccountTransferReadService(JdbcTemplate jdbcTemplate) {
return new SelfAccountTransferReadServiceImpl(jdbcTemplate);
}
@Bean
@ConditionalOnMissingBean(SelfBeneficiariesTPTReadPlatformService.class)
public SelfBeneficiariesTPTReadPlatformService selfBeneficiariesTPTReadPlatformService(PlatformSecurityContext context,
JdbcTemplate jdbcTemplate) {
return new SelfBeneficiariesTPTReadPlatformServiceImpl(context, jdbcTemplate);
}
@Bean
@ConditionalOnMissingBean(SelfBeneficiariesTPTWritePlatformService.class)
public SelfBeneficiariesTPTWritePlatformService selfBeneficiariesTPTWritePlatformService(PlatformSecurityContext context,
SelfBeneficiariesTPTRepository repository, SelfBeneficiariesTPTDataValidator validator,
LoanRepositoryWrapper loanRepositoryWrapper, SavingsAccountRepositoryWrapper savingRepositoryWrapper) {
return new SelfBeneficiariesTPTWritePlatformServiceImpl(context, repository, validator, loanRepositoryWrapper,
savingRepositoryWrapper);
}
}