NIHVIVO-1891 Don't do queries for properties known to be unpopulated

This commit is contained in:
rjy7 2011-01-31 22:47:14 +00:00
parent 37596f3408
commit eaa1d4ef78
6 changed files with 87 additions and 62 deletions

View file

@ -45,32 +45,40 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
private WebappDaoFactory wdf;
CollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject,
VitroRequest vreq, EditingPolicyHelper policyHelper)
throws InvalidConfigurationException {
VitroRequest vreq, EditingPolicyHelper policyHelper,
List<ObjectProperty> populatedObjectPropertyList)
throws InvalidConfigurationException {
super(op, subject, vreq, policyHelper);
/* 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, getSelectQuery(), getConstructQueries());
/* Apply post-processing */
postprocess(statementData, wdf);
/* Collate the data */
Map<String, List<ObjectPropertyStatementTemplateModel>> unsortedSubclasses =
collate(subjectUri, propertyUri, statementData, vreq, policyHelper);
/* Sort by subclass name */
subclasses = new TreeMap<String, List<ObjectPropertyStatementTemplateModel>>();
subclasses.putAll(unsortedSubclasses);
for (List<ObjectPropertyStatementTemplateModel> list : subclasses.values()) {
postprocessStatementList(list);
if (populatedObjectPropertyList.contains(op)) {
log.debug("Getting data for populated object property " + 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, getSelectQuery(), getConstructQueries());
/* Apply post-processing */
postprocess(statementData, wdf);
/* Collate the data */
Map<String, List<ObjectPropertyStatementTemplateModel>> unsortedSubclasses =
collate(subjectUri, propertyUri, statementData, vreq, policyHelper);
/* Sort by subclass name */
subclasses = new TreeMap<String, List<ObjectPropertyStatementTemplateModel>>();
subclasses.putAll(unsortedSubclasses);
for (List<ObjectPropertyStatementTemplateModel> list : subclasses.values()) {
postprocessStatementList(list);
}
} else {
log.debug("Object property " + getUri() + " is unpopulated.");
}
}

View file

@ -29,17 +29,23 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
private List<DataPropertyStatementTemplateModel> statements;
DataPropertyTemplateModel(DataProperty dp, Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper) {
DataPropertyTemplateModel(DataProperty dp, Individual subject, VitroRequest vreq,
EditingPolicyHelper policyHelper, List<DataProperty> populatedDataPropertyList) {
super(dp, subject, policyHelper);
setName(dp.getPublicName());
// Get the data property statements via a sparql query
DataPropertyStatementDao dpDao = vreq.getWebappDaoFactory().getDataPropertyStatementDao();
List<Literal> values = dpDao.getDataPropertyValuesForIndividualByProperty(subject, dp);
statements = new ArrayList<DataPropertyStatementTemplateModel>(values.size());
for (Literal value : values) {
statements.add(new DataPropertyStatementTemplateModel(subjectUri, propertyUri, value, policyHelper));
statements = new ArrayList<DataPropertyStatementTemplateModel>();
// If the property is populated, get the data property statements via a sparql query
if (populatedDataPropertyList.contains(dp)) {
log.debug("Getting data for populated data property " + getUri());
DataPropertyStatementDao dpDao = vreq.getWebappDaoFactory().getDataPropertyStatementDao();
List<Literal> values = dpDao.getDataPropertyValuesForIndividualByProperty(subject, dp);
for (Literal value : values) {
statements.add(new DataPropertyStatementTemplateModel(subjectUri, propertyUri, value, policyHelper));
}
} else {
log.debug("Data property " + getUri() + " is unpopulated.");
}
// Determine whether a new statement can be added

View file

@ -69,14 +69,14 @@ public class GroupedPropertyList extends BaseTemplateModel {
// First get all the object properties that occur in statements in the db with this subject as subject.
// This may include properties that are not defined as "possible properties" for a subject of this class,
// so we cannot just rely on getting that list.
List<ObjectProperty> objectPropertyList = subject.getPopulatedObjectPropertyList();
propertyList.addAll(objectPropertyList);
List<ObjectProperty> populatedObjectPropertyList = subject.getPopulatedObjectPropertyList();
propertyList.addAll(populatedObjectPropertyList);
// If editing this page, merge in object properties applicable to the individual that are currently
// unpopulated, so the properties are displayed to allow statements to be added to these properties.
// RY In future, we should limit this to properties that the user CAN add properties to.
if (policyHelper != null) {
mergeAllPossibleObjectProperties(objectPropertyList, propertyList);
mergeAllPossibleObjectProperties(populatedObjectPropertyList, propertyList);
}
// Now do much the same with data properties: get the list of populated data properties, then add in placeholders for missing ones
@ -85,8 +85,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
// DataPropertyStatements. Note that this does not apply to object properties, because the queries
// can be customized and thus differ from property to property. So it's easier for now to keep the
// two working in parallel.
List<DataProperty> dataPropertyList = subject.getPopulatedDataPropertyList();
propertyList.addAll(dataPropertyList);
List<DataProperty> populatedDataPropertyList = subject.getPopulatedDataPropertyList();
propertyList.addAll(populatedDataPropertyList);
if (policyHelper != null) {
mergeAllPossibleDataProperties(propertyList);
@ -100,7 +100,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
// Build the template data model from the groupList
groups = new ArrayList<PropertyGroupTemplateModel>(propertyGroupList.size());
for (PropertyGroup propertyGroup: propertyGroupList) {
groups.add(new PropertyGroupTemplateModel(vreq, propertyGroup, subject, policyHelper));
groups.add(new PropertyGroupTemplateModel(vreq, propertyGroup, subject,
policyHelper, populatedDataPropertyList, populatedObjectPropertyList));
}
}

View file

@ -169,18 +169,19 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
}
protected static ObjectPropertyTemplateModel getObjectPropertyTemplateModel(ObjectProperty op,
Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper) {
Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper,
List<ObjectProperty> populatedObjectPropertyList) {
if (op.getCollateBySubclass()) {
try {
return new CollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper);
return new CollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper, populatedObjectPropertyList);
} catch (InvalidConfigurationException e) {
log.warn(e.getMessage());
// If the collated config is invalid, instantiate an UncollatedObjectPropertyTemplateModel instead.
}
}
try {
return new UncollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper);
return new UncollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper, populatedObjectPropertyList);
} catch (InvalidConfigurationException e) {
log.error(e.getMessage());
return null;

View file

@ -24,7 +24,9 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
private String name;
private List<PropertyTemplateModel> properties;
PropertyGroupTemplateModel(VitroRequest vreq, PropertyGroup group, Individual subject, EditingPolicyHelper policyHelper) {
PropertyGroupTemplateModel(VitroRequest vreq, PropertyGroup group,
Individual subject, EditingPolicyHelper policyHelper,
List<DataProperty> populatedDataPropertyList, List<ObjectProperty> populatedObjectPropertyList) {
this.name = group.getName();
List<Property> propertyList = group.getPropertyList();
@ -32,9 +34,9 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
for (Property p : propertyList) {
if (p instanceof ObjectProperty) {
ObjectProperty op = (ObjectProperty)p;
properties.add(ObjectPropertyTemplateModel.getObjectPropertyTemplateModel(op, subject, vreq, policyHelper));
properties.add(ObjectPropertyTemplateModel.getObjectPropertyTemplateModel(op, subject, vreq, policyHelper, populatedObjectPropertyList));
} else {
properties.add(new DataPropertyTemplateModel((DataProperty)p, subject, vreq, policyHelper));
properties.add(new DataPropertyTemplateModel((DataProperty)p, subject, vreq, policyHelper, populatedDataPropertyList));
}
}
}

View file

@ -21,31 +21,38 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
private List<ObjectPropertyStatementTemplateModel> statements;
UncollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper)
UncollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject,
VitroRequest vreq, EditingPolicyHelper policyHelper,
List<ObjectProperty> populatedObjectPropertyList)
throws InvalidConfigurationException {
super(op, subject, vreq, policyHelper);
statements = new ArrayList<ObjectPropertyStatementTemplateModel>();
/* 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, getSelectQuery(), getConstructQueries());
/* Apply postprocessing */
postprocess(statementData, wdf);
/* Put into data structure to send to template */
statements = new ArrayList<ObjectPropertyStatementTemplateModel>(statementData.size());
String objectKey = getObjectKey();
for (Map<String, String> map : statementData) {
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri,
propertyUri, objectKey, map, policyHelper));
if (populatedObjectPropertyList.contains(op)) {
log.debug("Getting data for populated object property " + 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, getSelectQuery(), getConstructQueries());
/* Apply postprocessing */
postprocess(statementData, wdf);
/* Put into data structure to send to template */
String objectKey = getObjectKey();
for (Map<String, String> map : statementData) {
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri,
propertyUri, objectKey, map, policyHelper));
}
postprocessStatementList(statements);
} else {
log.debug("Object property " + getUri() + " is unpopulated.");
}
postprocessStatementList(statements);
}
/* Access methods for templates */