Clean up indentation
This commit is contained in:
parent
464a89ecaa
commit
d6f8ac002e
1 changed files with 188 additions and 186 deletions
|
@ -40,16 +40,16 @@ import freemarker.ext.beans.BeansWrapper;
|
||||||
import freemarker.template.TemplateModel;
|
import freemarker.template.TemplateModel;
|
||||||
|
|
||||||
public class DataGetterUtils {
|
public class DataGetterUtils {
|
||||||
protected static final String DATA_GETTER_MAP = "pageTypeToDataGetterMap";
|
protected static final String DATA_GETTER_MAP = "pageTypeToDataGetterMap";
|
||||||
private static final Log log = LogFactory.getLog(DataGetterUtils.class);
|
private static final Log log = LogFactory.getLog(DataGetterUtils.class);
|
||||||
|
|
||||||
public static Map<String,Object> getDataForPage(String pageUri, VitroRequest vreq, ServletContext context) {
|
public static Map<String,Object> getDataForPage(String pageUri, VitroRequest vreq, ServletContext context) {
|
||||||
//Based on page type get the appropriate data getter
|
//Based on page type get the appropriate data getter
|
||||||
Map<String, Object> page = getMapForPage(vreq, pageUri);
|
Map<String, Object> page = getMapForPage(vreq, pageUri);
|
||||||
//Get data getters map
|
//Get data getters map
|
||||||
Map<String, PageDataGetter> dataGetterMap = getPageDataGetterMap(context);
|
Map<String, PageDataGetter> dataGetterMap = getPageDataGetterMap(context);
|
||||||
//Get types associated with page
|
//Get types associated with page
|
||||||
Map<String,Object> data = new HashMap<String,Object>();
|
Map<String,Object> data = new HashMap<String,Object>();
|
||||||
List<String> dataGetters = (List<String>)page.get("dataGetters");
|
List<String> dataGetters = (List<String>)page.get("dataGetters");
|
||||||
if( dataGetters != null ){
|
if( dataGetters != null ){
|
||||||
for( String dataGetter : dataGetters){
|
for( String dataGetter : dataGetters){
|
||||||
|
@ -64,21 +64,21 @@ public class DataGetterUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Convert data to JSON for page uri based on type and related datagetters
|
* Convert data to JSON for page uri based on type and related datagetters
|
||||||
* TODO: How to handle different data getters? Will this replace json fields or add to them?
|
* TODO: How to handle different data getters? Will this replace json fields or add to them?
|
||||||
*/
|
*/
|
||||||
public static JSONObject covertDataToJSONForPage(String pageUri, Map<String, Object> data, VitroRequest vreq, ServletContext context) {
|
public static JSONObject covertDataToJSONForPage(String pageUri, Map<String, Object> data, VitroRequest vreq, ServletContext context) {
|
||||||
//Based on page type get the appropriate data getter
|
//Based on page type get the appropriate data getter
|
||||||
Map<String, Object> page = getMapForPage(vreq, pageUri);
|
Map<String, Object> page = getMapForPage(vreq, pageUri);
|
||||||
//Get data getters map
|
//Get data getters map
|
||||||
Map<String, PageDataGetter> dataGetterMap = getPageDataGetterMap(context);
|
Map<String, PageDataGetter> dataGetterMap = getPageDataGetterMap(context);
|
||||||
//Get types associated with page
|
//Get types associated with page
|
||||||
JSONObject rObj = null;
|
JSONObject rObj = null;
|
||||||
List<String> types = (List<String>)page.get("types");
|
List<String> types = (List<String>)page.get("types");
|
||||||
if( types != null ){
|
if( types != null ){
|
||||||
for( String type : types){
|
for( String type : types){
|
||||||
|
@ -87,14 +87,14 @@ public class DataGetterUtils {
|
||||||
try{
|
try{
|
||||||
typeObj = getter.convertToJSON(data, vreq);
|
typeObj = getter.convertToJSON(data, vreq);
|
||||||
if( typeObj != null) {
|
if( typeObj != null) {
|
||||||
//Copy over everything from this type Obj to
|
//Copy over everything from this type Obj to
|
||||||
//TODO: Review how to handle duplicate keys, etc.
|
//TODO: Review how to handle duplicate keys, etc.
|
||||||
if(rObj != null) {
|
if(rObj != null) {
|
||||||
//For now, just nests as separate entry
|
//For now, just nests as separate entry
|
||||||
rObj.put(type, typeObj);
|
rObj.put(type, typeObj);
|
||||||
} else {
|
} else {
|
||||||
rObj = typeObj;
|
rObj = typeObj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(Throwable th){
|
}catch(Throwable th){
|
||||||
|
@ -102,32 +102,33 @@ public class DataGetterUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rObj;
|
return rObj;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Returns map with all page attributes from display model
|
* Returns map with all page attributes from display model
|
||||||
*/
|
*/
|
||||||
public static Map<String, Object> getMapForPage(VitroRequest vreq, String pageUri) {
|
public static Map<String, Object> getMapForPage(VitroRequest vreq, String pageUri) {
|
||||||
//do a query to the display model for attributes of this page.
|
//do a query to the display model for attributes of this page.
|
||||||
return vreq.getWebappDaoFactory().getPageDao().getPage(pageUri);
|
return vreq.getWebappDaoFactory().getPageDao().getPage(pageUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setupDataGetters(ServletContext context){
|
public static void setupDataGetters(ServletContext context){
|
||||||
if( context != null && context.getAttribute(DATA_GETTER_MAP) == null ){
|
if( context != null && context.getAttribute(DATA_GETTER_MAP) == null ){
|
||||||
context.setAttribute(DATA_GETTER_MAP, new HashMap<String,PageDataGetter>());
|
context.setAttribute(DATA_GETTER_MAP, new HashMap<String,PageDataGetter>());
|
||||||
|
|
||||||
/* register all page data getters with the PageController servlet.
|
/* register all page data getters with the PageController servlet.
|
||||||
* There should be a better way of doing this. */
|
* There should be a better way of doing this. */
|
||||||
ClassGroupPageData cgpd = new ClassGroupPageData();
|
ClassGroupPageData cgpd = new ClassGroupPageData();
|
||||||
getPageDataGetterMap(context).put(cgpd.getType(), cgpd);
|
getPageDataGetterMap(context).put(cgpd.getType(), cgpd);
|
||||||
BrowseDataGetter bdg = new BrowseDataGetter();
|
BrowseDataGetter bdg = new BrowseDataGetter();
|
||||||
getPageDataGetterMap(context).put(bdg.getType(), bdg);
|
getPageDataGetterMap(context).put(bdg.getType(), bdg);
|
||||||
//TODO: Check if can include by type here
|
//TODO: Check if can include by type here
|
||||||
IndividualsForClassesDataGetter cidg = new IndividualsForClassesDataGetter();
|
IndividualsForClassesDataGetter cidg = new IndividualsForClassesDataGetter();
|
||||||
getPageDataGetterMap(context).put(cidg.getType(), cidg);
|
getPageDataGetterMap(context).put(cidg.getType(), cidg);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static Map<String,PageDataGetter> getPageDataGetterMap(ServletContext sc){
|
public static Map<String,PageDataGetter> getPageDataGetterMap(ServletContext sc){
|
||||||
setupDataGetters(sc);
|
setupDataGetters(sc);
|
||||||
return (Map<String,PageDataGetter>)sc.getAttribute(DATA_GETTER_MAP);
|
return (Map<String,PageDataGetter>)sc.getAttribute(DATA_GETTER_MAP);
|
||||||
|
@ -135,9 +136,9 @@ public class DataGetterUtils {
|
||||||
/*
|
/*
|
||||||
//Based on page Uri, do conversions
|
//Based on page Uri, do conversions
|
||||||
public static PageDataGetter getDataGetterForType(String type, ServletContext sc) {
|
public static PageDataGetter getDataGetterForType(String type, ServletContext sc) {
|
||||||
Map<String, PageDataGetter> map = getPageDataGetterMap(sc);
|
Map<String, PageDataGetter> map = getPageDataGetterMap(sc);
|
||||||
PageDataGetter pdg = (PageDataGetter) map.get(type);
|
PageDataGetter pdg = (PageDataGetter) map.get(type);
|
||||||
return pdg;
|
return pdg;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
protected static Map<String,Object> getAdditionalData(
|
protected static Map<String,Object> getAdditionalData(
|
||||||
|
@ -162,143 +163,144 @@ public class DataGetterUtils {
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
public static JSONObject processVclassResultsJSON(Map<String, Object> map, VitroRequest vreq, boolean multipleVclasses) {
|
public static JSONObject processVclassResultsJSON(Map<String, Object> map, VitroRequest vreq, boolean multipleVclasses) {
|
||||||
JSONObject rObj = new JSONObject();
|
JSONObject rObj = new JSONObject();
|
||||||
VClass vclass=null;
|
VClass vclass=null;
|
||||||
String errorMessage = null;
|
String errorMessage = null;
|
||||||
try{
|
|
||||||
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");
|
|
||||||
|
|
||||||
//this property is vivo specific
|
try {
|
||||||
DataProperty preferredTitleDp = (new DataProperty());
|
|
||||||
preferredTitleDp.setURI("http://vivoweb.org/ontology/core#preferredTitle");
|
|
||||||
|
|
||||||
|
// 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() ){
|
if( log.isDebugEnabled() ){
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Enumeration<String> e = vreq.getParameterNames();
|
Enumeration<String> e = vreq.getParameterNames();
|
||||||
while(e.hasMoreElements()){
|
while(e.hasMoreElements()){
|
||||||
String name = (String)e.nextElement();
|
String name = (String)e.nextElement();
|
||||||
log.debug("parameter: " + name);
|
log.debug("parameter: " + name);
|
||||||
for( String value : vreq.getParameterValues(name) ){
|
for( String value : vreq.getParameterValues(name) ){
|
||||||
log.debug("value for " + name + ": '" + value + "'");
|
log.debug("value for " + name + ": '" + value + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//need an unfiltered dao to get firstnames and lastnames
|
||||||
|
WebappDaoFactory fullWdf = vreq.getFullWebappDaoFactory();
|
||||||
|
|
||||||
|
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.debug("Couldn't retrieve vclass ");
|
||||||
|
throw new Exception (errorMessage = "Class " + vclassId + " not found");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}else{
|
||||||
}
|
log.debug("parameter vclassId URI parameter expected ");
|
||||||
|
throw new Exception("parameter vclassId URI parameter expected ");
|
||||||
//need an unfiltered dao to get firstnames and lastnames
|
}
|
||||||
WebappDaoFactory fullWdf = vreq.getFullWebappDaoFactory();
|
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
|
||||||
String[] vitroClassIdStr = vreq.getParameterValues("vclassId");
|
if(!multipleVclasses) {
|
||||||
if ( vitroClassIdStr != null && vitroClassIdStr.length > 0){
|
//currently used for ClassGroupPage
|
||||||
for(String vclassId: vitroClassIdStr) {
|
rObj.put("vclass",
|
||||||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassId);
|
new JSONObject().put("URI",vclass.getURI())
|
||||||
if (vclass == null) {
|
.put("name",vclass.getName()));
|
||||||
log.debug("Couldn't retrieve vclass ");
|
} else {
|
||||||
throw new Exception (errorMessage = "Class " + vclassId + " not found");
|
//For now, utilize very first first VClass (assume that that is the one to be employed)
|
||||||
}
|
//TODO: Find more general way of dealing with this
|
||||||
}
|
//put multiple ones in?
|
||||||
}else{
|
if(vclassIds.size() > 0) {
|
||||||
log.debug("parameter vclassId URI parameter expected ");
|
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassIds.get(0));
|
||||||
throw new Exception("parameter vclassId URI parameter expected ");
|
rObj.put("vclass", new JSONObject().put("URI",vclass.getURI())
|
||||||
}
|
|
||||||
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()));
|
.put("name",vclass.getName()));
|
||||||
} else {
|
}
|
||||||
//For now, utilize very first first VClass (assume that that is the one to be employed)
|
// rObj.put("vclasses", new JSONObject().put("URIs",vitroClassIdStr)
|
||||||
//TODO: Find more general way of dealing with this
|
// .put("name",vclass.getName()));
|
||||||
//put multiple ones in?
|
}
|
||||||
if(vclassIds.size() > 0) {
|
if (vclass != null) {
|
||||||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vclassIds.get(0));
|
|
||||||
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("totalCount", map.get("totalCount"));
|
||||||
rObj.put("alpha", map.get("alpha"));
|
rObj.put("alpha", map.get("alpha"));
|
||||||
|
|
||||||
List<Individual> inds = (List<Individual>)map.get("entities");
|
List<Individual> inds = (List<Individual>)map.get("entities");
|
||||||
|
|
||||||
JSONArray jInds = new JSONArray();
|
JSONArray jInds = new JSONArray();
|
||||||
for(Individual ind : inds ){
|
for(Individual ind : inds ){
|
||||||
JSONObject jo = new JSONObject();
|
JSONObject jo = new JSONObject();
|
||||||
jo.put("URI", ind.getURI());
|
jo.put("URI", ind.getURI());
|
||||||
jo.put("label",ind.getRdfsLabel());
|
jo.put("label",ind.getRdfsLabel());
|
||||||
jo.put("name",ind.getName());
|
jo.put("name",ind.getName());
|
||||||
jo.put("thumbUrl", ind.getThumbUrl());
|
jo.put("thumbUrl", ind.getThumbUrl());
|
||||||
jo.put("imageUrl", ind.getImageUrl());
|
jo.put("imageUrl", ind.getImageUrl());
|
||||||
jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq));
|
jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq));
|
||||||
|
|
||||||
jo.put("vclassName", SolrJsonServlet.getMostSpecificTypeName(ind,fullWdf));
|
jo.put("vclassName", SolrJsonServlet.getMostSpecificTypeName(ind,fullWdf));
|
||||||
|
|
||||||
jo.put("preferredTitle", SolrJsonServlet.getDataPropertyValue(ind, preferredTitleDp, fullWdf));
|
jo.put("preferredTitle", SolrJsonServlet.getDataPropertyValue(ind, preferredTitleDp, fullWdf));
|
||||||
jo.put("firstName", SolrJsonServlet.getDataPropertyValue(ind, fNameDp, fullWdf));
|
jo.put("firstName", SolrJsonServlet.getDataPropertyValue(ind, fNameDp, fullWdf));
|
||||||
jo.put("lastName", SolrJsonServlet.getDataPropertyValue(ind, lNameDp, fullWdf));
|
jo.put("lastName", SolrJsonServlet.getDataPropertyValue(ind, lNameDp, fullWdf));
|
||||||
|
|
||||||
jInds.put(jo);
|
jInds.put(jo);
|
||||||
}
|
}
|
||||||
rObj.put("individuals", jInds);
|
rObj.put("individuals", jInds);
|
||||||
|
|
||||||
JSONArray wpages = new JSONArray();
|
JSONArray wpages = new JSONArray();
|
||||||
//Made sure that PageRecord here is SolrIndividualListController not IndividualListController
|
//Made sure that PageRecord here is SolrIndividualListController not IndividualListController
|
||||||
List<PageRecord> pages = (List<PageRecord>)map.get("pages");
|
List<PageRecord> pages = (List<PageRecord>)map.get("pages");
|
||||||
for( PageRecord pr: pages ){
|
for( PageRecord pr: pages ){
|
||||||
JSONObject p = new JSONObject();
|
JSONObject p = new JSONObject();
|
||||||
p.put("text", pr.text);
|
p.put("text", pr.text);
|
||||||
p.put("param", pr.param);
|
p.put("param", pr.param);
|
||||||
p.put("index", pr.index);
|
p.put("index", pr.index);
|
||||||
wpages.put( p );
|
wpages.put( p );
|
||||||
}
|
}
|
||||||
rObj.put("pages",wpages);
|
rObj.put("pages",wpages);
|
||||||
|
|
||||||
JSONArray jletters = new JSONArray();
|
JSONArray jletters = new JSONArray();
|
||||||
List<String> letters = Controllers.getLetters();
|
List<String> letters = Controllers.getLetters();
|
||||||
for( String s : letters){
|
for( String s : letters){
|
||||||
JSONObject jo = new JSONObject();
|
JSONObject jo = new JSONObject();
|
||||||
jo.put("text", s);
|
jo.put("text", s);
|
||||||
jo.put("param", "alpha=" + URLEncoder.encode(s, "UTF-8"));
|
jo.put("param", "alpha=" + URLEncoder.encode(s, "UTF-8"));
|
||||||
jletters.put( jo );
|
jletters.put( jo );
|
||||||
}
|
}
|
||||||
rObj.put("letters", jletters);
|
rObj.put("letters", jletters);
|
||||||
}
|
}
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
log.error("Error occurred in processing JSON object", ex);
|
log.error("Error occurred in processing JSON object", ex);
|
||||||
}
|
}
|
||||||
return rObj;
|
return rObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copied from JSONServlet as expect this to be related to VitroClassGroup
|
* Copied from JSONServlet as expect this to be related to VitroClassGroup
|
||||||
*/
|
*/
|
||||||
public static JSONObject processVClassGroupJSON(VitroRequest vreq, ServletContext context, VClassGroup vcg) {
|
public static JSONObject processVClassGroupJSON(VitroRequest vreq, ServletContext context, VClassGroup vcg) {
|
||||||
JSONObject map = new JSONObject();
|
JSONObject map = new JSONObject();
|
||||||
try {
|
try {
|
||||||
ArrayList<JSONObject> classes = new ArrayList<JSONObject>(vcg.size());
|
ArrayList<JSONObject> classes = new ArrayList<JSONObject>(vcg.size());
|
||||||
for( VClass vc : vcg){
|
for( VClass vc : vcg){
|
||||||
JSONObject vcObj = new JSONObject();
|
JSONObject vcObj = new JSONObject();
|
||||||
vcObj.put("name", vc.getName());
|
vcObj.put("name", vc.getName());
|
||||||
vcObj.put("URI", vc.getURI());
|
vcObj.put("URI", vc.getURI());
|
||||||
vcObj.put("entityCount", vc.getEntityCount());
|
vcObj.put("entityCount", vc.getEntityCount());
|
||||||
classes.add(vcObj);
|
classes.add(vcObj);
|
||||||
}
|
}
|
||||||
map.put("classes", classes);
|
map.put("classes", classes);
|
||||||
map.put("classGroupName", vcg.getPublicName());
|
map.put("classGroupName", vcg.getPublicName());
|
||||||
map.put("classGroupUri", vcg.getURI());
|
map.put("classGroupUri", vcg.getURI());
|
||||||
} catch(Exception ex) {
|
|
||||||
log.error("Error occurred in processing VClass group ", ex);
|
} catch(Exception ex) {
|
||||||
}
|
log.error("Error occurred in processing VClass group ", ex);
|
||||||
return map;
|
}
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue