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);
return;
} 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);
return;
} 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)
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;
JSONObject rObj = null;
try{
VitroRequest vreq = new VitroRequest(req);
VClass vclass=null;
log.info("Retrieving solr individuals by vclasses");
log.debug("Retrieving solr individuals by vclasses");
// Could have multiple vclass ids sent in
String[] vitroClassIdStr = vreq.getParameterValues("vclassId");
if ( vitroClassIdStr != null && vitroClassIdStr.length > 0){
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);
if (vclass == null) {
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 {
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);
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);
return rObj;
}
//Including version for Solr query for Vclass Intersections
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);
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;
try {
map = IndividualListController.getResultsForVClassIntersections(

View file

@ -250,6 +250,7 @@ public class IndividualListController extends FreemarkerHttpServlet {
List<Individual> individuals = new ArrayList<Individual>(INDIVIDUALS_PER_PAGE);
int individualsAdded = 0;
int index = (page-1) * INDIVIDUALS_PER_PAGE;
if(docs.size() > 0) {
while (individualsAdded < INDIVIDUALS_PER_PAGE && index < hitCount) {
SolrDocument doc = docs.get(index);
if (doc != null) {
@ -265,7 +266,9 @@ public class IndividualListController extends FreemarkerHttpServlet {
}
index++;
}
} else {
log.debug("Docs size is 0");
}
// Test index < hitCount ensures that there are still some docs left
if ( hitCount > INDIVIDUALS_PER_PAGE && index < hitCount ){
rvMap.put("showPages", Boolean.TRUE);
@ -284,7 +287,24 @@ public class IndividualListController extends FreemarkerHttpServlet {
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 = "";
@ -313,7 +333,7 @@ public class IndividualListController extends FreemarkerHttpServlet {
// index, the current page of results might not retrieve any existing individuals,
// and nothing gets returned.
query.setStart(0)
.setRows(INDIVIDUAL_LIST_CONTROLLER_MAX_RESULTS)
.setRows(numberRows)
// Need a single-valued field for sorting
.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.VitroRequest;
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.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.
*/
@ -297,4 +306,6 @@ public class DataGetterUtils {
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.VClassGroup;
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.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
@ -56,6 +57,49 @@ public class IndividualsForClassesDataGetter implements PageDataGetter{
HashMap<String, Object> data, List<String> classes, List<String> restrictClasses ) {
processClassesForDisplay(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) {
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) {
@ -70,7 +114,6 @@ public class IndividualsForClassesDataGetter implements PageDataGetter{
//Retrieve vclass from cache to get the count
VClass vclass = vcgc.getCachedVClass(classUri);
if(vclass != null) {
log.debug("VClass does exist for " + classUri + " and entity count is " + vclass.getEntityCount());
vClasses.add(vclass);
} else {