From 480fd49fd0b3d07ec15e7ac7713ff4a79b3bf9b5 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sun, 19 Nov 2023 00:31:41 -0800 Subject: [PATCH] Keep transaction simplication --- .../com/wisemapping/config/AppConfig.java | 9 ++++ .../service/HibernateAppListener.java | 38 -------------- .../wisemapping/service/LabelServiceImpl.java | 11 ++-- .../service/MindmapServiceImpl.java | 10 +++- .../wisemapping/service/UserServiceImpl.java | 13 +++++ wise-webapp/src/main/webapp/WEB-INF/web.xml | 3 -- .../main/webapp/WEB-INF/wisemapping-dao.xml | 15 ------ .../webapp/WEB-INF/wisemapping-service.xml | 51 ------------------- 8 files changed, 38 insertions(+), 112 deletions(-) delete mode 100755 wise-webapp/src/main/java/com/wisemapping/service/HibernateAppListener.java diff --git a/wise-webapp/src/main/java/com/wisemapping/config/AppConfig.java b/wise-webapp/src/main/java/com/wisemapping/config/AppConfig.java index 647863eb..a31c0be8 100644 --- a/wise-webapp/src/main/java/com/wisemapping/config/AppConfig.java +++ b/wise-webapp/src/main/java/com/wisemapping/config/AppConfig.java @@ -1,7 +1,12 @@ package com.wisemapping.config; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.TransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.transaction.interceptor.TransactionAttributeSource; +import org.springframework.transaction.interceptor.TransactionInterceptor; import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @@ -11,8 +16,12 @@ import org.springframework.web.servlet.view.JstlView; @EnableWebMvc @Configuration +@EnableTransactionManagement public class AppConfig { + @Autowired + TransactionManager txManager; + @Bean HandlerExceptionResolver errorHandler() { final SimpleMappingExceptionResolver result = new SimpleMappingExceptionResolver(); diff --git a/wise-webapp/src/main/java/com/wisemapping/service/HibernateAppListener.java b/wise-webapp/src/main/java/com/wisemapping/service/HibernateAppListener.java deleted file mode 100755 index 1e9da9a2..00000000 --- a/wise-webapp/src/main/java/com/wisemapping/service/HibernateAppListener.java +++ /dev/null @@ -1,38 +0,0 @@ -/* -* Copyright [2022] [wisemapping] -* -* Licensed under WiseMapping Public License, Version 1.0 (the "License"). -* It is basically the Apache License, Version 2.0 (the "License") plus the -* "powered by wisemapping" text requirement on every single page; -* you may not use this file except in compliance with the License. -* You may obtain a copy of the license at -* -* http://www.wisemapping.org/license -* -* 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 com.wisemapping.service; - -import jakarta.servlet.ServletContextEvent; -import jakarta.servlet.ServletContextListener; - -public class HibernateAppListener implements ServletContextListener { - - public void contextInitialized(ServletContextEvent ce) { - - try { - - Class.forName("tomcatJndi.HibernateUtil").newInstance(); - - } catch (Exception e) {} - } - - /* Application Shutdown Event */ - public void contextDestroyed(ServletContextEvent ce) - { } -} diff --git a/wise-webapp/src/main/java/com/wisemapping/service/LabelServiceImpl.java b/wise-webapp/src/main/java/com/wisemapping/service/LabelServiceImpl.java index 8217dc1b..daaa0c9b 100644 --- a/wise-webapp/src/main/java/com/wisemapping/service/LabelServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/LabelServiceImpl.java @@ -23,17 +23,20 @@ import com.wisemapping.model.Label; import com.wisemapping.model.User; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import java.util.List; +@Service("labelService") +@Transactional(propagation = Propagation.REQUIRED) public class LabelServiceImpl implements LabelService { + @Autowired private LabelManager labelManager; - public void setLabelManager(LabelManager labelManager) { - this.labelManager = labelManager; - } - @Override public void addLabel(@NotNull final Label label, @NotNull final User user) throws WiseMappingException { diff --git a/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java b/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java index eeb46f01..c9ed4207 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java @@ -27,7 +27,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import java.io.UnsupportedEncodingException; import java.util.Calendar; @@ -35,8 +39,10 @@ import java.util.List; import java.util.Optional; import java.util.Set; - +@Service("mindmapService") +@Transactional(propagation = Propagation.REQUIRED) public class MindmapServiceImpl + implements MindmapService { @Autowired @@ -49,6 +55,8 @@ public class MindmapServiceImpl @Autowired private NotificationService notificationService; + + @Value("${admin.user}") private String adminUser; final private LockManager lockManager; diff --git a/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java b/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java index 5054ef99..f62aea75 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java @@ -33,18 +33,31 @@ import com.wisemapping.util.VelocityEngineUtils; import com.wisemapping.util.VelocityEngineWrapper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import java.util.*; +@Service("userService") +@Transactional(propagation = Propagation.REQUIRED) public class UserServiceImpl implements UserService { + + @Autowired private UserManager userManager; + @Autowired private MindmapService mindmapService; + @Autowired private NotificationService notificationService; + @Autowired private MessageSource messageSource; + @Autowired private VelocityEngineWrapper velocityEngineWrapper; + @Autowired private GoogleService googleService; @Override diff --git a/wise-webapp/src/main/webapp/WEB-INF/web.xml b/wise-webapp/src/main/webapp/WEB-INF/web.xml index 291b7ed2..a724fbf6 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/web.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/web.xml @@ -44,9 +44,6 @@ - WebApplicationContextUtils.getWebApplicationContext(servletContext). --> - - com.wisemapping.service.HibernateAppListener - com.wisemapping.listener.UnlockOnExpireListener diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-dao.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-dao.xml index 3a0d213f..ba55daa0 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-dao.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-dao.xml @@ -35,19 +35,4 @@ - - - - - PROPAGATION_REQUIRED - - - - - - - - - diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-service.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-service.xml index 2b6a3a8f..97dadf1c 100755 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-service.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-service.xml @@ -30,61 +30,10 @@ - - - - - - - - - - - - - - - PROPAGATION_REQUIRED - - - - - - - - - - - - - - - - txInterceptor - - - - - - - - - - - - - - - - PROPAGATION_REQUIRED - - - -