changes for the home page redesign
This commit is contained in:
parent
556af80432
commit
1ca0904911
13 changed files with 270 additions and 51 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -182,8 +182,19 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
|||
}
|
||||
return rvMap;
|
||||
}
|
||||
|
||||
|
||||
public static Map<String,Object> getRandomResultsForVClass(String vclassURI, int page, int pageSize, IndividualDao indDao, ServletContext context) {
|
||||
Map<String,Object> rvMap = new HashMap<String,Object>();
|
||||
try{
|
||||
List<String> 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<String> vclassUris, IndividualDao indDao, ServletContext context) {
|
||||
|
|
|
@ -180,7 +180,7 @@ class IndividualResponseBuilder {
|
|||
|
||||
private boolean getprofilePageTypesFlag() {
|
||||
String property = ConfigurationProperties.getBean(vreq).getProperty(
|
||||
"MultiViews.profilePageTypes");
|
||||
"multiViews.profilePageTypes");
|
||||
return "enabled".equals(property);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> 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<String, Object> modelMap = new HashMap<String, Object>();
|
||||
modelMap.put("individual",
|
||||
new IndividualTemplateModel(individual, vreq));
|
||||
modelMap.put("vclass", vclassName);
|
||||
|
||||
ShortViewService svs = ShortViewServiceSetup.getService(ctx);
|
||||
return svs.renderShortView(individual, ShortViewContext.BROWSE,
|
||||
modelMap, vreq);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String, Object> 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<String,Object> 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<String,Object> 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -211,7 +211,8 @@ public class PagedSearchController extends FreemarkerHttpServlet {
|
|||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
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);
|
||||
|
|
|
@ -190,6 +190,26 @@ public class SolrQueryUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static SolrQuery getRandomQuery(List<String> 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<String> vclassUris){
|
||||
List<String> queryTypes = new ArrayList<String>();
|
||||
try {
|
||||
|
@ -217,4 +237,16 @@ public class SolrQueryUtils {
|
|||
return results;
|
||||
}
|
||||
|
||||
public static IndividualListQueryResults buildAndExecuteRandomVClassQuery(
|
||||
List<String> 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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue