Search in sources :

Example 6 with HintFromMatcherEvent

use of won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent in project webofneeds by researchstudio-sat.

the class OpenConnectionAction method doRun.

@Override
public void doRun(final Event event, EventListener executingListener) throws Exception {
    if (event instanceof ConnectFromOtherNeedEvent) {
        ConnectionSpecificEvent connectEvent = (ConnectionSpecificEvent) event;
        logger.debug("auto-replying to connect for connection {}", connectEvent.getConnectionURI());
        getEventListenerContext().getWonMessageSender().sendWonMessage(createOpenWonMessage(connectEvent.getConnectionURI()));
        return;
    } else if (event instanceof OpenFromOtherNeedEvent) {
        ConnectionSpecificEvent connectEvent = (ConnectionSpecificEvent) event;
        URI connectionState = WonLinkedDataUtils.getConnectionStateforConnectionURI(connectEvent.getConnectionURI(), getEventListenerContext().getLinkedDataSource());
        if (ConnectionState.REQUEST_RECEIVED.getURI().equals(connectionState)) {
            logger.debug("auto-replying to open(REQUEST_RECEIVED) with open for connection {}", connectEvent.getConnectionURI());
            getEventListenerContext().getWonMessageSender().sendWonMessage(createOpenWonMessage(connectEvent.getConnectionURI()));
        } else {
        // else do not respond - we assume the connection is now established.
        }
        return;
    } else if (event instanceof HintFromMatcherEvent) {
        // TODO: the hint with a match object is not really suitable here. Would be better to
        // use connection object instead
        HintFromMatcherEvent hintEvent = (HintFromMatcherEvent) event;
        logger.debug("opening connection based on hint {}", event);
        getEventListenerContext().getWonMessageSender().sendWonMessage(createConnectWonMessage(hintEvent.getMatch().getFromNeed(), hintEvent.getMatch().getToNeed(), FacetType.OwnerFacet.getURI(), FacetType.OwnerFacet.getURI()));
    }
}
Also used : ConnectionSpecificEvent(won.bot.framework.eventbot.event.ConnectionSpecificEvent) OpenFromOtherNeedEvent(won.bot.framework.eventbot.event.impl.wonmessage.OpenFromOtherNeedEvent) HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) URI(java.net.URI) ConnectFromOtherNeedEvent(won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherNeedEvent)

Aggregations

HintFromMatcherEvent (won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent)6 URI (java.net.URI)4 WonMessage (won.protocol.message.WonMessage)3 Match (won.protocol.model.Match)3 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)2 WonURI (won.bot.framework.eventbot.action.impl.mail.model.WonURI)2 MimeMessage (javax.mail.internet.MimeMessage)1 Split (org.javasimon.Split)1 Stopwatch (org.javasimon.Stopwatch)1 Message (org.telegram.telegrambots.api.objects.Message)1 TelegramApiException (org.telegram.telegrambots.exceptions.TelegramApiException)1 FactoryBotContextWrapper (won.bot.framework.bot.context.FactoryBotContextWrapper)1 MailBotContextWrapper (won.bot.framework.bot.context.MailBotContextWrapper)1 TelegramBotContextWrapper (won.bot.framework.bot.context.TelegramBotContextWrapper)1 EventBus (won.bot.framework.eventbot.bus.EventBus)1 ConnectionSpecificEvent (won.bot.framework.eventbot.event.ConnectionSpecificEvent)1 FactoryHintEvent (won.bot.framework.eventbot.event.impl.factory.FactoryHintEvent)1 NeedCreatedEvent (won.bot.framework.eventbot.event.impl.needlifecycle.NeedCreatedEvent)1 ConnectFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherNeedEvent)1 OpenFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.OpenFromOtherNeedEvent)1