Search in sources :

Example 41 with Dataset

use of org.apache.jena.query.Dataset in project webofneeds by researchstudio-sat.

the class DeactivateAllNeedsAction method createWonMessage.

private WonMessage createWonMessage(URI needURI) throws WonMessageBuilderException {
    WonNodeInformationService wonNodeInformationService = getEventListenerContext().getWonNodeInformationService();
    Dataset ds = getEventListenerContext().getLinkedDataSource().getDataForResource(needURI);
    URI localWonNode = WonRdfUtils.NeedUtils.getWonNodeURIFromNeed(ds, needURI);
    return WonMessageBuilder.setMessagePropertiesForDeactivateFromOwner(wonNodeInformationService.generateEventURI(localWonNode), needURI, localWonNode).build();
}
Also used : Dataset(org.apache.jena.query.Dataset) WonNodeInformationService(won.protocol.service.WonNodeInformationService) URI(java.net.URI)

Example 42 with Dataset

use of org.apache.jena.query.Dataset in project webofneeds by researchstudio-sat.

the class TelegramCreateAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    EventListenerContext ctx = getEventListenerContext();
    if (event instanceof TelegramCreateNeedEvent && ctx.getBotContextWrapper() instanceof TelegramBotContextWrapper) {
        TelegramBotContextWrapper botContextWrapper = (TelegramBotContextWrapper) ctx.getBotContextWrapper();
        TelegramCreateNeedEvent telegramCreateNeedEvent = (TelegramCreateNeedEvent) event;
        String[] parameters = telegramCreateNeedEvent.getStrings();
        Long chatId = telegramCreateNeedEvent.getChat().getId();
        if (chatId == null) {
            logger.error("no chatid present");
            return;
        }
        try {
            NeedContentPropertyType type = telegramContentExtractor.getNeedContentType(parameters[0]);
            if (type == null) {
                throw new InvalidParameterException("no valid type was given");
            }
            String title = null;
            if (parameters.length > 1) {
                title = parameters[1];
            }
            if (title == null) {
                throw new InvalidParameterException("no valid title was given");
            }
            // MAKE THOSE ATTRIBUTES DIFFERENT AND EDITABLE
            boolean isUsedForTesting = true;
            boolean isDoNotMatch = false;
            WonNodeInformationService wonNodeInformationService = ctx.getWonNodeInformationService();
            final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
            final URI needURI = wonNodeInformationService.generateNeedURI(wonNodeUri);
            DefaultNeedModelWrapper wrapper = new DefaultNeedModelWrapper(needURI.toString());
            wrapper.setTitle(type, title);
            for (URI facet : facets) {
                wrapper.addFacetUri(facet.toString());
            }
            Dataset needDataset = wrapper.copyDataset();
            logger.debug("creating need on won node {} with content {} ", wonNodeUri, StringUtils.abbreviate(RdfUtils.toString(needDataset), 150));
            WonMessage createNeedMessage = createWonMessage(wonNodeInformationService, needURI, wonNodeUri, needDataset, isUsedForTesting, isDoNotMatch);
            EventBotActionUtils.rememberInList(ctx, needURI, uriListName);
            botContextWrapper.addChatIdWonURIRelation(chatId, new WonURI(needURI, UriType.NEED));
            botContextWrapper.addURIChatIdRelation(needURI, chatId);
            EventListener successCallback = new EventListener() {

                @Override
                public void onEvent(Event event) throws Exception {
                    logger.debug("need creation successful, new need URI is {}", needURI);
                    logger.debug("created need was from sender: " + botContextWrapper.getChatIdForURI(needURI));
                    try {
                        Message message = telegramCreateNeedEvent.getAbsSender().sendMessage(wonTelegramBotHandler.getTelegramMessageGenerator().getCreatedNeedMessage(chatId, needURI));
                        botContextWrapper.addMessageIdWonURIRelation(message.getMessageId(), new WonURI(needURI, UriType.NEED));
                    } catch (TelegramApiException te) {
                        logger.error(te.getMessage());
                    }
                }
            };
            EventListener failureCallback = new EventListener() {

                @Override
                public void onEvent(Event event) throws Exception {
                    String textMessage = WonRdfUtils.MessageUtils.getTextMessage(((FailureResponseEvent) event).getFailureMessage());
                    logger.error("need creation failed for need URI {}, original message URI {}: {}", new Object[] { needURI, ((FailureResponseEvent) event).getOriginalMessageURI(), textMessage });
                    EventBotActionUtils.removeFromList(getEventListenerContext(), needURI, uriListName);
                }
            };
            EventBotActionUtils.makeAndSubscribeResponseListener(createNeedMessage, successCallback, failureCallback, getEventListenerContext());
            logger.debug("registered listeners for response to message URI {}", createNeedMessage.getMessageURI());
            getEventListenerContext().getWonMessageSender().sendWonMessage(createNeedMessage);
            logger.debug("need creation message sent with message URI {}", createNeedMessage.getMessageURI());
        } catch (Exception e) {
            try {
                logger.error(e.getMessage());
                telegramCreateNeedEvent.getAbsSender().sendMessage(wonTelegramBotHandler.getTelegramMessageGenerator().getErrorMessage(chatId));
            } catch (TelegramApiException te) {
                logger.error(te.getMessage());
            }
        }
    }
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) DefaultNeedModelWrapper(won.protocol.util.DefaultNeedModelWrapper) Message(org.telegram.telegrambots.api.objects.Message) WonMessage(won.protocol.message.WonMessage) TelegramCreateNeedEvent(won.bot.framework.eventbot.event.impl.telegram.TelegramCreateNeedEvent) Dataset(org.apache.jena.query.Dataset) WonNodeInformationService(won.protocol.service.WonNodeInformationService) NeedContentPropertyType(won.protocol.model.NeedContentPropertyType) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) URI(java.net.URI) TelegramApiException(org.telegram.telegrambots.exceptions.TelegramApiException) InvalidParameterException(java.security.InvalidParameterException) TelegramApiException(org.telegram.telegrambots.exceptions.TelegramApiException) InvalidParameterException(java.security.InvalidParameterException) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) TelegramBotContextWrapper(won.bot.framework.bot.context.TelegramBotContextWrapper) WonMessage(won.protocol.message.WonMessage) TelegramCreateNeedEvent(won.bot.framework.eventbot.event.impl.telegram.TelegramCreateNeedEvent) FailureResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent) Event(won.bot.framework.eventbot.event.Event) EventListener(won.bot.framework.eventbot.listener.EventListener)

