Search in sources :

Example 16 with WonNodeInformationService

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

Example 17 with WonNodeInformationService

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

Example 18 with WonNodeInformationService

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

Example 19 with WonNodeInformationService

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);
        }
    }
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) DefaultNeedModelWrapper(won.protocol.util.DefaultNeedModelWrapper) MailBotContextWrapper(won.bot.framework.bot.context.MailBotContextWrapper) MessagingException(javax.mail.MessagingException) Dataset(org.apache.jena.query.Dataset) WonNodeInformationService(won.protocol.service.WonNodeInformationService) NeedContentPropertyType(won.protocol.model.NeedContentPropertyType) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) URI(java.net.URI) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) MimeMessage(javax.mail.internet.MimeMessage) WonMessage(won.protocol.message.WonMessage) CreateNeedFromMailEvent(won.bot.framework.eventbot.event.impl.mail.CreateNeedFromMailEvent) FailureResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent) Event(won.bot.framework.eventbot.event.Event) EventListener(won.bot.framework.eventbot.listener.EventListener) CreateNeedFromMailEvent(won.bot.framework.eventbot.event.impl.mail.CreateNeedFromMailEvent)

Example 20 with WonNodeInformationService

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