NIHVIVO-1510 Fix to exception-handling in creating a collated property list, so only invalid configuration exceptions trigger switching to a collated list.
This commit is contained in:
parent
7cd1f4384c
commit
8340088969
3 changed files with 27 additions and 2 deletions
|
@ -27,11 +27,23 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
|||
|
||||
private static final Log log = LogFactory.getLog(CollatedObjectPropertyTemplateModel.class);
|
||||
private static final String DEFAULT_CONFIG_FILE = "listViewConfig-default-collated.xml";
|
||||
private static final Pattern QUERY_PATTERN = Pattern.compile("SELECT[^{]*\\?subclass\\b");
|
||||
|
||||
private SortedMap<String, List<ObjectPropertyStatementTemplateModel>> subclasses;
|
||||
|
||||
CollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq) throws Exception {
|
||||
CollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq)
|
||||
throws InvalidConfigurationException {
|
||||
|
||||
super(op, subject, vreq);
|
||||
|
||||
/* Make sure the query contains a subclass variable. If not, throw an exception so the caller will create
|
||||
* an UncollatedObjectPropertyTemplateModel instead.
|
||||
*/
|
||||
String queryString = getQueryString();
|
||||
Matcher m = QUERY_PATTERN.matcher(queryString);
|
||||
if ( ! m.find()) {
|
||||
throw new InvalidConfigurationException("Invalid configuration: Query does not select a subclass variable.");
|
||||
}
|
||||
|
||||
/* Get the data */
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
|
|
|
@ -64,7 +64,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
if (op.getCollateBySubclass()) {
|
||||
try {
|
||||
return new CollatedObjectPropertyTemplateModel(op, subject, vreq);
|
||||
} catch (Exception e) {
|
||||
} catch (InvalidConfigurationException e) {
|
||||
log.error(e, e);
|
||||
return new UncollatedObjectPropertyTemplateModel(op, subject, vreq);
|
||||
}
|
||||
|
@ -209,6 +209,15 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
}
|
||||
}
|
||||
|
||||
protected class InvalidConfigurationException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected InvalidConfigurationException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
||||
/* Access methods for templates */
|
||||
|
||||
public String getType() {
|
||||
|
|
|
@ -55,6 +55,10 @@
|
|||
|
||||
<p>${year?number?c}</p>
|
||||
|
||||
<h3>Raw String Literals</h3>
|
||||
<p>${r"#{title}"}</p>
|
||||
<p>${r"${title}"}</p>
|
||||
|
||||
<@dump var="now" />
|
||||
<@dump var="urls" />
|
||||
<@dump var="fruit" />
|
||||
|
|
Loading…
Add table
Reference in a new issue