Search in sources :

Example 1 with CrawlConnectionDataBehaviour

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

Example 2 with CrawlConnectionDataBehaviour

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();
}
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)2 StopWatch (org.springframework.util.StopWatch)2 CrawlConnectionDataBehaviour (won.bot.framework.eventbot.behaviour.CrawlConnectionDataBehaviour)2 ConnectionMessageCommandEvent (won.bot.framework.eventbot.event.impl.command.connectionmessage.ConnectionMessageCommandEvent)2 CrawlConnectionCommandEvent (won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandEvent)2 Duration (java.time.Duration)1 CrawlConnectionCommandSuccessEvent (won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandSuccessEvent)1 AgreementProtocolState (won.protocol.agreement.AgreementProtocolState)1 WonConnectionValidator (won.protocol.validation.WonConnectionValidator)1