/** * 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; }
@Override public WonMessage process(final WonMessage message) throws WonMessageProcessingException { try { if (message.getMessageType() == WonMessageType.CREATE_NEED) { String needUri = message.getSenderNeedURI().toString(); Dataset msgDataset = WonMessageEncoder.encodeAsDataset(message); // generate and add need's public key to the need content String alias = keyPairAliasDerivationStrategy.getAliasForNeedUri(needUri); if (cryptographyService.getPrivateKey(alias) == null) { cryptographyService.createNewKeyPair(alias, alias); } PublicKey pubKey = cryptographyService.getPublicKey(alias); WonKeysReaderWriter keyWriter = new WonKeysReaderWriter(); String contentName = message.getContentGraphURIs().get(0); Model contentModel = msgDataset.getNamedModel(contentName); keyWriter.writeToModel(contentModel, contentModel.createResource(needUri), pubKey); return new WonMessage(msgDataset); } } catch (Exception e) { logger.error("Failed to add key", e); throw new WonMessageProcessingException("Failed to add key for need in message " + message.getMessageURI().toString()); } return message; }
if (wrappedMessage == null) return true; if (wrappedMessage.getEnvelopeGraphURIs().contains(graphUri)) return false; if (wrappedMessage.getContentGraphURIs().contains(graphUri)) return false; return true; }).toString();
equalsOrBothNull(processedMessage.getIsResponseToMessageURI(), message.getIsResponseToMessageURI()) && processedMessage.getContentGraphURIs().containsAll(message.getContentGraphURIs()) && equalsOrBothNull(processedMessage.getMessageType(), message.getMessageType())