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