mchades commented on code in PR #12625:
URL: https://github.com/apache/gravitino/pull/12625#discussion_r4118928638


##########
common/src/main/java/org/apache/gravitino/dto/responses/SemanticModelResponse.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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.gravitino.dto.responses;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.ToString;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.dto.semantic.SemanticModelDTO;
+
+/** Represents a response containing one Semantic Model. */
+@Getter
+@EqualsAndHashCode(callSuper = true)
+@ToString
+public class SemanticModelResponse extends BaseResponse {
+
+  @JsonProperty("semanticModel")
+  private final SemanticModelDTO semanticModel;
+
+  /** Default constructor for Jackson deserialization. */
+  public SemanticModelResponse() {
+    super();
+    this.semanticModel = null;
+  }
+
+  /**
+   * Creates a successful Semantic Model response.
+   *
+   * @param semanticModel The Semantic Model DTO.
+   */
+  public SemanticModelResponse(SemanticModelDTO semanticModel) {
+    super(0);
+    this.semanticModel = semanticModel;
+  }
+
+  @Override
+  public void validate() throws IllegalArgumentException {
+    super.validate();
+    Preconditions.checkArgument(semanticModel != null, "semanticModel must not 
be null");
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(semanticModel.name()),
+        "semanticModel 'name' must not be null or empty");
+    semanticModel.definition();

Review Comment:
   Replaced the side-effect call with an explicit shallow `hasDefinition()` 
presence check, consistent with other response DTO validators. 
`SemanticModelDTO.Builder` now keeps the supplied definition DTO instead of 
round-tripping it through the API model, removing the extra validation-only 
traversal.



##########
server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java:
##########
@@ -990,6 +1005,46 @@ public Response handle(OperationType op, String function, 
String schema, Excepti
     }
   }
 
+  private static class SemanticModelExceptionHandler extends 
BaseExceptionHandler {
+    private static final ExceptionHandler INSTANCE = new 
SemanticModelExceptionHandler();
+
+    private static String getSemanticModelErrorMsg(
+        String semanticModel, String operation, String schema, String reason) {
+      return String.format(
+          "Failed to operate Semantic Model(s)%s operation [%s] under schema 
[%s], reason [%s]",
+          semanticModel, operation, schema, reason);
+    }
+
+    @Override
+    public Response handle(OperationType op, String semanticModel, String 
schema, Exception e) {
+      String formatted = StringUtil.isBlank(semanticModel) ? "" : " [" + 
semanticModel + "]";
+      String errorMsg = getSemanticModelErrorMsg(formatted, op.name(), schema, 
getErrorMsg(e));
+      LOG.warn(errorMsg, e);
+
+      if (e instanceof IllegalArgumentException) {
+        return Utils.illegalArguments(errorMsg, e);
+
+      } else if (e instanceof NotFoundException) {
+        return Utils.notFound(errorMsg, e);
+
+      } else if (e instanceof SemanticModelAlreadyExistsException) {
+        return Utils.alreadyExists(errorMsg, e);
+
+      } else if (e instanceof ForbiddenException) {
+        return Utils.forbidden(errorMsg, e);
+
+      } else if (e instanceof UnsupportedOperationException) {
+        return Utils.unsupportedOperation(errorMsg, e);
+
+      } else if (e instanceof ConnectionFailedException) {
+        return Utils.connectionFailed(errorMsg, e);
+
+      } else {

Review Comment:
   Added the `NotInUseException` mapping to `Utils.notInUse(...)` and a REST 
test covering `MetalakeNotInUseException` as HTTP 409 with `NOT_IN_USE_CODE`.



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