MappingRest { @GET @Path("{recordId}") @Produces({MediaType.APPLICATION_OCTET_STREAM, "text/*", "application/*"}) @RolesAllowed("user") @ApiOperation("Download an uploaded mapping") @ResourceId(type = ValueType.PATH, value = "recordId") public Response downloadMapping(@PathParam("recordId") String recordId, @DefaultValue("jsonld") @QueryParam("format") String format) { try { logger.info("Downloading mapping " + recordId); MappingWrapper mapping = manager.retrieveMapping(vf.createIRI(recordId)).orElseThrow(() -> ErrorUtils.sendError("Mapping not found", Response.Status.NOT_FOUND)); RDFFormat rdfFormat = getRDFFormat(format); String mappingJsonld = groupedModelToString(mapping.getModel(), rdfFormat, transformer); StreamingOutput stream = os -> { Writer writer = new BufferedWriter(new OutputStreamWriter(os)); writer.write(format.equalsIgnoreCase("jsonld") ? getObjectFromJsonld(mappingJsonld).toString() : mappingJsonld); writer.flush(); writer.close(); }; return Response.ok(stream).header("Content-Disposition", "attachment; filename=" + vf.createIRI(mapping.getId().getMappingIdentifier().stringValue()).getLocalName() + "." + rdfFormat.getDefaultFileExtension()).header("Content-Type", rdfFormat.getDefaultMIMEType()) .build(); } catch (IllegalArgumentException e) { throw ErrorUtils.sendError(e, e.getMessage(), Response.Status.BAD_REQUEST); } catch (MobiException e) { throw ErrorUtils.sendError(e, e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR); } }  @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @RolesAllowed("user") @ApiOperation("Upload mapping sent as form data.") @ActionAttributes(@AttributeValue(id = com.mobi.ontologies.rdfs.Resource.type_IRI, value = MappingRecord.TYPE)) @ResourceId("http://mobi.com/catalog-local") Response upload(@Context ContainerRequestContext context,
                    @FormDataParam("title") String title,
                    @FormDataParam("description") String description,
                    @FormDataParam("markdown") String markdown,
                    @FormDataParam("keywords") List<FormDataBodyPart> keywords,
                    @FormDataParam("file") InputStream fileInputStream,
                    @FormDataParam("file") FormDataContentDisposition fileDetail,
                    @FormDataParam("jsonld") String jsonld); @GET @Path("{recordId}") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieve JSON-LD of an uploaded mapping") @ResourceId(type = ValueType.PATH, value = "recordId") Response getMapping(@PathParam("recordId") String recordId); @GET @Path("{recordId}") @Produces({MediaType.APPLICATION_OCTET_STREAM, "text/*", "application/*"}) @RolesAllowed("user") @ApiOperation("Download an uploaded mapping") @ResourceId(type = ValueType.PATH, value = "recordId") Response downloadMapping(@PathParam("recordId") String recordId,
                             @DefaultValue("jsonld") @QueryParam("format") String format); @DELETE @Path("{recordId}") @RolesAllowed("user") @ApiOperation("Delete an uploaded mapping") @ActionId(Delete.TYPE) @ResourceId(type = ValueType.PATH, value = "recordId") Response deleteMapping(@Context ContainerRequestContext context,
                           @PathParam("recordId") String recordId);  }
@Test public void downloadMappingTest() { Response response = target().path("mappings/" + encode(MAPPING_IRI)).request() .accept(MediaType.APPLICATION_OCTET_STREAM_TYPE).get(); assertEquals(response.getStatus(), 200); verify(manager).retrieveMapping(vf.createIRI(MAPPING_IRI)); }