Copilot commented on code in PR #13907:
URL: https://github.com/apache/cloudstack/pull/13907#discussion_r4149250591


##########
api/src/main/java/org/apache/cloudstack/api/command/user/bootgroup/UpdateInstanceBootGroupReadinessRuleCmd.java:
##########
@@ -0,0 +1,110 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.user.bootgroup;
+
+import java.util.Collection;
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandResourceType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
+import 
org.apache.cloudstack.api.response.InstanceBootGroupReadinessRuleResponse;
+import org.apache.cloudstack.context.CallContext;
+import 
org.apache.cloudstack.vm.bootgroup.readiness.InstanceBootGroupReadinessRule;
+import org.apache.cloudstack.vm.bootgroup.InstanceBootGroupService;
+
+@APICommand(name = "updateInstanceBootGroupReadinessRule",
+        description = "Updates an Instance Boot Group readiness rule. The rule 
type, Instance Boot Group and item are immutable after creation.",
+        since = "24.0",
+        responseObject = InstanceBootGroupReadinessRuleResponse.class,
+        entityType = {InstanceBootGroupReadinessRule.class},
+        requestHasSensitiveInfo = false,
+        responseHasSensitiveInfo = false,
+        authorized = {RoleType.Admin, RoleType.ResourceAdmin, 
RoleType.DomainAdmin, RoleType.User})
+public class UpdateInstanceBootGroupReadinessRuleCmd extends BaseCmd 
implements UserCmd {
+
+    @Inject
+    InstanceBootGroupService instanceBootGroupService;
+
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = 
InstanceBootGroupReadinessRuleResponse.class, required = true,
+            description = "The ID of the readiness rule")
+    private Long id;
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, 
description = "New name for the readiness rule")
+    private String name;
+
+    @Parameter(name = ApiConstants.ENABLED, type = CommandType.BOOLEAN, 
description = "Whether the rule is enabled")
+    private Boolean enabled;
+
+    @Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, 
description = "Rule-type-specific configuration")
+    private Map details;

Review Comment:
   Using a raw `Map` plus casting via `values().toArray()[0]` is brittle and 
obscures the expected request shape, and can fail with `ClassCastException` if 
the map structure differs (it also loses compile-time type safety). Consider 
tightening the field type to the actual structure produced by `CommandType.MAP` 
in this API and parsing it explicitly (or using a helper used elsewhere in the 
codebase) so the command consistently returns a well-typed `Map<String, 
String>`.



##########
api/src/main/java/org/apache/cloudstack/api/command/user/bootgroup/UpdateInstanceBootGroupReadinessRuleCmd.java:
##########
@@ -0,0 +1,110 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.user.bootgroup;
+
+import java.util.Collection;
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandResourceType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
+import 
org.apache.cloudstack.api.response.InstanceBootGroupReadinessRuleResponse;
+import org.apache.cloudstack.context.CallContext;
+import 
org.apache.cloudstack.vm.bootgroup.readiness.InstanceBootGroupReadinessRule;
+import org.apache.cloudstack.vm.bootgroup.InstanceBootGroupService;
+
+@APICommand(name = "updateInstanceBootGroupReadinessRule",
+        description = "Updates an Instance Boot Group readiness rule. The rule 
type, Instance Boot Group and item are immutable after creation.",
+        since = "24.0",
+        responseObject = InstanceBootGroupReadinessRuleResponse.class,
+        entityType = {InstanceBootGroupReadinessRule.class},
+        requestHasSensitiveInfo = false,
+        responseHasSensitiveInfo = false,
+        authorized = {RoleType.Admin, RoleType.ResourceAdmin, 
RoleType.DomainAdmin, RoleType.User})
+public class UpdateInstanceBootGroupReadinessRuleCmd extends BaseCmd 
implements UserCmd {
+
+    @Inject
+    InstanceBootGroupService instanceBootGroupService;
+
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = 
InstanceBootGroupReadinessRuleResponse.class, required = true,
+            description = "The ID of the readiness rule")
+    private Long id;
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, 
description = "New name for the readiness rule")
+    private String name;
+
+    @Parameter(name = ApiConstants.ENABLED, type = CommandType.BOOLEAN, 
description = "Whether the rule is enabled")
+    private Boolean enabled;
+
+    @Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, 
description = "Rule-type-specific configuration")
+    private Map details;
+
+    public Long getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public Boolean getEnabled() {
+        return enabled;
+    }
+
+    public Map<String, String> getDetails() {
+        if (this.details == null || this.details.isEmpty()) {
+            return null;
+        }
+        Collection<String> paramsCollection = this.details.values();
+        return (Map<String, String>) (paramsCollection.toArray())[0];
+    }

Review Comment:
   Using a raw `Map` plus casting via `values().toArray()[0]` is brittle and 
obscures the expected request shape, and can fail with `ClassCastException` if 
the map structure differs (it also loses compile-time type safety). Consider 
tightening the field type to the actual structure produced by `CommandType.MAP` 
in this API and parsing it explicitly (or using a helper used elsewhere in the 
codebase) so the command consistently returns a well-typed `Map<String, 
String>`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to