Search in sources :

Example 1 with DatasetHolder

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);
}
Also used : DatasetHolder(won.protocol.model.DatasetHolder) PageRequest(org.springframework.data.domain.PageRequest) Dataset(org.apache.jena.query.Dataset) Connection(won.protocol.model.Connection) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Sort(org.springframework.data.domain.Sort) DataWithEtag(won.protocol.model.DataWithEtag) MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with DatasetHolder

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;
}
Also used : DatasetHolder(won.protocol.model.DatasetHolder) Model(org.apache.jena.rdf.model.Model) DataWithEtag(won.protocol.model.DataWithEtag)

Example 3 with DatasetHolder

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);
}
Also used : DatasetHolder(won.protocol.model.DatasetHolder)

Example 4 with 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;
}
Also used : DatasetHolder(won.protocol.model.DatasetHolder) Dataset(org.apache.jena.query.Dataset) DataWithEtag(won.protocol.model.DataWithEtag)

Example 5 with DatasetHolder

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);
}
Also used : DatasetHolder(won.protocol.model.DatasetHolder) Dataset(org.apache.jena.query.Dataset) DataWithEtag(won.protocol.model.DataWithEtag) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DatasetHolder (won.protocol.model.DatasetHolder)5 DataWithEtag (won.protocol.model.DataWithEtag)4 Dataset (org.apache.jena.query.Dataset)3 Model (org.apache.jena.rdf.model.Model)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Resource (org.apache.jena.rdf.model.Resource)1 PageRequest (org.springframework.data.domain.PageRequest)1 Sort (org.springframework.data.domain.Sort)1 Connection (won.protocol.model.Connection)1 MessageEventPlaceholder (won.protocol.model.MessageEventPlaceholder)1