diff --git a/src/main/java/org/tkit/onecx/workspace/domain/criteria/WorkspaceSearchCriteria.java b/src/main/java/org/tkit/onecx/workspace/domain/criteria/WorkspaceSearchCriteria.java index 1c97146..1e79325 100644 --- a/src/main/java/org/tkit/onecx/workspace/domain/criteria/WorkspaceSearchCriteria.java +++ b/src/main/java/org/tkit/onecx/workspace/domain/criteria/WorkspaceSearchCriteria.java @@ -18,6 +18,8 @@ public class WorkspaceSearchCriteria implements Serializable { private String baseUrl; + private String productName; + private Integer pageNumber = 0; private Integer pageSize = 100; diff --git a/src/main/java/org/tkit/onecx/workspace/domain/daos/WorkspaceDAO.java b/src/main/java/org/tkit/onecx/workspace/domain/daos/WorkspaceDAO.java index 580a957..94bfa11 100644 --- a/src/main/java/org/tkit/onecx/workspace/domain/daos/WorkspaceDAO.java +++ b/src/main/java/org/tkit/onecx/workspace/domain/daos/WorkspaceDAO.java @@ -14,6 +14,7 @@ import jakarta.persistence.criteria.Predicate; import org.tkit.onecx.workspace.domain.criteria.WorkspaceSearchCriteria; +import org.tkit.onecx.workspace.domain.models.Product_; import org.tkit.onecx.workspace.domain.models.Workspace; import org.tkit.quarkus.jpa.daos.AbstractDAO; import org.tkit.quarkus.jpa.daos.Page; @@ -150,11 +151,17 @@ public PageResult findBySearchCriteria(WorkspaceSearchCriteria criter if (criteria.getNames() != null && !criteria.getNames().isEmpty()) { predicates.add(workspaceTable.get(NAME).in(criteria.getNames())); } - + if (criteria.getProductName() != null && !criteria.getProductName().isEmpty()) { + // cq.where(cb.equal(workspaceTable.get(PRODUCTS).get(Product_.PRODUCT_NAME), criteria.getProductName())); + var workspaceQuery = this.getEntityManager().createQuery(cq); + workspaceQuery.setHint(HINT_LOAD_GRAPH, + this.getEntityManager().getEntityGraph(Workspace.WORKSPACE_PRODUCTS)); + addSearchStringPredicate(predicates, cb, workspaceTable.get(PRODUCTS).get(Product_.PRODUCT_NAME), + criteria.getProductName()); + } if (!predicates.isEmpty()) { cq.where(cb.and(predicates.toArray(new Predicate[0]))); } - cq.orderBy(cb.asc(workspaceTable.get(NAME))); return createPageQuery(cq, Page.of(criteria.getPageNumber(), criteria.getPageSize())).getPageResult(); diff --git a/src/main/java/org/tkit/onecx/workspace/rs/internal/mappers/WorkspaceMapper.java b/src/main/java/org/tkit/onecx/workspace/rs/internal/mappers/WorkspaceMapper.java index 3d1536f..9c97e83 100644 --- a/src/main/java/org/tkit/onecx/workspace/rs/internal/mappers/WorkspaceMapper.java +++ b/src/main/java/org/tkit/onecx/workspace/rs/internal/mappers/WorkspaceMapper.java @@ -43,6 +43,7 @@ public interface WorkspaceMapper { @Mapping(target = "operator", ignore = true) void update(UpdateWorkspaceRequestDTO dto, @MappingTarget Workspace workspace); + @Mapping(target = "productName", ignore = true) @Mapping(target = "baseUrl", ignore = true) @Mapping(target = "names", ignore = true) WorkspaceSearchCriteria map(WorkspaceSearchCriteriaDTO dto); diff --git a/src/test/java/org/tkit/onecx/workspace/rs/external/v1/controllers/WorkspaceExternalV1RestControllerTest.java b/src/test/java/org/tkit/onecx/workspace/rs/external/v1/controllers/WorkspaceExternalV1RestControllerTest.java index 15f1234..e9b854c 100644 --- a/src/test/java/org/tkit/onecx/workspace/rs/external/v1/controllers/WorkspaceExternalV1RestControllerTest.java +++ b/src/test/java/org/tkit/onecx/workspace/rs/external/v1/controllers/WorkspaceExternalV1RestControllerTest.java @@ -95,7 +95,7 @@ void getALlWorkspacesByProductNameTest() { .extract().as(WorkspacePageResultDTOV1.class); assertThat(dto).isNotNull(); - assertThat(dto.getStream()).isNotNull().isNotEmpty().hasSize(6); + assertThat(dto.getStream()).isNotNull().isNotEmpty().hasSize(2); } @Test