Changing ViewFinder.java to not check the vclasses for custom short views. NIHVIVO-2024
This commit is contained in:
parent
8be9eaaeae
commit
e956a3668a
1 changed files with 91 additions and 91 deletions
|
@ -80,101 +80,101 @@ public class ViewFinder {
|
|||
}
|
||||
|
||||
private String findCustomTemplateByVClasses(Individual individual, VitroRequest vreq) {
|
||||
|
||||
Method method = view.getMethod();
|
||||
TemplateLoader templateLoader = ((Configuration) vreq.getAttribute("freemarkerConfig")).getTemplateLoader();
|
||||
|
||||
/* RY The logic here is incorrect. The vclasses are
|
||||
* returned in a random order, whereas we need to
|
||||
* traverse the class hierarchy and find the most
|
||||
* specific custom view applicable to the individual.
|
||||
* The logic is complex because individuals can belong
|
||||
* to multiple classes, and classes can subclass multiple
|
||||
* classes. If there are two competing custom views at the
|
||||
* same level of specificity, what should we do? Also, if we
|
||||
* are displaying a list of individuals belonging to a certain
|
||||
* class, we may want to use only a custom view defined for that
|
||||
* class and NOT a more specific one. See NIHVIVO-568. Similarly
|
||||
* when we're displaying an object property: if we are displaying
|
||||
* #hasPrincipalInvestigatorRole, the object should be displayed
|
||||
* as a PrincipalInvestigatorRole object rather than some other type.
|
||||
*
|
||||
* For now, iterate first through asserted classes, and if no custom view
|
||||
* found there, iterate through inferred classes. Modeled on MiscWebUtils.getCustomShortView().
|
||||
*/
|
||||
String customTemplate = null;
|
||||
VClassDao vcDao = vreq.getWebappDaoFactory().getVClassDao();
|
||||
List<VClass> vclasses = individual.getVClasses(true); // get directly asserted vclasses
|
||||
Set<String> superClasses = new HashSet<String>();
|
||||
|
||||
// First try directly asserted classes. There is no useful decision
|
||||
// mechanism for the case where two directly asserted classes
|
||||
// define a custom template.
|
||||
// RY If we're getting the custom short view with reference to an object property.
|
||||
// should we use the property's getRangeVClass() method instead?
|
||||
for (VClass vclass : vclasses) {
|
||||
// Use this class's custom template, if there is one
|
||||
customTemplate = findCustomTemplateForVClass(vclass, method, templateLoader);
|
||||
if (customTemplate != null) {
|
||||
return customTemplate;
|
||||
}
|
||||
// Otherwise, add superclass to list of vclasses to check for custom
|
||||
// templates.
|
||||
String vclassUri = vclass.getURI();
|
||||
superClasses.addAll(vcDao.getAllSuperClassURIs(vclassUri));
|
||||
}
|
||||
|
||||
// Next try superclasses. There is no useful decision mechanism for
|
||||
// the case where two superclasses have a custom template defined.
|
||||
for (String superClassUri : superClasses) {
|
||||
VClass vc = vcDao.getVClassByURI(superClassUri);
|
||||
customTemplate = findCustomTemplateForVClass(vc, method, templateLoader);
|
||||
if (customTemplate != null) {
|
||||
return customTemplate;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method method = view.getMethod();
|
||||
// TemplateLoader templateLoader = ((Configuration) vreq.getAttribute("freemarkerConfig")).getTemplateLoader();
|
||||
//
|
||||
// /* RY The logic here is incorrect. The vclasses are
|
||||
// * returned in a random order, whereas we need to
|
||||
// * traverse the class hierarchy and find the most
|
||||
// * specific custom view applicable to the individual.
|
||||
// * The logic is complex because individuals can belong
|
||||
// * to multiple classes, and classes can subclass multiple
|
||||
// * classes. If there are two competing custom views at the
|
||||
// * same level of specificity, what should we do? Also, if we
|
||||
// * are displaying a list of individuals belonging to a certain
|
||||
// * class, we may want to use only a custom view defined for that
|
||||
// * class and NOT a more specific one. See NIHVIVO-568. Similarly
|
||||
// * when we're displaying an object property: if we are displaying
|
||||
// * #hasPrincipalInvestigatorRole, the object should be displayed
|
||||
// * as a PrincipalInvestigatorRole object rather than some other type.
|
||||
// *
|
||||
// * For now, iterate first through asserted classes, and if no custom view
|
||||
// * found there, iterate through inferred classes. Modeled on MiscWebUtils.getCustomShortView().
|
||||
// */
|
||||
// String customTemplate = null;
|
||||
// VClassDao vcDao = vreq.getWebappDaoFactory().getVClassDao();
|
||||
// List<VClass> vclasses = individual.getVClasses(true); // get directly asserted vclasses
|
||||
// Set<String> superClasses = new HashSet<String>();
|
||||
//
|
||||
// // First try directly asserted classes. There is no useful decision
|
||||
// // mechanism for the case where two directly asserted classes
|
||||
// // define a custom template.
|
||||
// // RY If we're getting the custom short view with reference to an object property.
|
||||
// // should we use the property's getRangeVClass() method instead?
|
||||
// for (VClass vclass : vclasses) {
|
||||
// // Use this class's custom template, if there is one
|
||||
// customTemplate = findCustomTemplateForVClass(vclass, method, templateLoader);
|
||||
// if (customTemplate != null) {
|
||||
// return customTemplate;
|
||||
// }
|
||||
// // Otherwise, add superclass to list of vclasses to check for custom
|
||||
// // templates.
|
||||
// String vclassUri = vclass.getURI();
|
||||
// superClasses.addAll(vcDao.getAllSuperClassURIs(vclassUri));
|
||||
// }
|
||||
//
|
||||
// // Next try superclasses. There is no useful decision mechanism for
|
||||
// // the case where two superclasses have a custom template defined.
|
||||
// for (String superClassUri : superClasses) {
|
||||
// VClass vc = vcDao.getVClassByURI(superClassUri);
|
||||
// customTemplate = findCustomTemplateForVClass(vc, method, templateLoader);
|
||||
// if (customTemplate != null) {
|
||||
// return customTemplate;
|
||||
// }
|
||||
// }
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private String findCustomTemplateForVClass(VClass vclass, Method method, TemplateLoader templateLoader) {
|
||||
String customTemplate = null;
|
||||
String vClassCustomTemplate = null;
|
||||
|
||||
try {
|
||||
vClassCustomTemplate = (String) method.invoke(vclass);
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.error("Incorrect arguments passed to method " + method.getName() + " in findCustomTemplateForVClass().");
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error("Method " + method.getName() + " cannot be accessed in findCustomTemplateForVClass().");
|
||||
} catch (InvocationTargetException e) {
|
||||
log.error("Exception thrown by method " + method.getName() + " in findCustomTemplateForVClass().");
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(vClassCustomTemplate)) {
|
||||
log.debug("Custom template " + vClassCustomTemplate + " defined for class " + vclass.getName());
|
||||
try {
|
||||
// Make sure the template exists
|
||||
if (templateLoader.findTemplateSource(vClassCustomTemplate) != null) {
|
||||
log.debug("Found defined custom template " + vClassCustomTemplate + " for class " + vclass.getName());
|
||||
customTemplate = vClassCustomTemplate;
|
||||
} else {
|
||||
log.warn("Custom template " + vClassCustomTemplate + " for class " + vclass.getName() + " defined but does not exist.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("IOException looking for source for template " + vClassCustomTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
if (customTemplate != null) {
|
||||
log.debug("Using custom template " + customTemplate + " for class " + vclass.getName());
|
||||
} else {
|
||||
log.debug("No custom template found for class " + vclass.getName());
|
||||
}
|
||||
}
|
||||
return customTemplate;
|
||||
}
|
||||
// private String findCustomTemplateForVClass(VClass vclass, Method method, TemplateLoader templateLoader) {
|
||||
// String customTemplate = null;
|
||||
// String vClassCustomTemplate = null;
|
||||
//
|
||||
// try {
|
||||
// vClassCustomTemplate = (String) method.invoke(vclass);
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// log.error("Incorrect arguments passed to method " + method.getName() + " in findCustomTemplateForVClass().");
|
||||
// } catch (IllegalAccessException e) {
|
||||
// log.error("Method " + method.getName() + " cannot be accessed in findCustomTemplateForVClass().");
|
||||
// } catch (InvocationTargetException e) {
|
||||
// log.error("Exception thrown by method " + method.getName() + " in findCustomTemplateForVClass().");
|
||||
// }
|
||||
//
|
||||
// if (!StringUtils.isEmpty(vClassCustomTemplate)) {
|
||||
// log.debug("Custom template " + vClassCustomTemplate + " defined for class " + vclass.getName());
|
||||
// try {
|
||||
// // Make sure the template exists
|
||||
// if (templateLoader.findTemplateSource(vClassCustomTemplate) != null) {
|
||||
// log.debug("Found defined custom template " + vClassCustomTemplate + " for class " + vclass.getName());
|
||||
// customTemplate = vClassCustomTemplate;
|
||||
// } else {
|
||||
// log.warn("Custom template " + vClassCustomTemplate + " for class " + vclass.getName() + " defined but does not exist.");
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// log.error("IOException looking for source for template " + vClassCustomTemplate);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (log.isDebugEnabled()) {
|
||||
// if (customTemplate != null) {
|
||||
// log.debug("Using custom template " + customTemplate + " for class " + vclass.getName());
|
||||
// } else {
|
||||
// log.debug("No custom template found for class " + vclass.getName());
|
||||
// }
|
||||
// }
|
||||
// return customTemplate;
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue