Search in sources :

Example 1 with WonNodeInformationService

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();
}
Also used : Dataset(org.apache.jena.query.Dataset) WonNodeInformationService(won.protocol.service.WonNodeInformationService) URI(java.net.URI)

Example 2 with WonNodeInformationService

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();
}
Also used : Dataset(org.apache.jena.query.Dataset) WonNodeInformationService(won.protocol.service.WonNodeInformationService) URI(java.net.URI)

Example 3 with WonNodeInformationService

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();
}
Also used : Dataset(org.apache.jena.query.Dataset) WonNodeInformationService(won.protocol.service.WonNodeInformationService) URI(java.net.URI)

Example 4 with WonNodeInformationService

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();
}
Also used : Dataset(org.apache.jena.query.Dataset) WonNodeInformationService(won.protocol.service.WonNodeInformationService) URI(java.net.URI)

Example 5 with WonNodeInformationService

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());
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) DefaultNeedModelWrapper(won.protocol.util.DefaultNeedModelWrapper) NeedCreationFailedEvent(won.bot.framework.eventbot.event.NeedCreationFailedEvent) Dataset(org.apache.jena.query.Dataset) NeedCreatedEventForMatcher(won.bot.framework.eventbot.event.impl.matcher.NeedCreatedEventForMatcher) WonMessage(won.protocol.message.WonMessage) WonNodeInformationService(won.protocol.service.WonNodeInformationService) NeedCreationFailedEvent(won.bot.framework.eventbot.event.NeedCreationFailedEvent) FailureResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent) Event(won.bot.framework.eventbot.event.Event) NeedCreatedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedCreatedEvent) EventListener(won.bot.framework.eventbot.listener.EventListener) URI(java.net.URI) NeedCreatedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedCreatedEvent)

Aggregations

URI (java.net.URI)35 WonNodeInformationService (won.protocol.service.WonNodeInformationService)35 Dataset (org.apache.jena.query.Dataset)28 Event (won.bot.framework.eventbot.event.Event)7 FailureResponseEvent (won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent)7 EventListener (won.bot.framework.eventbot.listener.EventListener)7 WonMessage (won.protocol.message.WonMessage)7 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)6 DefaultNeedModelWrapper (won.protocol.util.DefaultNeedModelWrapper)4 NeedCreationFailedEvent (won.bot.framework.eventbot.event.NeedCreationFailedEvent)3 NeedCreatedEvent (won.bot.framework.eventbot.event.impl.needlifecycle.NeedCreatedEvent)3 Resource (org.apache.jena.rdf.model.Resource)2 WonURI (won.bot.framework.eventbot.action.impl.mail.model.WonURI)2 EventBus (won.bot.framework.eventbot.bus.EventBus)2 NeedCreatedEventForMatcher (won.bot.framework.eventbot.event.impl.matcher.NeedCreatedEventForMatcher)2 NeedContentPropertyType (won.protocol.model.NeedContentPropertyType)2 NeedModelWrapper (won.protocol.util.NeedModelWrapper)2 InvalidParameterException (java.security.InvalidParameterException)1 MessagingException (javax.mail.MessagingException)1 MimeMessage (javax.mail.internet.MimeMessage)1