首页>代码>工作流activiti-explorer在线设计器的整合 适合大多数自定义工作流流程审批系统>/activiti-explorer/src/main/java/org/activiti/explorer/conf/ActivitiEngineConfiguration.java
001package org.activiti.explorer.conf;
002 
003import java.sql.Driver;
004import java.util.ArrayList;
005import java.util.List;
006 
007import javax.sql.DataSource;
008 
009import org.activiti.engine.FormService;
010import org.activiti.engine.HistoryService;
011import org.activiti.engine.IdentityService;
012import org.activiti.engine.ManagementService;
013import org.activiti.engine.ProcessEngine;
014import org.activiti.engine.RepositoryService;
015import org.activiti.engine.RuntimeService;
016import org.activiti.engine.TaskService;
017import org.activiti.engine.form.AbstractFormType;
018import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
019import org.activiti.explorer.form.MonthFormType;
020import org.activiti.explorer.form.ProcessDefinitionFormType;
021import org.activiti.explorer.form.UserFormType;
022import org.activiti.spring.ProcessEngineFactoryBean;
023import org.activiti.spring.SpringProcessEngineConfiguration;
024import org.apache.commons.lang3.StringUtils;
025import org.slf4j.Logger;
026import org.slf4j.LoggerFactory;
027import org.springframework.beans.factory.annotation.Autowired;
028import org.springframework.context.annotation.Bean;
029import org.springframework.context.annotation.Configuration;
030import org.springframework.core.env.Environment;
031import org.springframework.jdbc.datasource.DataSourceTransactionManager;
032import org.springframework.jdbc.datasource.SimpleDriverDataSource;
033import org.springframework.transaction.PlatformTransactionManager;
034 
035@Configuration
036public class ActivitiEngineConfiguration {
037 
038  private final Logger log = LoggerFactory.getLogger(ActivitiEngineConfiguration.class);
039   
040  @Autowired
041  protected Environment environment;
042   
043  @Bean
044  public DataSource dataSource() {
045    SimpleDriverDataSource ds = new SimpleDriverDataSource();
046     
047    try {
048      @SuppressWarnings("unchecked")
049      Class<? extends Driver> driverClass = (Class<? extends Driver>) Class.forName(environment.getProperty("jdbc.driver", "org.h2.Driver"));
050      ds.setDriverClass(driverClass);
051       
052    } catch (Exception e) {
053      log.error("Error loading driver class", e);
054    }
055     
056    // Connection settings
057    ds.setUrl(environment.getProperty("jdbc.url", "jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"));
058    ds.setUsername(environment.getProperty("jdbc.username", "sa"));
059    ds.setPassword(environment.getProperty("jdbc.password", ""));
060     
061    return ds;
062  }
063 
064  @Bean(name = "transactionManager")
065  public PlatformTransactionManager annotationDrivenTransactionManager() {
066    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
067    transactionManager.setDataSource(dataSource());
068    return transactionManager;
069  }
070   
071  @Bean(name="processEngineFactoryBean")
072  public ProcessEngineFactoryBean processEngineFactoryBean() {
073    ProcessEngineFactoryBean factoryBean = new ProcessEngineFactoryBean();
074    factoryBean.setProcessEngineConfiguration(processEngineConfiguration());
075    return factoryBean;
076  }
077   
078  @Bean(name="processEngine")
079  public ProcessEngine processEngine() {
080    // Safe to call the getObject() on the @Bean annotated processEngineFactoryBean(), will be
081    // the fully initialized object instanced from the factory and will NOT be created more than once
082    try {
083      return processEngineFactoryBean().getObject();
084    } catch (Exception e) {
085      throw new RuntimeException(e);
086    }
087  }
088   
089  @Bean(name="processEngineConfiguration")
090  public ProcessEngineConfigurationImpl processEngineConfiguration() {
091    SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
092    processEngineConfiguration.setDataSource(dataSource());
093    processEngineConfiguration.setDatabaseSchemaUpdate(environment.getProperty("engine.schema.update", "true"));
094    processEngineConfiguration.setTransactionManager(annotationDrivenTransactionManager());
095    processEngineConfiguration.setJobExecutorActivate(Boolean.valueOf(
096        environment.getProperty("engine.activate.jobexecutor", "false")));
097    processEngineConfiguration.setAsyncExecutorEnabled(Boolean.valueOf(
098        environment.getProperty("engine.asyncexecutor.enabled", "true")));
099    processEngineConfiguration.setAsyncExecutorActivate(Boolean.valueOf(
100        environment.getProperty("engine.asyncexecutor.activate", "true")));
101    processEngineConfiguration.setHistory(environment.getProperty("engine.history.level", "full"));
102     
103    String mailEnabled = environment.getProperty("engine.email.enabled");
104    if ("true".equals(mailEnabled)) {
105      processEngineConfiguration.setMailServerHost(environment.getProperty("engine.email.host"));
106      int emailPort = 1025;
107      String emailPortProperty = environment.getProperty("engine.email.port");
108      if (StringUtils.isNotEmpty(emailPortProperty)) {
109        emailPort = Integer.valueOf(emailPortProperty);
110      }
111      processEngineConfiguration.setMailServerPort(emailPort);
112      String emailUsernameProperty = environment.getProperty("engine.email.username");
113      if (StringUtils.isNotEmpty(emailUsernameProperty)) {
114        processEngineConfiguration.setMailServerUsername(emailUsernameProperty);
115      }
116       
117      String emailPasswordProperty = environment.getProperty("engine.email.password");
118      if (StringUtils.isNotEmpty(emailPasswordProperty)) {
119        processEngineConfiguration.setMailServerPassword(emailPasswordProperty);
120      }
121    }
122     
123    List<AbstractFormType> formTypes = new ArrayList<AbstractFormType>();
124    formTypes.add(new UserFormType());
125    formTypes.add(new ProcessDefinitionFormType());
126    formTypes.add(new MonthFormType());
127    processEngineConfiguration.setCustomFormTypes(formTypes);
128     
129    return processEngineConfiguration;
130  }
131   
132  @Bean
133  public RepositoryService repositoryService() {
134    return processEngine().getRepositoryService();
135  }
136   
137  @Bean
138  public RuntimeService runtimeService() {
139    return processEngine().getRuntimeService();
140  }
141   
142  @Bean
143  public TaskService taskService() {
144    return processEngine().getTaskService();
145  }
146   
147  @Bean
148  public HistoryService historyService() {
149    return processEngine().getHistoryService();
150  }
151   
152  @Bean
153  public FormService formService() {
154    return processEngine().getFormService();
155  }
156   
157  @Bean
158  public IdentityService identityService() {
159    return processEngine().getIdentityService();
160  }
161   
162  @Bean
163  public ManagementService managementService() {
164    return processEngine().getManagementService();
165  }
166}
最近下载更多
whfuai  LV14 2024年9月28日
wang_d  LV12 2023年12月9日
yuan_bin1990  LV7 2023年11月13日
Zy980920  LV5 2023年8月28日
woldxy  LV12 2023年8月22日
monan111  LV2 2023年5月14日
青山梓地  LV1 2023年1月9日
xindong  LV12 2022年6月24日
crosa_Don  LV18 2022年6月2日
buxiaonan  LV2 2022年5月10日
最近浏览更多
四小只by白丫头  LV3 2月17日
whfuai  LV14 2024年9月28日
HANCW  LV9 2024年8月20日
云破月  LV8 2024年4月12日
denglu123321  LV4 2024年4月11日
Gin19960217  LV4 2024年3月5日
1049066887  LV13 2024年3月3日
weilaizhisheng  LV21 2024年1月16日
zhong8876  LV1 2023年11月29日
yuan_bin1990  LV7 2023年11月13日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友