use of won.bot.framework.eventbot.behaviour.CrawlConnectionDataBehaviour in project webofneeds by researchstudio-sat.
the class DebugBotIncomingMessageToEventMappingAction method referToEarlierMessages.
private void referToEarlierMessages(EventListenerContext ctx, EventBus bus, Connection con, String crawlAnnouncement, MessageFinder messageFinder, MessageReferrer messageReferrer, TextMessageMaker textMessageMaker) {
Model messageModel = WonRdfUtils.MessageUtils.textMessage(crawlAnnouncement);
bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
// initiate crawl behaviour
CrawlConnectionCommandEvent command = new CrawlConnectionCommandEvent(con.getNeedURI(), con.getConnectionURI());
CrawlConnectionDataBehaviour crawlConnectionDataBehaviour = new CrawlConnectionDataBehaviour(ctx, command, Duration.ofSeconds(60));
final StopWatch crawlStopWatch = new StopWatch();
crawlStopWatch.start("crawl");
AgreementProtocolState state = WonConversationUtils.getAgreementProtocolState(con.getConnectionURI(), ctx.getLinkedDataSource());
crawlStopWatch.stop();
Duration crawlDuration = Duration.ofMillis(crawlStopWatch.getLastTaskTimeMillis());
messageModel = WonRdfUtils.MessageUtils.textMessage("Finished crawl in " + getDurationString(crawlDuration) + " seconds. The dataset has " + state.getConversationDataset().asDatasetGraph().size() + " rdf graphs.");
getEventListenerContext().getEventBus().publish(new ConnectionMessageCommandEvent(con, messageModel));
messageModel = makeReferringMessage(state, messageFinder, messageReferrer, textMessageMaker);
getEventListenerContext().getEventBus().publish(new ConnectionMessageCommandEvent(con, messageModel));
crawlConnectionDataBehaviour.activate();
}
use of won.bot.framework.eventbot.behaviour.CrawlConnectionDataBehaviour in project webofneeds by researchstudio-sat.
the class DebugBotIncomingMessageToEventMappingAction method validate.
private void validate(EventListenerContext ctx, EventBus bus, Connection con) {
Model messageModel = WonRdfUtils.MessageUtils.textMessage("ok, I'll validate the connection - but I'll need to crawl the connection data first, please be patient.");
bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
// initiate crawl behaviour
CrawlConnectionCommandEvent command = new CrawlConnectionCommandEvent(con.getNeedURI(), con.getConnectionURI());
CrawlConnectionDataBehaviour crawlConnectionDataBehaviour = new CrawlConnectionDataBehaviour(ctx, command, Duration.ofSeconds(60));
final StopWatch crawlStopWatch = new StopWatch();
crawlStopWatch.start("crawl");
crawlConnectionDataBehaviour.onResult(new SendMessageReportingCrawlResultAction(ctx, con, crawlStopWatch));
crawlConnectionDataBehaviour.onResult(new SendMessageOnCrawlResultAction(ctx, con) {
@Override
protected Model makeSuccessMessage(CrawlConnectionCommandSuccessEvent successEvent) {
try {
logger.debug("validating data of connection {}", command.getConnectionURI());
// TODO: use one validator for all invocations
WonConnectionValidator validator = new WonConnectionValidator();
StringBuilder message = new StringBuilder();
boolean valid = validator.validate(successEvent.getCrawledData(), message);
String successMessage = "Connection " + command.getConnectionURI() + " is valid: " + valid + " " + message.toString();
return WonRdfUtils.MessageUtils.textMessage(successMessage);
} catch (Exception e) {
return WonRdfUtils.MessageUtils.textMessage("Caught exception during validation: " + e);
}
}
});
crawlConnectionDataBehaviour.activate();
}
Aggregations