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