Search in sources :

Example 1 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class EmptyProcessTest method testRunProcessWithHeader.

@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());
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 2 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class EmptyProcessTest method testObjectAsVariable.

@Deployment(resources = { "process/empty.bpmn20.xml" })
public void testObjectAsVariable() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = ctx.createProducerTemplate();
    Object expectedObj = new Long(99);
    Exchange exchange = ctx.getEndpoint("direct:startEmpty").createExchange();
    exchange.getIn().setBody(expectedObj);
    tpl.send("direct:startEmpty", exchange);
    String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY");
    assertProcessEnded(instanceId);
    HistoricVariableInstance var = processEngine.getHistoryService().createHistoricVariableInstanceQuery().variableName("camelBody").singleResult();
    assertNotNull(var);
    assertEquals(expectedObj, var.getValue());
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 3 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class ProcessInstanceLogQueryAndByteArrayTypeVariableTest method testIncludeVariableUpdates.

public void testIncludeVariableUpdates() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).variableName("var").singleResult();
        assertEquals(historicVariableInstance.getValue(), LARGE_STRING_VALUE);
        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(((HistoricDetailVariableInstanceUpdateEntity) event).getValue(), LARGE_STRING_VALUE);
        }
    }
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricData(org.activiti.engine.history.HistoricData) ProcessInstanceHistoryLog(org.activiti.engine.history.ProcessInstanceHistoryLog) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance)

Example 4 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class ProcessInstanceLogQueryAndByteArrayTypeVariableTest method testIncludeVariables.

public void testIncludeVariables() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).variableName("var").singleResult();
        assertEquals(historicVariableInstance.getValue(), LARGE_STRING_VALUE);
        ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId).includeVariables().singleResult();
        List<HistoricData> events = log.getHistoricData();
        assertEquals(1, events.size());
        for (HistoricData event : events) {
            assertTrue(event instanceof HistoricVariableInstance);
            assertEquals(((HistoricVariableInstanceEntity) event).getValue(), LARGE_STRING_VALUE);
        }
    }
}
Also used : HistoricData(org.activiti.engine.history.HistoricData) ProcessInstanceHistoryLog(org.activiti.engine.history.ProcessInstanceHistoryLog) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance)

Example 5 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class RestResponseFactory method createProcessInstanceResponse.

public ProcessInstanceResponse createProcessInstanceResponse(ProcessInstance processInstance, boolean returnVariables, Map<String, Object> runtimeVariableMap, List<HistoricVariableInstance> historicVariableList) {
    RestUrlBuilder urlBuilder = createUrlBuilder();
    ProcessInstanceResponse result = new ProcessInstanceResponse();
    result.setActivityId(processInstance.getActivityId());
    result.setBusinessKey(processInstance.getBusinessKey());
    result.setId(processInstance.getId());
    result.setName(processInstance.getName());
    result.setProcessDefinitionId(processInstance.getProcessDefinitionId());
    result.setProcessDefinitionUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId()));
    result.setProcessDefinitionKey(processInstance.getProcessDefinitionKey());
    result.setEnded(processInstance.isEnded());
    result.setSuspended(processInstance.isSuspended());
    result.setUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
    result.setTenantId(processInstance.getTenantId());
    //Added by Ryan Johnston
    if (processInstance.isEnded()) {
        //Process complete. Note the same in the result.
        result.setCompleted(true);
    } else {
        //Process not complete. Note the same in the result.
        result.setCompleted(false);
    }
    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;
}
Also used : HistoricProcessInstanceResponse(org.activiti.rest.service.api.history.HistoricProcessInstanceResponse) ProcessInstanceResponse(org.activiti.rest.service.api.runtime.process.ProcessInstanceResponse) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance)

Aggregations

HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)56 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)28 Deployment (org.activiti.engine.test.Deployment)25 HashMap (java.util.HashMap)20 Task (org.activiti.engine.task.Task)18 HistoricVariableInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5 Test (org.junit.Test)5 HistoricData (org.activiti.engine.history.HistoricData)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)4 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 BpmnModel (org.activiti.bpmn.model.BpmnModel)3 HistoryService (org.activiti.engine.HistoryService)3 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)3 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)3 HistoricVariableInstanceQuery (org.activiti.engine.history.HistoricVariableInstanceQuery)3 ProcessInstanceHistoryLog (org.activiti.engine.history.ProcessInstanceHistoryLog)3