Java Code Examples for org.flowable.engine.runtime.ProcessInstance#getProcessVariables()

The following examples show how to use org.flowable.engine.runtime.ProcessInstance#getProcessVariables() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestQueryWithIncludeVariabesTaskListener.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();

    ProcessInstance processInstance = processEngineConfiguration.getRuntimeService().createProcessInstanceQuery()
        .processInstanceId(delegateTask.getProcessInstanceId())
        .includeProcessVariables()
        .singleResult();
    PROCESS_INSTANCE_VARIABLES = processInstance.getProcessVariables();

    Task task = processEngineConfiguration.getTaskService().createTaskQuery()
        .taskId(delegateTask.getId())
        .includeProcessVariables()
        .singleResult();
    TASK_VARIABLES = task.getProcessVariables();

    TASK_LOCAL_VARIABLES = task.getTaskLocalVariables();

}
 
Example 2
Source File: DmnTaskTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {
        "org/flowable/bpmn/test/runtime/DmnTaskTest.oneDecisionTaskProcess.bpmn20.xml",
        "org/flowable/bpmn/test/runtime/DmnTaskTest.outputOrder.dmn"})
void withOutputOrder_ensureListOfItemIsReturnedEvenIfOnlyOneRowIsHit() {
    ProcessInstance processInstance = this.runtimeService.createProcessInstanceBuilder()
            .processDefinitionKey("oneDecisionTaskProcess")
            .variable("testInput", "second")
            .start();
    Map<String, Object> processVariables = processInstance.getProcessVariables();
    Object resultObject = processVariables.get("DecisionTable");
    assertThat(resultObject).isInstanceOf(ArrayNode.class);
    ArrayNode result = (ArrayNode) resultObject;
    assertThat(result).hasSize(1);
    assertThat(result.get(0)).isInstanceOf(ObjectNode.class);
    assertThat(result.get(0).get("testOutput")).isInstanceOf(DoubleNode.class);
    assertThat(result.get(0).get("testOutput").asDouble()).isEqualTo(2.0);
}
 
Example 3
Source File: DmnTaskTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {
        "org/flowable/bpmn/test/runtime/DmnTaskTest.oneDecisionTaskProcess.bpmn20.xml",
        "org/flowable/bpmn/test/runtime/DmnTaskTest.ruleOrder.dmn"})
void withRuleOrder_ensureListOfItemIsReturnedEvenIfOnlyOneRowIsHit() {
    ProcessInstance processInstance = this.runtimeService.createProcessInstanceBuilder()
            .processDefinitionKey("oneDecisionTaskProcess")
            .variable("testInput", "second")
            .start();
    Map<String, Object> processVariables = processInstance.getProcessVariables();
    Object resultObject = processVariables.get("DecisionTable");
    assertThat(resultObject).isInstanceOf(ArrayNode.class);
    ArrayNode result = (ArrayNode) resultObject;
    assertThat(result).hasSize(1);
    assertThat(result.get(0)).isInstanceOf(ObjectNode.class);
    assertThat(result.get(0).get("testOutput")).isInstanceOf(DoubleNode.class);
    assertThat(result.get(0).get("testOutput").asDouble()).isEqualTo(2.0);
}
 
Example 4
Source File: DmnTaskTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {
        "org/flowable/bpmn/test/runtime/DmnTaskTest.oneDecisionTaskProcess.bpmn20.xml",
        "org/flowable/bpmn/test/runtime/DmnTaskTest.ruleOrder.dmn"})
void withRuleOrderAndBackwardsCompatibilityFlag_ensureListOfItemIsReturnedEvenIfOnlyOneRowIsHit() {
    processEngineConfiguration.setAlwaysUseArraysForDmnMultiHitPolicies(false);
    ProcessInstance processInstance = this.runtimeService.createProcessInstanceBuilder()
            .processDefinitionKey("oneDecisionTaskProcess")
            .variable("testInput", "second")
            .start();
    Map<String, Object> processVariables = processInstance.getProcessVariables();
    Object resultObject = processVariables.get("DecisionTable");
    assertThat(resultObject).isNull();
    assertThat(processVariables.get("testOutput")).isEqualTo(2.0);

    processEngineConfiguration.setAlwaysUseArraysForDmnMultiHitPolicies(true);
}
 
