Search in sources :

Example 1 with DatasetHolderAggregator

use of won.protocol.model.DatasetHolderAggregator 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)

Aggregations

URI (java.net.URI)1 Dataset (org.apache.jena.query.Dataset)1 Model (org.apache.jena.rdf.model.Model)1 Resource (org.apache.jena.rdf.model.Resource)1 Sort (org.springframework.data.domain.Sort)1 DatasetHolderAggregator (won.protocol.model.DatasetHolderAggregator)1 MessageEventPlaceholder (won.protocol.model.MessageEventPlaceholder)1 NeedInformationService (won.protocol.service.NeedInformationService)1