org.flowable.variable.api.history.HistoricVariableInstance Java Examples

The following examples show how to use org.flowable.variable.api.history.HistoricVariableInstance. 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: CaseTaskTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@CmmnDeployment(resources = { "org/flowable/cmmn/test/oneProcessTask.cmmn", "org/flowable/cmmn/test/oneServiceTask.cmmn" })
public void testCaseHierarchyResolvementWithUserTask() {
    Deployment deployment = processEngineRepositoryService.createDeployment()
            .addClasspathResource("org/flowable/cmmn/test/userTaskAndCaseTaskProcess.bpmn20.xml")
            .deploy();

    try {
        CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder().caseDefinitionKey("oneProcessTaskCase").start();
        Task task = processEngineTaskService.createTaskQuery().taskDefinitionKey("userTask").singleResult();
        processEngineTaskService.complete(task.getId());

        assertThat(cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseInstance.getId()).count()).isZero();
        HistoricVariableInstance variableInstance = cmmnHistoryService.createHistoricVariableInstanceQuery()
                .variableName("linkCount")
                .singleResult();
        assertThat(variableInstance.getValue()).isEqualTo(2);

    } finally {
        processEngineRepositoryService.deleteDeployment(deployment.getId(), true);
    }
}
 
Example #2
Source File: HistoricVariableInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testSimpleNoWaitState() {
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.FULL, processEngineConfiguration)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
        assertProcessEnded(processInstance.getId());

        List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
        assertEquals(1, variables.size());

        HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
        assertEquals("test456", historicVariable.getTextValue());

        assertEquals(4, historyService.createHistoricActivityInstanceQuery().count());
        assertEquals(2, historyService.createHistoricDetailQuery().count());
    }
}
 
Example #3
Source File: HistoricVariableInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testSimple() {
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.FULL, processEngineConfiguration)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
        TaskQuery taskQuery = taskService.createTaskQuery();
        org.flowable.task.api.Task userTask = taskQuery.singleResult();
        assertEquals("userTask1", userTask.getName());

        taskService.complete(userTask.getId(), CollectionUtil.singletonMap("myVar", "test789"));

        assertProcessEnded(processInstance.getId());

        List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
        assertEquals(1, variables.size());

        HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
        assertEquals("test456", historicVariable.getTextValue());

        assertEquals(5, historyService.createHistoricActivityInstanceQuery().count());
        assertEquals(3, historyService.createHistoricDetailQuery().count());
    }
}
 
Example #4
Source File: ScriptExecutionListenerTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/examples/bpmn/executionlistener/ScriptExecutionListenerTest.bpmn20.xml" })
public void testScriptExecutionListener() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("scriptExecutionListenerProcess");

    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
        List<HistoricVariableInstance> historicVariables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).list();
        assertThat(historicVariables)
                .extracting(HistoricVariableInstance::getVariableName, HistoricVariableInstance::getValue)
                .containsExactlyInAnyOrder(
                        tuple("foo", "FOO"),
                        tuple("var1", "test"),
                        tuple("myVar", "BAR")
                );
    }
}
 
Example #5
Source File: HistoricVariableInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testTwoSubProcessInParallelWithinSubProcess() {
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.FULL, processEngineConfiguration)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoSubProcessInParallelWithinSubProcess");
        assertProcessEnded(processInstance.getId());

        List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().list();
        assertEquals(2, variables.size());

        HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
        assertEquals("myVar", historicVariable.getName());
        assertEquals("test101112", historicVariable.getTextValue());

        HistoricVariableInstanceEntity historicVariable1 = (HistoricVariableInstanceEntity) variables.get(1);
        assertEquals("myVar1", historicVariable1.getName());
        assertEquals("test789", historicVariable1.getTextValue());

        assertEquals(18, historyService.createHistoricActivityInstanceQuery().count());
        assertEquals(7, historyService.createHistoricDetailQuery().count());
    }
}
 
