NIHVIVO-2573 Rewrite collate() method so it doesn't assume the statementData is ordered by subclass
This commit is contained in:
parent
cab4c1edbd
commit
56e39bef6b
1 changed files with 30 additions and 17 deletions
|
@ -7,7 +7,6 @@ import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -144,11 +143,6 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
filteredList.add(dataForThisObject.get(0));
|
filteredList.add(dataForThisObject.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use retainAll() rather than clear() plus addAll() in order to retain the subclass ordering
|
|
||||||
// of statementData. Otherwise the list is now ordered by author, whereas collate() assumes
|
|
||||||
// the list is ordered by subclass.
|
|
||||||
//statementData.clear();
|
|
||||||
//statementData.addAll(filteredList);
|
|
||||||
statementData.retainAll(filteredList);
|
statementData.retainAll(filteredList);
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
|
@ -201,31 +195,50 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collate the statements by subclass. NB It is assumed that the statements in statementData
|
// Collate the statements by subclass.
|
||||||
// are ordered by subclass.
|
|
||||||
private SortedMap<String, List<ObjectPropertyStatementTemplateModel>> collate(String subjectUri, String propertyUri,
|
private SortedMap<String, List<ObjectPropertyStatementTemplateModel>> collate(String subjectUri, String propertyUri,
|
||||||
List<Map<String, String>> statementData, VitroRequest vreq, EditingPolicyHelper policyHelper) {
|
List<Map<String, String>> statementData, VitroRequest vreq, EditingPolicyHelper policyHelper) {
|
||||||
|
|
||||||
SortedMap<String, List<ObjectPropertyStatementTemplateModel>> subclassMap =
|
SortedMap<String, List<ObjectPropertyStatementTemplateModel>> subclassMap =
|
||||||
new TreeMap<String, List<ObjectPropertyStatementTemplateModel>>();
|
new TreeMap<String, List<ObjectPropertyStatementTemplateModel>>();
|
||||||
String currentSubclassUri = null;
|
|
||||||
List<ObjectPropertyStatementTemplateModel> currentList = null;
|
|
||||||
String objectKey = getObjectKey();
|
String objectKey = getObjectKey();
|
||||||
|
|
||||||
|
Map<String, String> subclassUrisToNames = new HashMap<String, String>();
|
||||||
|
|
||||||
for (Map<String, String> map : statementData) {
|
for (Map<String, String> map : statementData) {
|
||||||
|
|
||||||
String subclassUri = map.get(SUBCLASS_VARIABLE_NAME);
|
String subclassUri = map.get(SUBCLASS_VARIABLE_NAME);
|
||||||
|
|
||||||
// Rows with no subclass are put into a subclass map with an empty name.
|
// Rows with no subclass are put into a subclass map with an empty name.
|
||||||
if (subclassUri == null) {
|
if (subclassUri == null) {
|
||||||
subclassUri = "";
|
subclassUri = "";
|
||||||
}
|
}
|
||||||
if (!subclassUri.equals(currentSubclassUri)) {
|
|
||||||
currentSubclassUri = subclassUri;
|
// Keep a map of subclass uris to subclass names, so we don't have
|
||||||
currentList = new ArrayList<ObjectPropertyStatementTemplateModel>();
|
// to keep recomputing from the dao each time we hit the same subclass.
|
||||||
String subclassName = getSubclassName(subclassUri, vreq);
|
String subclassName;
|
||||||
subclassMap.put(subclassName, currentList);
|
if (subclassUri.isEmpty()) {
|
||||||
|
subclassName = "";
|
||||||
|
} else if ( subclassUrisToNames.containsKey(subclassUri) ) {
|
||||||
|
subclassName = subclassUrisToNames.get(subclassUri);
|
||||||
|
} else {
|
||||||
|
subclassName = getSubclassName(subclassUri, vreq);
|
||||||
|
subclassUrisToNames.put(subclassUri, subclassName);
|
||||||
}
|
}
|
||||||
currentList.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
|
||||||
|
List<ObjectPropertyStatementTemplateModel> listForThisSubclass;
|
||||||
|
if ( subclassMap.containsKey(subclassName) ) {
|
||||||
|
listForThisSubclass = subclassMap.get(subclassName);
|
||||||
|
} else {
|
||||||
|
listForThisSubclass = new ArrayList<ObjectPropertyStatementTemplateModel>();
|
||||||
|
subclassMap.put(subclassName, listForThisSubclass);
|
||||||
|
}
|
||||||
|
|
||||||
|
listForThisSubclass.add(new ObjectPropertyStatementTemplateModel(subjectUri,
|
||||||
propertyUri, objectKey, map, policyHelper, getTemplateName()));
|
propertyUri, objectKey, map, policyHelper, getTemplateName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return subclassMap;
|
return subclassMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue