Apply suggestions from copilot code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Hanarion 2026-06-18 20:15:31 +02:00 committed by GitHub
parent 92a7ac4e9e
commit 066cc1f4b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 14 additions and 8 deletions

View File

@ -80,6 +80,6 @@ public class CreateServiceOfferingCategoryCmd extends BaseCmd {
@Override
public long getEntityOwnerId() {
return Account.Type.ADMIN.ordinal();
return Account.ACCOUNT_ID_SYSTEM;
}
}

View File

@ -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;
/////////////////////////////////////////////////////

View File

@ -71,6 +71,6 @@ public class DeleteServiceOfferingCategoryCmd extends BaseCmd {
@Override
public long getEntityOwnerId() {
return Account.Type.ADMIN.ordinal();
return Account.ACCOUNT_ID_SYSTEM;
}
}

View File

@ -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;
/////////////////////////////////////////////////////

View File

@ -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;

View File

@ -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() {

View File

@ -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,

View File

@ -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);