response.setStatus(DSResponse.STATUS_FAILURE);
processResponse(request.getRequestId(), response);
}
public void onSuccess(final PageList<Bundle> result) {
BundleGroup unassignedBundleGroup = new BundleGroup();
unassignedBundleGroup.setId(0); // ID=0 is an indicator we use to denote the unassigned group
unassignedBundleGroup.setName(MSG.view_bundle_tree_unassigned_name());
unassignedBundleGroup.setDescription(MSG.view_bundle_tree_unassigned_desc());
// Because findBundleGroupsByCriteria would not have given us all unassigned bundles, we used
// findBundlesByCriteria. But we need to organize our tree structure with groups at the top, so
// we need to put our results aggregated in groups.
HashMap<Integer, BundleGroup> visibleBundleGroups = new HashMap<Integer, BundleGroup>();
for (Bundle bundle : result) {
Set<BundleGroup> bundleBundleGroups = bundle.getBundleGroups();
if (bundleBundleGroups == null || bundleBundleGroups.isEmpty()) {
unassignedBundleGroup.addBundle(bundle);
} else {
for (BundleGroup bundleBundleGroup : bundleBundleGroups) {
BundleGroup theGroup = visibleBundleGroups.get(bundleBundleGroup.getId());
if (theGroup == null) {
visibleBundleGroups.put(bundleBundleGroup.getId(), bundleBundleGroup);
theGroup = bundleBundleGroup;
}
theGroup.addBundle(bundle);
}
}
}
final ArrayList<BundleGroup> allVisibleBundleGroups = new ArrayList<BundleGroup>(visibleBundleGroups.values());