diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualController.java index e3b8d6f85..da2bca154 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualController.java @@ -30,7 +30,6 @@ import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDFS; -import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.Individual; @@ -47,17 +46,15 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Res import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao; +import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; 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.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.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; @@ -135,7 +132,7 @@ public class IndividualController extends FreemarkerHttpServlet { body.put("headContent", getRdfLinkTag(itm)); body.put("localName", new IndividualLocalNameMethod()); - String template = getIndividualTemplate(individual); + String template = getIndividualTemplate(individual, vreq); return new TemplateResponseValues(template, body); @@ -205,35 +202,37 @@ public class IndividualController extends FreemarkerHttpServlet { // Determine whether the individual has a custom display template based on its class membership. // If not, return the default individual template. - private String getIndividualTemplate(Individual individual) { + private String getIndividualTemplate(Individual individual, VitroRequest vreq) { @SuppressWarnings("unused") String vclassName = "unknown"; String customTemplate = null; - if( individual.getVClass() != null ){ + // First check vclass + if( individual.getVClass() != null ){ vclassName = individual.getVClass().getName(); - List clasList = individual.getVClasses(true); - for (VClass clas : clasList) { - customTemplate = clas.getCustomDisplayView(); + List directClasses = individual.getVClasses(true); + for (VClass vclass : directClasses) { + customTemplate = vclass.getCustomDisplayView(); if (customTemplate != null) { if (customTemplate.length()>0) { - vclassName = clas.getName(); // reset entity vclassname to name of class where a custom view; this call has side-effects - log.debug("Found direct class [" + clas.getName() + "] with custom view " + customTemplate + "; resetting entity vclassName to this class"); + vclassName = vclass.getName(); // reset entity vclassname to name of class where a custom view; this call has side-effects + log.debug("Found direct class [" + vclass.getName() + "] with custom view " + customTemplate + "; resetting entity vclassName to this class"); break; } else { customTemplate = null; } } } - if (customTemplate == null) { //still - clasList = individual.getVClasses(false); - for (VClass clas : clasList) { - customTemplate = clas.getCustomDisplayView(); + // If no custom template defined, check other vclasses + if (customTemplate == null) { + List inferredClasses = individual.getVClasses(false); + for (VClass vclass : inferredClasses) { + customTemplate = vclass.getCustomDisplayView(); if (customTemplate != null) { if (customTemplate.length()>0) { // note that NOT changing entity vclassName here yet - log.debug("Found inferred class [" + clas.getName() + "] with custom view " + customTemplate); + log.debug("Found inferred class [" + vclass.getName() + "] with custom view " + customTemplate); break; } else { customTemplate = null; @@ -241,6 +240,28 @@ public class IndividualController extends FreemarkerHttpServlet { } } } + // If still no custom template defined, and inferencing is asynchronous (under RDB), check + // superclasses of the vclass. + // The method to check for asynchronous inferencing will be added later; see NIHVIVO-1834. + if (customTemplate == null) { //&& inferencing is asynchronous) { + for (VClass directVClass : directClasses) { + VClassDao vcDao = vreq.getWebappDaoFactory().getVClassDao(); + List superClassUris = vcDao.getAllSuperClassURIs(directVClass.getURI()); + for (String uri : superClassUris) { + VClass vclass = vcDao.getVClassByURI(uri); + customTemplate = vclass.getCustomDisplayView(); + if (customTemplate != null) { + if (customTemplate.length()>0) { + // note that NOT changing entity vclassName here + log.debug("Found superclass [" + vclass.getName() + "] with custom view " + customTemplate); + break; + } else { + customTemplate = null; + } + } + } + } + } } else if (individual.getVClassURI() != null) { log.debug("Individual " + individual.getURI() + " with class URI " + individual.getVClassURI() + ": no class found with that URI"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java index f66ccca41..ed6e7725b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java @@ -3,6 +3,7 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; @@ -12,9 +13,11 @@ import org.openrdf.model.impl.URIImpl; import edu.cornell.mannlib.vedit.beans.LoginStatusBean; 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.freemarker.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route; +import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; @@ -56,6 +59,24 @@ public class IndividualTemplateModel extends BaseTemplateModel { return isSelfEditing || isCurator; } + private boolean isVClass(String vClassUri) { + boolean isVClass = individual.isVClass(vClassUri); + // If reasoning is asynchronous, this inference may not have been made yet. Check the superclasses + // of the individual's vclass. + if (!isVClass) { // & reasoning is asynchronous: method to be added later; see NIHVIVO-1834 + List directVClasses = individual.getVClasses(true); + for (VClass directVClass : directVClasses) { + VClassDao vcDao = vreq.getWebappDaoFactory().getVClassDao(); + List superClassUris = vcDao.getAllSuperClassURIs(directVClass.getURI()); + if (superClassUris.contains(vClassUri)) { + isVClass = true; + break; + } + } + } + return isVClass; + } + /* These methods perform some manipulation of the data returned by the Individual methods */ @@ -126,11 +147,11 @@ public class IndividualTemplateModel extends BaseTemplateModel { // and getVisualizationUrl() methods there, but we still need to know whether to // instantiate the IndividualTemplateModel or the VivoIndividualTemplateModel class. public boolean isPerson() { - return individual.isVClass("http://xmlns.com/foaf/0.1/Person"); + return isVClass("http://xmlns.com/foaf/0.1/Person"); } public boolean isOrganization() { - return individual.isVClass("http://xmlns.com/foaf/0.1/Organization"); + return isVClass("http://xmlns.com/foaf/0.1/Organization"); } public GroupedPropertyList getPropertyList() {