Package org.activiti.engine

Examples of org.activiti.engine.ProcessEngine


public class StartProcess {

  public static void main(String[] args) {
    ProcessEngines.init();   
    ProcessEngine processEngine = ProcessEngines.getProcessEngine(ProcessEngines.NAME_DEFAULT);   
      RuntimeService runtimeService = processEngine.getRuntimeService();
     
      Map<String,Object> variables = new HashMap<String,Object>();
      variables.put("test", "test");
     
      runtimeService.startProcessInstanceByKey("EasyBugFilingProcess", variables)
View Full Code Here


import org.activiti.engine.runtime.ProcessInstance;

public class Bmpn2Img {

  public static void main(String[] args) {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    RepositoryService repositoryService = processEngine.getRepositoryService();

    TaskService taskService = processEngine.getTaskService();
    ManagementService managementService = processEngine.getManagementService();
    IdentityService identityService = processEngine.getIdentityService();
    HistoryService historyService = processEngine.getHistoryService();
    FormService formService = processEngine.getFormService();

    Map<String, Object> variableMap = new HashMap<String, Object>();
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("MultitaskingProcess", variableMap);

    File f = new File("processInstanceImage.png");
View Full Code Here

            return Collections.emptyMap();
        }
    }

    public Void execute(CommandContext commandContext) {
        ProcessEngine processEngine = getProcessEngine();
        FormTemplateManager formTemplateManager = getFormTemplateManager();
        KeyValue keyValue = getKeyValue();
        String taskId = getParameter(OPERATION_TASK_ID);

        TaskService taskService = processEngine.getTaskService();
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();

        // 处理抄送任务
        if ("copy".equals(task.getCategory())) {
            new DeleteTaskWithCommentCmd(taskId, "已阅").execute(commandContext);

            return null;
        }

        // 先保存草稿
        new SaveDraftOperation().execute(getParameters());

        // 先设置登录用户
        IdentityService identityService = processEngine.getIdentityService();
        identityService.setAuthenticatedUserId(SpringSecurityUtils
                .getCurrentUsername());

        if (task == null) {
            throw new IllegalStateException("任务不存在");
        }

        logger.info("{}", task.getDelegationState());

        // 处理委办任务
        if (DelegationState.PENDING == task.getDelegationState()) {
            taskService.resolveTask(taskId);

            return null;
        }

        // 处理子任务
        if ("subtask".equals(task.getCategory())) {
            new DeleteTaskWithCommentCmd(taskId, "完成").execute(commandContext);

            int count = getJdbcTemplate().queryForObject(
                    "select count(*) from ACT_RU_TASK where PARENT_TASK_ID_=?",
                    Integer.class, task.getParentTaskId());

            if (count > 1) {
                return null;
            }

            taskId = task.getParentTaskId();
        }

        FormService formService = processEngine.getFormService();
        String taskFormKey = formService.getTaskFormKey(
                task.getProcessDefinitionId(), task.getTaskDefinitionKey());
        FormInfo formInfo = new FormInfo();
        formInfo.setTaskId(taskId);
        formInfo.setFormKey(taskFormKey);
View Full Code Here

            return Collections.emptyMap();
        }
    }

