NIHVIVO-1322 Separated IndividualTemplateModel into two classes, one for profile page and one for listing individuals in the context of search, browse, menupages, etc. The needs of the two cases are quite different.

This commit is contained in:
rjy7 2011-01-13 15:09:27 +00:00
parent bdfca9c730
commit 5ea215f7e1
11 changed files with 140 additions and 52 deletions

View file

@ -50,16 +50,15 @@ import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission;
import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo;
import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep;
import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQuery;
import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryWrapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
import edu.cornell.mannlib.vitro.webapp.web.functions.IndividualLocalNameMethod;
import edu.cornell.mannlib.vitro.webapp.web.functions.IndividualProfileUrlMethod;
import edu.cornell.mannlib.vitro.webapp.web.jsptags.StringProcessorTag;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ListedIndividualTemplateModel;
import freemarker.ext.beans.BeansWrapper;
/**
@ -165,7 +164,7 @@ public class IndividualController extends FreemarkerHttpServlet {
if (relatedSubjectInd != null) {
map = new HashMap<String, Object>();
map.put("name", relatedSubjectInd.getName());
map.put("url", (new IndividualTemplateModel(relatedSubjectInd, vreq)).getProfileUrl());
map.put("url", (new ListedIndividualTemplateModel(relatedSubjectInd, vreq)).getProfileUrl());
String relatingPredicateUri = vreq.getParameter("relatingPredicateUri");
if (relatingPredicateUri != null) {
ObjectProperty relatingPredicateProp = opDao.getObjectPropertyByURI(relatingPredicateUri);

View file

@ -14,13 +14,13 @@ 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.EntityListController;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.TabEntitiesController.PageRecord;
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.utils.StringUtils;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ListedIndividualTemplateModel;
import freemarker.ext.beans.BeansWrapper;
import freemarker.template.TemplateModel;
@ -82,9 +82,9 @@ public class IndividualListController extends FreemarkerHttpServlet {
body.putAll(map);
List<Individual> inds = (List<Individual>)map.get("entities");
List<IndividualTemplateModel> indsTm = new ArrayList<IndividualTemplateModel>();
List<ListedIndividualTemplateModel> indsTm = new ArrayList<ListedIndividualTemplateModel>();
for(Individual ind : inds ){
indsTm.add(new IndividualTemplateModel(ind,vreq));
indsTm.add(new ListedIndividualTemplateModel(ind,vreq));
}
body.put("individuals", indsTm);

View file

@ -74,7 +74,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
import edu.cornell.mannlib.vitro.webapp.utils.Html2Text;
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.LinkTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ListedIndividualTemplateModel;
import freemarker.template.Configuration;
/**
@ -334,7 +334,7 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
}
// Convert search result individuals to template model objects
body.put("individuals", IndividualTemplateModel
body.put("individuals", ListedIndividualTemplateModel
.getIndividualTemplateModelList(beans, vreq));
body.put("querytext", qtxt);

View file

@ -155,9 +155,6 @@ public class PropertyEditLinks extends TagSupport{
if (data == null) { // link to add a new value
links = doObjProp( subjectUri, predicateUri, policyToAccess(ids, policy, subjectUri, predicateUri), contextPath );
} else { // links to edit or delete an existing value
// RY **** May need new policyToAccess which gets the specific obj prop statement using the data as well as subject and predicate
// This is NOT the correct object property statement - we need the link individual uri in data, instead of the link URL
// Then we can combine this with doObjPropStmt
ObjectPropertyStatement prop = new ObjectPropertyStatementImpl(subjectUri, predicateUri, data);
links = doObjPropStmt( prop, policyToAccess(ids, policy, prop), contextPath );
}

View file

@ -32,13 +32,6 @@ public class IndividualTemplateModel extends BaseTemplateModel {
protected GroupedPropertyList propertyList = null;
protected LoginStatusBean loginStatusBean = null;
private EditingPolicyHelper policyHelper = null;
public IndividualTemplateModel(Individual individual, VitroRequest vreq) {
this.individual = individual;
this.vreq = vreq;
// Needed for getting portal-sensitive urls. Remove if multi-portal support is removed.
this.urlBuilder = new UrlBuilder(vreq.getPortal());
}
public IndividualTemplateModel(Individual individual, VitroRequest vreq, LoginStatusBean loginStatusBean) {
this.individual = individual;
@ -114,19 +107,6 @@ public class IndividualTemplateModel extends BaseTemplateModel {
return individual.isVClass("http://xmlns.com/foaf/0.1/Organization");
}
public String getSearchView() {
return getView(ClassView.SEARCH);
}
public String getDisplayView() {
return getView(ClassView.DISPLAY);
}
private String getView(ClassView view) {
ViewFinder vf = new ViewFinder(view);
return vf.findClassView(individual, vreq);
}
public Link getPrimaryLink() {
Link primaryLink = null;
String anchor = individual.getAnchor();
@ -139,8 +119,12 @@ public class IndividualTemplateModel extends BaseTemplateModel {
return primaryLink;
}
public List<Link> getAdditionalLinks() {
return individual.getLinksList();
}
public List<Link> getLinks() {
List<Link> additionalLinks = individual.getLinksList();
List<Link> additionalLinks = getAdditionalLinks();
List<Link> links = new ArrayList<Link>(additionalLinks.size()+1);
Link primaryLink = getPrimaryLink();
if (primaryLink != null) {
@ -150,14 +134,6 @@ public class IndividualTemplateModel extends BaseTemplateModel {
return links;
}
public static List<IndividualTemplateModel> getIndividualTemplateModelList(List<Individual> individuals, VitroRequest vreq) {
List<IndividualTemplateModel> models = new ArrayList<IndividualTemplateModel>(individuals.size());
for (Individual individual : individuals) {
models.add(new IndividualTemplateModel(individual, vreq));
}
return models;
}
public GroupedPropertyList getPropertyList() {
if (propertyList == null) {
propertyList = new GroupedPropertyList(individual, vreq, policyHelper);

View file

@ -0,0 +1,104 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
import java.util.ArrayList;
import java.util.List;
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.beans.Link;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
import edu.cornell.mannlib.vitro.webapp.web.ViewFinder;
import edu.cornell.mannlib.vitro.webapp.web.ViewFinder.ClassView;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
public class ListedIndividualTemplateModel extends BaseTemplateModel {
private static final Log log = LogFactory.getLog(ListedIndividualTemplateModel.class);
private static final String PATH = Route.INDIVIDUAL.path();
protected Individual individual;
protected VitroRequest vreq;
protected UrlBuilder urlBuilder;
public ListedIndividualTemplateModel(Individual individual, VitroRequest vreq) {
this.individual = individual;
this.vreq = vreq;
// Needed for getting portal-sensitive urls. Remove if multi-portal support is removed.
this.urlBuilder = new UrlBuilder(vreq.getPortal());
}
public static List<ListedIndividualTemplateModel> getIndividualTemplateModelList(List<Individual> individuals, VitroRequest vreq) {
List<ListedIndividualTemplateModel> models = new ArrayList<ListedIndividualTemplateModel>(individuals.size());
for (Individual individual : individuals) {
models.add(new ListedIndividualTemplateModel(individual, vreq));
}
return models;
}
/* Access methods for templates */
public String getProfileUrl() {
return UrlBuilder.getIndividualProfileUrl(individual, vreq.getWebappDaoFactory());
}
public Link getPrimaryLink() {
Link primaryLink = null;
String anchor = individual.getAnchor();
String url = individual.getUrl();
if (anchor != null && url != null) {
primaryLink = new Link();
primaryLink.setAnchor(individual.getAnchor());
primaryLink.setUrl(individual.getUrl());
}
return primaryLink;
}
public List<Link> getAdditionalLinks() {
return individual.getLinksList();
}
public List<Link> getLinks() {
List<Link> additionalLinks = getAdditionalLinks();
List<Link> links = new ArrayList<Link>(additionalLinks.size()+1);
Link primaryLink = getPrimaryLink();
if (primaryLink != null) {
links.add(primaryLink);
}
links.addAll(additionalLinks);
return links;
}
public String getName() {
return individual.getName();
}
public String getMoniker() {
return individual.getMoniker();
}
public String getUri() {
return individual.getURI();
}
public String getSearchView() {
return getView(ClassView.SEARCH);
}
public String getDisplayView() {
return getView(ClassView.DISPLAY);
}
private String getView(ClassView view) {
ViewFinder vf = new ViewFinder(view);
return vf.findClassView(individual, vreq);
}
}

View file

@ -21,7 +21,7 @@ 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.VClassTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ListedIndividualTemplateModel;
import freemarker.core.Environment;
import freemarker.template.TemplateModelException;
@ -125,9 +125,9 @@ public class BrowseWidget extends Widget {
List<Individual> inds = vreq.getWebappDaoFactory().getIndividualDao()
.getIndividualsByVClass(vclass);
List<IndividualTemplateModel> tInds = new ArrayList<IndividualTemplateModel>(inds.size());
List<ListedIndividualTemplateModel> tInds = new ArrayList<ListedIndividualTemplateModel>(inds.size());
for( Individual ind : inds){
tInds.add(new IndividualTemplateModel(ind, vreq));
tInds.add(new ListedIndividualTemplateModel(ind, vreq));
}
map.put("individualsInClass", tInds);