Search in sources :

Example 1 with IncidentEntity

use of io.zeebe.monitor.entity.IncidentEntity 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 IncidentEntity

use of io.zeebe.monitor.entity.IncidentEntity 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 3 with IncidentEntity

use of io.zeebe.monitor.entity.IncidentEntity 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 4 with IncidentEntity

use of io.zeebe.monitor.entity.IncidentEntity in project zeebe-simple-monitor by camunda-community-hub.

the class IncidentImporter method importIncident.

public void importIncident(final Schema.IncidentRecord record) {
    final IncidentIntent intent = IncidentIntent.valueOf(record.getMetadata().getIntent());
    final long key = record.getMetadata().getKey();
    final long timestamp = record.getMetadata().getTimestamp();
    final IncidentEntity entity = incidentRepository.findById(key).orElseGet(() -> {
        final IncidentEntity newEntity = new IncidentEntity();
        newEntity.setKey(key);
        newEntity.setBpmnProcessId(record.getBpmnProcessId());
        newEntity.setProcessDefinitionKey(record.getProcessDefinitionKey());
        newEntity.setProcessInstanceKey(record.getProcessInstanceKey());
        newEntity.setElementInstanceKey(record.getElementInstanceKey());
        newEntity.setJobKey(record.getJobKey());
        newEntity.setErrorType(record.getErrorType());
        newEntity.setErrorMessage(record.getErrorMessage());
        return newEntity;
    });
    if (intent == IncidentIntent.CREATED) {
        entity.setCreated(timestamp);
        incidentRepository.save(entity);
    } else if (intent == IncidentIntent.RESOLVED) {
        entity.setResolved(timestamp);
        incidentRepository.save(entity);
    }
}
Also used : IncidentEntity(io.zeebe.monitor.entity.IncidentEntity) IncidentIntent(io.camunda.zeebe.protocol.record.intent.IncidentIntent)

Example 5 with IncidentEntity

use of io.zeebe.monitor.entity.IncidentEntity in project zeebe-simple-monitor by camunda-community-hub.

the class InstancesCalledProcessesListViewController 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 calledProcessInstances = processInstanceRepository.findByParentProcessInstanceKey(instance.getKey(), pageable).stream().map(childEntity -> {
        final var childDto = new CalledProcessInstanceDto();
        childDto.setChildProcessInstanceKey(childEntity.getKey());
        childDto.setChildBpmnProcessId(childEntity.getBpmnProcessId());
        childDto.setChildState(childEntity.getState());
        childDto.setElementInstanceKey(childEntity.getParentElementInstanceKey());
        final var callElementId = elementIdsForKeys.getOrDefault(childEntity.getParentElementInstanceKey(), "");
        childDto.setElementId(callElementId);
        return childDto;
    }).collect(Collectors.toList());
    dto.setCalledProcessInstances(calledProcessInstances);
    final long count = processInstanceRepository.countByParentProcessInstanceKey(instance.getKey());
    addPaginationToModel(model, pageable, count);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) ProcessInstanceEntity(io.zeebe.monitor.entity.ProcessInstanceEntity) Transactional(javax.transaction.Transactional) CalledProcessInstanceDto(io.zeebe.monitor.rest.dto.CalledProcessInstanceDto) ElementInstanceEntity(io.zeebe.monitor.entity.ElementInstanceEntity) Controller(org.springframework.stereotype.Controller) Collectors(java.util.stream.Collectors) List(java.util.List) ProcessInstanceDto(io.zeebe.monitor.rest.dto.ProcessInstanceDto) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) Pageable(org.springframework.data.domain.Pageable) PageableDefault(org.springframework.data.web.PageableDefault) IncidentEntity(io.zeebe.monitor.entity.IncidentEntity) CalledProcessInstanceDto(io.zeebe.monitor.rest.dto.CalledProcessInstanceDto)

Aggregations

IncidentEntity (io.zeebe.monitor.entity.IncidentEntity)7 ElementInstanceEntity (io.zeebe.monitor.entity.ElementInstanceEntity)5 ProcessInstanceEntity (io.zeebe.monitor.entity.ProcessInstanceEntity)5 ProcessInstanceDto (io.zeebe.monitor.rest.dto.ProcessInstanceDto)5 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Transactional (javax.transaction.Transactional)4 Pageable (org.springframework.data.domain.Pageable)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 Instant (java.time.Instant)3 HashMap (java.util.HashMap)3 PageableDefault (org.springframework.data.web.PageableDefault)3 Controller (org.springframework.stereotype.Controller)3 PathVariable (org.springframework.web.bind.annotation.PathVariable)3 ArrayList (java.util.ArrayList)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Mustache (com.samskivert.mustache.Mustache)1 Template (com.samskivert.mustache.Template)1 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)1