From 3fbbd561c56747e20a19446568130a1baf7f76f8 Mon Sep 17 00:00:00 2001 From: ryounes Date: Tue, 24 May 2011 20:46:46 +0000 Subject: [PATCH] NIHVIVO-2460 Migrate menu pages to Solr index --- webapp/config/web.xml | 42 +++++++++---------- .../webapp/controller/SolrJsonServlet.java | 30 ++++++------- .../freemarker/HomePageController.java | 1 + .../controller/freemarker/PageController.java | 1 + .../body/partials/browse-classgroups.ftl | 2 +- .../partials/menupage/menupage-scripts.ftl | 3 +- 6 files changed, 40 insertions(+), 39 deletions(-) diff --git a/webapp/config/web.xml b/webapp/config/web.xml index 4f488055b..01f7cfdc1 100644 --- a/webapp/config/web.xml +++ b/webapp/config/web.xml @@ -143,17 +143,16 @@ + edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup - --> IndividualListController edu.cornell.mannlib.vitro.webapp.controller.freemarker.SolrIndividualListController - --> IndividualListController /individuallist - - + + IndividualListRdf edu.cornell.mannlib.vitro.webapp.controller.IndividualListRdfController - --> IndividualListRdf /listrdf/* - + + SearchController edu.cornell.mannlib.vitro.webapp.search.controller.SolrPagedSearchController - --> + SearchController /search @@ -933,16 +933,16 @@ /searchcontroller + + AutocompleteController edu.cornell.mannlib.vitro.webapp.search.controller.SolrAutocompleteController - - --> + AutocompleteController /autocomplete @@ -987,17 +987,17 @@ ContactFormController /contact - + + JSON Service edu.cornell.mannlib.vitro.webapp.controller.SolrJsonServlet - --> JSON Service /dataservice diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/SolrJsonServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/SolrJsonServlet.java index eed7e68de..5ed7fb989 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/SolrJsonServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/SolrJsonServlet.java @@ -33,9 +33,8 @@ 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.freemarker.IndividualListController; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.SolrIndividualListController.PageRecord; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.SolrIndividualListController; -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.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; @@ -44,7 +43,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; -import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel; /** * This servlet is for servicing requests for JSON objects/data. @@ -54,6 +52,7 @@ import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.Individual */ public class SolrJsonServlet extends VitroHttpServlet { + private static final long serialVersionUID = 1L; private static final Log log = LogFactory.getLog(SolrJsonServlet.class.getName()); private static final int REPLY_SIZE = 256; @@ -79,8 +78,8 @@ public class SolrJsonServlet extends VitroHttpServlet { }else if( vreq.getParameter("getN3EditOptionList") != null ){ doN3EditOptionList(req,resp); return; - }else if( vreq.getParameter("getLuceneIndividualsByVClass") != null ){ - getLuceneIndividualsByVClass(req,resp); + }else if( vreq.getParameter("getSolrIndividualsByVClass") != null ){ + getSolrIndividualsByVClass(req,resp); return; }else if( vreq.getParameter("getVClassesForVClassGroup") != null ){ getVClassesForVClassGroup(req,resp); @@ -127,7 +126,7 @@ public class SolrJsonServlet extends VitroHttpServlet { writer.write(map.toString()); } - private void getLuceneIndividualsByVClass( HttpServletRequest req, HttpServletResponse resp ){ + private void getSolrIndividualsByVClass( HttpServletRequest req, HttpServletResponse resp ){ String errorMessage = null; JSONObject rObj = null; try{ @@ -146,7 +145,7 @@ public class SolrJsonServlet extends VitroHttpServlet { log.debug("parameter vclassId URI parameter expected "); throw new Exception("parameter vclassId URI parameter expected "); } - rObj = getLuceneIndividualsByVClass(vclass.getURI(),req, getServletContext()); + rObj = getSolrIndividualsByVClass(vclass.getURI(),req, getServletContext()); }catch(Exception ex){ errorMessage = ex.toString(); log.error(ex,ex); @@ -175,7 +174,7 @@ public class SolrJsonServlet extends VitroHttpServlet { } - public static JSONObject getLuceneIndividualsByVClass(String vclassURI, HttpServletRequest req, ServletContext context) throws Exception { + public static JSONObject getSolrIndividualsByVClass(String vclassURI, HttpServletRequest req, ServletContext context) throws Exception { VitroRequest vreq = new VitroRequest(req); VClass vclass=null; @@ -193,6 +192,7 @@ public class SolrJsonServlet extends VitroHttpServlet { if( log.isDebugEnabled() ){ + @SuppressWarnings("unchecked") Enumeration e = vreq.getParameterNames(); while(e.hasMoreElements()){ String name = (String)e.nextElement(); @@ -224,9 +224,9 @@ public class SolrJsonServlet extends VitroHttpServlet { .put("name",vclass.getName())); if (vclass != null) { - String alpha = IndividualListController.getAlphaParameter(vreq); - int page = IndividualListController.getPageParameter(vreq); - Map map = IndividualListController.getResultsForVClass( + String alpha = SolrIndividualListController.getAlphaParameter(vreq); + int page = SolrIndividualListController.getPageParameter(vreq); + Map map = SolrIndividualListController.getResultsForVClass( vclass.getURI(), page, alpha, @@ -236,6 +236,7 @@ public class SolrJsonServlet extends VitroHttpServlet { rObj.put("totalCount", map.get("totalCount")); rObj.put("alpha", map.get("alpha")); + @SuppressWarnings("unchecked") List inds = (List)map.get("entities"); JSONArray jInds = new JSONArray(); @@ -261,6 +262,7 @@ public class SolrJsonServlet extends VitroHttpServlet { rObj.put("individuals", jInds); JSONArray wpages = new JSONArray(); + @SuppressWarnings("unchecked") List pages = (List)map.get("pages"); for( PageRecord pr: pages ){ JSONObject p = new JSONObject(); @@ -384,6 +386,7 @@ public class SolrJsonServlet extends VitroHttpServlet { HttpSession session = vreq.getSession(); if( session == null ) throw new ServletException("there is no session to get the pervious results from"); + @SuppressWarnings("unchecked") List entsInVClass = (List) session.getAttribute(resKey); if( entsInVClass == null ) throw new ServletException("Could not find List for resultKey " + resKey); @@ -391,7 +394,6 @@ public class SolrJsonServlet extends VitroHttpServlet { List entsToReturn = new ArrayList(REPLY_SIZE); boolean more = false; int count = 0; - int size = REPLY_SIZE; /* we have a large number of items to send back so we need to stash the list in the session scope */ if( entsInVClass.size() > REPLY_SIZE){ more = true; @@ -546,7 +548,7 @@ public class SolrJsonServlet extends VitroHttpServlet { private JSONArray individualsToJson(List individuals) throws ServletException { JSONArray ja = new JSONArray(); - Iterator it = individuals.iterator(); + Iterator it = individuals.iterator(); try{ while(it.hasNext()){ Individual ent = (Individual) it.next(); @@ -562,6 +564,4 @@ public class SolrJsonServlet extends VitroHttpServlet { return ja; } - - } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/HomePageController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/HomePageController.java index 8d7bfc2e6..6979697f9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/HomePageController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/HomePageController.java @@ -41,6 +41,7 @@ public class HomePageController extends FreemarkerHttpServlet { if(pageData != null) body.putAll(pageData); } + body.put("dataServiceUrlVClassesForVClassGroup", UrlBuilder.getUrl("/dataservice?getVClassesForVClassGroup=1&classgroupUri=")); return new TemplateResponseValues(BODY_TEMPLATE, body); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/PageController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/PageController.java index 4ad4f500f..05989a29d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/PageController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/PageController.java @@ -56,6 +56,7 @@ public class PageController extends FreemarkerHttpServlet{ if( page.containsKey("title") ){ mapForTemplate.put("title", page.get("title")); } + mapForTemplate.put("dataServiceUrlIndividualsByVClass", UrlBuilder.getUrl("/dataservice?getSolrIndividualsByVClass=1&vclassId=")); } catch (Throwable th) { return doNotFound(vreq); } diff --git a/webapp/web/templates/freemarker/body/partials/browse-classgroups.ftl b/webapp/web/templates/freemarker/body/partials/browse-classgroups.ftl index da15cc8ed..b2179fd93 100644 --- a/webapp/web/templates/freemarker/body/partials/browse-classgroups.ftl +++ b/webapp/web/templates/freemarker/body/partials/browse-classgroups.ftl @@ -67,7 +67,7 @@ ${stylesheets.add(' var browseData = { baseUrl: '${urls.base}', - dataServiceUrl: '${urls.base}/dataservice?getVClassesForVClassGroup=1&classgroupUri=', + dataServiceUrl: '${dataServiceUrlVClassesForVClassGroup}', defaultBrowseClassGroupUri: '${firstPopulatedClassGroup.uri!}', defaultBrowseClassGroupCount: '${firstPopulatedClassGroup.individualCount!}' }; diff --git a/webapp/web/templates/freemarker/body/partials/menupage/menupage-scripts.ftl b/webapp/web/templates/freemarker/body/partials/menupage/menupage-scripts.ftl index f7287d26d..c26cf60d9 100644 --- a/webapp/web/templates/freemarker/body/partials/menupage/menupage-scripts.ftl +++ b/webapp/web/templates/freemarker/body/partials/menupage/menupage-scripts.ftl @@ -15,11 +15,10 @@ -<#-- For v1.3: The controller should pass in the dataservice url. -->