Search in sources :

Example 1 with DeactivateAtomCommandFailureEvent

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

the class ExecuteDeactivateAtomCommandAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    if (!(event instanceof DeactivateAtomCommandEvent)) {
        return;
    }
    DeactivateAtomCommandEvent deactivateAtomCommandEvent = (DeactivateAtomCommandEvent) event;
    EventListenerContext ctx = getEventListenerContext();
    EventBus bus = ctx.getEventBus();
    final URI atomUri = deactivateAtomCommandEvent.getAtomUri();
    Dataset atomRDF = ctx.getLinkedDataSource().getDataForPublicResource(atomUri);
    final URI wonNodeUri = WonRdfUtils.ConnectionUtils.getWonNodeURIFromAtom(atomRDF, atomUri);
    WonNodeInformationService wonNodeInformationService = ctx.getWonNodeInformationService();
    WonMessage deactivateAtomMessage = createWonMessage(wonNodeInformationService, atomUri, wonNodeUri);
    deactivateAtomMessage = ctx.getWonMessageSender().prepareMessage(deactivateAtomMessage);
    EventListener successCallback = event12 -> {
        logger.debug("atom creation successful, new atom URI is {}", atomUri);
        bus.publish(new DeactivateAtomCommandSuccessEvent(atomUri, deactivateAtomCommandEvent));
    };
    EventListener failureCallback = event1 -> {
        String textMessage = WonRdfUtils.MessageUtils.getTextMessage(((FailureResponseEvent) event1).getFailureMessage());
        logger.debug("atom creation failed for atom URI {}, original message URI {}: {}", new Object[] { atomUri, ((FailureResponseEvent) event1).getOriginalMessageURI(), textMessage });
        bus.publish(new DeactivateAtomCommandFailureEvent(atomUri, deactivateAtomCommandEvent, textMessage));
    };
    EventBotActionUtils.makeAndSubscribeResponseListener(deactivateAtomMessage, successCallback, failureCallback, ctx);
    logger.debug("registered listeners for response to message URI {}", deactivateAtomMessage.getMessageURI());
    ctx.getWonMessageSender().sendMessage(deactivateAtomMessage);
    logger.debug("atom creation message sent with message URI {}", deactivateAtomMessage.getMessageURI());
}
Also used : WonNodeInformationService(won.protocol.service.WonNodeInformationService) Logger(org.slf4j.Logger) WonMessageBuilderException(won.protocol.exception.WonMessageBuilderException) DeactivateAtomCommandFailureEvent(won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateAtomCommandFailureEvent) MethodHandles(java.lang.invoke.MethodHandles) LoggerFactory(org.slf4j.LoggerFactory) EventBus(won.bot.framework.eventbot.bus.EventBus) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) EventBotActionUtils(won.bot.framework.eventbot.action.EventBotActionUtils) DeactivateAtomCommandEvent(won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateAtomCommandEvent) FailureResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent) WonMessage(won.protocol.message.WonMessage) WonRdfUtils(won.protocol.util.WonRdfUtils) WonMessageBuilder(won.protocol.message.builder.WonMessageBuilder) Event(won.bot.framework.eventbot.event.Event) DeactivateAtomCommandSuccessEvent(won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateAtomCommandSuccessEvent) EventListener(won.bot.framework.eventbot.listener.EventListener) URI(java.net.URI) Dataset(org.apache.jena.query.Dataset) EventListenerContext(won.bot.framework.eventbot.EventListenerContext) EventListenerContext(won.bot.framework.eventbot.EventListenerContext) Dataset(org.apache.jena.query.Dataset) WonNodeInformationService(won.protocol.service.WonNodeInformationService) EventBus(won.bot.framework.eventbot.bus.EventBus) URI(java.net.URI) DeactivateAtomCommandSuccessEvent(won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateAtomCommandSuccessEvent) WonMessage(won.protocol.message.WonMessage) DeactivateAtomCommandFailureEvent(won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateAtomCommandFailureEvent) EventListener(won.bot.framework.eventbot.listener.EventListener) FailureResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent) DeactivateAtomCommandEvent(won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateAtomCommandEvent)

Aggregations

MethodHandles (java.lang.invoke.MethodHandles)1 URI (java.net.URI)1 Dataset (org.apache.jena.query.Dataset)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)1 BaseEventBotAction (won.bot.framework.eventbot.action.BaseEventBotAction)1 EventBotActionUtils (won.bot.framework.eventbot.action.EventBotActionUtils)1 EventBus (won.bot.framework.eventbot.bus.EventBus)1 Event (won.bot.framework.eventbot.event.Event)1 DeactivateAtomCommandEvent (won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateAtomCommandEvent)1 DeactivateAtomCommandFailureEvent (won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateAtomCommandFailureEvent)1 DeactivateAtomCommandSuccessEvent (won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateAtomCommandSuccessEvent)1 FailureResponseEvent (won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent)1 EventListener (won.bot.framework.eventbot.listener.EventListener)1 WonMessageBuilderException (won.protocol.exception.WonMessageBuilderException)1 WonMessage (won.protocol.message.WonMessage)1 WonMessageBuilder (won.protocol.message.builder.WonMessageBuilder)1 WonNodeInformationService (won.protocol.service.WonNodeInformationService)1 WonRdfUtils (won.protocol.util.WonRdfUtils)1