Example #6
Source File: HistoricJPAVariableTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testGetJPAEntityAsHistoricVariable() {
    setupJPAEntities();
    // -----------------------------------------------------------------------------
    // Simple test, Start process with JPA entities as variables
    // -----------------------------------------------------------------------------
    Map<String, Object> variables = new HashMap<>();
    variables.put("simpleEntityFieldAccess", simpleEntityFieldAccess);

    // Start the process with the JPA-entities as variables. They will be stored in the DB.
    this.processInstanceId = runtimeService.startProcessInstanceByKey("JPAVariableProcess", variables).getId();

    for (org.flowable.task.api.Task task : taskService.createTaskQuery().includeTaskLocalVariables().list()) {
        taskService.complete(task.getId());
    }

    // Get JPAEntity Variable by HistoricVariableInstanceQuery
    HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery()
            .processInstanceId(processInstanceId).variableName("simpleEntityFieldAccess").singleResult();

    Object value = historicVariableInstance.getValue();
    assertThat(value).isInstanceOf(FieldAccessJPAEntity.class);
    assertThat(simpleEntityFieldAccess.getValue()).isEqualTo(((FieldAccessJPAEntity) value).getValue());
}
 
Example #7
Source File: HistoricVariableInstanceQueryImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public List<HistoricVariableInstance> executeList(CommandContext commandContext) {
    ensureVariablesInitialized();

    List<HistoricVariableInstance> historicVariableInstances = CommandContextUtil.getHistoricVariableInstanceEntityManager(commandContext).findHistoricVariableInstancesByQueryCriteria(this);

    if (!excludeVariableInitialization) {
        for (HistoricVariableInstance historicVariableInstance : historicVariableInstances) {
            if (historicVariableInstance instanceof HistoricVariableInstanceEntity) {
                HistoricVariableInstanceEntity variableEntity = (HistoricVariableInstanceEntity) historicVariableInstance;
                if (variableEntity.getVariableType() != null) {
                    variableEntity.getValue();

                    // make sure JPA entities are cached for later retrieval
                    if (JPAEntityVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName()) || JPAEntityListVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName())) {
                        ((CacheableVariable) variableEntity.getVariableType()).setForceCacheable(true);
                    }
                }
            }
        }
    }
    return historicVariableInstances;
}
 
Example #8
Source File: EmptyProcessTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "process/empty.bpmn20.xml" })
public void testRunProcessWithHeader() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = camelContext.createProducerTemplate();
    String body = "body text";
    Exchange exchange = ctx.getEndpoint("direct:startEmptyWithHeader").createExchange();
    exchange.getIn().setBody(body);
    tpl.send("direct:startEmptyWithHeader", exchange);

    String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY");
    assertProcessEnded(instanceId);
    HistoricVariableInstance var = processEngine.getHistoryService().createHistoricVariableInstanceQuery().variableName("camelBody").singleResult();
    assertThat(var).isNotNull();
    assertThat(var.getValue()).isEqualTo(body);
    var = processEngine.getHistoryService().createHistoricVariableInstanceQuery().variableName("MyVar").singleResult();
    assertThat(var).isNotNull();
    assertThat(var.getValue()).isEqualTo("Foo");
}
 
Example #9
Source File: HistoricJPAVariableTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testGetJPAEntityAsHistoricVariable() {
    setupJPAEntities();
    // -----------------------------------------------------------------------------
    // Simple test, Start process with JPA entities as variables
    // -----------------------------------------------------------------------------
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("simpleEntityFieldAccess", simpleEntityFieldAccess);

    // Start the process with the JPA-entities as variables. They will be stored
    // in the DB.
    this.processInstanceId = runtimeService.startProcessInstanceByKey("JPAVariableProcess", variables).getId();

    for (org.flowable.task.api.Task task : taskService.createTaskQuery().includeTaskLocalVariables().list()) {
        taskService.complete(task.getId());
    }

    // Get JPAEntity Variable by HistoricVariableInstanceQuery
    HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).variableName("simpleEntityFieldAccess")
            .singleResult();

    Object value = historicVariableInstance.getValue();
    assertTrue(value instanceof FieldAccessJPAEntity);
    assertEquals(((FieldAccessJPAEntity) value).getValue(), simpleEntityFieldAccess.getValue());
}
 
Example #10
Source File: HistoricVariableInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testSimpleNoWaitState() {
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.FULL, processEngineConfiguration)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
        assertProcessEnded(processInstance.getId());
        
        waitForHistoryJobExecutorToProcessAllJobs(7000, 100);

        List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
        assertThat(variables).hasSize(1);

        HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
        assertThat(historicVariable.getTextValue()).isEqualTo("test456");

        assertThat(historyService.createHistoricActivityInstanceQuery().count()).isEqualTo(7);
        assertThat(historyService.createHistoricDetailQuery().count()).isEqualTo(2);
    }
}
 
