use of won.protocol.validation.WonConnectionValidator 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