Skip to content

Commit

Permalink
fix: type mappings for user assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
JordenReuter committed Oct 25, 2024
1 parent 10f2dac commit 423cad2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
import org.tkit.onecx.permission.bff.rs.mappers.AssignmentMapper;
import org.tkit.onecx.permission.bff.rs.mappers.ExceptionMapper;
import org.tkit.onecx.permission.bff.rs.mappers.UserMapper;
import org.tkit.quarkus.log.cdi.LogService;

import gen.org.tkit.onecx.iam.client.api.AdminUserControllerApi;
Expand All @@ -24,6 +25,7 @@
import gen.org.tkit.onecx.permission.client.api.AssignmentInternalApi;
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.UserAssignmentPageResult;
import gen.org.tkit.onecx.permission.exim.client.api.PermissionExportImportApi;
import gen.org.tkit.onecx.permission.exim.client.model.AssignmentSnapshot;

Expand All @@ -47,6 +49,9 @@ public class AssignmentRestController implements AssignmentApiService {
@Inject
AssignmentMapper mapper;

@Inject
UserMapper userMapper;

@Inject
ExceptionMapper exceptionMapper;

Expand Down Expand Up @@ -150,7 +155,7 @@ public Response searchAssignments(AssignmentSearchCriteriaDTO assignmentSearchCr

@Override
public Response searchUserAssignments(AssignmentUserSearchCriteriaDTO assignmentUserSearchCriteriaDTO) {
AssignmentPageResult pageResult;
UserAssignmentPageResult pageResult;
List<String> roles = List.of();
try (Response response = iamClient.getUserRoles(assignmentUserSearchCriteriaDTO.getUserId())) {
UserRolesResponseIamV1 roleResponse = response.readEntity(UserRolesResponseIamV1.class);
Expand All @@ -163,8 +168,8 @@ public Response searchUserAssignments(AssignmentUserSearchCriteriaDTO assignment
}
try (Response assignmentResponse = assignmentClient
.searchAssignmentsByRoles(mapper.map(assignmentUserSearchCriteriaDTO, roles))) {
pageResult = assignmentResponse.readEntity(AssignmentPageResult.class);
return Response.status(assignmentResponse.getStatus()).entity(mapper.map(pageResult)).build();
pageResult = assignmentResponse.readEntity(UserAssignmentPageResult.class);
return Response.status(assignmentResponse.getStatus()).entity(userMapper.map(pageResult)).build();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/openapi/openapi-bff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/AssignmentPageResult'
$ref: '#/components/schemas/UserAssignmentPageResult'
400:
description: Bad request
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ void searchUsersAssignmentsByCriteriaTest() {
AssignmentRolesSearchCriteria criteria = new AssignmentRolesSearchCriteria();
criteria.pageNumber(1).pageSize(1).roles(List.of("role1"));

AssignmentPageResult pageResult = new AssignmentPageResult();
Assignment assignment = new Assignment();
assignment.permissionId("permission1").roleId("role1");
UserAssignmentPageResult pageResult = new UserAssignmentPageResult();
UserAssignment assignment = new UserAssignment();
assignment.productName("product1").roleName("role1");
pageResult.stream(List.of(assignment)).size(1).number(1).totalElements(1L).totalPages(1L);

// create mock rest endpoint
Expand All @@ -504,13 +504,13 @@ void searchUsersAssignmentsByCriteriaTest() {
.then()
.statusCode(Response.Status.OK.getStatusCode())
.contentType(APPLICATION_JSON)
.extract().as(AssignmentPageResultDTO.class);
.extract().as(UserAssignmentPageResultDTO.class);

Assertions.assertNotNull(output);
Assertions.assertEquals(pageResult.getSize(), output.getSize());
Assertions.assertEquals(pageResult.getStream().size(), output.getStream().size());
Assertions.assertEquals(pageResult.getStream().get(0).getRoleId(), output.getStream().get(0).getRoleId());
Assertions.assertEquals(pageResult.getStream().get(0).getPermissionId(), output.getStream().get(0).getPermissionId());
Assertions.assertEquals(pageResult.getStream().get(0).getRoleName(), output.getStream().get(0).getRoleName());
Assertions.assertEquals(pageResult.getStream().get(0).getProductName(), output.getStream().get(0).getProductName());

mockServerClient.clear(MOCKID);
mockServerClient.clear("MOCK_IAM_KC");
Expand Down

0 comments on commit 423cad2

Please sign in to comment.