diff --git a/src/main/java/org/tkit/onecx/workspace/domain/di/mappers/WorkspaceDataImportMapperV1.java b/src/main/java/org/tkit/onecx/workspace/domain/di/mappers/WorkspaceDataImportMapperV1.java index feeca10..cf9eb40 100644 --- a/src/main/java/org/tkit/onecx/workspace/domain/di/mappers/WorkspaceDataImportMapperV1.java +++ b/src/main/java/org/tkit/onecx/workspace/domain/di/mappers/WorkspaceDataImportMapperV1.java @@ -21,8 +21,6 @@ public interface WorkspaceDataImportMapperV1 { @Mapping(target = "modificationCount", ignore = true) @Mapping(target = "persisted", ignore = true) @Mapping(target = "tenantId", ignore = true) - @Mapping(target = "subjectLink", source = "subjectLinks") - @Mapping(target = "imageUrl", source = "imageUrls") Workspace createWorkspace(WorkspaceImportDTOV1 workspaceDTO); @AfterMapping diff --git a/src/main/java/org/tkit/onecx/workspace/domain/models/SubjectLink.java b/src/main/java/org/tkit/onecx/workspace/domain/models/SubjectLink.java deleted file mode 100644 index 1fc0096..0000000 --- a/src/main/java/org/tkit/onecx/workspace/domain/models/SubjectLink.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.tkit.onecx.workspace.domain.models; - -import java.io.Serializable; - -import jakarta.persistence.Embeddable; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Embeddable -public class SubjectLink implements Serializable { - - private String label; - private String url; -} 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 2659ebf..9a292f0 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 @@ -2,9 +2,7 @@ import static jakarta.persistence.FetchType.LAZY; -import java.util.HashSet; import java.util.List; -import java.util.Set; import jakarta.persistence.*; @@ -21,8 +19,7 @@ @UniqueConstraint(name = "WORKSPACE_NAME_TENANT_ID", columnNames = { "NAME", "TENANT_ID" }), @UniqueConstraint(name = "WORKSPACE_BASE_URL_TENANT_ID", columnNames = { "BASE_URL", "TENANT_ID" }) }) -@NamedEntityGraph(name = Workspace.WORKSPACE_FULL, attributeNodes = { @NamedAttributeNode("subjectLink"), - @NamedAttributeNode("imageUrl"), @NamedAttributeNode(value = "products") }) +@NamedEntityGraph(name = Workspace.WORKSPACE_FULL, attributeNodes = { @NamedAttributeNode(value = "products") }) @SuppressWarnings("squid:S2160") public class Workspace extends TraceableEntity { @@ -62,21 +59,10 @@ public class Workspace extends TraceableEntity { @Column(name = "FOOTER_LABEL") private String footerLabel; - @ElementCollection(fetch = LAZY) - @CollectionTable(name = "SUBJECT_LINK") - @AttributeOverride(name = "label", column = @Column(name = "link_label")) - @AttributeOverride(name = "url", column = @Column(name = "link_url")) - private Set subjectLink = new HashSet<>(); - @Column(name = "ROLES") @OneToMany(mappedBy = "workspace", fetch = LAZY, cascade = { CascadeType.REMOVE, CascadeType.PERSIST }) private List roles; - @ElementCollection(fetch = LAZY) - @CollectionTable(name = "IMAGE_URL") - @Column(name = "IMAGE_URL") - private Set imageUrl = new HashSet<>(); - @Column(name = "LOGO_URL") private String logoUrl; 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 92eae4f..694a40f 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 @@ -15,10 +15,7 @@ import org.jboss.resteasy.reactive.server.ServerExceptionMapper; import org.tkit.onecx.workspace.domain.criteria.MenuItemLoadCriteria; import org.tkit.onecx.workspace.domain.criteria.WorkspaceSearchCriteria; -import org.tkit.onecx.workspace.domain.daos.AssignmentDAO; -import org.tkit.onecx.workspace.domain.daos.MenuItemDAO; -import org.tkit.onecx.workspace.domain.daos.RoleDAO; -import org.tkit.onecx.workspace.domain.daos.WorkspaceDAO; +import org.tkit.onecx.workspace.domain.daos.*; import org.tkit.onecx.workspace.domain.models.*; import org.tkit.onecx.workspace.domain.services.MenuService; import org.tkit.onecx.workspace.rs.exim.v1.mappers.ExportImportExceptionMapperV1; @@ -55,6 +52,9 @@ class ExportImportRestControllerV1 implements WorkspaceExportImportApi { @Inject RoleDAO roleDAO; + @Inject + ProductDAO productDAO; + @Override public Response exportMenuByWorkspaceName(String name) { var workspace = dao.findByName(name); @@ -138,6 +138,10 @@ public Response importWorkspaces(WorkspaceSnapshotDTOV1 request) { workspace = mapper.create(dto); workspace.setName(name); dao.create(workspace); + if (dto.getProducts() != null) { + var products = mapper.create(dto.getProducts(), workspace); + productDAO.create(products); + } 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 1a71b26..9569335 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 @@ -4,9 +4,7 @@ import java.util.*; import org.mapstruct.*; -import org.tkit.onecx.workspace.domain.models.MenuItem; -import org.tkit.onecx.workspace.domain.models.Role; -import org.tkit.onecx.workspace.domain.models.Workspace; +import org.tkit.onecx.workspace.domain.models.*; import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; import gen.org.tkit.onecx.workspace.rs.exim.v1.model.*; @@ -36,8 +34,6 @@ default WorkspaceSnapshotDTOV1 create(Map workspaces) { @Mapping(target = "products", ignore = true) @Mapping(target = "modificationCount", ignore = true) @Mapping(target = "id", ignore = true) - @Mapping(target = "subjectLink", source = "subjectLinks") - @Mapping(target = "imageUrl", source = "imageUrls") Workspace create(EximWorkspaceDTOV1 workspaceDTO); @Mapping(target = "modificationCount", ignore = true) @@ -70,13 +66,16 @@ default void afterWorkspace(EximWorkspaceDTOV1 dto, @MappingTarget Workspace wor ImportWorkspaceResponseDTOV1 create(WorkspaceSnapshotDTOV1 request, Map workspaces); - @Mapping(target = "removeSubjectLinksItem", ignore = true) - @Mapping(target = "removeImageUrlsItem", ignore = true) - @Mapping(target = "subjectLinks", source = "subjectLink") - @Mapping(target = "imageUrls", source = "imageUrl") + @Mapping(target = "removeProductsItem", ignore = true) @Mapping(target = "removeRolesItem", ignore = true) EximWorkspaceDTOV1 map(Workspace workspace); + @Mapping(target = "removeMicrofrontendsItem", ignore = true) + EximProductDTOV1 map(Product product); + + @Mapping(target = "appId", source = "mfeId") + EximMicrofrontendDTOV1 map(Microfrontend microfrontend); + default MenuSnapshotDTOV1 create(List menuStructure) { MenuSnapshotDTOV1 snapshot = new MenuSnapshotDTOV1(); snapshot.setCreated(OffsetDateTime.now()); @@ -205,4 +204,27 @@ default MenuSnapshotDTOV1 mapTree(Collection entities, Map create(List products, Workspace workspace) { + List newProducts = new ArrayList<>(); + products.forEach(productDTOV1 -> newProducts.add(map(productDTOV1, workspace))); + return newProducts; + } + + @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 = "baseUrl", source = "productDTOV1.baseUrl") + Product map(EximProductDTOV1 productDTOV1, Workspace workspace); + + @Mapping(target = "mfeId", source = "appId") + @Mapping(target = "id", ignore = true) + Microfrontend map(EximMicrofrontendDTOV1 eximMicrofrontendDTOV1); } diff --git a/src/main/java/org/tkit/onecx/workspace/rs/external/v1/mappers/WorkspaceMapper.java b/src/main/java/org/tkit/onecx/workspace/rs/external/v1/mappers/WorkspaceMapper.java index aa36039..58178b9 100644 --- a/src/main/java/org/tkit/onecx/workspace/rs/external/v1/mappers/WorkspaceMapper.java +++ b/src/main/java/org/tkit/onecx/workspace/rs/external/v1/mappers/WorkspaceMapper.java @@ -39,11 +39,7 @@ default WorkspaceAbstractDTOV1 mapAbstract(Workspace workspace) { @Mapping(target = "names", ignore = true) WorkspaceSearchCriteria map(WorkspaceSearchCriteriaDTOV1 criteria); - @Mapping(target = "subjectLinks", ignore = true) @Mapping(target = "workspaceRoles", source = "roles") - @Mapping(target = "removeSubjectLinksItem", ignore = true) - @Mapping(target = "imageUrls", ignore = true) - @Mapping(target = "removeImageUrlsItem", ignore = true) @Mapping(target = "removeWorkspaceRolesItem", ignore = true) WorkspaceDTOV1 map(Workspace workspace); 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 f3d3641..5b60e30 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 @@ -44,10 +44,6 @@ public interface WorkspaceMapper { @Mapping(target = "removeStreamItem", ignore = true) WorkspacePageResultDTO mapPageResult(PageResult page); - @Mapping(target = "removeSubjectLinksItem", ignore = true) - @Mapping(target = "removeImageUrlsItem", ignore = true) - @Mapping(target = "subjectLinks", source = "subjectLink") - @Mapping(target = "imageUrls", source = "imageUrl") WorkspaceDTO map(Workspace data); } diff --git a/src/main/openapi/di-workspace-v1.yaml b/src/main/openapi/di-workspace-v1.yaml index 547cf78..c0d49a8 100644 --- a/src/main/openapi/di-workspace-v1.yaml +++ b/src/main/openapi/di-workspace-v1.yaml @@ -105,22 +105,11 @@ components: type: string footerLabel: type: string - subjectLinks: - maxItems: 3 - uniqueItems: true - type: array - items: - $ref: '#/components/schemas/SubjectLink' products: type: array uniqueItems: true items: $ref: "#/components/schemas/Product" - imageUrls: - uniqueItems: true - type: array - items: - type: string workspaceRoles: type: array uniqueItems: true diff --git a/src/main/openapi/onecx-workspace-exim-v1-openapi.yaml b/src/main/openapi/onecx-workspace-exim-v1-openapi.yaml index ed60dde..5171a88 100644 --- a/src/main/openapi/onecx-workspace-exim-v1-openapi.yaml +++ b/src/main/openapi/onecx-workspace-exim-v1-openapi.yaml @@ -177,17 +177,28 @@ components: type: array items: $ref: '#/components/schemas/EximWorkspaceRole' - subjectLinks: - uniqueItems: true - maxItems: 3 + products: type: array items: - $ref: '#/components/schemas/EximSubjectLink' - imageUrls: - uniqueItems: true + $ref: '#/components/schemas/EximProduct' + EximProduct: + type: object + properties: + productName: + type: string + baseUrl: + type: string + microfrontends: type: array items: - type: string + $ref: '#/components/schemas/EximMicrofrontend' + EximMicrofrontend: + type: object + properties: + appId: + type: string + basePath: + type: string EximWorkspaceRole: type: object properties: @@ -208,13 +219,6 @@ components: type: string postalCode: type: string - EximSubjectLink: - type: object - properties: - label: - type: string - url: - type: string MenuSnapshot: type: object properties: diff --git a/src/main/openapi/onecx-workspace-internal-openapi.yaml b/src/main/openapi/onecx-workspace-internal-openapi.yaml index a09500b..81b803a 100644 --- a/src/main/openapi/onecx-workspace-internal-openapi.yaml +++ b/src/main/openapi/onecx-workspace-internal-openapi.yaml @@ -963,17 +963,6 @@ components: type: string address: $ref: '#/components/schemas/WorkspaceAddress' - subjectLink: - uniqueItems: true - maxItems: 3 - type: array - items: - $ref: '#/components/schemas/SubjectLink' - imageUrl: - uniqueItems: true - type: array - items: - type: string UpdateWorkspaceRequest: required: - name @@ -1005,17 +994,6 @@ components: type: string address: $ref: '#/components/schemas/WorkspaceAddress' - subjectLink: - uniqueItems: true - maxItems: 3 - type: array - items: - $ref: '#/components/schemas/SubjectLink' - imageUrl: - uniqueItems: true - type: array - items: - type: string Workspace: required: - name @@ -1056,17 +1034,6 @@ components: type: string address: $ref: '#/components/schemas/WorkspaceAddress' - subjectLinks: - uniqueItems: true - maxItems: 3 - type: array - items: - $ref: '#/components/schemas/SubjectLink' - imageUrls: - uniqueItems: true - type: array - items: - type: string WorkspaceAbstract: required: - name diff --git a/src/main/openapi/onecx-workspace-v1-openapi.yaml b/src/main/openapi/onecx-workspace-v1-openapi.yaml index a7368b3..7282660 100644 --- a/src/main/openapi/onecx-workspace-v1-openapi.yaml +++ b/src/main/openapi/onecx-workspace-v1-openapi.yaml @@ -101,17 +101,6 @@ components: type: string address: $ref: '#/components/schemas/WorkspaceAddress' - subjectLinks: - uniqueItems: true - maxItems: 3 - type: array - items: - $ref: '#/components/schemas/SubjectLink' - imageUrls: - uniqueItems: true - type: array - items: - type: string WorkspaceAddress: type: object properties: diff --git a/src/main/resources/db/changeLog.xml b/src/main/resources/db/changeLog.xml index 1194f6b..39bbdcb 100644 --- a/src/main/resources/db/changeLog.xml +++ b/src/main/resources/db/changeLog.xml @@ -7,4 +7,5 @@ + \ No newline at end of file diff --git a/src/main/resources/db/v1/2024-03-20-drop-image-urls-subject-links.xml b/src/main/resources/db/v1/2024-03-20-drop-image-urls-subject-links.xml new file mode 100644 index 0000000..3d14522 --- /dev/null +++ b/src/main/resources/db/v1/2024-03-20-drop-image-urls-subject-links.xml @@ -0,0 +1,14 @@ + + + + + + + + + + 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 68c6d0d..f3a46f4 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 @@ -43,6 +43,10 @@ void exportWorkspaceTest() { assertThat(w.getRoles()).isNotNull().isNotEmpty().hasSize(3) .contains(new EximWorkspaceRoleDTOV1().name("role-1-2").description("d1")); + assertThat(w.getProducts()).isNotNull().isNotEmpty().hasSize(2) + .contains(new EximProductDTOV1().productName("onecx-core").baseUrl("/core") + .microfrontends(List.of(new EximMicrofrontendDTOV1().appId("menu").basePath("/menu"), + new EximMicrofrontendDTOV1().appId("theme").basePath("/theme")))); } @Test @@ -83,10 +87,19 @@ void importWorkspaceTest() { roles.add(new EximWorkspaceRoleDTOV1().name("role1").description("role1")); roles.add(new EximWorkspaceRoleDTOV1().name("role2").description("role2")); + var products = new ArrayList(); + var microFrontends = new ArrayList(); + microFrontends.add(new EximMicrofrontendDTOV1().appId("app1").basePath("/app1")); + products.add(new EximProductDTOV1() + .productName("product1") + .baseUrl("/productBase") + .microfrontends(microFrontends)); + EximWorkspaceDTOV1 workspace = new EximWorkspaceDTOV1() .baseUrl("/someurl") .name("testWorkspace") - .roles(roles); + .roles(roles) + .products(products); Map map = new HashMap<>(); map.put("testWorkspace", workspace); @@ -125,7 +138,62 @@ void importWorkspaceTest() { .containsExactly( new EximWorkspaceRoleDTOV1().name("role1").description("role1"), new EximWorkspaceRoleDTOV1().name("role2").description("role2")); + assertThat(w.getProducts()).isNotNull().isNotEmpty().hasSize(1) + .containsExactly(new EximProductDTOV1().productName("product1").baseUrl("/productBase") + .microfrontends(List.of(new EximMicrofrontendDTOV1().appId("app1").basePath("/app1")))); + } + + @Test + void importWorkspaceWithoutProductTest() { + WorkspaceSnapshotDTOV1 snapshot = new WorkspaceSnapshotDTOV1(); + + var roles = new ArrayList(); + roles.add(new EximWorkspaceRoleDTOV1().name("role1").description("role1")); + roles.add(new EximWorkspaceRoleDTOV1().name("role2").description("role2")); + + EximWorkspaceDTOV1 workspace = new EximWorkspaceDTOV1() + .baseUrl("/someurl") + .name("testWorkspace") + .roles(roles); + + Map map = new HashMap<>(); + map.put("testWorkspace", workspace); + snapshot.setWorkspaces(map); + + var importResponse = given() + .when() + .contentType(APPLICATION_JSON) + .body(snapshot) + .post("/import") + .then() + .statusCode(OK.getStatusCode()) + .extract().as(ImportWorkspaceResponseDTOV1.class); + + assertThat(importResponse).isNotNull(); + assertThat(importResponse.getWorkspaces()).containsEntry("testWorkspace", ImportResponseStatusDTOV1.CREATED); + + ExportWorkspacesRequestDTOV1 request = new ExportWorkspacesRequestDTOV1(); + request.addNamesItem("testWorkspace"); + var dto = given() + .when() + .contentType(APPLICATION_JSON) + .body(request) + .post("/export") + .then() + .statusCode(OK.getStatusCode()) + .extract().as(WorkspaceSnapshotDTOV1.class); + assertThat(dto).isNotNull(); + assertThat(dto.getWorkspaces()).isNotNull().isNotEmpty(); + var w = dto.getWorkspaces().get("testWorkspace"); + assertThat(w).isNotNull(); + assertThat(w.getName()).isEqualTo("testWorkspace"); + + assertThat(w.getRoles()).isNotNull().isNotEmpty().hasSize(2) + .containsExactly( + new EximWorkspaceRoleDTOV1().name("role1").description("role1"), + new EximWorkspaceRoleDTOV1().name("role2").description("role2")); + assertThat(w.getProducts()).isEmpty(); } @Test diff --git a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/WorkspaceInternalRestControllerTenantTest.java b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/WorkspaceInternalRestControllerTenantTest.java index b3a5dfe..ac4f324 100644 --- a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/WorkspaceInternalRestControllerTenantTest.java +++ b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/WorkspaceInternalRestControllerTenantTest.java @@ -167,8 +167,6 @@ void getWorkspace() { assertThat(dto.getBaseUrl()).isNotNull().isEqualTo("/company1"); assertThat(dto.getAddress()).isNotNull(); assertThat(dto.getAddress().getStreetNo()).isEqualTo("6"); - assertThat(dto.getImageUrls()).isNotEmpty(); - assertThat(dto.getSubjectLinks()).isNotEmpty(); } @ParameterizedTest diff --git a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/WorkspaceInternalRestControllerTest.java b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/WorkspaceInternalRestControllerTest.java index fbef373..88f30be 100644 --- a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/WorkspaceInternalRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/WorkspaceInternalRestControllerTest.java @@ -120,8 +120,6 @@ void getWorkspace() { assertThat(dto.getBaseUrl()).isNotNull().isEqualTo("/company1"); assertThat(dto.getAddress()).isNotNull(); assertThat(dto.getAddress().getStreetNo()).isEqualTo("6"); - assertThat(dto.getImageUrls()).isNotEmpty(); - assertThat(dto.getSubjectLinks()).isNotEmpty(); } @Test @@ -147,8 +145,6 @@ void getWorkspaceByName() { assertThat(dto.getBaseUrl()).isNotNull().isEqualTo("/company1"); assertThat(dto.getAddress()).isNotNull(); assertThat(dto.getAddress().getStreetNo()).isEqualTo("6"); - assertThat(dto.getImageUrls()).isNotEmpty(); - assertThat(dto.getSubjectLinks()).isNotEmpty(); } @Test diff --git a/src/test/resources/data/testdata-exim.xml b/src/test/resources/data/testdata-exim.xml index 75b34c4..2dab97c 100644 --- a/src/test/resources/data/testdata-exim.xml +++ b/src/test/resources/data/testdata-exim.xml @@ -9,6 +9,18 @@ + + + + + + + + + + + + diff --git a/src/test/resources/data/testdata-internal.xml b/src/test/resources/data/testdata-internal.xml index f9c27de..9e2fef7 100644 --- a/src/test/resources/data/testdata-internal.xml +++ b/src/test/resources/data/testdata-internal.xml @@ -40,14 +40,6 @@ - - - - - - - -