Search in sources :

Example 76 with BlankNodeOrIRI

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

the class ClerezzaTripleCallback method triple.

private void triple(String s, String p, String value, String datatype, String language, String graph) {
    final BlankNodeOrIRI subject = getBlankNodeOrIRI(s);
    final IRI predicate = new IRI(p);
    RDFTerm object;
    if (language != null) {
        object = new PlainLiteralImpl(value, new Language(language));
    } else if (datatype == null || RDF_LANG_STRING.equals(datatype)) {
        object = new PlainLiteralImpl(value);
    } else {
        object = new TypedLiteralImpl(value, new IRI(datatype));
    }
    mGraph.add(new TripleImpl(subject, predicate, object));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) Language(org.apache.clerezza.commons.rdf.Language) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) TypedLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.TypedLiteralImpl) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)

Example 77 with BlankNodeOrIRI

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

the class ClerezzaRDFParser method handleStatement.

private void handleStatement(RDFDataset result, Triple t, Map<BlankNode, String> bNodeMap) {
    final String subject = getResourceValue(t.getSubject(), bNodeMap);
    final String predicate = getResourceValue(t.getPredicate(), bNodeMap);
    final RDFTerm object = t.getObject();
    if (object instanceof Literal) {
        final String value = ((Literal) object).getLexicalForm();
        final String language;
        final String datatype;
        datatype = getResourceValue(((Literal) object).getDataType(), bNodeMap);
        Language l = ((Literal) object).getLanguage();
        if (l == null) {
            language = null;
        } else {
            language = l.toString();
        }
        result.addTriple(subject, predicate, value, datatype, language);
        count++;
    } else {
        result.addTriple(subject, predicate, getResourceValue((BlankNodeOrIRI) object, bNodeMap));
        count++;
    }
}
Also used : Language(org.apache.clerezza.commons.rdf.Language) Literal(org.apache.clerezza.commons.rdf.Literal) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm)

Example 78 with BlankNodeOrIRI

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

the class UserResource method storeRole.

private Response storeRole(GraphNode roleNode, UriInfo uriInfo, String roleName, String comment, List<String> permissions) {
    BlankNodeOrIRI roleResource = (BlankNodeOrIRI) roleNode.getNode();
    if (permissions != null) {
        clearPermissions(roleResource);
        Lock writeLock = systemGraph.getLock().writeLock();
        writeLock.lock();
        try {
            for (int i = 0; i < permissions.size(); i++) {
                permissions.set(i, permissions.get(i).trim());
                if (!permissions.get(i).equals("")) {
                    addPermission(roleNode, permissions.get(i));
                }
            }
        } finally {
            writeLock.unlock();
        }
    }
    //refresh the policy so it will recheck the permissions
    Policy.getPolicy().refresh();
    // showSystem();
    URI pageUri = uriInfo.getBaseUriBuilder().path("system/console/usermanagement").build();
    // header Cache-control: no-cache, just in case intermediaries are
    // holding onto old stuff
    CacheControl cc = new CacheControl();
    cc.setNoCache(true);
    // the jax-rs things available
    return Response.seeOther(pageUri).cacheControl(cc).build();
}
Also used : BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) CacheControl(javax.ws.rs.core.CacheControl) URI(java.net.URI) Lock(java.util.concurrent.locks.Lock)

Example 79 with BlankNodeOrIRI

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

the class UserAwarePolicy method getAllPermissionsOfAUserByName.

/**
	 * Returns the string representations of all permissions of a user. Those
	 * are his/her own permissions and the permissions of his roles
	 * 
	 */
private List<String> getAllPermissionsOfAUserByName(String userName) throws UserUnregisteredException {
    BlankNodeOrIRI user = getUserByName(userName);
    List<String> result = getPermissionEntriesOfAUser(user, userName);
    Iterator<Triple> roleTriples = systemGraph.filter(user, SIOC.has_function, null);
    while (roleTriples.hasNext()) {
        BlankNodeOrIRI anotherRole = (BlankNodeOrIRI) roleTriples.next().getObject();
        result.addAll(getPermissionEntriesOfARole(anotherRole, userName, user));
    }
    Iterator<BlankNodeOrIRI> baseRoles = getResourcesOfType(PERMISSION.BaseRole);
    while (baseRoles.hasNext()) {
        result.addAll(getPermissionEntriesOfARole(baseRoles.next(), userName, user));
    }
    return result;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI)

Example 80 with BlankNodeOrIRI

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

the class JenaToClerezzaConverterTest method setupClass.

@BeforeClass
public static void setupClass() {
    /*
		 * Set-up the Jena model for the test.
		 * Simply add the triples:
		 * 	AndreaNuzzolese isA Person
		 * 	EnricoDaga isA Person
		 *  AndreaNuzzolese knows EnricoDaga
		 */
    model = ModelFactory.createDefaultModel();
    Resource foafPersonInJena = model.createResource(foaf + "Person");
    Property knowsInJena = model.createProperty(foaf + "knows");
    Resource andreaNuzzoleseInJena = model.createResource(ns + "AndreaNuzzolese", foafPersonInJena);
    Resource enricoDagaInJena = model.createResource(ns + "EnricoDaga", foafPersonInJena);
    andreaNuzzoleseInJena.addProperty(knowsInJena, enricoDagaInJena);
    /*
		 * 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) Resource(com.hp.hpl.jena.rdf.model.Resource) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) Property(com.hp.hpl.jena.rdf.model.Property) BeforeClass(org.junit.BeforeClass)

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