diff --git a/src/main/java/org/tkit/onecx/permission/domain/criteria/AssignmentSearchCriteria.java b/src/main/java/org/tkit/onecx/permission/domain/criteria/AssignmentSearchCriteria.java index 1595f59..1701b83 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/criteria/AssignmentSearchCriteria.java +++ b/src/main/java/org/tkit/onecx/permission/domain/criteria/AssignmentSearchCriteria.java @@ -7,7 +7,7 @@ @Setter public class AssignmentSearchCriteria { - private String appId; + private String[] appId; private Integer pageNumber; private Integer pageSize; } diff --git a/src/main/java/org/tkit/onecx/permission/domain/daos/AssignmentDAO.java b/src/main/java/org/tkit/onecx/permission/domain/daos/AssignmentDAO.java index e27b335..711a78d 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/daos/AssignmentDAO.java +++ b/src/main/java/org/tkit/onecx/permission/domain/daos/AssignmentDAO.java @@ -1,13 +1,10 @@ package org.tkit.onecx.permission.domain.daos; -import static org.tkit.quarkus.jpa.utils.QueryCriteriaUtil.addSearchStringPredicate; - -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import jakarta.enterprise.context.ApplicationScoped; import jakarta.persistence.NoResultException; -import jakarta.persistence.criteria.Predicate; import jakarta.transaction.Transactional; import org.tkit.onecx.permission.domain.criteria.AssignmentSearchCriteria; @@ -47,13 +44,11 @@ public PageResult findByCriteria(AssignmentSearchCriteria criteria) var cq = cb.createQuery(Assignment.class); var root = cq.from(Assignment.class); - List predicates = new ArrayList<>(); - - addSearchStringPredicate(predicates, cb, root.get(Assignment_.permission).get(Permission_.APP_ID), - criteria.getAppId()); - - if (!predicates.isEmpty()) { - cq.where(predicates.toArray(new Predicate[] {})); + if (criteria.getAppId() != null) { + List filteredAppIds = Arrays.stream(criteria.getAppId()).filter(s -> !s.isBlank()).toList(); + if (!filteredAppIds.isEmpty()) { + cq.where(root.get(Assignment_.permission).get(Permission_.APP_ID).in(filteredAppIds)); + } } cq.orderBy(cb.asc(root.get(AbstractTraceableEntity_.creationDate))); diff --git a/src/main/java/org/tkit/onecx/permission/rs/internal/mappers/AssignmentMapper.java b/src/main/java/org/tkit/onecx/permission/rs/internal/mappers/AssignmentMapper.java index 11e618c..2885012 100644 --- a/src/main/java/org/tkit/onecx/permission/rs/internal/mappers/AssignmentMapper.java +++ b/src/main/java/org/tkit/onecx/permission/rs/internal/mappers/AssignmentMapper.java @@ -34,5 +34,6 @@ public interface AssignmentMapper { @Mapping(target = "permissionId", ignore = true) Assignment create(Role role, Permission permission); + @Mapping(target = "appId", source = "permission.appId") AssignmentDTO map(Assignment data); } diff --git a/src/main/openapi/onecx-permission-internal-openapi.yaml b/src/main/openapi/onecx-permission-internal-openapi.yaml index b208c39..5bf0a7c 100644 --- a/src/main/openapi/onecx-permission-internal-openapi.yaml +++ b/src/main/openapi/onecx-permission-internal-openapi.yaml @@ -176,8 +176,8 @@ paths: schema: $ref: '#/components/schemas/UpdateRoleRequest' responses: - 204: - description: Theme updated + 200: + description: Role updated content: application/json: schema: @@ -291,7 +291,9 @@ components: type: object properties: appId: - type: string + type: array + items: + type: string pageNumber: format: int32 description: The number of page. @@ -350,6 +352,8 @@ components: type: string permissionId: type: string + appId: + type: string UpdateRoleRequest: type: object required: diff --git a/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java b/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java index a7871ef..3dc5a84 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java @@ -7,6 +7,8 @@ import static org.jboss.resteasy.reactive.RestResponse.Status.*; import static org.jboss.resteasy.reactive.RestResponse.Status.BAD_REQUEST; +import java.util.List; + import jakarta.ws.rs.core.HttpHeaders; import org.junit.jupiter.api.Test; @@ -136,7 +138,7 @@ void searchAssignmentTest() { assertThat(data.getTotalElements()).isEqualTo(3); assertThat(data.getStream()).isNotNull().hasSize(3); - criteria.setAppId(" "); + criteria.setAppId(List.of(" ")); data = given() .contentType(APPLICATION_JSON) @@ -152,11 +154,13 @@ void searchAssignmentTest() { assertThat(data.getTotalElements()).isEqualTo(3); assertThat(data.getStream()).isNotNull().hasSize(3); - criteria.setAppId("app1"); + var criteria2 = new AssignmentSearchCriteriaDTO(); + + criteria2.setAppId(List.of("app1")); data = given() .contentType(APPLICATION_JSON) - .body(criteria) + .body(criteria2) .post("/search") .then().log().all() .statusCode(OK.getStatusCode()) @@ -167,6 +171,25 @@ void searchAssignmentTest() { assertThat(data).isNotNull(); assertThat(data.getTotalElements()).isEqualTo(2); assertThat(data.getStream()).isNotNull().hasSize(2); + + //get by multiple appIds + var multipleAppIdsCriteria = new AssignmentSearchCriteriaDTO(); + multipleAppIdsCriteria.appId(List.of("app1", "app2", "")); + + var multipleAppIdsResult = given() + .contentType(APPLICATION_JSON) + .body(multipleAppIdsCriteria) + .post("/search") + .then() + .statusCode(OK.getStatusCode()) + .contentType(APPLICATION_JSON) + .extract() + .as(AssignmentPageResultDTO.class); + + assertThat(multipleAppIdsResult).isNotNull(); + assertThat(multipleAppIdsResult.getTotalElements()).isEqualTo(3); + assertThat(multipleAppIdsResult.getStream()).isNotNull().hasSize(3); + } @Test