Search in sources :

Example 1 with FactoryHintEvent

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

the class FactoryHintCheckAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    if (!(event instanceof HintFromMatcherEvent) || !(getEventListenerContext().getBotContextWrapper() instanceof FactoryBotContextWrapper)) {
        logger.error("FactoryHintCheckAction can only handle HintFromMatcherEvent with FactoryBotContextWrapper");
        return;
    }
    FactoryBotContextWrapper botContextWrapper = (FactoryBotContextWrapper) getEventListenerContext().getBotContextWrapper();
    Match match = ((HintFromMatcherEvent) event).getMatch();
    URI ownUri = match.getFromNeed();
    URI requesterUri = match.getToNeed();
    if (botContextWrapper.isFactoryNeed(ownUri)) {
        logger.debug("FactoryHint for factoryURI: " + ownUri + " from the requesterUri: " + requesterUri);
        EventBus bus = getEventListenerContext().getEventBus();
        bus.publish(new FactoryHintEvent(requesterUri, ownUri));
    } else {
        logger.warn("NON FactoryHint for URI: " + ownUri + " from the requesterUri: " + requesterUri + " ignore the hint");
    }
}
Also used : HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) FactoryHintEvent(won.bot.framework.eventbot.event.impl.factory.FactoryHintEvent) EventBus(won.bot.framework.eventbot.bus.EventBus) URI(java.net.URI) FactoryBotContextWrapper(won.bot.framework.bot.context.FactoryBotContextWrapper) Match(won.protocol.model.Match)

Aggregations

URI (java.net.URI)1 FactoryBotContextWrapper (won.bot.framework.bot.context.FactoryBotContextWrapper)1 EventBus (won.bot.framework.eventbot.bus.EventBus)1 FactoryHintEvent (won.bot.framework.eventbot.event.impl.factory.FactoryHintEvent)1 HintFromMatcherEvent (won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent)1 Match (won.protocol.model.Match)1