Search in sources :

Example 56 with Property

use of org.apache.jena.rdf.model.Property in project jena by apache.

the class SecuredModelTest method __testGetProperty_notExists.

private void __testGetProperty_notExists(Supplier<Property> supplier) {
    try {
        Property actual = supplier.get();
        Assert.assertEquals("http://example.com/graph/p3", actual.getURI());
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : ReadDeniedException(org.apache.jena.shared.ReadDeniedException) Property(org.apache.jena.rdf.model.Property)

Example 57 with Property

use of org.apache.jena.rdf.model.Property in project jena by apache.

the class TestDatasetTDB method load1.

private static void load1(Model model) {
    model.setNsPrefix("", base1);
    Resource r1 = model.createResource(base1 + "r1");
    Property p1 = model.createProperty(baseNS + "p1");
    model.add(r1, p1, "x1");
    model.add(r1, p1, "x2");
}
Also used : Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 58 with Property

use of org.apache.jena.rdf.model.Property in project jena by apache.

the class TestDatasetTDB method load3.

private static void load3(Model model) {
    Resource r3 = model.createResource(base1 + "r3");
    Property p1 = model.createProperty(baseNS + "p2");
    model.add(r3, p1, "x1");
    model.add(r3, p1, "x2");
}
Also used : Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 59 with Property

use of org.apache.jena.rdf.model.Property in project jena by apache.

the class TextQueryPF method objectToStruct.

/**
 * Deconstruct the node or list object argument and make a StrMatch
 * The 'executionTime' flag indicates whether this is for a build time
 * static check, or for runtime execution.
 */
private StrMatch objectToStruct(PropFuncArg argObject, boolean executionTime) {
    List<Resource> props = new ArrayList<>();
    if (argObject.isNode()) {
        // should be a single query string that will be searched on the text:defaultField
        Node o = argObject.getArg();
        if (!o.isLiteral()) {
            if (executionTime)
                log.warn("Object to text:query is not a literal " + argObject);
            return null;
        }
        String lang = o.getLiteralLanguage();
        RDFDatatype dt = o.getLiteralDatatype();
        if (lang.isEmpty()) {
            if (dt != null && dt != XSDDatatype.XSDstring) {
                log.warn("Object to text query is not a string");
                return null;
            }
        }
        lang = Strings.emptyToNull(lang);
        String qs = o.getLiteralLexicalForm();
        return new StrMatch(props, qs, lang, -1, 0, null);
    }
    List<Node> list = argObject.getArgList();
    if (list.size() == 0)
        throw new TextIndexException("text:query object list can not be empty");
    int idx = 0;
    Node x = list.get(idx);
    // Property?
    while (x.isURI()) {
        Property prop = ResourceFactory.createProperty(x.getURI());
        log.trace("objectToStruct: x.isURI(), prop: " + prop + " at idx: " + (idx));
        List<Resource> pList = Util.getPropList(prop);
        log.trace("objectToStruct: PROPERTY at " + idx + " IS " + prop + " WITH pList: " + pList);
        if (pList != null) {
            props.addAll(pList);
        } else {
            props.add(prop);
        }
        idx++;
        if (idx >= list.size())
            throw new TextIndexException("List of properties specified but no query string : " + list);
        if (!isIndexed(props)) {
            log.warn("objectToStruct: props are not indexed " + props);
            return null;
        }
        x = list.get(idx);
    }
    // String!
    if (!x.isLiteral()) {
        if (executionTime)
            log.warn("Text query string is not a literal " + list + " AT idx: " + idx);
        return null;
    }
    String lang = x.getLiteralLanguage();
    if (lang.isEmpty()) {
        if (x.getLiteralDatatype() != null && !x.getLiteralDatatype().equals(XSDDatatype.XSDstring)) {
            log.warn("Text query is not a string " + list);
            return null;
        }
    }
    lang = Strings.emptyToNull(lang);
    String queryString = x.getLiteralLexicalForm();
    idx++;
    int limit = -1;
    float score = 0;
    if (idx < list.size()) {
        // Limit?
        x = list.get(idx);
        idx++;
        if (!x.isLiteral()) {
            if (executionTime)
                log.warn("Text query limit is not an integer " + x);
            return null;
        }
        int v = NodeFactoryExtra.nodeToInt(x);
        limit = (v < 0) ? -1 : v;
    }
    // extract extra lang arg if present and if is usable.
    lang = lang == null ? extractArg("lang", list) : lang;
    if (lang != null && textIndex.getDocDef().getLangField() == null)
        log.warn("lang argument is ignored if langField not set in the index configuration");
    String highlight = extractArg("highlight", list);
    return new StrMatch(props, queryString, lang, limit, score, highlight);
}
Also used : Node(org.apache.jena.graph.Node) Resource(org.apache.jena.rdf.model.Resource) ArrayList(java.util.ArrayList) RDFDatatype(org.apache.jena.datatypes.RDFDatatype) Property(org.apache.jena.rdf.model.Property)

Example 60 with Property

use of org.apache.jena.rdf.model.Property in project jena by apache.

the class SecuredPropertyImpl method getInstance.

/**
 * Get an instance of SecuredProperty
 *
 * @param securedModel the Secured Model to use.
 * @param property     The property to secure
 * @return The SecuredProperty
 */
public static SecuredProperty getInstance(final SecuredModel securedModel, final Property property) {
    if (securedModel == null) {
        throw new IllegalArgumentException("SecuredModel may not be null");
    }
    if (property == null) {
        throw new IllegalArgumentException("Property may not be null");
    }
    // check that property has a securedModel.
    Property goodProp = property;
    if (goodProp.getModel() == null) {
        final Node n = property.asNode();
        if (property.isAnon()) {
            goodProp = securedModel.createProperty(n.getBlankNodeId().getLabelString());
        } else {
            goodProp = securedModel.createProperty(property.asNode().getURI());
        }
    }
    final ItemHolder<Property, SecuredProperty> holder = new ItemHolder<>(goodProp);
    final SecuredPropertyImpl checker = new SecuredPropertyImpl(securedModel, holder);
    // one.
    if (goodProp instanceof SecuredProperty) {
        if (checker.isEquivalent((SecuredProperty) goodProp)) {
            return (SecuredProperty) goodProp;
        }
    }
    return holder.setSecuredItem(new SecuredItemInvoker(property.getClass(), checker));
}
Also used : ItemHolder(org.apache.jena.permissions.impl.ItemHolder) SecuredItemInvoker(org.apache.jena.permissions.impl.SecuredItemInvoker) SecuredProperty(org.apache.jena.permissions.model.SecuredProperty) Node(org.apache.jena.graph.Node) SecuredProperty(org.apache.jena.permissions.model.SecuredProperty) Property(org.apache.jena.rdf.model.Property)

Aggregations

Property (org.apache.jena.rdf.model.Property)90 Resource (org.apache.jena.rdf.model.Resource)59 Model (org.apache.jena.rdf.model.Model)46 RDFNode (org.apache.jena.rdf.model.RDFNode)19 Test (org.junit.Test)18 Statement (org.apache.jena.rdf.model.Statement)17 ArrayList (java.util.ArrayList)14 StmtIterator (org.apache.jena.rdf.model.StmtIterator)14 Literal (org.apache.jena.rdf.model.Literal)11 Iterator (java.util.Iterator)6 Node (org.apache.jena.graph.Node)6 Triple (org.apache.jena.graph.Triple)6 QueryExecution (org.apache.jena.query.QueryExecution)6 OntModel (org.apache.jena.ontology.OntModel)5 Dataset (org.apache.jena.query.Dataset)5 Query (org.apache.jena.query.Query)4 InfModel (org.apache.jena.rdf.model.InfModel)4 Store (org.apache.jena.sdb.Store)4 IOException (java.io.IOException)3 LEGATO (legato.LEGATO)3