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()));
}
}
}
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");
}
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");
}
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);
}
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));
}
Aggregations