Skip to content

Commit

Permalink
Merge remote-tracking branch 'jbiblio/search-processes' into feature/…
Browse files Browse the repository at this point in the history
…search-processes
  • Loading branch information
nitram509 committed Dec 27, 2024
2 parents 5bce254 + 4a2764e commit e881c30
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 18 deletions.
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);
}
50 changes: 33 additions & 17 deletions src/main/java/io/zeebe/monitor/rest/ProcessesViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import jakarta.validation.constraints.Size;
import org.camunda.bpm.model.xml.instance.ModelElementInstance;
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 +59,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("bpmnProcessId") Optional<@Size(min = 3) String> bpmnProcessId) {

if (bpmnProcessId.isPresent()) {
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.remove("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
12 changes: 11 additions & 1 deletion src/main/resources/templates/process-list-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
New Deployment
</button>

<form method="get" action="{{context-path}}views/processes">
<label for="bpmn-search-input">
Search by BPMN Process ID
</label>
<input id="bpmn-search-input" placeholder="BPMN process id" name="bpmnProcessId" type="text" title="Type in a bpmnId" minlength="3" />
<button type="submit">Search</button>
</form>

</div>

<div class="col-md-12">
Expand All @@ -17,6 +25,7 @@

<table class="table table-striped">
<thead>
<tr>
<th>Process Definition Key</th>
<th>BPMN process id</th>
<th>Version</th>
Expand All @@ -28,6 +37,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 +64,4 @@
document.addEventListener('DOMContentLoaded', function(){
listSort('timestamp','process-deployment-time')
}, false);
</script>
</script>

0 comments on commit e881c30

Please sign in to comment.