Search in sources :

Example 31 with HistoricVariableInstance

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

the class DynamicServiceTaskTest method testChangeExpression.

@Deployment
public void testChangeExpression() {
    // first test without changing the class name
    DummyTestBean testBean = new DummyTestBean();
    Map<String, Object> varMap = new HashMap<String, Object>();
    varMap.put("bean", testBean);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("executed").singleResult();
        assertThat(historicVariableInstance).isNotNull();
        assertThat((Boolean) historicVariableInstance.getValue()).isTrue();
    }
    assertProcessEnded(processInstance.getId());
    // now test with changing the class name
    testBean = new DummyTestBean();
    varMap = new HashMap<String, Object>();
    varMap.put("bean2", testBean);
    processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
    String processDefinitionId = processInstance.getProcessDefinitionId();
    ObjectNode infoNode = dynamicBpmnService.changeServiceTaskExpression("service", "${bean2.test(execution)}");
    dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("executed").singleResult();
        assertThat(historicVariableInstance).isNotNull();
        assertThat((Boolean) historicVariableInstance.getValue()).isTrue();
    }
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 32 with HistoricVariableInstance

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

the class DynamicServiceTaskTest method testChangeDelegateExpression.

@Deployment
public void testChangeDelegateExpression() {
    // first test without changing the class name
    DummyTestDelegateBean testBean = new DummyTestDelegateBean();
    Map<String, Object> varMap = new HashMap<String, Object>();
    varMap.put("bean", testBean);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("executed").singleResult();
        assertThat(historicVariableInstance).isNotNull();
        assertThat((Boolean) historicVariableInstance.getValue()).isTrue();
    }
    assertProcessEnded(processInstance.getId());
    // now test with changing the class name
    testBean = new DummyTestDelegateBean();
    varMap = new HashMap<String, Object>();
    varMap.put("bean2", testBean);
    processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);
    String processDefinitionId = processInstance.getProcessDefinitionId();
    ObjectNode infoNode = dynamicBpmnService.changeServiceTaskDelegateExpression("service", "${bean2}");
    dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("executed").singleResult();
        assertThat(historicVariableInstance).isNotNull();
        assertThat((Boolean) historicVariableInstance.getValue()).isTrue();
    }
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 33 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowHistoricProcessInstanceService method toDto.

private WorkflowHistoricProcessInstanceDto toDto(HistoricProcessInstance instance, boolean trimmed) {
    if (instance == null) {
        return null;
    }
    String instanceName = instance.getName();
    // processInstanceName
    if (instanceName == null && instance.getProcessVariables() != null && instance.getProcessVariables().containsKey(WorkflowHistoricProcessInstanceService.PROCESS_INSTANCE_NAME)) {
        instanceName = (String) instance.getProcessVariables().get(WorkflowHistoricProcessInstanceService.PROCESS_INSTANCE_NAME);
    }
    // historic variables
    if (instanceName == null || instanceName.isEmpty()) {
        HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(instance.getId()).variableName(WorkflowHistoricProcessInstanceService.PROCESS_INSTANCE_NAME).singleResult();
        instanceName = variableInstance != null ? (String) variableInstance.getValue() : null;
    }
    if (instanceName == null || instanceName.isEmpty()) {
        instanceName = definitionService.get(instance.getProcessDefinitionId()).getName();
    }
    WorkflowHistoricProcessInstanceDto dto = new WorkflowHistoricProcessInstanceDto();
    dto.setTrimmed(trimmed);
    dto.setId(instance.getId());
    dto.setName(instanceName);
    dto.setProcessDefinitionId(instance.getProcessDefinitionId());
    dto.setProcessDefinitionKey(instance.getProcessDefinitionKey());
    dto.setProcessVariables(instance.getProcessVariables());
    dto.setDeleteReason(instance.getDeleteReason());
    dto.setDurationInMillis(instance.getDurationInMillis());
    dto.setEndTime(instance.getEndTime());
    dto.setStartActivityId(instance.getStartActivityId());
    dto.setStartTime(instance.getStartTime());
    dto.setStartUserId(instance.getStartUserId());
    dto.setSuperProcessInstanceId(instance.getSuperProcessInstanceId());
    return dto;
}
Also used : HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto)

Example 34 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project alfresco-remote-api by Alfresco.

the class ProcessesImpl method getVariables.

@Override
public CollectionWithPagingInfo<Variable> getVariables(String processId, Paging paging) {
    CollectionWithPagingInfo<Variable> result = null;
    // Check if user is allowed to get variables
    List<HistoricVariableInstance> variableInstances = validateIfUserAllowedToWorkWithProcess(processId);
    Map<String, Object> variables = new HashMap<String, Object>();
    for (HistoricVariableInstance variable : variableInstances) {
        variables.put(variable.getVariableName(), variable.getValue());
    }
    ProcessInstance processInstance = activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processId).singleResult();
    String processDefinitionId = null;
    if (processInstance != null) {
        processDefinitionId = processInstance.getProcessDefinitionId();
    } else {
        // Completed process instance
        HistoricProcessInstance historicInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (historicInstance == null) {
            throw new EntityNotFoundException(processId);
        }
        processDefinitionId = historicInstance.getProcessDefinitionId();
    }
    // Get start-task definition for explicit typing of variables submitted at the start
    String formKey = null;
    StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processDefinitionId);
    if (startFormData != null) {
        formKey = startFormData.getFormKey();
    }
    TypeDefinition startTaskTypeDefinition = getWorkflowFactory().getTaskFullTypeDefinition(formKey, true);
    // Convert raw variables to Variable objects
    List<Variable> resultingVariables = restVariableHelper.getVariables(variables, startTaskTypeDefinition);
    result = CollectionWithPagingInfo.asPaged(paging, resultingVariables);
    return result;
}
Also used : Variable(org.alfresco.rest.workflow.api.model.Variable) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) StartFormData(org.activiti.engine.form.StartFormData) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 35 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project alfresco-remote-api by Alfresco.

the class WorkflowRestImpl method getItemsFromProcess.

/**
 * Get all items from the process package variable
 */
public CollectionWithPagingInfo<Item> getItemsFromProcess(String processId, Paging paging) {
    ActivitiScriptNode packageScriptNode = null;
    try {
        HistoricVariableInstance variableInstance = activitiProcessEngine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(processId).variableName(BPM_PACKAGE).singleResult();
        if (variableInstance != null) {
            packageScriptNode = (ActivitiScriptNode) variableInstance.getValue();
        } else {
            throw new EntityNotFoundException(processId);
        }
    } catch (ActivitiObjectNotFoundException e) {
        throw new EntityNotFoundException(processId);
    }
    List<Item> page = new ArrayList<Item>();
    if (packageScriptNode != null) {
        List<ChildAssociationRef> documentList = nodeService.getChildAssocs(packageScriptNode.getNodeRef());
        for (ChildAssociationRef childAssociationRef : documentList) {
            Item item = createItemForNodeRef(childAssociationRef.getChildRef());
            page.add(item);
        }
    }
    return CollectionWithPagingInfo.asPaged(paging, page, false, page.size());
}
Also used : Item(org.alfresco.rest.workflow.api.model.Item) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) ArrayList(java.util.ArrayList) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

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