Search in sources :

Example 1 with ProcessEngine

use of org.flowable.engine.ProcessEngine in project syncope by apache.

the class DomainProcessEngineFactoryBean method getObject.

@Override
public DomainProcessEngine getObject() throws Exception {
    if (engine == null) {
        Map<String, ProcessEngine> engines = new HashMap<>();
        ctx.getBeansOfType(DataSource.class).entrySet().stream().filter(entry -> (!entry.getKey().startsWith("local"))).forEachOrdered(entry -> {
            String domain = StringUtils.substringBefore(entry.getKey(), DataSource.class.getSimpleName());
            DataSource dataSource = entry.getValue();
            PlatformTransactionManager transactionManager = ctx.getBean(domain + "TransactionManager", PlatformTransactionManager.class);
            Object entityManagerFactory = ctx.getBean(domain + "EntityManagerFactory");
            SpringProcessEngineConfiguration conf = ctx.getBean(SpringProcessEngineConfiguration.class);
            conf.setDataSource(dataSource);
            conf.setTransactionManager(transactionManager);
            conf.setTransactionsExternallyManaged(true);
            conf.setJpaEntityManagerFactory(entityManagerFactory);
            if (conf.getBeans() == null) {
                conf.setBeans(new SpringBeanFactoryProxyMap(ctx));
            }
            if (conf.getExpressionManager() == null) {
                conf.setExpressionManager(new SpringExpressionManager(ctx, conf.getBeans()));
            }
            if (EngineServiceUtil.getIdmEngineConfiguration(conf) == null) {
                conf.addEngineConfiguration(EngineConfigurationConstants.KEY_IDM_ENGINE_CONFIG, ctx.getBean(SpringIdmEngineConfiguration.class));
            }
            engines.put(domain, conf.buildProcessEngine());
        });
        engine = new DomainProcessEngine(engines);
    }
    return engine;
}
Also used : EngineServiceUtil(org.flowable.engine.impl.util.EngineServiceUtil) EngineConfigurationConstants(org.flowable.engine.common.impl.interceptor.EngineConfigurationConstants) HashMap(java.util.HashMap) BeansException(org.springframework.beans.BeansException) StringUtils(org.apache.commons.lang3.StringUtils) ProcessEngine(org.flowable.engine.ProcessEngine) ApplicationContext(org.springframework.context.ApplicationContext) SpringIdmEngineConfiguration(org.flowable.idm.spring.SpringIdmEngineConfiguration) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) SpringBeanFactoryProxyMap(org.flowable.engine.common.impl.cfg.SpringBeanFactoryProxyMap) FactoryBean(org.springframework.beans.factory.FactoryBean) SpringExpressionManager(org.flowable.spring.SpringExpressionManager) Map(java.util.Map) DisposableBean(org.springframework.beans.factory.DisposableBean) DataSource(javax.sql.DataSource) SpringProcessEngineConfiguration(org.flowable.spring.SpringProcessEngineConfiguration) ApplicationContextAware(org.springframework.context.ApplicationContextAware) HashMap(java.util.HashMap) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) DataSource(javax.sql.DataSource) SpringIdmEngineConfiguration(org.flowable.idm.spring.SpringIdmEngineConfiguration) SpringBeanFactoryProxyMap(org.flowable.engine.common.impl.cfg.SpringBeanFactoryProxyMap) SpringProcessEngineConfiguration(org.flowable.spring.SpringProcessEngineConfiguration) SpringExpressionManager(org.flowable.spring.SpringExpressionManager) ProcessEngine(org.flowable.engine.ProcessEngine)

Example 2 with ProcessEngine

use of org.flowable.engine.ProcessEngine in project syncope by apache.

the class FlowableDefinitionLoader method load.

