use of won.protocol.model.DatasetHolder in project webofneeds by researchstudio-sat.
the class LinkedDataServiceImpl method getConnectionDataset.
/**
* ETag-aware method for obtaining connection data. Currently does not take into account new events, only changes
* to the connection itself.
* @param connectionUri
* @param includeEventContainer
* @param includeLatestEvent
* @param etag
* @return
*/
@Override
@Transactional
public DataWithEtag<Dataset> getConnectionDataset(final URI connectionUri, final boolean includeEventContainer, final boolean includeLatestEvent, final String etag) {
DataWithEtag<Connection> data = null;
Connection connection = null;
data = needInformationService.readConnection(connectionUri, etag);
if (data.isNotFound()) {
return DataWithEtag.dataNotFound();
}
if (!data.isChanged()) {
return DataWithEtag.dataNotChanged(data);
}
connection = data.getData();
String newEtag = data.getEtag();
// load the model from storage
Model model = connectionModelMapper.toModel(connection);
Model additionalData = connection.getDatasetHolder() == null ? null : connection.getDatasetHolder().getDataset().getDefaultModel();
setNsPrefixes(model);
if (additionalData != null) {
model.add(additionalData);
}
// model.setNsPrefix("", connection.getConnectionURI().toString());
// create connection member
Resource connectionResource = model.getResource(connection.getConnectionURI().toString());
// add WON node link
connectionResource.addProperty(WON.HAS_WON_NODE, model.createResource(this.resourceURIPrefix));
Dataset eventDataset = null;
if (includeEventContainer) {
// create event container and attach it to the member
Resource eventContainer = model.createResource(connection.getConnectionURI().toString() + "/events");
connectionResource.addProperty(WON.HAS_EVENT_CONTAINER, eventContainer);
eventContainer.addProperty(RDF.type, WON.EVENT_CONTAINER);
if (includeLatestEvent) {
// we add the latest event in the connection
Slice<MessageEventPlaceholder> latestEvents = messageEventRepository.findByParentURIFetchDatasetEagerly(connectionUri, new PageRequest(0, 1, new Sort(Sort.Direction.DESC, "creationDate")));
if (latestEvents.hasContent()) {
MessageEventPlaceholder event = latestEvents.getContent().get(0);
// add the event's dataset
eventDataset = setDefaults(event.getDatasetHolder().getDataset());
// connect the event to its container
eventContainer.addProperty(RDFS.member, model.getResource(event.getMessageURI().toString()));
}
}
DatasetHolder datasetHolder = connection.getDatasetHolder();
if (datasetHolder != null) {
addAdditionalData(model, datasetHolder.getDataset().getDefaultModel(), connectionResource);
}
}
Dataset connectionDataset = addBaseUriAndDefaultPrefixes(newDatasetWithNamedModel(createDataGraphUriFromResource(connectionResource), model));
RdfUtils.addDatasetToDataset(connectionDataset, eventDataset);
return new DataWithEtag<>(connectionDataset, newEtag, etag);
}
use of won.protocol.model.DatasetHolder in project webofneeds by researchstudio-sat.
the class JpaRepositoryBasedRdfStorageServiceImpl method loadModel.
@Override
public DataWithEtag<Model> loadModel(final URI resourceURI, String etag) {
Integer version = Integer.valueOf(etag);
DatasetHolder datasetHolder = datasetHolderRepository.findOneByUriAndVersionNot(resourceURI, version);
DataWithEtag<Model> dataWithEtag = new DataWithEtag<Model>(datasetHolder == null ? null : datasetHolder.getDataset().getDefaultModel(), datasetHolder == null ? etag : Integer.toString(datasetHolder.getVersion()), etag);
return dataWithEtag;
}
use of won.protocol.model.DatasetHolder in project webofneeds by researchstudio-sat.
the class JpaRepositoryBasedRdfStorageServiceImpl method storeDataset.
@Override
public void storeDataset(final URI resourceURI, final Dataset dataset) {
DatasetHolder datasetHolder = datasetHolderRepository.findOneByUri(resourceURI);
if (datasetHolder != null) {
datasetHolder.setDataset(dataset);
} else {
datasetHolder = new DatasetHolder(resourceURI, dataset);
}
datasetHolderRepository.save(datasetHolder);
}
use of won.protocol.model.DatasetHolder in project webofneeds by researchstudio-sat.
the class JpaRepositoryBasedRdfStorageServiceImpl method loadDataset.
@Override
public DataWithEtag<Dataset> loadDataset(final URI resourceURI, String etag) {
Integer version = etag == null ? -1 : Integer.valueOf(etag);
DatasetHolder datasetHolder = datasetHolderRepository.findOneByUriAndVersionNot(resourceURI, version);
DataWithEtag<Dataset> dataWithEtag = new DataWithEtag<Dataset>(datasetHolder == null ? null : datasetHolder.getDataset(), datasetHolder == null ? etag : Integer.toString(datasetHolder.getVersion()), etag);
return dataWithEtag;
}
use of won.protocol.model.DatasetHolder in project webofneeds by researchstudio-sat.
the class LinkedDataServiceImpl method getDatasetForUri.
@Override
@Transactional
public DataWithEtag<Dataset> getDatasetForUri(URI datasetUri, String etag) {
Integer version = etag == null ? -1 : Integer.valueOf(etag);
DatasetHolder datasetHolder = datasetHolderRepository.findOneByUri(datasetUri);
if (datasetHolder == null) {
return DataWithEtag.dataNotFound();
}
if (version.intValue() == datasetHolder.getVersion()) {
return DataWithEtag.dataNotChanged(etag);
}
Dataset dataset = datasetHolder.getDataset();
DefaultPrefixUtils.setDefaultPrefixes(dataset.getDefaultModel());
addBaseUriAndDefaultPrefixes(dataset);
return new DataWithEtag<Dataset>(dataset, Integer.toString(datasetHolder.getVersion()), etag);
}
Aggregations