Skip to content

Commit

Permalink
feat: add workspace slots import
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed May 21, 2024
1 parent f152f51 commit 12362a7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ default List<Product> create(List<EximProductDTOV1> products, Workspace workspac
return newProducts;
}

default List<Slot> createSlots(List<EximSlotDTOV1> slots, Workspace workspace) {
List<Slot> 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)
Expand All @@ -236,4 +242,19 @@ default List<Product> create(List<EximProductDTOV1> 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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ void exportWorkspaceNotFoundTest() {
void importWorkspaceTest() {
WorkspaceSnapshotDTOV1 snapshot = new WorkspaceSnapshotDTOV1();

var slots = new ArrayList<EximSlotDTOV1>();
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<EximWorkspaceRoleDTOV1>();
roles.add(new EximWorkspaceRoleDTOV1().name("role1").description("role1"));
roles.add(new EximWorkspaceRoleDTOV1().name("role2").description("role2"));
Expand All @@ -101,7 +125,8 @@ void importWorkspaceTest() {
.baseUrl("/someurl")
.name("testWorkspace")
.roles(roles)
.products(products);
.products(products)
.slots(slots);

Map<String, EximWorkspaceDTOV1> map = new HashMap<>();
map.put("testWorkspace", workspace);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 12362a7

Please sign in to comment.