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 6dfa102d7..22aaaa804 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 @@ -9,6 +9,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; @@ -48,6 +49,7 @@ public class HomePageController extends FreemarkerHttpServlet { } }*/ body.put("dataServiceUrlVClassesForVClassGroup", UrlBuilder.getUrl("/dataservice?getVClassesForVClassGroup=1&classgroupUri=")); + body.put("geoFocusMapsEnabled", getGeoFocusMapsFlag(vreq)); return new TemplateResponseValues(BODY_TEMPLATE, body); } @@ -61,4 +63,11 @@ public class HomePageController extends FreemarkerHttpServlet { protected String getPageTemplateName() { return PAGE_TEMPLATE; } + + private boolean getGeoFocusMapsFlag(VitroRequest vreq) { + String property = ConfigurationProperties.getBean(vreq).getProperty( + "homePage.geoFocusMaps"); + return "enabled".equals(property); + } + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java index 77f1cc601..54b295e6d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java @@ -182,8 +182,19 @@ public class IndividualListController extends FreemarkerHttpServlet { } return rvMap; } - + public static Map getRandomResultsForVClass(String vclassURI, int page, int pageSize, IndividualDao indDao, ServletContext context) { + Map rvMap = new HashMap(); + try{ + List classUris = Collections.singletonList(vclassURI); + IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteRandomVClassQuery(classUris, page, pageSize, context, indDao); + rvMap = getResultsForVClassQuery(results, page, pageSize, ""); + } catch(Throwable th) { + log.error("An error occurred retrieving random results for vclass query", th); + } + return rvMap; + } + //TODO: Get rid of this method and utilize SolrQueryUtils - currently appears to be referenced //only within DataGetterUtils public static long getIndividualCount(List vclassUris, IndividualDao indDao, ServletContext context) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualResponseBuilder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualResponseBuilder.java index ac39c3b10..e63791df5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualResponseBuilder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualResponseBuilder.java @@ -180,7 +180,7 @@ class IndividualResponseBuilder { private boolean getprofilePageTypesFlag() { String property = ConfigurationProperties.getBean(vreq).getProperty( - "MultiViews.profilePageTypes"); + "multiViews.profilePageTypes"); return "enabled".equals(property); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSolrIndividualsByVClass.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSolrIndividualsByVClass.java new file mode 100644 index 000000000..5e4c268dd --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSolrIndividualsByVClass.java @@ -0,0 +1,84 @@ +/* $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.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONArray; +import org.json.JSONException; +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.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; +import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService; +import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService.ShortViewContext; +import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewServiceSetup; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel; + +/** + * Does a Solr search for individuals, and uses the short view to render each of + * the results. + */ +public class GetRandomSolrIndividualsByVClass extends GetSolrIndividualsByVClass { + private static final Log log = LogFactory + .getLog(GetRandomSolrIndividualsByVClass.class); + + protected GetRandomSolrIndividualsByVClass(VitroRequest vreq) { + super(vreq); + } + + /** + * Search for individuals by VClass. + */ + @Override + protected JSONObject process() throws Exception { + JSONObject rObj = null; + + //This gets the first vclass value and sets that as display type. + List vclassIds = super.getVclassIds(vreq); + String vclassId = vclassIds.get(0); + vreq.setAttribute("queryType", "random"); +// vreq.setAttribute("displayType", vclassId); + + //This will get all the solr individuals by VClass (if one value) or the intersection + //i.e. individuals that have all the types for the different vclasses entered + rObj = super.process(); + addShortViewRenderings(rObj); + return rObj; + } + + /** + * Look through the return object. For each individual, render the short + * view and insert the resulting HTML into the object. + */ + private void addShortViewRenderings(JSONObject rObj) throws JSONException { + JSONArray individuals = rObj.getJSONArray("individuals"); + String vclassName = rObj.getJSONObject("vclass").getString("name"); + for (int i = 0; i < individuals.length(); i++) { + JSONObject individual = individuals.getJSONObject(i); + individual.put("shortViewHtml", + renderShortView(individual.getString("URI"), vclassName)); + } + } + + private String renderShortView(String individualUri, String vclassName) { + IndividualDao iDao = vreq.getWebappDaoFactory().getIndividualDao(); + Individual individual = iDao.getIndividualByURI(individualUri); + + Map modelMap = new HashMap(); + modelMap.put("individual", + new IndividualTemplateModel(individual, vreq)); + modelMap.put("vclass", vclassName); + + ShortViewService svs = ShortViewServiceSetup.getService(ctx); + return svs.renderShortView(individual, ShortViewContext.BROWSE, + modelMap, vreq); + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSolrIndividualsByVClass.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSolrIndividualsByVClass.java index 154753322..0d40e6026 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSolrIndividualsByVClass.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/GetSolrIndividualsByVClass.java @@ -24,6 +24,7 @@ public class GetSolrIndividualsByVClass extends JsonObjectProducer { protected JSONObject process() throws Exception { VClass vclass=null; + String queryType = (String) vreq.getAttribute("queryType"); String vitroClassIdStr = vreq.getParameter("vclassId"); if ( vitroClassIdStr != null && !vitroClassIdStr.isEmpty()){ vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr); @@ -35,8 +36,13 @@ public class GetSolrIndividualsByVClass extends JsonObjectProducer { log.debug("parameter vclassId URI parameter expected "); throw new Exception("parameter vclassId URI parameter expected "); } + vreq.setAttribute("displayType", vitroClassIdStr); - return JsonServlet.getSolrIndividualsByVClass(vclass.getURI(), vreq, ctx); + if ( queryType != null && queryType.equals("random")){ + return JsonServlet.getRandomSolrIndividualsByVClass(vclass.getURI(), vreq, ctx); + } else { + return JsonServlet.getSolrIndividualsByVClass(vclass.getURI(), vreq, ctx); + } } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java index be3c2eb01..2fbd9d09f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/json/JsonServlet.java @@ -72,7 +72,10 @@ public class JsonServlet extends VitroHttpServlet { new GetDataForPage(vreq).process(resp); }else if( vreq.getParameter("getRenderedSolrIndividualsByVClass") != null ){ new GetRenderedSolrIndividualsByVClass(vreq).process(resp); + }else if( vreq.getParameter("getRandomSolrIndividualsByVClass") != null ){ + new GetRandomSolrIndividualsByVClass(vreq).process(resp); } + } @@ -135,7 +138,35 @@ public class JsonServlet extends VitroHttpServlet { return value; } + public static JSONObject getRandomSolrIndividualsByVClass(String vclassURI, HttpServletRequest req, ServletContext context) throws Exception { + VitroRequest vreq = new VitroRequest(req); + + Map map = getRandomSolrVClassResults(vclassURI, vreq, context); + //last parameter indicates single vclass instead of multiple vclasses + return processVClassResults(map, vreq, context, false); + } + //Including version for Random Solr query for Vclass Intersections + private static Map getRandomSolrVClassResults(String vclassURI, VitroRequest vreq, ServletContext context){ + log.debug("Retrieving random Solr intersection results for " + vclassURI); + + int page = IndividualListController.getPageParameter(vreq); + int pageSize = Integer.parseInt(vreq.getParameter("pageSize")); + log.debug("page and pageSize parameters = " + page + " and " + pageSize); + Map map = null; + try { + map = IndividualListController.getRandomResultsForVClass( + vclassURI, + page, + pageSize, + vreq.getWebappDaoFactory().getIndividualDao(), + context); + } catch(Exception ex) { + log.error("Error in retrieval of search results for VClass " + vclassURI, ex); + } + + return map; + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java index d85ba6ada..7889a825a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java @@ -211,7 +211,8 @@ public class PagedSearchController extends FreemarkerHttpServlet { Map body = new HashMap(); - String classGroupParam = vreq.getParameter(PARAM_CLASSGROUP); + String classGroupParam = vreq.getParameter(PARAM_CLASSGROUP); + log.debug("Query text is \""+ classGroupParam + "\""); boolean classGroupFilterRequested = false; if (!StringUtils.isEmpty(classGroupParam)) { VClassGroup grp = grpDao.getGroupByURI(classGroupParam); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrQueryUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrQueryUtils.java index c90281377..608ae0efc 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrQueryUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/solr/SolrQueryUtils.java @@ -190,6 +190,26 @@ public class SolrQueryUtils { } } + public static SolrQuery getRandomQuery(List vclassUris, int page, int pageSize){ + String queryText = ""; + + try { + queryText = makeMultiClassQuery(vclassUris); + log.debug("queryText is " + queryText); + SolrQuery query = new SolrQuery(queryText); + + //page count starts at 1, row count starts at 0 + query.setStart( page ).setRows( pageSize ); + + log.debug("Query is " + query.toString()); + return query; + + } catch (Exception ex){ + log.error("Could not make the Solr query",ex); + return new SolrQuery(); + } + } + public static String makeMultiClassQuery( List vclassUris){ List queryTypes = new ArrayList(); try { @@ -217,4 +237,16 @@ public class SolrQueryUtils { return results; } + public static IndividualListQueryResults buildAndExecuteRandomVClassQuery( + List vclassURIs, int page, int pageSize, + ServletContext context, IndividualDao indDao) + throws SolrServerException { + SolrQuery query = SolrQueryUtils.getRandomQuery(vclassURIs, page, pageSize); + IndividualListQueryResults results = IndividualListQueryResults.runQuery(query, indDao, context); + log.debug("Executed solr query for " + vclassURIs); + if (results.getIndividuals().isEmpty()) { + log.debug("entities list is null for vclass " + vclassURIs); + } + return results; + } } diff --git a/webapp/themes/vitro/templates/page-home.ftl b/webapp/themes/vitro/templates/page-home.ftl index a052acfe2..c4816bc95 100644 --- a/webapp/themes/vitro/templates/page-home.ftl +++ b/webapp/themes/vitro/templates/page-home.ftl @@ -1,7 +1,7 @@ <#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> <@widget name="login" include="assets" /> -<#include "browse-classgroups.ftl"> +<#import "lib-home-page.ftl" as lh> @@ -36,17 +36,14 @@
+
filter search @@ -57,19 +54,12 @@ <@widget name="login" /> - - <#--<@allClassGroups vClassGroups! />--> - -
-

