Search in sources :

Example 1 with ElementInstanceEntity

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);
}
Also used : ActiveScope(io.zeebe.monitor.rest.dto.ActiveScope) 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) ArrayList(java.util.ArrayList)

Example 2 with ElementInstanceEntity

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);
}
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 3 with ElementInstanceEntity

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());
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) ProcessInstanceEntity(io.zeebe.monitor.entity.ProcessInstanceEntity) Transactional(javax.transaction.Transactional) FlowElement(io.camunda.zeebe.model.bpmn.instance.FlowElement) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) ElementInstanceEntity(io.zeebe.monitor.entity.ElementInstanceEntity) HashMap(java.util.HashMap) Controller(org.springframework.stereotype.Controller) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) ProcessInstanceDto(io.zeebe.monitor.rest.dto.ProcessInstanceDto) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessesViewController.getBpmnElementInfos(io.zeebe.monitor.rest.ProcessesViewController.getBpmnElementInfos) Map(java.util.Map) Optional(java.util.Optional) GetMapping(org.springframework.web.bind.annotation.GetMapping) Pageable(org.springframework.data.domain.Pageable) PageableDefault(org.springframework.data.web.PageableDefault) AuditLogEntry(io.zeebe.monitor.rest.dto.AuditLogEntry) IncidentEntity(io.zeebe.monitor.entity.IncidentEntity) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) AuditLogEntry(io.zeebe.monitor.rest.dto.AuditLogEntry) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) FlowElement(io.camunda.zeebe.model.bpmn.instance.FlowElement)

Example 4 with ElementInstanceEntity

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);
}
Also used : VariableEntry(io.zeebe.monitor.rest.dto.VariableEntry) PathVariable(org.springframework.web.bind.annotation.PathVariable) ProcessInstanceEntity(io.zeebe.monitor.entity.ProcessInstanceEntity) Transactional(javax.transaction.Transactional) Autowired(org.springframework.beans.factory.annotation.Autowired) ElementInstanceEntity(io.zeebe.monitor.entity.ElementInstanceEntity) Controller(org.springframework.stereotype.Controller) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) ProcessInstanceDto(io.zeebe.monitor.rest.dto.ProcessInstanceDto) VariableEntity(io.zeebe.monitor.entity.VariableEntity) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) VariableRepository(io.zeebe.monitor.repository.VariableRepository) VariableUpdateEntry(io.zeebe.monitor.rest.dto.VariableUpdateEntry) Pageable(org.springframework.data.domain.Pageable) PageableDefault(org.springframework.data.web.PageableDefault) IncidentEntity(io.zeebe.monitor.entity.IncidentEntity) VariableEntry(io.zeebe.monitor.rest.dto.VariableEntry) VariableEntity(io.zeebe.monitor.entity.VariableEntity) VariableUpdateEntry(io.zeebe.monitor.rest.dto.VariableUpdateEntry) List(java.util.List)

Example 5 with ElementInstanceEntity

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");
}
Also used : ElementInstanceEntity(io.zeebe.monitor.entity.ElementInstanceEntity) Test(org.junit.jupiter.api.Test)

Aggregations

ElementInstanceEntity (io.zeebe.monitor.entity.ElementInstanceEntity)10 IncidentEntity (io.zeebe.monitor.entity.IncidentEntity)6 ProcessInstanceEntity (io.zeebe.monitor.entity.ProcessInstanceEntity)6 ProcessInstanceDto (io.zeebe.monitor.rest.dto.ProcessInstanceDto)6 List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 Pageable (org.springframework.data.domain.Pageable)5 Instant (java.time.Instant)4 HashMap (java.util.HashMap)4 Transactional (javax.transaction.Transactional)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 PageableDefault (org.springframework.data.web.PageableDefault)3 Controller (org.springframework.stereotype.Controller)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 PathVariable (org.springframework.web.bind.annotation.PathVariable)3 Mustache (com.samskivert.mustache.Mustache)2 Template (com.samskivert.mustache.Template)2 BpmnElementType (io.camunda.zeebe.protocol.record.value.BpmnElementType)2 ElementInstanceRepository (io.zeebe.monitor.repository.ElementInstanceRepository)2