Java Code Examples for org.flowable.variable.api.history.HistoricVariableInstance#getValue()

The following examples show how to use org.flowable.variable.api.history.HistoricVariableInstance#getValue() . 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: 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 2
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 3
Source File: StepsUtil.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
static List<ConfigurationEntry> getDeletedEntriesFromProcess(FlowableFacade flowableFacade, String processInstanceId) {
    HistoricVariableInstance deletedEntries = flowableFacade.getHistoricVariableInstance(processInstanceId,
                                                                                         Variables.DELETED_ENTRIES.getName());
    if (deletedEntries == null) {
        return Collections.emptyList();
    }
    byte[] deletedEntriesByteArray = (byte[]) deletedEntries.getValue();
    return Arrays.asList(JsonUtil.fromJsonBinary(deletedEntriesByteArray, ConfigurationEntry[].class));
}
 
Example 4
Source File: StepsUtil.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
static List<ConfigurationEntry> getPublishedEntriesFromProcess(FlowableFacade flowableFacade, String processInstanceId) {
    HistoricVariableInstance publishedEntries = flowableFacade.getHistoricVariableInstance(processInstanceId,
                                                                                           Variables.PUBLISHED_ENTRIES.getName());
    if (publishedEntries == null) {
        return Collections.emptyList();
    }
    byte[] binaryJson = (byte[]) publishedEntries.getValue();
    return Arrays.asList(JsonUtil.fromJsonBinary(binaryJson, ConfigurationEntry[].class));
}
 
Example 5
Source File: FlowableFacade.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private String getVariableFromHistoryService(String executionId, String variableName) {
    HistoricVariableInstance historicVariableInstance = processEngine.getHistoryService()
                                                                     .createHistoricVariableInstanceQuery()
                                                                     .executionId(executionId)
                                                                     .variableName(variableName)
                                                                     .singleResult();

    if (historicVariableInstance == null) {
        return null;
    }

    return (String) historicVariableInstance.getValue();
}
 
Example 6
Source File: CustomFlowExecutionListenerTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/examples/bpmn/executionlistener/CustomFlowExecutionListenerTest.bpmn20.xml" })
public void testScriptExecutionListener() {
    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("customFlowBean", new CustomFlowBean());
    runtimeService.startProcessInstanceByKey("scriptExecutionListenerProcess", variableMap);
    HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery().variableName("flow1_activiti_conditions").singleResult();
    assertNotNull(variable);
    assertEquals("flow1_activiti_conditions", variable.getVariableName());
    @SuppressWarnings("unchecked")
    List<String> conditions = (List<String>) variable.getValue();
    assertEquals(2, conditions.size());
    assertEquals("hello", conditions.get(0));
    assertEquals("world", conditions.get(1));
}
 
Example 7
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 8
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 9
Source File: HistoricCaseInstanceVariableDataResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public RestVariable getVariableFromRequest(boolean includeBinary, String caseInstanceId, String variableName, HttpServletRequest request) {
    HistoricCaseInstance caseObject = getHistoricCaseInstanceFromRequest(caseInstanceId);

    HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery()
                    .caseInstanceId(caseObject.getId())
                    .variableName(variableName)
                    .singleResult();

    if (variable == null || variable.getValue() == null) {
        throw new FlowableObjectNotFoundException("Historic case instance '" + caseInstanceId + "' variable value for " + variableName + " couldn't be found.", VariableInstanceEntity.class);
    } else {
        return restResponseFactory.createRestVariable(variableName, variable.getValue(), null, caseInstanceId, CmmnRestResponseFactory.VARIABLE_HISTORY_CASE, includeBinary);
    }
}
 
Example 10
Source File: CustomFlowExecutionListenerTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/examples/bpmn/executionlistener/CustomFlowExecutionListenerTest.bpmn20.xml" })
public void testScriptExecutionListener() {
    Map<String, Object> variableMap = new HashMap<>();
    variableMap.put("customFlowBean", new CustomFlowBean());
    runtimeService.startProcessInstanceByKey("scriptExecutionListenerProcess", variableMap);
    HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery().variableName("flow1_activiti_conditions").singleResult();
    assertThat(variable).isNotNull();
    assertThat(variable.getVariableName()).isEqualTo("flow1_activiti_conditions");
    @SuppressWarnings("unchecked")
    List<String> conditions = (List<String>) variable.getValue();
    assertThat(conditions)
            .containsExactly("hello", "world");
}
 