    public Void execute(CommandContext commandContext) {
        ProcessEngine processEngine = getProcessEngine();
        FormTemplateManager formTemplateManager = getFormTemplateManager();
        KeyValue keyValue = getKeyValue();
        String bpmProcessId = getParameter(OPERATION_BPM_PROCESS_ID);
        BpmProcess bpmProcess = getBpmProcessManager().get(
                Long.parseLong(bpmProcessId));
        String processDefinitionId = bpmProcess.getBpmConfBase()
                .getProcessDefinitionId();

        // 先保存草稿
        String businessKey = new ConfAssigneeOperation()
                .execute(getParameters());

        // 先设置登录用户
        IdentityService identityService = processEngine.getIdentityService();
        identityService.setAuthenticatedUserId(SpringSecurityUtils
                .getCurrentUserId());

        // 获得form的信息
        FormInfo formInfo = new FindStartFormCmd(processDefinitionId)
                .execute(commandContext);

        // 尝试根据表单里字段的类型,进行转换
        Map<String, String> formTypeMap = new HashMap<String, String>();

        if (formInfo.isFormExists()) {
            FormTemplate formTemplate = formTemplateManager.findUniqueBy(
                    "code", formInfo.getFormKey());

            String content = formTemplate.getContent();
            formTypeMap = this.fetchFormTypeMap(content);
        }

        Record record = keyValue.findByCode(businessKey);

        Map<String, Object> processParameters = new HashMap<String, Object>();

        // 如果有表单,就从数据库获取数据
        for (Prop prop : record.getProps().values()) {
            String key = prop.getCode();
            String value = prop.getValue();
            String formType = this.getFormType(formTypeMap, key);

            if ("userpicker".equals(formType)) {
                processParameters.put(key,
                        new ArrayList(Arrays.asList(value.split(","))));
            } else if (formType != null) {
                processParameters.put(key, value);
            }
        }

        ProcessInstance processInstance = processEngine.getRuntimeService()
                .startProcessInstanceById(processDefinitionId, businessKey,
                        processParameters);
        record = new RecordBuilder().build(record, STATUS_RUNNING,
                processInstance.getId());
        keyValue.save(record);
View Full Code Here

    private Map<String, String[]> parameters;

    public T execute(Map<String, String[]> parameters) {
        this.parameters = parameters;

        ProcessEngine processEngine = getProcessEngine();

        return processEngine.getManagementService().executeCommand(this);
    }
View Full Code Here

        jobExecutor.setQueueSize(2);
        jobExecutor.setMaxJobsPerAcquisition(5);
        jobExecutor.setWaitTimeInMillis(50);
        jobExecutor.setLockTimeInMillis(180000);

        ProcessEngine processEngine = new StandaloneInMemProcessEngineConfiguration()
            .setJobExecutorActivate(true)
            .setJobExecutor(jobExecutor)
            .setFailedJobCommandFactory(new ConfigurableFailedJobCommandFactory(2, 1))
            .buildProcessEngine();

        processEngine.getRepositoryService().createDeployment()
            .addClasspathResource("diagrams/alwaysFail.bpmn20.xml").deploy();

        Stopwatch stopwatch = new Stopwatch().start();
        processEngine.getRuntimeService().startProcessInstanceByKey("alwaysFail");

        while (AlwaysFailTask.COUNTER.get() != 3 /* = 1 normal execution + 2 retries */) {
            TimeUnit.MILLISECONDS.sleep(100);
        }

        stopwatch.stop();
        assertThat(stopwatch.elapsedTime(TimeUnit.SECONDS)).isGreaterThanOrEqualTo(2);

        processEngine.close();
    }
View Full Code Here

        when(execution.getVariable(eq(CoreProcessVariables.MACHINES))).thenReturn(machines);

        ProcessVariablesCollector collector = new ProcessVariablesCollector();
        collector.install(execution);

        ProcessEngine processEngine = new StandaloneInMemProcessEngineConfiguration()
            .setJobExecutorActivate(true).buildProcessEngine();
        processEngine.getRepositoryService().createDeployment()
            .addClasspathResource("diagrams/empty.bpmn20.xml").deploy();

        try {
            JavaDelegate delegate = new SpawnProcessForEachMachine(processEngine, EMPTY_PROCESS_KEY, "test", RESULT);
            delegate.execute(execution);

            @SuppressWarnings("unchecked")
            List<String> processInstanceIds = (List<String>) collector.getVariable(RESULT);

            assertThat(processInstanceIds).hasSize(2);

        } finally {
            processEngine.close();
        }
    }
View Full Code Here

     *
     * @param processKey
     * @throws InterruptedException
     */
    public void waitForProcessDeployment(String processKey) throws InterruptedException, TimeoutException {
        ProcessEngine engine = getOsgiService(ProcessEngine.class, 5000);
        int iteration = 0;
        while (iteration < 10) {
            ProcessDefinition definition = engine.getRepositoryService()
                .createProcessDefinitionQuery()
                .processDefinitionKey(processKey).singleResult();
            if (definition != null) {
                break;
            }
View Full Code Here

        ProcessInstance localInstance = getProcessInstanceById(processInstanceId);
        return localInstance != null && !localInstance.isEnded();
    }

    private ProcessInstance getProcessInstanceById(final String processInstanceId) throws InterruptedException {
        ProcessEngine engine = getOsgiService(ProcessEngine.class, 5000);
        return engine.getRuntimeService().createProcessInstanceQuery()
            .processInstanceId(processInstanceId)
            .singleResult();
    }
View Full Code Here

        multiValued = true, description = "Signal all activities in a process instances")
    private String[] activities;

    @Override
    protected Object doExecute() throws Exception {
        ProcessEngine engine = this.getProcessEngine();
        if (engine == null) {
            out().println("Process Engine NOT Found!");
            return null;
        }
        RuntimeService runtimeService = engine.getRuntimeService();

        if (this.instanceIDs != null && this.instanceIDs.length > 0) {
            for (String instanceID : this.instanceIDs) {
                signal(runtimeService, instanceID, this.activities);
            }
View Full Code Here

TOP

Related Classes of org.activiti.engine.ProcessEngine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.