to build Vitro and deploy to Tomcat's webapps directory.
+
+ The build script may run for as much as five minutes,
+ and creates more than 100 lines of output.
+ The process comprises several steps:
+
+
collecting the source files from the distribution directory,
+
compiling the Java source code,
+
compiling and running unit tests,
+
preparing the Solr search engine,
+
deploying Vitro and Solr to Tomcat.
+
+
+
+ The output of the build may include a variety of warning messages.
+ The Java compiler may warn of code that is outdated.
+ Unit tests may produce warning messages,
+ and some tests may be ignored if they do not produce consistent results.
+
+
+ BUILD SUCCESSFUL Total time: 1 minute 49 seconds
+
+
+ If the output ends with a success message, the build was successful.
+ Proceed to the next step.
+
+
+ BUILD FAILED Total time: 35 seconds
+
+
+ If the output ends with a failure message, the build has failed.
+ Find the cause of the failure, fix the problem, and run the script again.
+
+
VII. Configure Tomcat
Set JVM parameters
diff --git a/solr/homeDirectoryTemplate/conf/schema.xml b/solr/homeDirectoryTemplate/conf/schema.xml
index bc5fcad66..25517dd91 100644
--- a/solr/homeDirectoryTemplate/conf/schema.xml
+++ b/solr/homeDirectoryTemplate/conf/schema.xml
@@ -194,6 +194,9 @@
+
+
+
@@ -217,16 +220,10 @@
-
-
-
-
-
diff --git a/webapp/build.xml b/webapp/build.xml
index a144f0665..05e3edec9 100644
--- a/webapp/build.xml
+++ b/webapp/build.xml
@@ -1,522 +1,514 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- The Vitro build script requires Java 7 or later.
- Java system property java.version = ${java.version}
- Java system property java.home = ${java.home}
- JAVA_HOME environment variable = ${env.JAVA_HOME}
-
-
-
-
-
-
-
-
-
- The Vitro build script requires Ant 1.8 or later.
- Ant property ant.version = ${ant.version}
- Ant property ant.home = ${ant.home}
- ANT_HOME environment variable = ${env.ANT_HOME}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ${revisionInfo.timestamp}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-all - Runs "clean", then "deploy".
-clean - Delete all artifacts so the next build will be from scratch.
-compile - Compile the Java source files.
-orng - Configure and deploy the ORNG Shindig application.
-test - Compile and run the JUnit tests.
-distribute - Create WAR files to be deployed in a servlet container.
-deploy - Deploy the application directly into the Tomcat webapps directory.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The Vitro build script requires Java 7 or later.
+ Java system property java.version = ${java.version}
+ Java system property java.home = ${java.home}
+ JAVA_HOME environment variable = ${env.JAVA_HOME}
+
+
+
+
+
+
+
+
+
+ The Vitro build script requires Ant 1.8 or later.
+ Ant property ant.version = ${ant.version}
+ Ant property ant.home = ${ant.home}
+ ANT_HOME environment variable = ${env.ANT_HOME}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ${revisionInfo.timestamp}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+all - Runs "clean", then "deploy".
+clean - Delete all artifacts so the next build will be from scratch.
+compile - Compile the Java source files.
+orng - Configure and deploy the ORNG Shindig application.
+test - Compile and run the JUnit tests.
+distribute - Create WAR files to be deployed in a servlet container.
+deploy - Deploy the application directly into the Tomcat webapps directory.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/permissions/SimplePermission.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/permissions/SimplePermission.java
index f3e9b2618..80b32b478 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/permissions/SimplePermission.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/permissions/SimplePermission.java
@@ -74,6 +74,15 @@ public class SimplePermission extends Permission {
"SeeVerbosePropertyInformation");
public static final SimplePermission USE_ADVANCED_DATA_TOOLS_PAGES = new SimplePermission(
"UseAdvancedDataToolsPages");
+ public static final SimplePermission USE_SPARQL_QUERY_PAGE = new SimplePermission(
+ "UseSparqlQueryPage");
+
+ // ----------------------------------------------------------------------
+ // These instances are "catch all" permissions to cover poorly defined
+ // groups of actions until better definitions were found. Don't add usages
+ // of these, and remove existing usages where possible.
+ // ----------------------------------------------------------------------
+
public static final SimplePermission USE_BASIC_AJAX_CONTROLLERS = new SimplePermission(
"UseBasicAjaxControllers");
public static final SimplePermission USE_MISCELLANEOUS_ADMIN_PAGES = new SimplePermission(
@@ -84,8 +93,6 @@ public class SimplePermission extends Permission {
"UseMiscellaneousEditorPages");
public static final SimplePermission USE_MISCELLANEOUS_PAGES = new SimplePermission(
"UseMiscellaneousPages");
- public static final SimplePermission USE_SPARQL_QUERY_PAGE = new SimplePermission(
- "UseSparqlQueryPage");
public static List getAllInstances() {
return new ArrayList(allInstances.values());
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerConfiguration.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerConfiguration.java
index c6bc10185..b358b87b6 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerConfiguration.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerConfiguration.java
@@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -28,6 +29,8 @@ import edu.cornell.mannlib.vitro.webapp.i18n.freemarker.I18nMethodModel;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
import edu.cornell.mannlib.vitro.webapp.web.directives.IndividualShortViewDirective;
+import edu.cornell.mannlib.vitro.webapp.web.directives.UrlDirective;
+import edu.cornell.mannlib.vitro.webapp.web.directives.WidgetDirective;
import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualLocalNameMethod;
import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualPlaceholderImageUrlMethod;
import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualProfileUrlMethod;
@@ -166,16 +169,20 @@ public class FreemarkerConfiguration extends Configuration {
return urls;
}
- public static Map getDirectives() {
+ private static Map getDirectives() {
Map map = new HashMap();
map.put("dump", new freemarker.ext.dump.DumpDirective());
map.put("dumpAll", new freemarker.ext.dump.DumpAllDirective());
map.put("help", new freemarker.ext.dump.HelpDirective());
map.put("shortView", new IndividualShortViewDirective());
+ map.put("url", new UrlDirective());
+ map.put("widget", new WidgetDirective());
+
+
return map;
}
- public static Map getMethods() {
+ private static Map getMethods() {
Map map = new HashMap();
map.put("profileUrl", new IndividualProfileUrlMethod());
map.put("localName", new IndividualLocalNameMethod());
@@ -319,4 +326,54 @@ public class FreemarkerConfiguration extends Configuration {
}
}
+ // ----------------------------------------------------------------------
+ // Request info and overrides
+ // ----------------------------------------------------------------------
+
+ private ThreadLocal reqInfo = new ThreadLocal<>();
+
+ void setRequestInfo(HttpServletRequest req) {
+ reqInfo.set(new FreemarkerRequestInfo(req));
+ }
+
+ @Override
+ public Object getCustomAttribute(String name) {
+ if ("request".equals(name)) {
+ return reqInfo.get().getRequest();
+ } else {
+ return super.getCustomAttribute(name);
+ }
+ }
+
+ @Override
+ public String[] getCustomAttributeNames() {
+ String[] nameArray = super.getCustomAttributeNames();
+ Set nameSet = new HashSet(Arrays.asList(nameArray));
+ nameSet.add("request");
+ return nameSet.toArray(new String[nameSet.size()]);
+ }
+
+ @Override
+ public Locale getLocale() {
+ return reqInfo.get().getLocale();
+ }
+
+
+
+ public static class FreemarkerRequestInfo {
+ private final HttpServletRequest req;
+
+ public FreemarkerRequestInfo(HttpServletRequest req) {
+ this.req = req;
+ }
+
+ public HttpServletRequest getRequest() {
+ return req;
+ }
+
+ public Locale getLocale() {
+ return req.getLocale();
+ }
+ }
+
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerConfigurationLoader.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerConfigurationLoader.java
index b4e206181..340686d19 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerConfigurationLoader.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerConfigurationLoader.java
@@ -21,7 +21,9 @@ public class FreemarkerConfigurationLoader {
public static FreemarkerConfiguration getConfig(VitroRequest vreq) {
String themeDir = getThemeDir(vreq.getAppBean());
- return getConfigForTheme(themeDir, vreq.getAppBean(), vreq.getSession().getServletContext());
+ FreemarkerConfiguration config = getConfigForTheme(themeDir, vreq.getAppBean(), vreq.getSession().getServletContext());
+ config.setRequestInfo(vreq);
+ return config;
}
private static String getThemeDir(ApplicationBean appBean) {
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java
index 552846a98..3cf0faeb0 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java
@@ -427,10 +427,6 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
// the copyright text can be viewed with having to restart Tomcat
map.put("copyright", getCopyrightInfo(appBean));
- map.put("url", new edu.cornell.mannlib.vitro.webapp.web.directives.UrlDirective());
- map.put("widget", new edu.cornell.mannlib.vitro.webapp.web.directives.WidgetDirective());
- map.putAll( FreemarkerConfiguration.getDirectives() );
-
// Add these accumulator objects. They will collect tags so the template can write them
// at the appropriate location.
map.put("stylesheets", new Tags().wrap());
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java
index c1fd229f3..828b09555 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java
@@ -24,13 +24,9 @@ public class TemplateProcessingHelper {
private static final Log log = LogFactory.getLog(TemplateProcessingHelper.class);
private Configuration config = null;
- private HttpServletRequest request = null;
- private ServletContext context = null;
public TemplateProcessingHelper(HttpServletRequest request, ServletContext context) {
this.config = FreemarkerConfigurationLoader.getConfig(new VitroRequest(request));
- this.request = request;
- this.context = context;
}
public StringWriter processTemplate(String templateName, Map map)
@@ -46,14 +42,6 @@ public class TemplateProcessingHelper {
try {
Environment env = template.createProcessingEnvironment(map, writer);
- // Add request and servlet context as custom attributes of the environment, so they
- // can be used in directives.
- env.setCustomAttribute("request", request);
- env.setCustomAttribute("context", context);
-
- // Set the Locale from the request into the environment, so date builtins will be
- // Locale-dependent
- env.setLocale(request.getLocale());
// Define a setup template to be included by every page template
String templateType = (String) map.get("templateType");
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetDataForPage.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetDataForPage.java
deleted file mode 100644
index 632a0a611..000000000
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetDataForPage.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/* $This file is distributed under the terms of the license in /doc/license.txt$ */
-
-package edu.cornell.mannlib.vitro.webapp.controller.json;
-
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.json.JSONObject;
-
-import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
-import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils;
-
-/**
- * Gets data based on data getter for page uri and returns in the form of Json objects
- */
-public class GetDataForPage extends JsonObjectProducer {
- private static final Log log = LogFactory.getLog(GetDataForPage.class);
-
- protected GetDataForPage(VitroRequest vreq) {
- super(vreq);
- }
-
- @Override
- protected JSONObject process() throws Exception {
- JSONObject rObj = null;
- String pageUri = vreq.getParameter("pageUri");
- if(pageUri != null && !pageUri.isEmpty()) {
- Map data = PageDataGetterUtils.getDataForPage(pageUri, vreq, ctx);
- //Convert to json version based on type of page
- if(data != null) {
- //Convert to json version based on type of page
- rObj = PageDataGetterUtils.covertDataToJSONForPage(pageUri, data, vreq, ctx);
- }
- }
- return rObj;
- }
-
-}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java
index 2fbd9d09f..3f516e109 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java
@@ -3,8 +3,11 @@
package edu.cornell.mannlib.vitro.webapp.controller.json;
import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Enumeration;
import java.util.List;
import java.util.Map;
@@ -15,17 +18,21 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.json.JSONArray;
import org.json.JSONObject;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
+import edu.cornell.mannlib.vitro.webapp.beans.VClass;
+import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController;
+import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.PageRecord;
+import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.utils.log.LogUtils;
-import edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.PageDataGetterUtils;
/**
* This servlet is for servicing requests for JSON objects/data.
@@ -69,7 +76,9 @@ public class JsonServlet extends VitroHttpServlet {
log.debug("AJAX request to retrieve individuals by vclasses");
new GetSolrIndividualsByVClasses(vreq).process(resp);
} else if( vreq.getParameter("getDataForPage") != null ){
- new GetDataForPage(vreq).process(resp);
+ throw new IllegalArgumentException("The call invoked deprecated classes " +
+ "and the parameter for this call appeared nowhere in the code base, " +
+ "so it was removed in Aug 5th 2013.");
}else if( vreq.getParameter("getRenderedSolrIndividualsByVClass") != null ){
new GetRenderedSolrIndividualsByVClass(vreq).process(resp);
}else if( vreq.getParameter("getRandomSolrIndividualsByVClass") != null ){
@@ -85,7 +94,7 @@ public class JsonServlet extends VitroHttpServlet {
Map map = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
//last parameter indicates single vclass instead of multiple vclasses
- return processVClassResults(map, vreq, context, false);
+ return processVclassResultsJSON(map, vreq, false);
}
public static JSONObject getSolrIndividualsByVClasses(List vclassURIs, HttpServletRequest req, ServletContext context) throws Exception {
@@ -93,8 +102,8 @@ public class JsonServlet extends VitroHttpServlet {
log.debug("Retrieve solr results for vclasses" + vclassURIs.toString());
Map map = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
log.debug("Results returned from Solr for " + vclassURIs.toString() + " are of size " + map.size());
- JSONObject rObj = processVClassResults(map, vreq, context, true);
- return rObj;
+
+ return processVclassResultsJSON(map, vreq, true);
}
//Including version for Solr query for Vclass Intersections
@@ -119,10 +128,10 @@ public class JsonServlet extends VitroHttpServlet {
}
// Map given to process method includes the actual individuals returned from the search
- public static JSONObject processVClassResults(Map map, VitroRequest vreq, ServletContext context, boolean multipleVclasses) throws Exception{
- JSONObject rObj = PageDataGetterUtils.processVclassResultsJSON(map, vreq, multipleVclasses);
- return rObj;
- }
+// public static JSONObject processVClassResults(Map map, VitroRequest vreq, ServletContext context, boolean multipleVclasses) throws Exception{
+// JSONObject rObj = processVclassResultsJSON(map, vreq, multipleVclasses);
+// return rObj;
+// }
public static Collection getMostSpecificTypes(Individual individual, WebappDaoFactory wdf) {
ObjectPropertyStatementDao opsDao = wdf.getObjectPropertyStatementDao();
@@ -143,7 +152,7 @@ public class JsonServlet extends VitroHttpServlet {
Map map = getRandomSolrVClassResults(vclassURI, vreq, context);
//last parameter indicates single vclass instead of multiple vclasses
- return processVClassResults(map, vreq, context, false);
+ return processVclassResultsJSON(map, vreq, false);
}
//Including version for Random Solr query for Vclass Intersections
@@ -169,4 +178,120 @@ public class JsonServlet extends VitroHttpServlet {
}
+ /**
+ * Process results related to VClass or vclasses. Handles both single and multiple vclasses being sent.
+ */
+ public static JSONObject processVclassResultsJSON(Map map, VitroRequest vreq, boolean multipleVclasses) {
+ JSONObject rObj = new JSONObject();
+ VClass vclass=null;
+
+ try {
+
+ // Properties from ontologies used by VIVO - should not be in vitro
+ DataProperty fNameDp = (new DataProperty());
+ fNameDp.setURI("http://xmlns.com/foaf/0.1/firstName");
+ DataProperty lNameDp = (new DataProperty());
+ lNameDp.setURI("http://xmlns.com/foaf/0.1/lastName");
+ DataProperty preferredTitleDp = (new DataProperty());
+ preferredTitleDp.setURI("http://vivoweb.org/ontology/core#preferredTitle");
+
+ if( log.isDebugEnabled() ){
+ @SuppressWarnings("unchecked")
+ Enumeration e = vreq.getParameterNames();
+ while(e.hasMoreElements()){
+ String name = e.nextElement();
+ log.debug("parameter: " + name);
+ for( String value : vreq.getParameterValues(name) ){
+ log.debug("value for " + name + ": '" + value + "'");
+ }
+ }
+ }
+
+ //need an unfiltered dao to get firstnames and lastnames
+ WebappDaoFactory fullWdf = vreq.getUnfilteredWebappDaoFactory();
+
+ String[] vitroClassIdStr = vreq.getParameterValues("vclassId");
+ if ( vitroClassIdStr != null && vitroClassIdStr.length > 0){
+ for(String vclassId: vitroClassIdStr) {
+ vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassId);
+ if (vclass == null) {
+ log.error("Couldn't retrieve vclass ");
+ throw new Exception ("Class " + vclassId + " not found");
+ }
+ }
+ }else{
+ log.error("parameter vclassId URI parameter expected ");
+ throw new Exception("parameter vclassId URI parameter expected ");
+ }
+ List vclassIds = Arrays.asList(vitroClassIdStr);
+ //if single vclass expected, then include vclass. This relates to what the expected behavior is, not size of list
+ if(!multipleVclasses) {
+ //currently used for ClassGroupPage
+ rObj.put("vclass",
+ new JSONObject().put("URI",vclass.getURI())
+ .put("name",vclass.getName()));
+ } else {
+ //For now, utilize very last VClass (assume that that is the one to be employed)
+ //TODO: Find more general way of dealing with this
+ //put multiple ones in?
+ if(vclassIds.size() > 0) {
+ int numberVClasses = vclassIds.size();
+ vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassIds.get(numberVClasses - 1));
+ rObj.put("vclass", new JSONObject().put("URI",vclass.getURI())
+ .put("name",vclass.getName()));
+ }
+ // rObj.put("vclasses", new JSONObject().put("URIs",vitroClassIdStr)
+ // .put("name",vclass.getName()));
+ }
+ if (vclass != null) {
+
+ rObj.put("totalCount", map.get("totalCount"));
+ rObj.put("alpha", map.get("alpha"));
+
+ List inds = (List)map.get("entities");
+ log.debug("Number of individuals returned from request: " + inds.size());
+ JSONArray jInds = new JSONArray();
+ for(Individual ind : inds ){
+ JSONObject jo = new JSONObject();
+ jo.put("URI", ind.getURI());
+ jo.put("label",ind.getRdfsLabel());
+ jo.put("name",ind.getName());
+ jo.put("thumbUrl", ind.getThumbUrl());
+ jo.put("imageUrl", ind.getImageUrl());
+ jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq));
+
+ jo.put("mostSpecificTypes", JsonServlet.getMostSpecificTypes(ind,fullWdf));
+ jo.put("preferredTitle", JsonServlet.getDataPropertyValue(ind, preferredTitleDp, fullWdf));
+
+ jInds.put(jo);
+ }
+ rObj.put("individuals", jInds);
+
+ JSONArray wpages = new JSONArray();
+ //Made sure that PageRecord here is SolrIndividualListController not IndividualListController
+ List pages = (List)map.get("pages");
+ for( PageRecord pr: pages ){
+ JSONObject p = new JSONObject();
+ p.put("text", pr.text);
+ p.put("param", pr.param);
+ p.put("index", pr.index);
+ wpages.put( p );
+ }
+ rObj.put("pages",wpages);
+
+ JSONArray jletters = new JSONArray();
+ List letters = Controllers.getLetters();
+ for( String s : letters){
+ JSONObject jo = new JSONObject();
+ jo.put("text", s);
+ jo.put("param", "alpha=" + URLEncoder.encode(s, "UTF-8"));
+ jletters.put( jo );
+ }
+ rObj.put("letters", jletters);
+ }
+ } catch(Exception ex) {
+ log.error("Error occurred in processing JSON object", ex);
+ }
+ return rObj;
+ }
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/email/FreemarkerEmailMessage.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/email/FreemarkerEmailMessage.java
index 0dd14a2f3..1b3cd9a53 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/email/FreemarkerEmailMessage.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/email/FreemarkerEmailMessage.java
@@ -30,8 +30,6 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration;
import edu.cornell.mannlib.vitro.webapp.web.directives.EmailDirective;
-import freemarker.core.Environment;
-import freemarker.template.Template;
import freemarker.template.TemplateException;
/**
@@ -144,14 +142,8 @@ public class FreemarkerEmailMessage {
bodyMap.put("email", new EmailDirective(this));
try {
- Template template = config.getTemplate(templateName);
-
- Environment env = template.createProcessingEnvironment(bodyMap,
+ config.getTemplate(templateName).process(bodyMap,
new StringWriter());
- env.setCustomAttribute("request", vreq);
- env.setCustomAttribute("context", vreq.getSession()
- .getServletContext());
- env.process();
} catch (TemplateException e) {
log.error(e, e);
} catch (IOException e) {
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/FileUploadServletRequest.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/FileUploadServletRequest.java
index 6ecba1d70..ae34cabf8 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/FileUploadServletRequest.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/FileUploadServletRequest.java
@@ -3,8 +3,15 @@
package edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
@@ -12,6 +19,8 @@ import javax.servlet.http.HttpServletRequestWrapper;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
*
@@ -44,21 +53,39 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload;
*/
@SuppressWarnings("deprecation")
public abstract class FileUploadServletRequest extends HttpServletRequestWrapper {
+
+ private static final Log log = LogFactory
+ .getLog(FileUploadServletRequest.class);
+
public static final String FILE_ITEM_MAP = "file_item_map";
public static final String FILE_UPLOAD_EXCEPTION = "file_upload_exception";
+ private Map> parameters;
+ private Map> files;
+ private FileUploadException fileUploadException;
+
+ private static final String[] EMPTY_ARRAY = new String[0];
+
// ----------------------------------------------------------------------
// The factory method
// ----------------------------------------------------------------------
/**
* Wrap this {@link HttpServletRequest} in an appropriate wrapper class.
+ * set maxTempFileSize to 0 or -1 if streaming is desired. Set it to > 0 if
+ * you want any parts uploaded to a temporary directory
*/
- public static FileUploadServletRequest parseRequest(
- HttpServletRequest request, int maxFileSize) throws IOException {
+ public static FileUploadServletRequest parseRequest(
+ HttpServletRequest request, int maxTempFileSize) throws IOException {
+
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
+
if (isMultipart) {
- return new MultipartHttpServletRequest(request, maxFileSize);
+ if( maxTempFileSize <= 0 ){
+ return new StreamingMultipartHttpServletRequest(request);
+ }else{
+ return new MultipartHttpServletRequest(request, maxTempFileSize);
+ }
} else {
return new SimpleHttpServletRequestWrapper(request);
}
@@ -85,29 +112,184 @@ public abstract class FileUploadServletRequest extends HttpServletRequestWrapper
/** Was this a multipart HTTP request? */
public abstract boolean isMultipart();
+
+ protected void stashParametersInRequest(HttpServletRequest request, ServletFileUpload upload){
+ Map> parameters = new HashMap>();
+ Map> files = new HashMap>();
+
+ parseQueryString(request.getQueryString(), parameters);
+
+ try {
+ List items = upload.parseRequest( request );
+
+ for (FileItem item : items) {
+ // Process a regular form field
+ if (item.isFormField()) {
+ addToParameters(parameters, item.getFieldName(), item
+ .getString("UTF-8"));
+ log.debug("Form field (parameter) " + item.getFieldName()
+ + "=" + item.getString());
+ } else {
+ addToFileItems(files, item);
+ log.debug("File " + item.getFieldName() + ": "
+ + item.getName());
+ }
+ }
+ } catch (FileUploadException e) {
+ fileUploadException = e;
+ request.setAttribute(
+ FileUploadServletRequest.FILE_UPLOAD_EXCEPTION, e);
+ } catch (UnsupportedEncodingException e) {
+ log.error("could not convert to UTF-8",e);
+ }
+
+ this.parameters = Collections.unmodifiableMap(parameters);
+ log.debug("Parameters are: " + this.parameters);
+ this.files = Collections.unmodifiableMap(files);
+ log.debug("Files are: " + this.files);
+ request.setAttribute(FILE_ITEM_MAP, this.files);
+ }
+
+
/**
- * Get the map of file items, by name.
+ * Pull any parameters out of the URL.
*/
- public abstract Map> getFiles();
+ private void parseQueryString(String queryString,
+ Map> parameters) {
+ log.debug("Query string is : '" + queryString + "'");
+ if (queryString != null) {
+ String[] pieces = queryString.split("&");
+
+ for (String piece : pieces) {
+ int equalsHere = piece.indexOf('=');
+ if (piece.trim().isEmpty()) {
+ // Ignore an empty piece.
+ } else if (equalsHere <= 0) {
+ // A parameter without a value.
+ addToParameters(parameters, decode(piece), "");
+ } else {
+ // A parameter with a value.
+ String key = piece.substring(0, equalsHere);
+ String value = piece.substring(equalsHere + 1);
+ addToParameters(parameters, decode(key), decode(value));
+ }
+ }
+ }
+ log.debug("Parameters from query string are: " + parameters);
+ }
/**
- * Find a non-empty file item with this name.
- *
- * @return the first such file item, or null if no matching,
- * non-empty items were found.
+ * Remove any special URL-style encoding.
*/
- public abstract FileItem getFileItem(String string);
+ private String decode(String encoded) {
+ try {
+ return URLDecoder.decode(encoded, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ log.error(e, e);
+ return encoded;
+ }
+ }
- /**
- * Was there an exception when uploading the file items?
- */
- public abstract boolean hasFileUploadException();
- /**
- * Get the exception that occurred when uploading the file items. If no such
- * exception, return null.
- */
- public abstract FileUploadException getFileUploadException();
+ /** Either create a new List for the value, or add to an existing List. */
+ private void addToParameters(Map> map, String name,
+ String value) {
+ if (!map.containsKey(name)) {
+ map.put(name, new ArrayList());
+ }
+ map.get(name).add(value);
+ }
+
+ /** Either create a new List for the file, or add to an existing List. */
+ private void addToFileItems(Map> map, FileItem file) {
+ String name = file.getFieldName();
+ if (!map.containsKey(name)) {
+ map.put(name, new ArrayList());
+ }
+ map.get(name).add(file);
+ }
+
+
+ public FileUploadException getFileUploadException() {
+ return fileUploadException;
+ }
+
+ public boolean hasFileUploadException() {
+ return fileUploadException != null;
+ }
+
+ // ----------------------------------------------------------------------
+ // Parameter-related methods won't find anything on the delegate request,
+ // since parsing consumed the parameters. So we need to look to the parsed
+ // info for the answers.
+ // ----------------------------------------------------------------------
+
+ @Override
+ public String getParameter(String name) {
+ if (parameters.containsKey(name)) {
+ return parameters.get(name).get(0);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Enumeration> getParameterNames() {
+ return Collections.enumeration(parameters.keySet());
+ }
+
+ @Override
+ public String[] getParameterValues(String name) {
+ if (parameters.containsKey(name)) {
+ return parameters.get(name).toArray(EMPTY_ARRAY);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Map getParameterMap() {
+ Map result = new HashMap();
+ for (Entry> entry : parameters.entrySet()) {
+ result.put(entry.getKey(), entry.getValue().toArray(EMPTY_ARRAY));
+ }
+ log.debug("resulting parameter map: " + result);
+ return result;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * There may be more than one file item with the given name. If the first
+ * one is empty (size is zero), keep looking for a non-empty one.
+ *
+ */
+ public FileItem getFileItem(String name) {
+ List items = files.get(name);
+ if (items == null) {
+ return null;
+ }
+
+ for (FileItem item : items) {
+ if (item.getSize() > 0L) {
+ return item;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Gets a map of parameter names to files.
+ * This will should return null.
+ */
+ public Map> getFiles() {
+ if( files == null )
+ return Collections.emptyMap();
+ else
+ return files;
+ }
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/MultipartHttpServletRequest.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/MultipartHttpServletRequest.java
index 95f96f10a..a276e2275 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/MultipartHttpServletRequest.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/MultipartHttpServletRequest.java
@@ -33,33 +33,8 @@ public class MultipartHttpServletRequest extends FileUploadServletRequest {
private static final Log log = LogFactory
.getLog(MultipartHttpServletRequest.class);
- private static final String[] EMPTY_ARRAY = new String[0];
-
- private Map> parameters;
- private Map> files;
- private FileUploadException fileUploadException;
-
- private boolean storeFilesToTempDir = false;
private int maxFileSize = 0;
- private File tempDir = null;
-
- /**
- * Parse the multipart request. Store the info about the request parameters.
- * Don't store the uploaded files to a temporary directory to allow streaming.
- *
- * Only use this constructor if you plan to consume the FileItems using streaming
- * to deal with inputs of very large sizes.
- *
- * In all other case you should use the maxFileSize constructor to deal with
- * the size of the uploaded file in a safe way.
- */
- public MultipartHttpServletRequest(HttpServletRequest request)
- throws IOException{
- super(request);
- storeFilesToTempDir = false;
- setup(request);
-
- }
+ private File tempDir = null;
/**
* Parse the multipart request. Store the info about the request parameters
@@ -71,93 +46,16 @@ public class MultipartHttpServletRequest extends FileUploadServletRequest {
public MultipartHttpServletRequest(HttpServletRequest request,
int maxFileSize) throws IOException {
super(request);
- storeFilesToTempDir = true;
+
this.maxFileSize = maxFileSize;
this.tempDir = figureTemporaryDirectory(request);
- setup(request);
- }
-
- private void setup(HttpServletRequest request){
- Map> parameters = new HashMap>();
- Map> files = new HashMap>();
-
- ServletFileUpload upload = createUploadHandler();
-
- //File tempDir = figureTemporaryDirectory(request);
- //ServletFileUpload upload = createUploadHandler(maxFileSize, tempDir);
-
- parseQueryString(request.getQueryString(), parameters);
-
- try {
- List items = parseRequestIntoFileItems(request, upload);
-
- for (FileItem item : items) {
- // Process a regular form field
- if (item.isFormField()) {
- addToParameters(parameters, item.getFieldName(), item
- .getString("UTF-8"));
- log.debug("Form field (parameter) " + item.getFieldName()
- + "=" + item.getString());
- } else {
- addToFileItems(files, item);
- log.debug("File " + item.getFieldName() + ": "
- + item.getName());
- }
- }
- } catch (FileUploadException e) {
- fileUploadException = e;
- request.setAttribute(
- FileUploadServletRequest.FILE_UPLOAD_EXCEPTION, e);
- } catch (UnsupportedEncodingException e) {
- log.error("could not convert to UTF-8",e);
- }
-
- this.parameters = Collections.unmodifiableMap(parameters);
- log.debug("Parameters are: " + this.parameters);
- this.files = Collections.unmodifiableMap(files);
- log.debug("Files are: " + this.files);
- request.setAttribute(FILE_ITEM_MAP, this.files);
- }
-
- /**
- * Pull any parameters out of the URL.
- */
- private void parseQueryString(String queryString,
- Map> parameters) {
- log.debug("Query string is : '" + queryString + "'");
- if (queryString != null) {
- String[] pieces = queryString.split("&");
-
- for (String piece : pieces) {
- int equalsHere = piece.indexOf('=');
- if (piece.trim().isEmpty()) {
- // Ignore an empty piece.
- } else if (equalsHere <= 0) {
- // A parameter without a value.
- addToParameters(parameters, decode(piece), "");
- } else {
- // A parameter with a value.
- String key = piece.substring(0, equalsHere);
- String value = piece.substring(equalsHere + 1);
- addToParameters(parameters, decode(key), decode(value));
- }
- }
- }
- log.debug("Parameters from query string are: " + parameters);
- }
-
- /**
- * Remove any special URL-style encoding.
- */
- private String decode(String encoded) {
- try {
- return URLDecoder.decode(encoded, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- log.error(e, e);
- return encoded;
- }
+
+ //use an upload handler that will stash the file items in a temporary directory.
+ ServletFileUpload upload = createUploadHandler( this.maxFileSize, this.tempDir );
+ stashParametersInRequest( request , upload );
}
+
/**
* Find the temporary storage directory for this webapp.
*/
@@ -165,19 +63,7 @@ public class MultipartHttpServletRequest extends FileUploadServletRequest {
return (File) request.getSession().getServletContext().getAttribute(
"javax.servlet.context.tempdir");
}
-
- /**
- * Create an upload handler based on this.storeFilesToTempDir.
- */
- private ServletFileUpload createUploadHandler(){
- if( storeFilesToTempDir ){
- return createUploadHandler( this.maxFileSize, this.tempDir );
- }else{
- return new ServletFileUpload();
- }
- }
-
/**
* Create an upload handler that will throw an exception if the file is too
* large.
@@ -193,116 +79,10 @@ public class MultipartHttpServletRequest extends FileUploadServletRequest {
return upload;
}
- /** Either create a new List for the value, or add to an existing List. */
- private void addToParameters(Map> map, String name,
- String value) {
- if (!map.containsKey(name)) {
- map.put(name, new ArrayList());
- }
- map.get(name).add(value);
- }
-
- /** Either create a new List for the file, or add to an existing List. */
- private void addToFileItems(Map> map, FileItem file) {
- String name = file.getFieldName();
- if (!map.containsKey(name)) {
- map.put(name, new ArrayList());
- }
- map.get(name).add(file);
- }
-
- /** Minimize the code that uses the unchecked cast. */
- @SuppressWarnings("unchecked")
- private List parseRequestIntoFileItems(HttpServletRequest req,
- ServletFileUpload upload) throws FileUploadException {
- return upload.parseRequest(req);
- }
-
- // ----------------------------------------------------------------------
- // This is a multipart request, so make the file info available. If there
- // was an exception during parsing, make that available too.
- // ----------------------------------------------------------------------
-
- @Override
- public boolean isMultipart() {
- return true;
- }
-
- @Override
- public Map> getFiles() {
- return files;
- }
-
- /**
- * {@inheritDoc}
- *
- * There may be more than one file item with the given name. If the first
- * one is empty (size is zero), keep looking for a non-empty one.
- *
- */
- @Override
- public FileItem getFileItem(String name) {
- List items = files.get(name);
- if (items == null) {
- return null;
- }
-
- for (FileItem item : items) {
- if (item.getSize() > 0L) {
- return item;
- }
- }
-
- return null;
- }
-
- @Override
- public FileUploadException getFileUploadException() {
- return fileUploadException;
- }
-
- @Override
- public boolean hasFileUploadException() {
- return fileUploadException != null;
- }
-
- // ----------------------------------------------------------------------
- // Parameter-related methods won't find anything on the delegate request,
- // since parsing consumed the parameters. So we need to look to the parsed
- // info for the answers.
- // ----------------------------------------------------------------------
-
- @Override
- public String getParameter(String name) {
- if (parameters.containsKey(name)) {
- return parameters.get(name).get(0);
- } else {
- return null;
- }
- }
-
- @Override
- public Enumeration> getParameterNames() {
- return Collections.enumeration(parameters.keySet());
- }
-
- @Override
- public String[] getParameterValues(String name) {
- if (parameters.containsKey(name)) {
- return parameters.get(name).toArray(EMPTY_ARRAY);
- } else {
- return null;
- }
- }
-
- @Override
- public Map getParameterMap() {
- Map result = new HashMap();
- for (Entry> entry : parameters.entrySet()) {
- result.put(entry.getKey(), entry.getValue().toArray(EMPTY_ARRAY));
- }
- log.debug("resulting parameter map: " + result);
- return result;
- }
+ @Override
+ public boolean isMultipart() {
+ return true;
+ }
+
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/SimpleHttpServletRequestWrapper.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/SimpleHttpServletRequestWrapper.java
index 246377048..754226317 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/SimpleHttpServletRequestWrapper.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/SimpleHttpServletRequestWrapper.java
@@ -33,26 +33,7 @@ class SimpleHttpServletRequestWrapper extends FileUploadServletRequest {
return false;
}
- @Override
- public Map> getFiles() {
- return Collections.emptyMap();
- }
-
- @Override
- public FileItem getFileItem(String string) {
- return null;
- }
-
- @Override
- public FileUploadException getFileUploadException() {
- return null;
- }
-
- @Override
- public boolean hasFileUploadException() {
- return false;
- }
-
+
// ----------------------------------------------------------------------
// Since this is not a multipart request, the parameter methods can be
// delegated.
@@ -64,7 +45,7 @@ class SimpleHttpServletRequestWrapper extends FileUploadServletRequest {
}
@Override
- public Map, ?> getParameterMap() {
+ public Map getParameterMap() {
return getDelegate().getParameterMap();
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/StreamingMultipartHttpServletRequest.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/StreamingMultipartHttpServletRequest.java
new file mode 100644
index 000000000..e5e32c5c9
--- /dev/null
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/StreamingMultipartHttpServletRequest.java
@@ -0,0 +1,38 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+
+package edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
+
+/**
+ * Wrapping ServletRequest that does multipart. In order to allow
+ * streaming, this class does NOT save the parts to a temporary directory.
+ *
+ *
+ */
+public class StreamingMultipartHttpServletRequest extends
+ FileUploadServletRequest {
+ /**
+ * Parse the multipart request. Store the info about the request parameters.
+ * Don't store the uploaded files to a temporary directory to allow streaming.
+ *
+ * Only use this if you plan to consume the FileItems using streaming
+ * to deal with inputs of very large sizes.
+ *
+ */
+ public StreamingMultipartHttpServletRequest(HttpServletRequest request) {
+ super(request);
+
+ //use a file uploader that does not save the files to a temporary directory.
+ stashParametersInRequest( request , new ServletFileUpload());
+ }
+
+ @Override
+ public boolean isMultipart() {
+ return true;
+ }
+
+
+}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/VitroSearchTermNames.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/VitroSearchTermNames.java
index af49925fb..c46783f5a 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/VitroSearchTermNames.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/VitroSearchTermNames.java
@@ -3,31 +3,35 @@
package edu.cornell.mannlib.vitro.webapp.search;
public class VitroSearchTermNames {
+
/** Id of entity, vclass or tab */
public static String URI = "URI";
/** search document id */
public static String DOCID = "DocId";
- /** java class of the object that the Doc represents. */
- public static String JCLASS = "JCLASS";
+
/** rdf:type */
public static String RDFTYPE = "type";
- /** rdf:type */
- public static String CLASSGROUP_URI = "classgroup";
- /** Modtime from db */
- public static String MODTIME = "modTime";
-
+ /** class names in human readable form of an individual*/
+ public static final String CLASSLOCALNAME = "classLocalName";
+ /** classgroups from the individual's rdf:types */
+ public static String CLASSGROUP_URI = "classgroup";
+ /** Most specific types for individual*/
+ public static String MOST_SPECIFIC_TYPE_URIS = "mostSpecificTypeURIs";
+
/** time of index in msec since epoc */
public static String INDEXEDTIME= "indexedTime";
+
/** text for 'full text' search, this is stemmed */
public static String ALLTEXT = "ALLTEXT";
/** text for 'full text' search, this is unstemmed for
* use with wildcards and prefix queries */
- public static String ALLTEXTUNSTEMMED = "ALLTEXTUNSTEMMED";
+ public static String ALLTEXTUNSTEMMED = "ALLTEXTUNSTEMMED";
+
/** Does the individual have a thumbnail image? 1=yes 0=no */
public static final String THUMBNAIL = "THUMBNAIL";
- /** class names in human readable form of an individual*/
- public static final String CLASSLOCALNAME = "classLocalName";
-
+ /** download url location for thumbnail */
+ public static final String THUMBNAIL_URL = "THUMBNAIL_URL";
+
// Fields derived from rdfs:label
/** Raw rdfs:label: no lowercasing, no tokenizing, no stop words, no stemming **/
public static String NAME_RAW = "nameRaw"; //
@@ -44,6 +48,11 @@ public class VitroSearchTermNames {
/** rdfs:label lowercased, tokenized, stop words, stemmed **/
public static String NAME_STEMMED = "nameStemmed";
+
+ /** preferred title */
+ public static final String PREFERRED_TITLE = "PREFERRED_TITLE";
+
+ public static final String NAME_PHONETIC = "NAME_PHONETIC";
/** rdfs:label lowercased, untokenized, edge-n-gram-filtered for autocomplete on people names **/
public static String AC_NAME_UNTOKENIZED = "acNameUntokenized";
@@ -55,24 +64,13 @@ public class VitroSearchTermNames {
/* There is currently no use case for an autocomplete search field that is tokenized but not stemmed.
public static String AC_NAME_UNSTEMMED = "acNameUnstemmed"; */
- /** field for beta values of all documents **/
+ /** Beta values used in weighting **/
public static final String BETA = "BETA";
- public static final String PHI = "PHI";
- public static final String ADJACENT_NODES = "ADJACENT_NODES";
-
- /** adding phonetic field **/
- public static final String ALLTEXT_PHONETIC = "ALLTEXT_PHONETIC";
- public static final String NAME_PHONETIC = "NAME_PHONETIC";
-
- /** download url location for thumbnail */
- public static final String THUMBNAIL_URL = "THUMBNAIL_URL";
-
- /** source institution url */
+
+ /** Source institution URL */
public static final String SITE_URL = "siteURL";
-
- /** source institution name */
+
+ /** Source institution name */
public static final String SITE_NAME = "siteName";
- /** preferred title */
- public static final String PREFERRED_TITLE = "PREFERRED_TITLE";
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java
index 359a53529..51958ba45 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java
@@ -33,7 +33,7 @@ import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup;
/**
* AutocompleteController generates autocomplete content
- * via the search index.
+ * via the search index.
*/
public class AutocompleteController extends VitroAjaxController {
@@ -49,7 +49,7 @@ public class AutocompleteController extends VitroAjaxController {
String NORESULT_MSG = "";
- private static final int DEFAULT_MAX_HIT_COUNT = 1000;
+ private static final int DEFAULT_MAX_HIT_COUNT = 1000;
public static final int MAX_QUERY_LENGTH = 500;
@@ -57,50 +57,50 @@ public class AutocompleteController extends VitroAjaxController {
protected Actions requiredActions(VitroRequest vreq) {
return SimplePermission.USE_BASIC_AJAX_CONTROLLERS.ACTIONS;
}
-
+
@Override
protected void doRequest(VitroRequest vreq, HttpServletResponse response)
throws IOException, ServletException {
-
+
try {
-
+
String qtxt = vreq.getParameter(PARAM_QUERY);
-
- SolrQuery query = getQuery(qtxt, vreq);
+
+ SolrQuery query = getQuery(qtxt, vreq);
if (query == null ) {
log.debug("query for '" + qtxt +"' is null.");
doNoQuery(response);
return;
}
log.debug("query for '" + qtxt +"' is " + query.toString());
-
+
SolrServer solr = SolrSetup.getSolrServer(getServletContext());
QueryResponse queryResponse = solr.query(query);
if ( queryResponse == null) {
- log.error("Query response for a search was null");
+ log.error("Query response for a search was null");
doNoSearchResults(response);
return;
}
-
+
SolrDocumentList docs = queryResponse.getResults();
if ( docs == null) {
- log.error("Docs for a search was null");
+ log.error("Docs for a search was null");
doNoSearchResults(response);
return;
}
-
+
long hitCount = docs.getNumFound();
log.debug("Total number of hits = " + hitCount);
- if ( hitCount < 1 ) {
+ if ( hitCount < 1 ) {
doNoSearchResults(response);
return;
- }
+ }
List results = new ArrayList();
for (SolrDocument doc : docs) {
- try {
+ try {
String uri = doc.get(VitroSearchTermNames.URI).toString();
// RY 7/1/2011
// Comment was: VitroSearchTermNames.NAME_RAW is a multivalued field, so doc.get() returns a list.
@@ -116,61 +116,71 @@ public class AutocompleteController extends VitroAjaxController {
} else {
name = (String) nameRaw;
}
- SearchResult result = new SearchResult(name, uri);
+
+ Object mostSpecificType = doc.get(VitroSearchTermNames.MOST_SPECIFIC_TYPE_URIS);
+ String mst = null;
+ if (mostSpecificType instanceof List>) {
+ @SuppressWarnings("unchecked")
+ List mstList = (List) mostSpecificType;
+ mst = mstList.get(0);
+ } else {
+ mst = (String) mostSpecificType;
+ }
+
+ SearchResult result = new SearchResult(name, uri, mst);
results.add(result);
+ log.debug("results = " + results.toString());
} catch(Exception e){
log.error("problem getting usable individuals from search " +
"hits" + e.getMessage());
}
- }
+ }
Collections.sort(results);
-
+
JSONArray jsonArray = new JSONArray();
for (SearchResult result : results) {
jsonArray.put(result.toMap());
}
response.getWriter().write(jsonArray.toString());
-
+
} catch (Throwable e) {
- log.error(e, e);
+ log.error(e, e);
doSearchError(response);
}
}
private SolrQuery getQuery(String queryStr, VitroRequest vreq) {
-
+
if ( queryStr == null) {
- log.error("There was no parameter '"+ PARAM_QUERY
- +"' in the request.");
+ log.error("There was no parameter '"+ PARAM_QUERY
+ +"' in the request.");
return null;
} else if( queryStr.length() > MAX_QUERY_LENGTH ) {
log.debug("The search was too long. The maximum " +
"query length is " + MAX_QUERY_LENGTH );
return null;
}
-
+
SolrQuery query = new SolrQuery();
query.setStart(0)
- .setRows(DEFAULT_MAX_HIT_COUNT);
-
+ .setRows(DEFAULT_MAX_HIT_COUNT);
setNameQuery(query, queryStr, vreq);
-
// Filter by type
String typeParam = (String) vreq.getParameter(PARAM_RDFTYPE);
String multipleTypesParam = (String) vreq.getParameter(PARAM_MULTIPLE_RDFTYPE);
if (typeParam != null) {
addFilterQuery(query, typeParam, multipleTypesParam);
- }
-
- query.setFields(VitroSearchTermNames.NAME_RAW, VitroSearchTermNames.URI); // fields to retrieve
-
+ }
+
+ query.setFields(VitroSearchTermNames.NAME_RAW, VitroSearchTermNames.URI, VitroSearchTermNames.MOST_SPECIFIC_TYPE_URIS); // fields to retrieve
+
// Can't sort on multivalued field, so we sort the results in Java when we get them.
// query.setSortField(VitroSearchTermNames.NAME_LOWERCASE, SolrQuery.ORDER.asc);
-
+
return query;
}
-
+
private void addFilterQuery(SolrQuery query, String typeParam, String multipleTypesParam) {
if(multipleTypesParam == null || multipleTypesParam.equals("null") || multipleTypesParam.isEmpty()) {
//Single type parameter, process as usual
@@ -181,15 +191,13 @@ public class AutocompleteController extends VitroAjaxController {
int len = typeParams.length;
int i;
List filterQueries = new ArrayList();
-
+
for(i = 0; i < len; i++) {
filterQueries.add(VitroSearchTermNames.RDFTYPE + ":\"" + typeParams[i] + "\" ");
}
String filterQuery = StringUtils.join(filterQueries, " OR ");
query.addFilterQuery(filterQuery);
}
-
-
}
private void setNameQuery(SolrQuery query, String queryStr, HttpServletRequest request) {
@@ -197,10 +205,9 @@ public class AutocompleteController extends VitroAjaxController {
if (StringUtils.isBlank(queryStr)) {
log.error("No query string");
}
-
- String tokenizeParam = (String) request.getParameter("tokenize");
+ String tokenizeParam = (String) request.getParameter("tokenize");
boolean tokenize = "true".equals(tokenizeParam);
-
+
// Note: Stemming is only relevant if we are tokenizing: an untokenized name
// query will not be stemmed. So we don't look at the stem parameter until we get to
// setTokenizedNameQuery().
@@ -210,43 +217,43 @@ public class AutocompleteController extends VitroAjaxController {
setUntokenizedNameQuery(query, queryStr);
}
}
-
+
private void setTokenizedNameQuery(SolrQuery query, String queryStr, HttpServletRequest request) {
/* We currently have no use case for a tokenized, unstemmed autocomplete search field, so the option
* has been disabled. If needed in the future, will need to add a new field and field type which
* is like AC_NAME_STEMMED but doesn't include the stemmer.
- String stemParam = (String) request.getParameter("stem");
+ String stemParam = (String) request.getParameter("stem");
boolean stem = "true".equals(stemParam);
if (stem) {
String acTermName = VitroSearchTermNames.AC_NAME_STEMMED;
String nonAcTermName = VitroSearchTermNames.NAME_STEMMED;
} else {
String acTermName = VitroSearchTermNames.AC_NAME_UNSTEMMED;
- String nonAcTermName = VitroSearchTermNames.NAME_UNSTEMMED;
+ String nonAcTermName = VitroSearchTermNames.NAME_UNSTEMMED;
}
*/
-
+
String acTermName = VitroSearchTermNames.AC_NAME_STEMMED;
String nonAcTermName = VitroSearchTermNames.NAME_STEMMED;
String acQueryStr;
-
+
if (queryStr.endsWith(" ")) {
- acQueryStr = makeTermQuery(nonAcTermName, queryStr, true);
+ acQueryStr = makeTermQuery(nonAcTermName, queryStr, true);
} else {
int indexOfLastWord = queryStr.lastIndexOf(" ") + 1;
List terms = new ArrayList(2);
-
+
String allButLastWord = queryStr.substring(0, indexOfLastWord);
if (StringUtils.isNotBlank(allButLastWord)) {
terms.add(makeTermQuery(nonAcTermName, allButLastWord, true));
}
-
+
String lastWord = queryStr.substring(indexOfLastWord);
if (StringUtils.isNotBlank(lastWord)) {
terms.add(makeTermQuery(acTermName, lastWord, false));
}
-
+
acQueryStr = StringUtils.join(terms, " AND ");
}
@@ -255,26 +262,26 @@ public class AutocompleteController extends VitroAjaxController {
}
- private void setUntokenizedNameQuery(SolrQuery query, String queryStr) {
- queryStr = queryStr.trim();
+ private void setUntokenizedNameQuery(SolrQuery query, String queryStr) {
+ queryStr = queryStr.trim();
queryStr = makeTermQuery(VitroSearchTermNames.AC_NAME_UNTOKENIZED, queryStr, true);
query.setQuery(queryStr);
}
-
+
private String makeTermQuery(String term, String queryStr, boolean mayContainWhitespace) {
if (mayContainWhitespace) {
queryStr = "\"" + escapeWhitespaceInQueryString(queryStr) + "\"";
}
return term + ":" + queryStr;
}
-
+
private String escapeWhitespaceInQueryString(String queryStr) {
// Solr wants whitespace to be escaped with a backslash
return queryStr.replaceAll("\\s+", "\\\\ ");
}
-
+
private void doNoQuery(HttpServletResponse response) throws IOException {
- // For now, we are not sending an error message back to the client because
+ // For now, we are not sending an error message back to the client because
// with the default autocomplete configuration it chokes.
doNoSearchResults(response);
}
@@ -288,36 +295,46 @@ public class AutocompleteController extends VitroAjaxController {
private void doNoSearchResults(HttpServletResponse response) throws IOException {
response.getWriter().write("[]");
}
-
+
public class SearchResult implements Comparable