NIHVIVO-1510 Added error-checking of collation target in list view config file against sparql select terms.
This commit is contained in:
parent
544a0b8e4d
commit
1dd5885514
5 changed files with 35 additions and 8 deletions
|
@ -518,7 +518,6 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
}
|
||||
|
||||
protected void write(StringWriter sw, HttpServletResponse response) {
|
||||
|
||||
try {
|
||||
PrintWriter out = response.getWriter();
|
||||
out.print(sw);
|
||||
|
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -25,12 +28,18 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
|||
CollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject, WebappDaoFactory wdf) throws Exception {
|
||||
super(op, subject, wdf);
|
||||
|
||||
/* RY Temporarily throw an error because collation hasn't been implemented yet. We'll then use an uncollated one instead.
|
||||
* In final version, throw an error if config doesn't contain collation-target element. We'll use an uncollated one instead.
|
||||
*/
|
||||
String collationTargetError = getCollationTargetError();
|
||||
if ( ! collationTargetError.isEmpty()) {
|
||||
String errorMessage = "Collation target error for collated object property " + getName() + ": " +
|
||||
collationTargetError + " " +
|
||||
"Creating uncollated property list instead.";
|
||||
throw new Exception(errorMessage);
|
||||
}
|
||||
|
||||
// RY Temporarily throw an error because collation hasn't been implemented yet.
|
||||
boolean error = true;
|
||||
if (error) {
|
||||
throw new Exception("No collation target specified for collated object property " + op.getLabel());
|
||||
throw new Exception("No collation target specified for collated object property " + getName());
|
||||
}
|
||||
|
||||
ObjectPropertyStatementDao opDao = wdf.getObjectPropertyStatementDao();
|
||||
|
@ -49,6 +58,25 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
|||
|
||||
}
|
||||
|
||||
private String getCollationTargetError() {
|
||||
String errorMessage = null;
|
||||
String collationTarget = getCollationTarget();
|
||||
// Make sure the collation target is not null or empty.
|
||||
if (collationTarget == null || collationTarget.trim().isEmpty()) {
|
||||
errorMessage = "No collation target specified.";
|
||||
} else {
|
||||
// Make sure the collation target is one of the select terms in the query.
|
||||
String queryString = getQueryString();
|
||||
String selectClause = queryString.substring(0, queryString.indexOf("{"));
|
||||
Pattern collationTargetPattern = Pattern.compile("\\b\\\\?" + collationTarget + "\\b");
|
||||
Matcher matcher = collationTargetPattern.matcher(selectClause);
|
||||
if (! matcher.find()) {
|
||||
errorMessage = "Invalid collation target.";
|
||||
}
|
||||
}
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
private List<VClass> getDirectVClasses(String key, List<Map<String, Object>> data) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
try {
|
||||
return new CollatedObjectPropertyTemplateModel(op, subject, wdf);
|
||||
} catch (Exception e) {
|
||||
log.error(e, e);
|
||||
return new UncollatedObjectPropertyTemplateModel(op, subject, wdf);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -20,7 +20,6 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
|
|||
protected Property property; // needed to get the edit links
|
||||
|
||||
PropertyTemplateModel(Property property) {
|
||||
this.name = property.getLabel();
|
||||
// Do in subclass constructor. The label has not been set on the property, and getting the
|
||||
// label differs between object and data properties.
|
||||
// this.name = property.getLabel();
|
||||
|
|
Loading…
Add table
Reference in a new issue