use of org.apache.jena.rdf.model.NodeIterator in project webofneeds by researchstudio-sat.
the class RdfDatasetAttachmentConverter method getObjectOfPropertyAsString.
private String getObjectOfPropertyAsString(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 LinkedDataSourceBase method getURIsToCrawl.
/**
* For the specified properties, finds their objects and adds the identified
* resources to the returned set if they are not contained in the specified
* exclude set.
*
* @param dataset
* @param excludedUris
* @param properties
* @return
*/
private Set<URI> getURIsToCrawl(Dataset dataset, Set<URI> excludedUris, final List<URI> properties) {
Set<URI> toCrawl = new HashSet<>();
for (int i = 0; i < properties.size(); i++) {
final URI property = properties.get(i);
NodeIterator objectIterator = RdfUtils.visitFlattenedToNodeIterator(dataset, new RdfUtils.ModelVisitor<NodeIterator>() {
@Override
public NodeIterator visit(final Model model) {
final Property p = model.createProperty(property.toString());
return model.listObjectsOfProperty(p);
}
});
for (; objectIterator.hasNext(); ) {
RDFNode objectNode = objectIterator.next();
if (objectNode.isURIResource()) {
URI discoveredUri = URI.create(objectNode.asResource().getURI());
if (!excludedUris.contains(discoveredUri)) {
toCrawl.add(discoveredUri);
}
}
}
}
return toCrawl;
}
use of org.apache.jena.rdf.model.NodeIterator in project webofneeds by researchstudio-sat.
the class TwoPhaseCommitDeactivateOnCloseAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
// If we receive a close event, it must carry a commit message.
if (event instanceof CloseFromOtherNeedEvent) {
URI needURI = ((CloseFromOtherNeedEvent) event).getNeedURI();
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()));
}
});
assert ni.hasNext() : "no additional content found in close message, expected a commit";
String coordinationMessageUri = ni.toList().get(0).asResource().getURI().toString();
assert coordinationMessageUri.equals(WON_TX.COORDINATION_MESSAGE_COMMIT.getURI().toString()) : "expected a " + "Commmit message";
getEventListenerContext().getWonMessageSender().sendWonMessage(createWonMessage(needURI));
getEventListenerContext().getEventBus().publish(new NeedDeactivatedEvent(needURI));
}
}
use of org.apache.jena.rdf.model.NodeIterator in project webofneeds by researchstudio-sat.
the class AgreementProtocolState method acceptProposal.
/**
* @param proposalUri
* @return true if the operation had any effect, false otherwise
*/
private boolean acceptProposal(URI proposalUri) {
boolean changedSomething = false;
// first process proposeToCancel triples - this avoids that a message can
// successfully propose to cancel itself, as agreements are only made after the
// cancellations are processed.
Model cancellationProposals = pendingProposals.getDefaultModel();
NodeIterator nIt = cancellationProposals.listObjectsOfProperty(cancellationProposals.getResource(proposalUri.toString()), WONAGR.PROPOSES_TO_CANCEL);
if (nIt.hasNext()) {
// remember that this proposal contained a cancellation
this.acceptedCancellationProposalUris.add(proposalUri);
changedSomething = true;
}
while (nIt.hasNext()) {
RDFNode agreementToCancelUri = nIt.next();
changedSomething = cancelAgreement(URI.create(agreementToCancelUri.asResource().getURI())) || changedSomething;
}
changedSomething = removeCancellationProposal(proposalUri) || changedSomething;
// move proposal to agreements
changedSomething = moveNamedGraph(proposalUri, pendingProposals, agreements) || changedSomething;
return changedSomething;
}
use of org.apache.jena.rdf.model.NodeIterator in project jena by apache.
the class SecurityEvaluatorAssembler method open.
// initialization and registration is performed by SecuredAssembler
@Override
public SecurityEvaluator open(Assembler a, Resource root, Mode mode) {
Literal className = getUniqueLiteral(root, EVALUATOR_CLASS);
if (className == null) {
throw new AssemblerException(root, String.format(NO_X_PROVIDED, EVALUATOR_CLASS, root));
}
Class<?> clazz;
try {
clazz = Class.forName(className.getString());
} catch (ClassNotFoundException e1) {
throw new AssemblerException(root, String.format("Can not locate class %s as specified by %s in %s", className, EVALUATOR_CLASS, root));
}
if (!SecurityEvaluator.class.isAssignableFrom(clazz)) {
throw new AssemblerException(root, String.format("Class %s as specified by %s in %s does not implement SecurityEvaluator", className, EVALUATOR_CLASS, root));
}
// get the arguments as specified.
List<Object> args = new ArrayList<>();
Resource argRes = getUniqueResource(root, ARGUMENT_LIST);
if (argRes != null) {
Seq seq = argRes.as(Seq.class);
NodeIterator iter = seq.iterator();
RDFNode n = null;
while (iter.hasNext()) {
n = iter.next();
if (n.isLiteral()) {
args.add(n.asLiteral().getValue());
} else if (n.isResource()) {
args.add(a.open(a, n.asResource(), mode));
} else {
throw new AssemblerException(root, String.format("%s must be a literal or a resource", n));
}
}
}
for (Constructor<?> c : clazz.getConstructors()) {
if (c.getParameterTypes().length == args.size()) {
try {
if (args.size() == 0) {
return (SecurityEvaluator) c.newInstance();
}
return (SecurityEvaluator) c.newInstance(args.toArray());
} catch (InstantiationException e) {
throw new AssemblerException(root, e.getMessage(), e);
} catch (IllegalAccessException e) {
throw new AssemblerException(root, e.getMessage(), e);
} catch (IllegalArgumentException e) {
throw new AssemblerException(root, e.getMessage(), e);
} catch (InvocationTargetException e) {
throw new AssemblerException(root, e.getMessage(), e);
}
}
}
throw new AssemblerException(root, String.format("Class %s does not have a %s argument constructor", className, args.size()));
}
Aggregations