Search in sources :

Example 16 with RuntimeService

use of org.activiti.engine.RuntimeService in project Activiti by Activiti.

the class MuleHttpTest method http.

@Test
public void http() throws Exception {
    Assert.assertTrue(muleContext.isStarted());
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    Deployment deployment = processEngine.getRepositoryService().createDeployment().addClasspathResource("org/activiti/mule/testHttp.bpmn20.xml").deploy();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
    Assert.assertFalse(processInstance.isEnded());
    Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
    Assert.assertEquals(20, result);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
    processEngine.getRepositoryService().deleteDeployment(deployment.getId());
    assertAndEnsureCleanDb(processEngine);
    ProcessEngines.destroy();
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) Deployment(org.activiti.engine.repository.Deployment) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngine(org.activiti.engine.ProcessEngine) Test(org.junit.Test)

Example 17 with RuntimeService

use of org.activiti.engine.RuntimeService in project midpoint by Evolveum.

the class ProcessInstanceManager method cleanupActivitiProcesses.

public void cleanupActivitiProcesses(OperationResult result) throws SchemaException {
    RuntimeService runtimeService = activitiEngine.getRuntimeService();
    TaskService taskService = activitiEngine.getTaskService();
    LOGGER.info("Starting cleanup of Activiti processes");
    Collection<String> processInstancesToKeep = getProcessInstancesToKeep(result);
    LOGGER.info("Process instances to keep: {}", processInstancesToKeep);
    List<ProcessInstance> instances = runtimeService.createProcessInstanceQuery().list();
    LOGGER.info("Existing process instances in Activiti: {}", instances.size());
    int ok = 0, fail = 0;
    for (ProcessInstance instance : instances) {
        String instanceId = instance.getId();
        if (processInstancesToKeep.contains(instanceId)) {
            continue;
        }
        LOGGER.debug("Deleting process instance {}", instance);
        try {
            runtimeService.setVariable(instanceId, CommonProcessVariableNames.VARIABLE_PROCESS_INSTANCE_IS_STOPPING, Boolean.TRUE);
            runtimeService.deleteProcessInstance(instanceId, "Deleted as part of activiti processes cleanup");
            ok++;
        } catch (Throwable t) {
            LOGGER.info("Couldn't delete process instance {}, retrying with explicit deletion of some variables for its tasks", instanceId);
            List<org.activiti.engine.task.Task> tasks = taskService.createTaskQuery().processInstanceId(instanceId).list();
            LOGGER.debug("Tasks: {}", tasks);
            for (org.activiti.engine.task.Task task : tasks) {
                taskService.removeVariables(task.getId(), Arrays.asList("approvalSchema", "level"));
            }
            try {
                runtimeService.deleteProcessInstance(instanceId, "Deleted as part of activiti processes cleanup");
                ok++;
            } catch (Throwable t2) {
                result.createSubresult(ProcessInstanceManager.class.getName() + ".cleanupActivitiProcess").recordPartialError("Couldn't delete Activiti process instance " + instanceId + ": " + t2.getMessage(), t2);
                fail++;
            }
        }
    }
    String message = "Successfully deleted " + ok + " instances; failed " + fail + " times";
    LOGGER.info(message);
    result.recordStatus(fail > 0 ? OperationResultStatus.PARTIAL_ERROR : OperationResultStatus.SUCCESS, message);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RuntimeService(org.activiti.engine.RuntimeService) TaskService(org.activiti.engine.TaskService) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SearchResultList(com.evolveum.midpoint.schema.SearchResultList)

Example 18 with RuntimeService

use of org.activiti.engine.RuntimeService in project midpoint by Evolveum.

the class DumpVariables method execute.

public void execute(DelegateExecution execution) {
    if (LOGGER.isTraceEnabled()) {
        RuntimeService runtimeService = execution.getEngineServices().getRuntimeService();
        Set<String> variablesSeen = new HashSet<>();
        LOGGER.trace("--------------------------------- DumpVariables: " + execution.getCurrentActivityId());
        //			LOGGER.trace("All variables for execution id={}, parent id={}", execution.getId(), execution.getParentId());
        //            execution.getVariableInstances().forEach((n, v) -> LOGGER.trace(" - {} = {} (in {})", n, v.getValue(), v.getExecutionId()));
        LOGGER.trace("Execution hierarchy for id={}", execution.getId());
        LOGGER.trace("------------------------------------");
        dumpExecutionVariables(execution.getId(), execution, null, variablesSeen, runtimeService);
        Collection<String> disjunction = CollectionUtils.disjunction(variablesSeen, execution.getVariableNames());
        if (!disjunction.isEmpty()) {
            LOGGER.trace("*** Variables not found in execution tree or 'execution.getVariableNames()': {}", disjunction);
        }
        LOGGER.trace("--------------------------------- DumpVariables: " + execution.getCurrentActivityId() + " END ------------");
    }
}
Also used : RuntimeService(org.activiti.engine.RuntimeService)

Example 19 with RuntimeService

use of org.activiti.engine.RuntimeService in project bamboobsc by billchen198318.

the class TestBPMN001 method startProcess.

@Test
public void startProcess() throws Exception {
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("confirmPublish", "N");
    String processId = "Employee360DegreeFeedbackProjectPublishProcess";
    RuntimeService runtimeService = (RuntimeService) AppContext.getBean("runtimeService");
    ProcessInstance process = runtimeService.startProcessInstanceByKey(processId, paramMap);
    System.out.println("DeploymentId: " + process.getDeploymentId());
    System.out.println("ActivityId: " + process.getActivityId());
    System.out.println("Name: " + process.getName());
    System.out.println("ProcessDefinitionId: " + process.getProcessDefinitionId());
    System.out.println("ProcessDefinitionKey: " + process.getProcessDefinitionKey());
    System.out.println("ProcessDefinitionName: " + process.getProcessDefinitionName());
    System.out.println("BusinessKey: " + process.getBusinessKey());
}
Also used : HashMap(java.util.HashMap) RuntimeService(org.activiti.engine.RuntimeService) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Test(org.junit.Test)

Aggregations

RuntimeService (org.activiti.engine.RuntimeService)19 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 Test (org.junit.Test)9 ProcessEngine (org.activiti.engine.ProcessEngine)6 TaskService (org.activiti.engine.TaskService)6 Task (org.activiti.engine.task.Task)5 HashMap (java.util.HashMap)4 RepositoryService (org.activiti.engine.RepositoryService)4 Deployment (org.activiti.engine.repository.Deployment)3 ReplaySimulationRun (org.activiti.crystalball.simulator.ReplaySimulationRun)2 SimulationDebugger (org.activiti.crystalball.simulator.SimulationDebugger)2 ManagementService (org.activiti.engine.ManagementService)2 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)2 StandaloneProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration)2 NoExecutionVariableScope (org.activiti.engine.impl.el.NoExecutionVariableScope)2 Deployment (org.activiti.engine.test.Deployment)2 SearchResultList (com.evolveum.midpoint.schema.SearchResultList)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 Map (java.util.Map)1