@Test(expected = ConflictException.class) @WithMockUser(authorities = { "EDIT_ENDPOINT_ACL" }) public void addExistingEndpointAccessRights() { doReturn(true).when(globalConfService).clientsExist(any()); doReturn(true).when(globalConfService).globalGroupsExist(any()); ServiceClients serviceClients = new ServiceClients() .addItemsItem(new ServiceClient().id(TestUtils.CLIENT_ID_SS6).serviceClientType( ServiceClientType.SUBSYSTEM)); endpointsApiController.addEndpointServiceClients("9", serviceClients); }
@Override @PreAuthorize("hasAuthority('EDIT_ENDPOINT_ACL')") public ResponseEntity<List<ServiceClient>> addEndpointServiceClients(String id, ServiceClients serviceClients) { Long endpointId = parseLongIdOrThrowNotFound(id); List<ServiceClientDto> serviceClientsByEndpoint = null; try { Set<XRoadId> xRoadIds = serviceClientHelper.processServiceClientXRoadIds(serviceClients); serviceClientsByEndpoint = accessRightService.addEndpointAccessRights(endpointId, new HashSet<>(xRoadIds)); } catch (EndpointNotFoundException e) { throw new ResourceNotFoundException(e); } catch (ClientNotFoundException | AccessRightService.DuplicateAccessRightException e) { throw new ConflictException(e); } catch (ServiceClientNotFoundException e) { throw new BadRequestException(e); } catch (ServiceClientIdentifierConverter.BadServiceClientIdentifierException e) { throw serviceClientHelper.wrapInBadRequestException(e); } List<ServiceClient> serviceClientsResult = serviceClientConverter .convertServiceClientDtos(serviceClientsByEndpoint); Collections.sort(serviceClientsResult, serviceClientSortingComparator); return new ResponseEntity<>(serviceClientsResult, HttpStatus.CREATED); }
EndpointsApiController implements EndpointsApi { @Override @PreAuthorize("hasAuthority('EDIT_ENDPOINT_ACL')") public ResponseEntity<List<ServiceClient>> addEndpointServiceClients(String id, ServiceClients serviceClients) { Long endpointId = parseLongIdOrThrowNotFound(id); List<ServiceClientDto> serviceClientsByEndpoint = null; try { Set<XRoadId> xRoadIds = serviceClientHelper.processServiceClientXRoadIds(serviceClients); serviceClientsByEndpoint = accessRightService.addEndpointAccessRights(endpointId, new HashSet<>(xRoadIds)); } catch (EndpointNotFoundException e) { throw new ResourceNotFoundException(e); } catch (ClientNotFoundException | AccessRightService.DuplicateAccessRightException e) { throw new ConflictException(e); } catch (ServiceClientNotFoundException e) { throw new BadRequestException(e); } catch (ServiceClientIdentifierConverter.BadServiceClientIdentifierException e) { throw serviceClientHelper.wrapInBadRequestException(e); } List<ServiceClient> serviceClientsResult = serviceClientConverter .convertServiceClientDtos(serviceClientsByEndpoint); Collections.sort(serviceClientsResult, serviceClientSortingComparator); return new ResponseEntity<>(serviceClientsResult, HttpStatus.CREATED); } }
EndpointsApiController implements EndpointsApi { @Override @PreAuthorize("hasAuthority('EDIT_ENDPOINT_ACL')") public ResponseEntity<List<ServiceClient>> addEndpointServiceClients(String id, ServiceClients serviceClients) { Long endpointId = parseLongIdOrThrowNotFound(id); List<ServiceClientDto> serviceClientsByEndpoint = null; try { Set<XRoadId> xRoadIds = serviceClientHelper.processServiceClientXRoadIds(serviceClients); serviceClientsByEndpoint = accessRightService.addEndpointAccessRights(endpointId, new HashSet<>(xRoadIds)); } catch (EndpointNotFoundException e) { throw new ResourceNotFoundException(e); } catch (ClientNotFoundException | AccessRightService.DuplicateAccessRightException e) { throw new ConflictException(e); } catch (ServiceClientNotFoundException e) { throw new BadRequestException(e); } catch (ServiceClientIdentifierConverter.BadServiceClientIdentifierException e) { throw serviceClientHelper.wrapInBadRequestException(e); } List<ServiceClient> serviceClientsResult = serviceClientConverter .convertServiceClientDtos(serviceClientsByEndpoint); Collections.sort(serviceClientsResult, serviceClientSortingComparator); return new ResponseEntity<>(serviceClientsResult, HttpStatus.CREATED); } @Autowired  EndpointsApiController(
            EndpointService endpointService,
            EndpointConverter endpointConverter,
            AccessRightService accessRightService,
            ServiceClientConverter serviceClientConverter,
            ServiceClientHelper serviceClientHelper,
            ServiceClientService serviceClientService); }
