if (parentId == null) {
// there is no parent - we are at the root of the tree
// get the bundles and build the bundle groups (including unassigned) from that
BundleCriteria criteria = new BundleCriteria();
criteria.fetchBundleGroups(true);
bundleService.findBundlesByCriteria(criteria, new AsyncCallback<PageList<Bundle>>() {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_bundle_tree_loadFailure(), caught);
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());
if (!unassignedBundleGroup.getBundles().isEmpty()) {
allVisibleBundleGroups.add(unassignedBundleGroup);
}
BundleGroupCriteria bundleGroupCriteria = new BundleGroupCriteria();
bundleGroupCriteria.addFilterIds(visibleBundleGroups.keySet().toArray(new Integer[0]));
bundleService.findBundleGroupsByCriteria(bundleGroupCriteria, new AsyncCallback<PageList<BundleGroup>>() {
public void onFailure(Throwable caught) {
// just log a message, but keep going, this just means we can't show lock icons where applicable
CoreGUI.getErrorHandler().handleError(MSG.view_bundle_tree_loadFailure(), caught);
}
public void onSuccess(PageList<BundleGroup> result) {
// if any of the bundle group tree nodes represent bundle groups the user isn't allowed
// to see, then mark the node with a locked icon
HashSet<Integer> permittedBundleGroups = new HashSet<Integer>();
for (BundleGroup bg : result) {
permittedBundleGroups.add(bg.getId());
}
ListGridRecord[] dataRecords = buildRecords(allVisibleBundleGroups);
for (ListGridRecord dataRecord : dataRecords) {
// we only want to examine bundle group records - and they are the only ones
// with ID attributes that are a simple number without "_" character.
// Ignore the Unassigned Bundle Group (whose id = "0") - never show a lock for that.
TreeNode dataRecordNode = (TreeNode) dataRecord;
String idString = dataRecordNode.getAttribute("id");
if (!idString.contains("_") && !idString.equals("0")
&& !permittedBundleGroups.contains(Integer.valueOf(idString))) {
dataRecordNode.setIcon(ImageManager.getLockedIcon());
dataRecordNode.setEnabled(false);
}
}
response.setData(dataRecords);
response.setTotalRows(allVisibleBundleGroups.size());
processResponse(request.getRequestId(), response);
}
});
}
});
} else {
String[] splitParentId = parentId.split("_", 3); // <bundleGroupId>_<bundleId>_<and the rest>
final Integer bundleGroupId = Integer.parseInt(splitParentId[0]);
Integer tmp;
try {
tmp = Integer.parseInt(splitParentId[1]);
} catch (NumberFormatException e) {
tmp = null;
}
final Integer bundleId = tmp;
// we are at an inner node, being asked to get the children of it
if (parentId.endsWith("_versions")) {
BundleVersionCriteria criteria = new BundleVersionCriteria();
criteria.addFilterBundleId(bundleId);
bundleService.findBundleVersionsByCriteria(criteria, new AsyncCallback<PageList<BundleVersion>>() {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_bundle_tree_loadFailure(), caught);
response.setStatus(DSResponse.STATUS_FAILURE);
processResponse(request.getRequestId(), response);
}
public void onSuccess(PageList<BundleVersion> result) {
response.setData(buildRecordsForKnownBundle(result, bundleGroupId, bundleId));
response.setTotalRows(result.getTotalSize());
processResponse(request.getRequestId(), response);
}
});
} else if (parentId.endsWith("_deployments")) {
BundleDeploymentCriteria criteria = new BundleDeploymentCriteria();
criteria.fetchBundleVersion(true);
criteria.addFilterBundleId(bundleId);
bundleService.findBundleDeploymentsByCriteria(criteria,
new AsyncCallback<PageList<BundleDeployment>>() {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_bundle_tree_loadFailure(), caught);
}
public void onSuccess(PageList<BundleDeployment> result) {
response.setData(buildRecordsForKnownBundle(result, bundleGroupId, bundleId));
processResponse(request.getRequestId(), response);
}
});
} else if (parentId.endsWith("_destinations")) {
BundleDestinationCriteria criteria = new BundleDestinationCriteria();
criteria.addFilterBundleId(bundleId);
criteria.fetchDeployments(true);
bundleService.findBundleDestinationsByCriteria(criteria,
new AsyncCallback<PageList<BundleDestination>>() {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_bundle_tree_loadFailure(), caught);
}
public void onSuccess(PageList<BundleDestination> result) {
response.setData(buildRecordsForKnownBundle(result, bundleGroupId, bundleId));
processResponse(request.getRequestId(), response);
}
});
} else {
// we are at a child node under a bundle node - its an individual destination or deployment node
BundleCriteria criteria = new BundleCriteria();
criteria.addFilterId(bundleId);
criteria.fetchDestinations(true);
bundleService.findBundlesByCriteria(criteria, new AsyncCallback<PageList<Bundle>>() {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_bundle_tree_loadFailure(), caught);
response.setStatus(DSResponse.STATUS_FAILURE);