Example #11
Source File: EmptyProcessTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "process/empty.bpmn20.xml" })
public void testObjectAsStringVariable() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = ctx.createProducerTemplate();
    Object expectedObj = 99L;

    Exchange exchange = ctx.getEndpoint("direct:startEmptyBodyAsString").createExchange();
    exchange.getIn().setBody(expectedObj);
    tpl.send("direct:startEmptyBodyAsString", exchange);

    String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY");

    assertProcessEnded(instanceId);
    HistoricVariableInstance var = processEngine.getHistoryService().createHistoricVariableInstanceQuery().variableName("camelBody").singleResult();
    assertThat(var).isNotNull();
    assertThat(var.getValue()).hasToString(expectedObj.toString());
}
 
Example #12
Source File: HistoricVariableInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testRestrictByExecutionId() {
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.FULL, processEngineConfiguration)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
        TaskQuery taskQuery = taskService.createTaskQuery();
        org.flowable.task.api.Task userTask = taskQuery.singleResult();
        assertThat(userTask.getName()).isEqualTo("userTask1");

        taskService.complete(userTask.getId(), CollectionUtil.singletonMap("myVar", "test789"));

        assertProcessEnded(processInstance.getId());
        
        waitForHistoryJobExecutorToProcessAllJobs(7000, 100);

        List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().executionId(processInstance.getId()).list();
        assertThat(variables).hasSize(1);

        HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
        assertThat(historicVariable.getTextValue()).isEqualTo("test456");

        assertThat(historyService.createHistoricActivityInstanceQuery().count()).isEqualTo(9);
        assertThat(historyService.createHistoricDetailQuery().count()).isEqualTo(3);
    }
}
 
Example #13
Source File: EmptyProcessTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "process/empty.bpmn20.xml" })
public void testRunProcessWithHeader() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = camelContext.createProducerTemplate();
    String body = "body text";
    Exchange exchange = ctx.getEndpoint("direct:startEmptyWithHeader").createExchange();
    exchange.getIn().setBody(body);
    tpl.send("direct:startEmptyWithHeader", exchange);

    String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY");
    assertProcessEnded(instanceId);
    HistoricVariableInstance var = processEngine.getHistoryService().createHistoricVariableInstanceQuery().variableName("camelBody").singleResult();
    assertNotNull(var);
    assertEquals(body, var.getValue());
    var = processEngine.getHistoryService().createHistoricVariableInstanceQuery().variableName("MyVar").singleResult();
    assertNotNull(var);
    assertEquals("Foo", var.getValue());
}
 
Example #14
Source File: ProcessInstanceLogQueryAndByteArrayTypeVariableTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void testIncludeVariableUpdates() {
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.FULL, processEngineConfiguration)) {

        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery()
                .processInstanceId(processInstanceId).variableName("var").singleResult();
        assertEquals(LARGE_STRING_VALUE, historicVariableInstance.getValue());

        ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId)
                .includeVariableUpdates()
                .singleResult();
        List<HistoricData> events = log.getHistoricData();
        assertEquals(1, events.size());

        for (HistoricData event : events) {
            assertTrue(event instanceof HistoricVariableUpdate);
            assertEquals(LARGE_STRING_VALUE, ((HistoricDetailVariableInstanceUpdateEntity) event).getValue());
        }
    }
}
 
Example #15
Source File: RestResponseFactory.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public ProcessInstanceResponse createProcessInstanceResponse(ProcessInstance processInstance, boolean returnVariables,
        Map<String, Object> runtimeVariableMap, List<HistoricVariableInstance> historicVariableList) {

    RestUrlBuilder urlBuilder = createUrlBuilder();
    ProcessInstanceResponse result = internalCreateProcessInstanceResponse(processInstance, urlBuilder);

    if (returnVariables) {

        if (processInstance.isEnded()) {
            if (historicVariableList != null) {
                for (HistoricVariableInstance historicVariable : historicVariableList) {
                    result.addVariable(createRestVariable(historicVariable.getVariableName(), historicVariable.getValue(), RestVariableScope.LOCAL, processInstance.getId(), VARIABLE_PROCESS, false,
                            urlBuilder));
                }
            }

        } else {
            if (runtimeVariableMap != null) {
                for (String name : runtimeVariableMap.keySet()) {
                    result.addVariable(createRestVariable(name, runtimeVariableMap.get(name), RestVariableScope.LOCAL, processInstance.getId(), VARIABLE_PROCESS, false, urlBuilder));
                }
            }
        }
    }
    return result;
}
 
