DatasetRest { @GET @Produces(MediaType.APPLICATION_JSON) @Path("{datasetRecordId}") @RolesAllowed("user") @ApiOperation("Gets a specific DatasetRecord from the local Catalog") public Response getDatasetRecord(@PathParam("datasetRecordId") String datasetRecordId) { Resource recordIRI = vf.createIRI(datasetRecordId); try { DatasetRecord datasetRecord = manager.getDatasetRecord(recordIRI).orElseThrow(() -> ErrorUtils.sendError("DatasetRecord " + datasetRecordId + " could not be found", Response.Status.NOT_FOUND)); Model copy = mf.createModel(); datasetRecord.getModel().forEach(st -> copy.add(st.getSubject(), st.getPredicate(), st.getObject())); return Response.ok(modelToJsonld(copy, transformer)).build(); } catch (IllegalArgumentException ex) { throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.BAD_REQUEST); } catch (IllegalStateException | MobiException ex) { throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR); } }  @GET @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves all DatasetRecords in the local Catalog") Response getDatasetRecords(@Context UriInfo uriInfo,
                               @QueryParam("offset") int offset,
                               @QueryParam("limit") int limit,
                               @QueryParam("sort") String sort,
                               @DefaultValue("true") @QueryParam("ascending") boolean asc,
                               @QueryParam("searchText") String searchText); @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.TEXT_PLAIN) @RolesAllowed("user") @ApiOperation("Creates a new DatasetRecord in the local Catalog and Dataset in the specified repository") Response createDatasetRecord(@Context ContainerRequestContext context,
                                 @FormDataParam("title") String title,
                                 @FormDataParam("repositoryId") String repositoryId,
                                 @FormDataParam("datasetIRI") String datasetIRI,
                                 @FormDataParam("description") String description,
                                 @FormDataParam("markdown") String markdown,
                                 @FormDataParam("keywords") List<FormDataBodyPart> keywords,
                                 @FormDataParam("ontologies") List<FormDataBodyPart> ontologies); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{datasetRecordId}") @RolesAllowed("user") @ApiOperation("Gets a specific DatasetRecord from the local Catalog") Response getDatasetRecord(@PathParam("datasetRecordId") String datasetRecordId); @DELETE @Path("{datasetRecordId}") @RolesAllowed("user") @ApiOperation("Deletes a specific DatasetRecord in the local Catalog") Response deleteDatasetRecord(@Context ContainerRequestContext context,
                                 @PathParam("datasetRecordId") String datasetRecordId,
                                 @DefaultValue("false") @QueryParam("force") boolean force); @DELETE @Path("{datasetRecordId}/data") @RolesAllowed("user") @ApiOperation("Clears the data within a specific DatasetRecord in the local Catalog") Response clearDatasetRecord(@PathParam("datasetRecordId") String datasetRecordId,
                                @DefaultValue("false") @QueryParam("force") boolean force); @POST @Path("{datasetRecordId}/data") @RolesAllowed("user") @ApiOperation("Uploads the data within an RDF file to a specific DatasetRecord in the local Catalog") Response uploadData(@PathParam("datasetRecordId") String datasetRecordId,
                        @FormDataParam("file") InputStream fileInputStream,
                        @FormDataParam("file") FormDataContentDisposition fileDetail);  }
@Test public void getDatasetRecordTest() { Response response = target().path("datasets/" + encode(record1.getResource().stringValue())).request().get(); assertEquals(response.getStatus(), 200); verify(datasetManager).getDatasetRecord(record1.getResource()); }
@Test public void getDatasetRecordThatCouldNotBeFoundTest() { when(datasetManager.getDatasetRecord(any(Resource.class))).thenReturn(Optional.empty()); Response response = target().path("datasets/" + encode(record1.getResource().stringValue())).request().get(); assertEquals(response.getStatus(), 404); verify(datasetManager).getDatasetRecord(record1.getResource()); }
@Test public void getDatasetRecordThatDoesNotExistTest() { doThrow(new IllegalArgumentException()).when(datasetManager).getDatasetRecord(any(Resource.class)); Response response = target().path("datasets/" + encode(record1.getResource().stringValue())).request().get(); assertEquals(response.getStatus(), 400); verify(datasetManager).getDatasetRecord(record1.getResource()); }
@Test public void getDatasetRecordWithIllegalStateTest() { doThrow(new IllegalStateException()).when(datasetManager).getDatasetRecord(any(Resource.class)); Response response = target().path("datasets/" + encode(record1.getResource().stringValue())).request().get(); assertEquals(response.getStatus(), 500); verify(datasetManager).getDatasetRecord(record1.getResource()); }
@Test public void getDatasetRecordWithFailedConnectionTest() { doThrow(new RepositoryException()).when(datasetManager).getDatasetRecord(any(Resource.class)); Response response = target().path("datasets/" + encode(record1.getResource().stringValue())).request().get(); assertEquals(response.getStatus(), 500); verify(datasetManager).getDatasetRecord(record1.getResource()); }