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

The following examples show how to use org.camunda.bpm.engine.impl.history.event.HistoricActivityInstanceEventEntity. 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: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public HistoryEvent createActivityInstanceEndEvt(DelegateExecution execution) {
  final ExecutionEntity executionEntity = (ExecutionEntity) execution;

  // create event instance
  HistoricActivityInstanceEventEntity evt = loadActivityInstanceEventEntity(executionEntity);
  evt.setActivityInstanceState(executionEntity.getActivityInstanceState());

  // initialize event
  initActivityInstanceEvent(evt, (ExecutionEntity) execution, HistoryEventTypes.ACTIVITY_INSTANCE_END);

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

  return evt;
}
 
Example #2
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public HistoryEvent createActivityInstanceUpdateEvt(DelegateExecution execution, DelegateTask task) {
  final ExecutionEntity executionEntity = (ExecutionEntity) execution;

  // create event instance
  HistoricActivityInstanceEventEntity evt = loadActivityInstanceEventEntity(executionEntity);

  // initialize event
  initActivityInstanceEvent(evt, executionEntity, HistoryEventTypes.ACTIVITY_INSTANCE_UPDATE);

  // update task assignment
  if(task != null) {
    evt.setTaskId(task.getId());
    evt.setTaskAssignee(task.getAssignee());
  }

  return evt;
}
 
Example #3
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void initActivityInstanceEvent(HistoricActivityInstanceEventEntity evt, ExecutionEntity execution, HistoryEventType eventType) {
  PvmScope eventSource = execution.getActivity();
  if (eventSource == null) {
    eventSource = (PvmScope) execution.getEventSource();
  }
  String activityInstanceId = execution.getActivityInstanceId();

  String parentActivityInstanceId = null;
  ExecutionEntity parentExecution = execution.getParent();

  if (parentExecution != null && CompensationBehavior.isCompensationThrowing(parentExecution) && execution.getActivity() != null) {
    parentActivityInstanceId = CompensationBehavior.getParentActivityInstanceId(execution);
  } else {
    parentActivityInstanceId = execution.getParentActivityInstanceId();
  }

  initActivityInstanceEvent(evt,
      execution,
      eventSource,
      activityInstanceId,
      parentActivityInstanceId,
      eventType);
}
 
Example #4
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void initActivityInstanceEvent(HistoricActivityInstanceEventEntity evt, MigratingActivityInstance migratingActivityInstance, HistoryEventType eventType) {
  PvmScope eventSource = migratingActivityInstance.getTargetScope();
  String activityInstanceId = migratingActivityInstance.getActivityInstanceId();

  MigratingActivityInstance parentInstance = migratingActivityInstance.getParent();
  String parentActivityInstanceId = null;
  if (parentInstance != null) {
    parentActivityInstanceId = parentInstance.getActivityInstanceId();
  }

  ExecutionEntity execution = migratingActivityInstance.resolveRepresentativeExecution();

  initActivityInstanceEvent(evt,
      execution,
      eventSource,
      activityInstanceId,
      parentActivityInstanceId,
      eventType);
}
 
Example #5
Source File: HistoricActivityInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testHistoricActivityInstanceReceive() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveProcess");

  HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();

  assertEquals("receive", historicActivityInstance.getActivityId());
  assertEquals("receiveTask", historicActivityInstance.getActivityType());
  assertNull(historicActivityInstance.getEndTime());
  assertNull(historicActivityInstance.getDurationInMillis());
  assertNotNull(historicActivityInstance.getProcessDefinitionId());
  assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
  assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
  assertNotNull(historicActivityInstance.getStartTime());

  // move clock by 1 second
  Date now = ClockUtil.getCurrentTime();
  ClockUtil.setCurrentTime(new Date(now.getTime() + 1000));

  runtimeService.signal(processInstance.getId());

  historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();

  assertEquals("receive", historicActivityInstance.getActivityId());
  assertEquals("receiveTask", historicActivityInstance.getActivityType());
  assertNotNull(historicActivityInstance.getEndTime());
  assertNotNull(historicActivityInstance.getProcessDefinitionId());
  assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
  assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
  assertNotNull(historicActivityInstance.getStartTime());
  assertTrue(historicActivityInstance.getDurationInMillis() >= 1000);
  assertTrue(((HistoricActivityInstanceEventEntity)historicActivityInstance).getDurationRaw() >= 1000);
}
 
Example #6
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public HistoryEvent createActivityInstanceMigrateEvt(MigratingActivityInstance actInstance) {

  // create event instance
  HistoricActivityInstanceEventEntity evt = loadActivityInstanceEventEntity(actInstance.resolveRepresentativeExecution());

  // initialize event
  initActivityInstanceEvent(evt, actInstance, HistoryEventTypes.ACTIVITY_INSTANCE_MIGRATE);

  return evt;
}
 
Example #7
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 #8
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 #9
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 #10
Source File: HistoricActivityInstanceManager.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void addRemovalTimeToActivityInstancesByRootProcessInstanceId(String rootProcessInstanceId, Date removalTime) {
  Map<String, Object> parameters = new HashMap<>();
  parameters.put("rootProcessInstanceId", rootProcessInstanceId);
  parameters.put("removalTime", removalTime);

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

  getDbEntityManager()
    .updatePreserveOrder(HistoricActivityInstanceEventEntity.class, "updateHistoricActivityInstancesByProcessInstanceId", parameters);
}
 
Example #12
Source File: HistoricActivityInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/history/HistoricActivityInstanceTest.testHistoricActivityInstanceReceive.bpmn20.xml" })
public void testLongRunningHistoricActivityInstanceReceive() {
  final long ONE_YEAR = 1000 * 60 * 60 * 24 * 365;

  Calendar cal = Calendar.getInstance();
  cal.set(Calendar.SECOND, 0);
  cal.set(Calendar.MILLISECOND, 0);

  ClockUtil.setCurrentTime(cal.getTime());

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveProcess");

  HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();

  assertEquals("receive", historicActivityInstance.getActivityId());
  assertEquals("receiveTask", historicActivityInstance.getActivityType());
  assertNull(historicActivityInstance.getEndTime());
  assertNull(historicActivityInstance.getDurationInMillis());
  assertNotNull(historicActivityInstance.getProcessDefinitionId());
  assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
  assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
  assertNotNull(historicActivityInstance.getStartTime());

  // move clock by 1 year
  cal.add(Calendar.YEAR, 1);
  ClockUtil.setCurrentTime(cal.getTime());

  runtimeService.signal(processInstance.getId());

  historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();

  assertEquals("receive", historicActivityInstance.getActivityId());
  assertEquals("receiveTask", historicActivityInstance.getActivityType());
  assertNotNull(historicActivityInstance.getEndTime());
  assertNotNull(historicActivityInstance.getProcessDefinitionId());
  assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
  assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
  assertNotNull(historicActivityInstance.getStartTime());
  assertTrue(historicActivityInstance.getDurationInMillis() >= ONE_YEAR);
  assertTrue(((HistoricActivityInstanceEventEntity)historicActivityInstance).getDurationRaw() >= ONE_YEAR);
}
 
Example #13
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public HistoryEvent createActivityInstanceStartEvt(DelegateExecution execution) {
  final ExecutionEntity executionEntity = (ExecutionEntity) execution;

  // create event instance
  HistoricActivityInstanceEventEntity evt = newActivityInstanceEventEntity(executionEntity);

  // initialize event
  initActivityInstanceEvent(evt, executionEntity, HistoryEventTypes.ACTIVITY_INSTANCE_START);

  // initialize sequence counter
  initSequenceCounter(executionEntity, evt);

  evt.setStartTime(ClockUtil.getCurrentTime());

  return evt;
}
 
Example #14
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected HistoricActivityInstanceEventEntity loadActivityInstanceEventEntity(ExecutionEntity execution) {
  return newActivityInstanceEventEntity(execution);
}
 
