Skip to content

Commit

Permalink
feat: clean-up and included products in exim
Browse files Browse the repository at this point in the history
  • Loading branch information
JordenReuter committed Mar 21, 2024
1 parent c3928bf commit cd87047
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -68,9 +66,16 @@ default void afterWorkspace(EximWorkspaceDTOV1 dto, @MappingTarget Workspace wor
ImportWorkspaceResponseDTOV1 create(WorkspaceSnapshotDTOV1 request,
Map<String, ImportResponseStatusDTOV1> workspaces);

@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<MenuItem> menuStructure) {
MenuSnapshotDTOV1 snapshot = new MenuSnapshotDTOV1();
snapshot.setCreated(OffsetDateTime.now());
Expand Down Expand Up @@ -199,4 +204,29 @@ default MenuSnapshotDTOV1 mapTree(Collection<MenuItem> entities, Map<String, Set
return dto;
}

default List<Product> create(List<EximProductDTOV1> products, Workspace workspace) {
List<Product> 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);
}
29 changes: 22 additions & 7 deletions src/main/openapi/onecx-workspace-exim-v1-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ components:
type: array
items:
$ref: '#/components/schemas/EximWorkspaceRole'
products:
type: array
items:
$ref: '#/components/schemas/EximProduct'
EximProduct:
type: object
properties:
productName:
type: string
baseUrl:
type: string
microfrontends:
type: array
items:
$ref: '#/components/schemas/EximMicrofrontend'
EximMicrofrontend:
type: object
properties:
appId:
type: string
basePath:
type: string
EximWorkspaceRole:
type: object
properties:
Expand All @@ -197,13 +219,6 @@ components:
type: string
postalCode:
type: string
EximSubjectLink:
type: object
properties:
label:
type: string
url:
type: string
MenuSnapshot:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<EximProductDTOV1>();
var microFrontends = new ArrayList<EximMicrofrontendDTOV1>();
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<String, EximWorkspaceDTOV1> map = new HashMap<>();
map.put("testWorkspace", workspace);
Expand Down Expand Up @@ -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<EximWorkspaceRoleDTOV1>();
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<String, EximWorkspaceDTOV1> 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
Expand Down
12 changes: 12 additions & 0 deletions src/test/resources/data/testdata-exim.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
<WORKSPACE guid="33-111" optlock="0" company_name="Company4" theme="22-222" description="Company4 test" home_page="main_page" name="test04" phone_number="606450342" rss_feed_url="url.com" city="Poznan" country="Poland" base_url="/company4" postalcode="56-789" street="Kolorowa" streetno="6" tenant_id="tenant-200"/>
<WORKSPACE guid="33-222" optlock="0" company_name="Company5" theme="22-222" description="Company5 Test" home_page="main_page" name="test05" phone_number="3856382" rss_feed_url="url.com" city="Berlin" country="Germany" base_url="/company5" postalcode="12-345" street="Unter den Linden" streetno="23" tenant_id="tenant-200"/>

<!-- PRODUCT -->
<PRODUCT guid="1234" optlock="10" workspace_guid="11-111" product_name="onecx-core" base_url="/core" tenant_id="tenant-100"/>
<PRODUCT guid="5678" optlock="10" workspace_guid="11-111" product_name="onecx-apm" base_url="/apm" tenant_id="tenant-100"/>

<!-- MICROFRONTEND -->
<MICROFRONTEND guid="1234" mfe_id="menu" base_path="/menu" product_guid="1234"/>
<MICROFRONTEND guid="5678" mfe_id="theme" base_path="/theme" product_guid="1234"/>
<MICROFRONTEND guid="1111" mfe_id="apm1" base_path="/a1" product_guid="5678"/>
<MICROFRONTEND guid="2222" mfe_id="apm2" base_path="/a2" product_guid="5678"/>
<MICROFRONTEND guid="3333" mfe_id="apm3" base_path="/a3" product_guid="5678"/>
<MICROFRONTEND guid="4444" mfe_id="apm4" base_path="/a4" product_guid="5678"/>

<!-- MENU_ITEM -->
<MENU_ITEM guid="33-1" optlock="0" disabled="FALSE" key="PORTAL_MAIN_MENU" name="Main Menu" external="FALSE" pos="0" scope="WORKSPACE" url="" workspace="11-111" application_id="" tenant_id="tenant-100"/>
<MENU_ITEM guid="33-2" optlock="0" disabled="FALSE" key="PORTAL_MAIN_MENU2" name="33-3" external="FALSE" pos="0" scope="WORKSPACE" url="" workspace="11-111" application_id="" tenant_id="tenant-100"/>
Expand Down

0 comments on commit cd87047

Please sign in to comment.