use of won.protocol.service.WonNodeInformationService in project webofneeds by researchstudio-sat.
the class BotActionUtils method createWonMessage.
public static WonMessage createWonMessage(final EventListenerContext context, final URI connectionURI, final String message) throws WonMessageBuilderException {
WonNodeInformationService wonNodeInformationService = context.getWonNodeInformationService();
Dataset connectionRDF = context.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 = context.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 TwoPhaseCommitDeactivateOnCloseAction method createWonMessage.
private WonMessage createWonMessage(URI needURI) throws WonMessageBuilderException {
WonNodeInformationService wonNodeInformationService = getEventListenerContext().getWonNodeInformationService();
Dataset ds = getEventListenerContext().getLinkedDataSource().getDataForResource(needURI);
URI localWonNode = WonRdfUtils.NeedUtils.getWonNodeURIFromNeed(ds, needURI);
return WonMessageBuilder.setMessagePropertiesForDeactivateFromOwner(wonNodeInformationService.generateEventURI(localWonNode), needURI, localWonNode).build();
}
use of won.protocol.service.WonNodeInformationService in project webofneeds by researchstudio-sat.
the class OpenConnectionDebugAction method createCloseWonMessage.
private WonMessage createCloseWonMessage(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.setMessagePropertiesForClose(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 SendNDebugMessagesAction 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 CreateEchoNeedWithFacetsAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
String replyText = "";
if (!(event instanceof NeedCreatedEventForMatcher)) {
logger.error("CreateEchoNeedWithFacetsAction can only handle NeedCreatedEventForMatcher");
return;
}
final URI reactingToNeedUri = ((NeedCreatedEventForMatcher) event).getNeedURI();
final Dataset needDataset = ((NeedCreatedEventForMatcher) event).getNeedData();
DefaultNeedModelWrapper needModelWrapper = new DefaultNeedModelWrapper(needDataset);
String titleString = needModelWrapper.getSomeTitleFromIsOrAll("en", "de");
if (titleString != null) {
replyText = titleString;
} else {
replyText = "Your Posting (" + reactingToNeedUri.toString() + ")";
}
WonNodeInformationService wonNodeInformationService = ctx.getWonNodeInformationService();
final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
final URI needURI = wonNodeInformationService.generateNeedURI(wonNodeUri);
needModelWrapper = new DefaultNeedModelWrapper(needURI.toString());
needModelWrapper.createContentNode(NeedContentPropertyType.IS_AND_SEEKS, needURI.toString());
needModelWrapper.setTitle(NeedContentPropertyType.IS_AND_SEEKS, "RE: " + replyText);
needModelWrapper.setDescription(NeedContentPropertyType.IS_AND_SEEKS, "This is a need automatically created by the EchoBot.");
for (URI facetUri : facets) {
needModelWrapper.addFacetUri(facetUri.toString());
}
final Dataset echoNeedDataset = needModelWrapper.copyDataset();
logger.debug("creating need on won node {} with content {} ", wonNodeUri, StringUtils.abbreviate(RdfUtils.toString(echoNeedDataset), 150));
WonMessage createNeedMessage = createWonMessage(wonNodeInformationService, needURI, wonNodeUri, echoNeedDataset);
// 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);
// save the mapping between the original and the reaction in to the context.
getEventListenerContext().getBotContextWrapper().addUriAssociation(reactingToNeedUri, needURI);
ctx.getEventBus().publish(new NeedCreatedEvent(needURI, wonNodeUri, echoNeedDataset, null));
}
};
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));
}
};
EventBotActionUtils.makeAndSubscribeResponseListener(createNeedMessage, successCallback, failureCallback, ctx);
logger.debug("registered listeners for response to message URI {}", createNeedMessage.getMessageURI());
getEventListenerContext().getWonMessageSender().sendWonMessage(createNeedMessage);
logger.debug("need creation message sent with message URI {}", createNeedMessage.getMessageURI());
}
Aggregations