Search in sources :

Example 1 with TURTLE

use of org.apache.jena.riot.Lang.TURTLE in project trellis by trellis-ldp.

the class WebAcService method generateDefaultRootAuthorizationsDataset.

static Dataset generateDefaultRootAuthorizationsDataset(final String resource) {
    final Dataset dataset = rdf.createDataset();
    final Model model = createDefaultModel();
    try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) {
        if (is != null) {
            LOGGER.debug("Using classpath resource for default root ACL: {}", resource);
            RDFParser.source(is).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model);
        } else {
            LOGGER.debug("Using external resource for default root ACL: {}", resource);
            RDFParser.source(resource).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model);
        }
        fromJena(model.getGraph()).stream().map(triple -> rdf.createQuad(Trellis.PreferAccessControl, triple.getSubject(), triple.getPredicate(), triple.getObject())).forEach(dataset::add);
    } catch (final IOException | RiotException ex) {
        LOGGER.warn("Couldn't initialize root ACL with {}, falling back to default: {}", resource, ex.getMessage());
    } finally {
        model.close();
    }
    // Fallback to manual creation
    if (dataset.size() == 0) {
        dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Read));
        dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Write));
        dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Control));
        dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Append));
        dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.agentClass, FOAF.Agent));
        dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.default_, root));
        dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.accessTo, root));
    }
    return dataset;
}
Also used : TrellisRuntimeException(org.trellisldp.api.TrellisRuntimeException) Collections.unmodifiableList(java.util.Collections.unmodifiableList) Resource(org.trellisldp.api.Resource) Model(org.apache.jena.rdf.model.Model) Graph(org.apache.commons.rdf.api.Graph) CacheService(org.trellisldp.api.CacheService) Collectors.toSet(java.util.stream.Collectors.toSet) DELETED_RESOURCE(org.trellisldp.api.Resource.SpecialResources.DELETED_RESOURCE) TYPE(java.lang.annotation.ElementType.TYPE) FIELD(java.lang.annotation.ElementType.FIELD) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) Set(java.util.Set) TrellisUtils.toGraph(org.trellisldp.api.TrellisUtils.toGraph) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) TRELLIS_DATA_PREFIX(org.trellisldp.api.TrellisUtils.TRELLIS_DATA_PREFIX) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) FOAF(org.trellisldp.vocabulary.FOAF) JenaCommonsRDF.fromJena(org.apache.jena.commonsrdf.JenaCommonsRDF.fromJena) RiotException(org.apache.jena.riot.RiotException) TURTLE(org.apache.jena.riot.Lang.TURTLE) Session(org.trellisldp.api.Session) RDFTerm(org.apache.commons.rdf.api.RDFTerm) ACL(org.trellisldp.vocabulary.ACL) PARAMETER(java.lang.annotation.ElementType.PARAMETER) CompletableFuture(java.util.concurrent.CompletableFuture) TrellisUtils.getContainer(org.trellisldp.api.TrellisUtils.getContainer) VCARD(org.trellisldp.vocabulary.VCARD) Function(java.util.function.Function) RDF(org.apache.commons.rdf.api.RDF) Triple(org.apache.commons.rdf.api.Triple) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Metadata(org.trellisldp.api.Metadata) String.join(java.lang.String.join) ResourceService(org.trellisldp.api.ResourceService) Objects.requireNonNull(java.util.Objects.requireNonNull) Dataset(org.apache.commons.rdf.api.Dataset) Trellis(org.trellisldp.vocabulary.Trellis) RDFFactory(org.trellisldp.api.RDFFactory) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) RDFParser(org.apache.jena.riot.RDFParser) IOException(java.io.IOException) TrellisUtils(org.trellisldp.api.TrellisUtils) RUNTIME(java.lang.annotation.RetentionPolicy.RUNTIME) METHOD(java.lang.annotation.ElementType.METHOD) Collectors.toList(java.util.stream.Collectors.toList) ModelFactory.createDefaultModel(org.apache.jena.rdf.model.ModelFactory.createDefaultModel) IRI(org.apache.commons.rdf.api.IRI) Quad(org.apache.commons.rdf.api.Quad) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) MISSING_RESOURCE(org.trellisldp.api.Resource.SpecialResources.MISSING_RESOURCE) Collections(java.util.Collections) InputStream(java.io.InputStream) RiotException(org.apache.jena.riot.RiotException) Dataset(org.apache.commons.rdf.api.Dataset) InputStream(java.io.InputStream) Model(org.apache.jena.rdf.model.Model) ModelFactory.createDefaultModel(org.apache.jena.rdf.model.ModelFactory.createDefaultModel) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 String.join (java.lang.String.join)1 FIELD (java.lang.annotation.ElementType.FIELD)1 METHOD (java.lang.annotation.ElementType.METHOD)1 PARAMETER (java.lang.annotation.ElementType.PARAMETER)1 TYPE (java.lang.annotation.ElementType.TYPE)1 RUNTIME (java.lang.annotation.RetentionPolicy.RUNTIME)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptySet (java.util.Collections.emptySet)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Function (java.util.function.Function)1