Search in sources :

Example 46 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 47 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 48 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 49 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)

Example 50 with RuntimeService

use of org.activiti.engine.RuntimeService in project crnk-framework by crnk-project.

the class ApprovalManagerTest method setup.

@Before
public void setup() {
    runtimeService = Mockito.mock(RuntimeService.class);
    TaskService taskService = Mockito.mock(TaskService.class);
    repositoryFacade = Mockito.mock(ResourceRepositoryV2.class);
    ApprovalMapper approvalMapper = new ApprovalMapper();
    ActivitiResourceMapper resourceMapper = new ActivitiResourceMapper(new TypeParser(), new DefaultDateTimeMapper());
    ResourceInformation information = Mockito.mock(ResourceInformation.class);
    registryEntry = Mockito.mock(RegistryEntry.class);
    ResourceRegistry resourceRegistry = Mockito.mock(ResourceRegistry.class);
    Mockito.when(registryEntry.getResourceInformation()).thenReturn(information);
    Mockito.when(registryEntry.getResourceRepositoryFacade()).thenReturn(repositoryFacade);
    Mockito.when(information.getResourceType()).thenReturn("schedule");
    Mockito.when(information.getId(Mockito.any())).thenReturn(mockId);
    Mockito.when(resourceRegistry.getEntry(Mockito.any(Class.class))).thenReturn(registryEntry);
    Mockito.when(resourceRegistry.getEntry(Mockito.any(String.class))).thenReturn(registryEntry);
    ModuleRegistry moduleRegistry = Mockito.mock(ModuleRegistry.class);
    Mockito.when(moduleRegistry.getResourceRegistry()).thenReturn(resourceRegistry);
    originalResource = new Schedule();
    originalResource.setId(mockId);
    originalResource.setName("Jane");
    Mockito.when(repositoryFacade.findOne(Mockito.any(Long.class), Mockito.any(QuerySpec.class))).thenReturn(originalResource);
    manager = new ApprovalManager();
    manager.init(runtimeService, taskService, resourceMapper, approvalMapper, moduleRegistry);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) TypeParser(io.crnk.core.engine.parser.TypeParser) RuntimeService(org.activiti.engine.RuntimeService) ActivitiResourceMapper(io.crnk.activiti.mapper.ActivitiResourceMapper) TaskService(org.activiti.engine.TaskService) DefaultDateTimeMapper(io.crnk.activiti.mapper.DefaultDateTimeMapper) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ApprovalManager(io.crnk.activiti.example.approval.ApprovalManager) Schedule(io.crnk.test.mock.models.Schedule) QuerySpec(io.crnk.core.queryspec.QuerySpec) ApprovalMapper(io.crnk.activiti.example.approval.ApprovalMapper) Before(org.junit.Before)

Aggregations

RuntimeService (org.activiti.engine.RuntimeService)77 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)32 ProcessEngine (org.activiti.engine.ProcessEngine)16 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)15 Test (org.junit.Test)14 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)14 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)13 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)12 RepositoryService (org.activiti.engine.RepositoryService)10 TaskService (org.activiti.engine.TaskService)10 HashMap (java.util.HashMap)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 ArrayList (java.util.ArrayList)7 Path (javax.ws.rs.Path)7 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)7 Execution (org.activiti.engine.runtime.Execution)7 Produces (javax.ws.rs.Produces)6 Task (org.activiti.engine.task.Task)6 BPMNInstance (org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance)6 ActivitiException (org.activiti.engine.ActivitiException)5