DatasetRest { @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") public 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) { checkStringParam(title, "Title is required"); checkStringParam(repositoryId, "Repository id is required"); User activeUser = getActiveUser(context, engineManager); CreateActivity createActivity = null; try { createActivity = provUtils.startCreateActivity(activeUser); DatasetRecordConfig.DatasetRecordBuilder builder = new DatasetRecordConfig.DatasetRecordBuilder(title, Collections.singleton(activeUser), repositoryId); if (StringUtils.isNotEmpty(datasetIRI)) { builder.dataset(datasetIRI); } if (StringUtils.isNotEmpty(description)) { builder.description(description); } if (StringUtils.isNotEmpty(markdown)) { builder.markdown(markdown); } if (keywords != null) { builder.keywords(keywords.stream().map(FormDataBodyPart::getValue).collect(Collectors.toSet())); } if (ontologies != null) { ontologies.forEach(formDataBodyPart -> builder.ontology( getOntologyIdentifier(vf.createIRI(formDataBodyPart.getValue())))); } DatasetRecord record = manager.createDataset(builder.build()); provUtils.endCreateActivity(createActivity, record.getResource()); return Response.status(201).entity(record.getResource().stringValue()).build(); } catch (IllegalArgumentException ex) { provUtils.removeActivity(createActivity); throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.BAD_REQUEST); } catch (IllegalStateException | MobiException ex) { provUtils.removeActivity(createActivity); throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR); } catch (Exception ex) { provUtils.removeActivity(createActivity); throw ex; } }  @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 createDatasetRecordTest() { FormDataMultiPart fd = new FormDataMultiPart().field("title", "title") .field("datasetIRI", "http: .field("repositoryId", "system") .field("description", "description") .field("markdown", "#markdown") .field("keywords", "test") .field("keywords", "demo") .field("ontologies", ontologyRecordIRI.stringValue()); Response response = target().path("datasets").request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 201); ArgumentCaptor<DatasetRecordConfig> config = ArgumentCaptor.forClass(DatasetRecordConfig.class); verify(datasetManager).createDataset(config.capture()); assertEquals("http: assertEquals("system", config.getValue().getRepositoryId()); assertEquals(1, config.getValue().getOntologies().size()); assertEquals("title", config.getValue().getTitle()); assertEquals("description", config.getValue().getDescription()); assertEquals("#markdown", config.getValue().getMarkdown()); assertNull(config.getValue().getIdentifier()); assertEquals(Stream.of("test", "demo").collect(Collectors.toSet()), config.getValue().getKeywords()); assertEquals(Collections.singleton(user), config.getValue().getPublishers()); verify(catalogManager).getMasterBranch(localIRI, ontologyRecordIRI); assertEquals(response.readEntity(String.class), record1.getResource().stringValue()); verify(provUtils).startCreateActivity(user); verify(provUtils).endCreateActivity(createActivity, record1.getResource()); }