Example #16
Source File: HistoricVariableInstanceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "org/flowable/engine/test/history/HistoricVariableInstanceTest.testSimple.bpmn20.xml")
public void testNativeHistoricVariableInstanceQuery() {

    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.FULL, processEngineConfiguration)) {

        assertThat(managementService.getTableName(HistoricVariableInstance.class, false)).isEqualTo("ACT_HI_VARINST");
        assertThat(managementService.getTableName(HistoricVariableInstanceEntity.class, false)).isEqualTo("ACT_HI_VARINST");

        String tableName = managementService.getTableName(HistoricVariableInstance.class);
        String baseQuerySql = "SELECT * FROM " + tableName;

        Map<String, Object> variables = new HashMap<>();
        variables.put("var1", "value1");
        variables.put("var2", "value2");
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc", variables);
        assertThat(processInstance).isNotNull();
        
        waitForHistoryJobExecutorToProcessAllJobs(7000, 100);

        assertThat(historyService.createNativeHistoricVariableInstanceQuery().sql(baseQuerySql).list()).hasSize(3);

        String sqlWithConditions = baseQuerySql + " where NAME_ = #{name}";
        assertThat(historyService.createNativeHistoricVariableInstanceQuery().sql(sqlWithConditions).parameter("name", "myVar").singleResult().getValue()).isEqualTo("test123");

        sqlWithConditions = baseQuerySql + " where NAME_ like #{name}";
        assertThat(historyService.createNativeHistoricVariableInstanceQuery().sql(sqlWithConditions).parameter("name", "var%").list()).hasSize(2);

        // paging
        assertThat(historyService.createNativeHistoricVariableInstanceQuery().sql(baseQuerySql).listPage(0, 3)).hasSize(3);
        assertThat(historyService.createNativeHistoricVariableInstanceQuery().sql(baseQuerySql).listPage(1, 3)).hasSize(2);
        assertThat(historyService.createNativeHistoricVariableInstanceQuery().sql(sqlWithConditions).parameter("name", "var%").listPage(0, 2)).hasSize(2);
    }

}
 
Example #17
Source File: HistoricVariableInstanceDataResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public RestVariable getVariableFromRequest(boolean includeBinary, String varInstanceId, HttpServletRequest request) {
    HistoricVariableInstance varObject = historyService.createHistoricVariableInstanceQuery().id(varInstanceId).singleResult();

    if (varObject == null) {
        throw new FlowableObjectNotFoundException("Historic variable instance '" + varInstanceId + "' could not be found.", VariableInstanceEntity.class);
    } else {
        
        if (restApiInterceptor != null) {
            restApiInterceptor.accessHistoryVariableInfoById(varObject);
        }
        
        return restResponseFactory.createRestVariable(varObject.getVariableName(), varObject.getValue(), null, varInstanceId, RestResponseFactory.VARIABLE_HISTORY_VARINSTANCE, includeBinary);
    }
}
 
