// delete a newly created deployment but only if it's status is failure and it has
// no deployments. This should be rare, or maybe impossible, but in an odd case that
// the deployment fails and they user wants to Cancel as opposed to Finish, let's
// clean up as best as possible.
if ((null != getNewDeployment()) && (0 < getNewDeployment().getId())) {
BundleGWTServiceAsync bundleServer = GWTServiceLookup.getBundleService();
BundleDeploymentCriteria c = new BundleDeploymentCriteria();
c.addFilterId(getNewDeployment().getId());
c.fetchResourceDeployments(true);
bundleServer.findBundleDeploymentsByCriteria(c, //
new AsyncCallback<PageList<BundleDeployment>>() {
public void onSuccess(PageList<BundleDeployment> newDeploymentList) {
if (!newDeploymentList.isEmpty()) {
BundleDeployment newDeployment = newDeploymentList.get(0);
boolean isFailedToLaunch = BundleDeploymentStatus.FAILURE.equals(newDeployment.getStatus())
|| BundleDeploymentStatus.PENDING.equals(newDeployment.getStatus());
boolean hasNoResourceDeployments = ((null == newDeployment.getResourceDeployments()) || newDeployment
.getResourceDeployments().isEmpty());
// go ahead and delete it if it hasn't really done anything but get created.
// otherwise, let folks inspect via the ui and take further action.
// if the deployment can't be deleted then don't try to delete the destination,
// it's now in use by the deployment
if (isFailedToLaunch && hasNoResourceDeployments) {
BundleGWTServiceAsync bundleServer = GWTServiceLookup.getBundleService();
bundleServer.deleteBundleDeployment(newDeployment.getId(), //
new AsyncCallback<Void>() {
public void onSuccess(Void voidReturn) {
deleteNewDestination();
}