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 noStorageDomainInParams = (getParameters().getStorageDomainId() == null) || (Guid.Empty.equals(getParameters().getStorageDomainId())); if (diskImage.getVmEntityType() != null && diskImage.getVmEntityType().isTemplateType()) { if (noStorageDomainInParams) { addCanDoActionMessage(EngineMessage.ACTION_TYPE_FAILED_CANT_DELETE_TEMPLATE_DISK_WITHOUT_SPECIFYING_DOMAIN); return false; } diskImage.setStorageIds(getDiskImageDao().get(diskImage.getImageId()).getStorageIds()); } else if (noStorageDomainInParams) { getParameters().setStorageDomainId(diskImage.getStorageIds().get(0)); setStorageDomainId(diskImage.getStorageIds().get(0)); } 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); } 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; }