Search in sources :

Example 11 with HistoricDetail

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

the class HistoricDetailDataResource method getVariableFromRequest.

public RestVariable getVariableFromRequest(boolean includeBinary, String detailId, HttpServletRequest request) {
    Object value = null;
    HistoricVariableUpdate variableUpdate = null;
    HistoricDetail detailObject = historyService.createHistoricDetailQuery().id(detailId).singleResult();
    if (detailObject instanceof HistoricVariableUpdate) {
        variableUpdate = (HistoricVariableUpdate) detailObject;
        value = variableUpdate.getValue();
    }
    if (value == null) {
        throw new ActivitiObjectNotFoundException("Historic detail '" + detailId + "' doesn't have a variable value.", VariableInstanceEntity.class);
    } else {
        return restResponseFactory.createRestVariable(variableUpdate.getVariableName(), value, null, detailId, RestResponseFactory.VARIABLE_HISTORY_DETAIL, includeBinary);
    }
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 12 with HistoricDetail

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

the class RestResponseFactory method createHistoricDetailResponse.

public List<HistoricDetailResponse> createHistoricDetailResponse(List<HistoricDetail> detailList) {
    RestUrlBuilder urlBuilder = createUrlBuilder();
    List<HistoricDetailResponse> responseList = new ArrayList<HistoricDetailResponse>();
    for (HistoricDetail instance : detailList) {
        responseList.add(createHistoricDetailResponse(instance, urlBuilder));
    }
    return responseList;
}
Also used : HistoricDetail(org.activiti.engine.history.HistoricDetail) HistoricDetailResponse(org.activiti.rest.service.api.history.HistoricDetailResponse) ArrayList(java.util.ArrayList)

Example 13 with HistoricDetail

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

the class FullHistoryTest method testReadJpaVariableValueFromHistoricVariableUpdate.

@Deployment(resources = { "org/activiti/standalone/jpa/JPAVariableTest.testQueryJPAVariable.bpmn20.xml" })
public void testReadJpaVariableValueFromHistoricVariableUpdate() {
    EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) processEngineConfiguration.getSessionFactories().get(EntityManagerSession.class);
    EntityManagerFactory entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();
    String executionId = runtimeService.startProcessInstanceByKey("JPAVariableProcess").getProcessInstanceId();
    String variableName = "name";
    FieldAccessJPAEntity entity = new FieldAccessJPAEntity();
    entity.setId(1L);
    entity.setValue("Test");
    EntityManager manager = entityManagerFactory.createEntityManager();
    manager.getTransaction().begin();
    manager.persist(entity);
    manager.flush();
    manager.getTransaction().commit();
    manager.close();
    Task task = taskService.createTaskQuery().processInstanceId(executionId).taskName("my task").singleResult();
    runtimeService.setVariable(executionId, variableName, entity);
    taskService.complete(task.getId());
    List<HistoricDetail> variableUpdates = historyService.createHistoricDetailQuery().processInstanceId(executionId).variableUpdates().list();
    assertEquals(1, variableUpdates.size());
    HistoricVariableUpdate update = (HistoricVariableUpdate) variableUpdates.get(0);
    assertNotNull(update.getValue());
    assertTrue(update.getValue() instanceof FieldAccessJPAEntity);
    assertEquals(entity.getId(), ((FieldAccessJPAEntity) update.getValue()).getId());
}
Also used : EntityManagerSession(org.activiti.engine.impl.variable.EntityManagerSession) HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) EntityManagerSessionFactory(org.activiti.engine.impl.variable.EntityManagerSessionFactory) HistoricDetail(org.activiti.engine.history.HistoricDetail) EntityManager(javax.persistence.EntityManager) Task(org.activiti.engine.task.Task) EntityManagerFactory(javax.persistence.EntityManagerFactory) FieldAccessJPAEntity(org.activiti.standalone.jpa.FieldAccessJPAEntity) Deployment(org.activiti.engine.test.Deployment)

Example 14 with HistoricDetail

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

the class FullHistoryTest method testVariableUpdatesLinkedToActivity.

@Deployment(resources = { "org/activiti/standalone/history/FullHistoryTest.testVariableUpdatesAreLinkedToActivity.bpmn20.xml" })
public void testVariableUpdatesLinkedToActivity() throws Exception {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("ProcessWithSubProcess");
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("test", "1");
    taskService.complete(task.getId(), variables);
    // now we are in the subprocess
    task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    variables.clear();
    variables.put("test", "2");
    taskService.complete(task.getId(), variables);
    // now we are ended
    assertProcessEnded(pi.getId());
    // check history
    List<HistoricDetail> updates = historyService.createHistoricDetailQuery().variableUpdates().list();
    assertEquals(2, updates.size());
    Map<String, HistoricVariableUpdate> updatesMap = new HashMap<String, HistoricVariableUpdate>();
    HistoricVariableUpdate update = (HistoricVariableUpdate) updates.get(0);
    updatesMap.put((String) update.getValue(), update);
    update = (HistoricVariableUpdate) updates.get(1);
    updatesMap.put((String) update.getValue(), update);
    HistoricVariableUpdate update1 = updatesMap.get("1");
    HistoricVariableUpdate update2 = updatesMap.get("2");
    assertNotNull(update1.getActivityInstanceId());
    assertNotNull(update1.getExecutionId());
    HistoricActivityInstance historicActivityInstance1 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update1.getActivityInstanceId()).singleResult();
    assertEquals(historicActivityInstance1.getExecutionId(), update1.getExecutionId());
    assertEquals("usertask1", historicActivityInstance1.getActivityId());
    assertNotNull(update2.getActivityInstanceId());
    HistoricActivityInstance historicActivityInstance2 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update2.getActivityInstanceId()).singleResult();
    assertEquals("usertask2", historicActivityInstance2.getActivityId());
    /*
     * This is OK! The variable is set on the root execution, on a execution never run through the activity, where the process instances
     * stands when calling the set Variable. But the ActivityId of this flow node is used. So the execution id's doesn't have to be equal.
     * 
     * execution id: On which execution it was set
     * activity id: in which activity was the process instance when setting the variable
     */
    assertFalse(historicActivityInstance2.getExecutionId().equals(update2.getExecutionId()));
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 15 with HistoricDetail

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

