Merge branch 'maint-rel-1.6' of git+ssh://github.com/vivo-project/Vitro into maint-rel-1.6
This commit is contained in:
commit
999e0c9008
2 changed files with 22 additions and 36 deletions
|
@ -9,18 +9,16 @@ import java.util.Map;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
|
||||||
import com.hp.hpl.jena.query.QueryExecution;
|
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
|
||||||
import com.hp.hpl.jena.query.QuerySolution;
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
|
import com.hp.hpl.jena.query.ResultSetFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
|
||||||
import com.hp.hpl.jena.sparql.resultset.ResultSetMem;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for executing queries and working with query results.
|
* Utilities for executing queries and working with query results.
|
||||||
|
@ -115,31 +113,21 @@ public class QueryUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResultSet getQueryResults(String queryStr, VitroRequest vreq) {
|
public static ResultSet getQueryResults(String queryStr, VitroRequest vreq) {
|
||||||
return getQueryResults(queryStr, vreq.getDataset());
|
return getQueryResults(queryStr, vreq.getRDFService());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResultSet getLanguageNeutralQueryResults(String queryStr, VitroRequest vreq) {
|
public static ResultSet getLanguageNeutralQueryResults(String queryStr, VitroRequest vreq) {
|
||||||
return getQueryResults(queryStr, vreq.getUnfilteredDataset());
|
return getQueryResults(queryStr, vreq.getUnfilteredRDFService());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Already have the dataset, so process the query and return the results. */
|
/** Already have the dataset, so process the query and return the results. */
|
||||||
private static ResultSet getQueryResults(String queryStr, Dataset dataset) {
|
private static ResultSet getQueryResults(String queryStr, RDFService rdfService) {
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
try {
|
||||||
QueryExecution qexec = null;
|
return ResultSetFactory.fromJSON(
|
||||||
ResultSet results = null;
|
rdfService.sparqlSelectQuery(queryStr, RDFService.ResultFormat.JSON));
|
||||||
try {
|
} catch (RDFServiceException e) {
|
||||||
qexec = QueryExecutionFactory.create(queryStr, dataset);
|
throw new RuntimeException(e);
|
||||||
results = new ResultSetMem(qexec.execSelect());
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e, e);
|
|
||||||
} finally {
|
|
||||||
dataset.getLock().leaveCriticalSection();
|
|
||||||
if (qexec != null) {
|
|
||||||
qexec.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,10 +105,7 @@ public class EditConfigurationUtils {
|
||||||
|
|
||||||
|
|
||||||
public static ObjectProperty getObjectProperty(VitroRequest vreq) {
|
public static ObjectProperty getObjectProperty(VitroRequest vreq) {
|
||||||
//gets the predicate uri from the request
|
return getObjectPropertyForPredicate(vreq, getPredicateUri(vreq));
|
||||||
String predicateUri = getPredicateUri(vreq);
|
|
||||||
String rangeUri = getRangeUri(vreq);
|
|
||||||
return getObjectPropertyForPredicate(vreq, predicateUri, rangeUri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataProperty getDataProperty(VitroRequest vreq) {
|
public static DataProperty getDataProperty(VitroRequest vreq) {
|
||||||
|
@ -116,17 +113,18 @@ public class EditConfigurationUtils {
|
||||||
return getDataPropertyForPredicate(vreq, predicateUri);
|
return getDataPropertyForPredicate(vreq, predicateUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq, String predicateUri) {
|
public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq,
|
||||||
return getObjectPropertyForPredicate(vreq, predicateUri, null);
|
String predicateUri) {
|
||||||
|
String domainUri = getDomainUri(vreq);
|
||||||
|
String rangeUri = getRangeUri(vreq);
|
||||||
|
return getObjectPropertyForPredicate(vreq, predicateUri, domainUri, rangeUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq, String predicateUri, String rangeUri) {
|
public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq,
|
||||||
|
String predicateUri, String domainUri, String rangeUri) {
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURIs(
|
||||||
if (rangeUri != null) {
|
predicateUri, domainUri, rangeUri);
|
||||||
objectProp.setRangeVClassURI(rangeUri);
|
|
||||||
// TODO implement this in the DAO?
|
|
||||||
}
|
|
||||||
return objectProp;
|
return objectProp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue