Merge branch 'maint-rel-1.6' of https://github.com/vivo-project/Vitro into maint-rel-1.6
This commit is contained in:
commit
03cc412c39
3 changed files with 40 additions and 41 deletions
|
@ -9,18 +9,16 @@ import java.util.Map;
|
|||
import org.apache.commons.logging.Log;
|
||||
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.ResultSet;
|
||||
import com.hp.hpl.jena.query.ResultSetFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
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.rdfservice.RDFService;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||
|
||||
/**
|
||||
* Utilities for executing queries and working with query results.
|
||||
|
@ -115,31 +113,21 @@ public class QueryUtils {
|
|||
}
|
||||
|
||||
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) {
|
||||
return getQueryResults(queryStr, vreq.getUnfilteredDataset());
|
||||
return getQueryResults(queryStr, vreq.getUnfilteredRDFService());
|
||||
}
|
||||
|
||||
/** Already have the dataset, so process the query and return the results. */
|
||||
private static ResultSet getQueryResults(String queryStr, Dataset dataset) {
|
||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||
QueryExecution qexec = null;
|
||||
ResultSet results = null;
|
||||
try {
|
||||
qexec = QueryExecutionFactory.create(queryStr, dataset);
|
||||
results = new ResultSetMem(qexec.execSelect());
|
||||
} catch (Exception e) {
|
||||
log.error(e, e);
|
||||
} finally {
|
||||
dataset.getLock().leaveCriticalSection();
|
||||
if (qexec != null) {
|
||||
qexec.close();
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
private static ResultSet getQueryResults(String queryStr, RDFService rdfService) {
|
||||
try {
|
||||
return ResultSetFactory.fromJSON(
|
||||
rdfService.sparqlSelectQuery(queryStr, RDFService.ResultFormat.JSON));
|
||||
} catch (RDFServiceException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -105,10 +105,7 @@ public class EditConfigurationUtils {
|
|||
|
||||
|
||||
public static ObjectProperty getObjectProperty(VitroRequest vreq) {
|
||||
//gets the predicate uri from the request
|
||||
String predicateUri = getPredicateUri(vreq);
|
||||
String rangeUri = getRangeUri(vreq);
|
||||
return getObjectPropertyForPredicate(vreq, predicateUri, rangeUri);
|
||||
return getObjectPropertyForPredicate(vreq, getPredicateUri(vreq));
|
||||
}
|
||||
|
||||
public static DataProperty getDataProperty(VitroRequest vreq) {
|
||||
|
@ -116,17 +113,18 @@ public class EditConfigurationUtils {
|
|||
return getDataPropertyForPredicate(vreq, predicateUri);
|
||||
}
|
||||
|
||||
public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq, String predicateUri) {
|
||||
return getObjectPropertyForPredicate(vreq, predicateUri, null);
|
||||
public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq,
|
||||
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();
|
||||
ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
||||
if (rangeUri != null) {
|
||||
objectProp.setRangeVClassURI(rangeUri);
|
||||
// TODO implement this in the DAO?
|
||||
}
|
||||
ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURIs(
|
||||
predicateUri, domainUri, rangeUri);
|
||||
return objectProp;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
|||
* requested.
|
||||
*
|
||||
* The stack trace is abbreviated. It will reach into this class, and will not
|
||||
* extend past the first reference to the ApplicationFilterChain. Perhaps it
|
||||
* should be abbreviated further?
|
||||
* extend past the first reference to the ApplicationFilterChain. It also omits
|
||||
* any Jena classes. Perhaps it should be abbreviated further?
|
||||
*/
|
||||
public class RDFServiceLogger implements AutoCloseable {
|
||||
private static final Log log = LogFactory.getLog(RDFServiceLogger.class);
|
||||
|
@ -96,6 +96,7 @@ public class RDFServiceLogger implements AutoCloseable {
|
|||
|
||||
trimStackTraceAtBeginning(list);
|
||||
trimStackTraceAtEnd(list);
|
||||
removeJenaClassesFromStackTrace(list);
|
||||
|
||||
if (list.isEmpty()) {
|
||||
this.methodName = "UNKNOWN";
|
||||
|
@ -104,6 +105,8 @@ public class RDFServiceLogger implements AutoCloseable {
|
|||
}
|
||||
|
||||
this.trace = list;
|
||||
log.debug("Stack array: " + Arrays.toString(stack));
|
||||
log.debug("Stack trace: " + this.trace);
|
||||
}
|
||||
|
||||
private void trimStackTraceAtBeginning(List<StackTraceElement> list) {
|
||||
|
@ -131,12 +134,22 @@ public class RDFServiceLogger implements AutoCloseable {
|
|||
}
|
||||
}
|
||||
|
||||
private void removeJenaClassesFromStackTrace(List<StackTraceElement> list) {
|
||||
ListIterator<StackTraceElement> iter = list.listIterator();
|
||||
while (iter.hasNext()) {
|
||||
StackTraceElement ste = iter.next();
|
||||
if (ste.getClassName().startsWith("com.hp.hpl.jena.")) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean passesRestrictions() {
|
||||
if (restriction == null) {
|
||||
return true;
|
||||
}
|
||||
for (StackTraceElement ste : trace) {
|
||||
if (restriction.matcher(ste.getClassName()).matches()) {
|
||||
if (restriction.matcher(ste.getClassName()).find()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -163,8 +176,8 @@ public class RDFServiceLogger implements AutoCloseable {
|
|||
|
||||
if (traceRequested) {
|
||||
for (StackTraceElement ste : trace) {
|
||||
sb.append(String.format("\n %d %s", ste.getLineNumber(),
|
||||
ste.getClassName()));
|
||||
sb.append(String.format("\n line %d4, %s",
|
||||
ste.getLineNumber(), ste.getClassName()));
|
||||
}
|
||||
sb.append("\n ...");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue