Updating class counts for internal class menu pages (so counts retrieved based on what you see on page). Also reverted some log info statements in json servlet back to debug level.

This commit is contained in:
hjkhjk54 2011-07-18 20:16:28 +00:00
parent d8e0734581
commit 1d9e1fb2ae
4 changed files with 102 additions and 28 deletions

View file

@ -84,7 +84,7 @@ public class JsonServlet extends VitroHttpServlet {
getVClassesForVClassGroup(req,resp); getVClassesForVClassGroup(req,resp);
return; return;
} else if( vreq.getParameter("getSolrIndividualsByVClasses") != null ){ } else if( vreq.getParameter("getSolrIndividualsByVClasses") != null ){
log.info("AJAX request to retrieve individuals by vclasses"); log.debug("AJAX request to retrieve individuals by vclasses");
getSolrIndividualsByVClasses(req,resp); getSolrIndividualsByVClasses(req,resp);
return; return;
} else if( vreq.getParameter("getDataForPage") != null ){ } else if( vreq.getParameter("getDataForPage") != null ){
@ -197,18 +197,18 @@ public class JsonServlet extends VitroHttpServlet {
// Accepts multiple vclasses and returns individuals which correspond to the intersection of those classes (i.e. have all those types) // Accepts multiple vclasses and returns individuals which correspond to the intersection of those classes (i.e. have all those types)
private void getSolrIndividualsByVClasses( HttpServletRequest req, HttpServletResponse resp ){ private void getSolrIndividualsByVClasses( HttpServletRequest req, HttpServletResponse resp ){
log.info("Executing retrieval of individuals by vclasses"); log.debug("Executing retrieval of individuals by vclasses");
String errorMessage = null; String errorMessage = null;
JSONObject rObj = null; JSONObject rObj = null;
try{ try{
VitroRequest vreq = new VitroRequest(req); VitroRequest vreq = new VitroRequest(req);
VClass vclass=null; VClass vclass=null;
log.info("Retrieving solr individuals by vclasses"); log.debug("Retrieving solr individuals by vclasses");
// Could have multiple vclass ids sent in // Could have multiple vclass ids sent in
String[] vitroClassIdStr = vreq.getParameterValues("vclassId"); String[] vitroClassIdStr = vreq.getParameterValues("vclassId");
if ( vitroClassIdStr != null && vitroClassIdStr.length > 0){ if ( vitroClassIdStr != null && vitroClassIdStr.length > 0){
for(String vclassId: vitroClassIdStr) { for(String vclassId: vitroClassIdStr) {
log.info("Iterating throug vclasses, using VClass " + vclassId); log.debug("Iterating throug vclasses, using VClass " + vclassId);
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassId); vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassId);
if (vclass == null) { if (vclass == null) {
log.error("Couldn't retrieve vclass "); log.error("Couldn't retrieve vclass ");
@ -250,19 +250,19 @@ public class JsonServlet extends VitroHttpServlet {
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 {
VitroRequest vreq = new VitroRequest(req); VitroRequest vreq = new VitroRequest(req);
log.info("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.info("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); JSONObject rObj = processVClassResults(map, vreq, context, true);
return rObj; return rObj;
} }
//Including version for Solr query for Vclass Intersections //Including version for Solr query for Vclass Intersections
private static Map<String,Object> getSolrVClassIntersectionResults(List<String> vclassURIs, VitroRequest vreq, ServletContext context){ private static Map<String,Object> getSolrVClassIntersectionResults(List<String> vclassURIs, VitroRequest vreq, ServletContext context){
log.info("Retrieving Solr intersection results for " + vclassURIs.toString()); log.debug("Retrieving Solr intersection results for " + vclassURIs.toString());
String alpha = IndividualListController.getAlphaParameter(vreq); String alpha = IndividualListController.getAlphaParameter(vreq);
int page = IndividualListController.getPageParameter(vreq); int page = IndividualListController.getPageParameter(vreq);
log.info("Alpha and page parameters are " + alpha + " and " + page); log.debug("Alpha and page parameters are " + alpha + " and " + page);
Map<String,Object> map = null; Map<String,Object> map = null;
try { try {
map = IndividualListController.getResultsForVClassIntersections( map = IndividualListController.getResultsForVClassIntersections(

View file

@ -250,22 +250,25 @@ public class IndividualListController extends FreemarkerHttpServlet {
List<Individual> individuals = new ArrayList<Individual>(INDIVIDUALS_PER_PAGE); List<Individual> individuals = new ArrayList<Individual>(INDIVIDUALS_PER_PAGE);
int individualsAdded = 0; int individualsAdded = 0;
int index = (page-1) * INDIVIDUALS_PER_PAGE; int index = (page-1) * INDIVIDUALS_PER_PAGE;
while (individualsAdded < INDIVIDUALS_PER_PAGE && index < hitCount) { if(docs.size() > 0) {
SolrDocument doc = docs.get(index); while (individualsAdded < INDIVIDUALS_PER_PAGE && index < hitCount) {
if (doc != null) { SolrDocument doc = docs.get(index);
String uri = doc.get(VitroSearchTermNames.URI).toString(); if (doc != null) {
Individual individual = indDao.getIndividualByURI( uri ); String uri = doc.get(VitroSearchTermNames.URI).toString();
if (individual != null) { Individual individual = indDao.getIndividualByURI( uri );
individualsAdded++; if (individual != null) {
individuals.add(individual); individualsAdded++;
log.debug("Adding individual " + uri + " to individual list display"); individuals.add(individual);
} else { log.debug("Adding individual " + uri + " to individual list display");
log.debug("No existing individual for search document with uri = " + uri); } else {
} log.debug("No existing individual for search document with uri = " + uri);
} }
index++; }
index++;
}
} else {
log.debug("Docs size is 0");
} }
// Test index < hitCount ensures that there are still some docs left // Test index < hitCount ensures that there are still some docs left
if ( hitCount > INDIVIDUALS_PER_PAGE && index < hitCount ){ if ( hitCount > INDIVIDUALS_PER_PAGE && index < hitCount ){
rvMap.put("showPages", Boolean.TRUE); rvMap.put("showPages", Boolean.TRUE);
@ -284,7 +287,24 @@ public class IndividualListController extends FreemarkerHttpServlet {
return rvMap; return rvMap;
} }
private static SolrQuery getQuery(List<String> vclassUris, String alpha){ //Get count of individuals without actually getting the results
public static long getIndividualCount(List<String> vclassUris, IndividualDao indDao, ServletContext context) {
SolrQuery query = getQuery(vclassUris, null, 0);
try {
Map<String,Object> rvMap = getResultsForVClassQuery(query, 1, null, indDao, context);
Long count = (Long) rvMap.get("totalCount");
return count.longValue();
} catch(Exception ex) {
log.error("An error occured in retrieving individual count", ex);
}
return 0;
}
private static SolrQuery getQuery(List<String> vclassUris, String alpha) {
return getQuery(vclassUris, alpha, INDIVIDUAL_LIST_CONTROLLER_MAX_RESULTS);
}
private static SolrQuery getQuery(List<String> vclassUris, String alpha, int numberRows){
String queryText = ""; String queryText = "";
@ -307,13 +327,13 @@ public class IndividualListController extends FreemarkerHttpServlet {
SolrQuery query = new SolrQuery(queryText); SolrQuery query = new SolrQuery(queryText);
log.debug("Query text is " + queryText); log.debug("Query text is " + queryText);
// Get all available results from index rather than just those for the current page. // Get all available results from index rather than just those for the current page.
// Otherwise, if there are a large number of non-existent individuals in the search // Otherwise, if there are a large number of non-existent individuals in the search
// index, the current page of results might not retrieve any existing individuals, // index, the current page of results might not retrieve any existing individuals,
// and nothing gets returned. // and nothing gets returned.
query.setStart(0) query.setStart(0)
.setRows(INDIVIDUAL_LIST_CONTROLLER_MAX_RESULTS) .setRows(numberRows)
// Need a single-valued field for sorting // Need a single-valued field for sorting
.setSortField(VitroSearchTermNames.NAME_LOWERCASE_SINGLE_VALUED, SolrQuery.ORDER.asc); .setSortField(VitroSearchTermNames.NAME_LOWERCASE_SINGLE_VALUED, SolrQuery.ORDER.asc);

View file

@ -26,6 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.JsonServlet; import edu.cornell.mannlib.vitro.webapp.controller.JsonServlet;
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.PageRecord; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.PageRecord;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
@ -153,6 +154,14 @@ public class DataGetterUtils {
} }
} }
/**
* 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. * Process results related to VClass or vclasses. Handles both single and multiple vclasses being sent.
*/ */
@ -297,4 +306,6 @@ public class DataGetterUtils {
return map; return map;
} }
} }

View file

@ -19,6 +19,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
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.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache; import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
@ -56,9 +57,52 @@ public class IndividualsForClassesDataGetter implements PageDataGetter{
HashMap<String, Object> data, List<String> classes, List<String> restrictClasses ) { HashMap<String, Object> data, List<String> classes, List<String> restrictClasses ) {
processClassesForDisplay(context, data, classes); processClassesForDisplay(context, data, classes);
processRestrictionClasses(vreq, context, data, restrictClasses); processRestrictionClasses(vreq, context, data, restrictClasses);
processIntersections(vreq, context, data);
} }
private void processClassesForDisplay(ServletContext context, HashMap<String, Object> data, List<String> classes) { //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) {
List<VClass> newVClassList = new ArrayList<VClass>();
//Iterate through vclasses and get updated counts
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 = new VClass(v.getURI());
copyVClass.setEntityCount(oldCount);
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);
}
}
//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 = DataGetterUtils.getIndividualCountForIntersection(vreq, context, classUris);
return new Long(count).intValue();
}
private void processClassesForDisplay(ServletContext context, HashMap<String, Object> data, List<String> classes) {
VClassGroup classesGroup = new VClassGroup(); VClassGroup classesGroup = new VClassGroup();
classesGroup.setURI("displayClasses"); classesGroup.setURI("displayClasses");
@ -70,7 +114,6 @@ public class IndividualsForClassesDataGetter implements PageDataGetter{
//Retrieve vclass from cache to get the count //Retrieve vclass from cache to get the count
VClass vclass = vcgc.getCachedVClass(classUri); VClass vclass = vcgc.getCachedVClass(classUri);
if(vclass != null) { if(vclass != null) {
log.debug("VClass does exist for " + classUri + " and entity count is " + vclass.getEntityCount()); log.debug("VClass does exist for " + classUri + " and entity count is " + vclass.getEntityCount());
vClasses.add(vclass); vClasses.add(vclass);
} else { } else {