FINERACT-1932: Add starter Configuration class for portfolio.fund module

This commit is contained in:
Mohamed Magdi-Abdelmonem
2023-10-27 17:37:13 +02:00
committed by Aleksandar Vidakovic
parent 0d3f0372cd
commit c5932ec7a5
3 changed files with 55 additions and 25 deletions
@@ -21,28 +21,21 @@ package org.apache.fineract.portfolio.fund.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.fund.data.FundData;
import org.apache.fineract.portfolio.fund.exception.FundNotFoundException;
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.stereotype.Service;
@Service
@RequiredArgsConstructor
public class FundReadPlatformServiceImpl implements FundReadPlatformService {
private final JdbcTemplate jdbcTemplate;
private final PlatformSecurityContext context;
@Autowired
public FundReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate) {
this.context = context;
this.jdbcTemplate = jdbcTemplate;
}
private static final class FundMapper implements RowMapper<FundData> {
public String schema() {
@@ -20,6 +20,8 @@ package org.apache.fineract.portfolio.fund.service;
import jakarta.persistence.PersistenceException;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
@@ -30,32 +32,19 @@ import org.apache.fineract.portfolio.fund.domain.Fund;
import org.apache.fineract.portfolio.fund.domain.FundRepository;
import org.apache.fineract.portfolio.fund.exception.FundNotFoundException;
import org.apache.fineract.portfolio.fund.serialization.FundCommandFromApiJsonDeserializer;
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.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Slf4j
@RequiredArgsConstructor
public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatformService {
private static final Logger LOG = LoggerFactory.getLogger(FundWritePlatformServiceJpaRepositoryImpl.class);
private final PlatformSecurityContext context;
private final FundCommandFromApiJsonDeserializer fromApiJsonDeserializer;
private final FundRepository fundRepository;
@Autowired
public FundWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
final FundCommandFromApiJsonDeserializer fromApiJsonDeserializer, final FundRepository fundRepository) {
this.context = context;
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
this.fundRepository = fundRepository;
}
@Transactional
@Override
@CacheEvict(value = "funds", key = "T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('fn')")
@@ -123,7 +112,7 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf
"name", name);
}
LOG.error("Error occured.", dve);
log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.fund.unknown.data.integrity.issue",
"Unknown data integrity issue with resource: " + realCause.getMessage());
}
@@ -0,0 +1,48 @@
/**
* 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.fund.starter;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.fund.domain.FundRepository;
import org.apache.fineract.portfolio.fund.serialization.FundCommandFromApiJsonDeserializer;
import org.apache.fineract.portfolio.fund.service.FundReadPlatformService;
import org.apache.fineract.portfolio.fund.service.FundReadPlatformServiceImpl;
import org.apache.fineract.portfolio.fund.service.FundWritePlatformService;
import org.apache.fineract.portfolio.fund.service.FundWritePlatformServiceJpaRepositoryImpl;
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 FundConfiguration {
@Bean
@ConditionalOnMissingBean(FundReadPlatformService.class)
public FundReadPlatformService fundReadPlatformService(JdbcTemplate jdbcTemplate, PlatformSecurityContext context) {
return new FundReadPlatformServiceImpl(jdbcTemplate, context);
}
@Bean
@ConditionalOnMissingBean(FundWritePlatformService.class)
public FundWritePlatformService fundWritePlatformService(PlatformSecurityContext context,
FundCommandFromApiJsonDeserializer fromApiJsonDeserializer, FundRepository fundRepository) {
return new FundWritePlatformServiceJpaRepositoryImpl(context, fromApiJsonDeserializer, fundRepository);
}
}