Example #18
Source File: FullHistoryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "org/flowable/standalone/history/FullHistoryTest.testVariableUpdates.bpmn20.xml")
public void testHistoricVariableInstanceQuery() {
    Map<String, Object> variables = new HashMap<>();
    variables.put("process", "one");
    runtimeService.startProcessInstanceByKey("receiveTask", variables);
    runtimeService.trigger(runtimeService.createExecutionQuery().activityId("waitState").singleResult().getId());

    assertThat(historyService.createHistoricVariableInstanceQuery().variableName("process").count()).isEqualTo(1);
    assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "one").count()).isEqualTo(1);

    Map<String, Object> variables2 = new HashMap<>();
    variables2.put("process", "two");
    runtimeService.startProcessInstanceByKey("receiveTask", variables2);
    runtimeService.trigger(runtimeService.createExecutionQuery().activityId("waitState").singleResult().getId());

    assertThat(historyService.createHistoricVariableInstanceQuery().variableName("process").count()).isEqualTo(2);
    assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "one").count()).isEqualTo(1);
    assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "two").count()).isEqualTo(1);

    HistoricVariableInstance historicProcessVariable = historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "one")
            .singleResult();
    assertThat(historicProcessVariable.getVariableName()).isEqualTo("process");
    assertThat(historicProcessVariable.getValue()).isEqualTo("one");

    Map<String, Object> variables3 = new HashMap<>();
    variables3.put("long", 1000l);
    variables3.put("double", 25.43d);
    runtimeService.startProcessInstanceByKey("receiveTask", variables3);
    runtimeService.trigger(runtimeService.createExecutionQuery().activityId("waitState").singleResult().getId());

    assertThat(historyService.createHistoricVariableInstanceQuery().variableName("long").count()).isEqualTo(1);
    assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("long", 1000l).count()).isEqualTo(1);
    assertThat(historyService.createHistoricVariableInstanceQuery().variableName("double").count()).isEqualTo(1);
    assertThat(historyService.createHistoricVariableInstanceQuery().variableValueEquals("double", 25.43d).count()).isEqualTo(1);
}
 
Example #19
Source File: DebuggerRestVariable.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public DebuggerRestVariable(HistoricVariableInstance historicVariableInstance) {
    type = historicVariableInstance.getVariableTypeName();
    name = historicVariableInstance.getVariableName();
    value = historicVariableInstance.getValue();
    executionId = historicVariableInstance.getProcessInstanceId();
    processId = historicVariableInstance.getProcessInstanceId();
    taskId = historicVariableInstance.getTaskId();
}
 
Example #20
Source File: HistoricVariableInstanceEscapeClauseTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryLikeByQueryVariableValue() {
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
        HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLike("var%", "%|%%").singleResult();
        assertThat(historicVariable).isNotNull();
        assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance1.getId());

        historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLike("var_", "%|_%").singleResult();
        assertThat(historicVariable).isNotNull();
        assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance2.getId());
    }
}
 
Example #21
Source File: CallActivityTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotInheritVariablesSubprocess() throws Exception {
    BpmnModel mainBpmnModel = loadBPMNModel(NOT_INHERIT_VARIABLES_MAIN_PROCESS_RESOURCE);
    BpmnModel childBpmnModel = loadBPMNModel(INHERIT_VARIABLES_CHILD_PROCESS_RESOURCE);

    processEngine.getRepositoryService()
            .createDeployment()
            .name("childProcessDeployment")
            .addBpmnModel("childProcess.bpmn20.xml", childBpmnModel).deploy();

    processEngine.getRepositoryService()
            .createDeployment()
            .name("mainProcessDeployment")
            .addBpmnModel("mainProcess.bpmn20.xml", mainBpmnModel).deploy();

    Map<String, Object> variables = new HashMap<>();
    variables.put("var1", "String test value");
    variables.put("var2", true);
    variables.put("var3", 12345);
    variables.put("var4", 67890);

    ProcessInstance mainProcessInstance = runtimeService.startProcessInstanceByKey("mainProcess", variables);

    HistoricActivityInstanceQuery activityInstanceQuery = historyService.createHistoricActivityInstanceQuery();
    activityInstanceQuery.processInstanceId(mainProcessInstance.getId());
    activityInstanceQuery.activityId("childProcessCall");
    HistoricActivityInstance activityInstance = activityInstanceQuery.singleResult();
    String calledInstanceId = activityInstance.getCalledProcessInstanceId();

    HistoricVariableInstanceQuery variableInstanceQuery = historyService.createHistoricVariableInstanceQuery();
    variableInstanceQuery.processInstanceId(calledInstanceId);
    List<HistoricVariableInstance> variableInstances = variableInstanceQuery.list();

    assertThat(variableInstances).isEmpty();
}
 
