From b45d20c9e49f0f865f739eab215e20d8bdb9c548 Mon Sep 17 00:00:00 2001 From: Ralph O'Flinn Date: Fri, 2 Aug 2019 12:20:15 -0500 Subject: [PATCH] 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 --- .../VitroLinkedDataFragmentServlet.java | 30 +++++++++++++++++-- .../checkstyle-suppressions.xml | 3 ++ .../config/example.runtime.properties | 5 ++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/org/vivoweb/linkeddatafragments/servlet/VitroLinkedDataFragmentServlet.java b/api/src/main/java/org/vivoweb/linkeddatafragments/servlet/VitroLinkedDataFragmentServlet.java index fe265022c..6e99778d0 100644 --- a/api/src/main/java/org/vivoweb/linkeddatafragments/servlet/VitroLinkedDataFragmentServlet.java +++ b/api/src/main/java/org/vivoweb/linkeddatafragments/servlet/VitroLinkedDataFragmentServlet.java @@ -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.modelaccess.ModelAccess; 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.jena.riot.Lang; +import org.apache.commons.lang3.StringUtils; import org.linkeddatafragments.config.ConfigReader; import org.linkeddatafragments.datasource.DataSourceFactory; import org.linkeddatafragments.datasource.DataSourceTypesRegistry; @@ -47,11 +49,15 @@ import java.util.Map.Entry; @WebServlet(name = "TpfServlet", urlPatterns = {"/tpf/*"}) 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 final HashMap dataSources = new HashMap<>(); private final Collection mimeTypes = new ArrayList<>(); + private ConfigurationProperties configProps; + private String tpfActiveFlag; private File getConfigFile(ServletConfig config) throws IOException { String path = config.getServletContext().getRealPath("/"); @@ -73,6 +79,16 @@ public class VitroLinkedDataFragmentServlet extends VitroHttpServlet { public void init(ServletConfig servletConfig) throws ServletException { try { 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(); 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 { String contextPath = request.getContextPath(); String requestURI = request.getRequestURI(); diff --git a/checkstyle/src/main/resources/vitro-checkstyle/checkstyle-suppressions.xml b/checkstyle/src/main/resources/vitro-checkstyle/checkstyle-suppressions.xml index ad64ea835..bc451e127 100644 --- a/checkstyle/src/main/resources/vitro-checkstyle/checkstyle-suppressions.xml +++ b/checkstyle/src/main/resources/vitro-checkstyle/checkstyle-suppressions.xml @@ -3,6 +3,9 @@ "-//Puppy Crawl//DTD Suppressions 1.1//EN" "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd"> + + + diff --git a/home/src/main/resources/config/example.runtime.properties b/home/src/main/resources/config/example.runtime.properties index 9822be25e..a0bf89a4f 100644 --- a/home/src/main/resources/config/example.runtime.properties +++ b/home/src/main/resources/config/example.runtime.properties @@ -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. # # 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