Merge r5980 from nihvivo-rel-1.1.-maint: custom sorting and collation.

This commit is contained in:
rjy7 2010-09-29 19:48:21 +00:00
parent 5bb2fe05b7
commit a83304b5b8

View file

@ -483,21 +483,27 @@ public class EntityMergedPropertyListController extends VitroHttpServlet {
} }
Map<String,VClass> directClasses = getDirectClasses( getObjectsFromStmts( orgStmtList ) ); Map<String,VClass> directClasses = getDirectClasses( getObjectsFromStmts( orgStmtList ) );
//don't do collateBySubclass if there is only one class //don't do collateBySubclass if there is only one class
if( directClasses.size() < 2 ) { if( directClasses.size() < 2 ) {
prop.setCollateBySubclass(false); //this overrides the value from the model // rjy7 Removed this, so we still get the heading for the single populated subclass
} //prop.setCollateBySubclass(false); //this overrides the value from the model
else{ // Still need to apply custom sort. Since we no longer set collateBySubclass to false,
// we won't know in applyCustomSortToUncollatedProperty whether the statements have
// been sorted or not, so we must do that now.
applyCustomSortToUncollatedStatements(prop, orgStmtList);
} else {
log.debug("statements for object property: " + orgStmtList.size()); log.debug("statements for object property: " + orgStmtList.size());
//get list of direct classes and sort them //get list of direct classes and sort them
List<VClass> vclasses = new LinkedList<VClass>(directClasses.values()); List<VClass> vclasses = new LinkedList<VClass>(directClasses.values());
Collections.sort( Collections.sort(
vclasses, vclasses,
new Comparator<VClass>(){ new Comparator<VClass>(){
public int compare(VClass o1, VClass o2) { public int compare(VClass o1, VClass o2) {
return o1.getName().compareTo(o2.getName()); return o1.getName().compareTo(o2.getName());
} }
}); });
//order object property statements by sorted direct class list //order object property statements by sorted direct class list
List<ObjectPropertyStatement> sortedStmtList = new LinkedList<ObjectPropertyStatement>(); List<ObjectPropertyStatement> sortedStmtList = new LinkedList<ObjectPropertyStatement>();
@ -515,13 +521,13 @@ public class EntityMergedPropertyListController extends VitroHttpServlet {
List<VClass> vclassesForObj = obj.getVClasses(true); List<VClass> vclassesForObj = obj.getVClasses(true);
if (vclassesForObj != null && vclassesForObj.contains(clazz)) { if (vclassesForObj != null && vclassesForObj.contains(clazz)) {
log.debug("adding " + stmt + " to class " log.debug("adding " + stmt + " to class "
+ clazz.getURI()); + clazz.getURI());
log.debug("subjectURI " + stmt.getSubjectURI() log.debug("subjectURI " + stmt.getSubjectURI()
+ " objectURI" + stmt.getObject().getURI()); + " objectURI" + stmt.getObject().getURI());
log.debug("stmtsForclass size: " log.debug("stmtsForclass size: "
+ stmtsForClass.size()); + stmtsForClass.size());
log.debug("stmtsForclass size: " log.debug("stmtsForclass size: "
+ stmtsForClass.size()); + stmtsForClass.size());
stmtsForClass.add(stmt); stmtsForClass.add(stmt);
} }
@ -534,14 +540,14 @@ public class EntityMergedPropertyListController extends VitroHttpServlet {
sortStatements(prop, stmtsForClass); sortStatements(prop, stmtsForClass);
log.debug("stmtsForclass size after sort: " log.debug("stmtsForclass size after sort: "
+ stmtsForClass.size()); + stmtsForClass.size());
log.debug("sortedStmtList size before add: " log.debug("sortedStmtList size before add: "
+ sortedStmtList.size()); + sortedStmtList.size());
sortedStmtList.addAll(stmtsForClass); sortedStmtList.addAll(stmtsForClass);
log.debug("sortedStmtList size after add: " log.debug("sortedStmtList size after add: "
+ sortedStmtList.size()); + sortedStmtList.size());
} }
prop.setObjectPropertyStatements(sortedStmtList); prop.setObjectPropertyStatements(sortedStmtList);
} }
@ -624,16 +630,17 @@ public class EntityMergedPropertyListController extends VitroHttpServlet {
return false; return false;
} }
private void applyCustomSortToUncollatedProperty(ObjectProperty op, List<ObjectPropertyStatement> opStmts) {
if (!op.getCollateBySubclass()) {
applyCustomSortToUncollatedStatements(op, opStmts);
}
}
// Apply custom sorting to an uncollated property. If the property is collated, the custom sorting has already // Apply custom sorting to an uncollated property. If the property is collated, the custom sorting has already
// been applied to each subclass listing individually. // been applied to each subclass listing individually.
private void applyCustomSortToUncollatedProperty(ObjectProperty op, List<ObjectPropertyStatement> opStmts) { private void applyCustomSortToUncollatedStatements(ObjectProperty op, List<ObjectPropertyStatement> opStmts) {
// This includes the case where the ontology doesn't specify collating, as well as the case if (applyCustomSort(op, opStmts)) {
// where we don't collate because only one subclass is populated, since then we've set op.setObjectPropertyStatements(opStmts);
// the collation value to false.
if (!op.getCollateBySubclass()) {
if (applyCustomSort(op, opStmts)) {
op.setObjectPropertyStatements(opStmts);
}
} }
} }