org.camunda.bpm.engine.impl.history.event.HistoricTaskInstanceEventEntity Java Examples

The following examples show how to use org.camunda.bpm.engine.impl.history.event.HistoricTaskInstanceEventEntity. 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: CamundaEventingIT.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEventHistoryTaskFollowUpDateChanges() {
  // given
  startEventingInstance();
  Task task = taskService.createTaskQuery().active().singleResult();
  eventCaptor.clear();

  Date now = DateUtil.now();

  // when
  task.setFollowUpDate(now);
  taskService.saveTask(task);

  // then
  HistoryEvent taskChangeEvent = eventCaptor.historyEvents.pop();
  assertThat(taskChangeEvent.getEventType()).isEqualTo("update");
  if (taskChangeEvent instanceof HistoricTaskInstanceEventEntity) {
    assertThat(((HistoricTaskInstanceEventEntity) taskChangeEvent).getFollowUpDate()).isEqualTo(now);
  } else {
    fail("Expected task instance change event");
  }
}
 
Example #2
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public HistoryEvent createTaskInstanceCompleteEvt(DelegateTask task, String deleteReason) {

    // create event instance
    HistoricTaskInstanceEventEntity evt = loadTaskInstanceEvent(task);

    // initialize event
    initTaskInstanceEvent(evt, (TaskEntity) task, HistoryEventTypes.TASK_INSTANCE_COMPLETE);

    // set end time
    evt.setEndTime(ClockUtil.getCurrentTime());
    if(evt.getStartTime() != null) {
      evt.setDurationInMillis(evt.getEndTime().getTime()-evt.getStartTime().getTime());
    }

    // set delete reason
    evt.setDeleteReason(deleteReason);

    return evt;
  }
 
Example #3
Source File: CamundaEventingIT.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEventHistoryTaskAttributeChanges() {
  // given
  startEventingInstance();
  Task task = taskService.createTaskQuery().active().singleResult();
  eventCaptor.clear();

  // when
  task.setName("new Name");
  taskService.saveTask(task);

  // then
  HistoryEvent taskChangeEvent = eventCaptor.historyEvents.pop();
  assertThat(taskChangeEvent.getEventType()).isEqualTo("update");
  if (taskChangeEvent instanceof HistoricTaskInstanceEventEntity) {
    assertThat(((HistoricTaskInstanceEventEntity) taskChangeEvent).getName()).isEqualTo("new Name");
  } else {
    fail("Expected task instance change event");
  }

}
 
Example #4
Source File: CamundaEventingIT.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEventHistoryTaskAttributeChanges() {
  // given
  startEventingInstance();
  Task task = taskService.createTaskQuery().active().singleResult();
  eventCaptor.clear();

  // when
  task.setName("new Name");
  taskService.saveTask(task);

  // then
  HistoryEvent taskChangeEvent = eventCaptor.historyEvents.pop();
  assertThat(taskChangeEvent.getEventType()).isEqualTo("update");
  if (taskChangeEvent instanceof HistoricTaskInstanceEventEntity) {
    assertThat(((HistoricTaskInstanceEventEntity) taskChangeEvent).getName()).isEqualTo("new Name");
  } else {
    fail("Expected task instance change event");
  }

}
 
Example #5
Source File: CamundaEventingIT.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEventHistoryTaskFollowUpDateChanges() {
  // given
  startEventingInstance();
  Task task = taskService.createTaskQuery().active().singleResult();
  eventCaptor.clear();

  Date now = DateUtil.now();

  // when
  task.setFollowUpDate(now);
  taskService.saveTask(task);

  // then
  HistoryEvent taskChangeEvent = eventCaptor.historyEvents.pop();
  assertThat(taskChangeEvent.getEventType()).isEqualTo("update");
  if (taskChangeEvent instanceof HistoricTaskInstanceEventEntity) {
    assertThat(((HistoricTaskInstanceEventEntity) taskChangeEvent).getFollowUpDate()).isEqualTo(now);
  } else {
    fail("Expected task instance change event");
  }
}
 