Example 5
Source File: ProcessInstanceAndVariablesQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testOrQuery() {
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .or().variableValueEquals("undefined", 999).variableValueEquals("anothertest", 123).endOr().singleResult();
    Map<String, Object> variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .or().variableValueEquals("undefined", 999).endOr().singleResult();
    assertNull(processInstance);

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .or().variableValueEquals("anothertest", 123).variableValueEquals("undefined", 999).endOr().singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .or().variableValueEquals("anothertest", 999).endOr().singleResult();
    assertNull(processInstance);

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .or().variableValueEquals("anothertest", 999).variableValueEquals("anothertest", 123).endOr().singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));
}
 
Example 6
Source File: RestResponseFactory.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public ProcessInstanceResponse createProcessInstanceResponse(ProcessInstance processInstance, RestUrlBuilder urlBuilder) {
    ProcessInstanceResponse result = internalCreateProcessInstanceResponse(processInstance, urlBuilder);
    if (processInstance.getProcessVariables() != null) {
        Map<String, Object> variableMap = processInstance.getProcessVariables();
        for (String name : variableMap.keySet()) {
            result.addVariable(createRestVariable(name, variableMap.get(name), RestVariableScope.LOCAL, processInstance.getId(), VARIABLE_PROCESS, false, urlBuilder));
        }
    }

    return result;
}
 
Example 7
Source File: ProcessInstanceAndVariablesQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testOrQuery() {
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .or().variableValueEquals("undefined", 999).variableValueEquals("anothertest", 123).endOr().singleResult();
    Map<String, Object> variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .or().variableValueEquals("undefined", 999).endOr().singleResult();
    assertNull(processInstance);

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .or().variableValueEquals("anothertest", 123).variableValueEquals("undefined", 999).endOr().singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .or().variableValueEquals("anothertest", 999).endOr().singleResult();
    assertNull(processInstance);

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .or().variableValueEquals("anothertest", 999).variableValueEquals("anothertest", 123).endOr().singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));
}
 
Example 8
Source File: DmnTaskTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {
        "org/flowable/bpmn/test/runtime/DmnTaskTest.oneDecisionTaskProcess.bpmn20.xml",
        "org/flowable/bpmn/test/runtime/DmnTaskTest.firstHit.dmn"})
void withFirstHitPolicy_ensureItemIsReturned() {
    ProcessInstance processInstance = this.runtimeService.createProcessInstanceBuilder()
            .processDefinitionKey("oneDecisionTaskProcess")
            .variable("testInput", "second")
            .start();
    Map<String, Object> processVariables = processInstance.getProcessVariables();
    assertThat(processVariables.get("testOutput")).isEqualTo(2d);
}
 
Example 9
Source File: DmnTaskTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {
        "org/flowable/bpmn/test/runtime/DmnTaskTest.oneDecisionTaskProcess.bpmn20.xml",
        "org/flowable/bpmn/test/runtime/DmnTaskTest.ruleOrder.dmn"})
void withRuleOrder_ensureListOfItemIsReturnedEvenIfNoRowIsHit() {
    ProcessInstance processInstance = this.runtimeService.createProcessInstanceBuilder()
            .processDefinitionKey("oneDecisionTaskProcess")
            .variable("testInput", "fourth")
            .start();
    Map<String, Object> processVariables = processInstance.getProcessVariables();
    Object resultObject = processVariables.get("DecisionTable");
    assertThat(resultObject).isInstanceOf(ArrayNode.class);
    ArrayNode result = (ArrayNode) resultObject;
    assertThat(result).isEmpty();
}
 
