Source:
private boolean canRemoveDiskBasedOnImageStorageCheck() { boolean retValue = true; DiskImage diskImage = getDiskImage(); DiskImagesValidator diskImagesValidator = new DiskImagesValidator(Collections.singletonList(diskImage)); if (diskImage.isOvfStore() && !validate(diskImagesValidator.disksInStatus(ImageStatus.ILLEGAL, EngineMessage.ACTION_TYPE_FAILED_OVF_DISK_NOT_IN_APPLICABLE_STATUS))) { return false; } boolean isVmTemplateType = diskImage.getVmEntityType() != null && diskImage.getVmEntityType().isTemplateType(); if (Guid.isNullOrEmpty(getParameters().getStorageDomainId())) { if (isVmTemplateType) { return failCanDoAction(EngineMessage.ACTION_TYPE_FAILED_CANT_DELETE_TEMPLATE_DISK_WITHOUT_SPECIFYING_DOMAIN); } else { getParameters().setStorageDomainId(diskImage.getStorageIds().get(0)); setStorageDomainId(diskImage.getStorageIds().get(0)); } } if (isVmTemplateType) { diskImage.setStorageIds(getDiskImageDao().get(diskImage.getImageId()).getStorageIds()); } if (!diskImage.getStorageIds().contains(getParameters().getStorageDomainId())) { retValue = false; addCanDoActionMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_IS_WRONG); } StorageDomainValidator validator = new StorageDomainValidator(getStorageDomain()); retValue = retValue && validate(validator.isDomainExistAndActive()) && validate(validator.domainIsValidDestination()); if (retValue && diskImage.getImageStatus() == ImageStatus.LOCKED) { retValue = false; addCanDoActionMessage(EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED); } if (retValue && getDisk().getVmEntityType() != null) { if (getDisk().getVmEntityType().isVmType()) { retValue = canRemoveVmImageDisk(); } else if (getDisk().getVmEntityType().isTemplateType()) { retValue = canRemoveTemplateDisk(); } } return retValue; }

Target:
private boolean canRemoveDiskBasedOnImageStorageCheck() { boolean retValue = true; DiskImage diskImage = getDiskImage(); DiskImagesValidator diskImagesValidator = new DiskImagesValidator(Collections.singletonList(diskImage)); if (diskImage.isOvfStore() && !validate(diskImagesValidator.disksInStatus(ImageStatus.ILLEGAL, EngineMessage.ACTION_TYPE_FAILED_OVF_DISK_NOT_IN_APPLICABLE_STATUS))) { return false; } boolean isVmTemplateType = diskImage.getVmEntityType() != null && diskImage.getVmEntityType().isTemplateType(); if (Guid.isNullOrEmpty(getParameters().getStorageDomainId())) { if (isVmTemplateType) { return failCanDoAction(EngineMessage.ACTION_TYPE_FAILED_CANT_DELETE_TEMPLATE_DISK_WITHOUT_SPECIFYING_DOMAIN); } getParameters().setStorageDomainId(diskImage.getStorageIds().get(0)); setStorageDomainId(diskImage.getStorageIds().get(0)); } if (isVmTemplateType) { diskImage.setStorageIds(getDiskImageDao().get(diskImage.getImageId()).getStorageIds()); } if (!diskImage.getStorageIds().contains(getParameters().getStorageDomainId())) { retValue = false; addCanDoActionMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_IS_WRONG); } StorageDomainValidator validator = new StorageDomainValidator(getStorageDomain()); retValue = retValue && validate(validator.isDomainExistAndActive()) && validate(validator.domainIsValidDestination()); if (retValue && diskImage.getImageStatus() == ImageStatus.LOCKED) { retValue = false; addCanDoActionMessage(EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED); } if (retValue && getDisk().getVmEntityType() != null) { if (getDisk().getVmEntityType().isVmType()) { retValue = canRemoveVmImageDisk(); } else if (getDisk().getVmEntityType().isTemplateType()) { retValue = canRemoveTemplateDisk(); } } return retValue; }