Skip to content

Commit

Permalink
feat: aligned to permission and workspace api changes (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordenReuter authored Feb 29, 2024
1 parent 344511f commit 6c8ba97
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public Response createAssignment(CreateAssignmentRequestDTO createAssignmentRequ
}
}

@Override
public Response createProductAssignments(CreateProductAssignmentsRequestDTO createProductAssignmentsRequestDTO) {
try (Response response = assignmentClient.createProductAssignment(mapper.map(createProductAssignmentsRequestDTO))) {
return Response.status(response.getStatus()).build();
}
}

@Override
public Response deleteAssignment(String id) {
try (Response response = assignmentClient.deleteAssignment(id)) {
Expand All @@ -59,6 +66,13 @@ public Response getAssignment(String id) {
}
}

@Override
public Response revokeAssignments(RevokeAssignmentRequestDTO revokeAssignmentRequestDTO) {
try (Response response = assignmentClient.revokeAssignments(mapper.map(revokeAssignmentRequestDTO))) {
return Response.status(response.getStatus()).build();
}
}

@Override
public Response searchAssignments(AssignmentSearchCriteriaDTO assignmentSearchCriteriaDTO) {
try (Response response = assignmentClient.searchAssignments(mapper.map(assignmentSearchCriteriaDTO))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package org.tkit.onecx.permission.bff.rs.controllers;

import static jakarta.ws.rs.core.Response.Status.*;

import java.util.ArrayList;
import java.util.List;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
Expand Down Expand Up @@ -36,11 +41,21 @@ public class RoleRestController implements RoleApiService {
ExceptionMapper exceptionMapper;

@Override
public Response createRole(CreateRoleRequestDTO createRoleRequestDTO) {
try (Response response = roleClient
.createRole(mapper.map(createRoleRequestDTO))) {
RoleDTO responseDTO = mapper.map(response.readEntity(Role.class));
return Response.status(response.getStatus()).entity(responseDTO).build();
public Response createRole(CreateRolesRequestDTO createsRoleRequestDTO) {
List<RoleDTO> createdRoles = new ArrayList<>();
createsRoleRequestDTO.getRoles().forEach(r -> {
try (Response response = roleClient
.createRole(mapper.map(r))) {
createdRoles.add(mapper.map(response.readEntity(Role.class)));
} catch (Exception ex) {
// ignore failed creation
}
});
if (!createdRoles.isEmpty()) {
return Response.status(CREATED).entity(createdRoles).build();
} else {
return Response.status(BAD_REQUEST)
.entity(new ProblemDetailResponseDTO().errorCode("400").detail("No roles created")).build();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.tkit.onecx.permission.bff.rs.controllers;

import java.util.Arrays;
import java.util.List;

import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -14,10 +13,12 @@

import gen.org.tkit.onecx.permission.bff.rs.internal.WorkspaceApiService;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.WorkspaceDetailsDTO;
import gen.org.tkit.onecx.permission.client.api.ProductExternalApi;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.WorkspaceSearchCriteriaDTO;
import gen.org.tkit.onecx.permission.client.api.WorkspaceExternalApi;
import gen.org.tkit.onecx.permission.client.model.Product;
import gen.org.tkit.onecx.permission.client.model.Workspace;
import gen.org.tkit.onecx.permission.client.model.WorkspaceLoad;
import gen.org.tkit.onecx.permission.client.model.WorkspacePageResult;
import gen.org.tkit.onecx.product.store.client.api.ProductsApi;
import gen.org.tkit.onecx.product.store.client.model.ProductItemLoadSearchCriteria;
import gen.org.tkit.onecx.product.store.client.model.ProductsLoadResult;
Expand All @@ -31,10 +32,6 @@ public class WorkspaceRestController implements WorkspaceApiService {
@Inject
WorkspaceExternalApi workspaceClient;

@RestClient
@Inject
ProductExternalApi productClient;

@RestClient
@Inject
ProductsApi productStoreClient;
Expand All @@ -44,15 +41,16 @@ public class WorkspaceRestController implements WorkspaceApiService {

@Override
public Response getAllProductsByWorkspaceName(String workspaceName) {
try (Response response = productClient.getProducts(workspaceName)) {
return Response.status(response.getStatus()).entity(mapper.map(response.readEntity(Product[].class))).build();
try (Response response = workspaceClient.loadWorkspaceByName(workspaceName)) {
return Response.status(response.getStatus()).entity(mapper.map(response.readEntity(WorkspaceLoad.class))).build();
}
}

@Override
public Response getAllWorkspaceNames() {
try (Response response = workspaceClient.getAllWorkspaceNames()) {
return Response.status(response.getStatus()).entity(response.readEntity(String[].class)).build();
public Response searchWorkspaces(WorkspaceSearchCriteriaDTO criteriaDTO) {
try (Response response = workspaceClient.searchWorkspaces(mapper.map(criteriaDTO))) {
return Response.status(response.getStatus()).entity(mapper.map(response.readEntity(WorkspacePageResult.class)))
.build();
}
}

Expand All @@ -67,9 +65,9 @@ public Response getDetailsByWorkspaceName(String workspaceName) {
workspaceRoles = workspaceResponse.getWorkspaceRoles().stream().toList();

//get products of workspace
try (Response wsProductsResponse = productClient.getProducts(workspaceName)) {
try (Response wsProductsResponse = workspaceClient.loadWorkspaceByName(workspaceName)) {
//list of product names registered in workspace
productNames = Arrays.stream(wsProductsResponse.readEntity(Product[].class))
productNames = wsProductsResponse.readEntity(WorkspaceLoad.class).getProducts().stream()
.map(Product::getProductName).toList();

//get mfe and ms for each product by name from product-store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@
import org.mapstruct.Mapping;
import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper;

import gen.org.tkit.onecx.permission.bff.rs.internal.model.AssignmentDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.AssignmentPageResultDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.AssignmentSearchCriteriaDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.CreateAssignmentRequestDTO;
import gen.org.tkit.onecx.permission.client.model.Assignment;
import gen.org.tkit.onecx.permission.client.model.AssignmentPageResult;
import gen.org.tkit.onecx.permission.client.model.AssignmentSearchCriteria;
import gen.org.tkit.onecx.permission.client.model.CreateAssignmentRequest;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.*;
import gen.org.tkit.onecx.permission.client.model.*;

@Mapper(uses = { OffsetDateTimeMapper.class })
public interface AssignmentMapper {
Expand All @@ -24,4 +18,8 @@ public interface AssignmentMapper {

@Mapping(target = "removeStreamItem", ignore = true)
AssignmentPageResultDTO map(AssignmentPageResult pageResult);

RevokeAssignmentRequest map(RevokeAssignmentRequestDTO revokeAssignmentRequestDTO);

CreateProductAssignmentRequest map(CreateProductAssignmentsRequestDTO createProductAssignmentsRequestDTO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@
import org.mapstruct.Mapping;
import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper;

import gen.org.tkit.onecx.permission.bff.rs.internal.model.ProductDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.ProductDetailsDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.WorkspaceDetailsDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.*;
import gen.org.tkit.onecx.permission.client.model.Product;
import gen.org.tkit.onecx.permission.client.model.WorkspaceLoad;
import gen.org.tkit.onecx.permission.client.model.WorkspacePageResult;
import gen.org.tkit.onecx.permission.client.model.WorkspaceSearchCriteria;
import gen.org.tkit.onecx.product.store.client.model.ProductsAbstract;
import gen.org.tkit.onecx.product.store.client.model.ProductsLoadResult;

@Mapper(uses = { OffsetDateTimeMapper.class })
public interface WorkspaceMapper {
ProductDTO[] map(Product[] products);

@Mapping(source = "products", target = ".")
default List<ProductDTO> map(WorkspaceLoad load) {
return mapProductList(load.getProducts());
}

List<ProductDTO> mapProductList(List<Product> list);

@Mapping(target = "removeMicrofrontendsItem", ignore = true)
ProductDTO map(Product product);

@Mapping(target = "removeMsItem", ignore = true)
Expand All @@ -34,4 +42,9 @@ default WorkspaceDetailsDTO map(List<String> workspaceRoles, ProductsLoadResult
workspaceDetailsDTO.setProducts(map(productsLoadResult.getStream()));
return workspaceDetailsDTO;
}

WorkspaceSearchCriteria map(WorkspaceSearchCriteriaDTO criteriaDTO);

@Mapping(target = "removeStreamItem", ignore = true)
WorkspacePageResultDTO map(WorkspacePageResult pageResult);
}
Loading

0 comments on commit 6c8ba97

Please sign in to comment.