Example 11
Source File: HistoryUtil.java    From multiapps-controller with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T> T getValue(HistoricVariableInstance variable) {
    return variable == null ? null : (T) variable.getValue();
}
 
Example 12
Source File: ProcessInstanceHistoryLogQueryImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessInstanceHistoryLog execute(CommandContext commandContext) {

    // Fetch historic process instance
    HistoricProcessInstanceEntity historicProcessInstance = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext).findById(processInstanceId);

    if (historicProcessInstance == null) {
        return null;
    }

    // Create a log using this historic process instance
    ProcessInstanceHistoryLogImpl processInstanceHistoryLog = new ProcessInstanceHistoryLogImpl(historicProcessInstance);

    // Add events, based on query settings

    // Tasks
    if (includeTasks) {
        List<? extends HistoricData> tasks = CommandContextUtil.getHistoricTaskService().findHistoricTaskInstancesByQueryCriteria(
                        new HistoricTaskInstanceQueryImpl(commandExecutor).processInstanceId(processInstanceId));
        processInstanceHistoryLog.addHistoricData(tasks);
    }

    // Activities
    if (includeActivities) {
        List<HistoricActivityInstance> activities = CommandContextUtil.getHistoricActivityInstanceEntityManager(commandContext).findHistoricActivityInstancesByQueryCriteria(
                new HistoricActivityInstanceQueryImpl(commandExecutor).processInstanceId(processInstanceId));
        processInstanceHistoryLog.addHistoricData(activities);
    }

    // Variables
    if (includeVariables) {
        List<HistoricVariableInstance> variables = CommandContextUtil.getHistoricVariableService().findHistoricVariableInstancesByQueryCriteria(
                new HistoricVariableInstanceQueryImpl(commandExecutor).processInstanceId(processInstanceId));

        // Make sure all variables values are fetched (similar to the HistoricVariableInstance query)
        for (HistoricVariableInstance historicVariableInstance : variables) {
            historicVariableInstance.getValue();

            // make sure JPA entities are cached for later retrieval
            HistoricVariableInstanceEntity variableEntity = (HistoricVariableInstanceEntity) historicVariableInstance;
            if (JPAEntityVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName()) || JPAEntityListVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName())) {
                ((CacheableVariable) variableEntity.getVariableType()).setForceCacheable(true);
            }
        }

        processInstanceHistoryLog.addHistoricData(variables);
    }

    // Comment
    if (includeComments) {
        List<? extends HistoricData> comments = CommandContextUtil.getCommentEntityManager(commandContext).findCommentsByProcessInstanceId(processInstanceId);
        processInstanceHistoryLog.addHistoricData(comments);
    }

    // Details: variables
    if (includeVariableUpdates) {
        List<? extends HistoricData> variableUpdates = CommandContextUtil.getHistoricDetailEntityManager(commandContext).findHistoricDetailsByQueryCriteria(
                new HistoricDetailQueryImpl(commandExecutor).variableUpdates());

        // Make sure all variables values are fetched (similar to the HistoricVariableInstance query)
        for (HistoricData historicData : variableUpdates) {
            HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) historicData;
            variableUpdate.getValue();
        }

        processInstanceHistoryLog.addHistoricData(variableUpdates);
    }

    // Details: form properties
    if (includeFormProperties) {
        List<? extends HistoricData> formProperties = CommandContextUtil.getHistoricDetailEntityManager(commandContext).findHistoricDetailsByQueryCriteria(
                new HistoricDetailQueryImpl(commandExecutor).formProperties());
        processInstanceHistoryLog.addHistoricData(formProperties);
    }

    // All events collected. Sort them by date.
    processInstanceHistoryLog.orderHistoricData();

    return processInstanceHistoryLog;
}