NIHVIVO-2411 Modify ClassGroupPageData.java and browseByVClass.js to use the new BROWSE short view. This means that the VIVO-specific browseByVClassPeople.js and menupage--classgroup-people.ftl can be replaced by a VIVO-specific short view.
This commit is contained in:
parent
47b3565e58
commit
af3ca17ef1
4 changed files with 152 additions and 78 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.services.shortview;
|
package edu.cornell.mannlib.vitro.webapp.services.shortview;
|
||||||
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService.ShortViewContext.SEARCH;
|
import static edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService.ShortViewContext.BROWSE;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -12,8 +12,23 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Property;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
|
||||||
|
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.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
|
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
|
@ -21,20 +36,31 @@ import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetter;
|
||||||
* Get rid of this when the Application Ontology is implemented.
|
* Get rid of this when the Application Ontology is implemented.
|
||||||
*/
|
*/
|
||||||
public class FakeApplicationOntologyService {
|
public class FakeApplicationOntologyService {
|
||||||
|
private static final Log log = LogFactory
|
||||||
|
.getLog(FakeApplicationOntologyService.class);
|
||||||
|
|
||||||
private static final String FACULTY_MEMBER_CLASS_URI = "http://vivoweb.org/ontology/core#FacultyMember";
|
private static final String FACULTY_MEMBER_CLASS_URI = "http://vivoweb.org/ontology/core#FacultyMember";
|
||||||
|
private static final String PEOPLE_CLASSGROUP_URI = "http://vivoweb.org/ontology#vitroClassGrouppeople";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the template name and DataGetter instances associated with this
|
* Return the template name and DataGetter instances associated with this
|
||||||
* class and this short view context. If none, return null.
|
* class and this short view context. If none, return null.
|
||||||
*/
|
*/
|
||||||
public TemplateAndDataGetters getShortViewProperties(String classUri,
|
public TemplateAndDataGetters getShortViewProperties(WebappDaoFactory wadf,
|
||||||
String contextName) {
|
Individual individual, String classUri, String contextName) {
|
||||||
// if ((SEARCH.name().equals(contextName))
|
if ((BROWSE.name().equals(contextName))
|
||||||
// && (classUri.equals(FACULTY_MEMBER_CLASS_URI))) {
|
&& (isClassInPeopleClassGroup(wadf, classUri))) {
|
||||||
// return new TemplateAndDataGetters("view-search-faculty.ftl", new FakeFacultyDataGetter());
|
return new TemplateAndDataGetters("view-browse-people.ftl",
|
||||||
// } else {
|
new FakeVivoPeopleDataGetter(individual.getURI()));
|
||||||
return null;
|
}
|
||||||
// }
|
// A mockup of Tammy's use case.
|
||||||
|
// if ((SEARCH.name().equals(contextName))
|
||||||
|
// && (classUri.equals(FACULTY_MEMBER_CLASS_URI))) {
|
||||||
|
// return new TemplateAndDataGetters("view-search-faculty.ftl", new
|
||||||
|
// FakeFacultyDataGetter());
|
||||||
|
// } else {
|
||||||
|
return null;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The info associated with a short view. */
|
/** The info associated with a short view. */
|
||||||
|
@ -59,6 +85,36 @@ public class FakeApplicationOntologyService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isClassInPeopleClassGroup(WebappDaoFactory wadf,
|
||||||
|
String classUri) {
|
||||||
|
if (wadf == null) {
|
||||||
|
log.debug("isClassInPeopleClassGroup: WebappDaoFactory is null.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
VClassDao vcDao = wadf.getVClassDao();
|
||||||
|
if (vcDao == null) {
|
||||||
|
log.debug("isClassInPeopleClassGroup: VClassDao is null.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
VClass vclass = vcDao.getVClassByURI(classUri);
|
||||||
|
if (vclass == null) {
|
||||||
|
log.debug("isClassInPeopleClassGroup: VClass is null.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String vclassGroupUri = vclass.getGroupURI();
|
||||||
|
if (vclassGroupUri == null) {
|
||||||
|
log.debug("isClassInPeopleClassGroup: vclassGroupUri is null.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isPeople = PEOPLE_CLASSGROUP_URI.equals(vclassGroupUri);
|
||||||
|
log.debug("isClassInPeopleClassGroup: isPeople = " + isPeople);
|
||||||
|
return isPeople;
|
||||||
|
}
|
||||||
|
|
||||||
private static class FakeFacultyDataGetter implements DataGetter {
|
private static class FakeFacultyDataGetter implements DataGetter {
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getData(ServletContext context,
|
public Map<String, Object> getData(ServletContext context,
|
||||||
|
@ -69,6 +125,52 @@ public class FakeApplicationOntologyService {
|
||||||
map.put("extra", extras);
|
map.put("extra", extras);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A SPARQL query data getter that initializes itself from its own private
|
||||||
|
* "display model". The query finds a preferred title for the individual.
|
||||||
|
*/
|
||||||
|
private static class FakeVivoPeopleDataGetter extends SparqlQueryDataGetter {
|
||||||
|
private static final String QUERY_STRING = "SELECT ?uri ?pt WHERE {\n"
|
||||||
|
+ " ?uri <http://vivoweb.org/ontology/core#preferredTitle> ?pt\n"
|
||||||
|
+ "} LIMIT 1";
|
||||||
|
|
||||||
|
private static final String FAKE_VIVO_PEOPLE_DATA_GETTER_URI = "http://FakeVivoPeopleDataGetter";
|
||||||
|
|
||||||
|
private static OntModel fakeDisplayModel = initializeFakeDisplayModel();
|
||||||
|
|
||||||
|
private static OntModel initializeFakeDisplayModel() {
|
||||||
|
OntModel m = ModelFactory
|
||||||
|
.createOntologyModel(OntModelSpec.OWL_DL_MEM);
|
||||||
|
|
||||||
|
Resource dataGetter = m
|
||||||
|
.getResource(FAKE_VIVO_PEOPLE_DATA_GETTER_URI);
|
||||||
|
Property queryProperty = m.getProperty(DisplayVocabulary.QUERY);
|
||||||
|
Property saveToVarProperty = m
|
||||||
|
.getProperty(DisplayVocabulary.SAVE_TO_VAR);
|
||||||
|
|
||||||
|
m.add(dataGetter, queryProperty, QUERY_STRING);
|
||||||
|
m.add(dataGetter, saveToVarProperty, "extra");
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String individualUri;
|
||||||
|
|
||||||
|
public FakeVivoPeopleDataGetter(String individualUri) {
|
||||||
|
super(fakeDisplayModel, "http://FakeVivoPeopleDataGetter");
|
||||||
|
this.individualUri = individualUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getData(ServletContext context,
|
||||||
|
VitroRequest vreq, Map<String, Object> pageData) {
|
||||||
|
Map<String, String[]> parms = new HashMap<String, String[]>();
|
||||||
|
parms.put("uri", new String[] { individualUri });
|
||||||
|
|
||||||
|
return doQuery(parms, getModel(context, vreq, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,18 +12,7 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import com.hp.hpl.jena.query.Query;
|
|
||||||
import com.hp.hpl.jena.query.QueryExecution;
|
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
|
||||||
import com.hp.hpl.jena.query.QueryFactory;
|
|
||||||
import com.hp.hpl.jena.query.QuerySolution;
|
|
||||||
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.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -164,7 +153,7 @@ public class ClassGroupPageData extends DataGetterBase implements DataGetter{
|
||||||
|
|
||||||
//Get data servuice
|
//Get data servuice
|
||||||
public String getDataServiceUrl() {
|
public String getDataServiceUrl() {
|
||||||
return UrlBuilder.getUrl("/dataservice?getSolrIndividualsByVClass=1&vclassId=");
|
return UrlBuilder.getUrl("/dataservice?getRenderedSolrIndividualsByVClass=1&vclassId=");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -105,36 +105,8 @@ var browseByVClass = {
|
||||||
} else {
|
} else {
|
||||||
var vclassName = results.vclass.name;
|
var vclassName = results.vclass.name;
|
||||||
$.each(results.individuals, function(i, item) {
|
$.each(results.individuals, function(i, item) {
|
||||||
var individual,
|
var individual = results.individuals[i];
|
||||||
label,
|
individualList += individual.shortViewHtml;
|
||||||
mostSpecificTypes,
|
|
||||||
uri,
|
|
||||||
profileUrl,
|
|
||||||
image,
|
|
||||||
listItem;
|
|
||||||
|
|
||||||
individual = results.individuals[i];
|
|
||||||
label = individual.label;
|
|
||||||
mostSpecificTypes = individual.mostSpecificTypes;
|
|
||||||
moreInfo = browseByVClass.getMoreInfo(mostSpecificTypes, vclassName);
|
|
||||||
uri = individual.URI;
|
|
||||||
profileUrl = individual.profileUrl;
|
|
||||||
if ( individual.thumbUrl ) {
|
|
||||||
image = browseByVClass.baseUrl + individual.thumbUrl;
|
|
||||||
}
|
|
||||||
// Build the content of each list item, piecing together each component
|
|
||||||
listItem = '<li class="individual" role="listitem" role="navigation">';
|
|
||||||
if ( typeof individual.thumbUrl !== "undefined" ) {
|
|
||||||
listItem += '<img src="'+ image +'" width="90" alt="'+ label +'" /><h1 class="thumb">';
|
|
||||||
} else {
|
|
||||||
listItem += '<h1>';
|
|
||||||
}
|
|
||||||
listItem += '<a href="'+ profileUrl +'" title="View the profile page for '+ label +'">'+ label +'</a></h1>';
|
|
||||||
if ( moreInfo != '' ) {
|
|
||||||
listItem += '<span class="title">'+ moreInfo +'</span>';
|
|
||||||
}
|
|
||||||
listItem += '</li>';
|
|
||||||
individualList += listItem;
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Remove existing content
|
// Remove existing content
|
||||||
|
@ -158,32 +130,6 @@ var browseByVClass = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Handle mostSpecificType as array
|
|
||||||
// * remove requested class for redundancy
|
|
||||||
// * allow override by another property (passed as argument)
|
|
||||||
getMoreInfo: function(mostSpecificTypes, requestedClass, override) {
|
|
||||||
var requestedClassIndex = $.inArray(requestedClass, mostSpecificTypes);
|
|
||||||
if ( requestedClassIndex > -1 ) {
|
|
||||||
mostSpecificTypes.splice(requestedClassIndex, 1);
|
|
||||||
}
|
|
||||||
var mostSpecificTypeCount = mostSpecificTypes.length;
|
|
||||||
|
|
||||||
if ( typeof override !== "undefined" ) {
|
|
||||||
return override;
|
|
||||||
} else {
|
|
||||||
if ( mostSpecificTypeCount > 1 ) {
|
|
||||||
var assembledList = '<ul class="mostSpecificTypes">';
|
|
||||||
$.each(mostSpecificTypes, function(i, item) {
|
|
||||||
assembledList += '<li>'+ item +'</li>';
|
|
||||||
})
|
|
||||||
assembledList += '</ul>';
|
|
||||||
return assembledList;
|
|
||||||
} else {
|
|
||||||
return mostSpecificTypes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// getPageScroll() by quirksmode.org
|
// getPageScroll() by quirksmode.org
|
||||||
getPageScroll: function() {
|
getPageScroll: function() {
|
||||||
var xScroll, yScroll;
|
var xScroll, yScroll;
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||||
|
|
||||||
|
<#-- Default individual browse view -->
|
||||||
|
|
||||||
|
<#import "lib-properties.ftl" as p>
|
||||||
|
|
||||||
|
<li class="individual" role="listitem" role="navigation">
|
||||||
|
|
||||||
|
<#if (individual.thumbUrl)??>
|
||||||
|
<img src="${individual.thumbUrl}" width="90" alt="${individual.name}" />
|
||||||
|
<h1 class="thumb">
|
||||||
|
<a href="${individual.profileUrl}" title="View the profile page for ${individual.name}}">${individual.name}</a>
|
||||||
|
</h1>
|
||||||
|
<#else>
|
||||||
|
<h1>
|
||||||
|
<a href="${individual.profileUrl}" title="View the profile page for ${individual.name}}">${individual.name}</a>
|
||||||
|
</h1>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#assign typesString>
|
||||||
|
[<#list individual.mostSpecificTypes as type><#if type != vclass>,"${type}"</#if></#list>]
|
||||||
|
</#assign>
|
||||||
|
<#assign cleanTypes = typesString?replace("[,", "[")?eval >
|
||||||
|
|
||||||
|
<#if cleanTypes?size == 1>
|
||||||
|
<span class="title">${cleanTypes[0]}</span>
|
||||||
|
<#elseif (cleanTypes?size > 1) >
|
||||||
|
<span class="title">
|
||||||
|
<ul>
|
||||||
|
<#list cleanTypes as type>
|
||||||
|
<li>${type}</li>
|
||||||
|
</#list>
|
||||||
|
</ul>
|
||||||
|
</span>
|
||||||
|
</#if>
|
||||||
|
</li>
|
||||||
|
|
Loading…
Add table
Reference in a new issue