Changing VClassGroupCache to not filter out groups and classes with no individuals as part of NIHVIVO-1666 Fixing URLs in browse widget as part of NIHVIVO-592
This commit is contained in:
parent
dea0385806
commit
b024863f42
8 changed files with 277 additions and 146 deletions
|
@ -23,6 +23,19 @@ public class VClassGroup extends LinkedList <VClass> implements Comparable<VClas
|
||||||
private String localName = null;
|
private String localName = null;
|
||||||
private String publicName = null;
|
private String publicName = null;
|
||||||
private int displayRank = -1;
|
private int displayRank = -1;
|
||||||
|
private int individualCount = -1;
|
||||||
|
|
||||||
|
public boolean isIndividualCountSet(){
|
||||||
|
return individualCount >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndividualCount() {
|
||||||
|
return individualCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndividualCount(int individualCount) {
|
||||||
|
this.individualCount = individualCount;
|
||||||
|
}
|
||||||
|
|
||||||
public int getDisplayRank() {
|
public int getDisplayRank() {
|
||||||
return displayRank;
|
return displayRank;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -77,11 +78,57 @@ public class JSONServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getLuceneIndividualsByVClass(HttpServletRequest req, HttpServletResponse resp) {
|
private void getLuceneIndividualsByVClass( HttpServletRequest req, HttpServletResponse resp ){
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(req);
|
|
||||||
String errorMessage = null;
|
String errorMessage = null;
|
||||||
String message = null;
|
JSONObject rObj = null;
|
||||||
|
try{
|
||||||
|
VitroRequest vreq = new VitroRequest(req);
|
||||||
|
VClass vclass=null;
|
||||||
|
|
||||||
|
|
||||||
|
String vitroClassIdStr = vreq.getParameter("vclassId");
|
||||||
|
if ( vitroClassIdStr != null && !vitroClassIdStr.isEmpty()){
|
||||||
|
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr);
|
||||||
|
if (vclass == null) {
|
||||||
|
log.debug("Couldn't retrieve vclass ");
|
||||||
|
throw new Exception (errorMessage = "Class " + vitroClassIdStr + " not found");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
log.debug("parameter vclassId URI parameter expected ");
|
||||||
|
throw new Exception("parameter vclassId URI parameter expected ");
|
||||||
|
}
|
||||||
|
rObj = getLuceneIndividualsByVClass(vclass.getURI(),req,resp,getServletContext());
|
||||||
|
}catch(Exception ex){
|
||||||
|
errorMessage = ex.toString();
|
||||||
|
log.error(ex,ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( rObj == null )
|
||||||
|
rObj = new JSONObject();
|
||||||
|
|
||||||
|
try{
|
||||||
|
resp.setCharacterEncoding("UTF-8");
|
||||||
|
resp.setContentType("application/json;charset=UTF-8");
|
||||||
|
|
||||||
|
if( errorMessage != null ){
|
||||||
|
rObj.put("errorMessage", errorMessage);
|
||||||
|
resp.setStatus(500 /*HttpURLConnection.HTTP_SERVER_ERROR*/);
|
||||||
|
}else{
|
||||||
|
rObj.put("errorMessage", "");
|
||||||
|
}
|
||||||
|
Writer writer = resp.getWriter();
|
||||||
|
writer.write(rObj.toString());
|
||||||
|
}catch(JSONException jse){
|
||||||
|
log.error(jse,jse);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e,e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static JSONObject getLuceneIndividualsByVClass(String vclassURI, HttpServletRequest req, HttpServletResponse resp, ServletContext context) throws Exception {
|
||||||
|
|
||||||
|
VitroRequest vreq = new VitroRequest(req);
|
||||||
VClass vclass=null;
|
VClass vclass=null;
|
||||||
JSONObject rObj = new JSONObject();
|
JSONObject rObj = new JSONObject();
|
||||||
|
|
||||||
|
@ -109,111 +156,90 @@ public class JSONServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
//need an unfiltered dao to get firstnames and lastnames
|
//need an unfiltered dao to get firstnames and lastnames
|
||||||
WebappDaoFactory fullWdf = vreq.getFullWebappDaoFactory();
|
WebappDaoFactory fullWdf = vreq.getFullWebappDaoFactory();
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
String vitroClassIdStr = vreq.getParameter("vclassId");
|
|
||||||
if ( vitroClassIdStr != null && !vitroClassIdStr.isEmpty()){
|
|
||||||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr);
|
|
||||||
if (vclass == null) {
|
|
||||||
log.debug("Couldn't retrieve vclass ");
|
|
||||||
throw new Exception (errorMessage = "Class " + vitroClassIdStr + " not found");
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
log.debug("parameter vclassId URI parameter expected ");
|
|
||||||
throw new Exception("parameter vclassId URI parameter expected ");
|
|
||||||
}
|
|
||||||
|
|
||||||
rObj.put("vclass",
|
|
||||||
new JSONObject().put("URI",vclass.getURI())
|
|
||||||
.put("name",vclass.getName()));
|
|
||||||
|
|
||||||
if (vclass != null) {
|
|
||||||
String alpha = EntityListController.getAlphaParamter(vreq);
|
|
||||||
int page = EntityListController.getPageParameter(vreq);
|
|
||||||
Map<String,Object> map = EntityListController.getResultsForVClass(
|
|
||||||
vclass.getURI(),
|
|
||||||
page,
|
|
||||||
alpha,
|
|
||||||
vreq.getPortal(),
|
|
||||||
vreq.getWebappDaoFactory().getPortalDao().isSinglePortal(),
|
|
||||||
vreq.getWebappDaoFactory().getIndividualDao(),
|
|
||||||
getServletContext());
|
|
||||||
|
|
||||||
rObj.put("totalCount", map.get("totalCount"));
|
|
||||||
rObj.put("alpha", map.get("alpha"));
|
String vitroClassIdStr = vreq.getParameter("vclassId");
|
||||||
|
if ( vitroClassIdStr != null && !vitroClassIdStr.isEmpty()){
|
||||||
List<Individual> inds = (List<Individual>)map.get("entities");
|
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr);
|
||||||
List<IndividualTemplateModel> indsTm = new ArrayList<IndividualTemplateModel>();
|
if (vclass == null) {
|
||||||
JSONArray jInds = new JSONArray();
|
log.debug("Couldn't retrieve vclass ");
|
||||||
for(Individual ind : inds ){
|
throw new Exception ("Class " + vitroClassIdStr + " not found");
|
||||||
JSONObject jo = new JSONObject();
|
}
|
||||||
jo.put("URI", ind.getURI());
|
}else{
|
||||||
jo.put("label",ind.getRdfsLabel());
|
log.debug("parameter vclassId URI parameter expected ");
|
||||||
jo.put("name",ind.getName());
|
throw new Exception("parameter vclassId URI parameter expected ");
|
||||||
jo.put("thumbUrl", ind.getThumbUrl());
|
|
||||||
jo.put("imageUrl", ind.getImageUrl());
|
|
||||||
jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq.getWebappDaoFactory()));
|
|
||||||
|
|
||||||
String moniker = getDataPropertyValue(ind, monikerDp, fullWdf);
|
|
||||||
jo.put("moniker", moniker);
|
|
||||||
jo.put("vclassName", getVClassName(ind,moniker,fullWdf));
|
|
||||||
|
|
||||||
jo.put("perferredTitle", getDataPropertyValue(ind, perferredTitleDp, fullWdf));
|
|
||||||
jo.put("firstName", getDataPropertyValue(ind, fNameDp, fullWdf));
|
|
||||||
jo.put("lastName", getDataPropertyValue(ind, lNameDp, fullWdf));
|
|
||||||
|
|
||||||
jInds.put(jo);
|
|
||||||
}
|
|
||||||
rObj.put("individuals", jInds);
|
|
||||||
|
|
||||||
JSONArray wpages = new JSONArray();
|
|
||||||
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){
|
|
||||||
errorMessage = ex.getMessage();
|
|
||||||
}
|
|
||||||
try{
|
|
||||||
resp.setCharacterEncoding("UTF-8");
|
|
||||||
resp.setContentType("application/json;charset=UTF-8");
|
|
||||||
|
|
||||||
if( errorMessage != null ){
|
|
||||||
rObj.put("errorMessage", errorMessage);
|
|
||||||
resp.setStatus(500 /*HttpURLConnection.HTTP_SERVER_ERROR*/);
|
|
||||||
}else{
|
|
||||||
rObj.put("errorMessage", "");
|
|
||||||
}
|
|
||||||
Writer writer = resp.getWriter();
|
|
||||||
writer.write(rObj.toString());
|
|
||||||
}catch(JSONException jse){
|
|
||||||
log.error(jse,jse);
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e,e);
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
|
rObj.put("vclass",
|
||||||
|
new JSONObject().put("URI",vclass.getURI())
|
||||||
|
.put("name",vclass.getName()));
|
||||||
|
|
||||||
|
if (vclass != null) {
|
||||||
|
String alpha = EntityListController.getAlphaParamter(vreq);
|
||||||
|
int page = EntityListController.getPageParameter(vreq);
|
||||||
|
Map<String,Object> map = EntityListController.getResultsForVClass(
|
||||||
|
vclass.getURI(),
|
||||||
|
page,
|
||||||
|
alpha,
|
||||||
|
vreq.getPortal(),
|
||||||
|
vreq.getWebappDaoFactory().getPortalDao().isSinglePortal(),
|
||||||
|
vreq.getWebappDaoFactory().getIndividualDao(),
|
||||||
|
context);
|
||||||
|
|
||||||
|
rObj.put("totalCount", map.get("totalCount"));
|
||||||
|
rObj.put("alpha", map.get("alpha"));
|
||||||
|
|
||||||
|
List<Individual> inds = (List<Individual>)map.get("entities");
|
||||||
|
List<IndividualTemplateModel> indsTm = new ArrayList<IndividualTemplateModel>();
|
||||||
|
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.getWebappDaoFactory()));
|
||||||
|
|
||||||
|
String moniker = getDataPropertyValue(ind, monikerDp, fullWdf);
|
||||||
|
jo.put("moniker", moniker);
|
||||||
|
jo.put("vclassName", getVClassName(ind,moniker,fullWdf));
|
||||||
|
|
||||||
|
jo.put("perferredTitle", getDataPropertyValue(ind, perferredTitleDp, fullWdf));
|
||||||
|
jo.put("firstName", getDataPropertyValue(ind, fNameDp, fullWdf));
|
||||||
|
jo.put("lastName", getDataPropertyValue(ind, lNameDp, fullWdf));
|
||||||
|
|
||||||
|
jInds.put(jo);
|
||||||
|
}
|
||||||
|
rObj.put("individuals", jInds);
|
||||||
|
|
||||||
|
JSONArray wpages = new JSONArray();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String getVClassName(Individual ind, String moniker,
|
private static String getVClassName(Individual ind, String moniker,
|
||||||
WebappDaoFactory fullWdf) {
|
WebappDaoFactory fullWdf) {
|
||||||
/* so the moniker frequently has a vclass name in it. Try to return
|
/* so the moniker frequently has a vclass name in it. Try to return
|
||||||
* the vclass name that is the same as the moniker so that the templates
|
* the vclass name that is the same as the moniker so that the templates
|
||||||
|
@ -239,7 +265,7 @@ public class JSONServlet extends VitroHttpServlet {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
String getDataPropertyValue(Individual ind, DataProperty dp, WebappDaoFactory wdf){
|
static String getDataPropertyValue(Individual ind, DataProperty dp, WebappDaoFactory wdf){
|
||||||
List<Literal> values = wdf.getDataPropertyStatementDao()
|
List<Literal> values = wdf.getDataPropertyStatementDao()
|
||||||
.getDataPropertyValuesForIndividualByProperty(ind, dp);
|
.getDataPropertyValuesForIndividualByProperty(ind, dp);
|
||||||
if( values == null || values.isEmpty() )
|
if( values == null || values.isEmpty() )
|
||||||
|
|
|
@ -79,6 +79,20 @@ public class VClassGroupCache implements ServletContextListener{
|
||||||
return getGroups(getVCGDao(),portalId );
|
return getGroups(getVCGDao(),portalId );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* May return null.
|
||||||
|
*/
|
||||||
|
public VClassGroup getGroup( int portalId, String vClassGroupURI ){
|
||||||
|
if( vClassGroupURI == null || vClassGroupURI.isEmpty() )
|
||||||
|
return null;
|
||||||
|
List<VClassGroup> cgList = getGroups(portalId);
|
||||||
|
for( VClassGroup cg : cgList ){
|
||||||
|
if( vClassGroupURI.equals( cg.getURI()))
|
||||||
|
return cg;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void clearGroupCache(){
|
public void clearGroupCache(){
|
||||||
_groupListMap = new ConcurrentHashMap<Integer, List<VClassGroup>>();
|
_groupListMap = new ConcurrentHashMap<Integer, List<VClassGroup>>();
|
||||||
}
|
}
|
||||||
|
@ -90,13 +104,13 @@ public class VClassGroupCache implements ServletContextListener{
|
||||||
log.debug("needed to build vclassGroups for portal " + portalId);
|
log.debug("needed to build vclassGroups for portal " + portalId);
|
||||||
// Get all classgroups, each populated with a list of their member vclasses
|
// Get all classgroups, each populated with a list of their member vclasses
|
||||||
List<VClassGroup> groups =
|
List<VClassGroup> groups =
|
||||||
vcgDao.getPublicGroupsWithVClasses(ORDER_BY_DISPLAYRANK, !INCLUDE_UNINSTANTIATED, includeIndividualCount);
|
vcgDao.getPublicGroupsWithVClasses(ORDER_BY_DISPLAYRANK, INCLUDE_UNINSTANTIATED, includeIndividualCount);
|
||||||
|
|
||||||
// remove classes that have been configured to be hidden from search results
|
// remove classes that have been configured to be hidden from search results
|
||||||
vcgDao.removeClassesHiddenFromSearch(groups);
|
vcgDao.removeClassesHiddenFromSearch(groups);
|
||||||
|
|
||||||
// now cull out the groups with no populated classes
|
// now cull out the groups with no populated classes
|
||||||
vcgDao.removeUnpopulatedGroups(groups);
|
//vcgDao.removeUnpopulatedGroups(groups);
|
||||||
|
|
||||||
return groups;
|
return groups;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -158,9 +158,13 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (groups.size()>0) {
|
if (groups.size()>0) {
|
||||||
|
if( getIndividualCount )
|
||||||
|
addIndividualCountToGroups(groups);
|
||||||
return groups;
|
return groups;
|
||||||
} else {
|
} else {
|
||||||
classDao.addVClassesToGroups(groups);
|
classDao.addVClassesToGroups(groups);
|
||||||
|
if( getIndividualCount )
|
||||||
|
addIndividualCountToGroups(groups);
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -169,6 +173,16 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addIndividualCountToGroups( List<VClassGroup> cgList ){
|
||||||
|
for( VClassGroup cg : cgList){
|
||||||
|
int count = 0;
|
||||||
|
for( VClass vc : cg){
|
||||||
|
count = count + vc.getEntityCount();
|
||||||
|
}
|
||||||
|
cg.setIndividualCount(count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public VClassGroup groupFromGroupIndividual(Individual groupInd) {
|
public VClassGroup groupFromGroupIndividual(Individual groupInd) {
|
||||||
if (groupInd==null) {
|
if (groupInd==null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -16,6 +16,7 @@ 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.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;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This will pass these variables to the template:
|
* This will pass these variables to the template:
|
||||||
|
@ -67,12 +68,51 @@ public class ClassGroupPageData implements PageDataGetter{
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static VClassGroupTemplateModel getClassGroup(String classGroupUri, ServletContext context, VitroRequest vreq){
|
||||||
|
|
||||||
|
VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(context);
|
||||||
|
List<VClassGroup> vcgList = vcgc.getGroups(vreq.getPortalId());
|
||||||
|
VClassGroup group = null;
|
||||||
|
for( VClassGroup vcg : vcgList){
|
||||||
|
if( vcg.getURI() != null && vcg.getURI().equals(classGroupUri)){
|
||||||
|
group = vcg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( classGroupUri != null && !classGroupUri.isEmpty() && group == null ){
|
||||||
|
/*This could be for two reasons: one is that the classgroup doesn't exist
|
||||||
|
* The other is that there are no individuals in any of the classgroup's classes */
|
||||||
|
group = vreq.getWebappDaoFactory().getVClassGroupDao().getGroupByURI(classGroupUri);
|
||||||
|
if( group != null ){
|
||||||
|
List<VClassGroup> vcgFullList = vreq.getWebappDaoFactory().getVClassGroupDao()
|
||||||
|
.getPublicGroupsWithVClasses(false, true, false);
|
||||||
|
for( VClassGroup vcg : vcgFullList ){
|
||||||
|
if( classGroupUri.equals(vcg.getURI()) ){
|
||||||
|
group = vcg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( group == null ){
|
||||||
|
log.error("Cannot get classgroup '" + classGroupUri + "'");
|
||||||
|
return null;
|
||||||
|
}else{
|
||||||
|
setAllClassCountsToZero(group);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
log.error("classgroup " + classGroupUri + " does not exist in the system");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new VClassGroupTemplateModel(group);
|
||||||
|
}
|
||||||
|
|
||||||
public String getType(){
|
public String getType(){
|
||||||
return DisplayVocabulary.CLASSGROUP_PAGE_TYPE;
|
return DisplayVocabulary.CLASSGROUP_PAGE_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setAllClassCountsToZero(VClassGroup vcg){
|
protected static void setAllClassCountsToZero(VClassGroup vcg){
|
||||||
for(VClass vc : vcg){
|
for(VClass vc : vcg){
|
||||||
vc.setEntityCount(0);
|
vc.setEntityCount(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,4 +54,16 @@ public class VClassGroupTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getIndividualCount(){
|
||||||
|
if( vClassGroup.isIndividualCountSet() )
|
||||||
|
return Integer.toString(vClassGroup.getIndividualCount());
|
||||||
|
else
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIndividualCountSet(){
|
||||||
|
return vClassGroup.isIndividualCountSet();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,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.dao.jena.VClassGroupCache;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateModel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassTemplateModel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||||
|
@ -61,7 +62,7 @@ public class BrowseWidget extends Widget {
|
||||||
|
|
||||||
protected WidgetTemplateValues doAllClassGroupsDisplay(Environment env, Map params,
|
protected WidgetTemplateValues doAllClassGroupsDisplay(Environment env, Map params,
|
||||||
HttpServletRequest request, ServletContext context) {
|
HttpServletRequest request, ServletContext context) {
|
||||||
Map<String,Object> body = getAllClassGroupData(request, params);
|
Map<String,Object> body = getAllClassGroupData(request, params, context);
|
||||||
try {
|
try {
|
||||||
body.put("urls",env.getDataModel().get("urls"));
|
body.put("urls",env.getDataModel().get("urls"));
|
||||||
body.put("currentPage", env.getDataModel().get("currentPage"));
|
body.put("currentPage", env.getDataModel().get("currentPage"));
|
||||||
|
@ -73,29 +74,36 @@ public class BrowseWidget extends Widget {
|
||||||
return new WidgetTemplateValues(macroName, body);
|
return new WidgetTemplateValues(macroName, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String,Object> getAllClassGroupData(HttpServletRequest request, Map params){
|
/**
|
||||||
|
* Gets a list of all VClassGroups with vclasses with individual counts.
|
||||||
|
*/
|
||||||
|
protected Map<String,Object> getAllClassGroupData(HttpServletRequest request, Map params, ServletContext context){
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,Object> map = new HashMap<String,Object>();
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
List<VClassGroup> classGroups =
|
|
||||||
vreq.getWebappDaoFactory().getVClassGroupDao().getPublicGroupsWithVClasses();
|
|
||||||
|
|
||||||
LinkedList<VClassGroupTemplateModel> cgList = new LinkedList<VClassGroupTemplateModel>();
|
VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(context);
|
||||||
for( VClassGroup classGroup : classGroups){
|
List<VClassGroup> cgList = vcgc.getGroups(vreq.getPortalId());
|
||||||
cgList.add( new VClassGroupTemplateModel( classGroup ));
|
|
||||||
|
// List<VClassGroup> classGroups =
|
||||||
|
// vreq.getWebappDaoFactory().getVClassGroupDao().getPublicGroupsWithVClasses();
|
||||||
|
//
|
||||||
|
LinkedList<VClassGroupTemplateModel> cgtmList = new LinkedList<VClassGroupTemplateModel>();
|
||||||
|
for( VClassGroup classGroup : cgList){
|
||||||
|
cgtmList.add( new VClassGroupTemplateModel( classGroup ));
|
||||||
}
|
}
|
||||||
map.put("vclassGroupList",cgList);
|
map.put("vclassGroupList",cgtmList);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected WidgetTemplateValues doClassDisplay(Environment env, Map params,
|
protected WidgetTemplateValues doClassDisplay(Environment env, Map params,
|
||||||
HttpServletRequest request, ServletContext context) {
|
HttpServletRequest request, ServletContext context) {
|
||||||
|
|
||||||
Map<String,Object> body = getClassData(request,params);
|
Map<String,Object> body = getClassData(request,params,context);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
body.put("urls",env.getDataModel().get("urls"));
|
body.put("urls",env.getDataModel().get("urls"));
|
||||||
body.put("urlMapping",env.getDataModel().get("urlMapping"));
|
body.put("currentPage", env.getDataModel().get("currentPage"));
|
||||||
} catch (TemplateModelException e) {
|
} catch (TemplateModelException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -104,10 +112,10 @@ public class BrowseWidget extends Widget {
|
||||||
return new WidgetTemplateValues(macroName, body);
|
return new WidgetTemplateValues(macroName, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> getClassData(HttpServletRequest request, Map params) {
|
private Map<String, Object> getClassData(HttpServletRequest request, Map params, ServletContext context) {
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,Object> map = new HashMap<String,Object>();
|
||||||
|
|
||||||
map.putAll(getClassGroupData(request, params));
|
map.putAll(getClassGroupData(request, params,context));
|
||||||
|
|
||||||
String classUri = getParam(Mode.VCLASS, request, params);
|
String classUri = getParam(Mode.VCLASS, request, params);
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
|
@ -129,11 +137,11 @@ public class BrowseWidget extends Widget {
|
||||||
protected WidgetTemplateValues doClassGroupDisplay(Environment env,
|
protected WidgetTemplateValues doClassGroupDisplay(Environment env,
|
||||||
Map params, HttpServletRequest request, ServletContext context) {
|
Map params, HttpServletRequest request, ServletContext context) {
|
||||||
|
|
||||||
Map<String,Object> body = getClassGroupData(request,params);
|
Map<String,Object> body = getClassGroupData(request,params, context);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
body.put("urls",env.getDataModel().get("urls"));
|
body.put("urls",env.getDataModel().get("urls"));
|
||||||
body.put("urlMapping",env.getDataModel().get("urlMapping"));
|
body.put("currentPage", env.getDataModel().get("currentPage"));
|
||||||
} catch (TemplateModelException e) {
|
} catch (TemplateModelException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -142,14 +150,17 @@ public class BrowseWidget extends Widget {
|
||||||
return new WidgetTemplateValues(macroName, body);
|
return new WidgetTemplateValues(macroName, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String, Object> getClassGroupData(HttpServletRequest request, Map params) {
|
protected Map<String, Object> getClassGroupData(HttpServletRequest request, Map params, ServletContext context) {
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,Object> map = new HashMap<String,Object>();
|
||||||
|
|
||||||
String vcgName = getParam(Mode.CLASS_GROUP, request, params);
|
String vcgUri = getParam(Mode.CLASS_GROUP, request, params);
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
VClassGroup vcg = vreq.getWebappDaoFactory().getVClassGroupDao().getGroupByName(vcgName);
|
//VClassGroup vcg = vreq.getWebappDaoFactory().getVClassGroupDao().getGroupByURI(vcgUri);
|
||||||
|
|
||||||
vreq.getWebappDaoFactory().getVClassDao().addVClassesToGroup(vcg, false, true);
|
VClassGroupCache vcgc = VClassGroupCache.getVClassGroupCache(context);
|
||||||
|
VClassGroup vcg = vcgc.getGroup(vreq.getPortalId(), vcgUri);
|
||||||
|
|
||||||
|
//vreq.getWebappDaoFactory().getVClassDao().addVClassesToGroup(vcg, false, true);
|
||||||
ArrayList<VClassTemplateModel> classes = new ArrayList<VClassTemplateModel>(vcg.size());
|
ArrayList<VClassTemplateModel> classes = new ArrayList<VClassTemplateModel>(vcg.size());
|
||||||
for( VClass vc : vcg){
|
for( VClass vc : vcg){
|
||||||
classes.add(new VClassTemplateModel(vc));
|
classes.add(new VClassTemplateModel(vc));
|
||||||
|
@ -157,7 +168,7 @@ public class BrowseWidget extends Widget {
|
||||||
map.put("classes", classes);
|
map.put("classes", classes);
|
||||||
|
|
||||||
map.put("classGroup", new VClassGroupTemplateModel(vcg));
|
map.put("classGroup", new VClassGroupTemplateModel(vcg));
|
||||||
map.put("classGroupName", vcgName);
|
map.put("classGroupName", vcg.getPublicName());
|
||||||
map.put("classGroupUri", vcg.getURI());
|
map.put("classGroupUri", vcg.getURI());
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
|
@ -166,7 +177,7 @@ public class BrowseWidget extends Widget {
|
||||||
enum Mode{
|
enum Mode{
|
||||||
VCLASS_ALPHA("vclassAlpha","vclassAlpha"),
|
VCLASS_ALPHA("vclassAlpha","vclassAlpha"),
|
||||||
VCLASS("vclass","vclassUri"),
|
VCLASS("vclass","vclassUri"),
|
||||||
CLASS_GROUP("classGroup","classGroup"),
|
CLASS_GROUP("classGroup","classgroupUri"),
|
||||||
ALL_CLASS_GROUPS("allClassGroups","all");
|
ALL_CLASS_GROUPS("allClassGroups","all");
|
||||||
|
|
||||||
String macroName;
|
String macroName;
|
||||||
|
|
|
@ -16,41 +16,41 @@
|
||||||
|
|
||||||
<ul id="browse-classgroups" role="list">
|
<ul id="browse-classgroups" role="list">
|
||||||
<#list vclassGroupList as group>
|
<#list vclassGroupList as group>
|
||||||
<li role="listitem"><a href="${urls.base}/${currentPage}?classgroupUri=${group.publicName?url}">${group.publicName} <span class="count-classes">(n)</span></a></li>
|
<li role="listitem"><a href="${urls.base}/${currentPage}?classgroupUri=${group.uri?url}">${group.publicName} <span class="count-classes">(n)</span></a></li>
|
||||||
</#list>
|
</#list>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
<#macro classGroup>
|
<#macro classGroup>
|
||||||
<section>
|
<section id="browse" role="region">
|
||||||
<#--<h2>Macro classGroup from widget-browse.ftl</h2>
|
<h4>Browse</h4>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
There are ${classes?size} classes in classGroup ${classGroup.publicName}.
|
There are ${classes?size} classes in classGroup ${classGroup.publicName}.
|
||||||
Only classes with instances are included.
|
There are ${classGroup.individualCount} individuals in the class group.
|
||||||
</div>-->
|
Classes with and without instances are included.
|
||||||
|
</div>-
|
||||||
|
|
||||||
<nav role="navigation">
|
<nav role="navigation">
|
||||||
<ul id="foaf-person-childClasses">
|
<ul id="foaf-person-childClasses">
|
||||||
<#list classes as class>
|
<#list classes as class>
|
||||||
<li><a href="${urls.base}/${currentPage}?classgroupUri=${classGroup.publicName?url}&vclassUri=${class.uri?url}">${class.name}<span class="count-classes"> ${class.individualCount}</span></a></li>
|
<li><a href="${urls.base}/${currentPage}?classgroupUri=${classGroup.uri?url}&vclassUri=${class.uri?url}">${class.name}<span class="count-classes"> ${class.individualCount}</span></a></li>
|
||||||
</#list>
|
</#list>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<#--<ul>
|
|
||||||
<#list classes as class>
|
|
||||||
<li><a href="${urls.base}/${currentPage}?classgroupUri=${classGroup.publicName?url}&vclassUri=${class.uri?url}">${class.name}</a> ${class.individualCount}</li>
|
|
||||||
</#list>
|
|
||||||
</ul>-->
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
<#macro vclass>
|
<#macro vclass>
|
||||||
<section>
|
<section id="browse" role="region">
|
||||||
<h2>vclass ${class.name} from ${classGroup.publicName}</h2>
|
<h4>Browse</h4>
|
||||||
This has classGroup, classes, individualsInClass and class.
|
<div>
|
||||||
|
vclass ${class.name} from ${classGroup.publicName}
|
||||||
|
This has classGroup, classes, individualsInClass and class.
|
||||||
|
</div>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<#list individualsInClass as ind>
|
<#list individualsInClass as ind>
|
||||||
|
@ -60,7 +60,8 @@
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
<#macro vclassAlpha>
|
<#macro vclassAlpha>
|
||||||
<section role="region">
|
<section id="browse" role="region">
|
||||||
<h2>vclassAlpha</h2>
|
<h4>Browse</h4>
|
||||||
|
<div>vclassAlpha is not yet implemented.</div>
|
||||||
</section>
|
</section>
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue