Search in sources :

Example 1 with OpenFromOtherNeedEvent

use of won.bot.framework.eventbot.event.impl.wonmessage.OpenFromOtherNeedEvent 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

URI (java.net.URI)1 ConnectionSpecificEvent (won.bot.framework.eventbot.event.ConnectionSpecificEvent)1 ConnectFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherNeedEvent)1 HintFromMatcherEvent (won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent)1 OpenFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.OpenFromOtherNeedEvent)1