Example 10
Source File: ProcessInstanceAndVariablesQueryTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void testQuery() {
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .variableValueEquals("anothertest", 123).singleResult();
    Map<String, Object> variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));

    List<ProcessInstance> instanceList = runtimeService.createProcessInstanceQuery().includeProcessVariables().list();
    assertEquals(6, instanceList.size());

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .variableValueLike("casetest", "MyCase%").singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals("MyCaseTest", variableMap.get("casetest"));

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .variableValueLikeIgnoreCase("casetest", "mycase%").singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals("MyCaseTest", variableMap.get("casetest"));

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .variableValueLikeIgnoreCase("casetest", "mycase2%").singleResult();
    assertNull(processInstance);

    instanceList = runtimeService.createProcessInstanceQuery().includeProcessVariables().processDefinitionKey(PROCESS_DEFINITION_KEY).list();
    assertEquals(4, instanceList.size());
    processInstance = instanceList.get(0);
    variableMap = processInstance.getProcessVariables();
    assertEquals(2, variableMap.size());
    assertEquals("test", variableMap.get("test"));
    assertEquals("test2", variableMap.get("test2"));

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .processDefinitionKey(PROCESS_DEFINITION_KEY_2).singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));

    instanceList = runtimeService.createProcessInstanceQuery()
            .includeProcessVariables()
            .processDefinitionKey(PROCESS_DEFINITION_KEY)
            .listPage(0, 5);
    assertEquals(4, instanceList.size());
    processInstance = instanceList.get(0);
    variableMap = processInstance.getProcessVariables();
    assertEquals(2, variableMap.size());
    assertEquals("test", variableMap.get("test"));
    assertEquals("test2", variableMap.get("test2"));

    instanceList = runtimeService.createProcessInstanceQuery()
            .includeProcessVariables()
            .processDefinitionKey(PROCESS_DEFINITION_KEY)
            .listPage(0, 1);
    assertEquals(1, instanceList.size());
    processInstance = instanceList.get(0);
    variableMap = processInstance.getProcessVariables();
    assertEquals(2, variableMap.size());
    assertEquals("test", variableMap.get("test"));
    assertEquals("test2", variableMap.get("test2"));

    instanceList = runtimeService.createProcessInstanceQuery()
            .includeProcessVariables()
            .processDefinitionKey(PROCESS_DEFINITION_KEY)
            .orderByProcessDefinitionKey()
            .asc()
            .listPage(2, 4);
    assertEquals(2, instanceList.size());
    processInstance = instanceList.get(0);
    variableMap = processInstance.getProcessVariables();
    assertEquals(2, variableMap.size());
    assertEquals("test", variableMap.get("test"));
    assertEquals("test2", variableMap.get("test2"));

    instanceList = runtimeService.createProcessInstanceQuery()
            .includeProcessVariables()
            .processDefinitionKey(PROCESS_DEFINITION_KEY)
            .orderByProcessDefinitionKey()
            .asc()
            .listPage(4, 5);
    assertEquals(0, instanceList.size());
}
 
Example 11
Source File: ProcessInstanceAndVariablesQueryTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void testOrQueryMultipleVariableValues() {
    ProcessInstanceQuery query0 = runtimeService.createProcessInstanceQuery().includeProcessVariables().or();
    for (int i = 0; i < 20; i++) {
        query0 = query0.variableValueEquals("anothertest", i);
    }
    query0 = query0.endOr();
    assertNull(query0.singleResult());

    ProcessInstanceQuery query1 = runtimeService.createProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 123);
    for (int i = 0; i < 20; i++) {
        query1 = query1.variableValueEquals("anothertest", i);
    }
    query1 = query1.endOr();
    assertNull(query0.singleResult());

    ProcessInstance processInstance = query1.singleResult();
    Map<String, Object> variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));

    ProcessInstanceQuery query2 = runtimeService.createProcessInstanceQuery().includeProcessVariables().or();
    for (int i = 0; i < 20; i++) {
        query2 = query2.variableValueEquals("anothertest", i);
    }
    query2 = query2.endOr()
            .or()
            .processDefinitionKey(PROCESS_DEFINITION_KEY_2)
            .processDefinitionId("undefined")
            .endOr();
    assertNull(query2.singleResult());

    ProcessInstanceQuery query3 = runtimeService.createProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 123);
    for (int i = 0; i < 20; i++) {
        query3 = query3.variableValueEquals("anothertest", i);
    }
    query3 = query3.endOr()
            .or()
            .processDefinitionKey(PROCESS_DEFINITION_KEY_2)
            .processDefinitionId("undefined")
            .endOr();
    variableMap = query3.singleResult().getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));
}
 
