VIVO-1614 - Update to allow the TPF API to be toggled via the runtime.properties. (#127)
* Update to allow the TPF API to be toggled via the runtime.properties. Resolves: https://jira.duraspace.org/browse/VIVO-1614
This commit is contained in:
parent
1a2debe5c3
commit
b45d20c9e4
3 changed files with 36 additions and 2 deletions
|
@ -6,8 +6,10 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.jena.riot.Lang;
|
import org.apache.jena.riot.Lang;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.linkeddatafragments.config.ConfigReader;
|
import org.linkeddatafragments.config.ConfigReader;
|
||||||
import org.linkeddatafragments.datasource.DataSourceFactory;
|
import org.linkeddatafragments.datasource.DataSourceFactory;
|
||||||
import org.linkeddatafragments.datasource.DataSourceTypesRegistry;
|
import org.linkeddatafragments.datasource.DataSourceTypesRegistry;
|
||||||
|
@ -47,11 +49,15 @@ import java.util.Map.Entry;
|
||||||
@WebServlet(name = "TpfServlet", urlPatterns = {"/tpf/*"})
|
@WebServlet(name = "TpfServlet", urlPatterns = {"/tpf/*"})
|
||||||
public class VitroLinkedDataFragmentServlet extends VitroHttpServlet {
|
public class VitroLinkedDataFragmentServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
private final static long serialVersionUID = 1L;
|
private final static long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private static final String PROPERTY_TPF_ACTIVE_FLAG = "tpf.activeFlag";
|
||||||
|
|
||||||
private ConfigReader config;
|
private ConfigReader config;
|
||||||
private final HashMap<String, IDataSource> dataSources = new HashMap<>();
|
private final HashMap<String, IDataSource> dataSources = new HashMap<>();
|
||||||
private final Collection<String> mimeTypes = new ArrayList<>();
|
private final Collection<String> mimeTypes = new ArrayList<>();
|
||||||
|
private ConfigurationProperties configProps;
|
||||||
|
private String tpfActiveFlag;
|
||||||
|
|
||||||
private File getConfigFile(ServletConfig config) throws IOException {
|
private File getConfigFile(ServletConfig config) throws IOException {
|
||||||
String path = config.getServletContext().getRealPath("/");
|
String path = config.getServletContext().getRealPath("/");
|
||||||
|
@ -73,6 +79,16 @@ public class VitroLinkedDataFragmentServlet extends VitroHttpServlet {
|
||||||
public void init(ServletConfig servletConfig) throws ServletException {
|
public void init(ServletConfig servletConfig) throws ServletException {
|
||||||
try {
|
try {
|
||||||
ServletContext ctx = servletConfig.getServletContext();
|
ServletContext ctx = servletConfig.getServletContext();
|
||||||
|
configProps = ConfigurationProperties.getBean(ctx);
|
||||||
|
|
||||||
|
if (!configurationPresent()) {
|
||||||
|
throw new ServletException("TPF is currently disabled. To enable, add 'tpfActive.flag=true' to the runtime.properties.");
|
||||||
|
} else {
|
||||||
|
if (!tpfActiveFlag.equalsIgnoreCase("true")) {
|
||||||
|
throw new ServletException("TPF is currently disabled. To enable, set 'tpfActive.flag=true' in runtime.properties.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RDFService rdfService = ModelAccess.on(ctx).getRDFService();
|
RDFService rdfService = ModelAccess.on(ctx).getRDFService();
|
||||||
RDFServiceBasedRequestProcessorForTPFs.setRDFService(rdfService);
|
RDFServiceBasedRequestProcessorForTPFs.setRDFService(rdfService);
|
||||||
|
|
||||||
|
@ -120,6 +136,16 @@ public class VitroLinkedDataFragmentServlet extends VitroHttpServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean configurationPresent() {
|
||||||
|
String activeFlag = configProps.getProperty(PROPERTY_TPF_ACTIVE_FLAG);
|
||||||
|
if (StringUtils.isNotEmpty(activeFlag)) {
|
||||||
|
this.tpfActiveFlag = activeFlag;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private IDataSource getDataSource(HttpServletRequest request) throws DataSourceNotFoundException {
|
private IDataSource getDataSource(HttpServletRequest request) throws DataSourceNotFoundException {
|
||||||
String contextPath = request.getContextPath();
|
String contextPath = request.getContextPath();
|
||||||
String requestURI = request.getRequestURI();
|
String requestURI = request.getRequestURI();
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
|
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
|
||||||
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
|
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
|
||||||
<suppressions>
|
<suppressions>
|
||||||
|
<!-- For Debug Only -->
|
||||||
|
<!-- <suppress files=".+\.(?:txt|xml|csv|sh|thrift|html|sql|eot|ttf|woff|css|png|java|jar|zip|war|class|tar|bin|gif|jpg|jpeg|properties)$" checks=".*"/> -->
|
||||||
|
|
||||||
<!-- Suppressions for Javadoc in Test classes -->
|
<!-- Suppressions for Javadoc in Test classes -->
|
||||||
<suppress checks="JavadocMethod" files="src[/\\]test[/\\]java"/>
|
<suppress checks="JavadocMethod" files="src[/\\]test[/\\]java"/>
|
||||||
<suppress checks="JavadocType" files="src[/\\]test[/\\]java"/>
|
<suppress checks="JavadocType" files="src[/\\]test[/\\]java"/>
|
||||||
|
|
|
@ -153,3 +153,8 @@ proxy.eligibleTypeList = http://www.w3.org/2002/07/owl#Thing
|
||||||
# This should not be used with languages.forceLocale, which will override it.
|
# This should not be used with languages.forceLocale, which will override it.
|
||||||
#
|
#
|
||||||
# languages.selectableLocales = en, es, fr
|
# languages.selectableLocales = en, es, fr
|
||||||
|
|
||||||
|
# Triple pattern fragments is a very fast, very simple means for querying a triple store.
|
||||||
|
# The triple pattern fragments API in VIVO puts little load on the server, providing a simple means for getting data from the triple store. The API has a web interface for manual use, can be used from the command line via curl, and can be used by programs.
|
||||||
|
|
||||||
|
# tpf.activeFlag = true
|
||||||
|
|
Loading…
Add table
Reference in a new issue