List of usage examples for org.apache.commons.rdf.api IRI getIRIString
String getIRIString();
From source file:org.trellisldp.rosid.file.CachedResource.java
/** * Write the resource data into a file as JSON * @param directory the directory//from w ww.j av a2 s . co m * @param identifier the resource identifier * @param time the time * @return true if the write operation succeeds */ public static Boolean write(final File directory, final IRI identifier, final Instant time) { if (isNull(directory)) { return false; } // Write the JSON file LOGGER.debug("Writing JSON cache for {}", identifier.getIRIString()); final Optional<ResourceData> data = VersionedResource.read(directory, identifier, time); try { if (data.isPresent()) { MAPPER.writeValue(new File(directory, RESOURCE_CACHE), data.get()); } else { LOGGER.error("No resource data to cache for {}", identifier.getIRIString()); return false; } } catch (final IOException ex) { LOGGER.error("Error writing resource metadata cache for {}: {}", identifier.getIRIString(), ex.getMessage()); return false; } // Write the quads LOGGER.debug("Writing NQuads cache for {}", identifier.getIRIString()); try (final BufferedWriter writer = newBufferedWriter(new File(directory, RESOURCE_QUADS).toPath(), UTF_8, CREATE, WRITE, TRUNCATE_EXISTING)) { final File file = new File(directory, RESOURCE_JOURNAL); final Iterator<String> lineIter = RDFPatch.asStream(rdf, file, identifier, time) .map(RDFPatch.quadToString).iterator(); while (lineIter.hasNext()) { writer.write(lineIter.next() + lineSeparator()); } } catch (final IOException ex) { LOGGER.error("Error writing resource cache for {}: {}", identifier.getIRIString(), ex.getMessage()); return false; } return true; }
From source file:org.trellisldp.rosid.file.FileResourceService.java
private void init() throws IOException { for (final Map.Entry<String, String> storage : partitions.entrySet()) { final File data = storage.getValue().startsWith("file:") ? new File(create(storage.getValue())) : new File(storage.getValue()); LOGGER.info("Using resource data directory for '{}': {}", storage.getKey(), data.getAbsolutePath()); if (!data.exists()) { data.mkdirs();/*from ww w. ja v a 2 s . co m*/ } if (!data.canWrite()) { throw new IOException("Cannot write to " + data.getAbsolutePath()); } final IRI identifier = rdf.createIRI(TRELLIS_PREFIX + storage.getKey()); final IRI authIdentifier = rdf.createIRI(TRELLIS_PREFIX + storage.getKey() + "#auth"); final File root = resourceDirectory(partitions, identifier); final File rootData = new File(root, RESOURCE_JOURNAL); if (!root.exists() || !rootData.exists()) { LOGGER.info("Initializing root container for '{}'", identifier.getIRIString()); root.mkdirs(); final Instant time = now(); final IRI skolem = (IRI) skolemize(rdf.createBlankNode()); final Stream<Quad> quads = of( rdf.createQuad(Trellis.PreferServerManaged, identifier, RDF.type, LDP.Container), rdf.createQuad(Trellis.PreferAccessControl, authIdentifier, RDF.type, ACL.Authorization), rdf.createQuad(Trellis.PreferAccessControl, authIdentifier, ACL.mode, ACL.Read), rdf.createQuad(Trellis.PreferAccessControl, authIdentifier, ACL.mode, ACL.Write), rdf.createQuad(Trellis.PreferAccessControl, authIdentifier, ACL.mode, ACL.Control), rdf.createQuad(Trellis.PreferAccessControl, authIdentifier, ACL.accessTo, identifier), rdf.createQuad(Trellis.PreferAccessControl, authIdentifier, ACL.agentClass, FOAF.Agent), rdf.createQuad(Trellis.PreferAudit, identifier, PROV.wasGeneratedBy, skolem), rdf.createQuad(Trellis.PreferAudit, skolem, RDF.type, PROV.Activity), rdf.createQuad(Trellis.PreferAudit, skolem, RDF.type, AS.Create), rdf.createQuad(Trellis.PreferAudit, skolem, PROV.wasAssociatedWith, Trellis.RepositoryAdministrator), rdf.createQuad(Trellis.PreferAudit, skolem, PROV.generatedAtTime, rdf.createLiteral(time.toString(), XSD.dateTime))); RDFPatch.write(rootData, empty(), quads, now()); CachedResource.write(root, identifier); } } }
From source file:org.trellisldp.rosid.file.FileUtils.java
/** * Partition an identifier into a directory structure * @param identifier the identifier/*from w ww . j a va2 s . c om*/ * @return a string usable as a directory path */ public static String partition(final IRI identifier) { return partition(identifier.getIRIString()); }
From source file:org.trellisldp.rosid.file.FileUtils.java
/** * Get the resource directory for a given identifier * @param config the configuration//from ww w. j a v a 2s . com * @param identifier the identifier * @return the file */ public static File resourceDirectory(final Map<String, String> config, final IRI identifier) { return resourceDirectory(config, identifier.getIRIString()); }
From source file:org.trellisldp.rosid.file.VersionedResource.java
/** * Create a File-based versioned resource * @param directory the directory/* ww w . ja va 2 s . c o m*/ * @param identifier the resource identifier * @param data the resource data * @param time the time */ protected VersionedResource(final File directory, final IRI identifier, final ResourceData data, final Instant time) { super(directory, identifier, data); this.time = time; LOGGER.debug("Creating a Versioned Resource for {}", identifier.getIRIString()); }
From source file:org.trellisldp.spi.RDFUtils.java
/** * Clean the identifier/* w ww . j av a 2s. co m*/ * @param identifier the identifier * @return the cleaned identifier */ public static IRI cleanIdentifier(final IRI identifier) { return rdf.createIRI(cleanIdentifier(identifier.getIRIString())); }
From source file:org.trellisldp.test.TestUtils.java
/** * Test if the given ldp:constrainedBy link is present. * @param iri the IRI/*from w ww . ja v a 2 s. c o m*/ * @return true if present; false otherwise */ public static Predicate<Link> hasConstrainedBy(final IRI iri) { return link -> LDP.constrainedBy.getIRIString().equals(link.getRel()) && iri.getIRIString().equals(link.getUri().toString()); }
From source file:org.trellisldp.test.TestUtils.java
/** * Test if the given type link is present. * @param iri the IRI/*from www . ja v a 2s .co m*/ * @return true if present; false otherwise */ public static Predicate<Link> hasType(final IRI iri) { return link -> "type".equals(link.getRel()) && iri.getIRIString().equals(link.getUri().toString()); }
From source file:org.trellisldp.triplestore.TriplestoreResourceService.java
private Node getAclIRI(final IRI identifier) { return createURI(identifier.getIRIString() + "?ext=acl"); }
From source file:org.trellisldp.triplestore.TriplestoreResourceService.java
private Node getAuditIRI(final IRI identifier) { return createURI(identifier.getIRIString() + "?ext=audit"); }