Search in sources :

Example 6 with MessageEventPlaceholder

use of won.protocol.model.MessageEventPlaceholder in project webofneeds by researchstudio-sat.

the class LinkedDataServiceImpl method listConnectionEventURIs.

@Override
@Transactional
public Dataset listConnectionEventURIs(final URI connectionUri, boolean deep) throws NoSuchConnectionException {
    Model model = ModelFactory.createDefaultModel();
    setNsPrefixes(model);
    Connection connection = needInformationService.readConnection(connectionUri);
    Resource eventContainer = model.createResource(connection.getConnectionURI().toString() + "/events", WON.EVENT_CONTAINER);
    // add the events with the new format (only the URI, no content)
    List<MessageEventPlaceholder> connectionEvents = messageEventRepository.findByParentURI(connectionUri);
    Dataset eventsContainerDataset = newDatasetWithNamedModel(createDataGraphUriFromResource(eventContainer), model);
    addBaseUriAndDefaultPrefixes(eventsContainerDataset);
    for (MessageEventPlaceholder event : connectionEvents) {
        model.add(model.createStatement(eventContainer, RDFS.member, model.getResource(event.getMessageURI().toString())));
        if (deep) {
            Dataset eventDataset = event.getDatasetHolder().getDataset();
            RdfUtils.addDatasetToDataset(eventsContainerDataset, eventDataset);
        }
    }
    return eventsContainerDataset;
}
Also used : Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) Connection(won.protocol.model.Connection) Resource(org.apache.jena.rdf.model.Resource) MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with MessageEventPlaceholder

use of won.protocol.model.MessageEventPlaceholder in project webofneeds by researchstudio-sat.

the class LinkedDataServiceImpl method eventsToContainerPage.

/**
 * Returns a container resource with the messageUris of all MessageEventPlaceholder objects in the slice.
 * If deep == true, the event datasets are added, too.
 * @param containerUri
 * @param slice
 * @param deep
 * @return
 */
private NeedInformationService.PagedResource<Dataset, URI> eventsToContainerPage(String containerUri, Slice<MessageEventPlaceholder> slice, boolean deep) {
    List<MessageEventPlaceholder> events = slice.getContent();
    URI resumeBefore = null;
    URI resumeAfter = null;
    if (slice.getSort() != null && !events.isEmpty()) {
        Iterator<Sort.Order> sortOrders = slice.getSort().iterator();
        if (sortOrders.hasNext()) {
            Sort.Order sortOrder = sortOrders.next();
            if (sortOrder.getDirection() == Sort.Direction.ASC) {
                resumeBefore = events.get(0).getMessageURI();
                resumeAfter = events.get(events.size() - 1).getMessageURI();
            } else {
                resumeBefore = events.get(events.size() - 1).getMessageURI();
                resumeAfter = events.get(0).getMessageURI();
            }
        }
    }
    Model model = ModelFactory.createDefaultModel();
    setNsPrefixes(model);
    Resource needListPageResource = null;
    needListPageResource = model.createResource(containerUri);
    DatasetHolderAggregator aggregator = new DatasetHolderAggregator();
    for (MessageEventPlaceholder event : events) {
        model.add(model.createStatement(needListPageResource, RDFS.member, model.createResource(event.getMessageURI().toString())));
        if (deep) {
            aggregator.appendDataset(event.getDatasetHolder());
        }
    }
    Dataset dataset = aggregator.aggregate();
    dataset.addNamedModel(createDataGraphUriFromResource(needListPageResource), model);
    addBaseUriAndDefaultPrefixes(dataset);
    NeedInformationService.PagedResource<Dataset, URI> containerPage = new NeedInformationService.PagedResource(dataset, resumeBefore, resumeAfter);
    return containerPage;
}
Also used : NeedInformationService(won.protocol.service.NeedInformationService) Dataset(org.apache.jena.query.Dataset) Resource(org.apache.jena.rdf.model.Resource) URI(java.net.URI) MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder) DatasetHolderAggregator(won.protocol.model.DatasetHolderAggregator) Model(org.apache.jena.rdf.model.Model) Sort(org.springframework.data.domain.Sort)

Example 8 with MessageEventPlaceholder

use of won.protocol.model.MessageEventPlaceholder in project webofneeds by researchstudio-sat.

the class MessageReferencer method updateReferenced.

private void updateReferenced(List<MessageAndPlaceholder> selected) {
    selected.stream().forEach((MessageAndPlaceholder m) -> {
        MessageEventPlaceholder messageEventPlaceholder = m.getMessageEventPlaceholder();
        messageEventPlaceholder.setReferencedByOtherMessage(true);
        messageEventRepository.save(messageEventPlaceholder);
    });
}
Also used : MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder)

Example 9 with MessageEventPlaceholder

use of won.protocol.model.MessageEventPlaceholder in project webofneeds by researchstudio-sat.

the class MessageReferencer method selectLatestMessage.

/**
 * Selects the latest
 *
 * @param selectedUris
 * @param message
 */
private void selectLatestMessage(Set<MessageUriAndParentUri> selectedUris, WonMessage message) {
    // initialize a variable for the result
    WonMessageType messageType = message.getMessageType();
    switch(messageType) {
        case SUCCESS_RESPONSE:
        case FAILURE_RESPONSE:
            // the current message is a response message. We want to reference the message we are responding to.
            // we find identify the message with the same parent as our current message and add it
            URI isResponseToURI = WonMessageUtils.getLocalIsResponseToURI(message);
            MessageEventPlaceholder messageEventPlaceholder = messageEventRepository.findOneByMessageURI(isResponseToURI);
            String methodName = "selectLatestMessage::response";
            if (messageEventPlaceholder != null) {
                selectedUris.add(new MessageUriAndParentUri(messageEventPlaceholder.getMessageURI(), messageEventPlaceholder.getParentURI()));
            }
            break;
        case CREATE_NEED:
            // a create message does not reference any other message. It is the root of the message structure
            break;
        default:
            // any other message: reference the latest message in the parent (i.e. the container of the message)
            // if we don't find any: reference the create message of the need.
            URI parentUri = WonMessageUtils.getParentEntityUri(message);
            messageEventPlaceholder = messageEventRepository.findNewestByParentURI(parentUri);
            if (messageEventPlaceholder != null) {
                selectedUris.add(new MessageUriAndParentUri(messageEventPlaceholder.getMessageURI(), messageEventPlaceholder.getParentURI()));
            } else {
                // we did not find any message to link to. Choose the create message of the need
                // we're starting a conversation, link to the create message of the need.
                URI parentNeedUri = WonMessageUtils.getParentNeedUri(message);
                List<MessageEventPlaceholder> eventsToSelect = messageEventRepository.findByParentURIAndMessageType(parentNeedUri, WonMessageType.CREATE_NEED);
                selectedUris.addAll(eventsToSelect.stream().map(p -> (new MessageUriAndParentUri(p.getMessageURI(), p.getParentURI()))).collect(Collectors.toList()));
            }
    }
}
Also used : URI(java.net.URI) MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder)

Aggregations

MessageEventPlaceholder (won.protocol.model.MessageEventPlaceholder)9 Dataset (org.apache.jena.query.Dataset)5 URI (java.net.URI)4 Model (org.apache.jena.rdf.model.Model)4 Resource (org.apache.jena.rdf.model.Resource)4 Transactional (org.springframework.transaction.annotation.Transactional)3 Connection (won.protocol.model.Connection)3 Sort (org.springframework.data.domain.Sort)2 WonMessage (won.protocol.message.WonMessage)2 DataWithEtag (won.protocol.model.DataWithEtag)2 PageRequest (org.springframework.data.domain.PageRequest)1 NoSuchNeedException (won.protocol.exception.NoSuchNeedException)1 DatasetHolder (won.protocol.model.DatasetHolder)1 DatasetHolderAggregator (won.protocol.model.DatasetHolderAggregator)1 Need (won.protocol.model.Need)1 UnreadMessageInfoForNeed (won.protocol.model.unread.UnreadMessageInfoForNeed)1 NeedInformationService (won.protocol.service.NeedInformationService)1