Search in sources :

Example 1 with DeactivateNeedCommandSuccessEvent

use of won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateNeedCommandSuccessEvent in project webofneeds by researchstudio-sat.

the class ExecuteDeactivateNeedCommandAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    if (!(event instanceof DeactivateNeedCommandEvent))
        return;
    DeactivateNeedCommandEvent deactivateNeedCommandEvent = (DeactivateNeedCommandEvent) event;
    EventListenerContext ctx = getEventListenerContext();
    EventBus bus = ctx.getEventBus();
    final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
    WonNodeInformationService wonNodeInformationService = ctx.getWonNodeInformationService();
    final URI needURI = wonNodeInformationService.generateNeedURI(wonNodeUri);
    WonMessage deactivateNeedMessage = createWonMessage(wonNodeInformationService, needURI, wonNodeUri);
    EventListener successCallback = new EventListener() {

        @Override
        public void onEvent(Event event) throws Exception {
            logger.debug("need creation successful, new need URI is {}", needURI);
            bus.publish(new DeactivateNeedCommandSuccessEvent(needURI, deactivateNeedCommandEvent));
        }
    };
    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 });
            bus.publish(new DeactivateNeedCommandFailureEvent(needURI, deactivateNeedCommandEvent, textMessage));
        }
    };
    EventBotActionUtils.makeAndSubscribeResponseListener(deactivateNeedMessage, successCallback, failureCallback, ctx);
    logger.debug("registered listeners for response to message URI {}", deactivateNeedMessage.getMessageURI());
    ctx.getWonMessageSender().sendWonMessage(deactivateNeedMessage);
    logger.debug("need creation message sent with message URI {}", deactivateNeedMessage.getMessageURI());
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) DeactivateNeedCommandFailureEvent(won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateNeedCommandFailureEvent) DeactivateNeedCommandSuccessEvent(won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateNeedCommandSuccessEvent) WonMessage(won.protocol.message.WonMessage) WonNodeInformationService(won.protocol.service.WonNodeInformationService) DeactivateNeedCommandFailureEvent(won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateNeedCommandFailureEvent) FailureResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent) Event(won.bot.framework.eventbot.event.Event) DeactivateNeedCommandSuccessEvent(won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateNeedCommandSuccessEvent) DeactivateNeedCommandEvent(won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateNeedCommandEvent) DeactivateNeedCommandEvent(won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateNeedCommandEvent) EventBus(won.bot.framework.eventbot.bus.EventBus) EventListener(won.bot.framework.eventbot.listener.EventListener) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)1 EventBus (won.bot.framework.eventbot.bus.EventBus)1 Event (won.bot.framework.eventbot.event.Event)1 DeactivateNeedCommandEvent (won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateNeedCommandEvent)1 DeactivateNeedCommandFailureEvent (won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateNeedCommandFailureEvent)1 DeactivateNeedCommandSuccessEvent (won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateNeedCommandSuccessEvent)1 FailureResponseEvent (won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent)1 EventListener (won.bot.framework.eventbot.listener.EventListener)1 WonMessage (won.protocol.message.WonMessage)1 WonNodeInformationService (won.protocol.service.WonNodeInformationService)1