Skip to content

Commit

Permalink
feat: add export workspace include menus flag (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras authored Jun 4, 2024
1 parent 1417729 commit 45a28ea
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,16 @@ public Response exportWorkspacesByNames(ExportWorkspacesRequestDTOV1 request) {
}
var images = imageDAO.findByRefIds(data.keySet());

var ids = data.values().stream().map(TraceableEntity::getId).collect(toSet());
var menus = menuItemDAO.loadAllMenuItemsByWorkspaces(ids);

var ma = assignmentDAO.findAssignmentMenuForWorkspaces(ids);
Map<String, Set<String>> roles = ma.stream()
.collect(groupingBy(AssignmentMenu::menuItemId, mapping(AssignmentMenu::roleName, toSet())));

Collection<MenuItem> menus = List.of();
Map<String, Set<String>> roles = Map.of();
if (request.getIncludeMenus()) {
var ids = data.values().stream().map(TraceableEntity::getId).collect(toSet());
menus = menuItemDAO.loadAllMenuItemsByWorkspaces(ids);

var ma = assignmentDAO.findAssignmentMenuForWorkspaces(ids);
roles = ma.stream()
.collect(groupingBy(AssignmentMenu::menuItemId, mapping(AssignmentMenu::roleName, toSet())));
}
return Response.ok(mapper.create(data, images, menus, roles)).build();
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/openapi/onecx-workspace-exim-v1-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,17 @@ components:
type: string
ExportWorkspacesRequest:
type: object
required:
- includeMenus
properties:
names:
type: array
uniqueItems: true
items:
type: string
includeMenus:
type: boolean
default: true
EximProblemDetailResponse:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,39 @@ void exportWorkspaceTest() {
assertThat(w.getMenuItems()).isNotNull().isNotEmpty().hasSize(2);
}

@Test
void exportWorkspaceNoMenuTest() {
ExportWorkspacesRequestDTOV1 request = new ExportWorkspacesRequestDTOV1()
.includeMenus(false)
.addNamesItem("test01").addNamesItem("test02").addNamesItem("does-not-exists");
var dto = given()
.when()
.contentType(APPLICATION_JSON)
.body(request)
.post("/export")
.then().log().all()
.statusCode(OK.getStatusCode())
.extract().as(WorkspaceSnapshotDTOV1.class);

assertThat(dto).isNotNull();
assertThat(dto.getWorkspaces()).isNotNull().hasSize(2);
var w = dto.getWorkspaces().get("test01");
assertThat(w).isNotNull();
assertThat(w.getName()).isEqualTo("test01");

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"))));

assertThat(w.getSlots()).isNotNull().isNotEmpty().hasSize(3);

assertThat(w.getImages()).isNotNull().isNotEmpty().hasSize(2);
assertThat(w.getMenuItems()).isNull();
}

@Test
void exportAllWorkspaceTest() {
var dto = given()
Expand Down

0 comments on commit 45a28ea

Please sign in to comment.