From 0c1997aa9ab5806662965d2ecf5dc36e1fcbaca6 Mon Sep 17 00:00:00 2001 From: Mohamed Magdi-Abdelmonem Date: Wed, 4 Oct 2023 19:03:21 +0300 Subject: [PATCH] FINERACT-1932: Add stater configuration class for spm module services --- .../spm/service/LookupTableService.java | 12 +--- .../ScorecardReadPlatformServiceImpl.java | 11 +--- .../spm/service/ScorecardService.java | 12 +--- .../fineract/spm/service/SpmService.java | 14 +--- .../spm/starter/SpmConfiguration.java | 64 +++++++++++++++++++ 5 files changed, 72 insertions(+), 41 deletions(-) create mode 100644 fineract-provider/src/main/java/org/apache/fineract/spm/starter/SpmConfiguration.java diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/service/LookupTableService.java b/fineract-provider/src/main/java/org/apache/fineract/spm/service/LookupTableService.java index f98d4ab42..13c18dd62 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/service/LookupTableService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/service/LookupTableService.java @@ -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 findByKey(final String key) { this.securityContext.authenticatedUser(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/service/ScorecardReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/spm/service/ScorecardReadPlatformServiceImpl.java index a1e1ce863..d458ff12c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/service/ScorecardReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/service/ScorecardReadPlatformServiceImpl.java @@ -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 { public String schema() { diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/service/ScorecardService.java b/fineract-provider/src/main/java/org/apache/fineract/spm/service/ScorecardService.java index 52b162ca8..00297f7bb 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/service/ScorecardService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/service/ScorecardService.java @@ -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 createScorecard(final List scorecards) { this.securityContext.authenticatedUser(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java b/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java index 22c741846..a65f21418 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java @@ -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 fetchValidSurveys() { this.securityContext.authenticatedUser(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/starter/SpmConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/spm/starter/SpmConfiguration.java new file mode 100644 index 000000000..6e009e9b0 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/starter/SpmConfiguration.java @@ -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); + } +}