use of won.protocol.message.WonMessage 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());
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class Hint2TelegramAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof HintFromMatcherEvent && ctx.getBotContextWrapper() instanceof TelegramBotContextWrapper) {
TelegramBotContextWrapper botContextWrapper = (TelegramBotContextWrapper) ctx.getBotContextWrapper();
Match match = ((HintFromMatcherEvent) event).getMatch();
WonMessage wonMessage = ((HintFromMatcherEvent) event).getWonMessage();
URI yourNeedUri = match.getFromNeed();
URI remoteNeedUri = match.getToNeed();
Long chatId = botContextWrapper.getChatIdForURI(yourNeedUri);
if (chatId == null) {
logger.error("No chatId found for the specified needUri");
return;
}
try {
Message message = wonTelegramBotHandler.sendMessage(wonTelegramBotHandler.getTelegramMessageGenerator().getHintMessage(chatId, remoteNeedUri, yourNeedUri));
botContextWrapper.addMessageIdWonURIRelation(message.getMessageId(), new WonURI(wonMessage.getReceiverURI(), UriType.CONNECTION));
} catch (TelegramApiException te) {
logger.error(te.getMessage());
}
}
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class Message2TelegramAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof MessageFromOtherNeedEvent && ctx.getBotContextWrapper() instanceof TelegramBotContextWrapper) {
TelegramBotContextWrapper botContextWrapper = (TelegramBotContextWrapper) ctx.getBotContextWrapper();
Connection con = ((MessageFromOtherNeedEvent) event).getCon();
WonMessage wonMessage = ((MessageFromOtherNeedEvent) event).getWonMessage();
URI yourNeedUri = con.getNeedURI();
URI remoteNeedUri = con.getRemoteNeedURI();
Long chatId = botContextWrapper.getChatIdForURI(yourNeedUri);
if (chatId == null) {
logger.error("No chatId found for the specified needUri");
return;
}
try {
Message message = wonTelegramBotHandler.sendMessage(wonTelegramBotHandler.getTelegramMessageGenerator().getConnectionTextMessage(chatId, remoteNeedUri, yourNeedUri, wonMessage));
botContextWrapper.addMessageIdWonURIRelation(message.getMessageId(), new WonURI(con.getConnectionURI(), UriType.CONNECTION));
} catch (TelegramApiException te) {
logger.error(te.getMessage());
}
}
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class DuplicateMessageSenderDecorator method getWonMessageSender.
@Override
public WonMessageSender getWonMessageSender() {
final WonMessageSender delegate = super.getWonMessageSender();
return new WonMessageSender() {
@Override
public void sendWonMessage(WonMessage message) throws WonMessageSenderException {
delegate.sendWonMessage(message);
delegate.sendWonMessage(message);
}
};
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class EagerlyCachePopulatingMessageProcessor method process.
@Override
public WonMessage process(WonMessage message) throws WonMessageProcessingException {
if (this.linkedDataSourceOnBehalfOfNeed != null && this.linkedDataSourceOnBehalfOfNeed instanceof CachingLinkedDataSource) {
logger.debug("eagerly fetching delivery chain for mesasge {} into cache", message.getMessageURI());
URI requester = message.getReceiverNeedURI();
((CachingLinkedDataSource) linkedDataSourceOnBehalfOfNeed).addToCache(message.getCompleteDataset(), message.getMessageURI(), requester);
// load the original message(s) into cache, too
Set<URI> toLoad = new HashSet<URI>();
addIfNotNull(toLoad, message.getIsRemoteResponseToMessageURI());
addIfNotNull(toLoad, message.getIsResponseToMessageURI());
addIfNotNull(toLoad, message.getCorrespondingRemoteMessageURI());
List<URI> previous = WonRdfUtils.MessageUtils.getPreviousMessageUrisIncludingRemote(message);
addIfNotNull(toLoad, previous);
parallelRequestsThreadpool.submit(() -> toLoad.parallelStream().forEach(uri -> linkedDataSourceOnBehalfOfNeed.getDataForResource(uri, requester)));
}
return message;
}
Aggregations