Search in sources :

Example 16 with HistoricVariableUpdate

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

the class TaskServiceTest method testGetVariableByHistoricActivityInstance.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testGetVariableByHistoricActivityInstance() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        assertThat(processInstance).isNotNull();
        Task task = taskService.createTaskQuery().singleResult();
        taskService.setVariable(task.getId(), "variable1", "value1");
        taskService.setVariable(task.getId(), "variable1", "value2");
        HistoricActivityInstance historicActivitiInstance = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("theTask").singleResult();
        assertThat(historicActivitiInstance).isNotNull();
        List<HistoricDetail> resultSet = historyService.createHistoricDetailQuery().variableUpdates().activityInstanceId(historicActivitiInstance.getId()).list();
        assertThat(resultSet).hasSize(2);
        assertThat(resultSet).extracting(h -> ((HistoricVariableUpdate) h).getValue()).containsExactlyInAnyOrder("value1", "value2");
        assertThat(resultSet).extracting(h -> ((HistoricVariableUpdate) h).getVariableName()).containsOnly("variable1");
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) PluggableActivitiTestCase(org.activiti.engine.impl.test.PluggableActivitiTestCase) Date(java.util.Date) Authentication(org.activiti.engine.impl.identity.Authentication) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ActivitiTaskAlreadyClaimedException(org.activiti.engine.ActivitiTaskAlreadyClaimedException) HistoricDetail(org.activiti.engine.history.HistoricDetail) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) DelegationState(org.activiti.engine.task.DelegationState) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) Collections.singletonList(java.util.Collections.singletonList) CommentEntity(org.activiti.engine.impl.persistence.entity.CommentEntity) Arrays.asList(java.util.Arrays.asList) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Map(java.util.Map) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Collections.singletonMap(java.util.Collections.singletonMap) ActivitiOptimisticLockingException(org.activiti.engine.ActivitiOptimisticLockingException) Event(org.activiti.engine.task.Event) HistoricDetailVariableInstanceUpdateEntity(org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity) Task(org.activiti.engine.task.Task) Collections.emptyMap(java.util.Collections.emptyMap) IdentityLink(org.activiti.engine.task.IdentityLink) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) Collections.emptyList(java.util.Collections.emptyList) HistoryLevel(org.activiti.engine.impl.history.HistoryLevel) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Attachment(org.activiti.engine.task.Attachment) Comment(org.activiti.engine.task.Comment) List(java.util.List) TaskServiceImpl(org.activiti.engine.impl.TaskServiceImpl) Collections(java.util.Collections) Deployment(org.activiti.engine.test.Deployment) HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 17 with HistoricVariableUpdate

use of org.activiti.engine.history.HistoricVariableUpdate in project alfresco-repository by Alfresco.

the class ActivitiPropertyConverter method convertHistoricDetails.

/**
 * Convert a list of {@link HistoricDetail} to a map with key-value pairs.
 * @param details the histroicDetails. Should be a list of {@link HistoricVariableUpdate}s.
 */
public Map<String, Object> convertHistoricDetails(List<HistoricDetail> details) {
    HashMap<String, HistoricVariableUpdate> updateMap = new HashMap<String, HistoricVariableUpdate>();
    HistoricVariableUpdate previous = null;
    HistoricVariableUpdate current = null;
    boolean isMoreRecent = false;
    for (HistoricDetail detail : details) {
        current = (HistoricVariableUpdate) detail;
        previous = updateMap.get(current.getVariableName());
        if (previous == null) {
            isMoreRecent = true;
        } else {
            // Check if this update is more recent that the one already present in the map
            if (current.getTime().equals(previous.getTime())) {
                if (current.getRevision() == previous.getRevision()) {
                    // Revert to comparison of the ID
                    isMoreRecent = Long.valueOf(current.getId()).longValue() > Long.valueOf(previous.getId()).longValue();
                } else {
                    isMoreRecent = current.getRevision() > previous.getRevision();
                }
            } else {
                isMoreRecent = current.getTime().after(previous.getTime());
            }
        }
        // Add to the map if value is more recent than existing value or is the first value for this update
        if (isMoreRecent) {
            updateMap.put(current.getVariableName(), current);
        }
    }
    HashMap<String, Object> variables = new HashMap<String, Object>();
    for (Entry<String, HistoricVariableUpdate> entry : updateMap.entrySet()) {
        variables.put(entry.getKey(), entry.getValue().getValue());
    }
    return variables;
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) HashMap(java.util.HashMap)

Aggregations

HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)17 HistoricDetail (org.activiti.engine.history.HistoricDetail)14 HashMap (java.util.HashMap)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)8 Deployment (org.activiti.engine.test.Deployment)8 Task (org.activiti.engine.task.Task)6 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)5 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)5 HistoricFormProperty (org.activiti.engine.history.HistoricFormProperty)4 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)4 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 HistoryService (org.activiti.engine.HistoryService)2 HistoricData (org.activiti.engine.history.HistoricData)2 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)2 HistoricVariableInstanceQuery (org.activiti.engine.history.HistoricVariableInstanceQuery)2 Item (com.vaadin.data.Item)1 Label (com.vaadin.ui.Label)1 Table (com.vaadin.ui.Table)1