use of io.zeebe.monitor.entity.ElementInstanceEntity in project zeebe-simple-monitor by camunda-community-hub.
the class AbstractInstanceViewController method fillActiveScopesIntoDto.
protected void fillActiveScopesIntoDto(ProcessInstanceEntity instance, List<ElementInstanceEntity> events, Map<Long, String> elementIdsForKeys, ProcessInstanceDto dto) {
final List<ActiveScope> activeScopes = new ArrayList<>();
if (dto.isRunning()) {
activeScopes.add(new ActiveScope(instance.getKey(), instance.getBpmnProcessId()));
final List<Long> completedElementInstances = events.stream().filter(e -> PROCESS_INSTANCE_COMPLETED_INTENTS.contains(e.getIntent())).map(ElementInstanceEntity::getKey).collect(Collectors.toList());
final List<ActiveScope> activeElementInstances = events.stream().filter(e -> PROCESS_INSTANCE_ENTERED_INTENTS.contains(e.getIntent())).map(ElementInstanceEntity::getKey).filter(id -> !completedElementInstances.contains(id)).map(scopeKey -> new ActiveScope(scopeKey, elementIdsForKeys.get(scopeKey))).collect(Collectors.toList());
activeScopes.addAll(activeElementInstances);
}
dto.setActiveScopes(activeScopes);
}
use of io.zeebe.monitor.entity.ElementInstanceEntity in project zeebe-simple-monitor by camunda-community-hub.
the class AbstractInstanceViewController method fillActivityInformationForDiagramAnnotationIntoDto.
private void fillActivityInformationForDiagramAnnotationIntoDto(List<ElementInstanceEntity> events, ProcessInstanceDto dto, List<IncidentEntity> incidents, Map<Long, String> elementIdsForKeys) {
final List<String> completedActivities = events.stream().filter(e -> PROCESS_INSTANCE_COMPLETED_INTENTS.contains(e.getIntent())).filter(e -> !e.getBpmnElementType().equals(BpmnElementType.PROCESS.name())).map(ElementInstanceEntity::getElementId).collect(Collectors.toList());
final List<String> activeActivities = events.stream().filter(e -> PROCESS_INSTANCE_ENTERED_INTENTS.contains(e.getIntent())).filter(e -> !e.getBpmnElementType().equals(BpmnElementType.PROCESS.name())).map(ElementInstanceEntity::getElementId).filter(id -> !completedActivities.contains(id)).collect(Collectors.toList());
dto.setActiveActivities(activeActivities);
final List<String> takenSequenceFlows = events.stream().filter(e -> e.getIntent().equals("SEQUENCE_FLOW_TAKEN")).map(ElementInstanceEntity::getElementId).collect(Collectors.toList());
dto.setTakenSequenceFlows(takenSequenceFlows);
final Map<String, Long> completedElementsById = events.stream().filter(e -> PROCESS_INSTANCE_COMPLETED_INTENTS.contains(e.getIntent())).filter(e -> !EXCLUDE_ELEMENT_TYPES.contains(e.getBpmnElementType())).collect(Collectors.groupingBy(ElementInstanceEntity::getElementId, Collectors.counting()));
final Map<String, Long> enteredElementsById = events.stream().filter(e -> PROCESS_INSTANCE_ENTERED_INTENTS.contains(e.getIntent())).filter(e -> !EXCLUDE_ELEMENT_TYPES.contains(e.getBpmnElementType())).collect(Collectors.groupingBy(ElementInstanceEntity::getElementId, Collectors.counting()));
final List<ElementInstanceState> elementStates = enteredElementsById.entrySet().stream().map(e -> {
final String elementId = e.getKey();
final long enteredInstances = e.getValue();
final long completedInstances = completedElementsById.getOrDefault(elementId, 0L);
final ElementInstanceState state = new ElementInstanceState();
state.setElementId(elementId);
state.setActiveInstances(enteredInstances - completedInstances);
state.setEndedInstances(completedInstances);
return state;
}).collect(Collectors.toList());
dto.setElementInstances(elementStates);
final List<String> activitiesWitIncidents = incidents.stream().filter(i -> i.getResolved() == null || i.getResolved() <= 0).map(i -> elementIdsForKeys.get(i.getElementInstanceKey())).distinct().collect(Collectors.toList());
dto.setIncidentActivities(activitiesWitIncidents);
activeActivities.removeAll(activitiesWitIncidents);
dto.setActiveActivities(activeActivities);
}
use of io.zeebe.monitor.entity.ElementInstanceEntity in project zeebe-simple-monitor by camunda-community-hub.
the class InstancesAuditLogViewController method fillViewDetailsIntoDto.
@Override
protected void fillViewDetailsIntoDto(ProcessInstanceEntity instance, List<ElementInstanceEntity> events, List<IncidentEntity> incidents, Map<Long, String> elementIdsForKeys, Map<String, Object> model, Pageable pageable, ProcessInstanceDto dto) {
final var bpmnModelInstance = processRepository.findByKey(instance.getProcessDefinitionKey()).map(w -> new ByteArrayInputStream(w.getResource().getBytes())).map(Bpmn::readModelFromStream);
final Map<String, String> flowElements = new HashMap<>();
bpmnModelInstance.ifPresent(bpmn -> {
bpmn.getModelElementsByType(FlowElement.class).forEach(e -> flowElements.put(e.getId(), Optional.ofNullable(e.getName()).orElse("")));
dto.setBpmnElementInfos(getBpmnElementInfos(bpmn));
});
final List<AuditLogEntry> auditLogEntries = events.stream().skip((long) pageable.getPageSize() * pageable.getPageNumber()).map(e -> {
final AuditLogEntry entry = new AuditLogEntry();
entry.setKey(e.getKey());
entry.setFlowScopeKey(e.getFlowScopeKey());
entry.setElementId(e.getElementId());
entry.setElementName(flowElements.getOrDefault(e.getElementId(), ""));
entry.setBpmnElementType(e.getBpmnElementType());
entry.setState(e.getIntent());
entry.setTimestamp(Instant.ofEpochMilli(e.getTimestamp()).toString());
return entry;
}).limit(pageable.getPageSize()).collect(Collectors.toList());
dto.setAuditLogEntries(auditLogEntries);
addPaginationToModel(model, pageable, events.size());
}
use of io.zeebe.monitor.entity.ElementInstanceEntity in project zeebe-simple-monitor by camunda-community-hub.
the class InstancesVariableListController method fillViewDetailsIntoDto.
@Override
protected void fillViewDetailsIntoDto(ProcessInstanceEntity instance, List<ElementInstanceEntity> events, List<IncidentEntity> incidents, Map<Long, String> elementIdsForKeys, Map<String, Object> model, Pageable pageable, ProcessInstanceDto dto) {
final Map<VariableTuple, List<VariableEntity>> variablesByScopeAndName = variableRepository.findByProcessInstanceKey(instance.getKey(), pageable).stream().collect(Collectors.groupingBy(v -> new VariableTuple(v.getScopeKey(), v.getName())));
variablesByScopeAndName.forEach((scopeKeyName, variables) -> {
final VariableEntry variableDto = new VariableEntry();
final long scopeKey = scopeKeyName.scopeKey;
variableDto.setScopeKey(scopeKey);
variableDto.setElementId(elementIdsForKeys.get(scopeKey));
variableDto.setName(scopeKeyName.name);
final VariableEntity lastUpdate = variables.get(variables.size() - 1);
variableDto.setValue(lastUpdate.getValue());
variableDto.setTimestamp(Instant.ofEpochMilli(lastUpdate.getTimestamp()).toString());
final List<VariableUpdateEntry> varUpdates = variables.stream().map(v -> {
final VariableUpdateEntry varUpdate = new VariableUpdateEntry();
varUpdate.setValue(v.getValue());
varUpdate.setTimestamp(Instant.ofEpochMilli(v.getTimestamp()).toString());
return varUpdate;
}).collect(Collectors.toList());
variableDto.setUpdates(varUpdates);
dto.getVariables().add(variableDto);
});
final long count = variableRepository.countByProcessInstanceKey(instance.getKey());
addPaginationToModel(model, pageable, count);
}
use of io.zeebe.monitor.entity.ElementInstanceEntity in project zeebe-simple-monitor by camunda-community-hub.
the class ElementInstanceRepositoryTest method JPA_will_automatically_update_the_ID_attribute.
@Test
public void JPA_will_automatically_update_the_ID_attribute() {
// given
ElementInstanceEntity elementInstance = createElementInstance();
// when
elementInstanceRepository.save(elementInstance);
// then
assertThat(elementInstance.getId()).isEqualTo("123-456");
}
Aggregations