Stats

+ +
+

Statistics

diff --git a/webapp/web/css/vitro.css b/webapp/web/css/vitro.css index ea8b9cac4..6a84a8d24 100644 --- a/webapp/web/css/vitro.css +++ b/webapp/web/css/vitro.css @@ -341,11 +341,10 @@ a.filter-search { margin-top: 1em; width: 921px; height: 213px; - float: left; + clear: both; } -#home-stats h4 { +.home-sections h4 { margin-top: 0; - width: 64px; height: 34px; font-size: 18px; text-align: center; @@ -353,6 +352,9 @@ a.filter-search { padding: 0; line-height: 35px; } +#home-stats h4 { + width: 102px; +} #stats { margin: 0 auto; width: 875px; diff --git a/webapp/web/js/vitroUtils.js b/webapp/web/js/vitroUtils.js old mode 100755 new mode 100644 index e9b345abb..76b84d8c5 --- a/webapp/web/js/vitroUtils.js +++ b/webapp/web/js/vitroUtils.js @@ -10,15 +10,10 @@ $(document).ready(function(){ // fade in flash-message when user logs out jQuery('section#flash-message').css('display', 'none').fadeIn(1500); - ///////////////////////////// // Home search fiter // Toggle filter select list - var $searchFilterList = $('#filter-search-nav'); - var $selectedFilter; - var $queryToSend; - var $queryToSendAll = true; var $isFilterOpen = false; console.log("Filter is open = " + $isFilterOpen); @@ -63,15 +58,14 @@ $(document).ready(function(){ ev.preventDefault(); if ($(this).text() == 'All') { - $queryToSendAll = true; //Selected filter feedback $('.search-filter-selected').text(''); + $('input[name="classgroup"]').val(''); console.log("ALL"); } else { - //Selected filter feedback $('.search-filter-selected').text($(this).text()).fadeIn('slow'); - $queryToSendAll = false; + $('input[name="classgroup"]').val($(this).children("a").attr("title")); } //Hide filter select list @@ -82,10 +76,7 @@ $(document).ready(function(){ $('a.filter-search').removeClass('filter-active'); $('a.filter-search').addClass('filter-default'); - - $selectedFilter = $(this).text(); $isFilterOpen = false; - console.log("$queryToSend " + $selectedFilter); }); }); @@ -118,18 +109,4 @@ $(document).ready(function(){ console.log("HIDE input value ") ; }); - - $('#search-homepage').submit(function(){ - - if ($queryToSendAll) { - $filterType = ''; - }else { - $filterType = '&classgroup=http://vivoweb.org/ontology/vitroClassGroup' + $selectedFilter; - } - - $queryToSend = 'querytext=' + $('input.search-homepage').val() + $filterType; - console.log("Query to send: " + $queryToSend); - - return false; - }); -}); \ No newline at end of file +}); diff --git a/webapp/web/templates/freemarker/body/login/login.ftl b/webapp/web/templates/freemarker/body/login/login.ftl index e310b341e..930f195ea 100644 --- a/webapp/web/templates/freemarker/body/login/login.ftl +++ b/webapp/web/templates/freemarker/body/login/login.ftl @@ -2,4 +2,7 @@ <#-- Main template for the login page --> -<@widget name="login" /> \ No newline at end of file +<@widget name="login" /> + \ No newline at end of file diff --git a/webapp/web/templates/freemarker/lib/lib-home-page.ftl b/webapp/web/templates/freemarker/lib/lib-home-page.ftl new file mode 100644 index 000000000..7b0cac823 --- /dev/null +++ b/webapp/web/templates/freemarker/lib/lib-home-page.ftl @@ -0,0 +1,73 @@ +<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> + +<#-- Macros used to build the statistical information on the home page --> + +<#-- Get the classgroups so they can be used to qualify searches --> +<#macro allClassGroupNames classGroups> + <#list classGroups as group> + <#-- Only display populated class groups --> + <#if (group.individualCount > 0)> +
  • ${group.displayName?capitalize}
  • + + + + +<#-- builds the "stats" section of the home page, i.e., class group counts --> +<#macro allClassGroups classGroups> + <#-- Loop through classGroups first so we can account for situations when all class groups are empty --> + <#assign selected = 'class="selected" ' /> + <#assign classGroupList> + <#list classGroups as group> + <#-- Only display populated class groups --> + <#if (group.individualCount > 0)> + <#-- Catch the first populated class group. Will be used later as the default selected class group --> + <#if !firstPopulatedClassGroup??> + <#assign firstPopulatedClassGroup = group /> + + <#-- Determine the active (selected) group --> + <#assign activeGroup = "" /> + <#if !classGroup??> + <#if group_index == 0> + <#assign activeGroup = selected /> + + <#elseif classGroup.uri == group.uri> + <#assign activeGroup = selected /> + + <#if group.displayName != "equipment" && group.displayName != "locations" && group.displayName != "courses" > +
  • + +

    + <#if (group.individualCount > 10000) > + <#assign overTen = group.individualCount/1000> + ${overTen?round}k + <#elseif (group.individualCount > 1000)> + <#assign underTen = group.individualCount/1000> + ${underTen?string("0.#")}k + <#else> + ${group.individualCount}  + +

    +

    ${group.displayName?capitalize}

    +
    +
  • + + + + + + <#-- Display the class group browse only if we have at least one populated class group --> + <#if firstPopulatedClassGroup??> + ${classGroupList} + <#else> +

    There is currently no content in the system, or you need to create class groups and assign your classes to them.

    + + <#if user.loggedIn> + <#if user.hasSiteAdminAccess> +

    You can add content and manage this site from the Site Administration page.

    + + <#else> +

    Please log in to manage content.

    + + + +