Search in sources :

Example 1 with ElementInstanceState

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);
}
Also used : PROCESS_INSTANCE_COMPLETED_INTENTS(io.zeebe.monitor.rest.ProcessesViewController.PROCESS_INSTANCE_COMPLETED_INTENTS) NOT_FOUND(org.springframework.http.HttpStatus.NOT_FOUND) ProcessInstanceEntity(io.zeebe.monitor.entity.ProcessInstanceEntity) PROCESS_INSTANCE_ENTERED_INTENTS(io.zeebe.monitor.rest.ProcessesViewController.PROCESS_INSTANCE_ENTERED_INTENTS) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ProcessInstanceRepository(io.zeebe.monitor.repository.ProcessInstanceRepository) ArrayList(java.util.ArrayList) ElementInstanceState(io.zeebe.monitor.rest.dto.ElementInstanceState) Map(java.util.Map) ActiveScope(io.zeebe.monitor.rest.dto.ActiveScope) StreamSupport(java.util.stream.StreamSupport) Pageable(org.springframework.data.domain.Pageable) IncidentEntity(io.zeebe.monitor.entity.IncidentEntity) ResponseStatusException(org.springframework.web.server.ResponseStatusException) ProcessRepository(io.zeebe.monitor.repository.ProcessRepository) EXCLUDE_ELEMENT_TYPES(io.zeebe.monitor.rest.ProcessesViewController.EXCLUDE_ELEMENT_TYPES) ElementInstanceEntity(io.zeebe.monitor.entity.ElementInstanceEntity) IOException(java.io.IOException) IncidentRepository(io.zeebe.monitor.repository.IncidentRepository) Instant(java.time.Instant) Mustache(com.samskivert.mustache.Mustache) ElementInstanceRepository(io.zeebe.monitor.repository.ElementInstanceRepository) Collectors(java.util.stream.Collectors) List(java.util.List) Template(com.samskivert.mustache.Template) ProcessInstanceDto(io.zeebe.monitor.rest.dto.ProcessInstanceDto) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) Writer(java.io.Writer) ElementInstanceEntity(io.zeebe.monitor.entity.ElementInstanceEntity) ElementInstanceState(io.zeebe.monitor.rest.dto.ElementInstanceState)

Example 2 with ElementInstanceState

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;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) NOT_FOUND(org.springframework.http.HttpStatus.NOT_FOUND) ProcessInstanceEntity(io.zeebe.monitor.entity.ProcessInstanceEntity) ProcessEntity(io.zeebe.monitor.entity.ProcessEntity) ElementInstanceStatistics(io.zeebe.monitor.entity.ElementInstanceStatistics) ProcessDto(io.zeebe.monitor.rest.dto.ProcessDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) ProcessInstanceRepository(io.zeebe.monitor.repository.ProcessInstanceRepository) Controller(org.springframework.stereotype.Controller) MessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.MessageSubscriptionIntent) TimerEventDefinition(io.camunda.zeebe.model.bpmn.instance.TimerEventDefinition) TimerRepository(io.zeebe.monitor.repository.TimerRepository) ArrayList(java.util.ArrayList) CatchEvent(io.camunda.zeebe.model.bpmn.instance.CatchEvent) MessageSubscriptionRepository(io.zeebe.monitor.repository.MessageSubscriptionRepository) ProcessInstanceListDto(io.zeebe.monitor.rest.dto.ProcessInstanceListDto) ByteArrayInputStream(java.io.ByteArrayInputStream) ElementInstanceState(io.zeebe.monitor.rest.dto.ElementInstanceState) Map(java.util.Map) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) GetMapping(org.springframework.web.bind.annotation.GetMapping) Pageable(org.springframework.data.domain.Pageable) MessageSubscriptionEntity(io.zeebe.monitor.entity.MessageSubscriptionEntity) ResponseStatusException(org.springframework.web.server.ResponseStatusException) ErrorEventDefinition(io.camunda.zeebe.model.bpmn.instance.ErrorEventDefinition) Transactional(javax.transaction.Transactional) ProcessRepository(io.zeebe.monitor.repository.ProcessRepository) MessageSubscriptionDto(io.zeebe.monitor.rest.dto.MessageSubscriptionDto) ZeebeTaskDefinition(io.camunda.zeebe.model.bpmn.instance.zeebe.ZeebeTaskDefinition) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) TimerEntity(io.zeebe.monitor.entity.TimerEntity) SequenceFlow(io.camunda.zeebe.model.bpmn.instance.SequenceFlow) BpmnElementInfo(io.zeebe.monitor.rest.dto.BpmnElementInfo) ServiceTask(io.camunda.zeebe.model.bpmn.instance.ServiceTask) List(java.util.List) TimerDto(io.zeebe.monitor.rest.dto.TimerDto) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) Optional(java.util.Optional) ElementInstanceState(io.zeebe.monitor.rest.dto.ElementInstanceState) ElementInstanceStatistics(io.zeebe.monitor.entity.ElementInstanceStatistics)

Example 3 with ElementInstanceState

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";
}
Also used : ProcessInstanceEntity(io.zeebe.monitor.entity.ProcessInstanceEntity) MessageSubscriptionDto(io.zeebe.monitor.rest.dto.MessageSubscriptionDto) ElementInstanceState(io.zeebe.monitor.rest.dto.ElementInstanceState) ProcessEntity(io.zeebe.monitor.entity.ProcessEntity) ArrayList(java.util.ArrayList) TimerDto(io.zeebe.monitor.rest.dto.TimerDto) ProcessInstanceListDto(io.zeebe.monitor.rest.dto.ProcessInstanceListDto) ByteArrayInputStream(java.io.ByteArrayInputStream) ResponseStatusException(org.springframework.web.server.ResponseStatusException) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(javax.transaction.Transactional)

Aggregations

ProcessInstanceEntity (io.zeebe.monitor.entity.ProcessInstanceEntity)3 ElementInstanceState (io.zeebe.monitor.rest.dto.ElementInstanceState)3 ArrayList (java.util.ArrayList)3 ResponseStatusException (org.springframework.web.server.ResponseStatusException)3 BpmnElementType (io.camunda.zeebe.protocol.record.value.BpmnElementType)2 ProcessEntity (io.zeebe.monitor.entity.ProcessEntity)2 ProcessInstanceRepository (io.zeebe.monitor.repository.ProcessInstanceRepository)2 ProcessRepository (io.zeebe.monitor.repository.ProcessRepository)2 MessageSubscriptionDto (io.zeebe.monitor.rest.dto.MessageSubscriptionDto)2 ProcessInstanceListDto (io.zeebe.monitor.rest.dto.ProcessInstanceListDto)2 TimerDto (io.zeebe.monitor.rest.dto.TimerDto)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Instant (java.time.Instant)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Transactional (javax.transaction.Transactional)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Pageable (org.springframework.data.domain.Pageable)2 NOT_FOUND (org.springframework.http.HttpStatus.NOT_FOUND)2