use of won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent in project webofneeds by researchstudio-sat.
the class TwoPhaseCommitNoVoteDeactivateAllNeedsAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
// check the global COORDINATION_MESSAGE (must be ABORT)
if (event instanceof CloseFromOtherNeedEvent) {
WonMessage wonMessage = ((CloseFromOtherNeedEvent) event).getWonMessage();
NodeIterator ni = RdfUtils.visitFlattenedToNodeIterator(wonMessage.getMessageContent(), new RdfUtils.ModelVisitor<NodeIterator>() {
@Override
public NodeIterator visit(final Model model) {
return model.listObjectsOfProperty(model.createProperty(WON_TX.COORDINATION_MESSAGE.getURI()));
}
});
if (ni.hasNext()) {
String coordinationMessageUri = ni.toList().get(0).asResource().getURI().toString();
if (coordinationMessageUri.equals(WON_TX.COORDINATION_MESSAGE_ABORT.getURI().toString()))
logger.debug("Sent COORDINATION_MESSAGE: {}", coordinationMessageUri);
else
logger.error("Content of the COORDINATION_MESSAGE must be: {}. Currently it is: {}", WON_TX.COORDINATION_MESSAGE_ABORT.getURI(), coordinationMessageUri);
}
}
Collection<URI> toDeactivate = getEventListenerContext().getBotContext().retrieveAllNeedUris();
for (URI uri : toDeactivate) {
getEventListenerContext().getWonMessageSender().sendWonMessage(createWonMessage(uri));
getEventListenerContext().getEventBus().publish(new NeedDeactivatedEvent(uri));
}
}
use of won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent in project webofneeds by researchstudio-sat.
the class DeactivateAllNeedsAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
Collection<URI> toDeactivate = getEventListenerContext().getBotContext().retrieveAllNeedUris();
for (URI uri : toDeactivate) {
getEventListenerContext().getWonMessageSender().sendWonMessage(createWonMessage(uri));
getEventListenerContext().getEventBus().publish(new NeedDeactivatedEvent(uri));
}
}
use of won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent in project webofneeds by researchstudio-sat.
the class DeactivateAllNeedsOfListAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
Collection<URI> toDeactivate = ctx.getBotContext().getNamedNeedUriList(uriListName);
for (URI uri : toDeactivate) {
ctx.getWonMessageSender().sendWonMessage(createWonMessage(uri));
ctx.getEventBus().publish(new NeedDeactivatedEvent(uri));
}
}
use of won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent in project webofneeds by researchstudio-sat.
the class TwoPhaseCommitDeactivateOnCloseAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
// If we receive a close event, it must carry a commit message.
if (event instanceof CloseFromOtherNeedEvent) {
URI needURI = ((CloseFromOtherNeedEvent) event).getNeedURI();
WonMessage wonMessage = ((CloseFromOtherNeedEvent) event).getWonMessage();
NodeIterator ni = RdfUtils.visitFlattenedToNodeIterator(wonMessage.getMessageContent(), new RdfUtils.ModelVisitor<NodeIterator>() {
@Override
public NodeIterator visit(final Model model) {
return model.listObjectsOfProperty(model.createProperty(WON_TX.COORDINATION_MESSAGE.getURI()));
}
});
assert ni.hasNext() : "no additional content found in close message, expected a commit";
String coordinationMessageUri = ni.toList().get(0).asResource().getURI().toString();
assert coordinationMessageUri.equals(WON_TX.COORDINATION_MESSAGE_COMMIT.getURI().toString()) : "expected a " + "Commmit message";
getEventListenerContext().getWonMessageSender().sendWonMessage(createWonMessage(needURI));
getEventListenerContext().getEventBus().publish(new NeedDeactivatedEvent(needURI));
}
}
Aggregations