浏览代码

增加自定义manager自动配置

zhouhao 7 年之前
父节点
当前提交
c3079a1e15

+ 14 - 11
hsweb-system/hsweb-system-workflow/hsweb-system-workflow-flowable/pom.xml

@@ -89,18 +89,24 @@
         <dependency>
             <groupId>org.hswebframework.web</groupId>
             <artifactId>hsweb-authorization-api</artifactId>
-            <version>3.0-SNAPSHOT</version>
+            <version>${project.version}</version>
         </dependency>
         <dependency>
             <groupId>org.hswebframework.web</groupId>
             <artifactId>hsweb-commons-entity</artifactId>
-            <version>3.0-SNAPSHOT</version>
+            <version>${project.version}</version>
         </dependency>
         <dependency>
             <groupId>org.hswebframework.web</groupId>
             <artifactId>hsweb-commons-controller</artifactId>
-            <version>3.0-SNAPSHOT</version>
+            <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.hswebframework.web</groupId>
+            <artifactId>hsweb-system-authorization-service-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
         <dependency>
             <groupId>com.h2database</groupId>
             <artifactId>h2</artifactId>
@@ -126,18 +132,15 @@
         <dependency>
             <groupId>org.hswebframework.web</groupId>
             <artifactId>hsweb-spring-boot-starter</artifactId>
-            <version>3.0-SNAPSHOT</version>
+            <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
+
         <dependency>
             <groupId>org.hswebframework.web</groupId>
-            <artifactId>hsweb-system-authorization-entity</artifactId>
-            <version>3.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.hswebframework.web</groupId>
-            <artifactId>hsweb-system-authorization-service-api</artifactId>
-            <version>3.0-SNAPSHOT</version>
+            <artifactId>hsweb-system-authorization-starter</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
         </dependency>
     </dependencies>
 </project>

+ 71 - 0
hsweb-system/hsweb-system-workflow/hsweb-system-workflow-flowable/src/main/java/org/hswebframework/web/workflow/flowable/FlowableAutoConfiguration.java

@@ -0,0 +1,71 @@
+package org.hswebframework.web.workflow.flowable;
+
+import org.activiti.engine.impl.interceptor.SessionFactory;
+import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
+import org.hswebframework.web.service.authorization.UserService;
+import org.hswebframework.web.workflow.flowable.utils.CustomGroupEntityManager;
+import org.hswebframework.web.workflow.flowable.utils.CustomGroupEntityManagerFactory;
+import org.hswebframework.web.workflow.flowable.utils.CustomUserEntityManager;
+import org.hswebframework.web.workflow.flowable.utils.CustomUserEntityManagerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.List;
+
+/**
+ * Created by Administrator on 2017/7/26.
+ */
+@Configuration
+@AutoConfigureAfter(FlowableAutoConfiguration.CustomEntityManagerAutoConfiguration.class)
+public class FlowableAutoConfiguration {
+
+    @Autowired(required = false)
+    private List<SessionFactory> sessionFactories;
+
+    @Bean
+    public ProcessEngineConfigurationConfigurer processEngineConfigurationConfigurer() {
+        return configuration -> {
+            configuration
+                    .setAsyncExecutorActivate(false)
+                    .setJobExecutorActivate(false)
+                    .setActivityFontName("宋体")
+                    .setLabelFontName("宋体")
+                    .setAnnotationFontName("宋体");
+
+            if (sessionFactories != null) {
+                configuration.setCustomSessionFactories(sessionFactories);
+            }
+        };
+
+//        ProcessEngineConfiguration processEngineConfiguration = new StandaloneProcessEngineConfiguration()
+//                .setAsyncExecutorActivate(false)
+//                .setJobExecutorActivate(false)
+//                .setActivityFontName("宋体")
+//                .setLabelFontName("宋体")
+//                .setAnnotationFontName("宋体");
+//        return processEngineConfiguration;
+    }
+
+
+    @ConditionalOnBean(UserService.class)
+    @Configuration
+    public static class CustomEntityManagerAutoConfiguration {
+
+        @Autowired
+        private UserService userService;
+
+        @Bean
+        public CustomGroupEntityManagerFactory customGroupEntityManagerFactory() {
+            return new CustomGroupEntityManagerFactory(new CustomGroupEntityManager(userService));
+        }
+
+        @Bean
+        public CustomUserEntityManagerFactory customUserEntityManagerFactory() {
+            return new CustomUserEntityManagerFactory(new CustomUserEntityManager(userService));
+        }
+
+    }
+}

+ 4 - 2
hsweb-system/hsweb-system-workflow/hsweb-system-workflow-flowable/src/main/java/org/hswebframework/web/workflow/flowable/utils/CustomGroupEntityManager.java