EndpointsApiController implements EndpointsApi { @Override @PreAuthorize("hasAuthority('EDIT_ENDPOINT_ACL')") public ResponseEntity<List<ServiceClient>> addEndpointServiceClients(String id, ServiceClients serviceClients) { Long endpointId = parseLongIdOrThrowNotFound(id); List<ServiceClientDto> serviceClientsByEndpoint = null; try { Set<XRoadId> xRoadIds = serviceClientHelper.processServiceClientXRoadIds(serviceClients); serviceClientsByEndpoint = accessRightService.addEndpointAccessRights(endpointId, new HashSet<>(xRoadIds)); } catch (EndpointNotFoundException e) { throw new ResourceNotFoundException(e); } catch (ClientNotFoundException | AccessRightService.DuplicateAccessRightException e) { throw new ConflictException(e); } catch (ServiceClientNotFoundException e) { throw new BadRequestException(e); } catch (ServiceClientIdentifierConverter.BadServiceClientIdentifierException e) { throw serviceClientHelper.wrapInBadRequestException(e); } List<ServiceClient> serviceClientsResult = serviceClientConverter .convertServiceClientDtos(serviceClientsByEndpoint); Collections.sort(serviceClientsResult, serviceClientSortingComparator); return new ResponseEntity<>(serviceClientsResult, HttpStatus.CREATED); } @Autowired  EndpointsApiController(
            EndpointService endpointService,
            EndpointConverter endpointConverter,
            AccessRightService accessRightService,
            ServiceClientConverter serviceClientConverter,
            ServiceClientHelper serviceClientHelper,
            ServiceClientService serviceClientService); @Override @PreAuthorize("hasAuthority('VIEW_ENDPOINT')") ResponseEntity<Endpoint> getEndpoint(String id); @Override @PreAuthorize("hasAuthority('DELETE_ENDPOINT')") @AuditEventMethod(event = DELETE_REST_ENDPOINT) ResponseEntity<Void> deleteEndpoint(String id); @Override @PreAuthorize("hasAuthority('EDIT_OPENAPI3_ENDPOINT')") @AuditEventMethod(event = EDIT_REST_ENDPOINT) ResponseEntity<Endpoint> updateEndpoint(String id, EndpointUpdate endpointUpdate); @Override @PreAuthorize("hasAuthority('VIEW_ENDPOINT_ACL')") ResponseEntity<List<ServiceClient>> getEndpointServiceClients(String id); @Override @PreAuthorize("hasAuthority('EDIT_ENDPOINT_ACL')") ResponseEntity<List<ServiceClient>> addEndpointServiceClients(String id, ServiceClients serviceClients); @Override @PreAuthorize("hasAuthority('EDIT_ENDPOINT_ACL')") ResponseEntity<Void> deleteEndpointServiceClients(String id, ServiceClients serviceClients); }
EndpointsApiController implements EndpointsApi { @Override @PreAuthorize("hasAuthority('EDIT_ENDPOINT_ACL')") public ResponseEntity<List<ServiceClient>> addEndpointServiceClients(String id, ServiceClients serviceClients) { Long endpointId = parseLongIdOrThrowNotFound(id); List<ServiceClientDto> serviceClientsByEndpoint = null; try { Set<XRoadId> xRoadIds = serviceClientHelper.processServiceClientXRoadIds(serviceClients); serviceClientsByEndpoint = accessRightService.addEndpointAccessRights(endpointId, new HashSet<>(xRoadIds)); } catch (EndpointNotFoundException e) { throw new ResourceNotFoundException(e); } catch (ClientNotFoundException | AccessRightService.DuplicateAccessRightException e) { throw new ConflictException(e); } catch (ServiceClientNotFoundException e) { throw new BadRequestException(e); } catch (ServiceClientIdentifierConverter.BadServiceClientIdentifierException e) { throw serviceClientHelper.wrapInBadRequestException(e); } List<ServiceClient> serviceClientsResult = serviceClientConverter .convertServiceClientDtos(serviceClientsByEndpoint); Collections.sort(serviceClientsResult, serviceClientSortingComparator); return new ResponseEntity<>(serviceClientsResult, HttpStatus.CREATED); } @Autowired  EndpointsApiController(
            EndpointService endpointService,
            EndpointConverter endpointConverter,
            AccessRightService accessRightService,
            ServiceClientConverter serviceClientConverter,
            ServiceClientHelper serviceClientHelper,
            ServiceClientService serviceClientService); @Override @PreAuthorize("hasAuthority('VIEW_ENDPOINT')") ResponseEntity<Endpoint> getEndpoint(String id); @Override @PreAuthorize("hasAuthority('DELETE_ENDPOINT')") @AuditEventMethod(event = DELETE_REST_ENDPOINT) ResponseEntity<Void> deleteEndpoint(String id); @Override @PreAuthorize("hasAuthority('EDIT_OPENAPI3_ENDPOINT')") @AuditEventMethod(event = EDIT_REST_ENDPOINT) ResponseEntity<Endpoint> updateEndpoint(String id, EndpointUpdate endpointUpdate); @Override @PreAuthorize("hasAuthority('VIEW_ENDPOINT_ACL')") ResponseEntity<List<ServiceClient>> getEndpointServiceClients(String id); @Override @PreAuthorize("hasAuthority('EDIT_ENDPOINT_ACL')") ResponseEntity<List<ServiceClient>> addEndpointServiceClients(String id, ServiceClients serviceClients); @Override @PreAuthorize("hasAuthority('EDIT_ENDPOINT_ACL')") ResponseEntity<Void> deleteEndpointServiceClients(String id, ServiceClients serviceClients);  }