Search in sources :

Example 1 with WonConnectionValidator

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();
}
Also used : CrawlConnectionCommandSuccessEvent(won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandSuccessEvent) CrawlConnectionDataBehaviour(won.bot.framework.eventbot.behaviour.CrawlConnectionDataBehaviour) StopWatch(org.springframework.util.StopWatch) WonConnectionValidator(won.protocol.validation.WonConnectionValidator) Model(org.apache.jena.rdf.model.Model) ConnectionMessageCommandEvent(won.bot.framework.eventbot.event.impl.command.connectionmessage.ConnectionMessageCommandEvent) CrawlConnectionCommandEvent(won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandEvent)

Aggregations

Model (org.apache.jena.rdf.model.Model)1 StopWatch (org.springframework.util.StopWatch)1 CrawlConnectionDataBehaviour (won.bot.framework.eventbot.behaviour.CrawlConnectionDataBehaviour)1 ConnectionMessageCommandEvent (won.bot.framework.eventbot.event.impl.command.connectionmessage.ConnectionMessageCommandEvent)1 CrawlConnectionCommandEvent (won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandEvent)1 CrawlConnectionCommandSuccessEvent (won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandSuccessEvent)1 WonConnectionValidator (won.protocol.validation.WonConnectionValidator)1