@@ -16,12 +16,14 @@ import java.util.List;
 /**
  * Created by Administrator on 2016/3/19 0019.
  */
-@Service
 public class CustomGroupEntityManager extends GroupEntityManager {
 
-    @Autowired
     private UserService userService;
 
+    public CustomGroupEntityManager(UserService userService) {
+        this.userService = userService;
+    }
+
     public GroupEntity findGroupById(final String id) {
         if (id == null)
             return null;

+ 3 - 2
hsweb-system/hsweb-system-workflow/hsweb-system-workflow-flowable/src/main/java/org/hswebframework/web/workflow/flowable/utils/CustomGroupEntityManagerFactory.java

@@ -4,6 +4,7 @@ import org.activiti.engine.impl.interceptor.Session;
 import org.activiti.engine.impl.interceptor.SessionFactory;
 import org.activiti.engine.impl.persistence.entity.GroupEntityManager;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 /**
  * Created by Administrator on 2016/3/19 0019.
@@ -12,8 +13,8 @@ public class CustomGroupEntityManagerFactory implements SessionFactory {
 
     private CustomGroupEntityManager customGroupEntityManager;
 
-    @Autowired
-    public void setCustomGroupEntityManager(CustomGroupEntityManager customGroupEntityManager){
+
+    public CustomGroupEntityManagerFactory(CustomGroupEntityManager customGroupEntityManager) {
         this.customGroupEntityManager = customGroupEntityManager;
     }
 

+ 5 - 4
hsweb-system/hsweb-system-workflow/hsweb-system-workflow-flowable/src/main/java/org/hswebframework/web/workflow/flowable/utils/CustomUserEntityManager.java

@@ -16,14 +16,15 @@ import org.springframework.stereotype.Service;
 
 import java.util.List;
 
-@Service
 public class CustomUserEntityManager extends UserEntityManager {
     protected Logger logger = LoggerFactory.getLogger(this.getClass());
 
-    @SuppressWarnings("all")
-    @Autowired
     private UserService userService;
 
+    public CustomUserEntityManager(UserService userService) {
+        this.userService = userService;
+    }
+
     @Override
     public UserEntity findUserById(final String userId) {
         if (userId == null)
@@ -42,7 +43,7 @@ public class CustomUserEntityManager extends UserEntityManager {
             return null;
 
         List<RoleEntity> sysRoles = userService.getUserRole(userId);
-        return  ActivitiUserUtil.toActivitiGroups(sysRoles);
+        return ActivitiUserUtil.toActivitiGroups(sysRoles);
 
     }
 

+ 2 - 3
hsweb-system/hsweb-system-workflow/hsweb-system-workflow-flowable/src/main/java/org/hswebframework/web/workflow/flowable/utils/CustomUserEntityManagerFactory.java

@@ -3,13 +3,12 @@ package org.hswebframework.web.workflow.flowable.utils;
 import org.activiti.engine.impl.interceptor.Session;
 import org.activiti.engine.impl.interceptor.SessionFactory;
 import org.activiti.engine.impl.persistence.entity.UserIdentityManager;
-import org.springframework.beans.factory.annotation.Autowired;
 
 public class CustomUserEntityManagerFactory implements SessionFactory {
     private CustomUserEntityManager customUserEntityManager;
 
-    @Autowired
-    public void setCustomUserEntityManager(CustomUserEntityManager customUserEntityManager) {
+
+    public CustomUserEntityManagerFactory(CustomUserEntityManager customUserEntityManager) {
         this.customUserEntityManager = customUserEntityManager;
     }
 

+ 0 - 26
hsweb-system/hsweb-system-workflow/hsweb-system-workflow-flowable/src/main/java/org/hswebframework/web/workflow/flowable/utils/FlowableAutoConfiguration.java

@@ -1,26 +0,0 @@
-package org.hswebframework.web.workflow.flowable.utils;
-
-import org.activiti.engine.ProcessEngineConfiguration;
-import org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * Created by Administrator on 2017/7/26.
- */
-@Configuration
-public class FlowableAutoConfiguration {
-
-    @Bean
-    public ProcessEngineConfiguration processEngineConfiguration(){
-        ProcessEngineConfiguration processEngineConfiguration = new StandaloneProcessEngineConfiguration()
-                .setAsyncExecutorActivate(false)
-                .setJobExecutorActivate(false)
-                .setActivityFontName("宋体")
-                .setLabelFontName("宋体")
-                .setAnnotationFontName("宋体");
-
-        return processEngineConfiguration;
-    }
-
-}

+ 3 - 0
hsweb-system/hsweb-system-workflow/hsweb-system-workflow-flowable/src/main/resources/META-INF/spring.factories

@@ -0,0 +1,3 @@
+# Auto Configure
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.hswebframework.web.workflow.flowable.FlowableAutoConfiguration