the class FullHistoryTest method testHistoricFormProperties.

@Deployment
public void testHistoricFormProperties() throws Exception {
    Date startedDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss SSS").parse("01/01/2001 01:23:46 000");
    processEngineConfiguration.getClock().setCurrentTime(startedDate);
    Map<String, String> formProperties = new HashMap<String, String>();
    formProperties.put("formProp1", "Activiti rocks");
    formProperties.put("formProp2", "12345");
    ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("historicFormPropertiesProcess").singleResult();
    ProcessInstance processInstance = formService.submitStartFormData(procDef.getId(), formProperties);
    // Submit form-properties on the created task
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    // Out execution only has a single activity waiting, the task
    List<String> activityIds = runtimeService.getActiveActivityIds(task.getExecutionId());
    assertNotNull(activityIds);
    assertEquals(1, activityIds.size());
    String taskActivityId = activityIds.get(0);
    // Submit form properties
    formProperties = new HashMap<String, String>();
    formProperties.put("formProp3", "Activiti still rocks!!!");
    formProperties.put("formProp4", "54321");
    formService.submitTaskFormData(task.getId(), formProperties);
    // 4 historic form properties should be created. 2 when process started, 2 when task completed
    List<HistoricDetail> props = historyService.createHistoricDetailQuery().formProperties().processInstanceId(processInstance.getId()).orderByFormPropertyId().asc().list();
    HistoricFormProperty historicProperty1 = (HistoricFormProperty) props.get(0);
    assertEquals("formProp1", historicProperty1.getPropertyId());
    assertEquals("Activiti rocks", historicProperty1.getPropertyValue());
    assertEquals(startedDate, historicProperty1.getTime());
    assertEquals(processInstance.getId(), historicProperty1.getProcessInstanceId());
    assertNull(historicProperty1.getTaskId());
    assertNotNull(historicProperty1.getActivityInstanceId());
    HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityInstanceId(historicProperty1.getActivityInstanceId()).singleResult();
    assertNotNull(historicActivityInstance);
    assertEquals("start", historicActivityInstance.getActivityId());
    HistoricFormProperty historicProperty2 = (HistoricFormProperty) props.get(1);
    assertEquals("formProp2", historicProperty2.getPropertyId());
    assertEquals("12345", historicProperty2.getPropertyValue());
    assertEquals(startedDate, historicProperty2.getTime());
    assertEquals(processInstance.getId(), historicProperty2.getProcessInstanceId());
    assertNull(historicProperty2.getTaskId());
    assertNotNull(historicProperty2.getActivityInstanceId());
    historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityInstanceId(historicProperty2.getActivityInstanceId()).singleResult();
    assertNotNull(historicActivityInstance);
    assertEquals("start", historicActivityInstance.getActivityId());
    HistoricFormProperty historicProperty3 = (HistoricFormProperty) props.get(2);
    assertEquals("formProp3", historicProperty3.getPropertyId());
    assertEquals("Activiti still rocks!!!", historicProperty3.getPropertyValue());
    assertEquals(startedDate, historicProperty3.getTime());
    assertEquals(processInstance.getId(), historicProperty3.getProcessInstanceId());
    String activityInstanceId = historicProperty3.getActivityInstanceId();
    historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityInstanceId(activityInstanceId).singleResult();
    assertNotNull(historicActivityInstance);
    assertEquals(taskActivityId, historicActivityInstance.getActivityId());
    assertNotNull(historicProperty3.getTaskId());
    HistoricFormProperty historicProperty4 = (HistoricFormProperty) props.get(3);
    assertEquals("formProp4", historicProperty4.getPropertyId());
    assertEquals("54321", historicProperty4.getPropertyValue());
    assertEquals(startedDate, historicProperty4.getTime());
    assertEquals(processInstance.getId(), historicProperty4.getProcessInstanceId());
    activityInstanceId = historicProperty4.getActivityInstanceId();
    historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityInstanceId(activityInstanceId).singleResult();
    assertNotNull(historicActivityInstance);
    assertEquals(taskActivityId, historicActivityInstance.getActivityId());
    assertNotNull(historicProperty4.getTaskId());
    assertEquals(4, props.size());
}
Also used : HistoricDetail(org.activiti.engine.history.HistoricDetail) Task(org.activiti.engine.task.Task) HistoricFormProperty(org.activiti.engine.history.HistoricFormProperty) HashMap(java.util.HashMap) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Date(java.util.Date) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SimpleDateFormat(java.text.SimpleDateFormat) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

HistoricDetail (org.activiti.engine.history.HistoricDetail)19 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)11 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)10 Deployment (org.activiti.engine.test.Deployment)10 HashMap (java.util.HashMap)9 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)7 Task (org.activiti.engine.task.Task)7 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)6 HistoricFormProperty (org.activiti.engine.history.HistoricFormProperty)4 HistoricDetailVariableInstanceUpdateEntity (org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity)3 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2 HistoryService (org.activiti.engine.HistoryService)2 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)2 HistoricVariableInstanceQuery (org.activiti.engine.history.HistoricVariableInstanceQuery)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 Item (com.vaadin.data.Item)1 Label (com.vaadin.ui.Label)1