use of won.bot.framework.eventbot.event.impl.command.deactivate.DeactivateAtomCommandEvent 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());
}
Aggregations