Example 43 with Dataset

use of org.apache.jena.query.Dataset in project webofneeds by researchstudio-sat.

the class TelegramMessageGenerator method getHintMessage.

public SendMessage getHintMessage(Long chatId, URI remoteNeedUri, URI yourNeedUri) {
    Dataset remoteNeedRDF = eventListenerContext.getLinkedDataSource().getDataForResource(remoteNeedUri);
    DefaultNeedModelWrapper needModelWrapper = new DefaultNeedModelWrapper(remoteNeedRDF);
    String title = needModelWrapper.getSomeTitleFromIsOrAll("en", "de");
    String description = needModelWrapper.getSomeDescription(NeedContentPropertyType.ALL, "en", "de");
    SendMessage sendMessage = new SendMessage();
    sendMessage.setChatId(chatId);
    String text = "<b>We found a Match for you!\n\n</b><a href='" + remoteNeedUri + "'>" + title + "\n\n</a>";
    if (description != null) {
        text = text + "<em>" + description + "</em>";
    }
    sendMessage.setText(text);
    sendMessage.setReplyMarkup(getConnectionActionKeyboard("Request", "Close"));
    sendMessage.enableHtml(true);
    return sendMessage;
}
Also used : DefaultNeedModelWrapper(won.protocol.util.DefaultNeedModelWrapper) Dataset(org.apache.jena.query.Dataset) SendMessage(org.telegram.telegrambots.api.methods.send.SendMessage)

