Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search processes by their BPMN ID - version 2 #757

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<!-- pin Hazelcast version because of spring-boot-dependencies -->
<version.hazelcast>5.5.0</version.hazelcast>

<version.hibernate.validator>8.0.1.Final</version.hibernate.validator>

<!-- release parent settings -->
<version.java>17</version.java>
<java.version>${version.java}</java.version>
Expand Down Expand Up @@ -198,6 +200,12 @@
<artifactId>mysql-connector-j</artifactId>
</dependency>

<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${version.hibernate.validator}</version>
</dependency>

<!-- js libs -->

<dependency>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/zeebe/monitor/entity/ProcessEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import org.hibernate.Length;

@Entity(name = "PROCESS")
@Table(indexes = {
@Index(name = "process_bpmnProcessId", columnList = "BPMN_PROCESS_ID_"),
})
public class ProcessEntity {
@Id
@Column(name = "KEY_")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import java.util.Collection;
import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface ProcessRepository extends PagingAndSortingRepository<ProcessEntity, Long>, CrudRepository<ProcessEntity, Long> {

Expand All @@ -40,4 +42,7 @@ List<ElementInstanceStatistics> getElementInstanceStatisticsByKeyAndIntentIn(
@Param("key") long key,
@Param("intents") Collection<String> intents,
@Param("excludeElementTypes") Collection<String> excludeElementTypes);

@Transactional(readOnly = true)
List<ProcessEntity> findByBpmnProcessIdStartsWith(String bpmnProcessId);
}
49 changes: 32 additions & 17 deletions src/main/java/io/zeebe/monitor/rest/ProcessesViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

@Controller
Expand All @@ -59,26 +58,42 @@ public class ProcessesViewController extends AbstractViewController {

@GetMapping("/")
public String index(final Map<String, Object> model, final Pageable pageable) {
return processList(model, pageable);
return processList(model, pageable, Optional.empty());
}

@GetMapping("/views/processes")
public String processList(final Map<String, Object> model, final Pageable pageable) {

final long count = processRepository.count();

final List<ProcessDto> processes = new ArrayList<>();
for (final ProcessEntity processEntity : processRepository.findAll(pageable)) {
final ProcessDto dto = toDto(processEntity);
processes.add(dto);
public String processList(final Map<String, Object> model, final Pageable pageable, @RequestParam(value = "bpmnProcessId", required = false) Optional<String> bpmnProcessId) {

if (bpmnProcessId.isPresent() && bpmnProcessId.get().length() >= 3) {
final List<ProcessDto> processes = new ArrayList<>();
for (final ProcessEntity processEntity : processRepository.findByBpmnProcessIdStartsWith(bpmnProcessId.get())) {
final ProcessDto dto = toDto(processEntity);
processes.add(dto);
}

model.put("processes", processes);
model.put("bpmnProcessId", bpmnProcessId.get());
model.put("count", processes.size());

addPaginationToModel(model, Pageable.ofSize(Integer.MAX_VALUE), processes.size());
addDefaultAttributesToModel(model);
} else {
final long count = processRepository.count();

final List<ProcessDto> processes = new ArrayList<>();
for (final ProcessEntity processEntity : processRepository.findAll(pageable)) {
final ProcessDto dto = toDto(processEntity);
processes.add(dto);
}

model.put("processes", processes);
model.put("bpmnProcessId", "");
model.put("count", count);

addPaginationToModel(model, pageable, count);
addDefaultAttributesToModel(model);
}

model.put("processes", processes);
model.put("count", count);

addPaginationToModel(model, pageable, count);
addDefaultAttributesToModel(model);

return "process-list-view";
}

Expand Down
13 changes: 11 additions & 2 deletions src/main/resources/templates/process-list-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@
New Deployment
</button>

<form class="form-inline" method="get" action="{{context-path}}views/processes">
<div class="form-group mb-2 col-sm-3">
<label class="mx-sm-2" for="bpmn-search-input" >Search by</label>
<input class="col-sm-9 form-control" id="bpmn-search-input" placeholder="BPMN process id (min 3 characters)" name="bpmnProcessId" type="text" title="BPMN process id (min 3 characters)" value="{{bpmnProcessId}}" />
</div>
<button class="btn btn-secondary mb-2" type="submit">Search</button>
</form>
</div>

<div class="col-md-12">
<div class="col-md-12 border-top">

<span>{{count}} process definitions</span>

<table class="table table-striped">
<thead>
<tr>
<th>Process Definition Key</th>
<th>BPMN process id</th>
<th>Version</th>
Expand All @@ -28,6 +36,7 @@
<svg class="bi" width="12" height="12" fill="white"><use xlink:href="/img/bootstrap-icons.svg#caret-up-fill"/></svg>
</a>
</th>
</tr>
</thead>

{{#processes}}
Expand All @@ -54,4 +63,4 @@
document.addEventListener('DOMContentLoaded', function(){
listSort('timestamp','process-deployment-time')
}, false);
</script>
</script>
Loading