/** * Finds feedback in the message, processes it and removes it from the message. * * @param con * @param message * @return true if feedback was present, false otherwise */ private void processFeedbackMessage(final Connection con, final WonMessage message) { assert con != null : "connection must not be null"; assert message != null : "message must not be null"; final URI messageURI = message.getMessageURI(); RdfUtils.visit(message.getMessageContent(), new RdfUtils.ModelVisitor<Object>() { @Override public Model visit(final Model model) { Resource baseResource = model.getResource(messageURI.toString()); if (baseResource.hasProperty(WON.HAS_FEEDBACK)){ //add the base resource as a feedback event to the connection processFeedback(con, baseResource); } return null; } }); }
@Override public void process(final Exchange exchange) throws Exception { Message message = exchange.getIn(); WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER); Dataset needContent = wonMessage.getMessageContent(); URI needUri = getNeedURIFromWonMessage(needContent); if (needUri == null){ logger.warn("could not obtain needURI from message " + wonMessage.getMessageURI()); return; } Need need = needRepository.findOneByNeedURI(needUri); try { WonMessage newNeedNotificationMessage = makeNeedCreatedMessageForMatcher(need); matcherProtocolMatcherClient.needCreated(needUri, ModelFactory.createDefaultModel(), newNeedNotificationMessage); } catch (Exception e) { logger.warn("could not create NeedCreatedNotification", e); } }
private boolean hasSameContent(final WonMessage processedMessage, final WonMessage message) { Dataset messageContent = message.getMessageContent(); Dataset processedContent = processedMessage.getMessageContent(); for (String name : RdfUtils.getModelNames(processedContent)) { Model model = processedContent.getNamedModel(name); if (WonRdfUtils.SignatureUtils.isSignatureGraph(name, model) && !RdfUtils.getModelNames(messageContent).contains(name)) { processedContent.removeNamedModel(name); } } if (IsoMatcher.isomorphic(processedContent.asDatasetGraph(), messageContent.asDatasetGraph())) { return true; } return false; }
wonMessage.getMessageContent(), wonMessage.getMessageURI(), WON.HAS_MATCH_COUNTERPART).asResource().getURI()); wonMessage.getMessageContent(), wonMessage.getMessageURI(), WON.HAS_MATCH_SCORE).asLiteral().getDouble(); URI wmOriginator = wonMessage.getSenderNodeURI();
/** * Returns a property of the message (i.e. the object of the first triple ( [message-uri] [property] X ) * found in one of the content graphs of the specified message. */ private static URI getObjectOfMessageProperty(final WonMessage message, final Property property) { List<String> contentGraphUris = message.getContentGraphURIs(); Dataset contentGraphs = message.getMessageContent(); URI messageURI = message.getMessageURI(); for (String graphUri: contentGraphUris) { Model contentGraph = contentGraphs.getNamedModel(graphUri); StmtIterator smtIter = contentGraph.getResource(messageURI.toString()).listProperties(property); if (smtIter.hasNext()) { return URI.create(smtIter.nextStatement().getObject().asResource().getURI()); } } return null; }
/** * Returns a property of the corresponding remote message (i.e. the object of the first triple ( * [corresponding-remote-message-uri] [property] X ) * found in one of the content graphs of the specified message. */ private static URI getObjectOfRemoteMessageProperty(final WonMessage message, final Property property) { List<String> contentGraphUris = message.getContentGraphURIs(); Dataset contentGraphs = message.getMessageContent(); URI messageURI = message.getCorrespondingRemoteMessageURI(); if (messageURI != null) { for (String graphUri : contentGraphUris) { Model contentGraph = contentGraphs.getNamedModel(graphUri); StmtIterator smtIter = contentGraph.getResource(messageURI.toString()).listProperties(property); if (smtIter.hasNext()) { return URI.create(smtIter.nextStatement().getObject().asResource().getURI()); } } } return null; }
wonMessage.getMessageContent(), new RdfUtils.ModelVisitor<NodeIterator>()
@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)); } }
private Need storeNeed(final WonMessage wonMessage) { Dataset needContent = wonMessage.getMessageContent(); List<WonMessage.AttachmentHolder> attachmentHolders = wonMessage.getAttachments();
/** * Converts the specified hint message into a Match object. * @param wonMessage * @return a match object or null if the message is not a hint message. */ public static Match toMatch(final WonMessage wonMessage) { if (!WONMSG.TYPE_HINT.equals(wonMessage.getMessageType().getResource())){ return null; } Match match = new Match(); match.setFromNeed(wonMessage.getReceiverNeedURI()); Dataset messageContent = wonMessage.getMessageContent(); RDFNode score = findOnePropertyFromResource(messageContent, wonMessage.getMessageURI(), WON.HAS_MATCH_SCORE); if (!score.isLiteral()) return null; match.setScore(score.asLiteral().getDouble()); RDFNode counterpart = findOnePropertyFromResource(messageContent, wonMessage.getMessageURI(), WON.HAS_MATCH_COUNTERPART); if (!counterpart.isResource()) return null; match.setToNeed(URI.create(counterpart.asResource().getURI())); return match; }