Example 44 with Dataset

use of org.apache.jena.query.Dataset in project webofneeds by researchstudio-sat.

the class TelegramMessageGenerator method getCreatedNeedMessage.

public SendMessage getCreatedNeedMessage(Long chatId, URI needURI) {
    Dataset createdNeedRDF = eventListenerContext.getLinkedDataSource().getDataForResource(needURI);
    DefaultNeedModelWrapper needModelWrapper = new DefaultNeedModelWrapper(createdNeedRDF);
    String title = needModelWrapper.getSomeTitleFromIsOrAll("en", "de");
    String description = needModelWrapper.getSomeDescription(NeedContentPropertyType.ALL, "en", "de");
    SendMessage sendMessage = new SendMessage();
    sendMessage.setChatId(chatId);
    String text = "<b>We created a Need for you!\n\n</b><a href='" + needURI + "'>" + title + "\n\n</a>";
    if (description != null) {
        text = text + "<em>" + description + "</em>";
    }
    sendMessage.setText(text);
    sendMessage.enableHtml(true);
    return sendMessage;
}
Also used : DefaultNeedModelWrapper(won.protocol.util.DefaultNeedModelWrapper) Dataset(org.apache.jena.query.Dataset) SendMessage(org.telegram.telegrambots.api.methods.send.SendMessage)

Example 45 with Dataset

use of org.apache.jena.query.Dataset in project webofneeds by researchstudio-sat.

the class ConnectWithAssociatedNeedAction method createWonMessage.

private WonMessage createWonMessage(URI fromUri, URI toUri) throws WonMessageBuilderException {
    WonNodeInformationService wonNodeInformationService = getEventListenerContext().getWonNodeInformationService();
    Dataset localNeedRDF = getEventListenerContext().getLinkedDataSource().getDataForResource(fromUri);
    Dataset remoteNeedRDF = getEventListenerContext().getLinkedDataSource().getDataForResource(toUri);
    URI localWonNode = WonRdfUtils.NeedUtils.getWonNodeURIFromNeed(localNeedRDF, fromUri);
    URI remoteWonNode = WonRdfUtils.NeedUtils.getWonNodeURIFromNeed(remoteNeedRDF, toUri);
    return WonMessageBuilder.setMessagePropertiesForConnect(wonNodeInformationService.generateEventURI(localWonNode), localFacet, fromUri, localWonNode, remoteFacet, toUri, remoteWonNode, welcomeMessage).build();
}
Also used : Dataset(org.apache.jena.query.Dataset) WonNodeInformationService(won.protocol.service.WonNodeInformationService) URI(java.net.URI)

Aggregations

Dataset (org.apache.jena.query.Dataset)725 Test (org.junit.Test)401 Model (org.apache.jena.rdf.model.Model)173 Ignore (org.junit.Ignore)93 URI (java.net.URI)80 Resource (org.apache.jena.rdf.model.Resource)70 QueryExecution (org.apache.jena.query.QueryExecution)53 ArrayList (java.util.ArrayList)46 QuerySolution (org.apache.jena.query.QuerySolution)46 ResultSet (org.apache.jena.query.ResultSet)45 WonNodeInformationService (won.protocol.service.WonNodeInformationService)28 Statement (org.apache.jena.rdf.model.Statement)26 Node (org.apache.jena.graph.Node)23 InputStream (java.io.InputStream)22 RDFNode (org.apache.jena.rdf.model.RDFNode)21 RdfUtils (won.protocol.util.RdfUtils)19 WonMessage (won.protocol.message.WonMessage)17 Literal (org.apache.jena.rdf.model.Literal)16 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16