Example 12
Source File: HistoricProcessInstanceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Validation for https://activiti.atlassian.net/browse/ACT-2182
 */
public void testNameAndTenantIdSetWhenFetchingVariables() {

    String tenantId = "testTenantId";
    String processInstanceName = "myProcessInstance";

    String deploymentId = repositoryService.createDeployment()
            .addClasspathResource("org/activiti/engine/test/history/oneTaskProcess.bpmn20.xml")
            .tenantId(tenantId)
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy()
            .getId();

    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("name", "Kermit");
    vars.put("age", 60);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKeyAndTenantId("oneTaskProcess", vars, tenantId);
    runtimeService.setProcessInstanceName(processInstance.getId(), processInstanceName);

    // Verify name and tenant id (didn't work on mssql and db2) on process instance
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().includeProcessVariables().list();
    assertEquals(1, processInstances.size());
    processInstance = processInstances.get(0);

    assertEquals(processInstanceName, processInstance.getName());
    assertEquals(tenantId, processInstance.getTenantId());

    Map<String, Object> processInstanceVars = processInstance.getProcessVariables();
    assertEquals(2, processInstanceVars.size());
    assertEquals("Kermit", processInstanceVars.get("name"));
    assertEquals(60, processInstanceVars.get("age"));

    // Verify name and tenant id (didn't work on mssql and db2) on historic process instance
    List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().list();
    assertEquals(1, historicProcessInstances.size());
    HistoricProcessInstance historicProcessInstance = historicProcessInstances.get(0);

    // Verify name and tenant id (didn't work on mssql and db2) on process instance
    assertEquals(processInstanceName, historicProcessInstance.getName());
    assertEquals(tenantId, historicProcessInstance.getTenantId());

    Map<String, Object> historicProcessInstanceVars = historicProcessInstance.getProcessVariables();
    assertEquals(2, historicProcessInstanceVars.size());
    assertEquals("Kermit", historicProcessInstanceVars.get("name"));
    assertEquals(60, historicProcessInstanceVars.get("age"));

    // cleanup
    repositoryService.deleteDeployment(deploymentId, true);
}
 