Example #6
Source File: ElasticSearchDefaultIndexStrategy.java    From camunda-bpm-elasticsearch with Apache License 2.0 5 votes vote down vote up
protected boolean filterEvents(HistoryEvent historyEvent) {
  if (historyEvent instanceof HistoricProcessInstanceEventEntity ||
      historyEvent instanceof HistoricActivityInstanceEventEntity ||
      historyEvent instanceof HistoricTaskInstanceEventEntity ||
      historyEvent instanceof HistoricVariableUpdateEventEntity) {
    return false;
  }
  return true;
}
 
Example #7
Source File: ElasticSearchDefaultIndexStrategy.java    From camunda-bpm-elasticsearch with Apache License 2.0 5 votes vote down vote up
protected UpdateRequestBuilder prepareUpdateRequest(HistoryEvent historyEvent) throws IOException {
    UpdateRequestBuilder updateRequestBuilder = esClient.prepareUpdate()
        .setIndex(dispatcher.getDispatchTargetIndex(historyEvent))
        .setId(historyEvent.getProcessInstanceId());

    String dispatchTargetType = dispatcher.getDispatchTargetType(historyEvent);
    if (dispatchTargetType != null && !dispatchTargetType.isEmpty()) {
      updateRequestBuilder.setType(dispatchTargetType);
    }

    if (historyEvent instanceof HistoricProcessInstanceEventEntity) {
      prepareHistoricProcessInstanceEventUpdate(historyEvent, updateRequestBuilder);
    } else if (historyEvent instanceof HistoricActivityInstanceEventEntity ||
               historyEvent instanceof HistoricTaskInstanceEventEntity ||
               historyEvent instanceof HistoricVariableUpdateEventEntity) {
      updateRequestBuilder = prepareOtherHistoricEventsUpdateRequest(historyEvent, updateRequestBuilder);
    } else {
      // unknown event - insert...
      throw new IllegalArgumentException("Unknown event detected: '" + historyEvent + "'");
//      LOGGER.warning("Unknown event detected: '" + historyEvent + "'");
    }

    if (LOGGER.isLoggable(Level.FINE)) {
      updateRequestBuilder.setFields("_source");
    }

    return updateRequestBuilder;
  }
 
Example #8
Source File: ElasticSearchDefaultIndexStrategy.java    From camunda-bpm-elasticsearch with Apache License 2.0 5 votes vote down vote up
protected UpdateRequestBuilder prepareOtherHistoricEventsUpdateRequest(HistoryEvent historyEvent, UpdateRequestBuilder updateRequestBuilder) throws IOException {
  HashMap<String, Object> scriptParams = new HashMap<String, Object>();

  if (historyEvent instanceof HistoricActivityInstanceEventEntity) {
    scriptParams.put("isActivityInstanceEvent", true);
    scriptParams.put("isTaskInstanceEvent", false);
    scriptParams.put("isVariableUpdateEvent", false);
  } else if (historyEvent instanceof HistoricTaskInstanceEventEntity) {
    scriptParams.put("isActivityInstanceEvent", false);
    scriptParams.put("isTaskInstanceEvent", true);
    scriptParams.put("isVariableUpdateEvent", false);
  } else {
    scriptParams.put("isActivityInstanceEvent", false);
    scriptParams.put("isTaskInstanceEvent", false);
    scriptParams.put("isVariableUpdateEvent", true);
  }

  String eventJson = transformer.transformToJson(historyEvent);
  // needed otherwise the resulting json is not an array/list and the update script throws an error
  List<Map<String,Object>> events = transformer.transformJsonToList("[" + eventJson + "]");
  scriptParams.put("value", events);

  updateRequestBuilder.setScript(ES_INDEX_UPDATE_SCRIPT, ScriptService.ScriptType.INLINE)
      .setScriptParams(scriptParams);

  return updateRequestBuilder;
}
 
Example #9
Source File: HistoricTaskInstanceManager.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void addRemovalTimeToTaskInstancesByRootProcessInstanceId(String rootProcessInstanceId, Date removalTime) {
  Map<String, Object> parameters = new HashMap<>();
  parameters.put("rootProcessInstanceId", rootProcessInstanceId);
  parameters.put("removalTime", removalTime);

  getDbEntityManager()
    .updatePreserveOrder(HistoricTaskInstanceEventEntity.class, "updateHistoricTaskInstancesByRootProcessInstanceId", parameters);
}
 
