Search in sources :

Example 1 with VariableEntity

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

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

the class VariableImporter method importVariable.

public void importVariable(final Schema.VariableRecord record) {
    final VariableEntity newVariable = new VariableEntity();
    newVariable.setPosition(record.getMetadata().getPosition());
    newVariable.setPartitionId(record.getMetadata().getPartitionId());
    if (!variableRepository.existsById(newVariable.getGeneratedIdentifier())) {
        newVariable.setTimestamp(record.getMetadata().getTimestamp());
        newVariable.setProcessInstanceKey(record.getProcessInstanceKey());
        newVariable.setName(record.getName());
        newVariable.setValue(record.getValue());
        newVariable.setScopeKey(record.getScopeKey());
        newVariable.setState(record.getMetadata().getIntent().toLowerCase());
        variableRepository.save(newVariable);
    }
}
Also used : VariableEntity(io.zeebe.monitor.entity.VariableEntity)

Example 3 with VariableEntity

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

the class VariableRepositoryTest method createVariable.

private VariableEntity createVariable() {
    VariableEntity variable = new VariableEntity();
    variable.setPartitionId(123);
    variable.setPosition(456L);
    return variable;
}
Also used : VariableEntity(io.zeebe.monitor.entity.VariableEntity)

Example 4 with VariableEntity

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

the class VariableRepositoryTest method JPA_will_automatically_update_the_ID_attribute.

@Test
public void JPA_will_automatically_update_the_ID_attribute() {
    // given
    VariableEntity variable = createVariable();
    // when
    variableRepository.save(variable);
    // then
    assertThat(variable.getId()).isEqualTo("123-456");
}
Also used : VariableEntity(io.zeebe.monitor.entity.VariableEntity) Test(org.junit.jupiter.api.Test)

Example 5 with VariableEntity

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

the class VariableRepositoryTest method variable_can_be_retrieved_by_transient_ID.

@Test
public void variable_can_be_retrieved_by_transient_ID() {
    // given
    VariableEntity variable = createVariable();
    // when
    variableRepository.save(variable);
    // then
    Optional<VariableEntity> entity = variableRepository.findById("123-456");
    assertThat(entity).isPresent();
}
Also used : VariableEntity(io.zeebe.monitor.entity.VariableEntity) Test(org.junit.jupiter.api.Test)

Aggregations

VariableEntity (io.zeebe.monitor.entity.VariableEntity)5 Test (org.junit.jupiter.api.Test)2 ElementInstanceEntity (io.zeebe.monitor.entity.ElementInstanceEntity)1 IncidentEntity (io.zeebe.monitor.entity.IncidentEntity)1 ProcessInstanceEntity (io.zeebe.monitor.entity.ProcessInstanceEntity)1 VariableRepository (io.zeebe.monitor.repository.VariableRepository)1 ProcessInstanceDto (io.zeebe.monitor.rest.dto.ProcessInstanceDto)1 VariableEntry (io.zeebe.monitor.rest.dto.VariableEntry)1 VariableUpdateEntry (io.zeebe.monitor.rest.dto.VariableUpdateEntry)1 Instant (java.time.Instant)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Transactional (javax.transaction.Transactional)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Pageable (org.springframework.data.domain.Pageable)1 PageableDefault (org.springframework.data.web.PageableDefault)1 Controller (org.springframework.stereotype.Controller)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1