Example 13
Source File: ProcessInstanceAndVariablesQueryTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testQuery() {
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().variableValueEquals("anothertest", 123).singleResult();
    Map<String, Object> variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));

    List<ProcessInstance> instanceList = runtimeService.createProcessInstanceQuery().includeProcessVariables().list();
    assertEquals(7, instanceList.size());

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .variableValueLike("casetest", "MyCase%").singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals("MyCaseTest", variableMap.get("casetest"));

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .variableValueLikeIgnoreCase("casetest", "mycase%").singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals("MyCaseTest", variableMap.get("casetest"));

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
            .variableValueLikeIgnoreCase("casetest", "mycase2%").singleResult();
    assertNull(processInstance);

    instanceList = runtimeService.createProcessInstanceQuery().includeProcessVariables().processDefinitionKey(PROCESS_DEFINITION_KEY).list();
    assertEquals(4, instanceList.size());
    processInstance = instanceList.get(0);
    variableMap = processInstance.getProcessVariables();
    assertEquals(2, variableMap.size());
    assertEquals("test", variableMap.get("test"));
    assertEquals("test2", variableMap.get("test2"));

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().processDefinitionKey(PROCESS_DEFINITION_KEY_2).singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));

    instanceList = runtimeService.createProcessInstanceQuery().includeProcessVariables().processDefinitionKey(PROCESS_DEFINITION_KEY).listPage(0, 5);
    assertEquals(4, instanceList.size());
    processInstance = instanceList.get(0);
    variableMap = processInstance.getProcessVariables();
    assertEquals(2, variableMap.size());
    assertEquals("test", variableMap.get("test"));
    assertEquals("test2", variableMap.get("test2"));

    instanceList = runtimeService.createProcessInstanceQuery().includeProcessVariables().processDefinitionKey(PROCESS_DEFINITION_KEY).listPage(0, 1);
    assertEquals(1, instanceList.size());
    processInstance = instanceList.get(0);
    variableMap = processInstance.getProcessVariables();
    assertEquals(2, variableMap.size());
    assertEquals("test", variableMap.get("test"));
    assertEquals("test2", variableMap.get("test2"));

    instanceList = runtimeService.createProcessInstanceQuery().includeProcessVariables().processDefinitionKey(PROCESS_DEFINITION_KEY).orderByProcessDefinitionKey().asc().listPage(2, 4);
    assertEquals(2, instanceList.size());
    processInstance = instanceList.get(0);
    variableMap = processInstance.getProcessVariables();
    assertEquals(2, variableMap.size());
    assertEquals("test", variableMap.get("test"));
    assertEquals("test2", variableMap.get("test2"));

    instanceList = runtimeService.createProcessInstanceQuery().includeProcessVariables().processDefinitionKey(PROCESS_DEFINITION_KEY).orderByProcessDefinitionKey().asc().listPage(4, 5);
    assertEquals(0, instanceList.size());

    processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().variableValueEquals("test4", "test4").singleResult();
    variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals("test4", variableMap.get("test4"));
}
 
Example 14
Source File: ProcessInstanceAndVariablesQueryTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testOrQueryMultipleVariableValues() {
    ProcessInstanceQuery query0 = runtimeService.createProcessInstanceQuery().includeProcessVariables().or();
    for (int i = 0; i < 20; i++) {
        query0 = query0.variableValueEquals("anothertest", i);
    }
    query0 = query0.endOr();
    assertNull(query0.singleResult());

    ProcessInstanceQuery query1 = runtimeService.createProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 123);
    for (int i = 0; i < 20; i++) {
        query1 = query1.variableValueEquals("anothertest", i);
    }
    query1 = query1.endOr();
    assertNull(query0.singleResult());

    ProcessInstance processInstance = query1.singleResult();
    Map<String, Object> variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));

    ProcessInstanceQuery query2 = runtimeService.createProcessInstanceQuery().includeProcessVariables().or();
    for (int i = 0; i < 20; i++) {
        query2 = query2.variableValueEquals("anothertest", i);
    }
    query2 = query2.endOr()
            .or()
            .processDefinitionKey(PROCESS_DEFINITION_KEY_2)
            .processDefinitionId("undefined")
            .endOr();
    assertNull(query2.singleResult());

    ProcessInstanceQuery query3 = runtimeService.createProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 123);
    for (int i = 0; i < 20; i++) {
        query3 = query3.variableValueEquals("anothertest", i);
    }
    query3 = query3.endOr()
            .or()
            .processDefinitionKey(PROCESS_DEFINITION_KEY_2)
            .processDefinitionId("undefined")
            .endOr();
    variableMap = query3.singleResult().getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));
}
 
