NIHVIVO-3640 RDFService interface
This commit is contained in:
parent
1d151d63d3
commit
a60c3a2bc1
6 changed files with 325 additions and 0 deletions
|
@ -0,0 +1,41 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.rdfservice;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange.Operation;
|
||||
|
||||
/*
|
||||
* Input parameter to changeSetUpdate() method in RDFService.
|
||||
* Represents a precondition query and an ordered list of model changes.
|
||||
*/
|
||||
|
||||
public interface ChangeSet {
|
||||
|
||||
public String getPreconditionQuery();
|
||||
|
||||
public void setPreconditionQuery(String preconditionQuery);
|
||||
|
||||
public RDFService.SPARQLQueryType getPreconditionQueryType();
|
||||
|
||||
public void setPreconditionQueryType(RDFService.SPARQLQueryType queryType);
|
||||
|
||||
public List<ModelChange> getModelChanges();
|
||||
|
||||
public void addAddition(InputStream model,
|
||||
RDFService.ModelSerializationFormat format,
|
||||
String graphURI);
|
||||
|
||||
public void addRemoval(InputStream model,
|
||||
RDFService.ModelSerializationFormat format,
|
||||
String graphURI);
|
||||
|
||||
public ModelChange manufactureModelChange();
|
||||
|
||||
public ModelChange manufactureModelChange(InputStream serializedModel,
|
||||
RDFService.ModelSerializationFormat serializationFormat,
|
||||
Operation operation,
|
||||
String graphURI);
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.rdfservice;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange.Operation;
|
||||
|
||||
/*
|
||||
* Input parameter to changeSetUpdate() method in RDFService.
|
||||
* Represents a precondition query and an ordered list of model changes.
|
||||
*/
|
||||
public class ChangeSetImpl implements ChangeSet {
|
||||
|
||||
public ChangeSetImpl() {
|
||||
modelChanges = new ArrayList<ModelChange>();
|
||||
}
|
||||
|
||||
private String preconditionQuery;
|
||||
private RDFService.SPARQLQueryType queryType;
|
||||
private ArrayList<ModelChange> modelChanges;
|
||||
|
||||
@Override
|
||||
public String getPreconditionQuery() {
|
||||
return preconditionQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPreconditionQuery(String preconditionQuery) {
|
||||
this.preconditionQuery = preconditionQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RDFService.SPARQLQueryType getPreconditionQueryType() {
|
||||
return queryType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPreconditionQueryType(RDFService.SPARQLQueryType queryType) {
|
||||
this.queryType = queryType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ModelChange> getModelChanges() {
|
||||
return modelChanges;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAddition(InputStream model, RDFService.ModelSerializationFormat format, String graphURI) {
|
||||
modelChanges.add(manufactureModelChange(model,format, ModelChange.Operation.ADD, graphURI));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRemoval(InputStream model, RDFService.ModelSerializationFormat format, String graphURI) {
|
||||
modelChanges.add(manufactureModelChange(model, format, ModelChange.Operation.REMOVE, graphURI));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelChange manufactureModelChange() {
|
||||
return new ModelChangeImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelChange manufactureModelChange(InputStream serializedModel,
|
||||
RDFService.ModelSerializationFormat serializationFormat,
|
||||
Operation operation,
|
||||
String graphURI) {
|
||||
return new ModelChangeImpl(serializedModel, serializationFormat, operation, graphURI);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.rdfservice;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/*
|
||||
* A ModelChange is one component of a ChangeSet.
|
||||
* Represents a model (collection of RDF triples), the URI
|
||||
* of a graph, and an indication of whether to add or
|
||||
* remove the model from the graph.
|
||||
*/
|
||||
|
||||
public interface ModelChange {
|
||||
|
||||
public enum Operation {
|
||||
ADD, REMOVE
|
||||
}
|
||||
|
||||
abstract InputStream getSerializedModel();
|
||||
|
||||
public void setSerializedModel(InputStream serializedModel);
|
||||
|
||||
public RDFService.ModelSerializationFormat getSerializationFormat();
|
||||
|
||||
public void setSerializationFormat(RDFService.ModelSerializationFormat serializationFormat);
|
||||
|
||||
public Operation getOperation();
|
||||
|
||||
public void setOperation(Operation operation);
|
||||
|
||||
public String getGraphURI();
|
||||
|
||||
public void setGraphURI(String graphURI);
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.rdfservice;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/*
|
||||
* A ModelChange is one component of a ChangeSet.
|
||||
* Represents a model (collection of RDF triples), the URI
|
||||
* of a graph, and an indication of whether to add or
|
||||
* remove the model from the graph.
|
||||
*/
|
||||
public class ModelChangeImpl implements ModelChange {
|
||||
|
||||
private InputStream serializedModel;
|
||||
private RDFService.ModelSerializationFormat serializationFormat;
|
||||
private Operation operation;
|
||||
private String graphURI;
|
||||
|
||||
public ModelChangeImpl() {}
|
||||
|
||||
public ModelChangeImpl(InputStream serializedModel,
|
||||
RDFService.ModelSerializationFormat serializationFormat,
|
||||
Operation operation,
|
||||
String graphURI) {
|
||||
|
||||
this.serializedModel = serializedModel;
|
||||
this.serializationFormat = serializationFormat;
|
||||
this.operation = operation;
|
||||
this.graphURI = graphURI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getSerializedModel() {
|
||||
return serializedModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSerializedModel(InputStream serializedModel) {
|
||||
this.serializedModel = serializedModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RDFService.ModelSerializationFormat getSerializationFormat() {
|
||||
return serializationFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSerializationFormat(RDFService.ModelSerializationFormat serializationFormat) {
|
||||
this.serializationFormat = serializationFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOperation(Operation operation) {
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGraphURI() {
|
||||
return graphURI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGraphURI(String graphURI) {
|
||||
this.graphURI = graphURI;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.rdfservice;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* Interface for API to write, read, and update Vitro's RDF store, with support
|
||||
* to allow listening, logging and auditing.
|
||||
*/
|
||||
|
||||
public interface RDFService {
|
||||
|
||||
public enum SPARQLQueryType {
|
||||
SELECT, CONSTRUCT, DESCRIBE, ASK
|
||||
}
|
||||
|
||||
public enum ModelSerializationFormat {
|
||||
XML, N3
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a series of additions to and or removals from specified graphs
|
||||
* in the RDF store. For each change preConditionSparql will be executed
|
||||
* before the update is made and if it returns a non-empty result, no updates
|
||||
* will be made. The same preConditionSparql is used for each change/graph pair.
|
||||
*
|
||||
* @param ChangeSet - a set of changes to be performed on the RDF store.
|
||||
*/
|
||||
public void changeSetUpdate(ChangeSet changeSet) throws RDFServiceException;
|
||||
|
||||
/**
|
||||
* If the given individual already exists in the default graph, throws an
|
||||
* RDFServiceException, otherwise adds one type assertion to the default
|
||||
* graph.
|
||||
*
|
||||
* @param String individualURI - URI of the individual to be added
|
||||
* @param String individualTypeURI - URI of the type for the individual
|
||||
*/
|
||||
public void newIndividual(String individualURI, String individualTypeURI) throws RDFServiceException;
|
||||
|
||||
/**
|
||||
* If the given individual already exists in the given graph, throws an
|
||||
* RDFServiceException, otherwise adds one type assertion to the given
|
||||
* graph.
|
||||
*
|
||||
* @param String individualURI - URI of the individual to be added
|
||||
* @param String individualTypeURI - URI of the type for the individual
|
||||
* @param String graphURI - URI of the graph to which to add the individual
|
||||
*/
|
||||
public void newIndividual(String individualURI, String individualTypeURI, String graphURI) throws RDFServiceException;
|
||||
|
||||
/**
|
||||
* Performs a SPARQL query against the knowledge base. The query may have
|
||||
* an embedded graph identifier.
|
||||
*
|
||||
* @param String query - the SPARQL query to be executed against the RDF store
|
||||
* @param RDFService.SPARQLQueryType queryType - the type of SPARQL query (SELECT, CONSTRUCT, DESCRIBE, ASK)
|
||||
* @param RDFService.ModelSerializationFormat resultFormat - type of serialization for RDF result of the SPARQL query
|
||||
*
|
||||
* @return InputStream - the result of the SPARQL query
|
||||
*/
|
||||
public InputStream sparqlConstructQuery(String query, RDFService.SPARQLQueryType queryType, RDFService.ModelSerializationFormat resultFormat) throws RDFServiceException;
|
||||
|
||||
/**
|
||||
* Get a list of all the graph URIs in the RDF store.
|
||||
*
|
||||
* @return List<String> - list of all the graph URIs in the RDF store
|
||||
*/
|
||||
public List<String> getGraphURIs() throws RDFServiceException;
|
||||
|
||||
/**
|
||||
* TODO - what is the definition of this method?
|
||||
* @return
|
||||
*/
|
||||
public void getGraphMetadata() throws RDFServiceException;
|
||||
|
||||
/**
|
||||
* Get the URI of the default write graph
|
||||
*
|
||||
* @return String URI of default write graph
|
||||
*/
|
||||
public String getDefaultWriteGraphURI() throws RDFServiceException;
|
||||
|
||||
/**
|
||||
* Get the URI of the default read graph
|
||||
*
|
||||
* @return String URI of default read graph
|
||||
*/
|
||||
public String getDefaultReadGraphURI() throws RDFServiceException;
|
||||
|
||||
|
||||
/**
|
||||
* Create a ChangeSet object
|
||||
*
|
||||
* @return a ChangeSet object
|
||||
*/
|
||||
public ChangeSet manufactureChangeSet();
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.rdfservice;
|
||||
|
||||
public class RDFServiceException extends Exception {
|
||||
|
||||
public RDFServiceException() {
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue