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;
}
Aggregations