NIHVIVO-3729 Modify ProptyListConfig so it doesn't rely on the FreemarkerConfiguration being stored as a request attribute, but so it can still be stubbed out for unit tests.
This commit is contained in:
parent
e3d2a8fb47
commit
68f88fe257
3 changed files with 42 additions and 13 deletions
|
@ -40,6 +40,7 @@ public class PropertyListConfig {
|
|||
// TODO Lump these together into the PropertyListConfigContext
|
||||
private final ObjectPropertyTemplateModel optm;
|
||||
private final VitroRequest vreq;
|
||||
private final TemplateLoader templateLoader;
|
||||
|
||||
private boolean isDefaultConfig;
|
||||
private Set<String> constructQueries;
|
||||
|
@ -47,12 +48,14 @@ public class PropertyListConfig {
|
|||
private String templateName;
|
||||
private ObjectPropertyDataPostProcessor postprocessor; // never null
|
||||
|
||||
public PropertyListConfig(ObjectPropertyTemplateModel optm, VitroRequest vreq, ObjectProperty op, boolean editing)
|
||||
public PropertyListConfig(ObjectPropertyTemplateModel optm, TemplateLoader templateLoader, VitroRequest vreq,
|
||||
ObjectProperty op, boolean editing)
|
||||
throws InvalidConfigurationException {
|
||||
|
||||
this.optm = optm;
|
||||
this.vreq = vreq;
|
||||
WebappDaoFactory wadf = vreq.getWebappDaoFactory();
|
||||
this.templateLoader = templateLoader;
|
||||
|
||||
// Get the custom config filename
|
||||
String configFileName = wadf.getObjectPropertyDao().getCustomListViewConfigFileName(op);
|
||||
|
@ -117,10 +120,8 @@ public class PropertyListConfig {
|
|||
return ConfigError.NO_TEMPLATE;
|
||||
}
|
||||
|
||||
Configuration fmConfig = (Configuration) vreq.getAttribute("freemarkerConfig");
|
||||
TemplateLoader tl = fmConfig.getTemplateLoader();
|
||||
try {
|
||||
if ( tl.findTemplateSource(templateName) == null ) {
|
||||
if ( templateLoader.findTemplateSource(templateName) == null ) {
|
||||
return ConfigError.TEMPLATE_NOT_FOUND;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -22,6 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfigurationLoader;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||
|
@ -29,6 +30,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.InvalidConfigurationException;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.PropertyListConfig;
|
||||
import freemarker.cache.TemplateLoader;
|
||||
|
||||
public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel {
|
||||
|
||||
|
@ -87,7 +89,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
|
||||
// Get the config for this object property
|
||||
try {
|
||||
config = new PropertyListConfig(this, vreq, op, editing);
|
||||
config = new PropertyListConfig(this, getFreemarkerTemplateLoader(), vreq, op, editing);
|
||||
} catch (InvalidConfigurationException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
|
@ -128,6 +130,18 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pull this into a protected method so we can stub it out in the unit tests.
|
||||
* Other options:
|
||||
* 1) receive a TemplateLoader into the constructor of ObjectPropertyTemplateModel,
|
||||
* 2) provide a service that will check to see whether a given template name is valid,
|
||||
* 3) skip the test for valid template name until we try to use the thing.
|
||||
* This will do for now.
|
||||
*/
|
||||
protected TemplateLoader getFreemarkerTemplateLoader() {
|
||||
return FreemarkerConfigurationLoader.getConfig(vreq).getTemplateLoader();
|
||||
}
|
||||
|
||||
protected List<Map<String, String>> getStatementData() {
|
||||
ObjectPropertyStatementDao opDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao();
|
||||
return opDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, objectKey, getSelectQuery(), getConstructQueries());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue