protected boolean isInitialEvent(HistoryEvent historyEvent) { return historyEvent.getEventType() == null || historyEvent.isEventOfType(HistoryEventTypes.ACTIVITY_INSTANCE_START) || historyEvent.isEventOfType(HistoryEventTypes.PROCESS_INSTANCE_START) || historyEvent.isEventOfType(HistoryEventTypes.TASK_INSTANCE_CREATE) || historyEvent.isEventOfType(HistoryEventTypes.FORM_PROPERTY_UPDATE) || historyEvent.isEventOfType(HistoryEventTypes.INCIDENT_CREATE) || historyEvent.isEventOfType(HistoryEventTypes.CASE_INSTANCE_CREATE) || historyEvent.isEventOfType(HistoryEventTypes.DMN_DECISION_EVALUATE) || historyEvent.isEventOfType(HistoryEventTypes.BATCH_START) || historyEvent.isEventOfType(HistoryEventTypes.IDENTITY_LINK_ADD) || historyEvent.isEventOfType(HistoryEventTypes.IDENTITY_LINK_DELETE) ; }
/** general history event insert behavior */ protected void insertOrUpdate(HistoryEvent historyEvent) { final DbEntityManager dbEntityManager = getDbEntityManager(); if(isInitialEvent(historyEvent)) { dbEntityManager.insert(historyEvent); } else { if(dbEntityManager.getCachedEntity(historyEvent.getClass(), historyEvent.getId()) == null) { if (historyEvent instanceof HistoricScopeInstanceEvent) { // if this is a scope, get start time from existing event in DB HistoricScopeInstanceEvent existingEvent = (HistoricScopeInstanceEvent) dbEntityManager.selectById(historyEvent.getClass(), historyEvent.getId()); if(existingEvent != null) { HistoricScopeInstanceEvent historicScopeInstanceEvent = (HistoricScopeInstanceEvent) historyEvent; historicScopeInstanceEvent.setStartTime(existingEvent.getStartTime()); } } if(historyEvent.getId() == null) { // dbSqlSession.insert(historyEvent); } else { dbEntityManager.merge(historyEvent); } } } }
protected void provideRemovalTime(HistoryEvent historyEvent) { String rootProcessInstanceId = historyEvent.getRootProcessInstanceId(); if (rootProcessInstanceId != null) { HistoricProcessInstanceEventEntity historicRootProcessInstance = getHistoricRootProcessInstance(rootProcessInstanceId); if (historicRootProcessInstance != null) { Date removalTime = historicRootProcessInstance.getRemovalTime(); historyEvent.setRemovalTime(removalTime); } } }
public static HistoricOptimizeVariableUpdateDto fromHistoricVariableUpdate(HistoricVariableUpdate historicVariableUpdate) { HistoricOptimizeVariableUpdateDto dto = new HistoricOptimizeVariableUpdateDto(); fromHistoricVariableUpdate(dto, historicVariableUpdate); fromHistoricDetail(historicVariableUpdate, dto); if (historicVariableUpdate instanceof HistoryEvent) { HistoryEvent historyEvent = (HistoryEvent) historicVariableUpdate; dto.setSequenceCounter(historyEvent.getSequenceCounter()); } return dto; }
/** * Aimed to be the opposite of * {@link DbHistoryEventHandler#isInitialEvent(HistoryEvent event)} * for the purpose of the process test coverage - which just deals with * history events of type HistoricActivityInstanceEventEntity. * * Future versions of Camunda will eventually introduce additional events * requiring this method to be updated. Be careful to deal with backwards * compatibility issues when doing that. * * @param historyEvent * @return */ private boolean isEndEvent(HistoryEvent historyEvent) { EnumSet<HistoryEventTypes> endEventTypes = EnumSet.of( HistoryEventTypes.ACTIVITY_INSTANCE_END, HistoryEventTypes.PROCESS_INSTANCE_END, HistoryEventTypes.TASK_INSTANCE_COMPLETE ); // They should have handled compare/equals in the enum itself for (HistoryEventTypes endEventType : endEventTypes) { if (historyEvent.getEventType().equals(endEventType.getEventName())) { return true; } } return false; }
protected Date calculateRemovalTime(HistoryEvent historyEvent) { String processDefinitionId = historyEvent.getProcessDefinitionId(); ProcessDefinition processDefinition = findProcessDefinitionById(processDefinitionId); return Context.getProcessEngineConfiguration() .getHistoryRemovalTimeProvider() .calculateRemovalTime((HistoricProcessInstanceEventEntity) historyEvent, processDefinition); }
protected void initSequenceCounter(long sequenceCounter, HistoryEvent event) { event.setSequenceCounter(sequenceCounter); }
@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); } } }
public static HistoricOptimizeVariableUpdateDto fromHistoricVariableUpdate(HistoricVariableUpdate historicVariableUpdate) { HistoricOptimizeVariableUpdateDto dto = new HistoricOptimizeVariableUpdateDto(); fromHistoricVariableUpdate(dto, historicVariableUpdate); fromHistoricDetail(historicVariableUpdate, dto); if (historicVariableUpdate instanceof HistoryEvent) { HistoryEvent historyEvent = (HistoryEvent) historicVariableUpdate; dto.setSequenceCounter(historyEvent.getSequenceCounter()); } return dto; }
protected boolean isInitialEvent(HistoryEvent historyEvent) { String isInitialEvent = "isInitialEvent"; return Api.feature(DbHistoryEventHandler.class, isInitialEvent, HistoryEvent.class).isSupported() ? super.isInitialEvent(historyEvent): (Boolean) Api.feature(DbHistoryEventHandler.class, isInitialEvent, String.class).invoke(this, historyEvent.getEventType()); }
protected Date calculateRemovalTime(HistoryEvent historyEvent) { String processDefinitionId = historyEvent.getProcessDefinitionId(); ProcessDefinition processDefinition = findProcessDefinitionById(processDefinitionId); return Context.getProcessEngineConfiguration() .getHistoryRemovalTimeProvider() .calculateRemovalTime((HistoricProcessInstanceEventEntity) historyEvent, processDefinition); }
protected void initSequenceCounter(long sequenceCounter, HistoryEvent event) { event.setSequenceCounter(sequenceCounter); }
@Deployment(resources = {"org/camunda/bpm/engine/test/history/HistoricVariableInstanceTest.testHistoricVariableInstanceRevision.bpmn20.xml"}) public void testVariableUpdateOrder() { // given: // a finished process instance ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process"); assertProcessEnded(processInstance.getId()); // when // then HistoricVariableInstance variable = historyService .createHistoricVariableInstanceQuery() .singleResult(); assertNotNull(variable); if (isFullHistoryEnabled()) { List<HistoricDetail> details = historyService .createHistoricDetailQuery() .variableInstanceId(variable.getId()) .orderPartiallyByOccurrence() .asc() .list(); assertEquals(3, details.size()); HistoricVariableUpdate firstUpdate = (HistoricVariableUpdate) details.get(0); assertEquals(1, firstUpdate.getValue()); HistoricVariableUpdate secondUpdate = (HistoricVariableUpdate) details.get(1); assertEquals(2, secondUpdate.getValue()); assertTrue(((HistoryEvent)secondUpdate).getSequenceCounter() > ((HistoryEvent)firstUpdate).getSequenceCounter()); HistoricVariableUpdate thirdUpdate = (HistoricVariableUpdate) details.get(2); assertEquals(3, thirdUpdate.getValue()); assertTrue(((HistoryEvent)thirdUpdate).getSequenceCounter() > ((HistoryEvent)secondUpdate).getSequenceCounter()); } }
protected void provideRemovalTime(HistoryEvent historyEvent) { String rootProcessInstanceId = historyEvent.getRootProcessInstanceId(); if (rootProcessInstanceId != null) { HistoricProcessInstanceEventEntity historicRootProcessInstance = getHistoricRootProcessInstance(rootProcessInstanceId); if (historicRootProcessInstance != null) { Date removalTime = historicRootProcessInstance.getRemovalTime(); historyEvent.setRemovalTime(removalTime); } } }
protected boolean isInitialEvent(HistoryEvent historyEvent) { return historyEvent.getEventType() == null || historyEvent.isEventOfType(HistoryEventTypes.ACTIVITY_INSTANCE_START) || historyEvent.isEventOfType(HistoryEventTypes.PROCESS_INSTANCE_START) || historyEvent.isEventOfType(HistoryEventTypes.TASK_INSTANCE_CREATE) || historyEvent.isEventOfType(HistoryEventTypes.FORM_PROPERTY_UPDATE) || historyEvent.isEventOfType(HistoryEventTypes.INCIDENT_CREATE) || historyEvent.isEventOfType(HistoryEventTypes.CASE_INSTANCE_CREATE) || historyEvent.isEventOfType(HistoryEventTypes.DMN_DECISION_EVALUATE) || historyEvent.isEventOfType(HistoryEventTypes.BATCH_START) || historyEvent.isEventOfType(HistoryEventTypes.IDENTITY_LINK_ADD) || historyEvent.isEventOfType(HistoryEventTypes.IDENTITY_LINK_DELETE) ; }
protected Date calculateRemovalTime(HistoryEvent historyEvent) { String processDefinitionId = historyEvent.getProcessDefinitionId(); ProcessDefinition processDefinition = findProcessDefinitionById(processDefinitionId); return Context.getProcessEngineConfiguration() .getHistoryRemovalTimeProvider() .calculateRemovalTime((HistoricProcessInstanceEventEntity) historyEvent, processDefinition); }
protected void initSequenceCounter(long sequenceCounter, HistoryEvent event) { event.setSequenceCounter(sequenceCounter); }
/** general history event insert behavior */ protected void insertOrUpdate(HistoryEvent historyEvent) { final DbEntityManager dbEntityManager = getDbEntityManager(); if(isInitialEvent(historyEvent)) { dbEntityManager.insert(historyEvent); } else { if(dbEntityManager.getCachedEntity(historyEvent.getClass(), historyEvent.getId()) == null) { if (historyEvent instanceof HistoricScopeInstanceEvent) { // if this is a scope, get start time from existing event in DB HistoricScopeInstanceEvent existingEvent = (HistoricScopeInstanceEvent) dbEntityManager.selectById(historyEvent.getClass(), historyEvent.getId()); if(existingEvent != null) { HistoricScopeInstanceEvent historicScopeInstanceEvent = (HistoricScopeInstanceEvent) historyEvent; historicScopeInstanceEvent.setStartTime(existingEvent.getStartTime()); } } if(historyEvent.getId() == null) { // dbSqlSession.insert(historyEvent); } else { dbEntityManager.merge(historyEvent); } } } }
assertTrue(((HistoryEvent)secondUpdate).getSequenceCounter() > ((HistoryEvent)firstUpdate).getSequenceCounter()); assertTrue(((HistoryEvent)thirdUpdate).getSequenceCounter() > ((HistoryEvent)secondUpdate).getSequenceCounter());
protected void provideRemovalTime(HistoryEvent historyEvent) { String rootProcessInstanceId = historyEvent.getRootProcessInstanceId(); if (rootProcessInstanceId != null) { HistoricProcessInstanceEventEntity historicRootProcessInstance = getHistoricRootProcessInstance(rootProcessInstanceId); if (historicRootProcessInstance != null) { Date removalTime = historicRootProcessInstance.getRemovalTime(); historyEvent.setRemovalTime(removalTime); } } }