Search in sources :

Example 56 with RDFNode

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

the class GeoSPARQLOperations method convertSRSDatatype.

private static Model convertSRSDatatype(Model inputModel, String outputSrsURI, GeometryDatatype outputDatatype) {
    if (outputSrsURI == null) {
        outputSrsURI = GeoSPARQLOperations.findModeSRS(inputModel);
    }
    if (outputDatatype == null || !GeometryDatatype.check(outputDatatype)) {
        LOGGER.warn("Output datatype {} is not a recognised for Geometry Literal. Defaulting to {}.", outputDatatype, WKTDatatype.URI);
        outputDatatype = WKTDatatype.INSTANCE;
    }
    // Iterate through all statements: toNodeValue geometry literals and just add the rest.
    Model outputModel = ModelFactory.createDefaultModel();
    outputModel.setNsPrefixes(inputModel.getNsPrefixMap());
    Iterator<Statement> statementIt = inputModel.listStatements();
    while (statementIt.hasNext()) {
        Statement statement = statementIt.next();
        RDFNode object = statement.getObject();
        if (object.isLiteral()) {
            handleLiteral(statement, outputModel, outputSrsURI, outputDatatype);
        } else {
            // Not a statement of interest so store for output.
            outputModel.add(statement);
        }
    }
    return outputModel;
}
Also used : Statement(org.apache.jena.rdf.model.Statement) InfModel(org.apache.jena.rdf.model.InfModel) Model(org.apache.jena.rdf.model.Model) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 57 with RDFNode

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

the class SpatialIndex method getGeometryLiteralIndexItems.

/**
 * @param model
 * @param srsURI
 * @return GeometryLiteral items prepared for adding to SpatialIndex.
 * @throws SpatialIndexException
 */
private static Collection<SpatialIndexItem> getGeometryLiteralIndexItems(Model model, String srsURI) throws SpatialIndexException {
    List<SpatialIndexItem> items = new ArrayList<>();
    StmtIterator stmtIt = model.listStatements(null, Geo.HAS_GEOMETRY_PROP, (Resource) null);
    while (stmtIt.hasNext()) {
        Statement stmt = stmtIt.nextStatement();
        Resource feature = stmt.getSubject();
        Resource geometry = stmt.getResource();
        ExtendedIterator<RDFNode> nodeIter = model.listObjectsOfProperty(geometry, Geo.HAS_SERIALIZATION_PROP);
        if (!nodeIter.hasNext()) {
            NodeIterator wktNodeIter = model.listObjectsOfProperty(geometry, Geo.AS_WKT_PROP);
            NodeIterator gmlNodeIter = model.listObjectsOfProperty(geometry, Geo.AS_GML_PROP);
            nodeIter = wktNodeIter.andThen(gmlNodeIter);
        }
        while (nodeIter.hasNext()) {
            Literal geometryLiteral = nodeIter.next().asLiteral();
            GeometryWrapper geometryWrapper = GeometryWrapper.extract(geometryLiteral);
            try {
                // Ensure all entries in the target SRS URI.
                GeometryWrapper transformedGeometryWrapper = geometryWrapper.convertSRS(srsURI);
                Envelope envelope = transformedGeometryWrapper.getEnvelope();
                SpatialIndexItem item = new SpatialIndexItem(envelope, feature);
                items.add(item);
            } catch (FactoryException | MismatchedDimensionException | TransformException ex) {
                throw new SpatialIndexException("Transformation Exception: " + geometryLiteral + ". " + ex.getMessage());
            }
        }
    }
    return items;
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) StmtIterator(org.apache.jena.rdf.model.StmtIterator) FactoryException(org.opengis.util.FactoryException) Statement(org.apache.jena.rdf.model.Statement) ArrayList(java.util.ArrayList) Resource(org.apache.jena.rdf.model.Resource) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) TransformException(org.opengis.referencing.operation.TransformException) Envelope(org.locationtech.jts.geom.Envelope) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) Literal(org.apache.jena.rdf.model.Literal) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 58 with RDFNode

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

the class SecurityExample method main.

/**
 * @param args
 */
