Refactor statement data getting into ObjectPropertyTemplateModel, so shared by the subclasses.
This commit is contained in:
parent
0c4d72f777
commit
984162bffe
4 changed files with 32 additions and 38 deletions
|
@ -41,7 +41,6 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
|||
Pattern.compile("ORDER\\s+BY\\s+(DESC\\s*\\(\\s*)?\\?" + SUBCLASS_VARIABLE_NAME, Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private SortedMap<String, List<ObjectPropertyStatementTemplateModel>> subclasses;
|
||||
private WebappDaoFactory wdf;
|
||||
|
||||
CollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject,
|
||||
VitroRequest vreq, EditingPolicyHelper policyHelper,
|
||||
|
@ -53,20 +52,16 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
|||
subclasses = new TreeMap<String, List<ObjectPropertyStatementTemplateModel>>();
|
||||
|
||||
if (populatedObjectPropertyList.contains(op)) {
|
||||
log.debug("Getting data for populated object property " + getUri());
|
||||
log.debug("Getting data for populated object property " + op.getURI());
|
||||
|
||||
/* Get the data */
|
||||
wdf = vreq.getWebappDaoFactory();
|
||||
ObjectPropertyStatementDao opDao = wdf.getObjectPropertyStatementDao();
|
||||
String subjectUri = subject.getURI();
|
||||
String propertyUri = op.getURI();
|
||||
List<Map<String, String>> statementData =
|
||||
opDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, getObjectKey(), getSelectQuery(), getConstructQueries());
|
||||
|
||||
List<Map<String, String>> statementData = getStatementData();
|
||||
|
||||
/* Apply post-processing */
|
||||
postprocess(statementData, wdf);
|
||||
postprocess(statementData);
|
||||
|
||||
/* Collate the data */
|
||||
subclasses = collate(subjectUri, propertyUri, statementData, vreq, policyHelper);
|
||||
subclasses = collate(subjectUri, propertyUri, statementData, policyHelper);
|
||||
|
||||
for (List<ObjectPropertyStatementTemplateModel> list : subclasses.values()) {
|
||||
postprocessStatementList(list);
|
||||
|
@ -139,7 +134,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
|||
}
|
||||
}
|
||||
// Sort the data for this object from most to least specific subclass, with nulls at end
|
||||
Collections.sort(dataForThisObject, new SubclassComparator(wdf));
|
||||
Collections.sort(dataForThisObject, new SubclassComparator());
|
||||
filteredList.add(dataForThisObject.get(0));
|
||||
}
|
||||
|
||||
|
@ -155,8 +150,8 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
|||
|
||||
private VClassDao vclassDao;
|
||||
|
||||
SubclassComparator(WebappDaoFactory wdf) {
|
||||
this.vclassDao = wdf.getVClassDao();
|
||||
SubclassComparator() {
|
||||
this.vclassDao = vreq.getWebappDaoFactory().getVClassDao();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -197,7 +192,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
|||
|
||||
// Collate the statements by subclass.
|
||||
private SortedMap<String, List<ObjectPropertyStatementTemplateModel>> collate(String subjectUri, String propertyUri,
|
||||
List<Map<String, String>> statementData, VitroRequest vreq, EditingPolicyHelper policyHelper) {
|
||||
List<Map<String, String>> statementData, EditingPolicyHelper policyHelper) {
|
||||
|
||||
SortedMap<String, List<ObjectPropertyStatementTemplateModel>> subclassMap =
|
||||
new TreeMap<String, List<ObjectPropertyStatementTemplateModel>>();
|
||||
|
|
|
@ -35,6 +35,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
|||
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;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import freemarker.cache.TemplateLoader;
|
||||
|
@ -100,7 +101,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
|
||||
// Get the config for this object property
|
||||
try {
|
||||
config = new PropertyListConfig(op, vreq, policyHelper);
|
||||
config = new PropertyListConfig(op, policyHelper);
|
||||
} catch (InvalidConfigurationException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
|
@ -118,6 +119,11 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
}
|
||||
}
|
||||
|
||||
protected List<Map<String, String>> getStatementData() {
|
||||
ObjectPropertyStatementDao opDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao();
|
||||
return opDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, objectKey, getSelectQuery(), getConstructQueries());
|
||||
}
|
||||
|
||||
protected abstract boolean isEmpty();
|
||||
|
||||
@Override
|
||||
|
@ -139,11 +145,11 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
return null;
|
||||
}
|
||||
|
||||
protected String getSelectQuery() {
|
||||
private String getSelectQuery() {
|
||||
return config.selectQuery;
|
||||
}
|
||||
|
||||
protected Set<String> getConstructQueries() {
|
||||
private Set<String> getConstructQueries() {
|
||||
return config.constructQueries;
|
||||
}
|
||||
|
||||
|
@ -206,7 +212,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
}
|
||||
|
||||
/** Apply post-processing to query results to prepare for template */
|
||||
protected void postprocess(List<Map<String, String>> data, WebappDaoFactory wdf) {
|
||||
protected void postprocess(List<Map<String, String>> data) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Data for property " + getUri() + " before postprocessing");
|
||||
|
@ -342,7 +348,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
private String templateName;
|
||||
private ObjectPropertyDataPostProcessor postprocessor = null;
|
||||
|
||||
PropertyListConfig(ObjectProperty op, VitroRequest vreq, EditingPolicyHelper policyHelper)
|
||||
PropertyListConfig(ObjectProperty op, EditingPolicyHelper policyHelper)
|
||||
throws InvalidConfigurationException {
|
||||
|
||||
// Get the custom config filename
|
||||
|
@ -370,7 +376,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
}
|
||||
|
||||
if ( ! isDefaultConfig(configFileName) ) {
|
||||
ConfigError configError = checkConfiguration(vreq);
|
||||
ConfigError configError = checkConfiguration();
|
||||
if ( configError != null ) { // the configuration contains an error
|
||||
// If this is a collated property, throw an error: this results in creating an
|
||||
// UncollatedPropertyTemplateModel instead.
|
||||
|
@ -393,7 +399,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
return configFileName.equals(DEFAULT_CONFIG_FILE_NAME);
|
||||
}
|
||||
|
||||
private ConfigError checkConfiguration(VitroRequest vreq) {
|
||||
private ConfigError checkConfiguration() {
|
||||
|
||||
ConfigError error = ObjectPropertyTemplateModel.this.checkQuery(selectQuery);
|
||||
if (error != null) {
|
||||
|
|
|
@ -29,26 +29,23 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
|
|||
private String localName;
|
||||
protected String propertyUri;
|
||||
protected Map<String, Object> verboseDisplay = null;
|
||||
|
||||
// For editing
|
||||
protected String subjectUri = null;
|
||||
protected VitroRequest vreq;
|
||||
protected boolean addAccess = false;
|
||||
|
||||
PropertyTemplateModel(Property property, Individual subject, EditingPolicyHelper policyHelper, VitroRequest vreq) {
|
||||
subjectUri = subject.getURI();
|
||||
propertyUri = property.getURI();
|
||||
this.vreq = vreq;
|
||||
localName = property.getLocalName();
|
||||
log.debug("Local name for property " + propertyUri + ": " + localName);
|
||||
setVerboseDisplayValues(property, vreq);
|
||||
setVerboseDisplayValues(property);
|
||||
// Do in subclass constructor. The label has not been set on the property, and the
|
||||
// means of getting the label differs between object and data properties.
|
||||
// this.name = property.getLabel();
|
||||
|
||||
if (policyHelper != null) {
|
||||
subjectUri = subject.getURI();
|
||||
}
|
||||
}
|
||||
|
||||
protected void setVerboseDisplayValues(Property property, VitroRequest vreq) {
|
||||
protected void setVerboseDisplayValues(Property property) {
|
||||
// No verbose display for these properties
|
||||
if (GroupedPropertyList.VITRO_PROPS_TO_ADD_TO_LIST.contains(property)) {
|
||||
return;
|
||||
|
|
|
@ -30,17 +30,13 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
|
|||
statements = new ArrayList<ObjectPropertyStatementTemplateModel>();
|
||||
|
||||
if (populatedObjectPropertyList.contains(op)) {
|
||||
log.debug("Getting data for populated object property " + getUri());
|
||||
log.debug("Getting data for populated object property " + op.getURI());
|
||||
|
||||
/* Get the data */
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
ObjectPropertyStatementDao opDao = wdf.getObjectPropertyStatementDao();
|
||||
String subjectUri = subject.getURI();
|
||||
String propertyUri = op.getURI();
|
||||
List<Map<String, String>> statementData =
|
||||
opDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, getObjectKey(), getSelectQuery(), getConstructQueries());
|
||||
List<Map<String, String>> statementData = getStatementData();
|
||||
|
||||
/* Apply postprocessing */
|
||||
postprocess(statementData, wdf);
|
||||
postprocess(statementData);
|
||||
|
||||
/* Put into data structure to send to template */
|
||||
String objectKey = getObjectKey();
|
||||
|
|
Loading…
Add table
Reference in a new issue