NIHVIVO-1891 Don't do queries for properties known to be unpopulated
This commit is contained in:
parent
37596f3408
commit
eaa1d4ef78
6 changed files with 87 additions and 62 deletions
|
@ -45,11 +45,16 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
private WebappDaoFactory wdf;
|
private WebappDaoFactory wdf;
|
||||||
|
|
||||||
CollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject,
|
CollatedObjectPropertyTemplateModel(ObjectProperty op, Individual subject,
|
||||||
VitroRequest vreq, EditingPolicyHelper policyHelper)
|
VitroRequest vreq, EditingPolicyHelper policyHelper,
|
||||||
|
List<ObjectProperty> populatedObjectPropertyList)
|
||||||
throws InvalidConfigurationException {
|
throws InvalidConfigurationException {
|
||||||
|
|
||||||
super(op, subject, vreq, policyHelper);
|
super(op, subject, vreq, policyHelper);
|
||||||
|
|
||||||
|
subclasses = new TreeMap<String, List<ObjectPropertyStatementTemplateModel>>();
|
||||||
|
|
||||||
|
if (populatedObjectPropertyList.contains(op)) {
|
||||||
|
log.debug("Getting data for populated object property " + getUri());
|
||||||
/* Get the data */
|
/* Get the data */
|
||||||
wdf = vreq.getWebappDaoFactory();
|
wdf = vreq.getWebappDaoFactory();
|
||||||
ObjectPropertyStatementDao opDao = wdf.getObjectPropertyStatementDao();
|
ObjectPropertyStatementDao opDao = wdf.getObjectPropertyStatementDao();
|
||||||
|
@ -72,6 +77,9 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
for (List<ObjectPropertyStatementTemplateModel> list : subclasses.values()) {
|
for (List<ObjectPropertyStatementTemplateModel> list : subclasses.values()) {
|
||||||
postprocessStatementList(list);
|
postprocessStatementList(list);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("Object property " + getUri() + " is unpopulated.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ConfigError checkQuery(String queryString) {
|
protected ConfigError checkQuery(String queryString) {
|
||||||
|
|
|
@ -29,18 +29,24 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
|
|
||||||
private List<DataPropertyStatementTemplateModel> statements;
|
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);
|
super(dp, subject, policyHelper);
|
||||||
|
|
||||||
setName(dp.getPublicName());
|
setName(dp.getPublicName());
|
||||||
|
statements = new ArrayList<DataPropertyStatementTemplateModel>();
|
||||||
|
|
||||||
// Get the data property statements via a sparql query
|
// 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();
|
DataPropertyStatementDao dpDao = vreq.getWebappDaoFactory().getDataPropertyStatementDao();
|
||||||
List<Literal> values = dpDao.getDataPropertyValuesForIndividualByProperty(subject, dp);
|
List<Literal> values = dpDao.getDataPropertyValuesForIndividualByProperty(subject, dp);
|
||||||
statements = new ArrayList<DataPropertyStatementTemplateModel>(values.size());
|
|
||||||
for (Literal value : values) {
|
for (Literal value : values) {
|
||||||
statements.add(new DataPropertyStatementTemplateModel(subjectUri, propertyUri, value, policyHelper));
|
statements.add(new DataPropertyStatementTemplateModel(subjectUri, propertyUri, value, policyHelper));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("Data property " + getUri() + " is unpopulated.");
|
||||||
|
}
|
||||||
|
|
||||||
// Determine whether a new statement can be added
|
// Determine whether a new statement can be added
|
||||||
if (policyHelper != null) {
|
if (policyHelper != null) {
|
||||||
|
|
|
@ -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.
|
// 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,
|
// 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.
|
// so we cannot just rely on getting that list.
|
||||||
List<ObjectProperty> objectPropertyList = subject.getPopulatedObjectPropertyList();
|
List<ObjectProperty> populatedObjectPropertyList = subject.getPopulatedObjectPropertyList();
|
||||||
propertyList.addAll(objectPropertyList);
|
propertyList.addAll(populatedObjectPropertyList);
|
||||||
|
|
||||||
// If editing this page, merge in object properties applicable to the individual that are currently
|
// 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.
|
// 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.
|
// RY In future, we should limit this to properties that the user CAN add properties to.
|
||||||
if (policyHelper != null) {
|
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
|
// 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
|
// 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
|
// can be customized and thus differ from property to property. So it's easier for now to keep the
|
||||||
// two working in parallel.
|
// two working in parallel.
|
||||||
List<DataProperty> dataPropertyList = subject.getPopulatedDataPropertyList();
|
List<DataProperty> populatedDataPropertyList = subject.getPopulatedDataPropertyList();
|
||||||
propertyList.addAll(dataPropertyList);
|
propertyList.addAll(populatedDataPropertyList);
|
||||||
|
|
||||||
if (policyHelper != null) {
|
if (policyHelper != null) {
|
||||||
mergeAllPossibleDataProperties(propertyList);
|
mergeAllPossibleDataProperties(propertyList);
|
||||||
|
@ -100,7 +100,8 @@ public class GroupedPropertyList extends BaseTemplateModel {
|
||||||
// Build the template data model from the groupList
|
// Build the template data model from the groupList
|
||||||
groups = new ArrayList<PropertyGroupTemplateModel>(propertyGroupList.size());
|
groups = new ArrayList<PropertyGroupTemplateModel>(propertyGroupList.size());
|
||||||
for (PropertyGroup propertyGroup: propertyGroupList) {
|
for (PropertyGroup propertyGroup: propertyGroupList) {
|
||||||
groups.add(new PropertyGroupTemplateModel(vreq, propertyGroup, subject, policyHelper));
|
groups.add(new PropertyGroupTemplateModel(vreq, propertyGroup, subject,
|
||||||
|
policyHelper, populatedDataPropertyList, populatedObjectPropertyList));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,18 +169,19 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static ObjectPropertyTemplateModel getObjectPropertyTemplateModel(ObjectProperty op,
|
protected static ObjectPropertyTemplateModel getObjectPropertyTemplateModel(ObjectProperty op,
|
||||||
Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper) {
|
Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper,
|
||||||
|
List<ObjectProperty> populatedObjectPropertyList) {
|
||||||
|
|
||||||
if (op.getCollateBySubclass()) {
|
if (op.getCollateBySubclass()) {
|
||||||
try {
|
try {
|
||||||
return new CollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper);
|
return new CollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper, populatedObjectPropertyList);
|
||||||
} catch (InvalidConfigurationException e) {
|
} catch (InvalidConfigurationException e) {
|
||||||
log.warn(e.getMessage());
|
log.warn(e.getMessage());
|
||||||
// If the collated config is invalid, instantiate an UncollatedObjectPropertyTemplateModel instead.
|
// If the collated config is invalid, instantiate an UncollatedObjectPropertyTemplateModel instead.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return new UncollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper);
|
return new UncollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper, populatedObjectPropertyList);
|
||||||
} catch (InvalidConfigurationException e) {
|
} catch (InvalidConfigurationException e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -24,7 +24,9 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
||||||
private String name;
|
private String name;
|
||||||
private List<PropertyTemplateModel> properties;
|
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();
|
this.name = group.getName();
|
||||||
|
|
||||||
List<Property> propertyList = group.getPropertyList();
|
List<Property> propertyList = group.getPropertyList();
|
||||||
|
@ -32,9 +34,9 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
||||||
for (Property p : propertyList) {
|
for (Property p : propertyList) {
|
||||||
if (p instanceof ObjectProperty) {
|
if (p instanceof ObjectProperty) {
|
||||||
ObjectProperty op = (ObjectProperty)p;
|
ObjectProperty op = (ObjectProperty)p;
|
||||||
properties.add(ObjectPropertyTemplateModel.getObjectPropertyTemplateModel(op, subject, vreq, policyHelper));
|
properties.add(ObjectPropertyTemplateModel.getObjectPropertyTemplateModel(op, subject, vreq, policyHelper, populatedObjectPropertyList));
|
||||||
} else {
|
} else {
|
||||||
properties.add(new DataPropertyTemplateModel((DataProperty)p, subject, vreq, policyHelper));
|
properties.add(new DataPropertyTemplateModel((DataProperty)p, subject, vreq, policyHelper, populatedDataPropertyList));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,16 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
|
||||||
|
|
||||||
private List<ObjectPropertyStatementTemplateModel> statements;
|
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 {
|
throws InvalidConfigurationException {
|
||||||
|
|
||||||
super(op, subject, vreq, policyHelper);
|
super(op, subject, vreq, policyHelper);
|
||||||
|
statements = new ArrayList<ObjectPropertyStatementTemplateModel>();
|
||||||
|
|
||||||
|
if (populatedObjectPropertyList.contains(op)) {
|
||||||
|
log.debug("Getting data for populated object property " + getUri());
|
||||||
/* Get the data */
|
/* Get the data */
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
ObjectPropertyStatementDao opDao = wdf.getObjectPropertyStatementDao();
|
ObjectPropertyStatementDao opDao = wdf.getObjectPropertyStatementDao();
|
||||||
|
@ -38,7 +43,6 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
|
||||||
postprocess(statementData, wdf);
|
postprocess(statementData, wdf);
|
||||||
|
|
||||||
/* Put into data structure to send to template */
|
/* Put into data structure to send to template */
|
||||||
statements = new ArrayList<ObjectPropertyStatementTemplateModel>(statementData.size());
|
|
||||||
String objectKey = getObjectKey();
|
String objectKey = getObjectKey();
|
||||||
for (Map<String, String> map : statementData) {
|
for (Map<String, String> map : statementData) {
|
||||||
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
statements.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
||||||
|
@ -46,6 +50,9 @@ public class UncollatedObjectPropertyTemplateModel extends ObjectPropertyTemplat
|
||||||
}
|
}
|
||||||
|
|
||||||
postprocessStatementList(statements);
|
postprocessStatementList(statements);
|
||||||
|
} else {
|
||||||
|
log.debug("Object property " + getUri() + " is unpopulated.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Access methods for templates */
|
/* Access methods for templates */
|
||||||
|
|
Loading…
Add table
Reference in a new issue