Search in sources :

Example 1 with NodeIterator

use of org.apache.jena.rdf.model.NodeIterator in project webofneeds by researchstudio-sat.

the class TwoPhaseCommitNoVoteDeactivateAllNeedsAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    // check the global COORDINATION_MESSAGE (must be ABORT)
    if (event instanceof CloseFromOtherNeedEvent) {
        WonMessage wonMessage = ((CloseFromOtherNeedEvent) event).getWonMessage();
        NodeIterator ni = RdfUtils.visitFlattenedToNodeIterator(wonMessage.getMessageContent(), new RdfUtils.ModelVisitor<NodeIterator>() {

            @Override
            public NodeIterator visit(final Model model) {
                return model.listObjectsOfProperty(model.createProperty(WON_TX.COORDINATION_MESSAGE.getURI()));
            }
        });
        if (ni.hasNext()) {
            String coordinationMessageUri = ni.toList().get(0).asResource().getURI().toString();
            if (coordinationMessageUri.equals(WON_TX.COORDINATION_MESSAGE_ABORT.getURI().toString()))
                logger.debug("Sent COORDINATION_MESSAGE: {}", coordinationMessageUri);
            else
                logger.error("Content of the COORDINATION_MESSAGE must be: {}. Currently it is: {}", WON_TX.COORDINATION_MESSAGE_ABORT.getURI(), coordinationMessageUri);
        }
    }
    Collection<URI> toDeactivate = getEventListenerContext().getBotContext().retrieveAllNeedUris();
    for (URI uri : toDeactivate) {
        getEventListenerContext().getWonMessageSender().sendWonMessage(createWonMessage(uri));
        getEventListenerContext().getEventBus().publish(new NeedDeactivatedEvent(uri));
    }
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) CloseFromOtherNeedEvent(won.bot.framework.eventbot.event.impl.wonmessage.CloseFromOtherNeedEvent) WonMessage(won.protocol.message.WonMessage) Model(org.apache.jena.rdf.model.Model) WonRdfUtils(won.protocol.util.WonRdfUtils) RdfUtils(won.protocol.util.RdfUtils) URI(java.net.URI) NeedDeactivatedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent)

Example 2 with NodeIterator

use of org.apache.jena.rdf.model.NodeIterator in project webofneeds by researchstudio-sat.

the class LinkedDataWebController method getObjectOfPropertyAsString.

private String getObjectOfPropertyAsString(org.apache.jena.rdf.model.Model model, Property property) {
    NodeIterator nodeIteratr = model.listObjectsOfProperty(property);
    if (!nodeIteratr.hasNext())
        return null;
    String ret = nodeIteratr.next().asLiteral().getString();
    if (nodeIteratr.hasNext()) {
        throw new IncorrectPropertyCountException("found more than one property of cnt:bytes", 1, 2);
    }
    return ret;
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) IncorrectPropertyCountException(won.protocol.exception.IncorrectPropertyCountException)

Example 3 with NodeIterator

use of org.apache.jena.rdf.model.NodeIterator in project webofneeds by researchstudio-sat.

the class AgreementProtocolState method getCancellationPendingAgreementUris.

public Set<URI> getCancellationPendingAgreementUris() {
    Model cancellations = pendingProposals.getDefaultModel();
    if (cancellations == null) {
        return Collections.EMPTY_SET;
    }
    Set ret = new HashSet<URI>();
    NodeIterator it = cancellations.listObjectsOfProperty(WONAGR.PROPOSES_TO_CANCEL);
    while (it.hasNext()) {
        String uri = it.next().asResource().getURI();
        ret.add(URI.create(uri));
    }
    return ret;
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) HashSet(java.util.HashSet) Set(java.util.Set) Model(org.apache.jena.rdf.model.Model) HashSet(java.util.HashSet)

Example 4 with NodeIterator

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

the class TestListSubjectsEtc method testListObjectsNoRemove.

public void testListObjectsNoRemove() {
    final Model m = ModelHelper.modelWithStatements(this, "a P b; b Q c; c R a");
    final NodeIterator it = m.listObjects();
    it.next();
    try {
        it.remove();
        Assert.fail("listObjects should not support .remove()");
    } catch (final UnsupportedOperationException e) {
        JenaTestBase.pass();
    }
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) Model(org.apache.jena.rdf.model.Model)

Example 5 with NodeIterator

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

the class ModeSRS method search.

public void search(Model model) {
    ExtendedIterator<RDFNode> nodeIter = model.listObjectsOfProperty(Geo.HAS_SERIALIZATION_PROP);
    boolean isGeometryLiteralsFound = nodeIter.hasNext();
    if (!isGeometryLiteralsFound) {
        NodeIterator wktNodeIter = model.listObjectsOfProperty(Geo.AS_WKT_PROP);
        NodeIterator gmlNodeIter = model.listObjectsOfProperty(Geo.AS_GML_PROP);
        nodeIter = wktNodeIter.andThen(gmlNodeIter);
    }
    while (nodeIter.hasNext()) {
        RDFNode node = nodeIter.next();
        if (node.isLiteral()) {
            GeometryWrapper geometryWrapper = GeometryWrapper.extract(node.asLiteral());
            String srsURI = geometryWrapper.getSrsURI();
            // Put the SRS URI into the map.
            Integer count;
            if (srsMap.containsKey(srsURI)) {
                count = srsMap.get(srsURI);
                count++;
            } else {
                count = 1;
            }
            srsMap.put(srsURI, count);
        }
    }
    if (!isGeometryLiteralsFound) {
        // No GeometryLiterals so check for Geo predicates use.
        List<RDFNode> geoList = model.listObjectsOfProperty(SpatialExtension.GEO_LAT_PROP).toList();
        if (!geoList.isEmpty()) {
            srsMap.put(SRS_URI.WGS84_CRS, geoList.size());
        }
    }
    srsList = srsMap.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).collect(Collectors.toList());
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

NodeIterator (org.apache.jena.rdf.model.NodeIterator)16 RDFNode (org.apache.jena.rdf.model.RDFNode)8 Model (org.apache.jena.rdf.model.Model)6 Literal (org.apache.jena.rdf.model.Literal)5 Resource (org.apache.jena.rdf.model.Resource)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 RdfUtils (won.protocol.util.RdfUtils)3 HashSet (java.util.HashSet)2 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)2 Container (org.apache.jena.rdf.model.Container)2 NeedDeactivatedEvent (won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent)2 CloseFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.CloseFromOtherNeedEvent)2 IncorrectPropertyCountException (won.protocol.exception.IncorrectPropertyCountException)2 WonMessage (won.protocol.message.WonMessage)2 WonRdfUtils (won.protocol.util.WonRdfUtils)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Set (java.util.Set)1 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)1 DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)1