Example #22
Source File: SerializableVariableTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "org/flowable/engine/test/api/oneTaskProcess.bpmn20.xml")
void testGetSerializableValueFromValueInstance() {
    ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
            .processDefinitionKey("oneTaskProcess")
            .variable("var", new TestSerializableVariable(10))
            .start();

    assertThat(runtimeService.getVariable(processInstance.getId(), "var", TestSerializableVariable.class))
            .extracting(TestSerializableVariable::getNumber)
            .isEqualTo(10);

    VariableInstance variableInstance = runtimeService.getVariableInstance(processInstance.getId(), "var");
    assertThat(variableInstance).isNotNull();

    assertThat(variableInstance.getValue())
            .asInstanceOf(type(TestSerializableVariable.class))
            .extracting(TestSerializableVariable::getNumber)
            .isEqualTo(10);

    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId())
                .variableName("var")
                .singleResult();

        assertThat(historicVariableInstance.getValue())
                .asInstanceOf(type(TestSerializableVariable.class))
                .extracting(TestSerializableVariable::getNumber)
                .isEqualTo(10);
    }
}
 
Example #23
Source File: RestResponseFactory.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public HistoricVariableInstanceResponse createHistoricVariableInstanceResponse(HistoricVariableInstance variableInstance, RestUrlBuilder urlBuilder) {
    HistoricVariableInstanceResponse result = new HistoricVariableInstanceResponse();
    result.setId(variableInstance.getId());
    result.setProcessInstanceId(variableInstance.getProcessInstanceId());
    if (variableInstance.getProcessInstanceId() != null) {
        result.setProcessInstanceUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE, variableInstance.getProcessInstanceId()));
    }
    result.setTaskId(variableInstance.getTaskId());
    result.setVariable(createRestVariable(variableInstance.getVariableName(), variableInstance.getValue(), null, variableInstance.getId(), VARIABLE_HISTORY_VARINSTANCE, false, urlBuilder));
    return result;
}
 
Example #24
Source File: ServiceTaskTransientVariablesTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testStoreLocalTransientVariable() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");

    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {

        List<HistoricVariableInstance> variablesInstances = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId())
                .list();

        assertThat(variablesInstances)
                .extracting(HistoricVariableInstance::getValue)
                .containsOnly("Result is: test");
    }
}
 
Example #25
Source File: StandaloneTaskTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testHistoricVariableOkOnUpdate() {
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.AUDIT, processEngineConfiguration)) {
        // 1. create a task
        org.flowable.task.api.Task task = taskService.newTask();
        task.setName("test execution");
        task.setOwner("josOwner");
        task.setAssignee("JosAssignee");
        taskService.saveTask(task);

        // 2. set task variables
        Map<String, Object> taskVariables = new HashMap<>();
        taskVariables.put("finishedAmount", 0);
        taskService.setVariables(task.getId(), taskVariables);

        // 3. complete this task with a new variable
        Map<String, Object> finishVariables = new HashMap<>();
        finishVariables.put("finishedAmount", 40);
        taskService.complete(task.getId(), finishVariables);

        waitForHistoryJobExecutorToProcessAllJobs(7000, 100);

        // 4. get completed variable
        List<HistoricVariableInstance> hisVarList = historyService.createHistoricVariableInstanceQuery().taskId(task.getId()).list();
        assertThat(hisVarList)
                .extracting(HistoricVariableInstance::getValue)
                .containsExactly(40);

        // Cleanup
        historyService.deleteHistoricTaskInstance(task.getId());
        managementService.executeCommand(commandContext -> {
            CommandContextUtil.getHistoricTaskService(commandContext).deleteHistoricTaskLogEntriesForTaskId(task.getId());
            return null;
        });
    }
}
 
Example #26
Source File: CallActivityTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testInheritVariablesSubprocess() throws Exception {
    BpmnModel mainBpmnModel = loadBPMNModel(INHERIT_VARIABLES_MAIN_PROCESS_RESOURCE);
    BpmnModel childBpmnModel = loadBPMNModel(INHERIT_VARIABLES_CHILD_PROCESS_RESOURCE);

    processEngine.getRepositoryService()
            .createDeployment()
            .name("mainProcessDeployment")
            .addBpmnModel("mainProcess.bpmn20.xml", mainBpmnModel).deploy();

    processEngine.getRepositoryService()
            .createDeployment()
            .name("childProcessDeployment")
            .addBpmnModel("childProcess.bpmn20.xml", childBpmnModel).deploy();

    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("var1", "String test value");
    variables.put("var2", true);
    variables.put("var3", 12345);
    variables.put("var4", 67890);

    ProcessInstance mainProcessInstance = runtimeService.startProcessInstanceByKey("mainProcess", variables);

    HistoricActivityInstanceQuery activityInstanceQuery = historyService.createHistoricActivityInstanceQuery();
    activityInstanceQuery.processInstanceId(mainProcessInstance.getId());
    activityInstanceQuery.activityId("childProcessCall");
    HistoricActivityInstance activityInstance = activityInstanceQuery.singleResult();
    String calledInstanceId = activityInstance.getCalledProcessInstanceId();

    HistoricVariableInstanceQuery variableInstanceQuery = historyService.createHistoricVariableInstanceQuery();
    List<HistoricVariableInstance> variableInstances = variableInstanceQuery.processInstanceId(calledInstanceId).list();

    assertEquals(4, variableInstances.size());
    for (HistoricVariableInstance variable : variableInstances) {
        assertEquals(variables.get(variable.getVariableName()), variable.getValue());
    }
}
 
