Search in sources :

Example 81 with BlankNodeOrIRI

use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.

the class OWLAPIToClerezzaConverterTest method setupClass.

@BeforeClass
public static void setupClass() {
    /*
         * Set-up the OWL ontology for the test. Simply add the axioms: AndreaNuzzolese isA Person -> class
         * assertion axiom EnricoDaga isA Person -> class assertion axiom AndreaNuzzolese knows EnricoDaga ->
         * object property assertion axiom
         */
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLDataFactory factory = manager.getOWLDataFactory();
    try {
        ontology = manager.createOntology(org.semanticweb.owlapi.model.IRI.create(ns + "testOntology"));
    } catch (OWLOntologyCreationException e) {
        log.error(e.getMessage());
    }
    if (ontology != null) {
        OWLClass personClass = factory.getOWLClass(org.semanticweb.owlapi.model.IRI.create(foaf + "Person"));
        OWLNamedIndividual andreaNuzzoleseOWL = factory.getOWLNamedIndividual(org.semanticweb.owlapi.model.IRI.create(ns + "AndreaNuzzolese"));
        OWLNamedIndividual enricoDagaOWL = factory.getOWLNamedIndividual(org.semanticweb.owlapi.model.IRI.create(ns + "EnricoDaga"));
        OWLObjectProperty knowsOWL = factory.getOWLObjectProperty(org.semanticweb.owlapi.model.IRI.create(foaf + "knows"));
        OWLAxiom axiom = factory.getOWLClassAssertionAxiom(personClass, andreaNuzzoleseOWL);
        manager.addAxiom(ontology, axiom);
        axiom = factory.getOWLClassAssertionAxiom(personClass, enricoDagaOWL);
        manager.addAxiom(ontology, axiom);
        axiom = factory.getOWLObjectPropertyAssertionAxiom(knowsOWL, andreaNuzzoleseOWL, enricoDagaOWL);
        manager.addAxiom(ontology, axiom);
    }
    /*
         * Set-up the Clerezza model for the test. As before simply add the triples: AndreaNuzzolese isA
         * Person EnricoDaga isA Person AndreaNuzzolese knows EnricoDaga
         */
    mGraph = new SimpleGraph();
    IRI knowsInClerezza = new IRI(ns + "knows");
    IRI rdfType = new IRI(RDF.getURI() + "type");
    IRI foafPersonInClerezza = new IRI(foaf + "Person");
    BlankNodeOrIRI andreaNuzzoleseInClerezza = new IRI(ns + "AndreaNuzzolese");
    BlankNodeOrIRI enricoDagaInClerezza = new IRI(ns + "EnricoDaga");
    Triple triple = new TripleImpl(andreaNuzzoleseInClerezza, rdfType, foafPersonInClerezza);
    mGraph.add(triple);
    triple = new TripleImpl(enricoDagaInClerezza, rdfType, foafPersonInClerezza);
    mGraph.add(triple);
    triple = new TripleImpl(andreaNuzzoleseInClerezza, knowsInClerezza, enricoDagaInClerezza);
    mGraph.add(triple);
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) BeforeClass(org.junit.BeforeClass)

Example 82 with BlankNodeOrIRI

use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.

the class UserResource method clearPermissions.

//    []    a       <http://xmlns.com/foaf/0.1/Agent> ;
//      <http://clerezza.org/2008/10/permission#hasPermission>
//              [ a       <http://clerezza.org/2008/10/permission#Permission> ;
//                <http://clerezza.org/2008/10/permission#javaPermissionEntry>
//                        "(java.security.AllPermission \"\" \"\")"
//              ] ;
private void clearPermissions(BlankNodeOrIRI subject) {
    ArrayList<Triple> buffer = new ArrayList<Triple>();
    Lock readLock = systemGraph.getLock().readLock();
    readLock.lock();
    try {
        Iterator<Triple> permissions = systemGraph.filter(subject, PERMISSION.hasPermission, null);
        while (permissions.hasNext()) {
            Triple permissionTriple = permissions.next();
            buffer.add(permissionTriple);
            BlankNodeOrIRI permissionNode = (BlankNodeOrIRI) permissionTriple.getObject();
            Iterator<Triple> permissionTriples = systemGraph.filter(permissionNode, null, null);
            while (permissionTriples.hasNext()) {
                buffer.add(permissionTriples.next());
            }
        }
    } finally {
        readLock.unlock();
    }
    systemGraph.removeAll(buffer);
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) ArrayList(java.util.ArrayList) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) Lock(java.util.concurrent.locks.Lock)

Example 83 with BlankNodeOrIRI

use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.

the class UserResource method getUserRolesGraph.

/**
     * Provides a graph containing Role triples associated with a given user
     *
     * @param userName
     * @return roles graph
     */
private Graph getUserRolesGraph(String userName) {
    GraphNode userNode = getUser(userName);
    Iterator<RDFTerm> functionIterator = userNode.getObjects(SIOC.has_function);
    SimpleGraph rolesGraph = new SimpleGraph();
    while (functionIterator.hasNext()) {
        GraphNode functionNode = new GraphNode(functionIterator.next(), systemGraph);
        Iterator<Triple> roleIterator = systemGraph.filter((BlankNodeOrIRI) functionNode.getNode(), RDF.type, PERMISSION.Role);
        // needs lock?
        while (roleIterator.hasNext()) {
            Triple roleTriple = roleIterator.next();
            // rolesGraph.add(roleTriple);
            BlankNodeOrIRI roleNode = roleTriple.getSubject();
            SimpleGraph detailsGraph = new SimpleGraph(systemGraph.filter(roleNode, null, null));
            rolesGraph.addAll(detailsGraph);
        }
    }
    return rolesGraph;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm)

Example 84 with BlankNodeOrIRI

use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.

the class UserResource method getNamedRole.

/*
     * returns an existing user node from the graph.
     */
private GraphNode getNamedRole(String roleName) {
    GraphNode roleNode = null;
    Iterator<Triple> roleIterator = systemGraph.filter(null, RDF.type, PERMISSION.Role);
    //new PlainLiteralImpl(userName));
    if (!roleIterator.hasNext()) {
        return null;
    }
    ArrayList<Triple> tripleBuffer = new ArrayList<Triple>();
    Lock readLock = systemGraph.getLock().readLock();
    readLock.lock();
    try {
        while (roleIterator.hasNext()) {
            BlankNodeOrIRI role = roleIterator.next().getSubject();
            Iterator<Triple> roleNameTriples = systemGraph.filter(role, DC.title, null);
            while (roleNameTriples.hasNext()) {
                Literal roleLiteral = (Literal) roleNameTriples.next().getObject();
                if (roleName.equals(roleLiteral.getLexicalForm())) {
                    roleNode = new GraphNode(role, systemGraph);
                    break;
                }
            }
            if (roleNode != null) {
                break;
            }
        }
    } finally {
        readLock.unlock();
    }
    return roleNode;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) Literal(org.apache.clerezza.commons.rdf.Literal) ArrayList(java.util.ArrayList) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) Lock(java.util.concurrent.locks.Lock)

Example 85 with BlankNodeOrIRI

use of org.apache.clerezza.commons.rdf.BlankNodeOrIRI in project stanbol by apache.

the class UserResource method addUser.

/**
     * Endpoint-style user creation takes a little bunch of Turtle e.g. [] a
     * foaf:Agent ; cz:userName "Hugo Ball" .
     *
     * [has test]
     *
     * @TODO check for password
     *
     * @param userData
     * @return HTTP/1.1 204 No Content
     */
@POST
@Consumes(SupportedFormat.TURTLE)
@Path("add-user")
public Response addUser(@Context UriInfo uriInfo, ImmutableGraph inputGraph) {
    Iterator<Triple> agents = inputGraph.filter(null, null, FOAF.Agent);
    BlankNodeOrIRI userNode = agents.next().getSubject();
    Iterator<Triple> userTriples = inputGraph.filter(userNode, null, null);
    String userName = "";
    Triple userTriple = null;
    Lock writeLock = systemGraph.getLock().writeLock();
    writeLock.lock();
    try {
        GraphNode systemUserNode = new GraphNode(userNode, systemGraph);
        addRole(systemUserNode, "BasePermissionsRole");
        while (userTriples.hasNext()) {
            userTriple = userTriples.next();
            systemGraph.add(userTriple);
        }
        userName = ((Literal) userTriple.getObject()).getLexicalForm();
    } finally {
        writeLock.unlock();
    }
    UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
    URI createdResource = uriBuilder.replacePath("/user-management/users/" + userName).build();
    return Response.created(createdResource).build();
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Lock(java.util.concurrent.locks.Lock) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)89 Triple (org.apache.clerezza.commons.rdf.Triple)52 IRI (org.apache.clerezza.commons.rdf.IRI)41 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)30 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)27 HashSet (java.util.HashSet)24 Graph (org.apache.clerezza.commons.rdf.Graph)22 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)14 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)14 Literal (org.apache.clerezza.commons.rdf.Literal)13 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)12 Lock (java.util.concurrent.locks.Lock)10 BlankNode (org.apache.clerezza.commons.rdf.BlankNode)10 EnhancementEngineHelper.getString (org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper.getString)8 Test (org.junit.Test)8 Collection (java.util.Collection)7 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)7 Language (org.apache.clerezza.commons.rdf.Language)6 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)6