diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityMergedPropertyListController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityMergedPropertyListController.java index 0f6c2e402..838b0b3f8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityMergedPropertyListController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityMergedPropertyListController.java @@ -10,6 +10,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -506,14 +507,21 @@ public class EntityMergedPropertyListController extends VitroHttpServlet { //types? For now we just show them in whichever type shows up first. related to NIHVIVO-876 orgStmtList.removeAll(stmtsForClass); - Collections.sort(stmtsForClass, - new Comparator() { - public int compare(ObjectPropertyStatement o1, - ObjectPropertyStatement o2) { - return o1.getObject().getName().compareTo( - o2.getObject().getName()); - } - }); + // rjy7 Fix for NIHVIVO-426 Sort people in organization listing by name, rather than by the position name. + // This is an ugly hack and we should not refer to ontology properties here. Need a better fix in the long term. + if (prop.getURI().equals("http://vivoweb.org/ontology/core#organizationForPosition")) { + sortByRelatedIndividualNames(stmtsForClass, "http://vivoweb.org/ontology/core#positionForPerson"); + } else { + Collections.sort(stmtsForClass, + new Comparator() { + public int compare(ObjectPropertyStatement o1, + ObjectPropertyStatement o2) { + return o1.getObject().getName().compareTo( + o2.getObject().getName()); + } + }); + } + System.out.println("stmtsForclass size after sort: " + stmtsForClass.size()); System.out.println("sortedStmtList size before add: " @@ -527,7 +535,21 @@ public class EntityMergedPropertyListController extends VitroHttpServlet { } - + private void sortByRelatedIndividualNames(List opStmts, String predicateUri) { + + final LinkedHashMap stmtsToNames = new LinkedHashMap(opStmts.size()); + for (ObjectPropertyStatement stmt : opStmts) { + Individual relatedIndividual = stmt.getObject().getRelatedIndividual(predicateUri); + String relatedIndividualName = relatedIndividual != null ? relatedIndividual.getName() : ""; + stmtsToNames.put(stmt, relatedIndividualName); + } + // Sort the object property statements by the names + Collections.sort(opStmts, new Comparator() { + public int compare(ObjectPropertyStatement left, ObjectPropertyStatement right) { + return stmtsToNames.get(left).compareTo(stmtsToNames.get(right)); + } + }); + } private List getObjectsFromStmts(List orgStmtList) { List individuals = new LinkedList();