Skip to content

Commit

Permalink
feat(ui) add incident search filter for created before and after camu…
Browse files Browse the repository at this point in the history
  • Loading branch information
nitram509 committed Oct 5, 2022
1 parent dfac068 commit 58a6aaf
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
import com.querydsl.core.types.dsl.PathBuilder;
import io.zeebe.monitor.entity.QIncidentEntity;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static org.apache.commons.lang3.StringUtils.isEmpty;

public class IncidentEntityPredicatesBuilder {
final PathBuilder<QIncidentEntity> pathBuilder = new PathBuilder<>(QIncidentEntity.class, QIncidentEntity.incidentEntity.getMetadata());
private List<Predicate> predicates = new ArrayList<>();
private final List<Predicate> predicates = new ArrayList<>();

public IncidentEntityPredicatesBuilder onlyUnresolved() {
predicates.add(pathBuilder.getNumber("resolved", Long.class).isNull());
Expand All @@ -34,11 +39,38 @@ public IncidentEntityPredicatesBuilder withErrorType(String errorType) {
return this;
}

public BooleanExpression build() {
public IncidentEntityPredicatesBuilder createdAfter(String timestamp) {
if (!isEmpty(timestamp)) {
final Optional<Long> created = parseIsoToUtcMillis(timestamp);
created.ifPresent(utcMillis -> predicates.add(pathBuilder.getNumber("created", Long.class).goe(utcMillis)));
}
return this;
}

public IncidentEntityPredicatesBuilder createdBefore(String timestamp) {
if (!isEmpty(timestamp)) {
final Optional<Long> created = parseIsoToUtcMillis(timestamp);
created.ifPresent(utcMillis -> predicates.add(pathBuilder.getNumber("created", Long.class).loe(utcMillis)));
}
return this;
}

public Predicate build() {
BooleanExpression result = Expressions.asBoolean(true).isTrue();
for (Predicate predicate : predicates) {
result = result.and(predicate);
}
return result;
}

private Optional<Long> parseIsoToUtcMillis(String timestamp) {
try {
final ZonedDateTime zonedDateTime = ZonedDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(timestamp));
final long utcMillis = zonedDateTime.withZoneSameInstant(ZoneId.of("UTC")).toInstant().toEpochMilli();
return Optional.of(utcMillis);
} catch (DateTimeParseException ignore) {
// ignore
}
return Optional.empty();
}
}
24 changes: 14 additions & 10 deletions src/main/java/io/zeebe/monitor/rest/IncidentsViewController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.zeebe.monitor.rest;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.Predicate;
import io.zeebe.monitor.entity.IncidentEntity;
import io.zeebe.monitor.querydsl.IncidentEntityPredicatesBuilder;
import io.zeebe.monitor.repository.IncidentRepository;
Expand Down Expand Up @@ -28,15 +28,19 @@ public class IncidentsViewController extends AbstractViewController {
public String incidentList(final Map<String, Object> model,
final Pageable pageable,
@RequestParam(required = false) String bpmnProcessId,
@RequestParam(required = false) String errorType) {

final IncidentEntityPredicatesBuilder predicatesBuilder = new IncidentEntityPredicatesBuilder();
predicatesBuilder.onlyUnresolved();
predicatesBuilder.withProcessId(bpmnProcessId);
predicatesBuilder.withErrorType(errorType);
final BooleanExpression predicates = predicatesBuilder.build();

final Page<IncidentEntity> dtos = incidentRepository.findAll(predicates, pageable);
@RequestParam(required = false) String errorType,
@RequestParam(required = false) String createdAfter,
@RequestParam(required = false) String createdBefore) {

final Predicate predicate = new IncidentEntityPredicatesBuilder()
.onlyUnresolved()
.withProcessId(bpmnProcessId)
.withErrorType(errorType)
.createdAfter(createdAfter)
.createdBefore(createdBefore)
.build();

final Page<IncidentEntity> dtos = incidentRepository.findAll(predicate, pageable);
final List<IncidentListDto> incidents = new ArrayList<>();
for (final IncidentEntity incidentEntity : dtos) {
final IncidentListDto dto = toDto(incidentEntity);
Expand Down
19 changes: 14 additions & 5 deletions src/main/resources/templates/incident-list-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@
<div class="form-row align-items-center">
<div class="col-auto">
<div class="input-group mb-2">
<input type="text" class="form-control" id="filter-process-id" name="bpmnProcessId" placeholder="Process ID">
<input type="text" class="form-control" id="filter-process-id" name="bpmnProcessId" placeholder="process id" style="width: 15em">
</div>
</div>
<div class="col-auto">
<div class="input-group mb-2">
<input type="text" class="form-control" id="filter-error-type" name="errorType" placeholder="Error Type">
<input type="text" class="form-control" id="filter-error-type" name="errorType" placeholder="error type" style="width: 15em">
</div>
</div>
<div class="col-auto">
<div class="input-group mb-2">
<input type="text" class="form-control" id="filter-created-after" name="createdAfter" placeholder="created after" style="width: 15em">
</div>
</div>
<div class="col-auto">
<div class="input-group mb-2">
<input type="text" class="form-control" id="filter-created-before" name="createdBefore" placeholder="created before" style="width: 15em">
</div>
</div>
<div class="col-auto">
Expand Down Expand Up @@ -80,12 +90,11 @@
document.addEventListener('DOMContentLoaded', function(){
listSort('created','created-time')
}, false);
</script>

<script type="application/javascript">
document.addEventListener('DOMContentLoaded', function() {
bindQueryParamToElement("filter-process-id", "bpmnProcessId");
bindQueryParamToElement("filter-error-type", "errorType");
bindQueryParamToElement("filter-created-after", "createdAfter");
bindQueryParamToElement("filter-created-before", "createdBefore");
}, false);
</script>
</div>
Expand Down

0 comments on commit 58a6aaf

Please sign in to comment.