mirror of https://github.com/apache/cloudstack.git
Apply suggestions from copilot code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
92a7ac4e9e
commit
066cc1f4b2
|
|
@ -80,6 +80,6 @@ public class CreateServiceOfferingCategoryCmd extends BaseCmd {
|
|||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.Type.ADMIN.ordinal();
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ public class CreateServiceOfferingCmd extends BaseCmd {
|
|||
entityType = ServiceOfferingCategoryResponse.class,
|
||||
required = false,
|
||||
description = "the ID of the service offering category to associate with this offering",
|
||||
since = "4.23")
|
||||
since = "4.23.0")
|
||||
private Long categoryId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -71,6 +71,6 @@ public class DeleteServiceOfferingCategoryCmd extends BaseCmd {
|
|||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.Type.ADMIN.ordinal();
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ public class UpdateServiceOfferingCmd extends BaseCmd implements DomainAndZoneId
|
|||
entityType = ServiceOfferingCategoryResponse.class,
|
||||
required = false,
|
||||
description = "the ID of the service offering category to associate",
|
||||
since = "4.23")
|
||||
since = "4.23.0")
|
||||
private Long categoryId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesC
|
|||
|
||||
@Parameter(name = ApiConstants.SERVICE_OFFERING_CATEGORY_ID,
|
||||
type = CommandType.UUID,
|
||||
entityType = ServiceOfferingCategoryResponse .class,
|
||||
entityType = ServiceOfferingCategoryResponse.class,
|
||||
description = "the ID of the service offering category",
|
||||
since = "4.23.0")
|
||||
private Long categoryId;
|
||||
|
|
|
|||
|
|
@ -287,11 +287,11 @@ public class ServiceOfferingResponse extends BaseResponseWithAnnotations {
|
|||
private String leaseExpiryAction;
|
||||
|
||||
@SerializedName("categoryid")
|
||||
@Param(description = "the ID of the service offering category", since = "4.23")
|
||||
@Param(description = "the ID of the service offering category", since = "4.23.0")
|
||||
private String categoryId;
|
||||
|
||||
@SerializedName("category")
|
||||
@Param(description = "the name of the service offering category", since = "4.23")
|
||||
@Param(description = "the name of the service offering category", since = "4.23.0")
|
||||
private String categoryName;
|
||||
|
||||
public ServiceOfferingResponse() {
|
||||
|
|
|
|||
|
|
@ -28,10 +28,10 @@ CREATE TABLE IF NOT EXISTS `cloud`.`service_offering_category` (
|
|||
CONSTRAINT `uc_service_offering_category__uuid` UNIQUE (`uuid`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
|
||||
|
||||
INSERT INTO `cloud`.`service_offering_category` (id, name, uuid) VALUES (1, 'Default', UUID());
|
||||
|
||||
ALTER TABLE `cloud`.`service_offering` ADD COLUMN `category_id` bigint unsigned NOT NULL DEFAULT 1;
|
||||
ALTER TABLE `cloud`.`service_offering` ADD CONSTRAINT `fk_service_offering__category_id` FOREIGN KEY (`category_id`) REFERENCES `cloud`.`service_offering_category` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
INSERT INTO `cloud`.`service_offering_category` (id, name, uuid) VALUES (1, 'Default', UUID());
|
||||
|
||||
CREATE TABLE `cloud`.`backup_offering_details` (
|
||||
`id` bigint unsigned NOT NULL auto_increment,
|
||||
|
|
|
|||
|
|
@ -9613,6 +9613,12 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
throw new InvalidParameterValueException("Cannot delete the default service offering category");
|
||||
}
|
||||
|
||||
// Check if any service offering is using this category
|
||||
List<ServiceOfferingVO> offeringsUsingCategory = _serviceOfferingDao.listByCategoryId(categoryId);
|
||||
if (offeringsUsingCategory != null && !offeringsUsingCategory.isEmpty()) {
|
||||
throw new InvalidParameterValueException("Cannot delete service offering category with id " + categoryId +
|
||||
" because it is in use by one or more service offerings.");
|
||||
}
|
||||
boolean result = _serviceOfferingCategoryDao.remove(categoryId);
|
||||
if (result) {
|
||||
CallContext.current().setEventDetails("Service offering category id=" + categoryId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue