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