use of io.zeebe.monitor.rest.dto.ElementInstanceState 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.rest.dto.ElementInstanceState in project zeebe-simple-monitor by camunda-community-hub.
the class ProcessesViewController method getElementInstanceStates.
private List<ElementInstanceState> getElementInstanceStates(final long key) {
final List<ElementInstanceStatistics> elementEnteredStatistics = processRepository.getElementInstanceStatisticsByKeyAndIntentIn(key, PROCESS_INSTANCE_ENTERED_INTENTS, EXCLUDE_ELEMENT_TYPES);
final Map<String, Long> elementCompletedCount = processRepository.getElementInstanceStatisticsByKeyAndIntentIn(key, PROCESS_INSTANCE_COMPLETED_INTENTS, EXCLUDE_ELEMENT_TYPES).stream().collect(Collectors.toMap(ElementInstanceStatistics::getElementId, ElementInstanceStatistics::getCount));
final List<ElementInstanceState> elementInstanceStates = elementEnteredStatistics.stream().map(s -> {
final ElementInstanceState state = new ElementInstanceState();
final String elementId = s.getElementId();
state.setElementId(elementId);
final long completedInstances = elementCompletedCount.getOrDefault(elementId, 0L);
final long enteredInstances = s.getCount();
state.setActiveInstances(enteredInstances - completedInstances);
state.setEndedInstances(completedInstances);
return state;
}).collect(Collectors.toList());
return elementInstanceStates;
}
use of io.zeebe.monitor.rest.dto.ElementInstanceState in project zeebe-simple-monitor by camunda-community-hub.
the class ProcessesViewController method processDetail.
@GetMapping("/views/processes/{key}")
@Transactional
public String processDetail(@PathVariable final long key, final Map<String, Object> model, final Pageable pageable) {
final ProcessEntity process = processRepository.findByKey(key).orElseThrow(() -> new ResponseStatusException(NOT_FOUND, "No process found with key: " + key));
model.put("process", toDto(process));
model.put("resource", getProcessResource(process));
final List<ElementInstanceState> elementInstanceStates = getElementInstanceStates(key);
model.put("instance.elementInstances", elementInstanceStates);
final long count = processInstanceRepository.countByProcessDefinitionKey(key);
final List<ProcessInstanceListDto> instances = new ArrayList<>();
for (final ProcessInstanceEntity instanceEntity : processInstanceRepository.findByProcessDefinitionKey(key, pageable)) {
instances.add(toDto(instanceEntity));
}
model.put("instances", instances);
model.put("count", count);
final List<TimerDto> timers = timerRepository.findByProcessDefinitionKeyAndProcessInstanceKeyIsNull(key).stream().map(ProcessesViewController::toDto).collect(Collectors.toList());
model.put("timers", timers);
final List<MessageSubscriptionDto> messageSubscriptions = messageSubscriptionRepository.findByProcessDefinitionKeyAndProcessInstanceKeyIsNull(key).stream().map(ProcessesViewController::toDto).collect(Collectors.toList());
model.put("messageSubscriptions", messageSubscriptions);
final var resourceAsStream = new ByteArrayInputStream(process.getResource().getBytes());
final var bpmn = Bpmn.readModelFromStream(resourceAsStream);
model.put("instance.bpmnElementInfos", getBpmnElementInfos(bpmn));
addPaginationToModel(model, pageable, count);
addDefaultAttributesToModel(model);
return "process-detail-view";
}
Aggregations