Skip to content

Commit

Permalink
fixing filtered query (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciaM1 authored Feb 20, 2024
1 parent 17c81af commit d039664
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class BpmnVersionRepository implements PanacheRepositoryBase<BpmnVersion,
public Uni<PageInfo<BpmnVersion>> findByFilters(Map<String, Object> params, int pageIndex, int pageSize) {
String queryFilters = params.keySet().stream().map(key -> switch (key) {
case "modelVersion", "definitionVersionCamunda", "bpmnId", "status" -> ("b." + key + " = :" + key);
case "acquirerId", "branchId", "terminalId" -> ("bc.bpmnBankConfigPK." + key + " = :" + key);
case "fileName" -> ("b.resourceFile." + key + " LIKE concat(concat('%', :" + key + "), '%')");
default -> ("b." + key + " LIKE concat(concat('%', :" + key + "), '%')");
case "acquirerId", "branchId", "terminalId" -> ("lower(bc.bpmnBankConfigPK." + key + ") = lower(:" + key + ")");
case "fileName" -> ("lower(b.resourceFile." + key + ") LIKE lower(concat(concat(:" + key + "), '%'))");
default -> ("lower(b." + key + ") LIKE lower(concat(concat(:" + key + "), '%'))");
}).collect(Collectors.joining(" and "));
PanacheQuery<BpmnVersion> queryResult = find(("select distinct b from BpmnVersion b").concat(!params.containsKey("acquirerId") ? "" : " join BpmnBankConfig bc on b.bpmnId = bc.bpmnBankConfigPK.bpmnId and b.modelVersion = bc.bpmnBankConfigPK.bpmnModelVersion").concat(queryFilters.isBlank() ? "" : " where " + queryFilters), params).page(Page.of(pageIndex, pageSize));
PanacheQuery<BpmnVersion> queryResult = find(("select distinct b from BpmnVersion b").concat(!params.containsKey("acquirerId") ? "" : " join BpmnBankConfig bc on b.bpmnId = bc.bpmnBankConfigPK.bpmnId and b.modelVersion = bc.bpmnBankConfigPK.bpmnModelVersion").concat(queryFilters.isBlank() ? "" : " where " + queryFilters).concat(" order by b.lastUpdatedAt DESC"), params).page(Page.of(pageIndex, pageSize));
return queryResult.count()
.onItem().transformToUni(count -> {
int totalCount = count.intValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public Uni<ResourceEntity> findBySHA256(String sha256) {
public Uni<PageInfo<ResourceEntity>> findByFilters(Map<String, Object> params, int pageIndex, int pageSize) {
String queryFilters = params.keySet().stream().map(key -> switch (key) {
case "resourceId" -> ("r." + key + " = :" + key);
case "storageKey", "extension" -> ("r.resourceFile." + key +" LIKE concat(concat('%', :" + key + "), '%')");
default -> ("r." + key + " LIKE concat(concat('%', :" + key + "), '%')");
case "storageKey", "extension" -> ("lower(r.resourceFile." + key +") LIKE lower(concat(concat(:" + key + "), '%'))");
default -> ("lower(r." + key + ") LIKE lower(concat(concat(:" + key + "), '%'))");
}).collect(Collectors.joining(" and "));
PanacheQuery<ResourceEntity> queryResult = find(("select r from ResourceEntity r").concat(queryFilters.isBlank() ? "" : " where " + queryFilters), params).page(Page.of(pageIndex, pageSize));
PanacheQuery<ResourceEntity> queryResult = find(("select r from ResourceEntity r").concat(queryFilters.isBlank() ? "" : " where " + queryFilters).concat(" order by r.lastUpdatedAt DESC"), params).page(Page.of(pageIndex, pageSize));
return queryResult.count()
.onItem().transformToUni(count -> {
int totalCount = count.intValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public Uni<List<WorkflowResource>> findByStatus(StatusEnum status, int page, int

public Uni<PageInfo<WorkflowResource>> findByFilters(Map<String, Object> params, int pageIndex, int pageSize) {
String queryFilters = params.keySet().stream().map(key -> switch (key) {
case "fileName" -> ("b.resourceFile." + key + " LIKE concat(concat('%', :" + key + "), '%')");
case "fileName" -> ("lower(b.resourceFile." + key + ") LIKE lower(concat(concat(:" + key + "), '%'))");
case "definitionVersionCamunda", "workflowResourceId", "deploymentId", "status" -> ("b." + key + " = :" + key);
default -> ("b." + key + " LIKE concat(concat('%', :" + key + "), '%')");
default -> ("lower(b." + key + ") LIKE lower(concat(concat(:" + key + "), '%'))");
}).collect(Collectors.joining(" and "));
PanacheQuery<WorkflowResource> queryResult = find(("select b from WorkflowResource b").concat(queryFilters.isBlank() ? "" : " where " + queryFilters), params).page(Page.of(pageIndex, pageSize));
PanacheQuery<WorkflowResource> queryResult = find(("select b from WorkflowResource b").concat(queryFilters.isBlank() ? "" : " where " + queryFilters).concat(" order by b.lastUpdatedAt DESC"), params).page(Page.of(pageIndex, pageSize));
return queryResult.count()
.onItem().transformToUni(count -> {
int totalCount = count.intValue();
Expand Down

0 comments on commit d039664

Please sign in to comment.