From 12362a755c284acc2d9084388ea9ee3735121717 Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Tue, 21 May 2024 11:15:53 +0200 Subject: [PATCH] feat: add workspace slots import --- .../ExportImportRestControllerV1.java | 8 +++++ .../exim/v1/mappers/ExportImportMapperV1.java | 21 ++++++++++++++ .../WorkspaceEximV1RestControllerTest.java | 29 ++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tkit/onecx/workspace/rs/exim/v1/controllers/ExportImportRestControllerV1.java b/src/main/java/org/tkit/onecx/workspace/rs/exim/v1/controllers/ExportImportRestControllerV1.java index 6cf3753..66ffc61 100644 --- a/src/main/java/org/tkit/onecx/workspace/rs/exim/v1/controllers/ExportImportRestControllerV1.java +++ b/src/main/java/org/tkit/onecx/workspace/rs/exim/v1/controllers/ExportImportRestControllerV1.java @@ -55,6 +55,9 @@ class ExportImportRestControllerV1 implements WorkspaceExportImportApi { @Inject ProductDAO productDAO; + @Inject + SlotDAO slotDAO; + @Override public Response exportMenuByWorkspaceName(String name) { var workspace = dao.findByName(name); @@ -134,6 +137,7 @@ public Response importWorkspaces(WorkspaceSnapshotDTOV1 request) { request.getWorkspaces().forEach((name, dto) -> { try { var workspace = map.get(name); + if (workspace == null) { workspace = mapper.create(dto); workspace.setName(name); @@ -142,6 +146,10 @@ public Response importWorkspaces(WorkspaceSnapshotDTOV1 request) { var products = mapper.create(dto.getProducts(), workspace); productDAO.create(products); } + if (!dto.getSlots().isEmpty()) { + var slots = mapper.createSlots(dto.getSlots(), workspace); + slotDAO.create(slots); + } items.put(name, ImportResponseStatusDTOV1.CREATED); } else { items.put(name, ImportResponseStatusDTOV1.SKIPPED); 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 b853c7f..99ee86a 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 @@ -218,6 +218,12 @@ default List create(List products, Workspace workspac return newProducts; } + default List createSlots(List slots, Workspace workspace) { + List newSlots = new ArrayList<>(); + slots.forEach(dto -> newSlots.add(map(dto, workspace))); + return newSlots; + } + @Mapping(target = "workspaceId", ignore = true) @Mapping(target = "workspace", source = "workspace") @Mapping(target = "tenantId", ignore = true) @@ -236,4 +242,19 @@ default List create(List products, Workspace workspac @Mapping(target = "id", ignore = true) @Mapping(target = "productId", ignore = true) Microfrontend map(EximMicrofrontendDTOV1 eximMicrofrontendDTOV1); + + @Mapping(target = "workspaceId", ignore = true) + @Mapping(target = "workspace", source = "workspace") + @Mapping(target = "tenantId", ignore = true) + @Mapping(target = "persisted", ignore = true) + @Mapping(target = "modificationUser", ignore = true) + @Mapping(target = "modificationDate", ignore = true) + @Mapping(target = "modificationCount", ignore = true) + @Mapping(target = "id", ignore = true) + @Mapping(target = "creationUser", ignore = true) + @Mapping(target = "creationDate", ignore = true) + @Mapping(target = "controlTraceabilityManual", ignore = true) + @Mapping(target = "name", source = "dto.name") + Slot map(EximSlotDTOV1 dto, Workspace workspace); + } diff --git a/src/test/java/org/tkit/onecx/workspace/rs/exim/v1/controllers/WorkspaceEximV1RestControllerTest.java b/src/test/java/org/tkit/onecx/workspace/rs/exim/v1/controllers/WorkspaceEximV1RestControllerTest.java index cf8fea1..ec4c8e7 100644 --- a/src/test/java/org/tkit/onecx/workspace/rs/exim/v1/controllers/WorkspaceEximV1RestControllerTest.java +++ b/src/test/java/org/tkit/onecx/workspace/rs/exim/v1/controllers/WorkspaceEximV1RestControllerTest.java @@ -85,6 +85,30 @@ void exportWorkspaceNotFoundTest() { void importWorkspaceTest() { WorkspaceSnapshotDTOV1 snapshot = new WorkspaceSnapshotDTOV1(); + var slots = new ArrayList(); + slots.add(new EximSlotDTOV1().name("slot1") + .addComponentsItem( + new EximComponentDTOV1() + .appId("app1") + .productName("product1") + .name("component1")) + .addComponentsItem( + new EximComponentDTOV1() + .appId("app1") + .productName("product1") + .name("component2"))); + slots.add(new EximSlotDTOV1().name("slot2") + .addComponentsItem( + new EximComponentDTOV1() + .appId("app2") + .productName("product2") + .name("component3")) + .addComponentsItem( + new EximComponentDTOV1() + .appId("app2") + .productName("product2") + .name("component4"))); + var roles = new ArrayList(); roles.add(new EximWorkspaceRoleDTOV1().name("role1").description("role1")); roles.add(new EximWorkspaceRoleDTOV1().name("role2").description("role2")); @@ -101,7 +125,8 @@ void importWorkspaceTest() { .baseUrl("/someurl") .name("testWorkspace") .roles(roles) - .products(products); + .products(products) + .slots(slots); Map map = new HashMap<>(); map.put("testWorkspace", workspace); @@ -143,6 +168,8 @@ void importWorkspaceTest() { assertThat(w.getProducts()).isNotNull().isNotEmpty().hasSize(1) .containsExactly(new EximProductDTOV1().productName("product1").baseUrl("/productBase") .microfrontends(List.of(new EximMicrofrontendDTOV1().appId("app1").basePath("/app1")))); + + assertThat(w.getSlots()).isNotNull().isNotEmpty().hasSize(2); } @Test