FINERACT-1932: Add starter configuration class for portfolio.rate module
This commit is contained in:
committed by
Arnold Gálovics
parent
e41d7635e0
commit
c422d2611e
+2
-9
@@ -24,25 +24,18 @@ import com.google.gson.JsonObject;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
|
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
|
||||||
import org.apache.fineract.portfolio.loanproduct.LoanProductConstants;
|
import org.apache.fineract.portfolio.loanproduct.LoanProductConstants;
|
||||||
import org.apache.fineract.portfolio.rate.domain.Rate;
|
import org.apache.fineract.portfolio.rate.domain.Rate;
|
||||||
import org.apache.fineract.portfolio.rate.domain.RateRepositoryWrapper;
|
import org.apache.fineract.portfolio.rate.domain.RateRepositoryWrapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
@RequiredArgsConstructor
|
||||||
public class RateAssembler {
|
public class RateAssembler {
|
||||||
|
|
||||||
private final FromJsonHelper fromApiJsonHelper;
|
private final FromJsonHelper fromApiJsonHelper;
|
||||||
private final RateRepositoryWrapper rateRepository;
|
private final RateRepositoryWrapper rateRepository;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public RateAssembler(final FromJsonHelper fromApiJsonHelper, final RateRepositoryWrapper rateRepository) {
|
|
||||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
|
||||||
this.rateRepository = rateRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Rate> fromParsedJson(final JsonElement element) {
|
public List<Rate> fromParsedJson(final JsonElement element) {
|
||||||
|
|
||||||
final List<Rate> rateItems = new ArrayList<>();
|
final List<Rate> rateItems = new ArrayList<>();
|
||||||
|
|||||||
+2
-9
@@ -24,32 +24,25 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
|
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
|
||||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.apache.fineract.portfolio.rate.data.RateData;
|
import org.apache.fineract.portfolio.rate.data.RateData;
|
||||||
import org.apache.fineract.portfolio.rate.domain.RateAppliesTo;
|
import org.apache.fineract.portfolio.rate.domain.RateAppliesTo;
|
||||||
import org.apache.fineract.portfolio.rate.exception.RateNotFoundException;
|
import org.apache.fineract.portfolio.rate.exception.RateNotFoundException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.dao.EmptyResultDataAccessException;
|
import org.springframework.dao.EmptyResultDataAccessException;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bowpi GT Created by Jose on 19/07/2017.
|
* Bowpi GT Created by Jose on 19/07/2017.
|
||||||
*/
|
*/
|
||||||
@Service
|
@RequiredArgsConstructor
|
||||||
public class RateReadServiceImpl implements RateReadService {
|
public class RateReadServiceImpl implements RateReadService {
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public RateReadServiceImpl(PlatformSecurityContext context, final JdbcTemplate jdbcTemplate) {
|
|
||||||
this.context = context;
|
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<RateData> retrieveAllRates() {
|
public Collection<RateData> retrieveAllRates() {
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
|||||||
+5
-17
@@ -22,6 +22,8 @@ import static org.apache.fineract.portfolio.rate.api.RateApiConstants.approveUse
|
|||||||
|
|
||||||
import jakarta.persistence.PersistenceException;
|
import jakarta.persistence.PersistenceException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||||
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
@@ -35,36 +37,22 @@ import org.apache.fineract.portfolio.rate.serialization.RateDefinitionCommandFro
|
|||||||
import org.apache.fineract.useradministration.domain.AppUser;
|
import org.apache.fineract.useradministration.domain.AppUser;
|
||||||
import org.apache.fineract.useradministration.domain.AppUserRepository;
|
import org.apache.fineract.useradministration.domain.AppUserRepository;
|
||||||
import org.apache.fineract.useradministration.exception.UserNotFoundException;
|
import org.apache.fineract.useradministration.exception.UserNotFoundException;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.orm.jpa.JpaSystemException;
|
import org.springframework.orm.jpa.JpaSystemException;
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bowpi GT Created by Jose on 19/07/2017.
|
* Bowpi GT Created by Jose on 19/07/2017.
|
||||||
*/
|
*/
|
||||||
@Service
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class RateWriteServiceImpl implements RateWriteService {
|
public class RateWriteServiceImpl implements RateWriteService {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(RateWriteServiceImpl.class);
|
|
||||||
|
|
||||||
private final RateRepository rateRepository;
|
private final RateRepository rateRepository;
|
||||||
private final AppUserRepository appUserRepository;
|
private final AppUserRepository appUserRepository;
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final RateDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
private final RateDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public RateWriteServiceImpl(RateRepository rateRepository, AppUserRepository appUserRepository,
|
|
||||||
final RateDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer, PlatformSecurityContext context) {
|
|
||||||
this.rateRepository = rateRepository;
|
|
||||||
this.appUserRepository = appUserRepository;
|
|
||||||
this.context = context;
|
|
||||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult createRate(JsonCommand command) {
|
public CommandProcessingResult createRate(JsonCommand command) {
|
||||||
try {
|
try {
|
||||||
@@ -143,7 +131,7 @@ public class RateWriteServiceImpl implements RateWriteService {
|
|||||||
"A rate with name '" + name + "' already exists", "name", name);
|
"A rate with name '" + name + "' already exists", "name", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.error("Error due to Exception", dve);
|
log.error("Error due to Exception", dve);
|
||||||
throw new PlatformDataIntegrityException("error.msg.fund.unknown.data.integrity.issue",
|
throw new PlatformDataIntegrityException("error.msg.fund.unknown.data.integrity.issue",
|
||||||
"Unknown data integrity issue with resource: " + realCause.getMessage());
|
"Unknown data integrity issue with resource: " + realCause.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
* 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.rate.starter;
|
||||||
|
|
||||||
|
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
|
||||||
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
|
import org.apache.fineract.portfolio.rate.domain.RateRepository;
|
||||||
|
import org.apache.fineract.portfolio.rate.domain.RateRepositoryWrapper;
|
||||||
|
import org.apache.fineract.portfolio.rate.serialization.RateDefinitionCommandFromApiJsonDeserializer;
|
||||||
|
import org.apache.fineract.portfolio.rate.service.RateAssembler;
|
||||||
|
import org.apache.fineract.portfolio.rate.service.RateReadService;
|
||||||
|
import org.apache.fineract.portfolio.rate.service.RateReadServiceImpl;
|
||||||
|
import org.apache.fineract.portfolio.rate.service.RateWriteService;
|
||||||
|
import org.apache.fineract.portfolio.rate.service.RateWriteServiceImpl;
|
||||||
|
import org.apache.fineract.useradministration.domain.AppUserRepository;
|
||||||
|
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 RateConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(RateAssembler.class)
|
||||||
|
public RateAssembler rateAssembler(FromJsonHelper fromApiJsonHelper, RateRepositoryWrapper rateRepository) {
|
||||||
|
return new RateAssembler(fromApiJsonHelper, rateRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(RateReadService.class)
|
||||||
|
public RateReadService rateReadService(JdbcTemplate jdbcTemplate, PlatformSecurityContext context) {
|
||||||
|
return new RateReadServiceImpl(jdbcTemplate, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(RateWriteService.class)
|
||||||
|
public RateWriteService rateWriteService(RateRepository rateRepository, AppUserRepository appUserRepository,
|
||||||
|
PlatformSecurityContext context, RateDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer) {
|
||||||
|
return new RateWriteServiceImpl(rateRepository, appUserRepository, context, fromApiJsonDeserializer);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user