From 2b2b7363273e5b6d6f677ffe376ec5f781100776 Mon Sep 17 00:00:00 2001 From: JordenReuter <149687553+JordenReuter@users.noreply.github.com> Date: Thu, 16 May 2024 13:00:04 +0200 Subject: [PATCH] feat: added operator flag and exception handling (#52) --- .../domain/di/mappers/TemplateMapper.java | 1 + .../permission/domain/models/Permission.java | 6 +++++ .../controllers/PermissionRestController.java | 6 +++++ .../rs/internal/mappers/PermissionMapper.java | 4 +++- .../v1/mappers/OperatorPermissionMapper.java | 1 + .../onecx-permission-internal-openapi.yaml | 3 +++ src/main/resources/db/changeLog.xml | 1 + .../db/v1/2024-05-16-operator-flag.xml | 13 +++++++++++ .../PermissionRestControllerTest.java | 22 ++++++++++++++----- src/test/resources/data/test-internal.xml | 2 ++ 10 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/db/v1/2024-05-16-operator-flag.xml diff --git a/src/main/java/org/tkit/onecx/permission/domain/di/mappers/TemplateMapper.java b/src/main/java/org/tkit/onecx/permission/domain/di/mappers/TemplateMapper.java index 7d078e6..95f06e0 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/di/mappers/TemplateMapper.java +++ b/src/main/java/org/tkit/onecx/permission/domain/di/mappers/TemplateMapper.java @@ -20,6 +20,7 @@ public interface TemplateMapper { @Mapping(target = "persisted", ignore = true) Application createApplication(String productName, String appId, String name, String description); + @Mapping(target = "operator", constant = "false") @Mapping(target = "mandatory", ignore = true) @Mapping(target = "id", ignore = true) @Mapping(target = "creationDate", ignore = true) diff --git a/src/main/java/org/tkit/onecx/permission/domain/models/Permission.java b/src/main/java/org/tkit/onecx/permission/domain/models/Permission.java index 50744f2..0456687 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/models/Permission.java +++ b/src/main/java/org/tkit/onecx/permission/domain/models/Permission.java @@ -46,4 +46,10 @@ public class Permission extends TraceableEntity { @Column(name = "MANDATORY") private Boolean mandatory; + /** + * Flag to identify permissions created by an operator + */ + @Column(name = "OPERATOR") + private Boolean operator; + } diff --git a/src/main/java/org/tkit/onecx/permission/rs/internal/controllers/PermissionRestController.java b/src/main/java/org/tkit/onecx/permission/rs/internal/controllers/PermissionRestController.java index b39d6f2..48c84aa 100644 --- a/src/main/java/org/tkit/onecx/permission/rs/internal/controllers/PermissionRestController.java +++ b/src/main/java/org/tkit/onecx/permission/rs/internal/controllers/PermissionRestController.java @@ -13,6 +13,7 @@ import org.tkit.onecx.permission.domain.services.PermissionService; import org.tkit.onecx.permission.rs.internal.mappers.ExceptionMapper; import org.tkit.onecx.permission.rs.internal.mappers.PermissionMapper; +import org.tkit.quarkus.jpa.exceptions.ConstraintException; import org.tkit.quarkus.log.cdi.LogService; import gen.org.tkit.onecx.permission.rs.internal.PermissionInternalApi; @@ -86,4 +87,9 @@ public Response updatePermission(String id, UpdatePermissionRequestDTO updatePer public RestResponse constraint(ConstraintViolationException ex) { return exceptionMapper.constraint(ex); } + + @ServerExceptionMapper + public RestResponse constraint(ConstraintException ex) { + return exceptionMapper.exception(ex); + } } diff --git a/src/main/java/org/tkit/onecx/permission/rs/internal/mappers/PermissionMapper.java b/src/main/java/org/tkit/onecx/permission/rs/internal/mappers/PermissionMapper.java index 50e50e4..7327c24 100644 --- a/src/main/java/org/tkit/onecx/permission/rs/internal/mappers/PermissionMapper.java +++ b/src/main/java/org/tkit/onecx/permission/rs/internal/mappers/PermissionMapper.java @@ -20,7 +20,8 @@ public interface PermissionMapper { PermissionDTO map(Permission data); - @Mapping(target = "mandatory", ignore = true) + @Mapping(target = "mandatory", constant = "false") + @Mapping(target = "operator", constant = "false") @Mapping(target = "id", ignore = true) @Mapping(target = "creationDate", ignore = true) @Mapping(target = "creationUser", ignore = true) @@ -31,6 +32,7 @@ public interface PermissionMapper { @Mapping(target = "persisted", ignore = true) Permission create(CreatePermissionRequestDTO dto); + @Mapping(target = "operator", ignore = true) @Mapping(target = "mandatory", ignore = true) @Mapping(target = "id", ignore = true) @Mapping(target = "creationDate", ignore = true) diff --git a/src/main/java/org/tkit/onecx/permission/rs/operator/v1/mappers/OperatorPermissionMapper.java b/src/main/java/org/tkit/onecx/permission/rs/operator/v1/mappers/OperatorPermissionMapper.java index 9dc17b7..807effb 100644 --- a/src/main/java/org/tkit/onecx/permission/rs/operator/v1/mappers/OperatorPermissionMapper.java +++ b/src/main/java/org/tkit/onecx/permission/rs/operator/v1/mappers/OperatorPermissionMapper.java @@ -52,6 +52,7 @@ default List map(List list, String appId, String pr return data; } + @Mapping(target = "operator", constant = "true") @Mapping(target = "mandatory", ignore = true) @Mapping(target = "id", ignore = true) @Mapping(target = "creationDate", ignore = true) diff --git a/src/main/openapi/onecx-permission-internal-openapi.yaml b/src/main/openapi/onecx-permission-internal-openapi.yaml index 1917a71..73de14d 100644 --- a/src/main/openapi/onecx-permission-internal-openapi.yaml +++ b/src/main/openapi/onecx-permission-internal-openapi.yaml @@ -796,6 +796,9 @@ components: mandatory: type: boolean default: false + operator: + type: boolean + default: false CreatePermissionRequest: type: object properties: diff --git a/src/main/resources/db/changeLog.xml b/src/main/resources/db/changeLog.xml index 00e5c08..6e329ac 100644 --- a/src/main/resources/db/changeLog.xml +++ b/src/main/resources/db/changeLog.xml @@ -7,5 +7,6 @@ + \ No newline at end of file diff --git a/src/main/resources/db/v1/2024-05-16-operator-flag.xml b/src/main/resources/db/v1/2024-05-16-operator-flag.xml new file mode 100644 index 0000000..a5a593e --- /dev/null +++ b/src/main/resources/db/v1/2024-05-16-operator-flag.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/PermissionRestControllerTest.java b/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/PermissionRestControllerTest.java index 26f740c..7776c04 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/PermissionRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/PermissionRestControllerTest.java @@ -38,8 +38,8 @@ void searchTest() { .as(PermissionPageResultDTO.class); assertThat(data).isNotNull(); - assertThat(data.getTotalElements()).isEqualTo(7); - assertThat(data.getStream()).isNotNull().hasSize(7); + assertThat(data.getTotalElements()).isEqualTo(8); + assertThat(data.getStream()).isNotNull().hasSize(8); criteria.setAppId(" "); @@ -54,8 +54,8 @@ void searchTest() { .as(PermissionPageResultDTO.class); assertThat(data).isNotNull(); - assertThat(data.getTotalElements()).isEqualTo(7); - assertThat(data.getStream()).isNotNull().hasSize(7); + assertThat(data.getTotalElements()).isEqualTo(8); + assertThat(data.getStream()).isNotNull().hasSize(8); } @Test @@ -90,8 +90,8 @@ void searchCriteriaTest() { .as(PermissionPageResultDTO.class); assertThat(output).isNotNull(); - assertThat(output.getTotalElements()).isEqualTo(7); - assertThat(output.getStream()).isNotNull().hasSize(7); + assertThat(output.getTotalElements()).isEqualTo(8); + assertThat(output.getStream()).isNotNull().hasSize(8); } @@ -170,6 +170,16 @@ void deletePermissionTest() { } + @Test + void deletePermissionWithAssignmentByDifferentTenantTest() { + + given() + .contentType(APPLICATION_JSON) + .delete("p23") + .then() + .statusCode(BAD_REQUEST.getStatusCode()); + } + @Test void updatePermissionTest() { var criteria = new UpdatePermissionRequestDTO(); diff --git a/src/test/resources/data/test-internal.xml b/src/test/resources/data/test-internal.xml index d1bbc5d..fa0049e 100644 --- a/src/test/resources/data/test-internal.xml +++ b/src/test/resources/data/test-internal.xml @@ -14,6 +14,7 @@ + @@ -29,6 +30,7 @@ + \ No newline at end of file