Example #15
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected HistoricActivityInstanceEventEntity newActivityInstanceEventEntity(ExecutionEntity execution) {
  return new HistoricActivityInstanceEventEntity();
}
 
Example #16
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void initActivityInstanceEvent(HistoricActivityInstanceEventEntity evt,
    ExecutionEntity execution,
    PvmScope eventSource,
    String activityInstanceId,
    String parentActivityInstanceId,
    HistoryEventType eventType) {

  evt.setId(activityInstanceId);
  evt.setEventType(eventType.getEventName());
  evt.setActivityInstanceId(activityInstanceId);
  evt.setParentActivityInstanceId(parentActivityInstanceId);
  evt.setProcessDefinitionId(execution.getProcessDefinitionId());
  evt.setProcessInstanceId(execution.getProcessInstanceId());
  evt.setExecutionId(execution.getId());
  evt.setTenantId(execution.getTenantId());
  evt.setRootProcessInstanceId(execution.getRootProcessInstanceId());

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

  ProcessDefinitionEntity definition = execution.getProcessDefinition();
  if (definition != null) {
    evt.setProcessDefinitionKey(definition.getKey());
  }

  evt.setActivityId(eventSource.getId());
  evt.setActivityName((String) eventSource.getProperty("name"));
  evt.setActivityType((String) eventSource.getProperty("type"));

  // update sub process reference
  ExecutionEntity subProcessInstance = execution.getSubProcessInstance();
  if (subProcessInstance != null) {
    evt.setCalledProcessInstanceId(subProcessInstance.getId());
  }

  // update sub case reference
  CaseExecutionEntity subCaseInstance = execution.getSubCaseInstance();
  if (subCaseInstance != null) {
    evt.setCalledCaseInstanceId(subCaseInstance.getId());
  }
}
 
Example #17
Source File: ElasticSearchProcessInstanceHistoryEntity.java    From camunda-bpm-elasticsearch with Apache License 2.0 4 votes vote down vote up
public void addHistoricActivityInstanceEvent(HistoricActivityInstanceEventEntity activityInstanceEvent) {
  if (activities == null) {
    activities = new ArrayList<HistoricActivityInstanceEventEntity>();
  }
  activities.add(activityInstanceEvent);
}
 
Example #18
Source File: ElasticSearchProcessInstanceHistoryEntity.java    From camunda-bpm-elasticsearch with Apache License 2.0 4 votes vote down vote up
public void setActivities(List<HistoricActivityInstanceEventEntity> activities) {
  this.activities = activities;
}
 
Example #19
Source File: ElasticSearchProcessInstanceHistoryEntity.java    From camunda-bpm-elasticsearch with Apache License 2.0 4 votes vote down vote up
public List<HistoricActivityInstanceEventEntity> getActivities() {
  return activities;
}
 
Example #20
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 #21
Source File: FlowNodeHistoryEventHandler.java    From camunda-bpm-process-test-coverage with Apache License 2.0 3 votes vote down vote up
@Override
public void handleEvent(HistoryEvent historyEvent) {
    super.handleEvent(historyEvent);

    if (coverageTestRunState == null) {
        logger.warning("Coverage history event listener in use but no coverage run state assigned!");
        return;
    }

    if (historyEvent instanceof HistoricActivityInstanceEventEntity) {

        HistoricActivityInstanceEventEntity activityEvent = (HistoricActivityInstanceEventEntity) historyEvent;

        if (activityEvent.getActivityType().equals("multiInstanceBody"))
            return;

        final CoveredFlowNode coveredActivity =
            new CoveredFlowNode(historyEvent.getProcessDefinitionKey(), activityEvent.getActivityId());

        // Cover event start
        if (isInitialEvent(historyEvent)) {

            coverageTestRunState.addCoveredElement(coveredActivity);

        }
        // Cover event end
        else if (isEndEvent(historyEvent)) {

            coverageTestRunState.endCoveredElement(coveredActivity);
        }

    }

}