Example #10
Source File: HistoricTaskInstanceManager.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void addRemovalTimeToTaskInstancesByProcessInstanceId(String processInstanceId, Date removalTime) {
  Map<String, Object> parameters = new HashMap<>();
  parameters.put("processInstanceId", processInstanceId);
  parameters.put("removalTime", removalTime);

  getDbEntityManager()
    .updatePreserveOrder(HistoricTaskInstanceEventEntity.class, "updateHistoricTaskInstancesByProcessInstanceId", parameters);
}
 
Example #11
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public HistoryEvent createTaskInstanceMigrateEvt(DelegateTask task) {
  // create event instance
  HistoricTaskInstanceEventEntity evt = loadTaskInstanceEvent(task);

  // initialize event
  initTaskInstanceEvent(evt, (TaskEntity) task, HistoryEventTypes.TASK_INSTANCE_MIGRATE);

  return evt;
}
 
Example #12
Source File: ElasticSearchProcessInstanceHistoryEntity.java    From camunda-bpm-elasticsearch with Apache License 2.0 4 votes vote down vote up
public void setTasks(List<HistoricTaskInstanceEventEntity> tasks) {
  this.tasks = tasks;
}
 
Example #13
Source File: ElasticSearchProcessInstanceHistoryEntity.java    From camunda-bpm-elasticsearch with Apache License 2.0 4 votes vote down vote up
public void addHistoricTaskInstanceEvent(HistoricTaskInstanceEventEntity taskInstanceEvent) {
  if (tasks == null) {
    tasks = new ArrayList<HistoricTaskInstanceEventEntity>();
  }
  tasks.add(taskInstanceEvent);
}
 
Example #14
Source File: ElasticSearchProcessInstanceHistoryEntity.java    From camunda-bpm-elasticsearch with Apache License 2.0 4 votes vote down vote up
public List<HistoricTaskInstanceEventEntity> getTasks() {
  return tasks;
}
 
Example #15
Source File: ElasticSearchProcessInstanceHistoryEntity.java    From camunda-bpm-elasticsearch with Apache License 2.0 4 votes vote down vote up
public static ElasticSearchProcessInstanceHistoryEntity createFromHistoryEvent(HistoryEvent historyEvent) {
  ElasticSearchProcessInstanceHistoryEntity esHistoryEntity = new ElasticSearchProcessInstanceHistoryEntity();

  esHistoryEntity.setId(historyEvent.getId()); // maybe use process instance id here?
  esHistoryEntity.setProcessInstanceId(historyEvent.getProcessInstanceId());

  if (historyEvent instanceof HistoricProcessInstanceEventEntity) {
    HistoricProcessInstanceEventEntity pie = (HistoricProcessInstanceEventEntity) historyEvent;

    esHistoryEntity.setExecutionId(pie.getExecutionId());
    esHistoryEntity.setProcessDefinitionId(pie.getProcessDefinitionId());

    esHistoryEntity.setStartActivityId(pie.getStartActivityId());
    esHistoryEntity.setEndActivityId(pie.getEndActivityId());
    esHistoryEntity.setStartTime(pie.getStartTime());
    esHistoryEntity.setEndTime(pie.getEndTime());
    esHistoryEntity.setDurationInMillis(pie.getDurationInMillis());

    esHistoryEntity.setBusinessKey(pie.getBusinessKey());
    esHistoryEntity.setStartUserId(pie.getStartUserId());
    esHistoryEntity.setDeleteReason(pie.getDeleteReason());
    esHistoryEntity.setSuperProcessInstanceId(pie.getSuperProcessInstanceId());

  } else if (historyEvent instanceof HistoricActivityInstanceEventEntity) {

    HistoricActivityInstanceEventEntity aie = (HistoricActivityInstanceEventEntity) historyEvent;
    esHistoryEntity.addHistoricActivityInstanceEvent(aie);

  } else if (historyEvent instanceof HistoricTaskInstanceEventEntity) {

    HistoricTaskInstanceEventEntity tie = (HistoricTaskInstanceEventEntity) historyEvent;
    esHistoryEntity.addHistoricTaskInstanceEvent(tie);

  } else if (historyEvent instanceof HistoricVariableUpdateEventEntity) {

    HistoricVariableUpdateEventEntity vue = (HistoricVariableUpdateEventEntity) historyEvent;
    esHistoryEntity.addHistoricVariableUpdateEvent(vue);

  } else {
    // unknown event - throw exception or return null?
  }

  return esHistoryEntity;
}
 
