Search in sources :

Example 1 with ProcessEngineConfiguration

use of org.flowable.engine.ProcessEngineConfiguration 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)

Example 2 with ProcessEngineConfiguration

use of org.flowable.engine.ProcessEngineConfiguration in project plumdo-work by wengwh.

the class SaveModelEditorCmd method execute.

@Override
public Void execute(CommandContext commandContext) {
    ProcessEngineConfiguration processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
    RepositoryService repositoryService = processEngineConfiguration.getRepositoryService();
    try {
        byte[] bytes = editorJson.getBytes("utf-8");
        repositoryService.addModelEditorSource(modelId, bytes);
        ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(bytes);
        BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
        BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
        byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
        XMLInputFactory xif = XMLInputFactory.newInstance();
        InputStreamReader xmlIn = new InputStreamReader(new ByteArrayInputStream(bpmnBytes), "UTF-8");
        XMLStreamReader xtr = xif.createXMLStreamReader(xmlIn);
        bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
        ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
        InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", Collections.emptyList(), Collections.emptyList(), processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader(), 1.0);
        repositoryService.addModelEditorSourceExtra(modelId, IOUtils.toByteArray(resource));
    } catch (Exception e) {
        throw new FlowableException("create model exception :" + e.getMessage());
    }
    return null;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FlowableException(org.flowable.engine.common.api.FlowableException) BpmnModel(org.flowable.bpmn.model.BpmnModel) BpmnXMLConverter(org.flowable.bpmn.converter.BpmnXMLConverter) FlowableException(org.flowable.engine.common.api.FlowableException) ProcessEngineConfiguration(org.flowable.engine.ProcessEngineConfiguration) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessDiagramGenerator(org.flowable.image.ProcessDiagramGenerator) BpmnJsonConverter(org.flowable.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XMLInputFactory(javax.xml.stream.XMLInputFactory) RepositoryService(org.flowable.engine.RepositoryService)

Aggregations

ProcessEngineConfiguration (org.flowable.engine.ProcessEngineConfiguration)2 RepositoryService (org.flowable.engine.RepositoryService)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 LinkedHashMap (java.util.LinkedHashMap)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 BpmnXMLConverter (org.flowable.bpmn.converter.BpmnXMLConverter)1 BpmnModel (org.flowable.bpmn.model.BpmnModel)1 BpmnJsonConverter (org.flowable.editor.language.json.converter.BpmnJsonConverter)1 HistoryService (org.flowable.engine.HistoryService)1 ProcessEngine (org.flowable.engine.ProcessEngine)1 RuntimeService (org.flowable.engine.RuntimeService)1 TaskService (org.flowable.engine.TaskService)1 FlowableException (org.flowable.engine.common.api.FlowableException)1 HistoricActivityInstance (org.flowable.engine.history.HistoricActivityInstance)1 Deployment (org.flowable.engine.repository.Deployment)1