From ec63a98a0eed4377e636ad0e4582d68c191a81dd Mon Sep 17 00:00:00 2001 From: Jorden_Reuter Date: Fri, 12 Jul 2024 11:03:08 +0200 Subject: [PATCH] feat: added disabled flag --- .../onecx/workspace/domain/daos/WorkspaceDAO.java | 4 +++- .../workspace/domain/di/mappers/TemplateMapper.java | 1 + .../onecx/workspace/domain/models/Workspace.java | 6 ++++++ .../rs/exim/v1/mappers/ExportImportMapperV1.java | 1 + .../openapi/onecx-workspace-internal-openapi.yaml | 10 ++++++++++ src/main/openapi/onecx-workspace-v1-openapi.yaml | 8 ++++++++ src/main/resources/db/changeLog.xml | 1 + .../resources/db/v1/2024-07-12-disabled-flag.xml | 13 +++++++++++++ .../WorkspaceExternalV1RestControllerTest.java | 12 ++++++++++++ src/test/resources/data/testdata-external.xml | 12 ++++++------ src/test/resources/data/testdata-internal.xml | 6 +++--- 11 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 src/main/resources/db/v1/2024-07-12-disabled-flag.xml 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 58b0ab9..580a957 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 @@ -121,7 +121,9 @@ public Workspace loadByUrlProductsSlots(String url) { var cq = cb.createQuery(Workspace.class); var root = cq.from(Workspace.class); - cq.where(cb.like(cb.literal(url), cb.concat(root.get(BASE_URL), "%"))); + cq.where(cb.and(cb.like(cb.literal(url), cb.concat(root.get(BASE_URL), "%")), + cb.or(cb.isNull(root.get(DISABLED)), cb.isFalse(root.get(DISABLED))))); + var workspaceQuery = this.getEntityManager().createQuery(cq); workspaceQuery.setHint(HINT_LOAD_GRAPH, this.getEntityManager().getEntityGraph(Workspace.WORKSPACE_PRODUCTS_SLOTS)); diff --git a/src/main/java/org/tkit/onecx/workspace/domain/di/mappers/TemplateMapper.java b/src/main/java/org/tkit/onecx/workspace/domain/di/mappers/TemplateMapper.java index 9220d8d..10c1458 100644 --- a/src/main/java/org/tkit/onecx/workspace/domain/di/mappers/TemplateMapper.java +++ b/src/main/java/org/tkit/onecx/workspace/domain/di/mappers/TemplateMapper.java @@ -45,6 +45,7 @@ default List createAssignments(List roles, List menu return assignments; } + @Mapping(target = "disabled", ignore = true) @Mapping(target = "mandatory", constant = "true") @Mapping(target = "id", ignore = true) @Mapping(target = "theme", source = "themeName") diff --git a/src/main/java/org/tkit/onecx/workspace/domain/models/Workspace.java b/src/main/java/org/tkit/onecx/workspace/domain/models/Workspace.java index 9fc97c7..f4b86e1 100644 --- a/src/main/java/org/tkit/onecx/workspace/domain/models/Workspace.java +++ b/src/main/java/org/tkit/onecx/workspace/domain/models/Workspace.java @@ -88,4 +88,10 @@ public class Workspace extends TraceableEntity { */ @Column(name = "OPERATOR") private Boolean operator; + + /** + * Flag to disable a workspace + */ + @Column(name = "DISABLED") + private Boolean disabled; } diff --git a/src/main/java/org/tkit/onecx/workspace/rs/exim/v1/mappers/ExportImportMapperV1.java b/src/main/java/org/tkit/onecx/workspace/rs/exim/v1/mappers/ExportImportMapperV1.java index 6fad9ad..b55c1c6 100644 --- a/src/main/java/org/tkit/onecx/workspace/rs/exim/v1/mappers/ExportImportMapperV1.java +++ b/src/main/java/org/tkit/onecx/workspace/rs/exim/v1/mappers/ExportImportMapperV1.java @@ -98,6 +98,7 @@ default Map map(Map data, Map + \ No newline at end of file diff --git a/src/main/resources/db/v1/2024-07-12-disabled-flag.xml b/src/main/resources/db/v1/2024-07-12-disabled-flag.xml new file mode 100644 index 0000000..2a308e2 --- /dev/null +++ b/src/main/resources/db/v1/2024-07-12-disabled-flag.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file 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 2eddc48..15f1234 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 @@ -215,6 +215,7 @@ void getWorkspaceByUrlTest() { assertThat(dto).isNotNull(); assertThat(dto.getCompanyName()).isNotNull().isNotEmpty().isEqualTo("Company44"); + assertThat(dto.getDisabled()).isFalse(); // strange protocol requestDTOV1.setUrl("asd://"); @@ -243,6 +244,17 @@ void loadWorkspaceByUrlTest() { .then() .statusCode(NOT_FOUND.getStatusCode()); + // disabled workspace + requestDTOV1.setPath("/company3"); + given() + .auth().oauth2(getKeycloakClientToken("testClient")) + .when() + .contentType(APPLICATION_JSON) + .body(requestDTOV1) + .post("/load") + .then() + .statusCode(NOT_FOUND.getStatusCode()); + // existing workspace requestDTOV1.setPath("/company1/admin/my/url"); var dto = given() diff --git a/src/test/resources/data/testdata-external.xml b/src/test/resources/data/testdata-external.xml index 88cca2b..c742f3c 100644 --- a/src/test/resources/data/testdata-external.xml +++ b/src/test/resources/data/testdata-external.xml @@ -5,12 +5,12 @@ - - - - - - + + + + + + diff --git a/src/test/resources/data/testdata-internal.xml b/src/test/resources/data/testdata-internal.xml index ff1925f..0e1107c 100644 --- a/src/test/resources/data/testdata-internal.xml +++ b/src/test/resources/data/testdata-internal.xml @@ -3,9 +3,9 @@ - - - + + +