Merge branch 'maint-rel-1.6' into develop

This commit is contained in:
j2blake 2013-10-25 17:52:03 -04:00
commit a9fd7c3f6d
9 changed files with 332 additions and 332 deletions

View file

@ -13,10 +13,7 @@ import javax.servlet.ServletContext;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
@ -25,9 +22,8 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResults;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup;
import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual;
@ -94,16 +90,15 @@ public class IndividualListController extends FreemarkerHttpServlet {
String alpha = getAlphaParameter(vreq);
int page = getPageParameter(vreq);
Map<String,Object> map = getResultsForVClass(
IndividualListResults vcResults = getResultsForVClass(
vclass.getURI(),
page,
alpha,
vreq.getWebappDaoFactory().getIndividualDao(),
getServletContext());
body.putAll(map);
body.putAll(vcResults.asFreemarkerMap());
@SuppressWarnings("unchecked")
List<Individual> inds = (List<Individual>)map.get("entities");
List<Individual> inds = vcResults.getEntities();
List<ListedIndividual> indsTm = new ArrayList<ListedIndividual>();
if (inds != null) {
for ( Individual ind : inds ) {
@ -154,13 +149,12 @@ public class IndividualListController extends FreemarkerHttpServlet {
return SolrQueryUtils.getPageParameter(request);
}
public static Map<String,Object> getResultsForVClass(String vclassURI, int page, String alpha, IndividualDao indDao, ServletContext context)
public static IndividualListResults getResultsForVClass(String vclassURI, int page, String alpha, IndividualDao indDao, ServletContext context)
throws SearchException{
Map<String,Object> rvMap = new HashMap<String,Object>();
try{
List<String> classUris = Collections.singletonList(vclassURI);
IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteVClassQuery(classUris, alpha, page, INDIVIDUALS_PER_PAGE, context, indDao);
rvMap = getResultsForVClassQuery(results, page, INDIVIDUALS_PER_PAGE, alpha);
return getResultsForVClassQuery(results, page, INDIVIDUALS_PER_PAGE, alpha);
} catch (SolrServerException e) {
String msg = "An error occurred retrieving results for vclass query";
log.error(msg, e);
@ -168,31 +162,29 @@ public class IndividualListController extends FreemarkerHttpServlet {
throw new SearchException(msg);
} catch(Throwable th) {
log.error("An error occurred retrieving results for vclass query", th);
return IndividualListResults.EMPTY;
}
return rvMap;
}
public static Map<String,Object> getResultsForVClassIntersections(List<String> vclassURIs, int page, int pageSize, String alpha, IndividualDao indDao, ServletContext context) {
Map<String,Object> rvMap = new HashMap<String,Object>();
public static IndividualListResults getResultsForVClassIntersections(List<String> vclassURIs, int page, int pageSize, String alpha, IndividualDao indDao, ServletContext context) {
try{
IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteVClassQuery(vclassURIs, alpha, page, pageSize, context, indDao);
rvMap = getResultsForVClassQuery(results, page, pageSize, alpha);
return getResultsForVClassQuery(results, page, pageSize, alpha);
} catch(Throwable th) {
log.error("Error retrieving individuals corresponding to intersection multiple classes." + vclassURIs.toString(), th);
return IndividualListResults.EMPTY;
}
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>();
public static IndividualListResults getRandomResultsForVClass(String vclassURI, int page, int pageSize, IndividualDao indDao, ServletContext context) {
try{
List<String> classUris = Collections.singletonList(vclassURI);
IndividualListQueryResults results = SolrQueryUtils.buildAndExecuteRandomVClassQuery(classUris, page, pageSize, context, indDao);
rvMap = getResultsForVClassQuery(results, page, pageSize, "");
return getResultsForVClassQuery(results, page, pageSize, "");
} catch(Throwable th) {
log.error("An error occurred retrieving random results for vclass query", th);
return IndividualListResults.EMPTY;
}
return rvMap;
}
//TODO: Get rid of this method and utilize SolrQueryUtils - currently appears to be referenced
@ -201,24 +193,13 @@ public class IndividualListController extends FreemarkerHttpServlet {
return SolrQueryUtils.getIndividualCount(vclassUris, indDao, context);
}
private static Map<String,Object> getResultsForVClassQuery(IndividualListQueryResults results, int page, int pageSize, String alpha) {
Map<String,Object> rvMap = new HashMap<String,Object>();
private static IndividualListResults getResultsForVClassQuery(IndividualListQueryResults results, int page, int pageSize, String alpha) {
long hitCount = results.getHitCount();
if ( hitCount > pageSize ){
rvMap.put("showPages", Boolean.TRUE);
List<PageRecord> pageRecords = makePagesList(hitCount, pageSize, page);
rvMap.put("pages", pageRecords);
return new IndividualListResults(hitCount, results.getIndividuals(), alpha, true, makePagesList(hitCount, pageSize, page));
}else{
rvMap.put("showPages", Boolean.FALSE);
rvMap.put("pages", Collections.emptyList());
return new IndividualListResults(hitCount, results.getIndividuals(), alpha, false, Collections.<PageRecord>emptyList());
}
rvMap.put("alpha",alpha);
rvMap.put("totalCount", hitCount);
rvMap.put("entities", results.getIndividuals());
return rvMap;
}

View file

@ -0,0 +1,57 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.individuallist;
import java.util.Collection;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.controller.json.JsonServlet;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
/**
* Wrap an Individual in a JSON object for display by the script.
*
* This will be overridden in VIVO so we can have more info in the display.
*/
public class IndividualJsonWrapper {
static JSONObject packageIndividualAsJson(VitroRequest vreq, Individual ind)
throws JSONException {
// need an unfiltered dao to get firstnames and lastnames
WebappDaoFactory fullWdf = vreq.getUnfilteredWebappDaoFactory();
// TODO -- get this VIVO property out of Vitro code!
DataProperty preferredTitleDp = (new DataProperty());
preferredTitleDp
.setURI("http://vivoweb.org/ontology/core#preferredTitle");
JSONObject jo = new JSONObject();
jo.put("URI", ind.getURI());
jo.put("label", ind.getRdfsLabel());
jo.put("name", ind.getName());
jo.put("thumbUrl", ind.getThumbUrl());
jo.put("imageUrl", ind.getImageUrl());
jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq));
jo.put("mostSpecificTypes", getMostSpecificTypes(ind, fullWdf));
jo.put("preferredTitle", JsonServlet.getDataPropertyValue(ind,
preferredTitleDp, fullWdf));
return jo;
}
public static Collection<String> getMostSpecificTypes(
Individual individual, WebappDaoFactory wdf) {
ObjectPropertyStatementDao opsDao = wdf.getObjectPropertyStatementDao();
Map<String, String> mostSpecificTypes = opsDao
.getMostSpecificTypesInClassgroupsForIndividual(individual
.getURI());
return mostSpecificTypes.values();
}
}

View file

@ -0,0 +1,87 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.individuallist;
import java.util.Collections;
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 edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.PageRecord;
/**
* These are the paged results of a query for Individuals.
*
* The criteria for the search are the index of the desired page, the number of
* results displayed on each page, and an optional initial letter to search
* against.
*
* By the time this is built, the results have already been partially processed.
* A list of PageRecord object is included, with values that the GUI can use to
* create Alphabetical links. Maybe this processing should have been done later.
* Maybe it should have been left to the GUI.
*/
public class IndividualListResults {
private static final Log log = LogFactory
.getLog(IndividualListResults.class);
public static final IndividualListResults EMPTY = new IndividualListResults();
private final long totalCount;
private final List<Individual> entities;
private final String alpha;
private final boolean showPages;
private final List<PageRecord> pages;
public IndividualListResults(long totalCount, List<Individual> entities,
String alpha, boolean showPages, List<PageRecord> pages) {
this.totalCount = totalCount;
this.entities = entities;
this.alpha = alpha;
this.showPages = showPages;
this.pages = pages;
}
private IndividualListResults() {
this(0L, Collections.<Individual> emptyList(), "", false, Collections
.<PageRecord> emptyList());
}
public long getTotalCount() {
return totalCount;
}
public String getAlpha() {
return alpha;
}
public List<Individual> getEntities() {
return entities;
}
public List<PageRecord> getPages() {
return pages;
}
public boolean isShowPages() {
return showPages;
}
/**
* Some controllers put this data directly into the Freemarker body map.
* Others wrap it in JSON.
*/
public Map<String, Object> asFreemarkerMap() {
Map<String, Object> m = new HashMap<>();
m.put("showPages", showPages);
m.put("pages", pages);
m.put("alpha", alpha);
m.put("totalCount", totalCount);
m.put("entities", entities);
return m;
}
}

View file

@ -0,0 +1,148 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.individuallist;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.ArrayUtils;
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.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.PageRecord;
/**
* Utility methods for procesing the paged results of a query for a list of Individuals.
*
* Right now, there is only a method to wrap the results in Json.
*/
public class IndividualListResultsUtils {
private static final Log log = LogFactory
.getLog(IndividualListResultsUtils.class);
/**
* Process results related to VClass or vclasses. Handles both single and
* multiple vclasses being sent.
*/
public static JSONObject wrapIndividualListResultsInJson(IndividualListResults results, VitroRequest vreq,
boolean multipleVclasses) {
JSONObject rObj = new JSONObject();
if (log.isDebugEnabled()) {
dumpParametersFromRequest(vreq);
}
try {
List<VClass> vclasses = buildListOfRequestedVClasses(vreq);
VClass vclass = null;
// if single vclass expected, then include vclass.
// This relates to what the expected behavior is, not size of list
if (!multipleVclasses) {
vclass = vclasses.get(0);
// currently used for ClassGroupPage
} else {
// For now, utilize very last VClass (assume that that is the one to be employed)
// TODO: Find more general way of dealing with this: put multiple ones in?
vclass = vclasses.get(vclasses.size() - 1);
// rObj.put("vclasses", new JSONObject().put("URIs",vitroClassIdStr).put("name",vclass.getName()));
}
rObj.put("vclass", packageVClassAsJson(vclass));
rObj.put("totalCount", results.getTotalCount());
rObj.put("alpha", results.getAlpha());
rObj.put("individuals", packageIndividualsAsJson(vreq, results.getEntities()));
rObj.put("pages", packagePageRecordsAsJson(results.getPages()));
rObj.put("letters", packageLettersAsJson());
} catch (Exception ex) {
log.error("Error occurred in processing JSON object", ex);
}
return rObj;
}
private static List<VClass> buildListOfRequestedVClasses(VitroRequest vreq)
throws Exception {
String[] vitroClassIdStr = vreq.getParameterValues("vclassId");
if (ArrayUtils.isEmpty(vitroClassIdStr)) {
log.error("parameter vclassId URI parameter expected ");
throw new Exception("parameter vclassId URI parameter expected ");
}
List<VClass> list = new ArrayList<>();
for (String vclassId : vitroClassIdStr) {
VClass vclass = vreq.getWebappDaoFactory().getVClassDao()
.getVClassByURI(vclassId);
if (vclass == null) {
log.error("Couldn't retrieve vclass ");
throw new Exception("Class " + vclassId + " not found");
}
list.add(vclass);
}
return list;
}
private static JSONObject packageVClassAsJson(VClass vclass)
throws JSONException {
JSONObject jvclass = new JSONObject();
jvclass.put("URI", vclass.getURI());
jvclass.put("name", vclass.getName());
return jvclass;
}
private static JSONArray packageLettersAsJson() throws JSONException,
UnsupportedEncodingException {
List<String> letters = Controllers.getLetters();
JSONArray jletters = new JSONArray();
for (String s : letters) {
JSONObject jo = new JSONObject();
jo.put("text", s);
jo.put("param", "alpha=" + URLEncoder.encode(s, "UTF-8"));
jletters.put(jo);
}
return jletters;
}
private static JSONArray packagePageRecordsAsJson(List<PageRecord> pages)
throws JSONException {
JSONArray wpages = new JSONArray();
for (PageRecord pr : pages) {
JSONObject p = new JSONObject();
p.put("text", pr.text);
p.put("param", pr.param);
p.put("index", pr.index);
wpages.put(p);
}
return wpages;
}
private static JSONArray packageIndividualsAsJson(VitroRequest vreq,
List<Individual> inds) throws JSONException {
log.debug("Number of individuals returned from request: " + inds.size());
JSONArray jInds = new JSONArray();
for (Individual ind : inds) {
jInds.put(IndividualJsonWrapper.packageIndividualAsJson(vreq, ind));
}
return jInds;
}
private static void dumpParametersFromRequest(VitroRequest vreq) {
Map<String, String[]> pMap = vreq.getParameterMap();
for (String name : pMap.keySet()) {
for (String value : pMap.get(name)) {
log.debug("value for " + name + ": '" + value + "'");
}
}
}
}

View file

@ -3,11 +3,8 @@
package edu.cornell.mannlib.vitro.webapp.controller.json;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
@ -18,18 +15,15 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONObject;
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.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
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.IndividualListController.PageRecord;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResultsUtils;
import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResults;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.utils.log.LogUtils;
@ -94,29 +88,28 @@ public class JsonServlet extends VitroHttpServlet {
List<String> vclassURIs = Collections.singletonList(vclassURI);
VitroRequest vreq = new VitroRequest(req);
Map<String, Object> map = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
IndividualListResults vcResults = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
//last parameter indicates single vclass instead of multiple vclasses
return processVclassResultsJSON(map, vreq, false);
return IndividualListResultsUtils.wrapIndividualListResultsInJson(vcResults, vreq, false);
}
public static JSONObject getSolrIndividualsByVClasses(List<String> vclassURIs, HttpServletRequest req, ServletContext context) throws Exception {
VitroRequest vreq = new VitroRequest(req);
log.debug("Retrieve solr results for vclasses" + vclassURIs.toString());
Map<String, Object> map = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
log.debug("Results returned from Solr for " + vclassURIs.toString() + " are of size " + map.size());
IndividualListResults vcResults = getSolrVClassIntersectionResults(vclassURIs, vreq, context);
log.debug("Results returned from Solr for " + vclassURIs.toString() + " are of size " + vcResults.getTotalCount());
return processVclassResultsJSON(map, vreq, true);
return IndividualListResultsUtils.wrapIndividualListResultsInJson(vcResults, vreq, true);
}
//Including version for Solr query for Vclass Intersections
private static Map<String,Object> getSolrVClassIntersectionResults(List<String> vclassURIs, VitroRequest vreq, ServletContext context){
private static IndividualListResults getSolrVClassIntersectionResults(List<String> vclassURIs, VitroRequest vreq, ServletContext context){
log.debug("Retrieving Solr intersection results for " + vclassURIs.toString());
String alpha = IndividualListController.getAlphaParameter(vreq);
int page = IndividualListController.getPageParameter(vreq);
log.debug("Alpha and page parameters are " + alpha + " and " + page);
Map<String,Object> map = null;
try {
map = IndividualListController.getResultsForVClassIntersections(
return IndividualListController.getResultsForVClassIntersections(
vclassURIs,
page, INDIVIDUALS_PER_PAGE,
alpha,
@ -124,23 +117,10 @@ public class JsonServlet extends VitroHttpServlet {
context);
} catch(Exception ex) {
log.error("Error in retrieval of search results for VClass " + vclassURIs.toString(), ex);
return IndividualListResults.EMPTY;
}
return map;
}
// Map given to process method includes the actual individuals returned from the search
// public static JSONObject processVClassResults(Map<String, Object> map, VitroRequest vreq, ServletContext context, boolean multipleVclasses) throws Exception{
// JSONObject rObj = processVclassResultsJSON(map, vreq, multipleVclasses);
// return rObj;
// }
public static Collection<String> getMostSpecificTypes(Individual individual, WebappDaoFactory wdf) {
ObjectPropertyStatementDao opsDao = wdf.getObjectPropertyStatementDao();
Map<String, String> mostSpecificTypes = opsDao.getMostSpecificTypesInClassgroupsForIndividual(individual.getURI());
return mostSpecificTypes.values();
}
public static String getDataPropertyValue(Individual ind, DataProperty dp, WebappDaoFactory wdf){
String value = ind.getDataValue(dp.getURI());
if( value == null || value.isEmpty() )
@ -152,21 +132,20 @@ public class JsonServlet extends VitroHttpServlet {
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);
IndividualListResults vcResults = getRandomSolrVClassResults(vclassURI, vreq, context);
//last parameter indicates single vclass instead of multiple vclasses
return processVclassResultsJSON(map, vreq, false);
return IndividualListResultsUtils.wrapIndividualListResultsInJson(vcResults, vreq, false);
}
//Including version for Random Solr query for Vclass Intersections
private static Map<String,Object> getRandomSolrVClassResults(String vclassURI, VitroRequest vreq, ServletContext context){
private static IndividualListResults 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(
return IndividualListController.getRandomResultsForVClass(
vclassURI,
page,
pageSize,
@ -174,126 +153,8 @@ public class JsonServlet extends VitroHttpServlet {
context);
} catch(Exception ex) {
log.error("Error in retrieval of search results for VClass " + vclassURI, ex);
return IndividualListResults.EMPTY;
}
return map;
}
/**
* Process results related to VClass or vclasses. Handles both single and multiple vclasses being sent.
*/
public static JSONObject processVclassResultsJSON(Map<String, Object> map, VitroRequest vreq, boolean multipleVclasses) {
JSONObject rObj = new JSONObject();
VClass vclass=null;
try {
// Properties from ontologies used by VIVO - should not be in vitro
DataProperty fNameDp = (new DataProperty());
fNameDp.setURI("http://xmlns.com/foaf/0.1/firstName");
DataProperty lNameDp = (new DataProperty());
lNameDp.setURI("http://xmlns.com/foaf/0.1/lastName");
DataProperty preferredTitleDp = (new DataProperty());
preferredTitleDp.setURI("http://vivoweb.org/ontology/core#preferredTitle");
if( log.isDebugEnabled() ){
@SuppressWarnings("unchecked")
Enumeration<String> e = vreq.getParameterNames();
while(e.hasMoreElements()){
String name = e.nextElement();
log.debug("parameter: " + name);
for( String value : vreq.getParameterValues(name) ){
log.debug("value for " + name + ": '" + value + "'");
}
}
}
//need an unfiltered dao to get firstnames and lastnames
WebappDaoFactory fullWdf = vreq.getUnfilteredWebappDaoFactory();
String[] vitroClassIdStr = vreq.getParameterValues("vclassId");
if ( vitroClassIdStr != null && vitroClassIdStr.length > 0){
for(String vclassId: vitroClassIdStr) {
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassId);
if (vclass == null) {
log.error("Couldn't retrieve vclass ");
throw new Exception ("Class " + vclassId + " not found");
}
}
}else{
log.error("parameter vclassId URI parameter expected ");
throw new Exception("parameter vclassId URI parameter expected ");
}
List<String> vclassIds = Arrays.asList(vitroClassIdStr);
//if single vclass expected, then include vclass. This relates to what the expected behavior is, not size of list
if(!multipleVclasses) {
//currently used for ClassGroupPage
rObj.put("vclass",
new JSONObject().put("URI",vclass.getURI())
.put("name",vclass.getName()));
} else {
//For now, utilize very last VClass (assume that that is the one to be employed)
//TODO: Find more general way of dealing with this
//put multiple ones in?
if(vclassIds.size() > 0) {
int numberVClasses = vclassIds.size();
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassIds.get(numberVClasses - 1));
rObj.put("vclass", new JSONObject().put("URI",vclass.getURI())
.put("name",vclass.getName()));
}
// rObj.put("vclasses", new JSONObject().put("URIs",vitroClassIdStr)
// .put("name",vclass.getName()));
}
if (vclass != null) {
rObj.put("totalCount", map.get("totalCount"));
rObj.put("alpha", map.get("alpha"));
List<Individual> inds = (List<Individual>)map.get("entities");
log.debug("Number of individuals returned from request: " + inds.size());
JSONArray jInds = new JSONArray();
for(Individual ind : inds ){
JSONObject jo = new JSONObject();
jo.put("URI", ind.getURI());
jo.put("label",ind.getRdfsLabel());
jo.put("name",ind.getName());
jo.put("thumbUrl", ind.getThumbUrl());
jo.put("imageUrl", ind.getImageUrl());
jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq));
jo.put("mostSpecificTypes", JsonServlet.getMostSpecificTypes(ind,fullWdf));
jo.put("preferredTitle", JsonServlet.getDataPropertyValue(ind, preferredTitleDp, fullWdf));
jInds.put(jo);
}
rObj.put("individuals", jInds);
JSONArray wpages = new JSONArray();
//Made sure that PageRecord here is SolrIndividualListController not IndividualListController
List<PageRecord> pages = (List<PageRecord>)map.get("pages");
for( PageRecord pr: pages ){
JSONObject p = new JSONObject();
p.put("text", pr.text);
p.put("param", pr.param);
p.put("index", pr.index);
wpages.put( p );
}
rObj.put("pages",wpages);
JSONArray jletters = new JSONArray();
List<String> letters = Controllers.getLetters();
for( String s : letters){
JSONObject jo = new JSONObject();
jo.put("text", s);
jo.put("param", "alpha=" + URLEncoder.encode(s, "UTF-8"));
jletters.put( jo );
}
rObj.put("letters", jletters);
}
} catch(Exception ex) {
log.error("Error occurred in processing JSON object", ex);
}
return rObj;
}
}

View file

@ -3,10 +3,7 @@ package edu.cornell.mannlib.vitro.webapp.utils.dataGetter;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -17,7 +14,6 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONObject;
import com.hp.hpl.jena.query.Query;
@ -35,20 +31,13 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.vocabulary.OWL;
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.Controllers;
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.IndividualListController.PageRecord;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.controller.json.JsonServlet;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupsForRequest;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
@ -324,123 +313,6 @@ public class DataGetterUtils {
return classGroupUri;
}
/**
* Process results related to VClass or vclasses. Handles both single and multiple vclasses being sent.
*/
public static JSONObject processVclassResultsJSON(Map<String, Object> map, VitroRequest vreq, boolean multipleVclasses) {
JSONObject rObj = new JSONObject();
VClass vclass=null;
try {
// Properties from ontologies used by VIVO - should not be in vitro
DataProperty fNameDp = (new DataProperty());
fNameDp.setURI("http://xmlns.com/foaf/0.1/firstName");
DataProperty lNameDp = (new DataProperty());
lNameDp.setURI("http://xmlns.com/foaf/0.1/lastName");
DataProperty preferredTitleDp = (new DataProperty());
preferredTitleDp.setURI("http://vivoweb.org/ontology/core#preferredTitle");
if( log.isDebugEnabled() ){
@SuppressWarnings("unchecked")
Enumeration<String> e = vreq.getParameterNames();
while(e.hasMoreElements()){
String name = e.nextElement();
log.debug("parameter: " + name);
for( String value : vreq.getParameterValues(name) ){
log.debug("value for " + name + ": '" + value + "'");
}
}
}
//need an unfiltered dao to get firstnames and lastnames
WebappDaoFactory fullWdf = vreq.getUnfilteredWebappDaoFactory();
String[] vitroClassIdStr = vreq.getParameterValues("vclassId");
if ( vitroClassIdStr != null && vitroClassIdStr.length > 0){
for(String vclassId: vitroClassIdStr) {
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassId);
if (vclass == null) {
log.error("Couldn't retrieve vclass ");
throw new Exception ("Class " + vclassId + " not found");
}
}
}else{
log.error("parameter vclassId URI parameter expected ");
throw new Exception("parameter vclassId URI parameter expected ");
}
List<String> vclassIds = Arrays.asList(vitroClassIdStr);
//if single vclass expected, then include vclass. This relates to what the expected behavior is, not size of list
if(!multipleVclasses) {
//currently used for ClassGroupPage
rObj.put("vclass",
new JSONObject().put("URI",vclass.getURI())
.put("name",vclass.getName()));
} else {
//For now, utilize very last VClass (assume that that is the one to be employed)
//TODO: Find more general way of dealing with this
//put multiple ones in?
if(vclassIds.size() > 0) {
int numberVClasses = vclassIds.size();
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassIds.get(numberVClasses - 1));
rObj.put("vclass", new JSONObject().put("URI",vclass.getURI())
.put("name",vclass.getName()));
}
// rObj.put("vclasses", new JSONObject().put("URIs",vitroClassIdStr)
// .put("name",vclass.getName()));
}
if (vclass != null) {
rObj.put("totalCount", map.get("totalCount"));
rObj.put("alpha", map.get("alpha"));
List<Individual> inds = (List<Individual>)map.get("entities");
log.debug("Number of individuals returned from request: " + inds.size());
JSONArray jInds = new JSONArray();
for(Individual ind : inds ){
JSONObject jo = new JSONObject();
jo.put("URI", ind.getURI());
jo.put("label",ind.getRdfsLabel());
jo.put("name",ind.getName());
jo.put("thumbUrl", ind.getThumbUrl());
jo.put("imageUrl", ind.getImageUrl());
jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq));
jo.put("mostSpecificTypes", JsonServlet.getMostSpecificTypes(ind,fullWdf));
jo.put("preferredTitle", JsonServlet.getDataPropertyValue(ind, preferredTitleDp, fullWdf));
jInds.put(jo);
}
rObj.put("individuals", jInds);
JSONArray wpages = new JSONArray();
//Made sure that PageRecord here is SolrIndividualListController not IndividualListController
List<PageRecord> pages = (List<PageRecord>)map.get("pages");
for( PageRecord pr: pages ){
JSONObject p = new JSONObject();
p.put("text", pr.text);
p.put("param", pr.param);
p.put("index", pr.index);
wpages.put( p );
}
rObj.put("pages",wpages);
JSONArray jletters = new JSONArray();
List<String> letters = Controllers.getLetters();
for( String s : letters){
JSONObject jo = new JSONObject();
jo.put("text", s);
jo.put("param", "alpha=" + URLEncoder.encode(s, "UTF-8"));
jletters.put( jo );
}
rObj.put("letters", jletters);
}
} catch(Exception ex) {
log.error("Error occurred in processing JSON object", ex);
}
return rObj;
}
private static final String forClassGroupURI = "<" + DisplayVocabulary.FOR_CLASSGROUP + ">";
private static final String classGroupForDataGetterQuery =

View file

@ -353,14 +353,15 @@ public class IndividualsForClassesDataGetter extends DataGetterBase implements D
public String getDataServiceUrl() {
return UrlBuilder.getUrl("/dataservice?getRenderedSolrIndividualsByVClass=1&vclassId=");
}
/**
* For processig of JSONObject
*/
public JSONObject convertToJSON(Map<String, Object> map, VitroRequest vreq) {
JSONObject rObj = DataGetterUtils.processVclassResultsJSON(map, vreq, true);
public JSONObject convertToJSON(Map<String, Object> dataMap, VitroRequest vreq) {
JSONObject rObj = null;
return rObj;
}
protected static void setAllClassCountsToZero(VClassGroup vcg){
for(VClass vc : vcg){
vc.setEntityCount(0);

View file

@ -3,9 +3,7 @@ package edu.cornell.mannlib.vitro.webapp.utils.dataGetter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -23,7 +21,6 @@ import com.hp.hpl.jena.query.QuerySolutionMap;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.shared.Lock;
@ -33,8 +30,9 @@ 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.controller.freemarker.IndividualListController.SearchException;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResults;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.utils.solr.SolrQueryUtils;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual;
@ -174,16 +172,15 @@ public class SolrIndividualsDataGetter extends DataGetterBase implements DataGet
try {
String alpha = SolrQueryUtils.getAlphaParameter(vreq);
int page = SolrQueryUtils.getPageParameter(vreq);
Map<String,Object> map = IndividualListController.getResultsForVClass(
IndividualListResults vcResults = IndividualListController.getResultsForVClass(
vclass.getURI(),
page,
alpha,
vreq.getWebappDaoFactory().getIndividualDao(),
vreq.getSession().getServletContext());
body.putAll(map);
body.putAll(vcResults.asFreemarkerMap());
@SuppressWarnings("unchecked")
List<Individual> inds = (List<Individual>)map.get("entities");
List<Individual> inds = vcResults.getEntities();
List<ListedIndividual> indsTm = new ArrayList<ListedIndividual>();
if (inds != null) {
for ( Individual ind : inds ) {

View file

@ -4,8 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.utils.solr;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -20,9 +18,7 @@ import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
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.IndividualListQueryResults;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController.SearchException;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup;