use of won.protocol.service.WonNodeInformationService in project webofneeds by researchstudio-sat.
the class AutomaticMonitoredMessageResponderListener method createWonMessage.
private WonMessage createWonMessage(URI connectionURI, String message) throws WonMessageBuilderException {
WonNodeInformationService wonNodeInformationService = getEventListenerContext().getWonNodeInformationService();
Dataset connectionRDF = getEventListenerContext().getLinkedDataSource().getDataForResource(connectionURI);
URI remoteNeed = WonRdfUtils.ConnectionUtils.getRemoteNeedURIFromConnection(connectionRDF, connectionURI);
URI localNeed = WonRdfUtils.ConnectionUtils.getLocalNeedURIFromConnection(connectionRDF, connectionURI);
URI wonNode = WonRdfUtils.ConnectionUtils.getWonNodeURIFromConnection(connectionRDF, connectionURI);
Dataset remoteNeedRDF = getEventListenerContext().getLinkedDataSource().getDataForResource(remoteNeed);
URI messageURI = wonNodeInformationService.generateEventURI(wonNode);
return WonMessageBuilder.setMessagePropertiesForConnectionMessage(messageURI, connectionURI, localNeed, wonNode, WonRdfUtils.ConnectionUtils.getRemoteConnectionURIFromConnection(connectionRDF, connectionURI), remoteNeed, WonRdfUtils.NeedUtils.getWonNodeURIFromNeed(remoteNeedRDF, remoteNeed), message).build();
}
use of won.protocol.service.WonNodeInformationService in project webofneeds by researchstudio-sat.
the class LastSeenNeedsMatcherBot method createWonMessage.
private WonMessage createWonMessage(URI needURI, URI otherNeedURI, double score, URI originator) throws WonMessageBuilderException {
WonNodeInformationService wonNodeInformationService = getEventListenerContext().getWonNodeInformationService();
URI localWonNode = WonRdfUtils.NeedUtils.getWonNodeURIFromNeed(getEventListenerContext().getLinkedDataSource().getDataForResource(needURI), needURI);
return WonMessageBuilder.setMessagePropertiesForHint(wonNodeInformationService.generateEventURI(localWonNode), needURI, FacetType.OwnerFacet.getURI(), localWonNode, otherNeedURI, FacetType.OwnerFacet.getURI(), originator, score).build();
}
use of won.protocol.service.WonNodeInformationService in project webofneeds by researchstudio-sat.
the class OpenConnectionDebugAction method createOpenWonMessage.
private WonMessage createOpenWonMessage(URI connectionURI, String message) throws WonMessageBuilderException {
WonNodeInformationService wonNodeInformationService = getEventListenerContext().getWonNodeInformationService();
Dataset connectionRDF = getEventListenerContext().getLinkedDataSource().getDataForResource(connectionURI);
URI remoteNeed = WonRdfUtils.ConnectionUtils.getRemoteNeedURIFromConnection(connectionRDF, connectionURI);
URI localNeed = WonRdfUtils.ConnectionUtils.getLocalNeedURIFromConnection(connectionRDF, connectionURI);
URI wonNode = WonRdfUtils.ConnectionUtils.getWonNodeURIFromConnection(connectionRDF, connectionURI);
Dataset remoteNeedRDF = getEventListenerContext().getLinkedDataSource().getDataForResource(remoteNeed);
return WonMessageBuilder.setMessagePropertiesForOpen(wonNodeInformationService.generateEventURI(wonNode), connectionURI, localNeed, wonNode, WonRdfUtils.ConnectionUtils.getRemoteConnectionURIFromConnection(connectionRDF, connectionURI), remoteNeed, WonRdfUtils.NeedUtils.getWonNodeURIFromNeed(remoteNeedRDF, remoteNeed), message).build();
}
use of won.protocol.service.WonNodeInformationService in project webofneeds by researchstudio-sat.
the class CreateNeedFromMailAction method doRun.
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof CreateNeedFromMailEvent && ctx.getBotContextWrapper() instanceof MailBotContextWrapper) {
MailBotContextWrapper botContextWrapper = (MailBotContextWrapper) ctx.getBotContextWrapper();
MimeMessage message = ((CreateNeedFromMailEvent) event).getMessage();
try {
NeedContentPropertyType type = mailContentExtractor.getNeedType(message);
String title = mailContentExtractor.getTitle(message);
String description = mailContentExtractor.getDescription(message);
String[] tags = mailContentExtractor.getTags(message);
boolean isUsedForTesting = mailContentExtractor.isUsedForTesting(message);
boolean isDoNotMatch = mailContentExtractor.isDoNotMatch(message);
WonNodeInformationService wonNodeInformationService = ctx.getWonNodeInformationService();
final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
final URI needURI = wonNodeInformationService.generateNeedURI(wonNodeUri);
DefaultNeedModelWrapper needModelWrapper = new DefaultNeedModelWrapper(needURI.toString());
needModelWrapper.setTitle(type, title);
needModelWrapper.setDescription(type, description);
for (String tag : tags) {
needModelWrapper.addTag(type, tag);
}
for (URI facet : facets) {
needModelWrapper.addFacetUri(facet.toString());
}
Dataset dataset = needModelWrapper.copyDataset();
logger.debug("creating need on won node {} with content {} ", wonNodeUri, StringUtils.abbreviate(RdfUtils.toString(dataset), 150));
WonMessage createNeedMessage = createWonMessage(wonNodeInformationService, needURI, wonNodeUri, dataset, isUsedForTesting, isDoNotMatch);
EventBotActionUtils.rememberInList(ctx, needURI, uriListName);
botContextWrapper.addUriMimeMessageRelation(needURI, message);
EventListener successCallback = new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
logger.debug("need creation successful, new need URI is {}", needURI);
String sender = MailContentExtractor.getFromAddressString(botContextWrapper.getMimeMessageForURI(needURI));
botContextWrapper.addMailAddressWonURIRelation(sender, new WonURI(needURI, UriType.NEED));
logger.debug("created need was from sender: " + sender);
}
};
EventListener failureCallback = new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
String textMessage = WonRdfUtils.MessageUtils.getTextMessage(((FailureResponseEvent) event).getFailureMessage());
logger.debug("need creation failed for need URI {}, original message URI {}: {}", new Object[] { needURI, ((FailureResponseEvent) event).getOriginalMessageURI(), textMessage });
EventBotActionUtils.removeFromList(ctx, needURI, uriListName);
botContextWrapper.removeUriMimeMessageRelation(needURI);
}
};
EventBotActionUtils.makeAndSubscribeResponseListener(createNeedMessage, successCallback, failureCallback, ctx);
logger.debug("registered listeners for response to message URI {}", createNeedMessage.getMessageURI());
ctx.getWonMessageSender().sendWonMessage(createNeedMessage);
logger.debug("need creation message sent with message URI {}", createNeedMessage.getMessageURI());
} catch (MessagingException me) {
logger.error("messaging exception occurred: {}", me);
}
}
}
use of won.protocol.service.WonNodeInformationService in project webofneeds by researchstudio-sat.
the class CreateNeedWithFacetsAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (ctx.getNeedProducer().isExhausted()) {
logger.info("the bot's need producer is exhausted.");
ctx.getEventBus().publish(new NeedProducerExhaustedEvent());
return;
}
final Dataset needDataset = ctx.getNeedProducer().create();
if (needDataset == null) {
logger.warn("needproducer failed to produce a need model, aborting need creation");
return;
}
URI needUriFromProducer = null;
Resource needResource = WonRdfUtils.NeedUtils.getNeedResource(needDataset);
if (needResource.isURIResource()) {
needUriFromProducer = URI.create(needResource.getURI().toString());
RdfUtils.replaceBaseURI(needDataset, needResource.getURI());
} else {
RdfUtils.replaceBaseResource(needDataset, needResource);
}
final URI needUriBeforeCreation = needUriFromProducer;
NeedModelWrapper needModelWrapper = new NeedModelWrapper(needDataset);
for (URI facetURI : facets) {
WonRdfUtils.FacetUtils.addFacet(needModelWrapper.getNeedModel(), facetURI);
}
final Dataset needDatasetWithFacets = needModelWrapper.copyDataset();
final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
logger.debug("creating need on won node {} with content {} ", wonNodeUri, StringUtils.abbreviate(RdfUtils.toString(needDatasetWithFacets), 150));
WonNodeInformationService wonNodeInformationService = ctx.getWonNodeInformationService();
final URI needURI = wonNodeInformationService.generateNeedURI(wonNodeUri);
WonMessage createNeedMessage = createWonMessage(wonNodeInformationService, needURI, wonNodeUri, needDatasetWithFacets);
// remember the need URI so we can react to success/failure responses
EventBotActionUtils.rememberInList(ctx, needURI, uriListName);
EventListener successCallback = new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
logger.debug("need creation successful, new need URI is {}", needURI);
ctx.getEventBus().publish(new NeedCreatedEvent(needURI, wonNodeUri, needDatasetWithFacets, null, needUriBeforeCreation));
}
};
EventListener failureCallback = new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
String textMessage = WonRdfUtils.MessageUtils.getTextMessage(((FailureResponseEvent) event).getFailureMessage());
logger.debug("need creation failed for need URI {}, original message URI {}: {}", new Object[] { needURI, ((FailureResponseEvent) event).getOriginalMessageURI(), textMessage });
EventBotActionUtils.removeFromList(ctx, needURI, uriListName);
ctx.getEventBus().publish(new NeedCreationFailedEvent(wonNodeUri, needUriBeforeCreation));
}
};
EventBotActionUtils.makeAndSubscribeResponseListener(createNeedMessage, successCallback, failureCallback, ctx);
logger.debug("registered listeners for response to message URI {}", createNeedMessage.getMessageURI());
ctx.getWonMessageSender().sendWonMessage(createNeedMessage);
logger.debug("need creation message sent with message URI {}", createNeedMessage.getMessageURI());
}
Aggregations