@Override
public void load() {
    byte[] wfDef = new byte[0];
    try (InputStream wfIn = userWorkflowDef.getResource().getInputStream()) {
        wfDef = IOUtils.toByteArray(wfIn);
    } catch (IOException e) {
        LOG.error("While loading " + userWorkflowDef.getResource().getFilename(), e);
    }
    for (Map.Entry<String, ProcessEngine> entry : dpEngine.getEngines().entrySet()) {
        List<ProcessDefinition> processes = entry.getValue().getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(FlowableUserWorkflowAdapter.WF_PROCESS_ID).list();
        LOG.debug(FlowableUserWorkflowAdapter.WF_PROCESS_ID + " Flowable processes in repository: {}", processes);
        // Only loads process definition from file if not found in repository
        if (processes.isEmpty()) {
            entry.getValue().getRepositoryService().createDeployment().addInputStream(userWorkflowDef.getResource().getFilename(), new ByteArrayInputStream(wfDef)).deploy();
            ProcessDefinition procDef = entry.getValue().getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(FlowableUserWorkflowAdapter.WF_PROCESS_ID).latestVersion().singleResult();
            FlowableDeployUtils.deployModel(entry.getValue(), procDef);
            LOG.debug("Flowable Workflow definition loaded for domain {}", entry.getKey());
        }
        // jump to the next ID block
        for (int i = 0; i < entry.getValue().getProcessEngineConfiguration().getIdBlockSize(); i++) {
            SpringProcessEngineConfiguration.class.cast(entry.getValue().getProcessEngineConfiguration()).getIdGenerator().getNextId();
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) IOException(java.io.IOException) Map(java.util.Map) ProcessEngine(org.flowable.engine.ProcessEngine) DomainProcessEngine(org.apache.syncope.core.workflow.flowable.spring.DomainProcessEngine)

Example 3 with ProcessEngine

use of org.flowable.engine.ProcessEngine in project yyl_example by Relucent.

the class FlowableExample method main.

public static void main(String[] args) {
    System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
    ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("yyl/example/demo/flowable/flowable.cfg.xml");
    // configuration.setJdbcUrl("jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000");
    // configuration.setJdbcDriver("org.h2.Driver");
    // configuration.setJdbcUsername("sa");
    // configuration.setJdbcPassword("");
    // configuration.setDatabaseSchemaUpdate("true");
    // configuration.setAsyncExecutorActivate(false);
    // configuration.setMailServerHost("localhost");
    // configuration.setMailServerPort(25);
    // 创建流程引擎
    ProcessEngine processEngine = configuration.buildProcessEngine();
    // 创建了一个新的部署
    RepositoryService repositoryService = processEngine.getRepositoryService();
    Deployment deployment = // 
    repositoryService.createDeployment().addClasspathResource(// 
    "yyl/example/demo/flowable/holiday-request.bpmn20.xml").deploy();
    // 部署流程定义
    ProcessDefinition processDefinition = // 
    repositoryService.createProcessDefinitionQuery().deploymentId(// 
    deployment.getId()).singleResult();
    System.out.println("Found process definition : " + processDefinition.getName());
    // 参数传递
    Map<String, Object> variables = new LinkedHashMap<String, Object>();
    System.out.println("Enter employee:");
    variables.put("employee", SCANNER.nextLine());
    System.out.println("Enter holidays:");
    variables.put("holidays", SCANNER.nextLine());
    RuntimeService runtimeService = processEngine.getRuntimeService();
    // 通过RuntimeService启动流程实例
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holidayRequest", variables);
    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("managers").list();
    System.out.println("You have " + tasks.size() + " tasks:");
    for (int i = 0; i < tasks.size(); i++) {
        System.out.println((i + 1) + ") " + tasks.get(i).getName());
    }
    // 获取特定的流程实例变量
    System.out.println("Which task would you like to complete?");
    int taskIndex = Integer.valueOf(SCANNER.nextLine());
    Task task = tasks.get(taskIndex - 1);
    Map<String, Object> processVariables = taskService.getVariables(task.getId());
    System.out.println(processVariables);
    // 完成任务,传递排他网关条件
    boolean approved = SCANNER.nextLine().toLowerCase().equals("y");
    variables = new LinkedHashMap<String, Object>();
    variables.put("approved", approved);
    taskService.complete(task.getId(), variables);
    // 查询完成的活动,按结束时间排序
    HistoryService historyService = processEngine.getHistoryService();
    List<HistoricActivityInstance> activities = // 
    historyService.createHistoricActivityInstanceQuery().processInstanceId(// 
    processInstance.getId()).finished().orderByHistoricActivityInstanceEndTime().asc().list();
    for (HistoricActivityInstance activity : activities) {
        System.out.println(activity.getActivityId() + " took " + activity.getDurationInMillis() + " milliseconds");
    }
}
Also used : Task(org.flowable.task.api.Task) RuntimeService(org.flowable.engine.RuntimeService) TaskService(org.flowable.engine.TaskService) Deployment(org.flowable.engine.repository.Deployment) HistoryService(org.flowable.engine.HistoryService) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) LinkedHashMap(java.util.LinkedHashMap) ProcessEngineConfiguration(org.flowable.engine.ProcessEngineConfiguration) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ProcessEngine(org.flowable.engine.ProcessEngine) RepositoryService(org.flowable.engine.RepositoryService) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance)

Aggregations

ProcessEngine (org.flowable.engine.ProcessEngine)3 Map (java.util.Map)2 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 DataSource (javax.sql.DataSource)1 StringUtils (org.apache.commons.lang3.StringUtils)1 DomainProcessEngine (org.apache.syncope.core.workflow.flowable.spring.DomainProcessEngine)1 HistoryService (org.flowable.engine.HistoryService)1 ProcessEngineConfiguration (org.flowable.engine.ProcessEngineConfiguration)1 RepositoryService (org.flowable.engine.RepositoryService)1 RuntimeService (org.flowable.engine.RuntimeService)1 TaskService (org.flowable.engine.TaskService)1 SpringBeanFactoryProxyMap (org.flowable.engine.common.impl.cfg.SpringBeanFactoryProxyMap)1 EngineConfigurationConstants (org.flowable.engine.common.impl.interceptor.EngineConfigurationConstants)1 HistoricActivityInstance (org.flowable.engine.history.HistoricActivityInstance)1 EngineServiceUtil (org.flowable.engine.impl.util.EngineServiceUtil)1