use of won.protocol.exception.DataIntegrityException in project webofneeds by researchstudio-sat.
the class TensorEntrySparqlGenerator method generateTensorEntries.
public Collection<TensorEntry> generateTensorEntries() {
Collection<TensorEntry> tensorEntries = new LinkedList<>();
ParameterizedSparqlString pss = new ParameterizedSparqlString();
pss.setCommandText(query);
for (String key : parameterBindings.keySet()) {
Object value = parameterBindings.get(key);
if (value instanceof String) {
pss.setLiteral(key, (String) value);
} else if (value instanceof Long || value instanceof Integer) {
pss.setLiteral(key, (Long) value);
} else if (value instanceof Float || value instanceof Double) {
pss.setLiteral(key, (Double) value);
} else {
throw new IllegalArgumentException("Variable must be of type String/Long/Integer/Float/Double");
}
}
Query q = pss.asQuery();
QueryExecution qexec = QueryExecutionFactory.sparqlService(sparqlEndpoint, q);
ResultSet results = qexec.execSelect();
// check that the query returns the right variables
if (!results.getResultVars().containsAll(Arrays.asList(variableNames))) {
throw new DataIntegrityException("sparql query is expected to return variables: " + variableNames);
}
while (results.hasNext()) {
TensorEntry entry = new TensorEntry();
QuerySolution qs = results.next();
RDFNode node = qs.get("slice");
entry.setSliceName(node.isResource() ? node.asResource().getURI() : node.asLiteral().getString());
node = qs.get("need");
entry.setNeedUri(node.isResource() ? node.asResource().getURI() : node.asLiteral().getString());
node = qs.get("value");
entry.setValue(node.isResource() ? node.asResource().getURI() : node.asLiteral().getString());
tensorEntries.add(entry);
}
return tensorEntries;
}
use of won.protocol.exception.DataIntegrityException in project webofneeds by researchstudio-sat.
the class WonNodeSparqlService method getWonNodeInfoFromDataset.
/**
* Get the {@link won.protocol.service.WonNodeInfo} as an object from a {@link Dataset}
*
* @param ds Dataset which holds won node information
* @return
*/
public WonNodeInfo getWonNodeInfoFromDataset(Dataset ds) {
String dsWonNodeUri = getWonNodeUriFromDataset(ds);
WonNodeInfo nodeInfo = WonRdfUtils.WonNodeUtils.getWonNodeInfo(URI.create(dsWonNodeUri), ds);
if (nodeInfo == null) {
throw new DataIntegrityException("Could not load won node info from dataset with URI: " + dsWonNodeUri);
}
return nodeInfo;
}
use of won.protocol.exception.DataIntegrityException in project webofneeds by researchstudio-sat.
the class DatasetBackedOwnerCallbackAdapter method makeConnection.
@Override
protected Connection makeConnection(final WonMessage wonMessage) {
URI connUri = wonMessage.getReceiverURI();
ParameterizedSparqlString pss = new ParameterizedSparqlString();
pss.setNsPrefix("won", WON.BASE_URI);
pss.setCommandText(QUERY_CONNECTION);
pss.setIri("con", connUri.toString());
Query query = pss.asQuery();
QueryExecution qExec = QueryExecutionFactory.create(query, dataset);
qExec.getContext().set(TDB.symUnionDefaultGraph, true);
try {
Connection con = null;
final ResultSet results = qExec.execSelect();
if (results.hasNext()) {
QuerySolution soln = results.next();
if (results.hasNext()) {
throw new DataIntegrityException("Query must not yield multiple solutions");
}
con = new Connection();
con.setConnectionURI(getURIFromSolution(soln, "con"));
con.setTypeURI(getURIFromSolution(soln, "type"));
con.setNeedURI(getURIFromSolution(soln, "need"));
con.setState(ConnectionState.fromURI(getURIFromSolution(soln, "state")));
con.setRemoteNeedURI(getURIFromSolution(soln, "remoteNeed"));
con.setRemoteConnectionURI(getURIFromSolution(soln, "remoteCon"));
}
return con;
} finally {
if (!qExec.isClosed()) {
qExec.close();
}
}
}
Aggregations