class 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 public  EndpointsApiController(
            EndpointService endpointService,
            EndpointConverter endpointConverter,
            AccessRightService accessRightService,
            ServiceClientConverter serviceClientConverter,
            ServiceClientHelper serviceClientHelper,
            ServiceClientService serviceClientService);

}