首页>代码>工作流activiti-explorer在线设计器的整合 适合大多数自定义工作流流程审批系统>/activiti-explorer/src/main/java/org/activiti/explorer/conf/ActivitiEngineConfiguration.java
package org.activiti.explorer.conf;

import java.sql.Driver;
import java.util.ArrayList;
import java.util.List;

import javax.sql.DataSource;

import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ManagementService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.form.AbstractFormType;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.explorer.form.MonthFormType;
import org.activiti.explorer.form.ProcessDefinitionFormType;
import org.activiti.explorer.form.UserFormType;
import org.activiti.spring.ProcessEngineFactoryBean;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.transaction.PlatformTransactionManager;

@Configuration
public class ActivitiEngineConfiguration {

  private final Logger log = LoggerFactory.getLogger(ActivitiEngineConfiguration.class);
  
  @Autowired
  protected Environment environment;
  
  @Bean
  public DataSource dataSource() { 
    SimpleDriverDataSource ds = new SimpleDriverDataSource();
    
    try {
      @SuppressWarnings("unchecked")
      Class<? extends Driver> driverClass = (Class<? extends Driver>) Class.forName(environment.getProperty("jdbc.driver", "org.h2.Driver"));
      ds.setDriverClass(driverClass);
      
    } catch (Exception e) {
      log.error("Error loading driver class", e);
    }
    
    // Connection settings
    ds.setUrl(environment.getProperty("jdbc.url", "jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"));
    ds.setUsername(environment.getProperty("jdbc.username", "sa"));
    ds.setPassword(environment.getProperty("jdbc.password", ""));
    
    return ds;
  }

  @Bean(name = "transactionManager")
  public PlatformTransactionManager annotationDrivenTransactionManager() {
    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
    transactionManager.setDataSource(dataSource());
    return transactionManager;
  }
  
  @Bean(name="processEngineFactoryBean")
  public ProcessEngineFactoryBean processEngineFactoryBean() {
    ProcessEngineFactoryBean factoryBean = new ProcessEngineFactoryBean();
    factoryBean.setProcessEngineConfiguration(processEngineConfiguration());
    return factoryBean;
  }
  
  @Bean(name="processEngine")
  public ProcessEngine processEngine() {
    // Safe to call the getObject() on the @Bean annotated processEngineFactoryBean(), will be
    // the fully initialized object instanced from the factory and will NOT be created more than once
    try {
      return processEngineFactoryBean().getObject();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  
  @Bean(name="processEngineConfiguration")
  public ProcessEngineConfigurationImpl processEngineConfiguration() {
  	SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
  	processEngineConfiguration.setDataSource(dataSource());
  	processEngineConfiguration.setDatabaseSchemaUpdate(environment.getProperty("engine.schema.update", "true"));
  	processEngineConfiguration.setTransactionManager(annotationDrivenTransactionManager());
  	processEngineConfiguration.setJobExecutorActivate(Boolean.valueOf(
  	    environment.getProperty("engine.activate.jobexecutor", "false")));
  	processEngineConfiguration.setAsyncExecutorEnabled(Boolean.valueOf(
        environment.getProperty("engine.asyncexecutor.enabled", "true")));
  	processEngineConfiguration.setAsyncExecutorActivate(Boolean.valueOf(
        environment.getProperty("engine.asyncexecutor.activate", "true")));
  	processEngineConfiguration.setHistory(environment.getProperty("engine.history.level", "full"));
  	
  	String mailEnabled = environment.getProperty("engine.email.enabled");
  	if ("true".equals(mailEnabled)) {
  	  processEngineConfiguration.setMailServerHost(environment.getProperty("engine.email.host"));
  	  int emailPort = 1025;
  	  String emailPortProperty = environment.getProperty("engine.email.port");
  	  if (StringUtils.isNotEmpty(emailPortProperty)) {
  	    emailPort = Integer.valueOf(emailPortProperty);
  	  }
  	  processEngineConfiguration.setMailServerPort(emailPort);
  	  String emailUsernameProperty = environment.getProperty("engine.email.username");
  	  if (StringUtils.isNotEmpty(emailUsernameProperty)) {
  	    processEngineConfiguration.setMailServerUsername(emailUsernameProperty);
  	  }
  	  
  	  String emailPasswordProperty = environment.getProperty("engine.email.password");
      if (StringUtils.isNotEmpty(emailPasswordProperty)) {
        processEngineConfiguration.setMailServerPassword(emailPasswordProperty);
      }
  	}
  	
  	List<AbstractFormType> formTypes = new ArrayList<AbstractFormType>();
  	formTypes.add(new UserFormType());
  	formTypes.add(new ProcessDefinitionFormType());
  	formTypes.add(new MonthFormType());
  	processEngineConfiguration.setCustomFormTypes(formTypes);
  	
  	return processEngineConfiguration;
  }
  
  @Bean
  public RepositoryService repositoryService() {
  	return processEngine().getRepositoryService();
  }
  
  @Bean
  public RuntimeService runtimeService() {
  	return processEngine().getRuntimeService();
  }
  
  @Bean
  public TaskService taskService() {
  	return processEngine().getTaskService();
  }
  
  @Bean
  public HistoryService historyService() {
  	return processEngine().getHistoryService();
  }
  
  @Bean
  public FormService formService() {
  	return processEngine().getFormService();
  }
  
  @Bean
  public IdentityService identityService() {
  	return processEngine().getIdentityService();
  }
  
  @Bean
  public ManagementService managementService() {
  	return processEngine().getManagementService();
  }
}
最近下载更多
whfuai  LV14 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日
最近浏览更多
whfuai  LV14 9月28日
HANCW  LV9 8月20日
云破月  LV8 4月12日
denglu123321  LV4 4月11日
Gin19960217  LV4 3月5日
1049066887  LV13 3月3日
weilaizhisheng  LV21 1月16日
zhong8876  LV1 2023年11月29日
yuan_bin1990  LV7 2023年11月13日
3334004690  LV10 2023年11月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友