diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java index 675956d8f..00fd7e13b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java @@ -108,6 +108,7 @@ public class GroupedPropertyList extends BaseTemplateModel { if (editing) { mergeAllPossibleDataProperties(propertyList); + propertyList = correctLanguageForProperties(propertyList); } sort(propertyList); @@ -129,6 +130,35 @@ public class GroupedPropertyList extends BaseTemplateModel { } } + + // Use the language-filtering WebappDaoFactory to get the right version of + // each property. When editing, the methods that add to the property list + // are blissfully (and intentionally) language-unaware. + private List correctLanguageForProperties(List properties) { + List languageCorrectedProps = new ArrayList(); + for (Property p : properties) { + Property correctedProp = null; + if (p instanceof ObjectProperty) { + ObjectProperty op = (ObjectProperty) p; + correctedProp = wdf.getObjectPropertyDao() + .getObjectPropertyByURIs(op.getURI(), + op.getDomainVClassURI(), op.getRangeVClassURI()); + } else if (p instanceof DataProperty) { + correctedProp = wdf.getDataPropertyDao() + .getDataPropertyByURI(((DataProperty) p).getURI()); + } else { + log.warn("Ignoring " + p.getURI() + " which is neither an " + + "ObjectProperty nor a DatatypeProperty."); + } + if (correctedProp != null) { + languageCorrectedProps.add(correctedProp); + } else { + log.error("Unable to retrieve property " + p.getURI() + + " using the WebappDaoFactory associated with the request."); + } + } + return languageCorrectedProps; + } // It's possible that an object property retrieved in the call to getPopulatedObjectPropertyList() // is now empty of statements, because if not editing, some statements without a linked individual @@ -248,7 +278,9 @@ public class GroupedPropertyList extends BaseTemplateModel { } protected void mergeAllPossibleDataProperties(List propertyList) { - DataPropertyDao dpDao = wdf.getDataPropertyDao(); + // see comments in mergeAllPossibleObjectProperties() for the reason + // that we need a neutral WebappDaoFactory here. + DataPropertyDao dpDao = vreq.getLanguageNeutralWebappDaoFactory().getDataPropertyDao(); Collection allDatapropColl = dpDao .getAllPossibleDatapropsForIndividual(subject.getURI()); if (allDatapropColl != null) {