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


##########
api/src/main/java/org/apache/gravitino/semantic/OssieDocument.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.semantic;
+
+import com.google.common.base.Preconditions;
+import java.util.Objects;
+import org.apache.gravitino.annotation.Evolving;
+
+/**
+ * An immutable standalone Apache Ossie document containing serialized content 
and its format.
+ *
+ * <p>The content is the document text, not a file path or URL. Constructing 
this value does not
+ * parse or validate its content; validation takes place when the document is 
imported.
+ */
+@Evolving
+public final class OssieDocument {
+
+  private final String content;
+  private final OssieFormat format;
+
+  private OssieDocument(String content, OssieFormat format) {
+    Preconditions.checkArgument(content != null, "content must not be null");

Review Comment:
   Updated to use `StringUtils.isNotBlank(content)` and reject null, empty, and 
whitespace-only content at construction. The Javadoc and tests are updated; 
document parsing still happens during import.



##########
api/src/main/java/org/apache/gravitino/semantic/SemanticModelCatalog.java:
##########
@@ -85,6 +85,55 @@ SemanticModel createSemanticModel(
       throws NoSuchSchemaException, SemanticModelAlreadyExistsException,
           IllegalSemanticModelException;
 
+  /**
+   * Imports a standalone Apache Ossie document as a new Semantic Model in a 
schema.
+   *
+   * <p>The model name comes from the document. Import uses the same 
validation as {@link
+   * #createSemanticModel}; it does not replace an existing model. The 
document is parsed according
+   * to its declared format, without falling back to another format.
+   *
+   * <p>REST clients send {@link OssieDocument#content()} as the raw request 
body, without
+   * JSON-encoding the document string again. The {@code Content-Type} header 
selects the parser:
+   * {@code application/json} for JSON, or {@code application/yaml}, {@code 
application/x-yaml}, or
+   * {@code text/yaml} for YAML. If the header is absent, the REST endpoint 
defaults to YAML.
+   *
+   * <p>A root {@link CustomExtension#GRAVITINO_PROPERTIES_VENDOR} extension 
is consumed as model
+   * properties before creation. Its data must encode a JSON object with 
string values, and at most
+   * one such extension is allowed. Other custom extensions are preserved.
+   *
+   * @param namespace The destination schema namespace.
+   * @param document The standalone Ossie document and its serialization 
format.
+   * @return The created Semantic Model.
+   * @throws NoSuchSchemaException If the schema does not exist.
+   * @throws SemanticModelAlreadyExistsException If a model with the 
document's name already exists.
+   * @throws IllegalSemanticModelException If the document or Semantic Model 
definition is invalid.
+   * @throws UnsupportedOperationException If Ossie import is not supported.
+   */
+  default SemanticModel importOssieSemanticModel(Namespace namespace, 
OssieDocument document)

Review Comment:
   Renamed the methods to `importOssieDocument` and `exportOssieDocument` and 
updated the implementations and call sites. The REST paths and behavior are 
unchanged.



##########
api/src/main/java/org/apache/gravitino/semantic/SemanticModel.java:
##########
@@ -32,6 +32,12 @@
 @Evolving
 public interface SemanticModel extends Auditable {
 
+  /** The property key for the Apache Ossie document version. */
+  String PROPERTY_OSSIE_VERSION = "ossie-version";
+
+  /** The default Apache Ossie document version. */
+  String DEFAULT_OSSIE_VERSION = "0.2.0.dev0";

Review Comment:
   Moved the default version to `OssieVersion.DEFAULT_VERSION` and kept 
`PROPERTY_OSSIE_VERSION` on `SemanticModel`. The default value and version 
handling are unchanged.



##########
core/src/main/java/org/apache/gravitino/semantic/OssieSemanticModelDocumentConverter.java:
##########
@@ -0,0 +1,795 @@
+/*
+ * 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.semantic;
+
+import static 
org.apache.gravitino.semantic.CustomExtension.GRAVITINO_PROPERTIES_VENDOR;
+import static 
org.apache.gravitino.semantic.SemanticModel.DEFAULT_OSSIE_VERSION;
+import static 
org.apache.gravitino.semantic.SemanticModel.PROPERTY_OSSIE_VERSION;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.StreamReadFeature;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.json.JsonMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.dto.requests.SemanticModelCreateRequest;
+import org.apache.gravitino.dto.semantic.SemanticModelDefinitionDTO;
+import org.apache.gravitino.exceptions.IllegalSemanticModelException;
+
+/** Converts between standalone Apache Ossie documents and Gravitino Semantic 
Models. */
+public final class OssieSemanticModelDocumentConverter {

Review Comment:
   Renamed it to `OssieDocumentConverter` and updated the corresponding test 
and references.



##########
core/src/main/java/org/apache/gravitino/catalog/SemanticModelOperationDispatcher.java:
##########
@@ -94,10 +103,16 @@ public SemanticModel createSemanticModel(
       throws NoSuchSchemaException, SemanticModelAlreadyExistsException,
           IllegalSemanticModelException {
     Preconditions.checkArgument(properties != null, "Properties must not be 
null");
+    validatePropertyForCreate(PROPERTIES_METADATA, properties);
+    Map<String, String> effectiveProperties = new HashMap<>(properties);
+    effectiveProperties.putIfAbsent(

Review Comment:
   The default is persisted to retain the version selected at creation if the 
server default changes later. Removing the property opts back into the current 
export default. The property Javadoc now documents both behaviors.



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