Example 15
Source File: TestCacheTaskListener.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
    TaskService taskService = processEngineConfiguration.getTaskService();
    Task task = taskService.createTaskQuery().taskId(delegateTask.getId()).singleResult();
    if (task != null && task.getId().equals(delegateTask.getId())) {
        TASK_ID = task.getId();
    }
    
    HistoryService historyService = processEngineConfiguration.getHistoryService();
    HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().taskId(delegateTask.getId()).singleResult();
    if (historicTask != null && historicTask.getId().equals(delegateTask.getId())) {
        HISTORIC_TASK_ID = historicTask.getId();
    }

    delegateTask.setVariable("varFromTheListener", "valueFromTheListener");
    delegateTask.setVariableLocal("localVar", "localValue");

    // Used in CacheTaskTest#testTaskQueryWithIncludeVariables
    ProcessInstance processInstance = processEngineConfiguration.getRuntimeService().createProcessInstanceQuery()
        .processInstanceId(task.getProcessInstanceId())
        .includeProcessVariables()
        .singleResult();
    PROCESS_VARIABLES = processInstance.getProcessVariables();

    HistoricProcessInstance historicProcessInstance = processEngineConfiguration.getHistoryService().createHistoricProcessInstanceQuery()
        .processInstanceId(task.getProcessInstanceId())
        .includeProcessVariables()
        .singleResult();
    HISTORIC_PROCESS_VARIABLES = historicProcessInstance.getProcessVariables();

    // Used in CacheTaskTest#testTaskQueryWithIncludeVariables
    Task taskFromQuery = processEngineConfiguration.getTaskService().createTaskQuery()
        .taskId(delegateTask.getId())
        .includeProcessVariables()
        .includeTaskLocalVariables()
        .singleResult();
    TASK_PROCESS_VARIABLES = taskFromQuery.getProcessVariables();
    TASK_LOCAL_VARIABLES = taskFromQuery.getTaskLocalVariables();

    HistoricTaskInstance historicTaskFromQuery = processEngineConfiguration.getHistoryService().createHistoricTaskInstanceQuery()
        .taskId(delegateTask.getId())
        .includeProcessVariables()
        .includeTaskLocalVariables()
        .singleResult();
    HISTORIC_TASK_PROCESS_VARIABLES = historicTaskFromQuery.getProcessVariables();
    HISTORIC_TASK_LOCAL_VARIABLES = historicTaskFromQuery.getTaskLocalVariables();

}
 
Example 16
Source File: HistoricProcessInstanceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Validation for https://jira.codehaus.org/browse/ACT-2182
 */
@Test
public void testNameAndTenantIdSetWhenFetchingVariables() {

    String tenantId = "testTenantId";
    String processInstanceName = "myProcessInstance";

    String deploymentId = repositoryService.createDeployment().addClasspathResource("org/flowable/engine/test/history/oneTaskProcess.bpmn20.xml").tenantId(tenantId).deploy().getId();

    Map<String, Object> vars = new HashMap<>();
    vars.put("name", "Kermit");
    vars.put("age", 60);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKeyAndTenantId("oneTaskProcess", vars, tenantId);
    runtimeService.setProcessInstanceName(processInstance.getId(), processInstanceName);

    // Verify name and tenant id (didn't work on mssql and db2) on process instance
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().includeProcessVariables().list();
    assertThat(processInstances).hasSize(1);
    processInstance = processInstances.get(0);

    assertThat(processInstance.getName()).isEqualTo(processInstanceName);
    assertThat(processInstance.getTenantId()).isEqualTo(tenantId);

    Map<String, Object> processInstanceVars = processInstance.getProcessVariables();
    assertThat(processInstanceVars).hasSize(2);
    assertThat(processInstanceVars.get("name")).isEqualTo("Kermit");
    assertThat(processInstanceVars.get("age")).isEqualTo(60);
    
    waitForHistoryJobExecutorToProcessAllJobs(10000, 200);

    // Verify name and tenant id (didn't work on mssql and db2) on historic process instance
    List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().list();
    assertThat(historicProcessInstances).hasSize(1);
    HistoricProcessInstance historicProcessInstance = historicProcessInstances.get(0);

    // Verify name and tenant id (didn't work on mssql and db2) on process instance
    assertThat(historicProcessInstance.getName()).isEqualTo(processInstanceName);
    assertThat(historicProcessInstance.getTenantId()).isEqualTo(tenantId);

    Map<String, Object> historicProcessInstanceVars = historicProcessInstance.getProcessVariables();
    assertThat(historicProcessInstanceVars).hasSize(2);
    assertThat(historicProcessInstanceVars.get("name")).isEqualTo("Kermit");
    assertThat(historicProcessInstanceVars.get("age")).isEqualTo(60);
    
    waitForHistoryJobExecutorToProcessAllJobs(10000, 200);

    // cleanup
    deleteDeployment(deploymentId);
}