FINERACT-1932: Add stater configuration class for spm module services

This commit is contained in:
Mohamed Magdi-Abdelmonem
2023-10-11 08:13:34 +02:00
committed by Arnold Gálovics
parent 1173658520
commit 0c1997aa9a
5 changed files with 72 additions and 41 deletions
@@ -19,26 +19,18 @@
package org.apache.fineract.spm.service;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.spm.domain.LookupTable;
import org.apache.fineract.spm.domain.LookupTableRepository;
import org.apache.fineract.spm.domain.Survey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class LookupTableService {
private final PlatformSecurityContext securityContext;
private final LookupTableRepository lookupTableRepository;
@Autowired
public LookupTableService(final PlatformSecurityContext securityContext, final LookupTableRepository lookupTableRepository) {
this.securityContext = securityContext;
this.lookupTableRepository = lookupTableRepository;
}
public List<LookupTable> findByKey(final String key) {
this.securityContext.authenticatedUser();
@@ -23,27 +23,20 @@ import java.sql.SQLException;
import java.time.OffsetDateTime;
import java.util.Collection;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.spm.data.ScorecardData;
import org.apache.fineract.spm.data.ScorecardValue;
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 ScorecardReadPlatformServiceImpl implements ScorecardReadPlatformService {
private final JdbcTemplate jdbcTemplate;
private final PlatformSecurityContext context;
@Autowired
public ScorecardReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate) {
this.context = context;
this.jdbcTemplate = jdbcTemplate;
}
private static final class ScorecardMapper implements RowMapper<ScorecardData> {
public String schema() {
@@ -19,27 +19,19 @@
package org.apache.fineract.spm.service;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.client.domain.Client;
import org.apache.fineract.spm.domain.Scorecard;
import org.apache.fineract.spm.domain.ScorecardRepository;
import org.apache.fineract.spm.domain.Survey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class ScorecardService {
private final PlatformSecurityContext securityContext;
private final ScorecardRepository scorecardRepository;
@Autowired
public ScorecardService(final PlatformSecurityContext securityContext, final ScorecardRepository scorecardRepository) {
this.securityContext = securityContext;
this.scorecardRepository = scorecardRepository;
}
public List<Scorecard> createScorecard(final List<Scorecard> scorecards) {
this.securityContext.authenticatedUser();
@@ -22,6 +22,7 @@ import jakarta.persistence.EntityExistsException;
import jakarta.persistence.PersistenceException;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
@@ -29,27 +30,16 @@ import org.apache.fineract.spm.domain.Survey;
import org.apache.fineract.spm.domain.SurveyRepository;
import org.apache.fineract.spm.domain.SurveyValidator;
import org.apache.fineract.spm.exception.SurveyNotFoundException;
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 SpmService {
private final PlatformSecurityContext securityContext;
private final SurveyRepository surveyRepository;
private final SurveyValidator surveyValidator;
@Autowired
public SpmService(final PlatformSecurityContext securityContext, final SurveyRepository surveyRepository,
final SurveyValidator surveyValidator) {
this.securityContext = securityContext;
this.surveyRepository = surveyRepository;
this.surveyValidator = surveyValidator;
}
public List<Survey> fetchValidSurveys() {
this.securityContext.authenticatedUser();
@@ -0,0 +1,64 @@
/**
* 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.spm.starter;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.spm.domain.LookupTableRepository;
import org.apache.fineract.spm.domain.ScorecardRepository;
import org.apache.fineract.spm.domain.SurveyRepository;
import org.apache.fineract.spm.domain.SurveyValidator;
import org.apache.fineract.spm.service.LookupTableService;
import org.apache.fineract.spm.service.ScorecardReadPlatformService;
import org.apache.fineract.spm.service.ScorecardReadPlatformServiceImpl;
import org.apache.fineract.spm.service.ScorecardService;
import org.apache.fineract.spm.service.SpmService;
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 SpmConfiguration {
@Bean
@ConditionalOnMissingBean(LookupTableService.class)
public LookupTableService lookupTableService(PlatformSecurityContext securityContext, LookupTableRepository lookupTableRepository) {
return new LookupTableService(securityContext, lookupTableRepository);
}
@Bean
@ConditionalOnMissingBean(ScorecardReadPlatformService.class)
public ScorecardReadPlatformService scorecardReadPlatformService(JdbcTemplate jdbcTemplate, PlatformSecurityContext context) {
return new ScorecardReadPlatformServiceImpl(jdbcTemplate, context);
}
@Bean
@ConditionalOnMissingBean(ScorecardService.class)
public ScorecardService scorecardService(PlatformSecurityContext securityContext, ScorecardRepository scorecardRepository) {
return new ScorecardService(securityContext, scorecardRepository);
}
@Bean
@ConditionalOnMissingBean(SpmService.class)
public SpmService spmService(PlatformSecurityContext securityContext, SurveyRepository surveyRepository,
SurveyValidator surveyValidator) {
return new SpmService(securityContext, surveyRepository, surveyValidator);
}
}