Example #16
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void initTaskInstanceEvent(HistoricTaskInstanceEventEntity evt, TaskEntity taskEntity, HistoryEventType eventType) {

    String processDefinitionKey = null;
    ProcessDefinitionEntity definition = taskEntity.getProcessDefinition();
    if (definition != null) {
      processDefinitionKey = definition.getKey();
    }

    String processDefinitionId = taskEntity.getProcessDefinitionId();
    String processInstanceId = taskEntity.getProcessInstanceId();
    String executionId = taskEntity.getExecutionId();

    String caseDefinitionKey = null;
    CaseDefinitionEntity caseDefinition = taskEntity.getCaseDefinition();
    if (caseDefinition != null) {
      caseDefinitionKey = caseDefinition.getKey();
    }

    String caseDefinitionId = taskEntity.getCaseDefinitionId();
    String caseExecutionId = taskEntity.getCaseExecutionId();
    String caseInstanceId = taskEntity.getCaseInstanceId();
    String tenantId = taskEntity.getTenantId();

    evt.setId(taskEntity.getId());
    evt.setEventType(eventType.getEventName());
    evt.setTaskId(taskEntity.getId());

    evt.setProcessDefinitionKey(processDefinitionKey);
    evt.setProcessDefinitionId(processDefinitionId);
    evt.setProcessInstanceId(processInstanceId);
    evt.setExecutionId(executionId);

    evt.setCaseDefinitionKey(caseDefinitionKey);
    evt.setCaseDefinitionId(caseDefinitionId);
    evt.setCaseExecutionId(caseExecutionId);
    evt.setCaseInstanceId(caseInstanceId);

    evt.setAssignee(taskEntity.getAssignee());
    evt.setDescription(taskEntity.getDescription());
    evt.setDueDate(taskEntity.getDueDate());
    evt.setFollowUpDate(taskEntity.getFollowUpDate());
    evt.setName(taskEntity.getName());
    evt.setOwner(taskEntity.getOwner());
    evt.setParentTaskId(taskEntity.getParentTaskId());
    evt.setPriority(taskEntity.getPriority());
    evt.setTaskDefinitionKey(taskEntity.getTaskDefinitionKey());
    evt.setTenantId(tenantId);

    ExecutionEntity execution = taskEntity.getExecution();
    if (execution != null) {
      evt.setActivityInstanceId(execution.getActivityInstanceId());
      evt.setRootProcessInstanceId(execution.getRootProcessInstanceId());

      if (isHistoryRemovalTimeStrategyStart()) {
        provideRemovalTime(evt);
      }
    }

  }
 
Example #17
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected HistoricTaskInstanceEventEntity newTaskInstanceEventEntity(DelegateTask task) {
  return new HistoricTaskInstanceEventEntity();
}
 
Example #18
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected HistoricTaskInstanceEventEntity loadTaskInstanceEvent(DelegateTask task) {
  return newTaskInstanceEventEntity(task);
}
 
Example #19
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 3 votes vote down vote up
public HistoryEvent createTaskInstanceCreateEvt(DelegateTask task) {

    // create event instance
    HistoricTaskInstanceEventEntity evt = newTaskInstanceEventEntity(task);

    // initialize event
    initTaskInstanceEvent(evt, (TaskEntity) task, HistoryEventTypes.TASK_INSTANCE_CREATE);

    evt.setStartTime(ClockUtil.getCurrentTime());

    return evt;
  }
 
Example #20
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 3 votes vote down vote up
public HistoryEvent createTaskInstanceUpdateEvt(DelegateTask task) {

    // create event instance
    HistoricTaskInstanceEventEntity evt = loadTaskInstanceEvent(task);

    // initialize event
    initTaskInstanceEvent(evt, (TaskEntity) task, HistoryEventTypes.TASK_INSTANCE_UPDATE);

    return evt;
  }