Merge remote-tracking branch 'origin/develop' into dev-isf
Conflicts: webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/MultipartHttpServletRequest.java
This commit is contained in:
commit
a270043063
39 changed files with 1313 additions and 2278 deletions
|
@ -774,6 +774,39 @@
|
||||||
<p>
|
<p>
|
||||||
to build Vitro and deploy to Tomcat's webapps directory.
|
to build Vitro and deploy to Tomcat's webapps directory.
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
The build script may run for as much as five minutes,
|
||||||
|
and creates more than 100 lines of output.
|
||||||
|
The process comprises several steps:
|
||||||
|
<ul>
|
||||||
|
<li>collecting the source files from the distribution directory,</li>
|
||||||
|
<li>compiling the Java source code,</li>
|
||||||
|
<li>compiling and running unit tests,</li>
|
||||||
|
<li>preparing the Solr search engine,</li>
|
||||||
|
<li>deploying Vitro and Solr to Tomcat.</li>
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
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.
|
||||||
|
</p>
|
||||||
|
<table align="center"><tr><td>
|
||||||
|
BUILD SUCCESSFUL<br>Total time: 1 minute 49 seconds
|
||||||
|
</td></tr></table>
|
||||||
|
<p>
|
||||||
|
If the output ends with a success message, the build was successful.
|
||||||
|
Proceed to the next step.
|
||||||
|
</p>
|
||||||
|
<table align="center"><tr><td>
|
||||||
|
BUILD FAILED<br>Total time: 35 seconds
|
||||||
|
</td></tr></table>
|
||||||
|
<p>
|
||||||
|
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.
|
||||||
|
</p>
|
||||||
|
|
||||||
<h3 id="tomcat_settings">VII. Configure Tomcat</h3>
|
<h3 id="tomcat_settings">VII. Configure Tomcat</h3>
|
||||||
<h4>Set JVM parameters</h4>
|
<h4>Set JVM parameters</h4>
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -194,6 +194,9 @@
|
||||||
<field name="classLocalName" type="text" indexed="true" stored="true" multiValued="true"/>
|
<field name="classLocalName" type="text" indexed="true" stored="true" multiValued="true"/>
|
||||||
|
|
||||||
<field name="classgroup" type="string" indexed="true" stored="true" multiValued="true"/>
|
<field name="classgroup" type="string" indexed="true" stored="true" multiValued="true"/>
|
||||||
|
|
||||||
|
<field name="mostSpecificTypeURIs" type="string" indexed="true" stored="true" omitNorms="true" multiValued="true"/>
|
||||||
|
|
||||||
<field name="PROHIBITED_FROM_TEXT_RESULTS" type="string" indexed="true" stored="false" omitNorms="true" multiValued="true"/>
|
<field name="PROHIBITED_FROM_TEXT_RESULTS" type="string" indexed="true" stored="false" omitNorms="true" multiValued="true"/>
|
||||||
<field name="URI" type="string" indexed="true" stored="true" multiValued="false" omitNorms="true"/>
|
<field name="URI" type="string" indexed="true" stored="true" multiValued="false" omitNorms="true"/>
|
||||||
|
|
||||||
|
@ -217,16 +220,10 @@
|
||||||
|
|
||||||
<field name="ALLTEXT" type="text" indexed="true" stored="true" multiValued="true"/>
|
<field name="ALLTEXT" type="text" indexed="true" stored="true" multiValued="true"/>
|
||||||
<field name="ALLTEXTUNSTEMMED" type="textgen" indexed="true" stored="false" multiValued="true"/>
|
<field name="ALLTEXTUNSTEMMED" type="textgen" indexed="true" stored="false" multiValued="true"/>
|
||||||
<field name="ALLTEXT_PHONETIC" type="phonetic" indexed="true" stored="false" multiValued="true"/>
|
|
||||||
|
|
||||||
<field name="THUMBNAIL" type="string" indexed="true" stored="true"/>
|
<field name="THUMBNAIL" type="string" indexed="true" stored="true"/>
|
||||||
|
|
||||||
<field name="BETA" type="float" indexed="true" stored="true" multiValued="false"/>
|
<field name="BETA" type="float" indexed="true" stored="true" multiValued="false"/>
|
||||||
<!-- <field name="PHI" type="float" indexed="true" stored="true" multiValued="false"/>
|
|
||||||
<field name="ADJACENT_NODES" type="string" indexed="true" stored="true" multiValued="true"/> -->
|
|
||||||
|
|
||||||
<field name="modType" type="ignored"/>
|
|
||||||
<field name="JCLASS" type="ignored"/>
|
|
||||||
|
|
||||||
<!-- field for storing locations of thumbnails -->
|
<!-- field for storing locations of thumbnails -->
|
||||||
<field name="THUMBNAIL_URL" type="string" indexed="false" stored="true"/>
|
<field name="THUMBNAIL_URL" type="string" indexed="false" stored="true"/>
|
||||||
|
|
1036
webapp/build.xml
1036
webapp/build.xml
File diff suppressed because it is too large
Load diff
|
@ -74,6 +74,15 @@ public class SimplePermission extends Permission {
|
||||||
"SeeVerbosePropertyInformation");
|
"SeeVerbosePropertyInformation");
|
||||||
public static final SimplePermission USE_ADVANCED_DATA_TOOLS_PAGES = new SimplePermission(
|
public static final SimplePermission USE_ADVANCED_DATA_TOOLS_PAGES = new SimplePermission(
|
||||||
"UseAdvancedDataToolsPages");
|
"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(
|
public static final SimplePermission USE_BASIC_AJAX_CONTROLLERS = new SimplePermission(
|
||||||
"UseBasicAjaxControllers");
|
"UseBasicAjaxControllers");
|
||||||
public static final SimplePermission USE_MISCELLANEOUS_ADMIN_PAGES = new SimplePermission(
|
public static final SimplePermission USE_MISCELLANEOUS_ADMIN_PAGES = new SimplePermission(
|
||||||
|
@ -84,8 +93,6 @@ public class SimplePermission extends Permission {
|
||||||
"UseMiscellaneousEditorPages");
|
"UseMiscellaneousEditorPages");
|
||||||
public static final SimplePermission USE_MISCELLANEOUS_PAGES = new SimplePermission(
|
public static final SimplePermission USE_MISCELLANEOUS_PAGES = new SimplePermission(
|
||||||
"UseMiscellaneousPages");
|
"UseMiscellaneousPages");
|
||||||
public static final SimplePermission USE_SPARQL_QUERY_PAGE = new SimplePermission(
|
|
||||||
"UseSparqlQueryPage");
|
|
||||||
|
|
||||||
public static List<SimplePermission> getAllInstances() {
|
public static List<SimplePermission> getAllInstances() {
|
||||||
return new ArrayList<SimplePermission>(allInstances.values());
|
return new ArrayList<SimplePermission>(allInstances.values());
|
||||||
|
|
|
@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
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.DataGetter;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils;
|
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.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.IndividualLocalNameMethod;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualPlaceholderImageUrlMethod;
|
import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualPlaceholderImageUrlMethod;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualProfileUrlMethod;
|
import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualProfileUrlMethod;
|
||||||
|
@ -166,16 +169,20 @@ public class FreemarkerConfiguration extends Configuration {
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Object> getDirectives() {
|
private static Map<String, Object> getDirectives() {
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put("dump", new freemarker.ext.dump.DumpDirective());
|
map.put("dump", new freemarker.ext.dump.DumpDirective());
|
||||||
map.put("dumpAll", new freemarker.ext.dump.DumpAllDirective());
|
map.put("dumpAll", new freemarker.ext.dump.DumpAllDirective());
|
||||||
map.put("help", new freemarker.ext.dump.HelpDirective());
|
map.put("help", new freemarker.ext.dump.HelpDirective());
|
||||||
map.put("shortView", new IndividualShortViewDirective());
|
map.put("shortView", new IndividualShortViewDirective());
|
||||||
|
map.put("url", new UrlDirective());
|
||||||
|
map.put("widget", new WidgetDirective());
|
||||||
|
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Object> getMethods() {
|
private static Map<String, Object> getMethods() {
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put("profileUrl", new IndividualProfileUrlMethod());
|
map.put("profileUrl", new IndividualProfileUrlMethod());
|
||||||
map.put("localName", new IndividualLocalNameMethod());
|
map.put("localName", new IndividualLocalNameMethod());
|
||||||
|
@ -319,4 +326,54 @@ public class FreemarkerConfiguration extends Configuration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Request info and overrides
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
private ThreadLocal<FreemarkerRequestInfo> 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<String> nameSet = new HashSet<String>(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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,9 @@ public class FreemarkerConfigurationLoader {
|
||||||
|
|
||||||
public static FreemarkerConfiguration getConfig(VitroRequest vreq) {
|
public static FreemarkerConfiguration getConfig(VitroRequest vreq) {
|
||||||
String themeDir = getThemeDir(vreq.getAppBean());
|
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) {
|
private static String getThemeDir(ApplicationBean appBean) {
|
||||||
|
|
|
@ -427,10 +427,6 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
// the copyright text can be viewed with having to restart Tomcat
|
// the copyright text can be viewed with having to restart Tomcat
|
||||||
map.put("copyright", getCopyrightInfo(appBean));
|
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
|
// Add these accumulator objects. They will collect tags so the template can write them
|
||||||
// at the appropriate location.
|
// at the appropriate location.
|
||||||
map.put("stylesheets", new Tags().wrap());
|
map.put("stylesheets", new Tags().wrap());
|
||||||
|
|
|
@ -24,13 +24,9 @@ public class TemplateProcessingHelper {
|
||||||
private static final Log log = LogFactory.getLog(TemplateProcessingHelper.class);
|
private static final Log log = LogFactory.getLog(TemplateProcessingHelper.class);
|
||||||
|
|
||||||
private Configuration config = null;
|
private Configuration config = null;
|
||||||
private HttpServletRequest request = null;
|
|
||||||
private ServletContext context = null;
|
|
||||||
|
|
||||||
public TemplateProcessingHelper(HttpServletRequest request, ServletContext context) {
|
public TemplateProcessingHelper(HttpServletRequest request, ServletContext context) {
|
||||||
this.config = FreemarkerConfigurationLoader.getConfig(new VitroRequest(request));
|
this.config = FreemarkerConfigurationLoader.getConfig(new VitroRequest(request));
|
||||||
this.request = request;
|
|
||||||
this.context = context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringWriter processTemplate(String templateName, Map<String, Object> map)
|
public StringWriter processTemplate(String templateName, Map<String, Object> map)
|
||||||
|
@ -46,14 +42,6 @@ public class TemplateProcessingHelper {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Environment env = template.createProcessingEnvironment(map, writer);
|
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
|
// Define a setup template to be included by every page template
|
||||||
String templateType = (String) map.get("templateType");
|
String templateType = (String) map.get("templateType");
|
||||||
|
|
|
@ -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<String,Object> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -3,8 +3,11 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller.json;
|
package edu.cornell.mannlib.vitro.webapp.controller.json;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -15,17 +18,21 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
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.VitroHttpServlet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
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;
|
||||||
|
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.ObjectPropertyStatementDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.log.LogUtils;
|
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.
|
* 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");
|
log.debug("AJAX request to retrieve individuals by vclasses");
|
||||||
new GetSolrIndividualsByVClasses(vreq).process(resp);
|
new GetSolrIndividualsByVClasses(vreq).process(resp);
|
||||||
} else if( vreq.getParameter("getDataForPage") != null ){
|
} 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 ){
|
}else if( vreq.getParameter("getRenderedSolrIndividualsByVClass") != null ){
|
||||||
new GetRenderedSolrIndividualsByVClass(vreq).process(resp);
|
new GetRenderedSolrIndividualsByVClass(vreq).process(resp);
|
||||||
}else if( vreq.getParameter("getRandomSolrIndividualsByVClass") != null ){
|
}else if( vreq.getParameter("getRandomSolrIndividualsByVClass") != null ){
|
||||||
|
@ -85,7 +94,7 @@ public class JsonServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
Map<String, Object> map = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
|
Map<String, Object> map = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
|
||||||
//last parameter indicates single vclass instead of multiple vclasses
|
//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<String> vclassURIs, HttpServletRequest req, ServletContext context) throws Exception {
|
public static JSONObject getSolrIndividualsByVClasses(List<String> 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());
|
log.debug("Retrieve solr results for vclasses" + vclassURIs.toString());
|
||||||
Map<String, Object> map = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
|
Map<String, Object> map = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
|
||||||
log.debug("Results returned from Solr for " + vclassURIs.toString() + " are of size " + map.size());
|
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
|
//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
|
// Map given to process method includes the actual individuals returned from the search
|
||||||
public static JSONObject processVClassResults(Map<String, Object> map, VitroRequest vreq, ServletContext context, boolean multipleVclasses) throws Exception{
|
// public static JSONObject processVClassResults(Map<String, Object> map, VitroRequest vreq, ServletContext context, boolean multipleVclasses) throws Exception{
|
||||||
JSONObject rObj = PageDataGetterUtils.processVclassResultsJSON(map, vreq, multipleVclasses);
|
// JSONObject rObj = processVclassResultsJSON(map, vreq, multipleVclasses);
|
||||||
return rObj;
|
// return rObj;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static Collection<String> getMostSpecificTypes(Individual individual, WebappDaoFactory wdf) {
|
public static Collection<String> getMostSpecificTypes(Individual individual, WebappDaoFactory wdf) {
|
||||||
ObjectPropertyStatementDao opsDao = wdf.getObjectPropertyStatementDao();
|
ObjectPropertyStatementDao opsDao = wdf.getObjectPropertyStatementDao();
|
||||||
|
@ -143,7 +152,7 @@ public class JsonServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
Map<String, Object> map = getRandomSolrVClassResults(vclassURI, vreq, context);
|
Map<String, Object> map = getRandomSolrVClassResults(vclassURI, vreq, context);
|
||||||
//last parameter indicates single vclass instead of multiple vclasses
|
//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
|
//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<String, Object> 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<String> 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<String> 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<Individual> inds = (List<Individual>)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<PageRecord> pages = (List<PageRecord>)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<String> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.directives.EmailDirective;
|
import edu.cornell.mannlib.vitro.webapp.web.directives.EmailDirective;
|
||||||
import freemarker.core.Environment;
|
|
||||||
import freemarker.template.Template;
|
|
||||||
import freemarker.template.TemplateException;
|
import freemarker.template.TemplateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,14 +142,8 @@ public class FreemarkerEmailMessage {
|
||||||
bodyMap.put("email", new EmailDirective(this));
|
bodyMap.put("email", new EmailDirective(this));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Template template = config.getTemplate(templateName);
|
config.getTemplate(templateName).process(bodyMap,
|
||||||
|
|
||||||
Environment env = template.createProcessingEnvironment(bodyMap,
|
|
||||||
new StringWriter());
|
new StringWriter());
|
||||||
env.setCustomAttribute("request", vreq);
|
|
||||||
env.setCustomAttribute("context", vreq.getSession()
|
|
||||||
.getServletContext());
|
|
||||||
env.process();
|
|
||||||
} catch (TemplateException e) {
|
} catch (TemplateException e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -3,8 +3,15 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest;
|
package edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletRequestWrapper;
|
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.FileItem;
|
||||||
import org.apache.commons.fileupload.FileUploadException;
|
import org.apache.commons.fileupload.FileUploadException;
|
||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -44,21 +53,39 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public abstract class FileUploadServletRequest extends HttpServletRequestWrapper {
|
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_ITEM_MAP = "file_item_map";
|
||||||
public static final String FILE_UPLOAD_EXCEPTION = "file_upload_exception";
|
public static final String FILE_UPLOAD_EXCEPTION = "file_upload_exception";
|
||||||
|
|
||||||
|
private Map<String, List<String>> parameters;
|
||||||
|
private Map<String, List<FileItem>> files;
|
||||||
|
private FileUploadException fileUploadException;
|
||||||
|
|
||||||
|
private static final String[] EMPTY_ARRAY = new String[0];
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// The factory method
|
// The factory method
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap this {@link HttpServletRequest} in an appropriate wrapper class.
|
* 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(
|
public static FileUploadServletRequest parseRequest(
|
||||||
HttpServletRequest request, int maxFileSize) throws IOException {
|
HttpServletRequest request, int maxTempFileSize) throws IOException {
|
||||||
|
|
||||||
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
|
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
|
||||||
|
|
||||||
if (isMultipart) {
|
if (isMultipart) {
|
||||||
return new MultipartHttpServletRequest(request, maxFileSize);
|
if( maxTempFileSize <= 0 ){
|
||||||
|
return new StreamingMultipartHttpServletRequest(request);
|
||||||
|
}else{
|
||||||
|
return new MultipartHttpServletRequest(request, maxTempFileSize);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return new SimpleHttpServletRequestWrapper(request);
|
return new SimpleHttpServletRequestWrapper(request);
|
||||||
}
|
}
|
||||||
|
@ -85,29 +112,184 @@ public abstract class FileUploadServletRequest extends HttpServletRequestWrapper
|
||||||
|
|
||||||
/** Was this a multipart HTTP request? */
|
/** Was this a multipart HTTP request? */
|
||||||
public abstract boolean isMultipart();
|
public abstract boolean isMultipart();
|
||||||
|
|
||||||
|
protected void stashParametersInRequest(HttpServletRequest request, ServletFileUpload upload){
|
||||||
|
Map<String, List<String>> parameters = new HashMap<String, List<String>>();
|
||||||
|
Map<String, List<FileItem>> files = new HashMap<String, List<FileItem>>();
|
||||||
|
|
||||||
|
parseQueryString(request.getQueryString(), parameters);
|
||||||
|
|
||||||
|
try {
|
||||||
|
List<FileItem> 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<String, List<FileItem>> getFiles();
|
private void parseQueryString(String queryString,
|
||||||
|
Map<String, List<String>> 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.
|
* Remove any special URL-style encoding.
|
||||||
*
|
|
||||||
* @return the first such file item, or <code>null</code> if no matching,
|
|
||||||
* non-empty items were found.
|
|
||||||
*/
|
*/
|
||||||
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();
|
|
||||||
|
|
||||||
/**
|
/** Either create a new List for the value, or add to an existing List. */
|
||||||
* Get the exception that occurred when uploading the file items. If no such
|
private void addToParameters(Map<String, List<String>> map, String name,
|
||||||
* exception, return <code>null</code>.
|
String value) {
|
||||||
*/
|
if (!map.containsKey(name)) {
|
||||||
public abstract FileUploadException getFileUploadException();
|
map.put(name, new ArrayList<String>());
|
||||||
|
}
|
||||||
|
map.get(name).add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Either create a new List for the file, or add to an existing List. */
|
||||||
|
private void addToFileItems(Map<String, List<FileItem>> map, FileItem file) {
|
||||||
|
String name = file.getFieldName();
|
||||||
|
if (!map.containsKey(name)) {
|
||||||
|
map.put(name, new ArrayList<FileItem>());
|
||||||
|
}
|
||||||
|
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<String, String[]> getParameterMap() {
|
||||||
|
Map<String, String[]> result = new HashMap<String, String[]>();
|
||||||
|
for (Entry<String, List<String>> entry : parameters.entrySet()) {
|
||||||
|
result.put(entry.getKey(), entry.getValue().toArray(EMPTY_ARRAY));
|
||||||
|
}
|
||||||
|
log.debug("resulting parameter map: " + result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public FileItem getFileItem(String name) {
|
||||||
|
List<FileItem> 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<String, List<FileItem>> getFiles() {
|
||||||
|
if( files == null )
|
||||||
|
return Collections.emptyMap();
|
||||||
|
else
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,33 +33,8 @@ public class MultipartHttpServletRequest extends FileUploadServletRequest {
|
||||||
private static final Log log = LogFactory
|
private static final Log log = LogFactory
|
||||||
.getLog(MultipartHttpServletRequest.class);
|
.getLog(MultipartHttpServletRequest.class);
|
||||||
|
|
||||||
private static final String[] EMPTY_ARRAY = new String[0];
|
|
||||||
|
|
||||||
private Map<String, List<String>> parameters;
|
|
||||||
private Map<String, List<FileItem>> files;
|
|
||||||
private FileUploadException fileUploadException;
|
|
||||||
|
|
||||||
private boolean storeFilesToTempDir = false;
|
|
||||||
private int maxFileSize = 0;
|
private int maxFileSize = 0;
|
||||||
private File tempDir = null;
|
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the multipart request. Store the info about the request parameters
|
* Parse the multipart request. Store the info about the request parameters
|
||||||
|
@ -71,93 +46,16 @@ public class MultipartHttpServletRequest extends FileUploadServletRequest {
|
||||||
public MultipartHttpServletRequest(HttpServletRequest request,
|
public MultipartHttpServletRequest(HttpServletRequest request,
|
||||||
int maxFileSize) throws IOException {
|
int maxFileSize) throws IOException {
|
||||||
super(request);
|
super(request);
|
||||||
storeFilesToTempDir = true;
|
|
||||||
this.maxFileSize = maxFileSize;
|
this.maxFileSize = maxFileSize;
|
||||||
this.tempDir = figureTemporaryDirectory(request);
|
this.tempDir = figureTemporaryDirectory(request);
|
||||||
setup(request);
|
|
||||||
}
|
//use an upload handler that will stash the file items in a temporary directory.
|
||||||
|
ServletFileUpload upload = createUploadHandler( this.maxFileSize, this.tempDir );
|
||||||
private void setup(HttpServletRequest request){
|
stashParametersInRequest( request , upload );
|
||||||
Map<String, List<String>> parameters = new HashMap<String, List<String>>();
|
|
||||||
Map<String, List<FileItem>> files = new HashMap<String, List<FileItem>>();
|
|
||||||
|
|
||||||
ServletFileUpload upload = createUploadHandler();
|
|
||||||
|
|
||||||
//File tempDir = figureTemporaryDirectory(request);
|
|
||||||
//ServletFileUpload upload = createUploadHandler(maxFileSize, tempDir);
|
|
||||||
|
|
||||||
parseQueryString(request.getQueryString(), parameters);
|
|
||||||
|
|
||||||
try {
|
|
||||||
List<FileItem> 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<String, List<String>> 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the temporary storage directory for this webapp.
|
* Find the temporary storage directory for this webapp.
|
||||||
*/
|
*/
|
||||||
|
@ -165,19 +63,7 @@ public class MultipartHttpServletRequest extends FileUploadServletRequest {
|
||||||
return (File) request.getSession().getServletContext().getAttribute(
|
return (File) request.getSession().getServletContext().getAttribute(
|
||||||
"javax.servlet.context.tempdir");
|
"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
|
* Create an upload handler that will throw an exception if the file is too
|
||||||
* large.
|
* large.
|
||||||
|
@ -193,116 +79,10 @@ public class MultipartHttpServletRequest extends FileUploadServletRequest {
|
||||||
return upload;
|
return upload;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Either create a new List for the value, or add to an existing List. */
|
@Override
|
||||||
private void addToParameters(Map<String, List<String>> map, String name,
|
public boolean isMultipart() {
|
||||||
String value) {
|
return true;
|
||||||
if (!map.containsKey(name)) {
|
}
|
||||||
map.put(name, new ArrayList<String>());
|
|
||||||
}
|
|
||||||
map.get(name).add(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Either create a new List for the file, or add to an existing List. */
|
|
||||||
private void addToFileItems(Map<String, List<FileItem>> map, FileItem file) {
|
|
||||||
String name = file.getFieldName();
|
|
||||||
if (!map.containsKey(name)) {
|
|
||||||
map.put(name, new ArrayList<FileItem>());
|
|
||||||
}
|
|
||||||
map.get(name).add(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Minimize the code that uses the unchecked cast. */
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private List<FileItem> 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<String, List<FileItem>> getFiles() {
|
|
||||||
return files;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* <p>
|
|
||||||
* 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.
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public FileItem getFileItem(String name) {
|
|
||||||
List<FileItem> 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<String, String[]> getParameterMap() {
|
|
||||||
Map<String, String[]> result = new HashMap<String, String[]>();
|
|
||||||
for (Entry<String, List<String>> entry : parameters.entrySet()) {
|
|
||||||
result.put(entry.getKey(), entry.getValue().toArray(EMPTY_ARRAY));
|
|
||||||
}
|
|
||||||
log.debug("resulting parameter map: " + result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,26 +33,7 @@ class SimpleHttpServletRequestWrapper extends FileUploadServletRequest {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, List<FileItem>> 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
|
// Since this is not a multipart request, the parameter methods can be
|
||||||
// delegated.
|
// delegated.
|
||||||
|
@ -64,7 +45,7 @@ class SimpleHttpServletRequestWrapper extends FileUploadServletRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<?, ?> getParameterMap() {
|
public Map<String, String[]> getParameterMap() {
|
||||||
return getDelegate().getParameterMap();
|
return getDelegate().getParameterMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -3,31 +3,35 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.search;
|
package edu.cornell.mannlib.vitro.webapp.search;
|
||||||
|
|
||||||
public class VitroSearchTermNames {
|
public class VitroSearchTermNames {
|
||||||
|
|
||||||
/** Id of entity, vclass or tab */
|
/** Id of entity, vclass or tab */
|
||||||
public static String URI = "URI";
|
public static String URI = "URI";
|
||||||
/** search document id */
|
/** search document id */
|
||||||
public static String DOCID = "DocId";
|
public static String DOCID = "DocId";
|
||||||
/** java class of the object that the Doc represents. */
|
|
||||||
public static String JCLASS = "JCLASS";
|
|
||||||
/** rdf:type */
|
/** rdf:type */
|
||||||
public static String RDFTYPE = "type";
|
public static String RDFTYPE = "type";
|
||||||
/** rdf:type */
|
/** class names in human readable form of an individual*/
|
||||||
public static String CLASSGROUP_URI = "classgroup";
|
public static final String CLASSLOCALNAME = "classLocalName";
|
||||||
/** Modtime from db */
|
/** classgroups from the individual's rdf:types */
|
||||||
public static String MODTIME = "modTime";
|
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 */
|
/** time of index in msec since epoc */
|
||||||
public static String INDEXEDTIME= "indexedTime";
|
public static String INDEXEDTIME= "indexedTime";
|
||||||
|
|
||||||
/** text for 'full text' search, this is stemmed */
|
/** text for 'full text' search, this is stemmed */
|
||||||
public static String ALLTEXT = "ALLTEXT";
|
public static String ALLTEXT = "ALLTEXT";
|
||||||
/** text for 'full text' search, this is unstemmed for
|
/** text for 'full text' search, this is unstemmed for
|
||||||
* use with wildcards and prefix queries */
|
* 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 */
|
/** Does the individual have a thumbnail image? 1=yes 0=no */
|
||||||
public static final String THUMBNAIL = "THUMBNAIL";
|
public static final String THUMBNAIL = "THUMBNAIL";
|
||||||
/** class names in human readable form of an individual*/
|
/** download url location for thumbnail */
|
||||||
public static final String CLASSLOCALNAME = "classLocalName";
|
public static final String THUMBNAIL_URL = "THUMBNAIL_URL";
|
||||||
|
|
||||||
// Fields derived from rdfs:label
|
// Fields derived from rdfs:label
|
||||||
/** Raw rdfs:label: no lowercasing, no tokenizing, no stop words, no stemming **/
|
/** Raw rdfs:label: no lowercasing, no tokenizing, no stop words, no stemming **/
|
||||||
public static String NAME_RAW = "nameRaw"; //
|
public static String NAME_RAW = "nameRaw"; //
|
||||||
|
@ -44,6 +48,11 @@ public class VitroSearchTermNames {
|
||||||
|
|
||||||
/** rdfs:label lowercased, tokenized, stop words, stemmed **/
|
/** rdfs:label lowercased, tokenized, stop words, stemmed **/
|
||||||
public static String NAME_STEMMED = "nameStemmed";
|
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 **/
|
/** rdfs:label lowercased, untokenized, edge-n-gram-filtered for autocomplete on people names **/
|
||||||
public static String AC_NAME_UNTOKENIZED = "acNameUntokenized";
|
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.
|
/* There is currently no use case for an autocomplete search field that is tokenized but not stemmed.
|
||||||
public static String AC_NAME_UNSTEMMED = "acNameUnstemmed"; */
|
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 BETA = "BETA";
|
||||||
public static final String PHI = "PHI";
|
|
||||||
public static final String ADJACENT_NODES = "ADJACENT_NODES";
|
/** Source institution URL */
|
||||||
|
|
||||||
/** 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 */
|
|
||||||
public static final String SITE_URL = "siteURL";
|
public static final String SITE_URL = "siteURL";
|
||||||
|
|
||||||
/** source institution name */
|
/** Source institution name */
|
||||||
public static final String SITE_NAME = "siteName";
|
public static final String SITE_NAME = "siteName";
|
||||||
|
|
||||||
/** preferred title */
|
|
||||||
public static final String PREFERRED_TITLE = "PREFERRED_TITLE";
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AutocompleteController generates autocomplete content
|
* AutocompleteController generates autocomplete content
|
||||||
* via the search index.
|
* via the search index.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class AutocompleteController extends VitroAjaxController {
|
public class AutocompleteController extends VitroAjaxController {
|
||||||
|
@ -49,7 +49,7 @@ public class AutocompleteController extends VitroAjaxController {
|
||||||
|
|
||||||
|
|
||||||
String NORESULT_MSG = "";
|
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;
|
public static final int MAX_QUERY_LENGTH = 500;
|
||||||
|
|
||||||
|
@ -57,50 +57,50 @@ public class AutocompleteController extends VitroAjaxController {
|
||||||
protected Actions requiredActions(VitroRequest vreq) {
|
protected Actions requiredActions(VitroRequest vreq) {
|
||||||
return SimplePermission.USE_BASIC_AJAX_CONTROLLERS.ACTIONS;
|
return SimplePermission.USE_BASIC_AJAX_CONTROLLERS.ACTIONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doRequest(VitroRequest vreq, HttpServletResponse response)
|
protected void doRequest(VitroRequest vreq, HttpServletResponse response)
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String qtxt = vreq.getParameter(PARAM_QUERY);
|
String qtxt = vreq.getParameter(PARAM_QUERY);
|
||||||
|
|
||||||
SolrQuery query = getQuery(qtxt, vreq);
|
SolrQuery query = getQuery(qtxt, vreq);
|
||||||
if (query == null ) {
|
if (query == null ) {
|
||||||
log.debug("query for '" + qtxt +"' is null.");
|
log.debug("query for '" + qtxt +"' is null.");
|
||||||
doNoQuery(response);
|
doNoQuery(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.debug("query for '" + qtxt +"' is " + query.toString());
|
log.debug("query for '" + qtxt +"' is " + query.toString());
|
||||||
|
|
||||||
SolrServer solr = SolrSetup.getSolrServer(getServletContext());
|
SolrServer solr = SolrSetup.getSolrServer(getServletContext());
|
||||||
QueryResponse queryResponse = solr.query(query);
|
QueryResponse queryResponse = solr.query(query);
|
||||||
|
|
||||||
if ( queryResponse == null) {
|
if ( queryResponse == null) {
|
||||||
log.error("Query response for a search was null");
|
log.error("Query response for a search was null");
|
||||||
doNoSearchResults(response);
|
doNoSearchResults(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SolrDocumentList docs = queryResponse.getResults();
|
SolrDocumentList docs = queryResponse.getResults();
|
||||||
|
|
||||||
if ( docs == null) {
|
if ( docs == null) {
|
||||||
log.error("Docs for a search was null");
|
log.error("Docs for a search was null");
|
||||||
doNoSearchResults(response);
|
doNoSearchResults(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long hitCount = docs.getNumFound();
|
long hitCount = docs.getNumFound();
|
||||||
log.debug("Total number of hits = " + hitCount);
|
log.debug("Total number of hits = " + hitCount);
|
||||||
if ( hitCount < 1 ) {
|
if ( hitCount < 1 ) {
|
||||||
doNoSearchResults(response);
|
doNoSearchResults(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SearchResult> results = new ArrayList<SearchResult>();
|
List<SearchResult> results = new ArrayList<SearchResult>();
|
||||||
for (SolrDocument doc : docs) {
|
for (SolrDocument doc : docs) {
|
||||||
try {
|
try {
|
||||||
String uri = doc.get(VitroSearchTermNames.URI).toString();
|
String uri = doc.get(VitroSearchTermNames.URI).toString();
|
||||||
// RY 7/1/2011
|
// RY 7/1/2011
|
||||||
// Comment was: VitroSearchTermNames.NAME_RAW is a multivalued field, so doc.get() returns a list.
|
// 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 {
|
} else {
|
||||||
name = (String) nameRaw;
|
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<String> mstList = (List<String>) mostSpecificType;
|
||||||
|
mst = mstList.get(0);
|
||||||
|
} else {
|
||||||
|
mst = (String) mostSpecificType;
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchResult result = new SearchResult(name, uri, mst);
|
||||||
results.add(result);
|
results.add(result);
|
||||||
|
log.debug("results = " + results.toString());
|
||||||
} catch(Exception e){
|
} catch(Exception e){
|
||||||
log.error("problem getting usable individuals from search " +
|
log.error("problem getting usable individuals from search " +
|
||||||
"hits" + e.getMessage());
|
"hits" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(results);
|
Collections.sort(results);
|
||||||
|
|
||||||
JSONArray jsonArray = new JSONArray();
|
JSONArray jsonArray = new JSONArray();
|
||||||
for (SearchResult result : results) {
|
for (SearchResult result : results) {
|
||||||
jsonArray.put(result.toMap());
|
jsonArray.put(result.toMap());
|
||||||
}
|
}
|
||||||
response.getWriter().write(jsonArray.toString());
|
response.getWriter().write(jsonArray.toString());
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
doSearchError(response);
|
doSearchError(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SolrQuery getQuery(String queryStr, VitroRequest vreq) {
|
private SolrQuery getQuery(String queryStr, VitroRequest vreq) {
|
||||||
|
|
||||||
if ( queryStr == null) {
|
if ( queryStr == null) {
|
||||||
log.error("There was no parameter '"+ PARAM_QUERY
|
log.error("There was no parameter '"+ PARAM_QUERY
|
||||||
+"' in the request.");
|
+"' in the request.");
|
||||||
return null;
|
return null;
|
||||||
} else if( queryStr.length() > MAX_QUERY_LENGTH ) {
|
} else if( queryStr.length() > MAX_QUERY_LENGTH ) {
|
||||||
log.debug("The search was too long. The maximum " +
|
log.debug("The search was too long. The maximum " +
|
||||||
"query length is " + MAX_QUERY_LENGTH );
|
"query length is " + MAX_QUERY_LENGTH );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
SolrQuery query = new SolrQuery();
|
SolrQuery query = new SolrQuery();
|
||||||
query.setStart(0)
|
query.setStart(0)
|
||||||
.setRows(DEFAULT_MAX_HIT_COUNT);
|
.setRows(DEFAULT_MAX_HIT_COUNT);
|
||||||
|
|
||||||
setNameQuery(query, queryStr, vreq);
|
setNameQuery(query, queryStr, vreq);
|
||||||
|
|
||||||
// Filter by type
|
// Filter by type
|
||||||
String typeParam = (String) vreq.getParameter(PARAM_RDFTYPE);
|
String typeParam = (String) vreq.getParameter(PARAM_RDFTYPE);
|
||||||
String multipleTypesParam = (String) vreq.getParameter(PARAM_MULTIPLE_RDFTYPE);
|
String multipleTypesParam = (String) vreq.getParameter(PARAM_MULTIPLE_RDFTYPE);
|
||||||
if (typeParam != null) {
|
if (typeParam != null) {
|
||||||
addFilterQuery(query, typeParam, multipleTypesParam);
|
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.
|
// 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);
|
// query.setSortField(VitroSearchTermNames.NAME_LOWERCASE, SolrQuery.ORDER.asc);
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addFilterQuery(SolrQuery query, String typeParam, String multipleTypesParam) {
|
private void addFilterQuery(SolrQuery query, String typeParam, String multipleTypesParam) {
|
||||||
if(multipleTypesParam == null || multipleTypesParam.equals("null") || multipleTypesParam.isEmpty()) {
|
if(multipleTypesParam == null || multipleTypesParam.equals("null") || multipleTypesParam.isEmpty()) {
|
||||||
//Single type parameter, process as usual
|
//Single type parameter, process as usual
|
||||||
|
@ -181,15 +191,13 @@ public class AutocompleteController extends VitroAjaxController {
|
||||||
int len = typeParams.length;
|
int len = typeParams.length;
|
||||||
int i;
|
int i;
|
||||||
List<String> filterQueries = new ArrayList<String>();
|
List<String> filterQueries = new ArrayList<String>();
|
||||||
|
|
||||||
for(i = 0; i < len; i++) {
|
for(i = 0; i < len; i++) {
|
||||||
filterQueries.add(VitroSearchTermNames.RDFTYPE + ":\"" + typeParams[i] + "\" ");
|
filterQueries.add(VitroSearchTermNames.RDFTYPE + ":\"" + typeParams[i] + "\" ");
|
||||||
}
|
}
|
||||||
String filterQuery = StringUtils.join(filterQueries, " OR ");
|
String filterQuery = StringUtils.join(filterQueries, " OR ");
|
||||||
query.addFilterQuery(filterQuery);
|
query.addFilterQuery(filterQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNameQuery(SolrQuery query, String queryStr, HttpServletRequest request) {
|
private void setNameQuery(SolrQuery query, String queryStr, HttpServletRequest request) {
|
||||||
|
@ -197,10 +205,9 @@ public class AutocompleteController extends VitroAjaxController {
|
||||||
if (StringUtils.isBlank(queryStr)) {
|
if (StringUtils.isBlank(queryStr)) {
|
||||||
log.error("No query string");
|
log.error("No query string");
|
||||||
}
|
}
|
||||||
|
String tokenizeParam = (String) request.getParameter("tokenize");
|
||||||
String tokenizeParam = (String) request.getParameter("tokenize");
|
|
||||||
boolean tokenize = "true".equals(tokenizeParam);
|
boolean tokenize = "true".equals(tokenizeParam);
|
||||||
|
|
||||||
// Note: Stemming is only relevant if we are tokenizing: an untokenized name
|
// 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
|
// query will not be stemmed. So we don't look at the stem parameter until we get to
|
||||||
// setTokenizedNameQuery().
|
// setTokenizedNameQuery().
|
||||||
|
@ -210,43 +217,43 @@ public class AutocompleteController extends VitroAjaxController {
|
||||||
setUntokenizedNameQuery(query, queryStr);
|
setUntokenizedNameQuery(query, queryStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTokenizedNameQuery(SolrQuery query, String queryStr, HttpServletRequest request) {
|
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
|
/* 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
|
* 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.
|
* 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);
|
boolean stem = "true".equals(stemParam);
|
||||||
if (stem) {
|
if (stem) {
|
||||||
String acTermName = VitroSearchTermNames.AC_NAME_STEMMED;
|
String acTermName = VitroSearchTermNames.AC_NAME_STEMMED;
|
||||||
String nonAcTermName = VitroSearchTermNames.NAME_STEMMED;
|
String nonAcTermName = VitroSearchTermNames.NAME_STEMMED;
|
||||||
} else {
|
} else {
|
||||||
String acTermName = VitroSearchTermNames.AC_NAME_UNSTEMMED;
|
String acTermName = VitroSearchTermNames.AC_NAME_UNSTEMMED;
|
||||||
String nonAcTermName = VitroSearchTermNames.NAME_UNSTEMMED;
|
String nonAcTermName = VitroSearchTermNames.NAME_UNSTEMMED;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String acTermName = VitroSearchTermNames.AC_NAME_STEMMED;
|
String acTermName = VitroSearchTermNames.AC_NAME_STEMMED;
|
||||||
String nonAcTermName = VitroSearchTermNames.NAME_STEMMED;
|
String nonAcTermName = VitroSearchTermNames.NAME_STEMMED;
|
||||||
String acQueryStr;
|
String acQueryStr;
|
||||||
|
|
||||||
if (queryStr.endsWith(" ")) {
|
if (queryStr.endsWith(" ")) {
|
||||||
acQueryStr = makeTermQuery(nonAcTermName, queryStr, true);
|
acQueryStr = makeTermQuery(nonAcTermName, queryStr, true);
|
||||||
} else {
|
} else {
|
||||||
int indexOfLastWord = queryStr.lastIndexOf(" ") + 1;
|
int indexOfLastWord = queryStr.lastIndexOf(" ") + 1;
|
||||||
List<String> terms = new ArrayList<String>(2);
|
List<String> terms = new ArrayList<String>(2);
|
||||||
|
|
||||||
String allButLastWord = queryStr.substring(0, indexOfLastWord);
|
String allButLastWord = queryStr.substring(0, indexOfLastWord);
|
||||||
if (StringUtils.isNotBlank(allButLastWord)) {
|
if (StringUtils.isNotBlank(allButLastWord)) {
|
||||||
terms.add(makeTermQuery(nonAcTermName, allButLastWord, true));
|
terms.add(makeTermQuery(nonAcTermName, allButLastWord, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
String lastWord = queryStr.substring(indexOfLastWord);
|
String lastWord = queryStr.substring(indexOfLastWord);
|
||||||
if (StringUtils.isNotBlank(lastWord)) {
|
if (StringUtils.isNotBlank(lastWord)) {
|
||||||
terms.add(makeTermQuery(acTermName, lastWord, false));
|
terms.add(makeTermQuery(acTermName, lastWord, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
acQueryStr = StringUtils.join(terms, " AND ");
|
acQueryStr = StringUtils.join(terms, " AND ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,26 +262,26 @@ public class AutocompleteController extends VitroAjaxController {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUntokenizedNameQuery(SolrQuery query, String queryStr) {
|
private void setUntokenizedNameQuery(SolrQuery query, String queryStr) {
|
||||||
queryStr = queryStr.trim();
|
queryStr = queryStr.trim();
|
||||||
queryStr = makeTermQuery(VitroSearchTermNames.AC_NAME_UNTOKENIZED, queryStr, true);
|
queryStr = makeTermQuery(VitroSearchTermNames.AC_NAME_UNTOKENIZED, queryStr, true);
|
||||||
query.setQuery(queryStr);
|
query.setQuery(queryStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String makeTermQuery(String term, String queryStr, boolean mayContainWhitespace) {
|
private String makeTermQuery(String term, String queryStr, boolean mayContainWhitespace) {
|
||||||
if (mayContainWhitespace) {
|
if (mayContainWhitespace) {
|
||||||
queryStr = "\"" + escapeWhitespaceInQueryString(queryStr) + "\"";
|
queryStr = "\"" + escapeWhitespaceInQueryString(queryStr) + "\"";
|
||||||
}
|
}
|
||||||
return term + ":" + queryStr;
|
return term + ":" + queryStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String escapeWhitespaceInQueryString(String queryStr) {
|
private String escapeWhitespaceInQueryString(String queryStr) {
|
||||||
// Solr wants whitespace to be escaped with a backslash
|
// Solr wants whitespace to be escaped with a backslash
|
||||||
return queryStr.replaceAll("\\s+", "\\\\ ");
|
return queryStr.replaceAll("\\s+", "\\\\ ");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doNoQuery(HttpServletResponse response) throws IOException {
|
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.
|
// with the default autocomplete configuration it chokes.
|
||||||
doNoSearchResults(response);
|
doNoSearchResults(response);
|
||||||
}
|
}
|
||||||
|
@ -288,36 +295,46 @@ public class AutocompleteController extends VitroAjaxController {
|
||||||
private void doNoSearchResults(HttpServletResponse response) throws IOException {
|
private void doNoSearchResults(HttpServletResponse response) throws IOException {
|
||||||
response.getWriter().write("[]");
|
response.getWriter().write("[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SearchResult implements Comparable<Object> {
|
public class SearchResult implements Comparable<Object> {
|
||||||
private String label;
|
private String label;
|
||||||
private String uri;
|
private String uri;
|
||||||
|
private String msType;
|
||||||
SearchResult(String label, String uri) {
|
|
||||||
|
SearchResult(String label, String uri, String msType) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
|
this.msType = msType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJsonLabel() {
|
public String getJsonLabel() {
|
||||||
return JSONObject.quote(label);
|
return JSONObject.quote(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUri() {
|
public String getUri() {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJsonUri() {
|
public String getJsonUri() {
|
||||||
return JSONObject.quote(uri);
|
return JSONObject.quote(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMsType() {
|
||||||
|
return msType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJsonMsType() {
|
||||||
|
return JSONObject.quote(msType);
|
||||||
|
}
|
||||||
Map<String, String> toMap() {
|
Map<String, String> toMap() {
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
map.put("label", label);
|
map.put("label", label);
|
||||||
map.put("uri", uri);
|
map.put("uri", uri);
|
||||||
|
map.put("msType", msType);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServ
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.MultipartHttpServletRequest;
|
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.MultipartHttpServletRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
|
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ public class SearchServiceController extends FreemarkerHttpServlet {
|
||||||
protected Actions requiredActions(VitroRequest vreq) {
|
protected Actions requiredActions(VitroRequest vreq) {
|
||||||
try{
|
try{
|
||||||
// Works by side effect: parse the multi-part request and stash FileItems in request
|
// Works by side effect: parse the multi-part request and stash FileItems in request
|
||||||
new MultipartHttpServletRequest( vreq );
|
FileUploadServletRequest.parseRequest(vreq, 0);
|
||||||
|
|
||||||
//first figure out if the password and email login to an account with a password
|
//first figure out if the password and email login to an account with a password
|
||||||
String pw = vreq.getParameter("password");
|
String pw = vreq.getParameter("password");
|
||||||
|
|
|
@ -69,6 +69,7 @@ public class IndividualToSolrDocument {
|
||||||
//add classes, classgroups get if prohibited because of its class
|
//add classes, classgroups get if prohibited because of its class
|
||||||
StringBuffer classPublicNames = new StringBuffer("");
|
StringBuffer classPublicNames = new StringBuffer("");
|
||||||
addClasses(ind, doc, classPublicNames);
|
addClasses(ind, doc, classPublicNames);
|
||||||
|
addMostSpecificTypeUris( ind, doc );
|
||||||
|
|
||||||
log.debug(ind.getURI() + " post class boost: " + doc.getDocumentBoost());
|
log.debug(ind.getURI() + " post class boost: " + doc.getDocumentBoost());
|
||||||
|
|
||||||
|
@ -202,7 +203,6 @@ public class IndividualToSolrDocument {
|
||||||
|
|
||||||
doc.addField(term.ALLTEXT, alltext);
|
doc.addField(term.ALLTEXT, alltext);
|
||||||
doc.addField(term.ALLTEXTUNSTEMMED, alltext);
|
doc.addField(term.ALLTEXTUNSTEMMED, alltext);
|
||||||
doc.addField(term.ALLTEXT_PHONETIC, alltext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ public class IndividualToSolrDocument {
|
||||||
if( vclasses == null || vclasses.isEmpty() ){
|
if( vclasses == null || vclasses.isEmpty() ){
|
||||||
throw new SkipIndividualException("Not indexing because individual has no classes");
|
throw new SkipIndividualException("Not indexing because individual has no classes");
|
||||||
}
|
}
|
||||||
|
|
||||||
for(VClass clz : vclasses){
|
for(VClass clz : vclasses){
|
||||||
if(clz.getURI() == null){
|
if(clz.getURI() == null){
|
||||||
continue;
|
continue;
|
||||||
|
@ -286,6 +286,16 @@ public class IndividualToSolrDocument {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void addMostSpecificTypeUris(Individual ind, SolrInputDocument doc){
|
||||||
|
List<String> mstURIs = ind.getMostSpecificTypeURIs();
|
||||||
|
if( mstURIs != null ){
|
||||||
|
for( String typeURI : mstURIs ){
|
||||||
|
if( typeURI != null && ! typeURI.trim().isEmpty() )
|
||||||
|
doc.addField(term.MOST_SPECIFIC_TYPE_URIS, typeURI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void addLabel(Individual ind, SolrInputDocument doc) {
|
protected void addLabel(Individual ind, SolrInputDocument doc) {
|
||||||
String value = "";
|
String value = "";
|
||||||
|
|
|
@ -13,10 +13,8 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfigurationLoader;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfigurationLoader;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.log.LogUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.log.LogUtils;
|
||||||
import freemarker.core.Environment;
|
|
||||||
import freemarker.core.ParseException;
|
import freemarker.core.ParseException;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
import freemarker.template.Template;
|
import freemarker.template.Template;
|
||||||
|
@ -75,18 +73,7 @@ public class FreemarkerProcessingServiceImpl implements
|
||||||
|
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
try {
|
try {
|
||||||
// Add directives to the map. For some reason, having them in the
|
template.process(map, writer);
|
||||||
// configuration is not enough.
|
|
||||||
map.putAll(FreemarkerConfiguration.getDirectives());
|
|
||||||
|
|
||||||
// Add request and servlet context as custom attributes of the
|
|
||||||
// environment, so they
|
|
||||||
// can be used in directives.
|
|
||||||
Environment env = template.createProcessingEnvironment(map, writer);
|
|
||||||
env.setCustomAttribute("request", req);
|
|
||||||
env.setCustomAttribute("context", req.getSession()
|
|
||||||
.getServletContext());
|
|
||||||
env.process();
|
|
||||||
return writer.toString();
|
return writer.toString();
|
||||||
} catch (TemplateException e) {
|
} catch (TemplateException e) {
|
||||||
throw new TemplateProcessingException(
|
throw new TemplateProcessingException(
|
||||||
|
|
|
@ -5,7 +5,11 @@ package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -31,11 +35,13 @@ import com.hp.hpl.jena.shared.Lock;
|
||||||
import com.hp.hpl.jena.vocabulary.RDF;
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.ontology.update.KnowledgeBaseUpdater;
|
import edu.cornell.mannlib.vitro.webapp.ontology.update.KnowledgeBaseUpdater;
|
||||||
import edu.cornell.mannlib.vitro.webapp.ontology.update.UpdateSettings;
|
import edu.cornell.mannlib.vitro.webapp.ontology.update.UpdateSettings;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes process to test whether the knowledge base needs any updating
|
* Invokes process to test whether the knowledge base needs any updating
|
||||||
|
@ -44,21 +50,10 @@ import edu.cornell.mannlib.vitro.webapp.ontology.update.UpdateSettings;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class UpdateKnowledgeBase implements ServletContextListener {
|
public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
|
|
||||||
public static final String KBM_REQURIED_AT_STARTUP = "KNOWLEDGE_BASE_MIGRATION_REQUIRED_AT_STARTUP";
|
public static final String KBM_REQURIED_AT_STARTUP = "KNOWLEDGE_BASE_MIGRATION_REQUIRED_AT_STARTUP";
|
||||||
private final static Log log = LogFactory.getLog(UpdateKnowledgeBase.class);
|
private final static Log log = LogFactory.getLog(UpdateKnowledgeBase.class);
|
||||||
|
|
||||||
private static final String DATA_DIR = "/WEB-INF/ontologies/update/";
|
private static final String DATA_DIR = "/WEB-INF/ontologies/update/";
|
||||||
private static final String LOG_DIR = "logs/";
|
|
||||||
private static final String CHANGED_DATA_DIR = "changedData/";
|
|
||||||
private static final String ASK_QUERY_FILE = DATA_DIR + "askUpdated.sparql";
|
|
||||||
private static final String SUCCESS_ASSERTIONS_FILE = DATA_DIR + "success.n3";
|
|
||||||
private static final String SUCCESS_RDF_FORMAT = "N3";
|
|
||||||
private static final String DIFF_FILE = DATA_DIR + "diff.tab.txt";
|
|
||||||
private static final String REMOVED_DATA_FILE = DATA_DIR + CHANGED_DATA_DIR + "removedData.n3";
|
|
||||||
private static final String ADDED_DATA_FILE = DATA_DIR + CHANGED_DATA_DIR + "addedData.n3";
|
|
||||||
private static final String SPARQL_CONSTRUCT_ADDITIONS_DIR = DATA_DIR + "sparqlConstructs/additions/";
|
|
||||||
private static final String SPARQL_CONSTRUCT_DELETIONS_DIR = DATA_DIR + "sparqlConstructs/deletions/";
|
|
||||||
private static final String OLD_TBOX_MODEL_DIR = DATA_DIR + "oldVersion/";
|
private static final String OLD_TBOX_MODEL_DIR = DATA_DIR + "oldVersion/";
|
||||||
private static final String NEW_TBOX_MODEL_DIR = "/WEB-INF/filegraph/tbox/";
|
private static final String NEW_TBOX_MODEL_DIR = "/WEB-INF/filegraph/tbox/";
|
||||||
private static final String OLD_TBOX_ANNOTATIONS_DIR = DATA_DIR + "oldAnnotations/";
|
private static final String OLD_TBOX_ANNOTATIONS_DIR = DATA_DIR + "oldAnnotations/";
|
||||||
|
@ -72,33 +67,15 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
private static final String LOADED_STARTUPT_DISPLAYMODEL_DIR = "/WEB-INF/ontologies/app/loadedAtStartup/";
|
private static final String LOADED_STARTUPT_DISPLAYMODEL_DIR = "/WEB-INF/ontologies/app/loadedAtStartup/";
|
||||||
private static final String OLD_DISPLAYMODEL_VIVOLISTVIEW_PATH = DATA_DIR + "oldDisplayModel/vivoListViewConfig.rdf";
|
private static final String OLD_DISPLAYMODEL_VIVOLISTVIEW_PATH = DATA_DIR + "oldDisplayModel/vivoListViewConfig.rdf";
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
try {
|
ServletContext ctx = sce.getServletContext();
|
||||||
ServletContext ctx = sce.getServletContext();
|
StartupStatus ss = StartupStatus.getBean(ctx);
|
||||||
|
|
||||||
// If the DATA_DIR directory doesn't exist no migration check will be done.
|
|
||||||
// This is a normal situation for Vitro.
|
|
||||||
File updateDirectory = new File(ctx.getRealPath(DATA_DIR));
|
|
||||||
if (!updateDirectory.exists()) {
|
|
||||||
log.debug("Directory " + ctx.getRealPath(DATA_DIR) + " does not exist, no migration check will be attempted.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String logFileName = DATA_DIR + LOG_DIR + timestampedFileName("knowledgeBaseUpdate", "log");
|
try {
|
||||||
String errorLogFileName = DATA_DIR + LOG_DIR + timestampedFileName("knowledgeBaseUpdate.error", "log");
|
|
||||||
|
|
||||||
UpdateSettings settings = new UpdateSettings();
|
UpdateSettings settings = new UpdateSettings();
|
||||||
settings.setAskUpdatedQueryFile(getAskUpdatedQueryPath(ctx));
|
putReportingPathsIntoSettings(ctx, settings);
|
||||||
settings.setDataDir(ctx.getRealPath(DATA_DIR));
|
|
||||||
settings.setSparqlConstructAdditionsDir(ctx.getRealPath(SPARQL_CONSTRUCT_ADDITIONS_DIR));
|
|
||||||
settings.setSparqlConstructDeletionsDir(ctx.getRealPath(SPARQL_CONSTRUCT_DELETIONS_DIR));
|
|
||||||
settings.setDiffFile(ctx.getRealPath(DIFF_FILE));
|
|
||||||
settings.setSuccessAssertionsFile(ctx.getRealPath(SUCCESS_ASSERTIONS_FILE));
|
|
||||||
settings.setSuccessRDFFormat(SUCCESS_RDF_FORMAT);
|
|
||||||
settings.setLogFile(ctx.getRealPath(logFileName));
|
|
||||||
settings.setErrorLogFile(ctx.getRealPath(errorLogFileName));
|
|
||||||
settings.setAddedDataFile(ctx.getRealPath(ADDED_DATA_FILE));
|
|
||||||
settings.setRemovedDataFile(ctx.getRealPath(REMOVED_DATA_FILE));
|
|
||||||
WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
|
WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
|
||||||
settings.setDefaultNamespace(wadf.getDefaultNamespace());
|
settings.setDefaultNamespace(wadf.getDefaultNamespace());
|
||||||
settings.setAssertionOntModelSelector(ModelAccess.on(ctx).getBaseOntModelSelector());
|
settings.setAssertionOntModelSelector(ModelAccess.on(ctx).getBaseOntModelSelector());
|
||||||
|
@ -157,21 +134,54 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ioe) {
|
} catch (Exception ioe) {
|
||||||
String errMsg = "Exception updating knowledge base " +
|
ss.fatal(this, "Exception updating knowledge base for ontology changes: ", ioe);
|
||||||
"for ontology changes: ";
|
|
||||||
// Tomcat doesn't always seem to print exceptions thrown from
|
|
||||||
// context listeners
|
|
||||||
System.out.println(errMsg);
|
|
||||||
ioe.printStackTrace();
|
|
||||||
throw new RuntimeException(errMsg, ioe);
|
|
||||||
}
|
}
|
||||||
} catch (Throwable t){
|
} catch (Throwable t){
|
||||||
log.warn("warning", t);
|
ss.fatal(this, "Exception updating knowledge base for ontology changes: ", t);
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
ss.fatal(this, "Exception updating knowledge base for ontology changes: ", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the directories where we will report on the update.
|
||||||
|
* Put the paths for the directories and files into the settings object.
|
||||||
|
*/
|
||||||
|
private void putReportingPathsIntoSettings(ServletContext ctx, UpdateSettings settings) throws IOException {
|
||||||
|
ConfigurationProperties props = ConfigurationProperties.getBean(ctx);
|
||||||
|
Path homeDir = Paths.get(props.getProperty("vitro.home"));
|
||||||
|
|
||||||
|
Path dataDir = createDirectory(homeDir, "upgrade", "knowledgeBase");
|
||||||
|
settings.setDataDir(dataDir.toString());
|
||||||
|
StartupStatus.getBean(ctx).info(this, "Updating knowledge base: reports are in '" + dataDir + "'");
|
||||||
|
|
||||||
|
settings.setAskUpdatedQueryFile(dataDir.resolve("askUpdated.sparql").toString());
|
||||||
|
settings.setDiffFile(dataDir.resolve("diff.tab.txt").toString());
|
||||||
|
settings.setSuccessAssertionsFile(dataDir.resolve("success.n3").toString());
|
||||||
|
settings.setSuccessRDFFormat("N3");
|
||||||
|
|
||||||
|
settings.setSparqlConstructAdditionsDir(createDirectory(dataDir, "sparqlConstructs", "additions").toString());
|
||||||
|
settings.setSparqlConstructDeletionsDir(createDirectory(dataDir, "sparqlConstructs", "deletions").toString());
|
||||||
|
|
||||||
|
Path changedDir = createDirectory(dataDir, "changedData");
|
||||||
|
settings.setAddedDataFile(changedDir.resolve("addedData.n3").toString());
|
||||||
|
settings.setRemovedDataFile(changedDir.resolve("removedData.n3").toString());
|
||||||
|
|
||||||
|
Path logDir = createDirectory(dataDir, "logs");
|
||||||
|
settings.setLogFile(logDir.resolve(timestampedFileName("knowledgeBaseUpdate", "log")).toString());
|
||||||
|
settings.setErrorLogFile(logDir.resolve(timestampedFileName("knowledgeBaseUpdate.error", "log")).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path createDirectory(Path parent, String... children) throws IOException {
|
||||||
|
Path dir = parent;
|
||||||
|
for (String child : children) {
|
||||||
|
dir = dir.resolve(child);
|
||||||
|
}
|
||||||
|
Files.createDirectories(dir);
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Multiple changes from 1.4 to 1.5 will occur
|
//Multiple changes from 1.4 to 1.5 will occur
|
||||||
//update migration model
|
//update migration model
|
||||||
|
@ -473,15 +483,11 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent arg0) {
|
public void contextDestroyed(ServletContextEvent arg0) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAskUpdatedQueryPath(ServletContext ctx) {
|
|
||||||
return ctx.getRealPath(ASK_QUERY_FILE);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String timestampedFileName(String prefix, String suffix) {
|
private static String timestampedFileName(String prefix, String suffix) {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-sss");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-sss");
|
||||||
return prefix + "." + sdf.format(new Date()) + "." + suffix;
|
return prefix + "." + sdf.format(new Date()) + "." + suffix;
|
||||||
|
|
|
@ -190,7 +190,7 @@ public class UpdatePermissionSetUris implements ServletContextListener {
|
||||||
File homeDirectory = new File(homeDirectoryPath);
|
File homeDirectory = new File(homeDirectoryPath);
|
||||||
confirmIsDirectory(homeDirectory);
|
confirmIsDirectory(homeDirectory);
|
||||||
|
|
||||||
File upgradeDirectory = createDirectory(homeDirectory, "upgrade");
|
File upgradeDirectory = createDirectory(homeDirectory, "upgrade/permissions");
|
||||||
String filename = timestampedFilename("UpgradePermissionSetUris",
|
String filename = timestampedFilename("UpgradePermissionSetUris",
|
||||||
".txt");
|
".txt");
|
||||||
this.file = new File(upgradeDirectory, filename);
|
this.file = new File(upgradeDirectory, filename);
|
||||||
|
|
|
@ -1,234 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
|
|
||||||
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.Individual;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.json.JsonServlet;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupsForRequest;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.JsonToFmModel;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateModel;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassTemplateModel;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual;
|
|
||||||
|
|
||||||
public class BrowseDataGetter implements PageDataGetter {
|
|
||||||
final static Log log = LogFactory.getLog(BrowseDataGetter.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Object> getData(ServletContext context,
|
|
||||||
VitroRequest vreq, String pageUri, Map<String, Object> page) {
|
|
||||||
try{
|
|
||||||
Map params = vreq.getParameterMap();
|
|
||||||
|
|
||||||
Mode mode = getMode( vreq, params );
|
|
||||||
switch( mode ){
|
|
||||||
case VCLASS_ALPHA:
|
|
||||||
return doClassAlphaDisplay(params,vreq,context);
|
|
||||||
case CLASS_GROUP:
|
|
||||||
return doClassGroupDisplay(params, vreq, context);
|
|
||||||
case VCLASS:
|
|
||||||
return doClassDisplay(params, vreq, context);
|
|
||||||
case ALL_CLASS_GROUPS:
|
|
||||||
return doAllClassGroupsDisplay( params, page, vreq, context);
|
|
||||||
default:
|
|
||||||
return doAllClassGroupsDisplay( params, page, vreq, context);
|
|
||||||
}
|
|
||||||
}catch(Throwable th){
|
|
||||||
log.error(th,th);
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getType() {
|
|
||||||
return DisplayVocabulary.HOME_PAGE_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get data servuice
|
|
||||||
@Override
|
|
||||||
public String getDataServiceUrl() {
|
|
||||||
return UrlBuilder.getUrl("/dataservice?getSolrIndividualsByVClass=1&vclassId=");
|
|
||||||
}
|
|
||||||
private Map<String, Object> doClassAlphaDisplay( Map params, VitroRequest request, ServletContext context) throws Exception {
|
|
||||||
Map<String,Object> body = new HashMap<String,Object>();
|
|
||||||
body.putAll(getCommonValues(context, request));
|
|
||||||
body.putAll(getClassAlphaValues(params,request,context));
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String,Object> getClassAlphaValues( Map params, VitroRequest request, ServletContext context) throws Exception{
|
|
||||||
Map<String,Object> map= new HashMap<String,Object>();
|
|
||||||
|
|
||||||
String classUri = getParam(Mode.VCLASS, request, params);
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
VClass vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(classUri);
|
|
||||||
map.put("class", new VClassTemplateModel(vclass));
|
|
||||||
|
|
||||||
JSONObject vclassRes = JsonServlet.getSolrIndividualsByVClass(vclass.getURI(), request, context);
|
|
||||||
map.put("totalCount", JsonToFmModel.convertJSONObjectToMap( (String) vclassRes.get("totalCount") ));
|
|
||||||
map.put("alpha", JsonToFmModel.convertJSONObjectToMap( (String) vclassRes.get("alpha") ));
|
|
||||||
map.put("individuals", JsonToFmModel.convertJSONArrayToList( (JSONArray) vclassRes.get("individuals") ));
|
|
||||||
map.put("pages", JsonToFmModel.convertJSONArrayToList( (JSONArray) vclassRes.get("pages") ));
|
|
||||||
map.put("letters", JsonToFmModel.convertJSONArrayToList( (JSONArray) vclassRes.get("letters") ));
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String,Object> getCommonValues( ServletContext context, VitroRequest vreq){
|
|
||||||
Map<String,Object> values = new HashMap<String,Object>();
|
|
||||||
|
|
||||||
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
|
|
||||||
List<VClassGroup> cgList = vcgc.getGroups();
|
|
||||||
LinkedList<VClassGroupTemplateModel> cgtmList = new LinkedList<VClassGroupTemplateModel>();
|
|
||||||
for( VClassGroup classGroup : cgList){
|
|
||||||
cgtmList.add( new VClassGroupTemplateModel( classGroup ));
|
|
||||||
}
|
|
||||||
values.put("vClassGroups",cgtmList);
|
|
||||||
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<String, Object> doAllClassGroupsDisplay( Map params, Map<String, Object> page, VitroRequest request, ServletContext context) {
|
|
||||||
Map<String,Object> body = new HashMap<String,Object>();
|
|
||||||
body.putAll(getCommonValues(context,request));
|
|
||||||
body.putAll(getAllClassGroupData(request, params, page, context));
|
|
||||||
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a list of all VClassGroups with vclasses with individual counts.
|
|
||||||
* @param params2
|
|
||||||
*/
|
|
||||||
protected Map<String,Object> getAllClassGroupData(VitroRequest request, Map params, Map<String, Object> page, ServletContext context){
|
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<String, Object> doClassDisplay( Map params,
|
|
||||||
VitroRequest request, ServletContext context) {
|
|
||||||
Map<String,Object> body = new HashMap<String,Object>();
|
|
||||||
|
|
||||||
body.putAll(getCommonValues(context,request));
|
|
||||||
body.putAll(getClassData(request,params,context));
|
|
||||||
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, Object> getClassData(VitroRequest request, Map params, ServletContext context) {
|
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
|
||||||
|
|
||||||
map.putAll(getClassGroupData(request, params,context));
|
|
||||||
|
|
||||||
String classUri = getParam(Mode.VCLASS, request, params);
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
VClass vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(classUri);
|
|
||||||
map.put("class", new VClassTemplateModel(vclass));
|
|
||||||
|
|
||||||
List<Individual> inds = vreq.getWebappDaoFactory().getIndividualDao()
|
|
||||||
.getIndividualsByVClass(vclass);
|
|
||||||
|
|
||||||
List<ListedIndividual> tInds = new ArrayList<ListedIndividual>(inds.size());
|
|
||||||
for( Individual ind : inds){
|
|
||||||
tInds.add(new ListedIndividual(ind, vreq));
|
|
||||||
}
|
|
||||||
map.put("individualsInClass", tInds);
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<String, Object> doClassGroupDisplay(Map params, VitroRequest request, ServletContext context) {
|
|
||||||
Map<String,Object> body = new HashMap<String,Object>();
|
|
||||||
body.putAll(getCommonValues(context,request));
|
|
||||||
body.putAll( getClassGroupData(request,params, context));
|
|
||||||
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<String, Object> getClassGroupData(VitroRequest request, Map params, ServletContext context) {
|
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
|
||||||
|
|
||||||
String vcgUri = getParam(Mode.CLASS_GROUP, request, params);
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
|
|
||||||
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(request);
|
|
||||||
VClassGroup vcg = vcgc.getGroup(vcgUri);
|
|
||||||
|
|
||||||
ArrayList<VClassTemplateModel> classes = new ArrayList<VClassTemplateModel>(vcg.size());
|
|
||||||
for( VClass vc : vcg){
|
|
||||||
classes.add(new VClassTemplateModel(vc));
|
|
||||||
}
|
|
||||||
map.put("classes", classes);
|
|
||||||
|
|
||||||
map.put("classGroup", new VClassGroupTemplateModel(vcg));
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
enum Mode{
|
|
||||||
VCLASS_ALPHA("vclassAlpha"),
|
|
||||||
VCLASS("vclassUri"),
|
|
||||||
CLASS_GROUP("classgroupUri"),
|
|
||||||
ALL_CLASS_GROUPS("all");
|
|
||||||
String param;
|
|
||||||
Mode(String param){
|
|
||||||
this.param = param;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final static Mode DEFAULT_MODE = Mode.ALL_CLASS_GROUPS;
|
|
||||||
|
|
||||||
protected Mode getMode(VitroRequest request, Map<String, Object> params){
|
|
||||||
for( Mode mode : Mode.values()){
|
|
||||||
String queryParam = request.getParameter( mode.param );
|
|
||||||
if( queryParam != null && !queryParam.isEmpty() ){
|
|
||||||
return mode;
|
|
||||||
}
|
|
||||||
Object obj = params.get( mode.param );
|
|
||||||
String param = obj != null ? obj.toString():null;
|
|
||||||
if( param != null && !param.isEmpty() ){
|
|
||||||
return mode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DEFAULT_MODE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getParam(Mode mode, VitroRequest request, Map params){
|
|
||||||
if( request.getParameter(mode.param) != null )
|
|
||||||
return request.getParameter(mode.param);
|
|
||||||
if( params.get(mode.param) != null )
|
|
||||||
return params.get(mode.param).toString();
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For processig of JSONObject
|
|
||||||
*/
|
|
||||||
public JSONObject convertToJSON(Map<String, Object> dataMap, VitroRequest vreq) {
|
|
||||||
JSONObject rObj = null;
|
|
||||||
return rObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,155 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupsForRequest;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateModel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This will pass these variables to the template:
|
|
||||||
* classGroupUri: uri of the classgroup associated with this page.
|
|
||||||
* vClassGroup: a data structure that is the classgroup associated with this page.
|
|
||||||
*/
|
|
||||||
public class ClassGroupPageData implements PageDataGetter{
|
|
||||||
private static final Log log = LogFactory.getLog(ClassGroupPageData.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String,Object> getData(ServletContext context, VitroRequest vreq, String pageUri, Map<String, Object> page ){
|
|
||||||
HashMap<String, Object> data = new HashMap<String,Object>();
|
|
||||||
String classGroupUri = vreq.getWebappDaoFactory().getPageDao().getClassGroupPage(pageUri);
|
|
||||||
data.put("classGroupUri", classGroupUri);
|
|
||||||
|
|
||||||
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
|
|
||||||
List<VClassGroup> vcgList = vcgc.getGroups();
|
|
||||||
VClassGroup group = null;
|
|
||||||
for( VClassGroup vcg : vcgList){
|
|
||||||
if( vcg.getURI() != null && vcg.getURI().equals(classGroupUri)){
|
|
||||||
group = vcg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( classGroupUri != null && !classGroupUri.isEmpty() && group == null ){
|
|
||||||
/*This could be for two reasons: one is that the classgroup doesn't exist
|
|
||||||
* The other is that there are no individuals in any of the classgroup's classes */
|
|
||||||
group = vreq.getWebappDaoFactory().getVClassGroupDao().getGroupByURI(classGroupUri);
|
|
||||||
if( group != null ){
|
|
||||||
List<VClassGroup> vcgFullList = vreq.getWebappDaoFactory().getVClassGroupDao()
|
|
||||||
.getPublicGroupsWithVClasses(false, true, false);
|
|
||||||
for( VClassGroup vcg : vcgFullList ){
|
|
||||||
if( classGroupUri.equals(vcg.getURI()) ){
|
|
||||||
group = vcg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( group == null ){
|
|
||||||
log.error("Cannot get classgroup '" + classGroupUri + "' for page '" + pageUri + "'");
|
|
||||||
}else{
|
|
||||||
setAllClassCountsToZero(group);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
log.error("classgroup " + classGroupUri + " does not exist in the system");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
log.debug("Retrieved class group " + group.getURI() + " and returning to template");
|
|
||||||
//if debug enabled, print out the number of entities within each class in the class gorup
|
|
||||||
if(log.isDebugEnabled()){
|
|
||||||
List<VClass> groupClasses = group.getVitroClassList();
|
|
||||||
for(VClass v: groupClasses) {
|
|
||||||
log.debug("Class " + v.getName() + " - " + v.getURI() + " has " + v.getEntityCount() + " entities");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data.put("vClassGroup", group); //may put null
|
|
||||||
|
|
||||||
//This page level data getters tries to set its own template,
|
|
||||||
// not all of the data getters need to do this.
|
|
||||||
data.put("bodyTemplate", "page-classgroup.ftl");
|
|
||||||
|
|
||||||
//Also add data service url
|
|
||||||
//Hardcoding for now, need a more dynamic way of doing this
|
|
||||||
data.put("dataServiceUrlIndividualsByVClass", this.getDataServiceUrl());
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static VClassGroupTemplateModel getClassGroup(String classGroupUri, ServletContext context, VitroRequest vreq){
|
|
||||||
|
|
||||||
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
|
|
||||||
List<VClassGroup> vcgList = vcgc.getGroups();
|
|
||||||
VClassGroup group = null;
|
|
||||||
for( VClassGroup vcg : vcgList){
|
|
||||||
if( vcg.getURI() != null && vcg.getURI().equals(classGroupUri)){
|
|
||||||
group = vcg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( classGroupUri != null && !classGroupUri.isEmpty() && group == null ){
|
|
||||||
/*This could be for two reasons: one is that the classgroup doesn't exist
|
|
||||||
* The other is that there are no individuals in any of the classgroup's classes */
|
|
||||||
group = vreq.getWebappDaoFactory().getVClassGroupDao().getGroupByURI(classGroupUri);
|
|
||||||
if( group != null ){
|
|
||||||
List<VClassGroup> vcgFullList = vreq.getWebappDaoFactory().getVClassGroupDao()
|
|
||||||
.getPublicGroupsWithVClasses(false, true, false);
|
|
||||||
for( VClassGroup vcg : vcgFullList ){
|
|
||||||
if( classGroupUri.equals(vcg.getURI()) ){
|
|
||||||
group = vcg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( group == null ){
|
|
||||||
log.error("Cannot get classgroup '" + classGroupUri + "'");
|
|
||||||
return null;
|
|
||||||
}else{
|
|
||||||
setAllClassCountsToZero(group);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
log.error("classgroup " + classGroupUri + " does not exist in the system");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new VClassGroupTemplateModel(group);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getType(){
|
|
||||||
return PageDataGetterUtils.generateDataGetterTypeURI(ClassGroupPageData.class.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get data servuice
|
|
||||||
@Override
|
|
||||||
public String getDataServiceUrl() {
|
|
||||||
return UrlBuilder.getUrl("/dataservice?getSolrIndividualsByVClass=1&vclassId=");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For processing of JSONObject
|
|
||||||
*/
|
|
||||||
//Currently empty, TODO: Review requirements
|
|
||||||
@Override
|
|
||||||
public JSONObject convertToJSON(Map<String, Object> dataMap, VitroRequest vreq) {
|
|
||||||
JSONObject rObj = null;
|
|
||||||
return rObj;
|
|
||||||
}
|
|
||||||
protected static void setAllClassCountsToZero(VClassGroup vcg){
|
|
||||||
for(VClass vc : vcg){
|
|
||||||
vc.setEntityCount(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,316 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.PageDao;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupsForRequest;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateModel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This will pass these variables to the template:
|
|
||||||
* classGroupUri: uri of the classgroup associated with this page.
|
|
||||||
* vClassGroup: a data structure that is the classgroup associated with this page.
|
|
||||||
*/
|
|
||||||
public class IndividualsForClassesDataGetter implements PageDataGetter{
|
|
||||||
private static final Log log = LogFactory.getLog(IndividualsForClassesDataGetter.class);
|
|
||||||
protected static String restrictClassesTemplateName = null;
|
|
||||||
@Override
|
|
||||||
public Map<String,Object> getData(ServletContext context, VitroRequest vreq, String pageUri, Map<String, Object> page ){
|
|
||||||
this.setTemplateName();
|
|
||||||
HashMap<String, Object> data = new HashMap<String,Object>();
|
|
||||||
//This is the old technique of getting class intersections
|
|
||||||
PageDao pageDao = vreq.getWebappDaoFactory().getPageDao();
|
|
||||||
Map<String, Object> classIntersectionsMap = getClassIntersectionsMap(pageDao, pageUri);
|
|
||||||
|
|
||||||
try{
|
|
||||||
List<String> classes = retrieveClasses(context, classIntersectionsMap);
|
|
||||||
List<String> restrictClasses = retrieveRestrictClasses(context, classIntersectionsMap);
|
|
||||||
log.debug("Retrieving classes for " + classes.toString() + " and restricting by " + restrictClasses.toString());
|
|
||||||
processClassesAndRestrictions(vreq, context, data, classes, restrictClasses);
|
|
||||||
//Also add data service url
|
|
||||||
//Hardcoding for now, need a more dynamic way of doing this
|
|
||||||
data.put("dataServiceUrlIndividualsByVClass", this.getDataServiceUrl());
|
|
||||||
//this is the class group associated with the data getter utilized for display on menu editing, not the custom one created
|
|
||||||
data.put("classGroupUri", pageDao.getClassGroupPage(pageUri));
|
|
||||||
} catch(Exception ex) {
|
|
||||||
log.error("An error occurred retrieving Vclass Intersection individuals", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setTemplateName() {
|
|
||||||
this.restrictClassesTemplateName = "restricted";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<String, Object> getClassIntersectionsMap(PageDao pageDao,
|
|
||||||
String pageUri) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return pageDao.getClassesAndRestrictionsForPage(pageUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<String> retrieveClasses(
|
|
||||||
ServletContext context, Map<String, Object> classIntersectionsMap) {
|
|
||||||
List<String> restrictClasses = (List<String>) classIntersectionsMap.get("classes");
|
|
||||||
return restrictClasses;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<String> retrieveRestrictClasses(
|
|
||||||
ServletContext context, Map<String, Object> classIntersectionsMap) {
|
|
||||||
List<String> restrictClasses = (List<String>) classIntersectionsMap.get("restrictClasses");
|
|
||||||
return restrictClasses;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void processClassesAndRestrictions(VitroRequest vreq, ServletContext context,
|
|
||||||
HashMap<String, Object> data, List<String> classes, List<String> restrictClasses ) {
|
|
||||||
processClassesForDisplay(vreq, context, data, classes);
|
|
||||||
processRestrictionClasses(vreq, context, data, restrictClasses);
|
|
||||||
processIntersections(vreq, context, data);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//At this point, data specifices whether or not intersections included
|
|
||||||
private void processIntersections(VitroRequest vreq,
|
|
||||||
ServletContext context, HashMap<String, Object> data) {
|
|
||||||
VClassGroup classesGroup = (VClassGroup) data.get("vClassGroup");
|
|
||||||
List<VClass> vclassList = classesGroup.getVitroClassList();
|
|
||||||
List<VClass> restrictClasses = (List<VClass>) data.get("restrictVClasses");
|
|
||||||
//if there are restrict classes, then update counts
|
|
||||||
if(restrictClasses.size() > 0) {
|
|
||||||
log.debug("Restriction classes exist");
|
|
||||||
List<VClass> newVClassList = new ArrayList<VClass>();
|
|
||||||
//Iterate through vclasses and get updated counts, iterated and saved in same order as initially included
|
|
||||||
for(VClass v: vclassList) {
|
|
||||||
int oldCount = v.getEntityCount();
|
|
||||||
//Making a copy so as to ensure we don't touch the values in the cache
|
|
||||||
VClass copyVClass = makeCopyVClass(v);
|
|
||||||
int count = retrieveCount(vreq, context, v, restrictClasses);
|
|
||||||
if(oldCount != count) {
|
|
||||||
log.debug("Old count was " + v.getEntityCount() + " and New count for " + v.getURI() + " is " + count);
|
|
||||||
copyVClass.setEntityCount(count);
|
|
||||||
}
|
|
||||||
newVClassList.add(copyVClass);
|
|
||||||
}
|
|
||||||
classesGroup.setVitroClassList(newVClassList);
|
|
||||||
//TODO: Do we need to do this again or will this already be reset?
|
|
||||||
data.put("vClassGroup", classesGroup);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private VClass makeCopyVClass(VClass v) {
|
|
||||||
VClass copyVClass = new VClass(v.getURI());
|
|
||||||
copyVClass.setLocalName(copyVClass.getLocalName());
|
|
||||||
copyVClass.setDisplayRank(v.getDisplayRank());
|
|
||||||
copyVClass.setName(v.getName());
|
|
||||||
copyVClass.setNamespace(v.getNamespace());
|
|
||||||
copyVClass.setEntityCount(v.getEntityCount());
|
|
||||||
return copyVClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
//update class count based on restrict classes
|
|
||||||
private int retrieveCount(VitroRequest vreq, ServletContext context, VClass v, List<VClass> restrictClasses) {
|
|
||||||
//Execute solr query that returns only count of individuals
|
|
||||||
log.debug("Entity count is " + v.getEntityCount());
|
|
||||||
List<String> classUris = new ArrayList<String>();
|
|
||||||
classUris.add(v.getURI());
|
|
||||||
for(VClass r: restrictClasses) {
|
|
||||||
classUris.add(r.getURI());
|
|
||||||
}
|
|
||||||
long count = PageDataGetterUtils.getIndividualCountForIntersection(vreq, context, classUris);
|
|
||||||
return new Long(count).intValue();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processClassesForDisplay(VitroRequest vreq, ServletContext context, HashMap<String, Object> data, List<String> classes) {
|
|
||||||
VClassGroup classesGroup = new VClassGroup();
|
|
||||||
classesGroup.setURI("displayClasses");
|
|
||||||
log.debug("Processing classes that will be displayed");
|
|
||||||
List<VClass> vClasses = new ArrayList<VClass>();
|
|
||||||
|
|
||||||
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
|
|
||||||
for(String classUri: classes) {
|
|
||||||
//Retrieve vclass from cache to get the count
|
|
||||||
VClass vclass = vcgc.getCachedVClass(classUri);
|
|
||||||
//if not found in cache, possibly due to not being in any class group
|
|
||||||
if(vclass == null) {
|
|
||||||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(classUri);
|
|
||||||
}
|
|
||||||
if(vclass != null) {
|
|
||||||
log.debug("VClass does exist for " + classUri + " and entity count is " + vclass.getEntityCount());
|
|
||||||
vClasses.add(vclass);
|
|
||||||
} else {
|
|
||||||
log.debug("Vclass " + classUri + " does not exist in the cache");
|
|
||||||
log.error("Error occurred, vclass does not exist for this uri " + classUri);
|
|
||||||
//Throw exception here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Sort these classes
|
|
||||||
Collections.sort(vClasses);
|
|
||||||
log.debug("Sorting complete for V Classes");
|
|
||||||
classesGroup.setVitroClassList(vClasses);
|
|
||||||
log.debug("Returning vitro class list in data for template");
|
|
||||||
//Set vclass group
|
|
||||||
data.put("vClassGroup", classesGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processRestrictionClasses(VitroRequest vreq, ServletContext context,
|
|
||||||
HashMap<String, Object> data, List<String> restrictClasses) {
|
|
||||||
try {
|
|
||||||
VClassGroup restrictClassesGroup = new VClassGroup();
|
|
||||||
restrictClassesGroup.setURI("restrictClasses");
|
|
||||||
|
|
||||||
List<VClass> restrictVClasses = new ArrayList<VClass>();
|
|
||||||
|
|
||||||
List<String> urlEncodedRestrictClasses = new ArrayList<String>();
|
|
||||||
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
|
|
||||||
|
|
||||||
if(restrictClasses.size() > 0) {
|
|
||||||
//classes for restriction are not displayed so don't need to include their class individual counts
|
|
||||||
for(String restrictClassUri: restrictClasses) {
|
|
||||||
//Also uses cache to remain consistent with process classes and also allow
|
|
||||||
//vclasses to be returned even if switched to display model, although
|
|
||||||
//uris used within display model editing and not vclass objects
|
|
||||||
VClass vclass = vcgc.getCachedVClass(restrictClassUri);
|
|
||||||
//if not found in cache, possibly due to not being in any class group
|
|
||||||
if(vclass == null) {
|
|
||||||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(restrictClassUri);
|
|
||||||
}
|
|
||||||
if(vclass != null) {
|
|
||||||
log.debug("Found restrict class and adding to list " + restrictClassUri);
|
|
||||||
restrictVClasses.add(vclass);
|
|
||||||
} else {
|
|
||||||
log.error("Error occurred, vclass does not exist for this uri " + restrictClassUri);
|
|
||||||
}
|
|
||||||
//Assuming utf-8?
|
|
||||||
urlEncodedRestrictClasses.add(URLEncoder.encode(restrictClassUri, "UTF-8"));
|
|
||||||
}
|
|
||||||
|
|
||||||
restrictClassesGroup.setVitroClassList(restrictVClasses);
|
|
||||||
restrictClassesGroup.setIndividualCount(restrictVClasses.size());
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
String[] restrictClassesArray = new String[urlEncodedRestrictClasses.size()];
|
|
||||||
restrictClassesArray = urlEncodedRestrictClasses.toArray(restrictClassesArray);
|
|
||||||
|
|
||||||
//In case just want uris
|
|
||||||
log.debug("Variable name for including restriction classes " + getRestrictClassesTemplateName());
|
|
||||||
data.put(getRestrictClassesTemplateName(), StringUtils.join(restrictClassesArray, ","));
|
|
||||||
data.put("restrictVClasses", restrictVClasses);
|
|
||||||
//not sure if this is useful
|
|
||||||
data.put("restrictVClassGroup", restrictClassesGroup);
|
|
||||||
} catch(Exception ex) {
|
|
||||||
log.error("An error occurred in processing restriction classes ", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static VClassGroupTemplateModel getClassGroup(String classGroupUri, ServletContext context, VitroRequest vreq){
|
|
||||||
|
|
||||||
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
|
|
||||||
List<VClassGroup> vcgList = vcgc.getGroups();
|
|
||||||
VClassGroup group = null;
|
|
||||||
for( VClassGroup vcg : vcgList){
|
|
||||||
if( vcg.getURI() != null && vcg.getURI().equals(classGroupUri)){
|
|
||||||
group = vcg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( classGroupUri != null && !classGroupUri.isEmpty() && group == null ){
|
|
||||||
/*This could be for two reasons: one is that the classgroup doesn't exist
|
|
||||||
* The other is that there are no individuals in any of the classgroup's classes */
|
|
||||||
group = vreq.getWebappDaoFactory().getVClassGroupDao().getGroupByURI(classGroupUri);
|
|
||||||
if( group != null ){
|
|
||||||
List<VClassGroup> vcgFullList = vreq.getWebappDaoFactory().getVClassGroupDao()
|
|
||||||
.getPublicGroupsWithVClasses(false, true, false);
|
|
||||||
for( VClassGroup vcg : vcgFullList ){
|
|
||||||
if( classGroupUri.equals(vcg.getURI()) ){
|
|
||||||
group = vcg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( group == null ){
|
|
||||||
log.error("Cannot get classgroup '" + classGroupUri + "'");
|
|
||||||
return null;
|
|
||||||
}else{
|
|
||||||
setAllClassCountsToZero(group);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
log.error("classgroup " + classGroupUri + " does not exist in the system");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new VClassGroupTemplateModel(group);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getType(){
|
|
||||||
return PageDataGetterUtils.generateDataGetterTypeURI(IndividualsForClassesDataGetter.class.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get data servuice
|
|
||||||
@Override
|
|
||||||
public String getDataServiceUrl() {
|
|
||||||
return UrlBuilder.getUrl("/dataservice?getSolrIndividualsByVClasses=1&vclassId=");
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* For processig of JSONObject
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public JSONObject convertToJSON(Map<String, Object> map, VitroRequest vreq) {
|
|
||||||
JSONObject rObj = PageDataGetterUtils.processVclassResultsJSON(map, vreq, true);
|
|
||||||
return rObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void setAllClassCountsToZero(VClassGroup vcg){
|
|
||||||
for(VClass vc : vcg){
|
|
||||||
vc.setEntityCount(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static String getAlphaParameter(VitroRequest request){
|
|
||||||
return request.getParameter("alpha");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static int getPageParameter(VitroRequest request) {
|
|
||||||
String pageStr = request.getParameter("page");
|
|
||||||
if( pageStr != null ){
|
|
||||||
try{
|
|
||||||
return Integer.parseInt(pageStr);
|
|
||||||
}catch(NumberFormatException nfe){
|
|
||||||
log.debug("could not parse page parameter");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get template parameter
|
|
||||||
private static String getRestrictClassesTemplateName() {
|
|
||||||
return restrictClassesTemplateName;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
public interface PageDataGetter{
|
|
||||||
Map<String,Object> getData(ServletContext contect, VitroRequest vreq, String pageUri, Map<String, Object> page );
|
|
||||||
|
|
||||||
/** Gets the type that this class applies to */
|
|
||||||
//This has been changed to return the class name for data getter used in menu management
|
|
||||||
String getType();
|
|
||||||
|
|
||||||
//get data service url based on data getter requirements
|
|
||||||
//Get data servuice
|
|
||||||
String getDataServiceUrl();
|
|
||||||
|
|
||||||
/**Convert data to JSONObject based on what's required for the data processing**/
|
|
||||||
JSONObject convertToJSON(Map<String, Object> map, VitroRequest vreq);
|
|
||||||
}
|
|
|
@ -1,339 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
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.beans.VClassGroup;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
|
||||||
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.controller.json.JsonServlet;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupsForRequest;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
|
||||||
|
|
||||||
public class PageDataGetterUtils {
|
|
||||||
protected static final String DATA_GETTER_MAP = "pageTypeToDataGetterMap";
|
|
||||||
private static final Log log = LogFactory.getLog(PageDataGetterUtils.class);
|
|
||||||
|
|
||||||
public static Map<String,Object> getDataForPage(String pageUri, VitroRequest vreq, ServletContext context) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
|
|
||||||
//Based on page type get the appropriate data getter
|
|
||||||
Map<String, Object> page = vreq.getWebappDaoFactory().getPageDao().getPage(pageUri);
|
|
||||||
|
|
||||||
Map<String,Object> data = new HashMap<String,Object>();
|
|
||||||
List<PageDataGetter> dataGetters = getPageDataGetterObjects(vreq, pageUri);
|
|
||||||
for(PageDataGetter getter: dataGetters) {
|
|
||||||
try{
|
|
||||||
Map<String,Object> moreData = null;
|
|
||||||
moreData = getAdditionalData(pageUri, getter.getType(), page, vreq, getter, context);
|
|
||||||
if( moreData != null)
|
|
||||||
data.putAll(moreData);
|
|
||||||
}catch(Throwable th){
|
|
||||||
log.error(th,th);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Convert data to JSON for page uri based on type and related datagetters
|
|
||||||
* TODO: How to handle different data getters? Will this replace json fields or add to them?
|
|
||||||
* @throws ClassNotFoundException
|
|
||||||
* @throws IllegalAccessException
|
|
||||||
* @throws InstantiationException
|
|
||||||
*/
|
|
||||||
public static JSONObject covertDataToJSONForPage(String pageUri, Map<String, Object> data, VitroRequest vreq, ServletContext context) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
|
|
||||||
//Get PageDataGetter types associated with pageUri
|
|
||||||
JSONObject rObj = null;
|
|
||||||
List<PageDataGetter> dataGetters = getPageDataGetterObjects(vreq, pageUri);
|
|
||||||
for(PageDataGetter getter: dataGetters) {
|
|
||||||
JSONObject typeObj = null;
|
|
||||||
try{
|
|
||||||
typeObj = getter.convertToJSON(data, vreq);
|
|
||||||
if( typeObj != null) {
|
|
||||||
//Copy over everything from this type Obj to
|
|
||||||
//TODO: Review how to handle duplicate keys, etc.
|
|
||||||
if(rObj != null) {
|
|
||||||
//For now, just nests as separate entry
|
|
||||||
rObj.put(getter.getType(), typeObj);
|
|
||||||
} else {
|
|
||||||
rObj = typeObj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch(Throwable th){
|
|
||||||
log.error(th,th);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String,Object> getAdditionalData(
|
|
||||||
String pageUri, String dataGetterName, Map<String, Object> page, VitroRequest vreq, PageDataGetter getter, ServletContext context) {
|
|
||||||
if(dataGetterName == null || dataGetterName.isEmpty())
|
|
||||||
return Collections.emptyMap();
|
|
||||||
|
|
||||||
|
|
||||||
if( getter != null ){
|
|
||||||
try{
|
|
||||||
log.debug("Retrieve data for this data getter for " + pageUri);
|
|
||||||
return getter.getData(context, vreq, pageUri, page);
|
|
||||||
}catch(Throwable th){
|
|
||||||
log.error(th,th);
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* For the page, get the actual Data Getters to be employed.
|
|
||||||
* @throws ClassNotFoundException
|
|
||||||
* @throws IllegalAccessException
|
|
||||||
* @throws InstantiationException
|
|
||||||
*/
|
|
||||||
public static List<PageDataGetter> getPageDataGetterObjects(VitroRequest vreq, String pageUri) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
|
|
||||||
List<PageDataGetter> dataGetterObjects = new ArrayList<PageDataGetter>();
|
|
||||||
|
|
||||||
List<String> dataGetterClassNames = vreq.getWebappDaoFactory().getPageDao().getDataGetterClass(pageUri);
|
|
||||||
if( dataGetterClassNames == null )
|
|
||||||
return Collections.emptyList();
|
|
||||||
|
|
||||||
for(String dgClassName: dataGetterClassNames) {
|
|
||||||
String className = getClassNameFromUri(dgClassName);
|
|
||||||
Class<?> clz = Class.forName(className);
|
|
||||||
|
|
||||||
if( PageDataGetter.class.isAssignableFrom(clz)){
|
|
||||||
PageDataGetter pg = (PageDataGetter) clz.newInstance();
|
|
||||||
dataGetterObjects.add(pg);
|
|
||||||
}// else skip if class does not implement PageDataGetter
|
|
||||||
}
|
|
||||||
|
|
||||||
return dataGetterObjects;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Class URIs returned include "java:" and to instantiate object need to remove java: portion
|
|
||||||
public static String getClassNameFromUri(String dataGetterClassUri) {
|
|
||||||
if( !StringUtils.isEmpty(dataGetterClassUri) && dataGetterClassUri.contains("java:")) {
|
|
||||||
String[] splitArray = dataGetterClassUri.split("java:");
|
|
||||||
if(splitArray.length > 1) {
|
|
||||||
return splitArray[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dataGetterClassUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Individual count for Solr query for intersection of multiple classes
|
|
||||||
*/
|
|
||||||
public static long getIndividualCountForIntersection(VitroRequest vreq, ServletContext context, List<String> classUris) {
|
|
||||||
return IndividualListController.getIndividualCount(classUris, vreq.getWebappDaoFactory().getIndividualDao(), context);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process results related to VClass or vclasses. Handles both single and multiple vclasses being sent.
|
|
||||||
*/
|
|
||||||
public static JSONObject processVclassResultsJSON(Map<String, Object> 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<String> 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<String> 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<Individual> inds = (List<Individual>)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<PageRecord> pages = (List<PageRecord>)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<String> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copied from JSONServlet as expect this to be related to VitroClassGroup
|
|
||||||
*/
|
|
||||||
public static JSONObject processVClassGroupJSON(VitroRequest vreq, ServletContext context, VClassGroup vcg) {
|
|
||||||
JSONObject map = new JSONObject();
|
|
||||||
try {
|
|
||||||
ArrayList<JSONObject> classes = new ArrayList<JSONObject>(vcg.size());
|
|
||||||
for( VClass vc : vcg){
|
|
||||||
JSONObject vcObj = new JSONObject();
|
|
||||||
vcObj.put("name", vc.getName());
|
|
||||||
vcObj.put("URI", vc.getURI());
|
|
||||||
vcObj.put("entityCount", vc.getEntityCount());
|
|
||||||
classes.add(vcObj);
|
|
||||||
}
|
|
||||||
map.put("classes", classes);
|
|
||||||
map.put("classGroupName", vcg.getPublicName());
|
|
||||||
map.put("classGroupUri", vcg.getURI());
|
|
||||||
|
|
||||||
} catch(Exception ex) {
|
|
||||||
log.error("Error occurred in processing VClass group ", ex);
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Get All VClass Groups information
|
|
||||||
//Used within menu management and processing
|
|
||||||
//TODO: Check if more appropriate location possible
|
|
||||||
public static List<HashMap<String, String>> getClassGroups(HttpServletRequest req) {
|
|
||||||
//Wanted this to be
|
|
||||||
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(req);
|
|
||||||
List<VClassGroup> vcgList = vcgc.getGroups();
|
|
||||||
//For now encoding as hashmap with label and URI as trying to retrieve class group
|
|
||||||
//results in errors for some reason
|
|
||||||
List<HashMap<String, String>> classGroups = new ArrayList<HashMap<String, String>>();
|
|
||||||
for(VClassGroup vcg: vcgList) {
|
|
||||||
HashMap<String, String> hs = new HashMap<String, String>();
|
|
||||||
hs.put("publicName", vcg.getPublicName());
|
|
||||||
hs.put("URI", vcg.getURI());
|
|
||||||
classGroups.add(hs);
|
|
||||||
}
|
|
||||||
return classGroups;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return data getter type to be employed in display model
|
|
||||||
public static String generateDataGetterTypeURI(String dataGetterClassName) {
|
|
||||||
return "java:" + dataGetterClassName;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Check whether this needs to be put here or elsewhere, as this is data getter specific
|
|
||||||
//with respect to class groups
|
|
||||||
//Need to use VClassGroupCache to retrieve class group information - this is the information returned from "for class group"
|
|
||||||
public static void getClassGroupForDataGetter(HttpServletRequest req, Map<String, Object> pageData, Map<String, Object> templateData) {
|
|
||||||
//Get the class group from VClassGroup, this is the same as the class group for the class group page data getter
|
|
||||||
//and the associated class group (not custom) for individuals datagetter
|
|
||||||
String classGroupUri = (String) pageData.get("classGroupUri");
|
|
||||||
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(req);
|
|
||||||
VClassGroup group = vcgc.getGroup(classGroupUri);
|
|
||||||
|
|
||||||
templateData.put("classGroup", group);
|
|
||||||
templateData.put("associatedPage", group.getPublicName());
|
|
||||||
templateData.put("associatedPageURI", group.getURI());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -77,10 +77,10 @@ public class IndividualShortViewDirective extends BaseTemplateDirectiveModel {
|
||||||
private void renderShortView(Individual individual,
|
private void renderShortView(Individual individual,
|
||||||
ShortViewContext svContext) {
|
ShortViewContext svContext) {
|
||||||
Environment env = Environment.getCurrentEnvironment();
|
Environment env = Environment.getCurrentEnvironment();
|
||||||
|
HttpServletRequest request = (HttpServletRequest) env
|
||||||
|
.getCustomAttribute("request");
|
||||||
|
ServletContext ctx = request.getSession().getServletContext();
|
||||||
|
|
||||||
ServletContext ctx = (ServletContext) env.getCustomAttribute("context");
|
|
||||||
VitroRequest vreq = new VitroRequest(
|
|
||||||
(HttpServletRequest) env.getCustomAttribute("request"));
|
|
||||||
ShortViewService svs = ShortViewServiceSetup.getService(ctx);
|
ShortViewService svs = ShortViewServiceSetup.getService(ctx);
|
||||||
if (svs == null) {
|
if (svs == null) {
|
||||||
log.warn("ShortViewService was not initialized properly.");
|
log.warn("ShortViewService was not initialized properly.");
|
||||||
|
@ -88,7 +88,7 @@ public class IndividualShortViewDirective extends BaseTemplateDirectiveModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateAndSupplementalData svInfo = svs.getShortViewInfo(individual,
|
TemplateAndSupplementalData svInfo = svs.getShortViewInfo(individual,
|
||||||
svContext, vreq);
|
svContext, new VitroRequest(request));
|
||||||
|
|
||||||
ObjectWrapper objectWrapper = env.getConfiguration().getObjectWrapper();
|
ObjectWrapper objectWrapper = env.getConfiguration().getObjectWrapper();
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -57,7 +56,7 @@ public abstract class Widget {
|
||||||
|
|
||||||
public String doMarkup(Environment env, Map params) {
|
public String doMarkup(Environment env, Map params) {
|
||||||
HttpServletRequest request = (HttpServletRequest) env.getCustomAttribute("request");
|
HttpServletRequest request = (HttpServletRequest) env.getCustomAttribute("request");
|
||||||
ServletContext context = (ServletContext) env.getCustomAttribute("context");
|
ServletContext context = request.getSession().getServletContext();
|
||||||
|
|
||||||
WidgetTemplateValues values = null;
|
WidgetTemplateValues values = null;
|
||||||
|
|
||||||
|
@ -120,15 +119,7 @@ public abstract class Widget {
|
||||||
// We need to give each widget macro template a unique key in the StringTemplateLoader, and check
|
// We need to give each widget macro template a unique key in the StringTemplateLoader, and check
|
||||||
// if it's already there or else add it. Leave this for later.
|
// if it's already there or else add it. Leave this for later.
|
||||||
Template template = new Template("widget", new StringReader(templateString), env.getConfiguration());
|
Template template = new Template("widget", new StringReader(templateString), env.getConfiguration());
|
||||||
|
template.process(map, out);
|
||||||
// JB KLUGE The widget is processed in its own environment, which doesn't include these custom attributes.
|
|
||||||
// JB KLUGE Put them in.
|
|
||||||
Environment widgetEnv = template.createProcessingEnvironment(map, out);
|
|
||||||
ServletRequest request = (ServletRequest) env.getCustomAttribute("request");
|
|
||||||
widgetEnv.setCustomAttribute("request", request);
|
|
||||||
widgetEnv.setCustomAttribute("context", env.getCustomAttribute("context"));
|
|
||||||
widgetEnv.setLocale(request.getLocale());
|
|
||||||
widgetEnv.process();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Could not process widget " + widgetName, e);
|
log.error("Could not process widget " + widgetName, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.util.Set;
|
||||||
import javax.media.jai.JAI;
|
import javax.media.jai.JAI;
|
||||||
import javax.media.jai.RenderedOp;
|
import javax.media.jai.RenderedOp;
|
||||||
import javax.media.jai.operator.StreamDescriptor;
|
import javax.media.jai.operator.StreamDescriptor;
|
||||||
import javax.media.jai.widget.ImageCanvas;
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
@ -107,7 +106,7 @@ public class ImageUploaderThumbnailerTester_2 extends Frame {
|
||||||
JPanel p = new JPanel();
|
JPanel p = new JPanel();
|
||||||
p.setLayout(new BorderLayout());
|
p.setLayout(new BorderLayout());
|
||||||
p.add("South", l);
|
p.add("South", l);
|
||||||
p.add("Center", new ImageCanvas(image));
|
p.add("Center", new javax.media.jai.widget.ImageCanvas(image));
|
||||||
p.setBackground(new Color(0xFFFFFF));
|
p.setBackground(new Color(0xFFFFFF));
|
||||||
p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||||
|
|
||||||
|
|
|
@ -192,6 +192,7 @@ public class JsonServletTest extends AbstractTestClass {
|
||||||
public void individualsByClassNoIndividuals() throws ServletException,
|
public void individualsByClassNoIndividuals() throws ServletException,
|
||||||
IOException {
|
IOException {
|
||||||
setLoggerLevel(JsonServlet.class, Level.FATAL);
|
setLoggerLevel(JsonServlet.class, Level.FATAL);
|
||||||
|
setLoggerLevel(ModelAccess.class, Level.ERROR);
|
||||||
String vclassId = "http://myVclass";
|
String vclassId = "http://myVclass";
|
||||||
vcDao.setVClass(vclassId, new VClass(vclassId));
|
vcDao.setVClass(vclassId, new VClass(vclassId));
|
||||||
req.addParameter(GET_SOLR_INDIVIDUALS_BY_VCLASS, "true");
|
req.addParameter(GET_SOLR_INDIVIDUALS_BY_VCLASS, "true");
|
||||||
|
|
|
@ -67,15 +67,6 @@ public class DataGetterUtilsTest extends AbstractTestClass{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNonPageDataGetter() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException{
|
|
||||||
DataGetter dg = DataGetterUtils.dataGetterForURI(vreq, displayModel,dataGetterX);
|
|
||||||
Assert.assertNull(dg);
|
|
||||||
|
|
||||||
List<DataGetter> dgList =
|
|
||||||
DataGetterUtils.getDataGettersForPage(vreq, displayModel, pageX);
|
|
||||||
Assert.assertNotNull(dgList);
|
|
||||||
Assert.assertTrue("List should be, it was not", dgList.size() == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,14 +20,5 @@ display:query1data
|
||||||
display:saveToVar "people" .
|
display:saveToVar "people" .
|
||||||
|
|
||||||
|
|
||||||
### test of what happens with a PageDataGetter instead of a DataGetter ###
|
|
||||||
|
|
||||||
display:pageX
|
|
||||||
a display:Page ;
|
|
||||||
display:title "A PageDataGetter, not a DataGetter" ;
|
|
||||||
display:urlMapping "/query2" ;
|
|
||||||
display:hasDataGetter display:pageDataGetterX .
|
|
||||||
|
|
||||||
display:pageDataGetterX
|
|
||||||
a <java:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData> .
|
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.log4j.Level;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|
||||||
import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.SimpleOntModelSelector;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
|
||||||
|
|
||||||
public class PageDataGetterUtilsTest extends AbstractTestClass{
|
|
||||||
OntModel displayModel;
|
|
||||||
WebappDaoFactory wdf;
|
|
||||||
|
|
||||||
String pageURI = "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#pageX";
|
|
||||||
String pageURI_2 = "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#SPARQLPage";
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
// Suppress error logging.
|
|
||||||
setLoggerLevel(RDFDefaultErrorHandler.class, Level.OFF);
|
|
||||||
|
|
||||||
OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM);
|
|
||||||
InputStream in = PageDataGetterUtilsTest.class.getResourceAsStream("resources/pageDataGetter.n3");
|
|
||||||
model.read(in,"","N3");
|
|
||||||
displayModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM,model);
|
|
||||||
|
|
||||||
SimpleOntModelSelector sos = new SimpleOntModelSelector( ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM));
|
|
||||||
sos.setDisplayModel(displayModel);
|
|
||||||
|
|
||||||
wdf = new WebappDaoFactoryJena(sos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetPageDataGetterObjects() throws Exception{
|
|
||||||
VitroRequest vreq = new VitroRequest( new HttpServletRequestStub() );
|
|
||||||
ModelAccess.on(vreq).setWebappDaoFactory(wdf);
|
|
||||||
|
|
||||||
List<PageDataGetter> pdgList = PageDataGetterUtils.getPageDataGetterObjects(vreq, pageURI);
|
|
||||||
Assert.assertNotNull(pdgList);
|
|
||||||
Assert.assertTrue("should have one PageDataGetter", pdgList.size() == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetNonPageDataGetterObjects() throws Exception{
|
|
||||||
VitroRequest vreq = new VitroRequest( new HttpServletRequestStub() );
|
|
||||||
ModelAccess.on(vreq).setWebappDaoFactory(wdf);
|
|
||||||
|
|
||||||
List<PageDataGetter> pdgList = PageDataGetterUtils.getPageDataGetterObjects(vreq, pageURI_2);
|
|
||||||
Assert.assertNotNull(pdgList);
|
|
||||||
Assert.assertTrue("should have no PageDataGetters", pdgList.size() == 0);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
# $This file is distributed under the terms of the license in /doc/license.txt$
|
|
||||||
|
|
||||||
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
|
||||||
@prefix display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> .
|
|
||||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
|
||||||
@prefix core: <http://vivoweb.org/ontology/core#> .
|
|
||||||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
|
||||||
|
|
||||||
### This file is for the test PageDataGetterUtilsTest.java
|
|
||||||
|
|
||||||
display:SPARQLPage
|
|
||||||
a display:Page ;
|
|
||||||
display:title "TestQuery" ;
|
|
||||||
display:urlMapping "/query1" ;
|
|
||||||
display:hasDataGetter display:query1data .
|
|
||||||
|
|
||||||
display:query1data
|
|
||||||
a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
|
|
||||||
display:query "SELECT * WHERE { ?uri a <http://xmlns.com/foaf/0.1/Person> } " ;
|
|
||||||
display:saveToVar "people" .
|
|
||||||
|
|
||||||
display:pageX
|
|
||||||
a display:Page ;
|
|
||||||
display:title "A PageDataGetter, not a DataGetter" ;
|
|
||||||
display:urlMapping "/query2" ;
|
|
||||||
display:hasDataGetter display:pageDataGetterX .
|
|
||||||
|
|
||||||
display:pageDataGetterX
|
|
||||||
a <java:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData> .
|
|
||||||
|
|
|
@ -200,6 +200,7 @@ public class ServletContextStub implements ServletContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public Servlet getServlet(String arg0) throws ServletException {
|
public Servlet getServlet(String arg0) throws ServletException {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"ServletContextStub.getServlet() not implemented.");
|
"ServletContextStub.getServlet() not implemented.");
|
||||||
|
@ -213,6 +214,7 @@ public class ServletContextStub implements ServletContext {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
@Deprecated
|
||||||
public Enumeration getServletNames() {
|
public Enumeration getServletNames() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"ServletContextStub.getServletNames() not implemented.");
|
"ServletContextStub.getServletNames() not implemented.");
|
||||||
|
@ -220,6 +222,7 @@ public class ServletContextStub implements ServletContext {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
@Deprecated
|
||||||
public Enumeration getServlets() {
|
public Enumeration getServlets() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"ServletContextStub.getServlets() not implemented.");
|
"ServletContextStub.getServlets() not implemented.");
|
||||||
|
@ -231,6 +234,7 @@ public class ServletContextStub implements ServletContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void log(Exception arg0, String arg1) {
|
public void log(Exception arg0, String arg1) {
|
||||||
throw new RuntimeException("ServletContextStub.log() not implemented.");
|
throw new RuntimeException("ServletContextStub.log() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,8 @@ public class HttpServletRequestStub implements HttpServletRequest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supply the request URL as a single URL. We will parse it on the
|
* Supply the request URL as a single URL. We will parse it on the
|
||||||
* assumption that the contextPath and the pathInfo are empty.
|
* assumption that the contextPath and the pathInfo are empty. Don't include
|
||||||
* Don't include a query string. Instead, set parameters.
|
* a query string. Instead, set parameters.
|
||||||
*/
|
*/
|
||||||
public void setRequestUrl(URL url) {
|
public void setRequestUrl(URL url) {
|
||||||
this.contextPath = "";
|
this.contextPath = "";
|
||||||
|
@ -81,8 +81,7 @@ public class HttpServletRequestStub implements HttpServletRequest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supply the pieces of the request URL, so we can respond correctly when
|
* Supply the pieces of the request URL, so we can respond correctly when
|
||||||
* asked for a piece.
|
* asked for a piece. Don't include a query string. Instead, set parameters.
|
||||||
* Don't include a query string. Instead, set parameters.
|
|
||||||
*/
|
*/
|
||||||
public void setRequestUrlByParts(String shemeHostPort, String contextPath,
|
public void setRequestUrlByParts(String shemeHostPort, String contextPath,
|
||||||
String servletPath, String pathInfo) {
|
String servletPath, String pathInfo) {
|
||||||
|
@ -102,8 +101,9 @@ public class HttpServletRequestStub implements HttpServletRequest {
|
||||||
}
|
}
|
||||||
this.servletPath = servletPath;
|
this.servletPath = servletPath;
|
||||||
|
|
||||||
this.requestUri = contextPath + servletPath + ((pathInfo == null) ? "" : pathInfo);
|
this.requestUri = contextPath + servletPath
|
||||||
|
+ ((pathInfo == null) ? "" : pathInfo);
|
||||||
|
|
||||||
if (shemeHostPort == null) {
|
if (shemeHostPort == null) {
|
||||||
throw new NullPointerException("shemeHostPort may not be null.");
|
throw new NullPointerException("shemeHostPort may not be null.");
|
||||||
}
|
}
|
||||||
|
@ -183,21 +183,21 @@ public class HttpServletRequestStub implements HttpServletRequest {
|
||||||
public String getServletPath() {
|
public String getServletPath() {
|
||||||
return servletPath;
|
return servletPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPathInfo() {
|
public String getPathInfo() {
|
||||||
return pathInfo;
|
return pathInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getQueryString() {
|
public String getQueryString() {
|
||||||
if (parameters.isEmpty()) {
|
if (parameters.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String qs = "";
|
String qs = "";
|
||||||
for (String key:parameters.keySet()) {
|
for (String key : parameters.keySet()) {
|
||||||
for (String value: parameters.get(key)) {
|
for (String value : parameters.get(key)) {
|
||||||
qs += "&" + key + "=" + URLEncoder.encode(value);
|
qs += "&" + key + "=" + URLEncoder.encode(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,167 +302,202 @@ public class HttpServletRequestStub implements HttpServletRequest {
|
||||||
// Un-implemented methods
|
// Un-implemented methods
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getAuthType() {
|
public String getAuthType() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getAuthType() not implemented.");
|
"HttpServletRequestStub.getAuthType() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Cookie[] getCookies() {
|
public Cookie[] getCookies() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getCookies() not implemented.");
|
"HttpServletRequestStub.getCookies() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public long getDateHeader(String arg0) {
|
public long getDateHeader(String arg0) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getDateHeader() not implemented.");
|
"HttpServletRequestStub.getDateHeader() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getIntHeader(String arg0) {
|
public int getIntHeader(String arg0) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getIntHeader() not implemented.");
|
"HttpServletRequestStub.getIntHeader() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getPathTranslated() {
|
public String getPathTranslated() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getPathTranslated() not implemented.");
|
"HttpServletRequestStub.getPathTranslated() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getRemoteUser() {
|
public String getRemoteUser() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getRemoteUser() not implemented.");
|
"HttpServletRequestStub.getRemoteUser() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getRequestedSessionId() {
|
public String getRequestedSessionId() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getRequestedSessionId() not implemented.");
|
"HttpServletRequestStub.getRequestedSessionId() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Principal getUserPrincipal() {
|
public Principal getUserPrincipal() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getUserPrincipal() not implemented.");
|
"HttpServletRequestStub.getUserPrincipal() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isRequestedSessionIdFromCookie() {
|
public boolean isRequestedSessionIdFromCookie() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.isRequestedSessionIdFromCookie() not implemented.");
|
"HttpServletRequestStub.isRequestedSessionIdFromCookie() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isRequestedSessionIdFromURL() {
|
public boolean isRequestedSessionIdFromURL() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.isRequestedSessionIdFromURL() not implemented.");
|
"HttpServletRequestStub.isRequestedSessionIdFromURL() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
public boolean isRequestedSessionIdFromUrl() {
|
public boolean isRequestedSessionIdFromUrl() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.isRequestedSessionIdFromUrl() not implemented.");
|
"HttpServletRequestStub.isRequestedSessionIdFromUrl() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isRequestedSessionIdValid() {
|
public boolean isRequestedSessionIdValid() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.isRequestedSessionIdValid() not implemented.");
|
"HttpServletRequestStub.isRequestedSessionIdValid() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isUserInRole(String arg0) {
|
public boolean isUserInRole(String arg0) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.isUserInRole() not implemented.");
|
"HttpServletRequestStub.isUserInRole() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getCharacterEncoding() {
|
public String getCharacterEncoding() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getCharacterEncoding() not implemented.");
|
"HttpServletRequestStub.getCharacterEncoding() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getContentLength() {
|
public int getContentLength() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getContentLength() not implemented.");
|
"HttpServletRequestStub.getContentLength() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getContentType() {
|
public String getContentType() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getContentType() not implemented.");
|
"HttpServletRequestStub.getContentType() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ServletInputStream getInputStream() throws IOException {
|
public ServletInputStream getInputStream() throws IOException {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getInputStream() not implemented.");
|
"HttpServletRequestStub.getInputStream() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getLocalAddr() {
|
public String getLocalAddr() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getLocalAddr() not implemented.");
|
"HttpServletRequestStub.getLocalAddr() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getLocalName() {
|
public String getLocalName() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getLocalName() not implemented.");
|
"HttpServletRequestStub.getLocalName() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getLocalPort() {
|
public int getLocalPort() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getLocalPort() not implemented.");
|
"HttpServletRequestStub.getLocalPort() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Locale getLocale() {
|
public Locale getLocale() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getLocale() not implemented.");
|
"HttpServletRequestStub.getLocale() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public Enumeration getLocales() {
|
public Enumeration getLocales() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getLocales() not implemented.");
|
"HttpServletRequestStub.getLocales() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getProtocol() {
|
public String getProtocol() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getProtocol() not implemented.");
|
"HttpServletRequestStub.getProtocol() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BufferedReader getReader() throws IOException {
|
public BufferedReader getReader() throws IOException {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getReader() not implemented.");
|
"HttpServletRequestStub.getReader() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
public String getRealPath(String arg0) {
|
public String getRealPath(String arg0) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getRealPath() not implemented.");
|
"HttpServletRequestStub.getRealPath() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getRemoteHost() {
|
public String getRemoteHost() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getRemoteHost() not implemented.");
|
"HttpServletRequestStub.getRemoteHost() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getRemotePort() {
|
public int getRemotePort() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getRemotePort() not implemented.");
|
"HttpServletRequestStub.getRemotePort() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public RequestDispatcher getRequestDispatcher(String arg0) {
|
public RequestDispatcher getRequestDispatcher(String arg0) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getRequestDispatcher() not implemented.");
|
"HttpServletRequestStub.getRequestDispatcher() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getScheme() {
|
public String getScheme() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getScheme() not implemented.");
|
"HttpServletRequestStub.getScheme() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getServerName() {
|
public String getServerName() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getServerName() not implemented.");
|
"HttpServletRequestStub.getServerName() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getServerPort() {
|
public int getServerPort() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.getServerPort() not implemented.");
|
"HttpServletRequestStub.getServerPort() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isSecure() {
|
public boolean isSecure() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpServletRequestStub.isSecure() not implemented.");
|
"HttpServletRequestStub.isSecure() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setCharacterEncoding(String arg0)
|
public void setCharacterEncoding(String arg0)
|
||||||
throws UnsupportedEncodingException {
|
throws UnsupportedEncodingException {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
|
|
|
@ -126,12 +126,14 @@ public class HttpSessionStub implements HttpSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public Object getValue(String arg0) {
|
public Object getValue(String arg0) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpSessionStub.getValue() not implemented.");
|
"HttpSessionStub.getValue() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public String[] getValueNames() {
|
public String[] getValueNames() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpSessionStub.getValueNames() not implemented.");
|
"HttpSessionStub.getValueNames() not implemented.");
|
||||||
|
@ -149,12 +151,14 @@ public class HttpSessionStub implements HttpSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void putValue(String arg0, Object arg1) {
|
public void putValue(String arg0, Object arg1) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpSessionStub.putValue() not implemented.");
|
"HttpSessionStub.putValue() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void removeValue(String arg0) {
|
public void removeValue(String arg0) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"HttpSessionStub.removeValue() not implemented.");
|
"HttpSessionStub.removeValue() not implemented.");
|
||||||
|
|
|
@ -55,7 +55,12 @@ var customForm = {
|
||||||
// the verify popup window. Although there could be multiple verifyMatch objects
|
// the verify popup window. Although there could be multiple verifyMatch objects
|
||||||
// selecting one and binding the event works for all of them
|
// selecting one and binding the event works for all of them
|
||||||
this.verifyMatch = this.form.find('.verifyMatch');
|
this.verifyMatch = this.form.find('.verifyMatch');
|
||||||
|
this.defaultAcType = ""; // will be set in setType() first time through
|
||||||
|
this.templateDefinedAcTypes = false;
|
||||||
|
if ( this.acTypes != undefined ) {
|
||||||
|
this.templateDefinedAcTypes = true;
|
||||||
|
}
|
||||||
|
|
||||||
// find all the acSelector input elements
|
// find all the acSelector input elements
|
||||||
this.acSelectors = [] ;
|
this.acSelectors = [] ;
|
||||||
|
|
||||||
|
@ -86,7 +91,7 @@ var customForm = {
|
||||||
// Used with the cancel link. If the user cancels after a type selection, this check
|
// Used with the cancel link. If the user cancels after a type selection, this check
|
||||||
// ensures that any a/c fields (besides the one associated with the type) will be reset
|
// ensures that any a/c fields (besides the one associated with the type) will be reset
|
||||||
this.clearAcSelections = false;
|
this.clearAcSelections = false;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set up the form on page load
|
// Set up the form on page load
|
||||||
|
@ -126,6 +131,10 @@ var customForm = {
|
||||||
|
|
||||||
this.initFormView();
|
this.initFormView();
|
||||||
|
|
||||||
|
// Set the initial autocomplete help text in the acSelector fields.
|
||||||
|
$.each(this.acSelectors, function() {
|
||||||
|
customForm.addAcHelpText($(this));
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
initFormView: function() {
|
initFormView: function() {
|
||||||
|
@ -288,7 +297,7 @@ var customForm = {
|
||||||
//to the filtering list
|
//to the filtering list
|
||||||
this.getAcFilterForIndividuals();
|
this.getAcFilterForIndividuals();
|
||||||
this.acCache = {};
|
this.acCache = {};
|
||||||
|
|
||||||
$(selectedObj).autocomplete({
|
$(selectedObj).autocomplete({
|
||||||
minLength: 3,
|
minLength: 3,
|
||||||
source: function(request, response) {
|
source: function(request, response) {
|
||||||
|
@ -312,8 +321,9 @@ var customForm = {
|
||||||
},
|
},
|
||||||
complete: function(xhr, status) {
|
complete: function(xhr, status) {
|
||||||
// Not sure why, but we need an explicit json parse here.
|
// Not sure why, but we need an explicit json parse here.
|
||||||
var results = $.parseJSON(xhr.responseText),
|
var results = $.parseJSON(xhr.responseText),
|
||||||
filteredResults = customForm.filterAcResults(results);
|
filteredResults = customForm.filterAcResults(results);
|
||||||
|
|
||||||
customForm.acCache[request.term] = filteredResults;
|
customForm.acCache[request.term] = filteredResults;
|
||||||
response(filteredResults);
|
response(filteredResults);
|
||||||
}
|
}
|
||||||
|
@ -321,6 +331,9 @@ var customForm = {
|
||||||
},
|
},
|
||||||
select: function(event, ui) {
|
select: function(event, ui) {
|
||||||
customForm.showAutocompleteSelection(ui.item.label, ui.item.uri, $(selectedObj));
|
customForm.showAutocompleteSelection(ui.item.label, ui.item.uri, $(selectedObj));
|
||||||
|
if ( $(selectedObj).attr('acGroupName') == customForm.typeSelector.attr('acGroupName') ) {
|
||||||
|
customForm.typeSelector.val(ui.item.msType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -420,17 +433,24 @@ var customForm = {
|
||||||
// provides a way to monitor selection in other js files, e.g. to hide fields upon selection
|
// provides a way to monitor selection in other js files, e.g. to hide fields upon selection
|
||||||
$acDiv.addClass("userSelected");
|
$acDiv.addClass("userSelected");
|
||||||
|
|
||||||
// If the form has a type selector, add type name to label in add mode. In edit mode, use typeSelectorSpan
|
// If the form has a type selector, add type name to label in add mode. In edit mode,
|
||||||
// html. The second case is an "else if" and not an else because the template may not be passing the label
|
// use typeSelectorSpan html. The second case is an "else if" and not an else because
|
||||||
// to the acSelection macro or it may not be using the macro at all and the label is hard-coded in the html.
|
// the template may not be passing the label to the acSelection macro or it may not be
|
||||||
if ( this.typeSelector.length && ($acDiv.attr('acGroupName') == this.typeSelector.attr('acGroupName')) ) {
|
// using the macro at all and the label is hard-coded in the html.
|
||||||
$acDiv.find('label').html('Selected ' + this.typeName + ':');
|
// ** With release 1.6 and display of all fields, more labels are hard-coded in html.
|
||||||
}
|
// ** So check if there's a label before doing anything else.
|
||||||
else if ( this.typeSelectorSpan.html() && ($acDiv.attr('acGroupName') == this.typeSelectorInput.attr('acGroupName')) ) {
|
|
||||||
$acDiv.find('label').html('Selected ' + this.typeSelectorSpan.html() + ':');
|
if ( $acDiv.find('label').html().length === 0 ) {
|
||||||
}
|
|
||||||
else if ( $acDiv.find('label').html() == '' ) {
|
if ( this.typeSelector.length && ($acDiv.attr('acGroupName') == this.typeSelector.attr('acGroupName')) ) {
|
||||||
$acDiv.find('label').html('Selected ' + this.multipleTypeNames[$(selectedObj).attr('acGroupName')] + ':');
|
$acDiv.find('label').html('Selected ' + this.typeName + ':');
|
||||||
|
}
|
||||||
|
else if ( this.typeSelectorSpan.html() && ($acDiv.attr('acGroupName') == this.typeSelectorInput.attr('acGroupName')) ) {
|
||||||
|
$acDiv.find('label').html('Selected ' + this.typeSelectorSpan.html() + ':');
|
||||||
|
}
|
||||||
|
else if ( $acDiv.find('label').html() == '' ) {
|
||||||
|
$acDiv.find('label').html('Selected ' + this.multipleTypeNames[$(selectedObj).attr('acGroupName')] + ':');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$acDiv.show();
|
$acDiv.show();
|
||||||
|
@ -447,7 +467,6 @@ var customForm = {
|
||||||
//On initialization in this mode, submit button is disabled
|
//On initialization in this mode, submit button is disabled
|
||||||
this.enableSubmit();
|
this.enableSubmit();
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
undoAutocompleteSelection: function(selectedObj) {
|
undoAutocompleteSelection: function(selectedObj) {
|
||||||
|
@ -482,11 +501,12 @@ var customForm = {
|
||||||
$acSelector = customForm.getAcSelector($checkSelection);
|
$acSelector = customForm.getAcSelector($checkSelection);
|
||||||
$acSelector.parent('p').show();
|
$acSelector.parent('p').show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$acSelectionObj = $(selectedObj);
|
$acSelectionObj = $(selectedObj);
|
||||||
|
customForm.typeSelector.val('');
|
||||||
}
|
}
|
||||||
|
|
||||||
$acSelector = this.getAcSelector($acSelectionObj);
|
$acSelector = this.getAcSelector($acSelectionObj);
|
||||||
|
@ -530,10 +550,9 @@ var customForm = {
|
||||||
// Note: we still need this in edit mode, to set the text values.
|
// Note: we still need this in edit mode, to set the text values.
|
||||||
setType: function() {
|
setType: function() {
|
||||||
var selectedType;
|
var selectedType;
|
||||||
|
|
||||||
// If there's no type selector, these values have been specified in customFormData,
|
// If there's no type selector, these values have been specified in customFormData,
|
||||||
// and will not change over the life of the form.
|
// and will not change over the life of the form.
|
||||||
if (!this.typeSelector.length) {
|
if (!this.typeSelector.length) {
|
||||||
if ( this.editMode == 'edit' && (this.typeSelectorSpan.html() != null && this.typeSelectorInput.val() != null) ) {
|
if ( this.editMode == 'edit' && (this.typeSelectorSpan.html() != null && this.typeSelectorInput.val() != null) ) {
|
||||||
this.typeName = this.typeSelectorSpan.html();
|
this.typeName = this.typeSelectorSpan.html();
|
||||||
this.acTypes[this.typeSelectorInput.attr('acGroupName')] = this.typeSelectorInput.val();
|
this.acTypes[this.typeSelectorInput.attr('acGroupName')] = this.typeSelectorInput.val();
|
||||||
|
@ -542,7 +561,11 @@ var customForm = {
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedType = this.typeSelector.find(':selected');
|
selectedType = this.typeSelector.find(':selected');
|
||||||
var acTypeKey = this.typeSelector.attr('acGroupName');
|
var acTypeKey = this.typeSelector.attr('acGroupName');
|
||||||
|
|
||||||
|
if ( this.templateDefinedAcTypes && !this.defaultAcType.length ) {
|
||||||
|
this.defaultAcType = this.acTypes[acTypeKey];
|
||||||
|
}
|
||||||
if (selectedType.val().length) {
|
if (selectedType.val().length) {
|
||||||
this.acTypes[acTypeKey] = selectedType.val();
|
this.acTypes[acTypeKey] = selectedType.val();
|
||||||
this.typeName = selectedType.html();
|
this.typeName = selectedType.html();
|
||||||
|
@ -551,15 +574,20 @@ var customForm = {
|
||||||
$acSelect.find('label').html( customForm.selectedString + ' ' + this.typeName + ':');
|
$acSelect.find('label').html( customForm.selectedString + ' ' + this.typeName + ':');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// reset to empty values; may not need
|
// reset to empty values;
|
||||||
else {
|
else {
|
||||||
delete this.acTypes[acTypeKey];
|
if ( this.templateDefinedAcTypes ) {
|
||||||
this.typeName = '';
|
this.acTypes[acTypeKey] = this.defaultAcType;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.acTypes = new Object();
|
||||||
|
}
|
||||||
|
this.typeName = this.defaultTypeName;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set field labels based on type selection. Although these won't change in edit
|
// Set field labels based on type selection. Although these won't change in edit
|
||||||
// mode, it's easier to specify the text here than in the jsp.
|
// mode, it's easier to specify the text here than in the ftl.
|
||||||
setLabels: function() {
|
setLabels: function() {
|
||||||
var typeName = this.getTypeNameForLabels();
|
var typeName = this.getTypeNameForLabels();
|
||||||
|
|
||||||
|
@ -575,10 +603,20 @@ var customForm = {
|
||||||
// or in repair mode in a two-step form with no type selected. Use the default type
|
// or in repair mode in a two-step form with no type selected. Use the default type
|
||||||
// name specified in the form data.
|
// name specified in the form data.
|
||||||
if ( !selectedObj || !this.hasMultipleTypeNames ) {
|
if ( !selectedObj || !this.hasMultipleTypeNames ) {
|
||||||
return this.acTypes ? this.typeName : this.capitalize(this.defaultTypeName);
|
if ( this.acTypes && this.typeName ) {
|
||||||
|
return this.typeName;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return this.capitalize(this.defaultTypeName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ( selectedObj && ( $(selectedObj).attr('acGroupName') == this.typeSelector.attr('acGroupName') ) ) {
|
else if ( selectedObj && ( $(selectedObj).attr('acGroupName') == this.typeSelector.attr('acGroupName') ) ) {
|
||||||
return this.acTypes ? this.typeName : this.capitalize(this.defaultTypeName);
|
if ( this.acTypes && this.typeName ) {
|
||||||
|
return this.typeName;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return this.capitalize(this.defaultTypeName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var name = customForm.multipleTypeNames[$(selectedObj).attr('id')];
|
var name = customForm.multipleTypeNames[$(selectedObj).attr('id')];
|
||||||
|
|
Loading…
Add table
Reference in a new issue