@Test(expected = WebApplicationException.class) public void testFetchJobSpecSummariesThrowsExceptionIfPageSizeIsNegative() throws IOException { final List<JobSpecSummary> jobSpecSummariesReturnedByDAO = generateNJobSpecSummaries(5); final JobSpecDAO jobSpecDAO = mock(JobSpecDAO.class); when(jobSpecDAO.getJobSpecSummaries(anyInt(), anyInt())).thenReturn(jobSpecSummariesReturnedByDAO); final JobSpecResource jobSpecResource = new JobSpecResource(jobSpecDAO, DEFAULT_PAGE_SIZE); final SecurityContext securityContext = generateSecureSecurityContext(); final APIJobSpecSummaryCollection APIJobSpecSummaryCollection = jobSpecResource.fetchJobSpecSummaries(securityContext, Optional.empty(), Optional.of(-1), Optional.empty()); }
@GET @Operation( summary = "Get summaries of the job specs exposed by the system", description = "Returns an object that contains summaries of *some* of the job specs exposed by the system. " + "The response does not necessarily contain summaries for *all* job specs exposed by the system. " + "This is because pagination and client permissions may hide job specs. If further pages of job specs are " + "available, links shall be set to contain hrefs which the client may use to fetch more specs." + "The server may reorder job spec summaries based on its configuration or knowledge about the user. " + "If a client sets a query string, the server will respond appropriately; however, the same rules apply.") @ApiResponses(value = { @ApiResponse( responseCode = "200", description = "Job summaries returned", content = @Content( schema = @Schema(implementation = APIJobSpecSummaryCollection.class) )), }) @PermitAll public APIJobSpecSummaryCollection fetchJobSpecSummaries( @Context SecurityContext context, @Parameter(description = "The page number (0-indexed)") @QueryParam("page") Optional<Integer> page, @Parameter(description = "The number of entries a response page should contain.") @QueryParam("page-size") Optional<Integer> pageSize, @Parameter(description = "Client query string") @QueryParam("query") Optional<String> query) { final int requestedPage = page.isPresent() ? page.get() : 0; final int requestedPageSize = pageSize.isPresent() ? pageSize.get() : defaultPageSize; if (requestedPage < 0) throw new WebApplicationException("Requested page cannot be negative", 400); if (requestedPageSize < 0) throw new WebApplicationException("Requested page size cannot be negative", 400); final List<JobSpecSummary> jobSummaries = query.isPresent() ? jobSpecDAO.getJobSpecSummaries(requestedPageSize, requestedPage, query.get()) : jobSpecDAO.getJobSpecSummaries(requestedPageSize, requestedPage); final List<APIJobSpecSummary> apiJobSpecSummaries = jobSummaries.stream().map(summary -> { try { final Map<String, APIRestLink> restLinks = singletonMap( "details", new APIRestLink(new URI(HTTP_SPECS_PATH + "/" + summary.getId().toString()))); return APIJobSpecSummary.fromJobSpecSummary(summary, restLinks); } catch (URISyntaxException ex) { throw new WebApplicationException(ex); } }).collect(toList()); return new APIJobSpecSummaryCollection(apiJobSpecSummaries, emptyMap()); }
JobSpecResource { @GET @Operation( summary = "Get summaries of the job specs exposed by the system", description = "Returns an object that contains summaries of *some* of the job specs exposed by the system. " + "The response does not necessarily contain summaries for *all* job specs exposed by the system. " + "This is because pagination and client permissions may hide job specs. If further pages of job specs are " + "available, links shall be set to contain hrefs which the client may use to fetch more specs." + "The server may reorder job spec summaries based on its configuration or knowledge about the user. " + "If a client sets a query string, the server will respond appropriately; however, the same rules apply.") @ApiResponses(value = { @ApiResponse( responseCode = "200", description = "Job summaries returned", content = @Content( schema = @Schema(implementation = APIJobSpecSummaryCollection.class) )), }) @PermitAll public APIJobSpecSummaryCollection fetchJobSpecSummaries( @Context SecurityContext context, @Parameter(description = "The page number (0-indexed)") @QueryParam("page") Optional<Integer> page, @Parameter(description = "The number of entries a response page should contain.") @QueryParam("page-size") Optional<Integer> pageSize, @Parameter(description = "Client query string") @QueryParam("query") Optional<String> query) { final int requestedPage = page.isPresent() ? page.get() : 0; final int requestedPageSize = pageSize.isPresent() ? pageSize.get() : defaultPageSize; if (requestedPage < 0) throw new WebApplicationException("Requested page cannot be negative", 400); if (requestedPageSize < 0) throw new WebApplicationException("Requested page size cannot be negative", 400); final List<JobSpecSummary> jobSummaries = query.isPresent() ? jobSpecDAO.getJobSpecSummaries(requestedPageSize, requestedPage, query.get()) : jobSpecDAO.getJobSpecSummaries(requestedPageSize, requestedPage); final List<APIJobSpecSummary> apiJobSpecSummaries = jobSummaries.stream().map(summary -> { try { final Map<String, APIRestLink> restLinks = singletonMap( "details", new APIRestLink(new URI(HTTP_SPECS_PATH + "/" + summary.getId().toString()))); return APIJobSpecSummary.fromJobSpecSummary(summary, restLinks); } catch (URISyntaxException ex) { throw new WebApplicationException(ex); } }).collect(toList()); return new APIJobSpecSummaryCollection(apiJobSpecSummaries, emptyMap()); } }
JobSpecResource { @GET @Operation( summary = "Get summaries of the job specs exposed by the system", description = "Returns an object that contains summaries of *some* of the job specs exposed by the system. " + "The response does not necessarily contain summaries for *all* job specs exposed by the system. " + "This is because pagination and client permissions may hide job specs. If further pages of job specs are " + "available, links shall be set to contain hrefs which the client may use to fetch more specs." + "The server may reorder job spec summaries based on its configuration or knowledge about the user. " + "If a client sets a query string, the server will respond appropriately; however, the same rules apply.") @ApiResponses(value = { @ApiResponse( responseCode = "200", description = "Job summaries returned", content = @Content( schema = @Schema(implementation = APIJobSpecSummaryCollection.class) )), }) @PermitAll public APIJobSpecSummaryCollection fetchJobSpecSummaries( @Context SecurityContext context, @Parameter(description = "The page number (0-indexed)") @QueryParam("page") Optional<Integer> page, @Parameter(description = "The number of entries a response page should contain.") @QueryParam("page-size") Optional<Integer> pageSize, @Parameter(description = "Client query string") @QueryParam("query") Optional<String> query) { final int requestedPage = page.isPresent() ? page.get() : 0; final int requestedPageSize = pageSize.isPresent() ? pageSize.get() : defaultPageSize; if (requestedPage < 0) throw new WebApplicationException("Requested page cannot be negative", 400); if (requestedPageSize < 0) throw new WebApplicationException("Requested page size cannot be negative", 400); final List<JobSpecSummary> jobSummaries = query.isPresent() ? jobSpecDAO.getJobSpecSummaries(requestedPageSize, requestedPage, query.get()) : jobSpecDAO.getJobSpecSummaries(requestedPageSize, requestedPage); final List<APIJobSpecSummary> apiJobSpecSummaries = jobSummaries.stream().map(summary -> { try { final Map<String, APIRestLink> restLinks = singletonMap( "details", new APIRestLink(new URI(HTTP_SPECS_PATH + "/" + summary.getId().toString()))); return APIJobSpecSummary.fromJobSpecSummary(summary, restLinks); } catch (URISyntaxException ex) { throw new WebApplicationException(ex); } }).collect(toList()); return new APIJobSpecSummaryCollection(apiJobSpecSummaries, emptyMap()); } JobSpecResource(JobSpecDAO jobSpecDAO, int defaultPageSize); }
JobSpecResource { @GET @Operation( summary = "Get summaries of the job specs exposed by the system", description = "Returns an object that contains summaries of *some* of the job specs exposed by the system. " + "The response does not necessarily contain summaries for *all* job specs exposed by the system. " + "This is because pagination and client permissions may hide job specs. If further pages of job specs are " + "available, links shall be set to contain hrefs which the client may use to fetch more specs." + "The server may reorder job spec summaries based on its configuration or knowledge about the user. " + "If a client sets a query string, the server will respond appropriately; however, the same rules apply.") @ApiResponses(value = { @ApiResponse( responseCode = "200", description = "Job summaries returned", content = @Content( schema = @Schema(implementation = APIJobSpecSummaryCollection.class) )), }) @PermitAll public APIJobSpecSummaryCollection fetchJobSpecSummaries( @Context SecurityContext context, @Parameter(description = "The page number (0-indexed)") @QueryParam("page") Optional<Integer> page, @Parameter(description = "The number of entries a response page should contain.") @QueryParam("page-size") Optional<Integer> pageSize, @Parameter(description = "Client query string") @QueryParam("query") Optional<String> query) { final int requestedPage = page.isPresent() ? page.get() : 0; final int requestedPageSize = pageSize.isPresent() ? pageSize.get() : defaultPageSize; if (requestedPage < 0) throw new WebApplicationException("Requested page cannot be negative", 400); if (requestedPageSize < 0) throw new WebApplicationException("Requested page size cannot be negative", 400); final List<JobSpecSummary> jobSummaries = query.isPresent() ? jobSpecDAO.getJobSpecSummaries(requestedPageSize, requestedPage, query.get()) : jobSpecDAO.getJobSpecSummaries(requestedPageSize, requestedPage); final List<APIJobSpecSummary> apiJobSpecSummaries = jobSummaries.stream().map(summary -> { try { final Map<String, APIRestLink> restLinks = singletonMap( "details", new APIRestLink(new URI(HTTP_SPECS_PATH + "/" + summary.getId().toString()))); return APIJobSpecSummary.fromJobSpecSummary(summary, restLinks); } catch (URISyntaxException ex) { throw new WebApplicationException(ex); } }).collect(toList()); return new APIJobSpecSummaryCollection(apiJobSpecSummaries, emptyMap()); } JobSpecResource(JobSpecDAO jobSpecDAO, int defaultPageSize); @GET @Operation( summary = "Get summaries of the job specs exposed by the system", description = "Returns an object that contains summaries of *some* of the job specs exposed by the system. " + "The response does not necessarily contain summaries for *all* job specs exposed by the system. " + "This is because pagination and client permissions may hide job specs. If further pages of job specs are " + "available, links shall be set to contain hrefs which the client may use to fetch more specs." + "The server may reorder job spec summaries based on its configuration or knowledge about the user. " + "If a client sets a query string, the server will respond appropriately; however, the same rules apply.") @ApiResponses(value = { @ApiResponse( responseCode = "200", description = "Job summaries returned", content = @Content( schema = @Schema(implementation = APIJobSpecSummaryCollection.class) )), }) @PermitAll APIJobSpecSummaryCollection fetchJobSpecSummaries(
            @Context
                    SecurityContext context,
            @Parameter(description = "The page number (0-indexed)")
            @QueryParam("page")
                    Optional<Integer> page,
            @Parameter(description = "The number of entries a response page should contain.")
            @QueryParam("page-size")
                    Optional<Integer> pageSize,
            @Parameter(description = "Client query string")
            @QueryParam("query")
                    Optional<String> query); @GET @Path("{job-spec-id}") @Operation( summary = "Get a a job spec.", description = "If found, returns a job spec. A job spec describes declaratively what a " + "job needs in order to run.") @ApiResponses(value = { @ApiResponse( responseCode = "200", description = "Job specification found and returned", content = @Content( schema = @Schema(implementation = APIJobSpec.class) )), @ApiResponse( responseCode = "404", description = "The job specification cannot be found", content = @Content( schema = @Schema(implementation = APIErrorMessage.class) )) }) @PermitAll Optional<APIJobSpec> fetchJobSpecDetailsById(
            @Context
                    SecurityContext context,
            @Parameter(description = "The job spec's ID")
            @PathParam("job-spec-id")
            @NotNull
                    JobSpecId jobSpecId); }
JobSpecResource { @GET @Operation( summary = "Get summaries of the job specs exposed by the system", description = "Returns an object that contains summaries of *some* of the job specs exposed by the system. " + "The response does not necessarily contain summaries for *all* job specs exposed by the system. " + "This is because pagination and client permissions may hide job specs. If further pages of job specs are " + "available, links shall be set to contain hrefs which the client may use to fetch more specs." + "The server may reorder job spec summaries based on its configuration or knowledge about the user. " + "If a client sets a query string, the server will respond appropriately; however, the same rules apply.") @ApiResponses(value = { @ApiResponse( responseCode = "200", description = "Job summaries returned", content = @Content( schema = @Schema(implementation = APIJobSpecSummaryCollection.class) )), }) @PermitAll public APIJobSpecSummaryCollection fetchJobSpecSummaries( @Context SecurityContext context, @Parameter(description = "The page number (0-indexed)") @QueryParam("page") Optional<Integer> page, @Parameter(description = "The number of entries a response page should contain.") @QueryParam("page-size") Optional<Integer> pageSize, @Parameter(description = "Client query string") @QueryParam("query") Optional<String> query) { final int requestedPage = page.isPresent() ? page.get() : 0; final int requestedPageSize = pageSize.isPresent() ? pageSize.get() : defaultPageSize; if (requestedPage < 0) throw new WebApplicationException("Requested page cannot be negative", 400); if (requestedPageSize < 0) throw new WebApplicationException("Requested page size cannot be negative", 400); final List<JobSpecSummary> jobSummaries = query.isPresent() ? jobSpecDAO.getJobSpecSummaries(requestedPageSize, requestedPage, query.get()) : jobSpecDAO.getJobSpecSummaries(requestedPageSize, requestedPage); final List<APIJobSpecSummary> apiJobSpecSummaries = jobSummaries.stream().map(summary -> { try { final Map<String, APIRestLink> restLinks = singletonMap( "details", new APIRestLink(new URI(HTTP_SPECS_PATH + "/" + summary.getId().toString()))); return APIJobSpecSummary.fromJobSpecSummary(summary, restLinks); } catch (URISyntaxException ex) { throw new WebApplicationException(ex); } }).collect(toList()); return new APIJobSpecSummaryCollection(apiJobSpecSummaries, emptyMap()); } JobSpecResource(JobSpecDAO jobSpecDAO, int defaultPageSize); @GET @Operation( summary = "Get summaries of the job specs exposed by the system", description = "Returns an object that contains summaries of *some* of the job specs exposed by the system. " + "The response does not necessarily contain summaries for *all* job specs exposed by the system. " + "This is because pagination and client permissions may hide job specs. If further pages of job specs are " + "available, links shall be set to contain hrefs which the client may use to fetch more specs." + "The server may reorder job spec summaries based on its configuration or knowledge about the user. " + "If a client sets a query string, the server will respond appropriately; however, the same rules apply.") @ApiResponses(value = { @ApiResponse( responseCode = "200", description = "Job summaries returned", content = @Content( schema = @Schema(implementation = APIJobSpecSummaryCollection.class) )), }) @PermitAll APIJobSpecSummaryCollection fetchJobSpecSummaries(
            @Context
                    SecurityContext context,
            @Parameter(description = "The page number (0-indexed)")
            @QueryParam("page")
                    Optional<Integer> page,
            @Parameter(description = "The number of entries a response page should contain.")
            @QueryParam("page-size")
                    Optional<Integer> pageSize,
            @Parameter(description = "Client query string")
            @QueryParam("query")
                    Optional<String> query); @GET @Path("{job-spec-id}") @Operation( summary = "Get a a job spec.", description = "If found, returns a job spec. A job spec describes declaratively what a " + "job needs in order to run.") @ApiResponses(value = { @ApiResponse( responseCode = "200", description = "Job specification found and returned", content = @Content( schema = @Schema(implementation = APIJobSpec.class) )), @ApiResponse( responseCode = "404", description = "The job specification cannot be found", content = @Content( schema = @Schema(implementation = APIErrorMessage.class) )) }) @PermitAll Optional<APIJobSpec> fetchJobSpecDetailsById(
            @Context
                    SecurityContext context,
            @Parameter(description = "The job spec's ID")
            @PathParam("job-spec-id")
            @NotNull
                    JobSpecId jobSpecId);  }