Example #27
Source File: HistoricVariableInstanceEscapeClauseTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByVariableNameLike() {
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
        HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().variableNameLike("%|%%").singleResult();
        assertThat(historicVariable).isNotNull();
        assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance1.getId());
        assertThat(historicVariable.getValue()).isEqualTo("One%");

        historicVariable = historyService.createHistoricVariableInstanceQuery().variableNameLike("%|_%").singleResult();
        assertThat(historicVariable).isNotNull();
        assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance2.getId());
        assertThat(historicVariable.getValue()).isEqualTo("Two_");
    }
}
 
Example #28
Source File: AsyncTaskTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testAsyncEndEvent() {
    // start process
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncEndEvent");
    // now there should be one job in the database:
    assertEquals(1, managementService.createJobQuery().count());

    Object value = runtimeService.getVariable(processInstance.getId(), "variableSetInExecutionListener");
    assertNull(value);

    waitForJobExecutorToProcessAllJobs(2000L, 200L);

    // the job is done
    assertEquals(0, managementService.createJobQuery().count());

    assertProcessEnded(processInstance.getId());

    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).list();
        assertEquals(3, variables.size());

        Object historyValue = null;
        for (HistoricVariableInstance variable : variables) {
            if ("variableSetInExecutionListener".equals(variable.getVariableName())) {
                historyValue = variable.getValue();
            }
        }
        assertEquals("firstValue", historyValue);
    }
}
 
Example #29
Source File: ProcessInstanceLogQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testIncludeVariables() {
    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.FULL, processEngineConfiguration)) {
        ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId)
                .includeVariables()
                .singleResult();
        List<HistoricData> events = log.getHistoricData();
        assertEquals(2, events.size());

        for (HistoricData event : events) {
            assertTrue(event instanceof HistoricVariableInstance);
        }
    }
}
 
Example #30
Source File: CallActivityTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testNotInheritVariablesSubprocess() throws Exception {
    BpmnModel mainBpmnModel = loadBPMNModel(NOT_INHERIT_VARIABLES_MAIN_PROCESS_RESOURCE);
    BpmnModel childBpmnModel = loadBPMNModel(INHERIT_VARIABLES_CHILD_PROCESS_RESOURCE);

    processEngine.getRepositoryService()
            .createDeployment()
            .name("childProcessDeployment")
            .addBpmnModel("childProcess.bpmn20.xml", childBpmnModel).deploy();

    processEngine.getRepositoryService()
            .createDeployment()
            .name("mainProcessDeployment")
            .addBpmnModel("mainProcess.bpmn20.xml", mainBpmnModel).deploy();

    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("var1", "String test value");
    variables.put("var2", true);
    variables.put("var3", 12345);
    variables.put("var4", 67890);

    ProcessInstance mainProcessInstance = runtimeService.startProcessInstanceByKey("mainProcess", variables);

    HistoricActivityInstanceQuery activityInstanceQuery = historyService.createHistoricActivityInstanceQuery();
    activityInstanceQuery.processInstanceId(mainProcessInstance.getId());
    activityInstanceQuery.activityId("childProcessCall");
    HistoricActivityInstance activityInstance = activityInstanceQuery.singleResult();
    String calledInstanceId = activityInstance.getCalledProcessInstanceId();

    HistoricVariableInstanceQuery variableInstanceQuery = historyService.createHistoricVariableInstanceQuery();
    variableInstanceQuery.processInstanceId(calledInstanceId);
    List<HistoricVariableInstance> variableInstances = variableInstanceQuery.list();

    assertEquals(0, variableInstances.size());
}