[VIVO-1400] Add the capability to use / parse out precise-subquery tags.

This commit is contained in:
Graham Triggs 2017-10-12 09:30:37 +01:00
parent 107c2bff03
commit 792ca4138f
13 changed files with 78 additions and 7 deletions

View file

@ -254,6 +254,8 @@ public interface RDFService {
public Model getTriples(RDFNode subject, RDFNode predicate, RDFNode object, long limit, long offset) throws RDFServiceException;
public boolean preferPreciseOptionals();
/**
* Frees any resources held by this RDFService object
*

View file

@ -470,6 +470,11 @@ public class LanguageFilteringRDFService implements RDFService {
return s.getTriples(subject, predicate, object, limit, offset);
}
@Override
public boolean preferPreciseOptionals() {
return s.preferPreciseOptionals();
}
@Override
public void close() {
s.close();

View file

@ -306,6 +306,11 @@ public class SameAsFilteringRDFServiceFactory implements RDFServiceFactory {
return s.isEquivalentGraph(graphURI, graph);
}
@Override
public boolean preferPreciseOptionals() {
return s.preferPreciseOptionals();
}
@Override
public void close() {
s.close();

View file

@ -203,6 +203,11 @@ public class RDFServiceFactorySingle implements RDFServiceFactory {
return s.getTriples(subject, predicate, object, limit, offset);
}
@Override
public boolean preferPreciseOptionals() {
return s.preferPreciseOptionals();
}
@Override
public void close() {
// Don't close s. It's being used by everybody.

View file

@ -692,6 +692,10 @@ public abstract class RDFServiceJena extends RDFServiceImpl implements RDFServic
}
}
@Override
public boolean preferPreciseOptionals() {
return false;
}
@Override
public void close() {

View file

@ -273,6 +273,11 @@ public class RDFServiceSDB extends RDFServiceJena implements RDFService {
return super.getTriples(subject, predicate, object, limit, offset);
}
@Override
public boolean preferPreciseOptionals() {
return true;
}
@Override
public void close() {
if (conn != null) {

View file

@ -193,6 +193,11 @@ public class LoggingRDFService implements RDFService {
return innerService.getTriples(subject, predicate, object, limit, offset);
}
@Override
public boolean preferPreciseOptionals() {
return innerService.preferPreciseOptionals();
}
@Override
public void close() {
innerService.close();

View file

@ -909,6 +909,11 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
return graph.isIsomorphicWith(fromTripleStoreModel);
}
@Override
public boolean preferPreciseOptionals() {
return false;
}
protected HttpContext getContext(HttpRequestBase request) {
UsernamePasswordCredentials credentials = getCredentials();
if (credentials != null) {

View file

@ -20,6 +20,8 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
@ -56,6 +58,7 @@ public class CustomListViewConfigFile {
private static final String TAG_POSTPROCESSOR = "postprocessor";
private static final String TAG_COLLATED = "collated";
private static final String TAG_CRITICAL = "critical-data-required";
private static final String TAG_PRECISE = "precise-subquery";
// Will not be null. This is mutable, but don't modify it. Clone it and
// modify the clone.
@ -198,7 +201,7 @@ public class CustomListViewConfigFile {
}
}
public String getSelectQuery(boolean collated, boolean editing) {
public String getSelectQuery(boolean collated, boolean editing, boolean usePreciseSubquery) {
Element cloned = (Element) selectQueryElement.cloneNode(true);
if (!collated) {
@ -207,6 +210,9 @@ public class CustomListViewConfigFile {
if (editing) {
removeChildElements(cloned, TAG_CRITICAL);
}
if (!usePreciseSubquery) {
removeChildElements(cloned, TAG_PRECISE);
}
return cloned.getTextContent();
}

View file

@ -7,6 +7,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.util.Set;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -45,7 +46,6 @@ public class DataPropertyListConfig {
public DataPropertyListConfig(DataPropertyTemplateModel dptm, TemplateLoader templateLoader, VitroRequest vreq,
DataProperty dp, boolean editing)
throws InvalidConfigurationException {
this.dptm = dptm;
this.vreq = vreq;
WebappDaoFactory wadf = vreq.getWebappDaoFactory();
@ -125,7 +125,7 @@ public class DataPropertyListConfig {
FileReader reader = new FileReader(configFilePath);
CustomListViewConfigFile configFileContents = new CustomListViewConfigFile(reader);
selectQuery = configFileContents.getSelectQuery(false, editing);
selectQuery = configFileContents.getSelectQuery(false, editing, ListConfigUtils.getUsePreciseSubquery(vreq));
templateName = configFileContents.getTemplateName();
constructQueries = configFileContents.getConstructQueries();

View file

@ -0,0 +1,28 @@
/* $This file is distributed under the terms of the license in LICENSE$ */
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.sdb.RDFServiceSDB;
import org.apache.commons.lang3.StringUtils;
public final class ListConfigUtils {
private static Boolean usePrecise = null;
public static final boolean getUsePreciseSubquery(VitroRequest vreq) {
if (usePrecise == null) {
String usePreciseProp = ConfigurationProperties.getBean(vreq).getProperty("listview.usePreciseSubquery");
if (!StringUtils.isEmpty(usePreciseProp)) {
usePrecise = Boolean.parseBoolean(usePreciseProp);
} else if (vreq != null && vreq.getRDFService() != null) {
usePrecise = vreq.getRDFService().preferPreciseOptionals();
} else {
usePrecise = false;
}
}
return usePrecise;
}
}

View file

@ -8,6 +8,7 @@ import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.Set;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -140,7 +141,7 @@ public class PropertyListConfig {
boolean collated = optm instanceof CollatedObjectPropertyTemplateModel;
selectQuery = configFileContents.getSelectQuery(collated, editing);
selectQuery = configFileContents.getSelectQuery(collated, editing, ListConfigUtils.getUsePreciseSubquery(vreq));
templateName = configFileContents.getTemplateName();
constructQueries = configFileContents.getConstructQueries();

View file

@ -236,7 +236,7 @@ public class CustomListViewConfigFileTest extends AbstractTestClass {
String selectQuery, String[] constructQueries, String templateName,
String postprocessorName) {
assertEquals("select query", selectQuery,
configFile.getSelectQuery(collated, editing));
configFile.getSelectQuery(collated, editing, true));
assertEquals("construct queries",
new HashSet<String>(Arrays.asList(constructQueries)),
configFile.getConstructQueries());