use of won.protocol.model.DataWithEtag in project webofneeds by researchstudio-sat.
the class LinkedDataServiceImpl method getNeedDataset.
@Transactional
public DataWithEtag<Dataset> getNeedDataset(final URI needUri, String etag) {
DataWithEtag<Need> data = null;
try {
data = needInformationService.readNeed(needUri, etag);
} catch (NoSuchNeedException e) {
return DataWithEtag.dataNotFound();
}
if (data.isNotFound()) {
return DataWithEtag.dataNotFound();
}
if (!data.isChanged()) {
return DataWithEtag.dataNotChanged(data);
}
Need need = data.getData();
String newEtag = data.getEtag();
// load the dataset from storage
Dataset dataset = need.getDatatsetHolder().getDataset();
Model metaModel = needModelMapper.toModel(need);
Resource needResource = metaModel.getResource(needUri.toString());
// add connections
Resource connectionsContainer = metaModel.createResource(need.getNeedURI().toString() + "/connections");
metaModel.add(metaModel.createStatement(needResource, WON.HAS_CONNECTIONS, connectionsContainer));
// add need event container
Resource needEventContainer = metaModel.createResource(need.getNeedURI().toString() + "#events", WON.EVENT_CONTAINER);
metaModel.add(metaModel.createStatement(needResource, WON.HAS_EVENT_CONTAINER, needEventContainer));
// add need event URIs
Collection<MessageEventPlaceholder> messageEvents = need.getEventContainer().getEvents();
for (MessageEventPlaceholder messageEvent : messageEvents) {
metaModel.add(metaModel.createStatement(needEventContainer, RDFS.member, metaModel.getResource(messageEvent.getMessageURI().toString())));
}
// add WON node link
needResource.addProperty(WON.HAS_WON_NODE, metaModel.createResource(this.resourceURIPrefix));
// add meta model to dataset
String needMetaInformationURI = uriService.createNeedSysInfoGraphURI(needUri).toString();
dataset.addNamedModel(needMetaInformationURI, metaModel);
addBaseUriAndDefaultPrefixes(dataset);
return new DataWithEtag<>(dataset, newEtag, etag);
}
use of won.protocol.model.DataWithEtag 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.DataWithEtag 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.DataWithEtag 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.DataWithEtag 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