public static void main(String[] args) {
    String[] names = { "alice", "bob", "chuck", "darla" };
    RDFNode msgType = ResourceFactory.createResource("http://example.com/msg");
    Property pTo = ResourceFactory.createProperty("http://example.com/to");
    Property pFrom = ResourceFactory.createProperty("http://example.com/from");
    Property pSubj = ResourceFactory.createProperty("http://example.com/subj");
    Model model = ModelFactory.createDefaultModel();
    URL url = SecurityExample.class.getClassLoader().getResource("org/apache/jena/security/example/example.ttl");
    model.read(url.toExternalForm());
    ResIterator ri = model.listSubjectsWithProperty(RDF.type, msgType);
    System.out.println("All the messages");
    while (ri.hasNext()) {
        Resource msg = ri.next();
        Statement to = msg.getProperty(pTo);
        Statement from = msg.getProperty(pFrom);
        Statement subj = msg.getProperty(pSubj);
        System.out.println(String.format("%s to: %s  from: %s  subj: %s", msg, to.getObject(), from.getObject(), subj.getObject()));
    }
    System.out.println();
    ExampleEvaluator evaluator = new ExampleEvaluator(model);
    model = Factory.getInstance(evaluator, "http://example.com/SecuredModel", model);
    for (String userName : names) {
        evaluator.setPrincipal(userName);
        System.out.println("Messages " + userName + " can manipulate");
        ri = model.listSubjectsWithProperty(RDF.type, msgType);
        while (ri.hasNext()) {
            Resource msg = ri.next();
            Statement to = msg.getProperty(pTo);
            Statement from = msg.getProperty(pFrom);
            Statement subj = msg.getProperty(pSubj);
            System.out.println(String.format("%s to: %s  from: %s  subj: %s", msg, to.getObject(), from.getObject(), subj.getObject()));
        }
        ri.close();
        for (String name : names) {
            System.out.println(String.format("%s messages to %s", model.listSubjectsWithProperty(pTo, name).toList().size(), name));
        }
        System.out.println();
    }
}
Also used : ResIterator(org.apache.jena.rdf.model.ResIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode) URL(java.net.URL)

Example 59 with RDFNode

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

the class SecuredModelTest method testRDFNodeInModel.

@Test
public void testRDFNodeInModel() {
    // test uri
    final RDFNode rdfNode = ResourceFactory.createResource("http://exmple.com/testInModel");
    final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
    Assert.assertEquals("Should have placed RDFNode in secured securedModel", securedModel, rdfNode2.getModel());
}
Also used : RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test) SecuredPrefixMappingTest(org.apache.jena.permissions.graph.SecuredPrefixMappingTest)

Example 60 with RDFNode

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

the class SecuredModelTest method testAnonymousInModel.

@Test
public void testAnonymousInModel() {
    // test anonymous
    final RDFNode rdfNode = ResourceFactory.createResource();
    final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
    Assert.assertEquals("Should have placed RDFNode in secured securedModel", securedModel, rdfNode2.getModel());
}
Also used : RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test) SecuredPrefixMappingTest(org.apache.jena.permissions.graph.SecuredPrefixMappingTest)

Aggregations

RDFNode (org.apache.jena.rdf.model.RDFNode)145 Resource (org.apache.jena.rdf.model.Resource)51 Model (org.apache.jena.rdf.model.Model)30 Statement (org.apache.jena.rdf.model.Statement)27 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)22 Node (org.apache.jena.graph.Node)20 QuerySolution (org.apache.jena.query.QuerySolution)20 TextIndexException (org.apache.jena.query.text.TextIndexException)17 Property (org.apache.jena.rdf.model.Property)17 Literal (org.apache.jena.rdf.model.Literal)15 SecuredRDFNode (org.apache.jena.permissions.model.SecuredRDFNode)13 Dataset (org.apache.jena.query.Dataset)13 Triple (org.apache.jena.graph.Triple)12 QueryExecution (org.apache.jena.query.QueryExecution)10 StmtIterator (org.apache.jena.rdf.model.StmtIterator)9 Query (org.apache.jena.query.Query)8 NodeIterator (org.apache.jena.rdf.model.NodeIterator)8 RDFList (org.apache.jena.rdf.model.RDFList)8 AccessDeniedException (org.apache.jena.shared.AccessDeniedException)7