Manifest { public Path writeAsJsonLD() throws IOException { Path jsonld = bundle.getFileSystem().getPath(RO, MANIFEST_JSON); createDirectories(jsonld.getParent()); if (!getManifest().contains(jsonld)) getManifest().add(0, jsonld); ObjectMapper om = new ObjectMapper() .addMixIn(Path.class, PathMixin.class) .addMixIn(FileTime.class, FileTimeMixin.class) .enable(INDENT_OUTPUT) .disable(WRITE_EMPTY_JSON_ARRAYS) .disable(FAIL_ON_EMPTY_BEANS) .disable(WRITE_NULL_MAP_VALUES); om.setSerializationInclusion(Include.NON_NULL); try (Writer w = newBufferedWriter(jsonld, Charset.forName("UTF-8"), WRITE, TRUNCATE_EXISTING, CREATE)) { om.writeValue(w, this); } return jsonld; } Manifest(Bundle bundle); static FileTime now(); List<PathMetadata> getAggregates(); PathMetadata getAggregation(Path file); PathMetadata getAggregation(URI uri); List<PathAnnotation> getAnnotations(); @JsonIgnore Optional<PathAnnotation> getAnnotation(URI annotation); @JsonIgnore List<PathAnnotation> getAnnotations(final URI about); @JsonIgnore List<PathAnnotation> getAnnotations(Path about); List<Agent> getAuthoredBy(); FileTime getAuthoredOn(); @JsonIgnore URI getBaseURI(); @JsonIgnore Bundle getBundle(); List<URI> getConformsTo(); @JsonProperty(value = "@context") List<Object> getContext(); Agent getCreatedBy(); FileTime getCreatedOn(); URI getRetrievedFrom(); Agent getRetrievedBy(); FileTime getRetrievedOn(); List<String> getGraph(); List<Path> getHistory(); URI getId(); List<Path> getManifest(); String guessMediaType(Path file); void populateFromBundle(); URI relativeToBundleRoot(URI uri); @SuppressWarnings("deprecation") void setAggregates(List<PathMetadata> aggregates); void setAnnotations(List<PathAnnotation> annotations); void setAuthoredBy(List<Agent> authoredBy); void setAuthoredOn(FileTime authoredOn); void setBundle(Bundle bundle); void setConformsTo(List<URI> conformsTo); void setCreatedBy(Agent createdBy); void setCreatedOn(FileTime createdOn); void setRetrievedFrom(URI retrievedFrom); void setRetrievedBy(Agent retrievedBy); void setRetrievedOn(FileTime retrievedOn); void setGraph(List<String> graph); void setHistory(List<Path> history); void setId(URI id); void setManifest(List<Path> manifest); void writeAsCombineManifest(); Path writeAsJsonLD(); Path writeAsODFManifest();  }
@Test public void writeAsJsonLD() throws Exception { Manifest manifest = new Manifest(bundle); manifest.populateFromBundle(); PathMetadata helloMeta = null; for (PathMetadata meta : manifest.getAggregates()) { if (meta.getFile().endsWith("hello.txt")) { helloMeta = meta; } } assertNotNull("No metadata for </hello.txt>", helloMeta); Path jsonld = manifest.writeAsJsonLD(); assertEquals(bundle.getFileSystem().getPath("/.ro", "manifest.json"), jsonld); assertTrue(Files.exists(jsonld)); String manifestStr = new String(Files.readAllBytes(jsonld), "UTF8"); assertTrue(manifestStr.contains("@context")); assertTrue(manifestStr.contains("https: assertTrue(manifestStr.contains("/f/file2.txt")); assertTrue(manifestStr.contains("/hello.txt")); assertTrue(manifestStr.contains(helloMeta.getProxy().toASCIIString())); try (InputStream jsonIn = Files.newInputStream(jsonld)) { URI baseURI = jsonld.toUri(); Model model = RDFToManifest.jsonLdAsJenaModel(jsonIn, baseURI); model.write(new ByteArrayOutputStream(), "TURTLE", baseURI.toString()); model.write(new ByteArrayOutputStream(), "RDF/XML", baseURI.toString()); String queryStr = "PREFIX ore: <http: + "PREFIX bundle: <http: + "SELECT ?file ?proxy " + "WHERE {" + " ?ro ore:aggregates ?file ." + " OPTIONAL { ?file bundle:bundledAs ?proxy . } " + "}"; Query query = QueryFactory.create(queryStr); QueryExecution qexec = QueryExecutionFactory.create(query, model); try { ResultSet results = qexec.execSelect(); int aggregationCount = 0; for (; results.hasNext(); aggregationCount++) { QuerySolution soln = results.nextSolution(); Resource fileRes = soln.getResource("file"); Resource proxy = soln.getResource("proxy"); Path file = Paths.get(asURI(fileRes)); assertTrue(Files.exists(file)); PathMetadata meta = manifest.getAggregation(file); assertEquals(meta.getProxy(), asURI(proxy)); } assertEquals("Could not find all aggregations from manifest: " + manifest.getAggregates(), manifest.getAggregates() .size(), aggregationCount); } finally { qexec.close(); } } }