NIHVIVO-1510 Moved check for valid config for collated property to a separate method.

This commit is contained in:
rjy7 2011-01-06 19:57:24 +00:00
parent 8340088969
commit f38677d914
2 changed files with 17 additions and 8 deletions

View file

@ -36,13 +36,9 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
super(op, subject, vreq); super(op, subject, vreq);
/* Make sure the query contains a subclass variable. If not, throw an exception so the caller will create if ( ! validConfigurationForCollatedProperty() ) {
* an UncollatedObjectPropertyTemplateModel instead. throw new InvalidConfigurationException("Invalid configuration for property " + op.getURI() +
*/ ": Query does not select a subclass variable.");
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 */ /* Get the data */
@ -70,6 +66,19 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
subclasses.putAll(unsortedSubclasses); subclasses.putAll(unsortedSubclasses);
} }
private boolean validConfigurationForCollatedProperty() {
boolean validConfig = true;
// Make sure the query selects a ?subclass variable.
String queryString = getQueryString();
Matcher m = QUERY_PATTERN.matcher(queryString);
if ( ! m.find() ) {
validConfig = false;
}
return validConfig;
}
private Map<String, List<ObjectPropertyStatementTemplateModel>> collate(String subjectUri, private Map<String, List<ObjectPropertyStatementTemplateModel>> collate(String subjectUri,
String propertyUri, List<Map<String, String>> statementData, VitroRequest vreq) { String propertyUri, List<Map<String, String>> statementData, VitroRequest vreq) {

View file

@ -65,7 +65,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
try { try {
return new CollatedObjectPropertyTemplateModel(op, subject, vreq); return new CollatedObjectPropertyTemplateModel(op, subject, vreq);
} catch (InvalidConfigurationException e) { } catch (InvalidConfigurationException e) {
log.error(e, e); log.error(e);
return new UncollatedObjectPropertyTemplateModel(op, subject, vreq); return new UncollatedObjectPropertyTemplateModel(op, subject, vreq);
} }
} else { } else {