d : dialects) {
- String dialect = (String) d.get("dialect");
- Object exprValue = d.get("expression");
- String expression = exprValue != null ? exprValue.toString() : null;
- result.add(new DialectExpression(dialect, expression));
- }
- return result;
- }
-}
diff --git a/converters/polaris/src/main/java/org/apache/ossie/converter/polaris/OsiYamlGenerator.java b/converters/polaris/src/main/java/org/apache/ossie/converter/polaris/OsiYamlGenerator.java
deleted file mode 100644
index 2533b26e..00000000
--- a/converters/polaris/src/main/java/org/apache/ossie/converter/polaris/OsiYamlGenerator.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * 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.ossie.converter.polaris;
-
-import org.apache.ossie.converter.polaris.model.OsiModel;
-import org.apache.ossie.converter.polaris.model.OsiModel.*;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Generates Ossie YAML from an {@link OsiModel}.
- *
- * Produces well-formatted YAML that conforms to the Ossie specification.
- */
-public class OsiYamlGenerator {
-
- /**
- * Generate Ossie YAML string from a model.
- */
- public String generate(OsiModel model) {
- StringBuilder sb = new StringBuilder();
- sb.append("version: \"").append(model.getVersion()).append("\"\n\n");
- sb.append("semantic_model:\n");
-
- for (SemanticModel sm : model.getSemanticModels()) {
- generateSemanticModel(sb, sm);
- }
-
- return sb.toString();
- }
-
- private void generateSemanticModel(StringBuilder sb, SemanticModel sm) {
- sb.append(" - name: ").append(sm.getName()).append("\n");
- if (sm.getDescription() != null) {
- sb.append(" description: \"").append(escapeYaml(sm.getDescription())).append("\"\n");
- }
-
- // Datasets
- if (!sm.getDatasets().isEmpty()) {
- sb.append(" datasets:\n");
- for (Dataset ds : sm.getDatasets()) {
- generateDataset(sb, ds);
- }
- }
-
- // Relationships
- if (!sm.getRelationships().isEmpty()) {
- sb.append(" relationships:\n");
- for (Relationship rel : sm.getRelationships()) {
- generateRelationship(sb, rel);
- }
- }
-
- // Metrics
- if (!sm.getMetrics().isEmpty()) {
- sb.append(" metrics:\n");
- for (Metric metric : sm.getMetrics()) {
- generateMetric(sb, metric);
- }
- }
- }
-
- private void generateDataset(StringBuilder sb, Dataset ds) {
- sb.append(" - name: ").append(ds.getName()).append("\n");
- sb.append(" source: ").append(ds.getSource()).append("\n");
-
- if (!ds.getPrimaryKey().isEmpty()) {
- sb.append(" primary_key: [").append(String.join(", ", ds.getPrimaryKey())).append("]\n");
- }
-
- if (!ds.getUniqueKeys().isEmpty()) {
- sb.append(" unique_keys:\n");
- for (List uk : ds.getUniqueKeys()) {
- sb.append(" - [").append(String.join(", ", uk)).append("]\n");
- }
- }
-
- if (ds.getDescription() != null) {
- sb.append(" description: \"").append(escapeYaml(ds.getDescription())).append("\"\n");
- }
-
- if (!ds.getFields().isEmpty()) {
- sb.append(" fields:\n");
- for (Field field : ds.getFields()) {
- generateField(sb, field);
- }
- }
-
- if (!ds.getCustomExtensions().isEmpty()) {
- sb.append(" custom_extensions:\n");
- for (CustomExtension ext : ds.getCustomExtensions()) {
- sb.append(" - vendor_name: ").append(ext.getVendorName()).append("\n");
- sb.append(" data: '").append(ext.getData()).append("'\n");
- }
- }
- }
-
- private void generateField(StringBuilder sb, Field field) {
- sb.append(" - name: ").append(field.getName()).append("\n");
-
- if (!field.getExpressions().isEmpty()) {
- sb.append(" expression:\n");
- sb.append(" dialects:\n");
- for (DialectExpression de : field.getExpressions()) {
- sb.append(" - dialect: ").append(de.getDialect()).append("\n");
- sb.append(" expression: ");
- String expr = de.getExpression();
- if (needsQuoting(expr)) {
- sb.append("\"").append(escapeYaml(expr)).append("\"");
- } else {
- sb.append(expr);
- }
- sb.append("\n");
- }
- }
-
- if (field.isTime()) {
- sb.append(" dimension:\n");
- sb.append(" is_time: true\n");
- }
-
- if (field.getDescription() != null) {
- sb.append(" description: \"").append(escapeYaml(field.getDescription())).append("\"\n");
- }
- }
-
- private void generateRelationship(StringBuilder sb, Relationship rel) {
- sb.append(" - name: ").append(rel.getName()).append("\n");
- sb.append(" from: ").append(rel.getFrom()).append("\n");
- sb.append(" to: ").append(rel.getTo()).append("\n");
- sb.append(" from_columns: [").append(String.join(", ", rel.getFromColumns())).append("]\n");
- sb.append(" to_columns: [").append(String.join(", ", rel.getToColumns())).append("]\n");
- }
-
- private void generateMetric(StringBuilder sb, Metric metric) {
- sb.append(" - name: ").append(metric.getName()).append("\n");
-
- if (!metric.getExpressions().isEmpty()) {
- sb.append(" expression:\n");
- sb.append(" dialects:\n");
- for (DialectExpression de : metric.getExpressions()) {
- sb.append(" - dialect: ").append(de.getDialect()).append("\n");
- sb.append(" expression: ");
- String expr = de.getExpression();
- if (needsQuoting(expr)) {
- sb.append("\"").append(escapeYaml(expr)).append("\"");
- } else {
- sb.append(expr);
- }
- sb.append("\n");
- }
- }
-
- if (metric.getDescription() != null) {
- sb.append(" description: \"").append(escapeYaml(metric.getDescription())).append("\"\n");
- }
- }
-
- private boolean needsQuoting(String value) {
- if (value == null) return false;
- return value.contains("'") || value.contains("\"") || value.contains(":")
- || value.contains("{") || value.contains("}") || value.contains("[")
- || value.contains("]") || value.contains(",") || value.contains("&")
- || value.contains("*") || value.contains("#") || value.contains("?")
- || value.contains("|") || value.contains("-") || value.contains("<")
- || value.contains(">") || value.contains("=") || value.contains("!")
- || value.contains("%") || value.contains("@") || value.contains("`")
- || value.contains(" ");
- }
-
- private String escapeYaml(String value) {
- if (value == null) return "";
- return value.replace("\\", "\\\\").replace("\"", "\\\"");
- }
-}
diff --git a/converters/polaris/src/main/java/org/apache/ossie/converter/polaris/model/OsiModel.java b/converters/polaris/src/main/java/org/apache/ossie/converter/polaris/model/OsiModel.java
deleted file mode 100644
index e36a5e1d..00000000
--- a/converters/polaris/src/main/java/org/apache/ossie/converter/polaris/model/OsiModel.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * 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.ossie.converter.polaris.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Java representation of an Ossie semantic model parsed from YAML.
- */
-public class OsiModel {
-
- private String version;
- private List semanticModels = new ArrayList<>();
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public List getSemanticModels() {
- return semanticModels;
- }
-
- public void setSemanticModels(List semanticModels) {
- this.semanticModels = semanticModels;
- }
-
- // -----------------------------------------------------------------------
- // Nested model classes
- // -----------------------------------------------------------------------
-
- public static class SemanticModel {
- private String name;
- private String description;
- private List datasets = new ArrayList<>();
- private List relationships = new ArrayList<>();
- private List metrics = new ArrayList<>();
-
- public String getName() { return name; }
- public void setName(String name) { this.name = name; }
-
- public String getDescription() { return description; }
- public void setDescription(String description) { this.description = description; }
-
- public List getDatasets() { return datasets; }
- public void setDatasets(List datasets) { this.datasets = datasets; }
-
- public List getRelationships() { return relationships; }
- public void setRelationships(List relationships) { this.relationships = relationships; }
-
- public List getMetrics() { return metrics; }
- public void setMetrics(List metrics) { this.metrics = metrics; }
- }
-
- public static class Dataset {
- private String name;
- private String source;
- private List primaryKey = new ArrayList<>();
- private List> uniqueKeys = new ArrayList<>();
- private String description;
- private List fields = new ArrayList<>();
- private List customExtensions = new ArrayList<>();
-
- public String getName() { return name; }
- public void setName(String name) { this.name = name; }
-
- public String getSource() { return source; }
- public void setSource(String source) { this.source = source; }
-
- public List getPrimaryKey() { return primaryKey; }
- public void setPrimaryKey(List primaryKey) { this.primaryKey = primaryKey; }
-
- public List> getUniqueKeys() { return uniqueKeys; }
- public void setUniqueKeys(List> uniqueKeys) { this.uniqueKeys = uniqueKeys; }
-
- public String getDescription() { return description; }
- public void setDescription(String description) { this.description = description; }
-
- public List getFields() { return fields; }
- public void setFields(List fields) { this.fields = fields; }
-
- public List getCustomExtensions() { return customExtensions; }
- public void setCustomExtensions(List customExtensions) { this.customExtensions = customExtensions; }
- }
-
- public static class Field {
- private String name;
- private String description;
- private List expressions = new ArrayList<>();
- private boolean isTime;
-
- public String getName() { return name; }
- public void setName(String name) { this.name = name; }
-
- public String getDescription() { return description; }
- public void setDescription(String description) { this.description = description; }
-
- public List getExpressions() { return expressions; }
- public void setExpressions(List expressions) { this.expressions = expressions; }
-
- public boolean isTime() { return isTime; }
- public void setTime(boolean time) { isTime = time; }
- }
-
- public static class DialectExpression {
- private String dialect;
- private String expression;
-
- public DialectExpression() {}
-
- public DialectExpression(String dialect, String expression) {
- this.dialect = dialect;
- this.expression = expression;
- }
-
- public String getDialect() { return dialect; }
- public void setDialect(String dialect) { this.dialect = dialect; }
-
- public String getExpression() { return expression; }
- public void setExpression(String expression) { this.expression = expression; }
- }
-
- public static class Relationship {
- private String name;
- private String from;
- private String to;
- private List fromColumns = new ArrayList<>();
- private List toColumns = new ArrayList<>();
-
- public String getName() { return name; }
- public void setName(String name) { this.name = name; }
-
- public String getFrom() { return from; }
- public void setFrom(String from) { this.from = from; }
-
- public String getTo() { return to; }
- public void setTo(String to) { this.to = to; }
-
- public List getFromColumns() { return fromColumns; }
- public void setFromColumns(List fromColumns) { this.fromColumns = fromColumns; }
-
- public List getToColumns() { return toColumns; }
- public void setToColumns(List toColumns) { this.toColumns = toColumns; }
- }
-
- public static class Metric {
- private String name;
- private String description;
- private List expressions = new ArrayList<>();
-
- public String getName() { return name; }
- public void setName(String name) { this.name = name; }
-
- public String getDescription() { return description; }
- public void setDescription(String description) { this.description = description; }
-
- public List getExpressions() { return expressions; }
- public void setExpressions(List expressions) { this.expressions = expressions; }
- }
-
- public static class CustomExtension {
- private String vendorName;
- private String data;
-
- public CustomExtension() {}
-
- public CustomExtension(String vendorName, String data) {
- this.vendorName = vendorName;
- this.data = data;
- }
-
- public String getVendorName() { return vendorName; }
- public void setVendorName(String vendorName) { this.vendorName = vendorName; }
-
- public String getData() { return data; }
- public void setData(String data) { this.data = data; }
- }
-}
diff --git a/core-spec/osi-schema.json b/core-spec/osi-schema.json
index 385e18a9..b59580e7 100644
--- a/core-spec/osi-schema.json
+++ b/core-spec/osi-schema.json
@@ -1,6 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/apache/ossie/core-spec/osi-schema.json",
+ "javaName": "OsiModel",
"title": "Apache Ossie Core Metadata Specification",
"description": "JSON Schema for validating Apache Ossie semantic model definitions",
"type": "object",