From e75e758e7167706416f4f2cf6582997e5f6f1cb2 Mon Sep 17 00:00:00 2001 From: "Sinha, Abhinav" Date: Mon, 23 Oct 2023 19:31:07 -0400 Subject: [PATCH] Add custom Configuration class for notification module (FINERACT-1932) --- .../NotificationDomainServiceImpl.java | 2 - ...ionGeneratorReadRepositoryWrapperImpl.java | 8 +- ...cationMapperReadRepositoryWrapperImpl.java | 8 +- ...icationMapperWritePlatformServiceImpl.java | 8 +- .../NotificationReadPlatformServiceImpl.java | 2 - .../NotificationWritePlatformServiceImpl.java | 2 - .../service/UserNotificationServiceImpl.java | 2 - .../starter/NotificationConfiguration.java | 81 +++++++++++++++++++ 8 files changed, 87 insertions(+), 26 deletions(-) create mode 100644 fineract-provider/src/main/java/org/apache/fineract/notification/starter/NotificationConfiguration.java diff --git a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationDomainServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationDomainServiceImpl.java index e6efa2567..4a9f2232c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationDomainServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationDomainServiceImpl.java @@ -55,9 +55,7 @@ import org.apache.fineract.portfolio.savings.domain.RecurringDepositAccount; import org.apache.fineract.portfolio.savings.domain.SavingsAccount; import org.apache.fineract.portfolio.savings.domain.SavingsAccountTransaction; import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccount; -import org.springframework.stereotype.Service; -@Service @RequiredArgsConstructor @Slf4j public class NotificationDomainServiceImpl implements NotificationDomainService { diff --git a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationGeneratorReadRepositoryWrapperImpl.java b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationGeneratorReadRepositoryWrapperImpl.java index 1267aa585..fcec6503c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationGeneratorReadRepositoryWrapperImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationGeneratorReadRepositoryWrapperImpl.java @@ -19,21 +19,17 @@ package org.apache.fineract.notification.service; import java.util.List; +import lombok.RequiredArgsConstructor; import org.apache.fineract.notification.domain.Notification; import org.apache.fineract.notification.domain.NotificationRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service +@RequiredArgsConstructor public class NotificationGeneratorReadRepositoryWrapperImpl implements NotificationGeneratorReadRepositoryWrapper { private final NotificationRepository notificationRepository; - @Autowired - public NotificationGeneratorReadRepositoryWrapperImpl(NotificationRepository notificationRepository) { - this.notificationRepository = notificationRepository; - } - @Override public Notification findById(Long id) { return this.notificationRepository.findById(id).orElse(null); diff --git a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationMapperReadRepositoryWrapperImpl.java b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationMapperReadRepositoryWrapperImpl.java index 91f879825..a332a45a3 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationMapperReadRepositoryWrapperImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationMapperReadRepositoryWrapperImpl.java @@ -19,21 +19,17 @@ package org.apache.fineract.notification.service; import java.util.List; +import lombok.RequiredArgsConstructor; import org.apache.fineract.notification.domain.NotificationMapper; import org.apache.fineract.notification.domain.NotificationMapperRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service +@RequiredArgsConstructor public class NotificationMapperReadRepositoryWrapperImpl implements NotificationMapperReadRepositoryWrapper { private final NotificationMapperRepository notificationMapperRepository; - @Autowired - public NotificationMapperReadRepositoryWrapperImpl(NotificationMapperRepository notificationMapperRepository) { - this.notificationMapperRepository = notificationMapperRepository; - } - @Override public NotificationMapper findById(Long id) { return this.notificationMapperRepository.findById(id).orElse(null); diff --git a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationMapperWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationMapperWritePlatformServiceImpl.java index e74dcc276..c2b95b5f8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationMapperWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationMapperWritePlatformServiceImpl.java @@ -18,21 +18,17 @@ */ package org.apache.fineract.notification.service; +import lombok.RequiredArgsConstructor; import org.apache.fineract.notification.domain.NotificationMapper; import org.apache.fineract.notification.domain.NotificationMapperRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service +@RequiredArgsConstructor public class NotificationMapperWritePlatformServiceImpl implements NotificationMapperWritePlatformService { private final NotificationMapperRepository notificationMapperRepository; - @Autowired - public NotificationMapperWritePlatformServiceImpl(NotificationMapperRepository notificationMapperRepository) { - this.notificationMapperRepository = notificationMapperRepository; - } - @Override public Long create(NotificationMapper notificationMapper) { this.notificationMapperRepository.saveAndFlush(notificationMapper); diff --git a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationReadPlatformServiceImpl.java index ae19bad6a..1ddd1129f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationReadPlatformServiceImpl.java @@ -35,9 +35,7 @@ import org.apache.fineract.notification.data.NotificationData; import org.apache.fineract.notification.data.NotificationMapperData; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Service; -@Service @RequiredArgsConstructor public class NotificationReadPlatformServiceImpl implements NotificationReadPlatformService { diff --git a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationWritePlatformServiceImpl.java index e5a5b68f4..a459c74b0 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/notification/service/NotificationWritePlatformServiceImpl.java @@ -27,10 +27,8 @@ import org.apache.fineract.notification.domain.Notification; import org.apache.fineract.notification.domain.NotificationMapper; import org.apache.fineract.useradministration.domain.AppUser; import org.apache.fineract.useradministration.domain.AppUserRepository; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service @Transactional @RequiredArgsConstructor public class NotificationWritePlatformServiceImpl implements NotificationWritePlatformService { diff --git a/fineract-provider/src/main/java/org/apache/fineract/notification/service/UserNotificationServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/notification/service/UserNotificationServiceImpl.java index f597aa4a1..5f06f8986 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/notification/service/UserNotificationServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/notification/service/UserNotificationServiceImpl.java @@ -33,9 +33,7 @@ import org.apache.fineract.notification.data.NotificationData; import org.apache.fineract.notification.eventandlistener.NotificationEventPublisher; import org.apache.fineract.useradministration.domain.AppUser; import org.apache.fineract.useradministration.domain.AppUserRepository; -import org.springframework.stereotype.Service; -@Service @RequiredArgsConstructor @Slf4j public class UserNotificationServiceImpl implements UserNotificationService { diff --git a/fineract-provider/src/main/java/org/apache/fineract/notification/starter/NotificationConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/notification/starter/NotificationConfiguration.java new file mode 100644 index 000000000..4c8766c38 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/notification/starter/NotificationConfiguration.java @@ -0,0 +1,81 @@ +/** + * 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.notification.starter; + +import org.apache.fineract.infrastructure.core.config.FineractProperties; +import org.apache.fineract.infrastructure.core.service.PaginationHelper; +import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator; +import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.apache.fineract.infrastructure.security.utils.ColumnValidator; +import org.apache.fineract.notification.eventandlistener.NotificationEventPublisher; +import org.apache.fineract.notification.service.NotificationDomainService; +import org.apache.fineract.notification.service.NotificationDomainServiceImpl; +import org.apache.fineract.notification.service.NotificationGeneratorReadRepositoryWrapper; +import org.apache.fineract.notification.service.NotificationGeneratorWritePlatformService; +import org.apache.fineract.notification.service.NotificationMapperWritePlatformService; +import org.apache.fineract.notification.service.NotificationReadPlatformService; +import org.apache.fineract.notification.service.NotificationReadPlatformServiceImpl; +import org.apache.fineract.notification.service.NotificationWritePlatformService; +import org.apache.fineract.notification.service.NotificationWritePlatformServiceImpl; +import org.apache.fineract.notification.service.UserNotificationService; +import org.apache.fineract.notification.service.UserNotificationServiceImpl; +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 NotificationConfiguration { + + @Bean + @ConditionalOnMissingBean(NotificationDomainService.class) + public NotificationDomainService notificationDomainService(BusinessEventNotifierService businessEventNotifierService, + PlatformSecurityContext context, UserNotificationService userNotificationService) { + return new NotificationDomainServiceImpl(businessEventNotifierService, context, userNotificationService); + } + + @Bean + @ConditionalOnMissingBean(NotificationReadPlatformService.class) + public NotificationReadPlatformService notificationReadPlatformService(JdbcTemplate jdbcTemplate, PlatformSecurityContext context, + ColumnValidator columnValidator, PaginationHelper paginationHelper, DatabaseSpecificSQLGenerator sqlGenerator) { + return new NotificationReadPlatformServiceImpl(jdbcTemplate, context, columnValidator, paginationHelper, sqlGenerator); + } + + @Bean + @ConditionalOnMissingBean(NotificationWritePlatformService.class) + public NotificationWritePlatformService notificationWritePlatformService( + NotificationGeneratorWritePlatformService notificationGeneratorWritePlatformService, + NotificationGeneratorReadRepositoryWrapper notificationGeneratorReadRepositoryWrapper, AppUserRepository appUserRepository, + NotificationMapperWritePlatformService notificationMapperWritePlatformService) { + return new NotificationWritePlatformServiceImpl(notificationGeneratorWritePlatformService, + notificationGeneratorReadRepositoryWrapper, appUserRepository, notificationMapperWritePlatformService); + } + + @Bean + @ConditionalOnMissingBean(UserNotificationService.class) + public UserNotificationService userNotificationService(NotificationEventPublisher notificationEventPublisher, + AppUserRepository appUserRepository, FineractProperties fineractProperties, + NotificationReadPlatformService notificationReadPlatformService, + NotificationWritePlatformService notificationWritePlatformService) { + return new UserNotificationServiceImpl(notificationEventPublisher, appUserRepository, fineractProperties, + notificationReadPlatformService, notificationWritePlatformService); + } +}