int topCommID = 1;
String topCommName = "m1";
boolean curSelectedIsTop = curCommCollSelectedName.equals(topCommName) ? true : false;
Community mtop = Community.find(context, topCommID);
sortedHandleWithSolrName.put(Integer.parseInt(mtop.getHandle().split("/")[1]), topCommName);
sortedSolrNameWithDSpaceObject.put(topCommName, mtop);
Collection[] collections = mtop.getCollections();
for (Collection l : collections) {
String solrName = "l" + l.getID();
if (solrName.equals(curCommCollSelectedName))
curSelectedIsTop = true;
sortedHandleWithSolrName.put(Integer.parseInt(l.getHandle().split("/")[1]), solrName);
sortedSolrNameWithDSpaceObject.put(solrName, l);
}
Community[] communities = mtop.getSubcommunities();
for (Community mm : communities) {
String solrName = "m" + mm.getID();
if (solrName.equals(curCommCollSelectedName))
curSelectedIsTop = true;
sortedHandleWithSolrName.put(Integer.parseInt(mm.getHandle().split("/")[1]), solrName);
sortedSolrNameWithDSpaceObject.put(solrName, mm);
}
if (curSelectedIsTop == false) {
if (curCommCollSelectedType == Constants.COMMUNITY) {
Community msel = Community.find(context, curCommCollSelectedID);
Community[] parents = msel.getAllParents();
if (parents.length < 2) {
log.error("Something is wrong: this should not happen.");
}
Community topParent = parents[parents.length - 2];
curCommCollSelectedName = "m" + topParent.getID();
} else {
// Supposing Constants.COLLECTION
Collection lsel = Collection.find(context, curCommCollSelectedID);
Community firstParent = lsel.getCommunities()[0];
Community[] parents = firstParent.getAllParents();
if (parents.length == 0) {
//log.error("Something is wrong: this should not happen.");
//firstParent is a top community.
curCommCollSelectedName = "m" + firstParent.getID();
} else if (parents.length == 1) {
//firstParent is a second level community.
curCommCollSelectedName = "m" + firstParent.getID();
} else {
// get second level parent
Community topParent = parents[parents.length - 2];
curCommCollSelectedName = "m" + topParent.getID();
}
}
}
// Iterator<FacetField.Count> iter = sortedValues.values().iterator();
Iterator<String> iter = sortedHandleWithSolrName.values().iterator();