You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2023/03/29 13:22:15 UTC
[airavata-data-catalog] branch custos-integration updated (115764e -> b493b4f)
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a change to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
from 115764e Merge pull request #22 from apache/calcite
new 454ca5a Adding custos sharing lib
new 5fbb510 implement sharing logic
new 4ae109c Merge branch 'custos-integration' into main
new b493b4f Merge pull request #17 from isururanawaka/main
The 36 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.gitignore | 4 +
data-catalog-api/server/pom.xml | 15 +++
.../api/DataCatalogApiServiceApplication.java | 7 ++
.../datacatalog/api/sharing/SharingManager.java | 17 ++--
.../api/sharing/SharingManagerImpl.java | 102 +++++++++++++++++++++
.../src/main/resources/application.properties | 2 +-
.../stubs/src/main/proto/DataCatalogAPI.proto | 1 +
pom.xml | 2 +-
8 files changed, 140 insertions(+), 10 deletions(-)
create mode 100644 data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManagerImpl.java
[airavata-data-catalog] 09/36: Fixing issue with 'user' being reserved word by changing table name
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit dd0e7707181e94dc6cc462236e69c7c3205c8a55
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Feb 8 17:59:56 2023 -0500
Fixing issue with 'user' being reserved word by changing table name
---
.../java/org/apache/airavata/datacatalog/api/model/UserEntity.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/UserEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/UserEntity.java
index 99a642a..cdc24f1 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/UserEntity.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/UserEntity.java
@@ -10,7 +10,8 @@ import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
@Entity
-@Table(name = "user")
+// 'user' is a reserved word, so naming this table 'user_table'
+@Table(name = "user_table")
public class UserEntity {
@Id
[airavata-data-catalog] 16/36: moved test package
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 011dff88095c38a309db9d43ed4266dc2381b204
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Feb 15 15:31:38 2023 -0500
moved test package
---
.../api}/DataCatalogApiServerApplicationTests.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/data-catalog-api/server/src/test/java/org/apache/airavata/datacatalogapiserver/DataCatalogApiServerApplicationTests.java b/data-catalog-api/server/src/test/java/org/apache/airavata/datacatalog/api/DataCatalogApiServerApplicationTests.java
similarity index 79%
rename from data-catalog-api/server/src/test/java/org/apache/airavata/datacatalogapiserver/DataCatalogApiServerApplicationTests.java
rename to data-catalog-api/server/src/test/java/org/apache/airavata/datacatalog/api/DataCatalogApiServerApplicationTests.java
index f7ed907..00bd885 100644
--- a/data-catalog-api/server/src/test/java/org/apache/airavata/datacatalogapiserver/DataCatalogApiServerApplicationTests.java
+++ b/data-catalog-api/server/src/test/java/org/apache/airavata/datacatalog/api/DataCatalogApiServerApplicationTests.java
@@ -1,4 +1,4 @@
-package org.apache.airavata.datacatalogapiserver;
+package org.apache.airavata.datacatalog.api;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
[airavata-data-catalog] 05/36: Initial work on sharing management interface
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 2e6393961620230cfbdc9ad5f4f799904905a728
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Thu Jan 26 11:19:20 2023 -0500
Initial work on sharing management interface
---
.../datacatalog/api/model/DataProductEntity.java | 11 ++-
.../airavata/datacatalog/api/model/UserEntity.java | 79 ++++++++++++++++
.../api/service/DataCatalogAPIService.java | 4 +
.../datacatalog/api/sharing/SharingManager.java | 102 +++++++++++++++++++++
.../stubs/src/main/proto/DataCatalogAPI.proto | 18 ++++
5 files changed, 209 insertions(+), 5 deletions(-)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
index c9a67d2..65b24e7 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
@@ -22,27 +22,28 @@ import jakarta.persistence.UniqueConstraint;
public class DataProductEntity {
@Id
- @SequenceGenerator(name="data_product_data_product_id_seq", sequenceName = "data_product_data_product_id_seq", allocationSize = 1)
+ @SequenceGenerator(name = "data_product_data_product_id_seq", sequenceName = "data_product_data_product_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "data_product_data_product_id_seq")
- @Column(name="data_product_id")
+ @Column(name = "data_product_id")
private Long dataProductId;
@ManyToOne(optional = true)
- @JoinColumn(name="parent_data_product_id", referencedColumnName = "data_product_id", nullable = true)
+ @JoinColumn(name = "parent_data_product_id", referencedColumnName = "data_product_id", nullable = true)
private DataProductEntity parentDataProductEntity;
@Basic
- @Column(name="external_id", nullable = false)
+ @Column(name = "external_id", nullable = false)
private String externalId;
@Basic
- @Column(name="name", nullable = false)
+ @Column(name = "name", nullable = false)
private String name;
@Type(JsonType.class)
@Column(name = "metadata", columnDefinition = "jsonb")
private JsonNode metadata;
+ // TODO: ManyToOne mapping to owner: UserEntity
public Long getDataProductId() {
return dataProductId;
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/UserEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/UserEntity.java
new file mode 100644
index 0000000..0540ab2
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/UserEntity.java
@@ -0,0 +1,79 @@
+package org.apache.airavata.datacatalog.api.model;
+
+import jakarta.persistence.Basic;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.SequenceGenerator;
+import jakarta.persistence.Table;
+
+@Entity
+@Table(name = "user")
+public class UserEntity {
+
+ @Id
+ @SequenceGenerator(name = "user_user_id_seq", sequenceName = "user_user_id_seq", allocationSize = 1)
+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_user_id_seq")
+ @Column(name = "user_id")
+ private Long userId;
+
+ @Basic
+ @Column(name = "external_id", nullable = false)
+ private String externalId;
+
+ @Basic
+ @Column(name = "name", nullable = false)
+ private String name;
+
+ public Long getUserId() {
+ return userId;
+ }
+
+ public void setUserId(Long userId) {
+ this.userId = userId;
+ }
+
+ public String getExternalId() {
+ return externalId;
+ }
+
+ public void setExternalId(String externalId) {
+ this.externalId = externalId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((userId == null) ? 0 : userId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ UserEntity other = (UserEntity) obj;
+ if (userId == null) {
+ if (other.userId != null)
+ return false;
+ } else if (!userId.equals(other.userId))
+ return false;
+ return true;
+ }
+
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index fa979a6..e14c437 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -30,6 +30,7 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
public void createDataProduct(DataProductCreateRequest request,
StreamObserver<DataProductCreateResponse> responseObserver) {
+ // TODO: SharingManager.resolveUser
logger.info("Creating data product {}", request.getDataProduct());
DataProductEntity dataProductEntity = new DataProductEntity();
dataProductEntity.setExternalId(UUID.randomUUID().toString());
@@ -51,6 +52,9 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
}
DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProductEntity);
+ // TODO: SharingManager.grantPermissionToUser(userInfo, dataProduct,
+ // Permission.OWNER)
+
DataProductCreateResponse.Builder responseBuilder = DataProductCreateResponse.newBuilder();
responseBuilder.getDataProductBuilder()
.setDataProductId(savedDataProductEntity.getExternalId())
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManager.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManager.java
new file mode 100644
index 0000000..cbe470e
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManager.java
@@ -0,0 +1,102 @@
+package org.apache.airavata.datacatalog.api.sharing;
+
+import org.apache.airavata.datacatalog.api.DataProduct;
+import org.apache.airavata.datacatalog.api.GroupInfo;
+import org.apache.airavata.datacatalog.api.Permission;
+import org.apache.airavata.datacatalog.api.UserInfo;
+import org.apache.airavata.datacatalog.api.model.UserEntity;
+
+public interface SharingManager {
+
+ /**
+ * Get or create a {@link UserEntity}.
+ *
+ * @param userInfo
+ * @return
+ */
+ UserEntity resolveUser(UserInfo userInfo);
+
+ /**
+ * Return true if the user has access to the data product with the given
+ * permission.
+ *
+ * @param userInfo
+ * @param dataProduct
+ * @param permission
+ * @return
+ */
+ boolean userHasAccess(UserInfo userInfo, DataProduct dataProduct, Permission permission);
+
+ /**
+ * Return the name of the database view that includes sharing information
+ * for each data product. The view should contain the following columns:
+ * data_product_id, user_id, and permission_id where the permission_id
+ * should be a number as defined in the {@link Permission} enum.
+ *
+ * @return
+ */
+ String getDataProductSharingView();
+
+ /**
+ * Grant permission to the user for the given data product.
+ *
+ * @param userInfo
+ * @param dataProduct
+ * @param permission
+ */
+ void grantPermissionToUser(UserInfo userInfo, DataProduct dataProduct, Permission permission);
+
+ /**
+ * Revoke permission from the user for the given data product.
+ *
+ * @param userInfo
+ * @param dataProduct
+ * @param permission
+ */
+ void revokePermissionFromUser(UserInfo userInfo, DataProduct dataProduct, Permission permission);
+
+ /**
+ * Grant permission to the group for the given data product.
+ *
+ * @param groupInfo
+ * @param dataProduct
+ * @param permission
+ */
+ void grantPermissionToGroup(GroupInfo groupInfo, DataProduct dataProduct, Permission permission);
+
+ /**
+ * Revoke permission from the group for the given data product.
+ *
+ * @param groupInfo
+ * @param dataProduct
+ * @param permission
+ */
+ void revokePermissionFromGroup(GroupInfo groupInfo, DataProduct dataProduct, Permission permission);
+
+ /**
+ * Return true if public access at the given permission is granted for the
+ * given data product. Public access means anonymous access; no user information
+ * provided in the API request.
+ *
+ * @param dataProduct
+ * @param permission
+ * @return
+ */
+ boolean hasPublicAccess(DataProduct dataProduct, Permission permission);
+
+ /**
+ * Grant public access to the given data product.
+ *
+ * @param dataProduct
+ * @param permission
+ */
+ void grantPublicAccess(DataProduct dataProduct, Permission permission);
+
+ /**
+ * Revoke public access from the given data product.
+ *
+ * @param dataProduct
+ * @param permission
+ */
+ void revokePublicAccess(DataProduct dataProduct, Permission permission);
+}
diff --git a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
index 43854f9..bc8f656 100644
--- a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@ -20,6 +20,24 @@ syntax = "proto3";
option java_multiple_files = true;
option java_package = "org.apache.airavata.datacatalog.api";
+message UserInfo {
+ string user_id = 1;
+ optional string tenant_id = 2;
+}
+
+message GroupInfo {
+ string group_id = 1;
+ optional string tenant_id = 2;
+}
+
+enum Permission {
+ OWNER = 0;
+ READ = 1;
+ READ_METADATA = 2;
+ WRITE = 3;
+ WRITE_METADATA = 4;
+ MANAGE_SHARING = 5;
+}
message DataProduct {
string data_product_id = 1;
[airavata-data-catalog] 25/36: Initial result of running pg query through Calcite
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit c3abe75b4e3343e5de252ac45fad5d4a23706dd8
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Fri Feb 24 09:48:48 2023 -0500
Initial result of running pg query through Calcite
---
data-catalog-api/server/pom.xml | 5 +
.../datacatalog/api/query/MetadataQueryParser.java | 138 +++++++++++++++++++++
2 files changed, 143 insertions(+)
diff --git a/data-catalog-api/server/pom.xml b/data-catalog-api/server/pom.xml
index d2b0ce1..cdaf834 100644
--- a/data-catalog-api/server/pom.xml
+++ b/data-catalog-api/server/pom.xml
@@ -62,6 +62,11 @@
<artifactId>jackson-module-jakarta-xmlbind-annotations</artifactId>
<version>2.14.1</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.calcite</groupId>
+ <artifactId>calcite-core</artifactId>
+ <version>1.32.0</version>
+ </dependency>
</dependencies>
<build>
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataQueryParser.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataQueryParser.java
new file mode 100644
index 0000000..57d2b17
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataQueryParser.java
@@ -0,0 +1,138 @@
+package org.apache.airavata.datacatalog.api.query;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+import org.apache.calcite.adapter.jdbc.JdbcSchema;
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.RelRoot;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.sql.SqlExplainFormat;
+import org.apache.calcite.sql.SqlExplainLevel;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.dialect.PostgresqlSqlDialect;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.tools.FrameworkConfig;
+import org.apache.calcite.tools.Frameworks;
+import org.apache.calcite.tools.Planner;
+import org.apache.calcite.tools.RelConversionException;
+import org.apache.calcite.tools.RelRunner;
+import org.apache.calcite.tools.ValidationException;
+
+public class MetadataQueryParser {
+ private static final String POSTGRESQL_SCHEMA = "PUBLIC";
+
+ public static void main(String[] args)
+ throws SqlParseException, SQLException, ValidationException, RelConversionException {
+ // SqlParser parser = SqlParser.create(
+ // "SELECT * FROM smilesdb WHERE created_date > '2020-01-01' AND absorb < 300.0
+ // ORDER BY created_date desc LIMIT 10");
+ // SqlNode query = parser.parseQuery();
+ // System.out.println(query.toSqlString(PostgresqlSqlDialect.DEFAULT));
+
+ // Properties props = new Properties();
+ // props.setProperty("currentSchema", "data_catalog");
+ // props.setProperty("password", "secret");
+ // props.setProperty("ssl", "true");
+ // Connection connection = DriverManager.getConnection("jdbc:calcite:", props);
+ Connection connection = DriverManager.getConnection("jdbc:calcite:");
+ // Set the default schema for the connection
+ // connection.setSchema("data_catalog");
+ // Unwrap our connection using the CalciteConnection
+ CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
+ // calciteConnection.setSchema("data_catalog");
+
+ // Get a pointer to our root schema for our Calcite Connection
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
+ // SchemaPlus rootSchema = Frameworks.createRootSchema(false);
+
+ // Instantiate a data source, this can be autowired in using Spring as well
+ DataSource postgresDataSource = JdbcSchema.dataSource(
+ "jdbc:postgresql://localhost/data_catalog",
+ "org.postgresql.Driver", // Change this if you want to use something like MySQL, Oracle,
+ // etc.
+ "postgres", // username
+ "example" // password
+ );
+ // JdbcSchema jdbcSchema = JdbcSchema.create(rootSchema, POSTGRESQL_SCHEMA,
+ // postgresDataSource, null, null);
+ // System.out.println("tables: " + jdbcSchema.getTableNames());
+ // rootSchema.add(POSTGRESQL_SCHEMA,
+ // JdbcSchema.create(rootSchema, POSTGRESQL_SCHEMA, postgresDataSource, null,
+ // null));
+ // rootSchema.add("data_product", jdbcSchema.getTable("data_product"));
+ JdbcSchema dcSchema = JdbcSchema.create(rootSchema, "data_catalog", postgresDataSource, null, null);
+ rootSchema.add("data_catalog", dcSchema);
+
+ System.out.println("subschemas: " + rootSchema.getSubSchemaNames());
+
+ FrameworkConfig config = Frameworks.newConfigBuilder()
+ .defaultSchema(rootSchema)
+ .parserConfig(PostgresqlSqlDialect.DEFAULT.configureParser(SqlParser.config()))
+ // .parserConfig(SqlParser.Config.DEFAULT.withCaseSensitive(false).withQuoting(Quoting.))
+ .build();
+ // String query = "SELECT * FROM public.\"data_product\" WHERE
+ // \"data_product_id\" = 1";
+ String query = "SELECT * FROM data_catalog.data_product WHERE data_product_id = 1";
+ // String query = "SELECT * FROM data_product WHERE data_product_id = 1";
+ Planner planner = Frameworks.getPlanner(config);
+ SqlNode parse = planner.parse(query);
+
+ // Change unqualified table referenced into qualified
+ // final SqlNode transformedNode = parse.accept(
+ // new SqlShuttle() {
+ // @Override
+ // public SqlNode visit(SqlIdentifier id) {
+ // System.out.println("id: " + id);
+ // System.out.println("id.names: " + id.names);
+ // if (id.names.equals(Collections.singletonList("data_product"))) {
+ // return new SqlIdentifier(Arrays.asList("data_catalog", "data_product"),
+ // id.getParserPosition());
+ // }
+ // return id;
+ // }
+ // });
+ System.out.println(parse.toSqlString(PostgresqlSqlDialect.DEFAULT));
+ // System.out.println(parse.toString());
+
+ SqlNode validate = planner.validate(parse);
+ RelRoot relRoot = planner.rel(validate);
+ // RelNode rel = relRoot.project();
+ RelNode rel = relRoot.rel;
+ System.out.println(RelOptUtil.dumpPlan("", rel, SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES));
+
+ final RelRunner runner = connection.unwrap(RelRunner.class);
+ PreparedStatement ps = runner.prepareStatement(rel);
+
+ ps.executeQuery();
+
+ ResultSet resultSet = ps.getResultSet();
+
+ final StringBuilder buf = new StringBuilder();
+
+ while (resultSet.next()) {
+
+ int columnCount = resultSet.getMetaData().getColumnCount();
+
+ for (int i = 1; i <= columnCount; i++) {
+
+ buf.append(i > 1 ? "; " : "")
+ .append(resultSet.getMetaData().getColumnLabel(i))
+ .append("=")
+ .append(resultSet.getObject(i));
+ }
+
+ System.out.println("Entry: " + buf.toString());
+
+ buf.setLength(0);
+ }
+ }
+}
[airavata-data-catalog] 01/36: Initial commit, createDataProduct implemented
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 96785f9fe0b4db9841a953c2e34590106b7e7156
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Jan 23 15:30:03 2023 -0500
Initial commit, createDataProduct implemented
---
.gitignore | 3 +
data-catalog-api/client/pom.xml | 29 +++++++
.../api/client/DataCatalogAPIClient.java | 49 ++++++++++++
data-catalog-api/pom.xml | 39 +++++++++
data-catalog-api/server/pom.xml | 68 ++++++++++++++++
.../api/DataCatalogApiServiceApplication.java | 13 +++
.../datacatalog/api/model/DataProductEntity.java | 92 ++++++++++++++++++++++
.../api/repository/DataProductRepository.java | 10 +++
.../api/service/DataCatalogAPIService.java | 53 +++++++++++++
.../src/main/resources/application.properties | 5 ++
.../server/src/main/resources/logback.xml | 54 +++++++++++++
.../DataCatalogApiServerApplicationTests.java | 13 +++
data-catalog-api/stubs/pom.xml | 87 ++++++++++++++++++++
.../stubs/src/main/proto/DataCatalogAPI.proto | 39 +++++++++
pom.xml | 54 +++++++++++++
15 files changed, 608 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..79edcba
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+target
+.vscode
+logs
diff --git a/data-catalog-api/client/pom.xml b/data-catalog-api/client/pom.xml
new file mode 100644
index 0000000..431b57a
--- /dev/null
+++ b/data-catalog-api/client/pom.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>data-catalog-api</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>data-catalog-api-client</artifactId>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>data-catalog-api-stubs</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </dependency>
+ <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+
+ </dependencies>
+
+</project>
diff --git a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
new file mode 100644
index 0000000..5ba7ebc
--- /dev/null
+++ b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
@@ -0,0 +1,49 @@
+package org.apache.airavata.datacatalog.api.client;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.grpc.Channel;
+import io.grpc.ManagedChannel;
+import io.grpc.ManagedChannelBuilder;
+
+import java.text.MessageFormat;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc;
+import org.apache.airavata.datacatalog.api.DataProduct;
+import org.apache.airavata.datacatalog.api.DataProductCreateRequest;
+import org.apache.airavata.datacatalog.api.DataProductCreateResponse;
+import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc.DataCatalogAPIServiceBlockingStub;;
+
+public class DataCatalogAPIClient {
+
+ private static final Logger logger = LoggerFactory.getLogger(DataCatalogAPIClient.class);
+
+ private final DataCatalogAPIServiceBlockingStub blockingStub;
+
+ public DataCatalogAPIClient(Channel channel) {
+ blockingStub = DataCatalogAPIServiceGrpc.newBlockingStub(channel);
+ }
+
+ public DataProduct createDataProduct(DataProduct dataProduct) {
+ DataProductCreateRequest request = DataProductCreateRequest.newBuilder().setDataProduct(dataProduct).build();
+ DataProductCreateResponse response = blockingStub.createDataProduct(request);
+ return response.getDataProduct();
+ }
+
+ public static void main(String[] args) throws InterruptedException {
+ String target = "localhost:6565";
+
+ ManagedChannel channel = ManagedChannelBuilder.forTarget(target).usePlaintext().build();
+ try {
+ DataCatalogAPIClient client = new DataCatalogAPIClient(channel);
+ DataProduct dataProduct = DataProduct.newBuilder().setName("testing").build();
+ DataProduct result = client.createDataProduct(dataProduct);
+ System.out.println(MessageFormat.format("Created data product with id [{0}]", result.getDataProductId()));
+
+ }finally {
+ channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
+ }
+ }
+}
diff --git a/data-catalog-api/pom.xml b/data-catalog-api/pom.xml
new file mode 100644
index 0000000..5d1da44
--- /dev/null
+++ b/data-catalog-api/pom.xml
@@ -0,0 +1,39 @@
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-data-catalog</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>data-catalog-api</artifactId>
+ <modelVersion>4.0.0</modelVersion>
+
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>server</module>
+ <module>stubs</module>
+ <module>client</module>
+ </modules>
+</project>
diff --git a/data-catalog-api/server/pom.xml b/data-catalog-api/server/pom.xml
new file mode 100644
index 0000000..b3c9cf1
--- /dev/null
+++ b/data-catalog-api/server/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>data-catalog-api</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>data-catalog-api-server</artifactId>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-parent</artifactId>
+ <version>${spring.boot.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.github.lognet</groupId>
+ <artifactId>grpc-spring-boot-starter</artifactId>
+ <version>${grpc.spring.boot}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>data-catalog-api-stubs</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring.boot.version}</version>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/DataCatalogApiServiceApplication.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/DataCatalogApiServiceApplication.java
new file mode 100644
index 0000000..5b3fa8e
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/DataCatalogApiServiceApplication.java
@@ -0,0 +1,13 @@
+package org.apache.airavata.datacatalog.api;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class DataCatalogApiServiceApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(DataCatalogApiServiceApplication.class, args);
+ }
+
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
new file mode 100644
index 0000000..63af7e8
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
@@ -0,0 +1,92 @@
+package org.apache.airavata.datacatalog.api.model;
+
+import jakarta.persistence.Basic;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.JoinColumn;
+import jakarta.persistence.ManyToOne;
+import jakarta.persistence.SequenceGenerator;
+import jakarta.persistence.Table;
+
+@Entity
+@Table(name="data_product")
+public class DataProductEntity {
+
+ @Id
+ @SequenceGenerator(name="data_product_data_product_id_seq", sequenceName = "data_product_data_product_id_seq", allocationSize = 1)
+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "data_product_data_product_id_seq")
+ @Column(name="data_product_id")
+ private Long dataProductId;
+
+ @ManyToOne(optional = true)
+ @JoinColumn(name="parent_data_product_id", referencedColumnName = "data_product_id", nullable = true)
+ private DataProductEntity parentDataProductEntity;
+
+ @Basic
+ @Column(name="external_id", nullable = false)
+ private String externalId;
+
+ @Basic
+ @Column(name="name", nullable = false)
+ private String name;
+
+ public Long getDataProductId() {
+ return dataProductId;
+ }
+
+ public void setDataProductId(Long dataProductId) {
+ this.dataProductId = dataProductId;
+ }
+
+ public DataProductEntity getParentDataProductEntity() {
+ return parentDataProductEntity;
+ }
+
+ public void setParentDataProductEntity(DataProductEntity parentDataProductEntity) {
+ this.parentDataProductEntity = parentDataProductEntity;
+ }
+
+ public String getExternalId() {
+ return externalId;
+ }
+
+ public void setExternalId(String externalId) {
+ this.externalId = externalId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((dataProductId == null) ? 0 : dataProductId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ DataProductEntity other = (DataProductEntity) obj;
+ if (dataProductId == null) {
+ if (other.dataProductId != null)
+ return false;
+ } else if (!dataProductId.equals(other.dataProductId))
+ return false;
+ return true;
+ }
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java
new file mode 100644
index 0000000..770eb8f
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java
@@ -0,0 +1,10 @@
+package org.apache.airavata.datacatalog.api.repository;
+
+import org.apache.airavata.datacatalog.api.model.DataProductEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface DataProductRepository extends JpaRepository<DataProductEntity, Long> {
+
+ DataProductEntity findByExternalId(String parentDataProductId);
+
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
new file mode 100644
index 0000000..d4e9589
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -0,0 +1,53 @@
+package org.apache.airavata.datacatalog.api.service;
+
+import java.util.UUID;
+
+import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc;
+import org.apache.airavata.datacatalog.api.DataProduct;
+import org.apache.airavata.datacatalog.api.DataProductCreateRequest;
+import org.apache.airavata.datacatalog.api.DataProductCreateResponse;
+import org.apache.airavata.datacatalog.api.model.DataProductEntity;
+import org.apache.airavata.datacatalog.api.repository.DataProductRepository;
+import org.lognet.springboot.grpc.GRpcService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import io.grpc.stub.StreamObserver;
+
+@GRpcService
+public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalogAPIServiceImplBase {
+
+ private static final Logger logger = LoggerFactory.getLogger(DataCatalogAPIService.class);
+
+ @Autowired
+ DataProductRepository dataProductRepository;
+
+ @Override
+ public void createDataProduct(DataProductCreateRequest request,
+ StreamObserver<DataProductCreateResponse> responseObserver) {
+
+ logger.info("Creating data product {}", request.getDataProduct());
+ DataProductEntity dataProductEntity = new DataProductEntity();
+ dataProductEntity.setExternalId(UUID.randomUUID().toString());
+ dataProductEntity.setName(request.getDataProduct().getName());
+ if (request.getDataProduct().hasParentDataProductId()) {
+ // TODO: handle parent data product not found
+ DataProductEntity parentDataProductEntity = dataProductRepository
+ .findByExternalId(request.getDataProduct().getParentDataProductId());
+ dataProductEntity.setParentDataProductEntity(parentDataProductEntity);
+ }
+ DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProductEntity);
+
+ DataProductCreateResponse.Builder responseBuilder = DataProductCreateResponse.newBuilder();
+ responseBuilder.getDataProductBuilder()
+ .setDataProductId(savedDataProductEntity.getExternalId())
+ .setName(savedDataProductEntity.getName()).build();
+ if (savedDataProductEntity.getParentDataProductEntity() != null) {
+ responseBuilder.getDataProductBuilder()
+ .setParentDataProductId(savedDataProductEntity.getParentDataProductEntity().getExternalId());
+ }
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onCompleted();
+ }
+}
diff --git a/data-catalog-api/server/src/main/resources/application.properties b/data-catalog-api/server/src/main/resources/application.properties
new file mode 100644
index 0000000..2064c00
--- /dev/null
+++ b/data-catalog-api/server/src/main/resources/application.properties
@@ -0,0 +1,5 @@
+spring.datasource.url=jdbc:postgresql://localhost:5432/data_catalog
+spring.datasource.username=postgres
+spring.datasource.password=example
+spring.jpa.hibernate.ddl-auto=update
+spring.jpa.show-sql=true
diff --git a/data-catalog-api/server/src/main/resources/logback.xml b/data-catalog-api/server/src/main/resources/logback.xml
new file mode 100644
index 0000000..5cd56ea
--- /dev/null
+++ b/data-catalog-api/server/src/main/resources/logback.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+
+ 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.
+
+-->
+<configuration>
+
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d [%t] %-5p %c{30} %m [%X]%n</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="LOGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <File>../logs/airavata.log</File>
+ <Append>true</Append>
+ <encoder>
+ <pattern>%d [%t] %-5p %c{30} %m [%X]%n</pattern>
+ </encoder>
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <fileNamePattern>../logs/airavata.log.%d{yyyy-MM-dd}</fileNamePattern>
+ <maxHistory>30</maxHistory>
+ <totalSizeCap>1GB</totalSizeCap>
+ </rollingPolicy>
+ </appender>
+
+ <logger name="ch.qos.logback" level="WARN"/>
+ <logger name="org.apache.helix" level="WARN"/>
+ <logger name="org.apache.zookeeper" level="ERROR"/>
+ <logger name="org.apache.airavata" level="INFO"/>
+ <logger name="org.hibernate" level="INFO"/>
+ <logger name="net.schmizz.sshj" level="WARN"/>
+ <root level="INFO">
+ <appender-ref ref="CONSOLE"/>
+ <appender-ref ref="LOGFILE"/>
+ </root>
+</configuration>
diff --git a/data-catalog-api/server/src/test/java/org/apache/airavata/datacatalogapiserver/DataCatalogApiServerApplicationTests.java b/data-catalog-api/server/src/test/java/org/apache/airavata/datacatalogapiserver/DataCatalogApiServerApplicationTests.java
new file mode 100644
index 0000000..f7ed907
--- /dev/null
+++ b/data-catalog-api/server/src/test/java/org/apache/airavata/datacatalogapiserver/DataCatalogApiServerApplicationTests.java
@@ -0,0 +1,13 @@
+package org.apache.airavata.datacatalogapiserver;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class DataCatalogApiServerApplicationTests {
+
+ @Test
+ void contextLoads() {
+ }
+
+}
diff --git a/data-catalog-api/stubs/pom.xml b/data-catalog-api/stubs/pom.xml
new file mode 100644
index 0000000..18f5fe6
--- /dev/null
+++ b/data-catalog-api/stubs/pom.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>data-catalog-api</artifactId>
+ <groupId>org.apache.airavata</groupId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>data-catalog-api-stubs</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-netty-shaded</artifactId>
+ <version>${grpc.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-protobuf</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-stub</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency> <!-- necessary for Java 9+ -->
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>annotations-api</artifactId>
+ <version>${tomcat.annotations-api.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <extensions>
+ <extension>
+ <groupId>kr.motd.maven</groupId>
+ <artifactId>os-maven-plugin</artifactId>
+ <version>${os.maven.plugin}</version>
+ </extension>
+ </extensions>
+ <plugins>
+ <plugin>
+ <groupId>org.xolstice.maven.plugins</groupId>
+ <artifactId>protobuf-maven-plugin</artifactId>
+ <version>${protobuf.maven.plugin}</version>
+ <configuration>
+ <protocArtifact>com.google.protobuf:protoc:${protobuf.protoc.version}:exe:${os.detected.classifier}</protocArtifact>
+ <pluginId>grpc-java</pluginId>
+ <pluginArtifact>io.grpc:protoc-gen-grpc-java:${protoc-gen-grpc-java.version}:exe:${os.detected.classifier}</pluginArtifact>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>compile-custom</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
new file mode 100644
index 0000000..0a2a083
--- /dev/null
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@ -0,0 +1,39 @@
+// 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.
+
+syntax = "proto3";
+
+option java_multiple_files = true;
+option java_package = "org.apache.airavata.datacatalog.api";
+
+
+message DataProduct {
+ string data_product_id = 1;
+ optional string parent_data_product_id = 2;
+ string name = 3;
+}
+
+message DataProductCreateRequest {
+ DataProduct data_product = 1;
+}
+message DataProductCreateResponse {
+ DataProduct data_product = 1;
+}
+
+service DataCatalogAPIService {
+ rpc createDataProduct(DataProductCreateRequest) returns (DataProductCreateResponse){}
+}
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..2fd997b
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,54 @@
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-data-catalog</artifactId>
+ <packaging>pom</packaging>
+ <version>0.1-SNAPSHOT</version>
+ <name>airavata-data-catalog</name>
+ <url>http://airavata.apache.org</url>
+
+ <modules>
+ <module>data-catalog-api</module>
+ </modules>
+
+ <properties>
+ <java.version>17</java.version>
+ <maven.compiler.source>${java.version}</maven.compiler.source>
+ <maven.compiler.target>${java.version}</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <spring.boot.version>3.0.1</spring.boot.version>
+ <grpc.spring.boot>5.0.0</grpc.spring.boot>
+ <slf4j.version>2.0.6</slf4j.version>
+ <os.maven.plugin>1.6.2</os.maven.plugin>
+ <protobuf.maven.plugin>0.6.1</protobuf.maven.plugin>
+ <protobuf.protoc.version>3.21.7</protobuf.protoc.version>
+ <grpc.version>1.52.1</grpc.version>
+ <protoc-gen-grpc-java.version>${grpc.version}</protoc-gen-grpc-java.version>
+ <tomcat.annotations-api.version>6.0.53</tomcat.annotations-api.version>
+ </properties>
+
+ <dependencies>
+ </dependencies>
+</project>
[airavata-data-catalog] 10/36: Data Product CRUD API Fixes #6
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 25a311a5c8f6f01d8492132da7ded99efcf01510
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Thu Feb 9 12:29:39 2023 -0500
Data Product CRUD API
Fixes #6
---
.../api/client/DataCatalogAPIClient.java | 63 ++++++++++++++---
.../datacatalog/api/mapper/DataProductMapper.java | 54 +++++++++++++++
.../api/repository/DataProductRepository.java | 6 +-
.../api/service/DataCatalogAPIService.java | 81 ++++++++++++++--------
.../stubs/src/main/proto/DataCatalogAPI.proto | 20 ++++++
5 files changed, 187 insertions(+), 37 deletions(-)
diff --git a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
index 4ba83e1..8ae7d07 100644
--- a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
+++ b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
@@ -1,20 +1,24 @@
package org.apache.airavata.datacatalog.api.client;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import io.grpc.Channel;
-import io.grpc.ManagedChannel;
-import io.grpc.ManagedChannelBuilder;
-
import java.text.MessageFormat;
import java.util.concurrent.TimeUnit;
import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc;
+import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc.DataCatalogAPIServiceBlockingStub;
import org.apache.airavata.datacatalog.api.DataProduct;
import org.apache.airavata.datacatalog.api.DataProductCreateRequest;
import org.apache.airavata.datacatalog.api.DataProductCreateResponse;
-import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc.DataCatalogAPIServiceBlockingStub;;
+import org.apache.airavata.datacatalog.api.DataProductDeleteRequest;
+import org.apache.airavata.datacatalog.api.DataProductGetRequest;
+import org.apache.airavata.datacatalog.api.DataProductGetResponse;
+import org.apache.airavata.datacatalog.api.DataProductUpdateRequest;
+import org.apache.airavata.datacatalog.api.DataProductUpdateResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.grpc.Channel;
+import io.grpc.ManagedChannel;
+import io.grpc.ManagedChannelBuilder;;
public class DataCatalogAPIClient {
@@ -32,18 +36,59 @@ public class DataCatalogAPIClient {
return response.getDataProduct();
}
+ public DataProduct updateDataProduct(DataProduct dataProduct) {
+ DataProductUpdateRequest request = DataProductUpdateRequest.newBuilder().setDataProduct(dataProduct).build();
+ DataProductUpdateResponse response = blockingStub.updateDataProduct(request);
+ return response.getDataProduct();
+ }
+
+ public DataProduct getDataProduct(String dataProductId) {
+ DataProductGetRequest request = DataProductGetRequest.newBuilder().setDataProductId(dataProductId).build();
+ DataProductGetResponse response = blockingStub.getDataProduct(request);
+ return response.getDataProduct();
+ }
+
+ public void deleteDataProduct(String dataProductId) {
+ DataProductDeleteRequest request = DataProductDeleteRequest.newBuilder().setDataProductId(dataProductId)
+ .build();
+ blockingStub.deleteDataProduct(request);
+ }
+
public static void main(String[] args) throws InterruptedException {
String target = "localhost:6565";
ManagedChannel channel = ManagedChannelBuilder.forTarget(target).usePlaintext().build();
try {
DataCatalogAPIClient client = new DataCatalogAPIClient(channel);
+ DataProduct parentDataProduct = DataProduct.newBuilder().setName("parent dp").build();
+ DataProduct parentResult = client.createDataProduct(parentDataProduct);
+
DataProduct dataProduct = DataProduct.newBuilder().setName("testing").setMetadata("{\"foo\": \"bar\"}")
+ .setParentDataProductId(parentResult.getDataProductId())
.build();
DataProduct result = client.createDataProduct(dataProduct);
System.out.println(MessageFormat.format("Created data product with id [{0}]", result.getDataProductId()));
- }finally {
+ DataProduct updatedDataProduct = result.toBuilder().setName("updated name").build();
+ result = client.updateDataProduct(updatedDataProduct);
+ System.out.println(MessageFormat.format("Updated data product with id [{0}] to have name [{1}]",
+ result.getDataProductId(), result.getName()));
+
+ DataProduct retrievedDataProduct = client.getDataProduct(result.getDataProductId());
+ System.out.println(MessageFormat.format("Retrieved data product with id [{0}] to have name [{1}]",
+ retrievedDataProduct.getDataProductId(), retrievedDataProduct.getName()));
+
+ DataProduct dataProduct2 = DataProduct.newBuilder().setName("testing 2").setMetadata("{\"foo\": \"bar\"}")
+ .build();
+ DataProduct result2 = client.createDataProduct(dataProduct2);
+ System.out.println(
+ MessageFormat.format("Created second data product [{0}]", result2));
+
+ client.deleteDataProduct(result2.getDataProductId());
+ System.out.println(
+ MessageFormat.format("Deleted data product with id [{0}]", result2.getDataProductId()));
+
+ } finally {
channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
}
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
new file mode 100644
index 0000000..8e1e155
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
@@ -0,0 +1,54 @@
+package org.apache.airavata.datacatalog.api.mapper;
+
+import org.apache.airavata.datacatalog.api.DataProduct;
+import org.apache.airavata.datacatalog.api.model.DataProductEntity;
+import org.apache.airavata.datacatalog.api.repository.DataProductRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * Map to/from
+ * {@link org.apache.airavata.datacatalog.api.model.DataProductEntity}
+ * <-> {@link org.apache.airavata.datacatalog.api.DataProduct}
+ */
+@Component
+public class DataProductMapper {
+
+ @Autowired
+ DataProductRepository dataProductRepository;
+
+ public void mapModelToEntity(DataProduct dataProduct, DataProductEntity dataProductEntity) {
+
+ dataProductEntity.setName(dataProduct.getName());
+
+ if (dataProduct.hasParentDataProductId()) {
+ // TODO: handle parent data product not found
+ DataProductEntity parentDataProductEntity = dataProductRepository
+ .findByExternalId(dataProduct.getParentDataProductId());
+ dataProductEntity.setParentDataProductEntity(parentDataProductEntity);
+ }
+ if (dataProduct.hasMetadata()) {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ JsonNode metadata = mapper.readTree(dataProduct.getMetadata());
+ dataProductEntity.setMetadata(metadata);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ public void mapEntityToModel(DataProductEntity dataProductEntity, DataProduct.Builder dataProductBuilder) {
+
+ dataProductBuilder
+ .setDataProductId(dataProductEntity.getExternalId())
+ .setName(dataProductEntity.getName());
+ if (dataProductEntity.getParentDataProductEntity() != null) {
+ dataProductBuilder.setParentDataProductId(dataProductEntity.getParentDataProductEntity().getExternalId());
+ }
+ }
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java
index 770eb8f..acec036 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java
@@ -2,9 +2,13 @@ package org.apache.airavata.datacatalog.api.repository;
import org.apache.airavata.datacatalog.api.model.DataProductEntity;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.transaction.annotation.Transactional;
public interface DataProductRepository extends JpaRepository<DataProductEntity, Long> {
- DataProductEntity findByExternalId(String parentDataProductId);
+ DataProductEntity findByExternalId(String externalId);
+
+ @Transactional
+ void deleteByExternalId(String externalId);
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index e14c437..65f92b7 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -3,8 +3,16 @@ package org.apache.airavata.datacatalog.api.service;
import java.util.UUID;
import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc;
+import org.apache.airavata.datacatalog.api.DataProduct;
import org.apache.airavata.datacatalog.api.DataProductCreateRequest;
import org.apache.airavata.datacatalog.api.DataProductCreateResponse;
+import org.apache.airavata.datacatalog.api.DataProductDeleteRequest;
+import org.apache.airavata.datacatalog.api.DataProductDeleteResponse;
+import org.apache.airavata.datacatalog.api.DataProductGetRequest;
+import org.apache.airavata.datacatalog.api.DataProductGetResponse;
+import org.apache.airavata.datacatalog.api.DataProductUpdateRequest;
+import org.apache.airavata.datacatalog.api.DataProductUpdateResponse;
+import org.apache.airavata.datacatalog.api.mapper.DataProductMapper;
import org.apache.airavata.datacatalog.api.model.DataProductEntity;
import org.apache.airavata.datacatalog.api.repository.DataProductRepository;
import org.lognet.springboot.grpc.GRpcService;
@@ -12,10 +20,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
import io.grpc.stub.StreamObserver;
@GRpcService
@@ -26,6 +30,9 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
@Autowired
DataProductRepository dataProductRepository;
+ @Autowired
+ DataProductMapper dataProductMapper = new DataProductMapper();
+
@Override
public void createDataProduct(DataProductCreateRequest request,
StreamObserver<DataProductCreateResponse> responseObserver) {
@@ -34,35 +41,55 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
logger.info("Creating data product {}", request.getDataProduct());
DataProductEntity dataProductEntity = new DataProductEntity();
dataProductEntity.setExternalId(UUID.randomUUID().toString());
- dataProductEntity.setName(request.getDataProduct().getName());
- if (request.getDataProduct().hasParentDataProductId()) {
- // TODO: handle parent data product not found
- DataProductEntity parentDataProductEntity = dataProductRepository
- .findByExternalId(request.getDataProduct().getParentDataProductId());
- dataProductEntity.setParentDataProductEntity(parentDataProductEntity);
- }
- if (request.getDataProduct().hasMetadata()) {
- ObjectMapper mapper = new ObjectMapper();
- try {
- JsonNode metadata = mapper.readTree(request.getDataProduct().getMetadata());
- dataProductEntity.setMetadata(metadata);
- } catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- }
+ dataProductMapper.mapModelToEntity(request.getDataProduct(), dataProductEntity);
DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProductEntity);
// TODO: SharingManager.grantPermissionToUser(userInfo, dataProduct,
// Permission.OWNER)
DataProductCreateResponse.Builder responseBuilder = DataProductCreateResponse.newBuilder();
- responseBuilder.getDataProductBuilder()
- .setDataProductId(savedDataProductEntity.getExternalId())
- .setName(savedDataProductEntity.getName()).build();
- if (savedDataProductEntity.getParentDataProductEntity() != null) {
- responseBuilder.getDataProductBuilder()
- .setParentDataProductId(savedDataProductEntity.getParentDataProductEntity().getExternalId());
- }
+ dataProductMapper.mapEntityToModel(savedDataProductEntity, responseBuilder.getDataProductBuilder());
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onCompleted();
+ }
+
+ @Override
+ public void updateDataProduct(DataProductUpdateRequest request,
+ StreamObserver<DataProductUpdateResponse> responseObserver) {
+
+ // TODO: check that user has access to update data product record
+ // TODO: handle data product does not exist
+ DataProduct dataProduct = request.getDataProduct();
+ DataProductEntity dataProductEntity = dataProductRepository
+ .findByExternalId(dataProduct.getDataProductId());
+ dataProductMapper.mapModelToEntity(dataProduct, dataProductEntity);
+
+ DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProductEntity);
+
+ DataProductUpdateResponse.Builder responseBuilder = DataProductUpdateResponse.newBuilder();
+ dataProductMapper.mapEntityToModel(savedDataProductEntity, responseBuilder.getDataProductBuilder());
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onCompleted();
+ }
+
+ @Override
+ public void getDataProduct(DataProductGetRequest request, StreamObserver<DataProductGetResponse> responseObserver) {
+ // TODO: check that user has READ access on data product record
+ // TODO: handle data product does not exist
+ DataProductEntity dataProductEntity = dataProductRepository
+ .findByExternalId(request.getDataProductId());
+ DataProductGetResponse.Builder responseBuilder = DataProductGetResponse.newBuilder();
+ dataProductMapper.mapEntityToModel(dataProductEntity, responseBuilder.getDataProductBuilder());
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onCompleted();
+ }
+
+ @Override
+ public void deleteDataProduct(DataProductDeleteRequest request,
+ StreamObserver<DataProductDeleteResponse> responseObserver) {
+ // TODO: check that user has WRITE access on data product record
+ dataProductRepository.deleteByExternalId(request.getDataProductId());
+ DataProductDeleteResponse.Builder responseBuilder = DataProductDeleteResponse.newBuilder();
responseObserver.onNext(responseBuilder.build());
responseObserver.onCompleted();
}
diff --git a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
index 9508fff..779002c 100644
--- a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@ -70,7 +70,27 @@ message DataProductCreateRequest {
message DataProductCreateResponse {
DataProduct data_product = 1;
}
+message DataProductUpdateRequest {
+ DataProduct data_product = 1;
+}
+message DataProductUpdateResponse {
+ DataProduct data_product = 1;
+}
+message DataProductGetRequest {
+ string data_product_id = 1;
+}
+message DataProductGetResponse {
+ DataProduct data_product = 1;
+}
+message DataProductDeleteRequest {
+ string data_product_id = 1;
+}
+message DataProductDeleteResponse {
+}
service DataCatalogAPIService {
rpc createDataProduct(DataProductCreateRequest) returns (DataProductCreateResponse){}
+ rpc updateDataProduct(DataProductUpdateRequest) returns (DataProductUpdateResponse){}
+ rpc getDataProduct(DataProductGetRequest) returns (DataProductGetResponse){}
+ rpc deleteDataProduct(DataProductDeleteRequest) returns (DataProductDeleteResponse){}
}
[airavata-data-catalog] 14/36: implement sharing logic
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 5fbb51088f359d3b3a7800faebc01a28cd5b9dce
Author: Isuru Ranawaka <ir...@gmail.com>
AuthorDate: Tue Feb 14 15:01:30 2023 -0500
implement sharing logic
---
.gitignore | 4 ++
.../datacatalog/api/sharing/SharingManager.java | 17 +++---
.../api/sharing/SharingManagerImpl.java | 61 +++++++++++++++++-----
.../stubs/src/main/proto/DataCatalogAPI.proto | 1 +
4 files changed, 61 insertions(+), 22 deletions(-)
diff --git a/.gitignore b/.gitignore
index 79edcba..a78af18 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,7 @@
target
.vscode
logs
+.idea
+.iml
+.ipr
+.iws
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManager.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManager.java
index cbe470e..65c61df 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManager.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManager.java
@@ -5,6 +5,7 @@ import org.apache.airavata.datacatalog.api.GroupInfo;
import org.apache.airavata.datacatalog.api.Permission;
import org.apache.airavata.datacatalog.api.UserInfo;
import org.apache.airavata.datacatalog.api.model.UserEntity;
+import org.apache.custos.sharing.core.exceptions.CustosSharingException;
public interface SharingManager {
@@ -25,7 +26,7 @@ public interface SharingManager {
* @param permission
* @return
*/
- boolean userHasAccess(UserInfo userInfo, DataProduct dataProduct, Permission permission);
+ boolean userHasAccess(UserInfo userInfo, DataProduct dataProduct, Permission permission) throws Exception;
/**
* Return the name of the database view that includes sharing information
@@ -44,7 +45,7 @@ public interface SharingManager {
* @param dataProduct
* @param permission
*/
- void grantPermissionToUser(UserInfo userInfo, DataProduct dataProduct, Permission permission);
+ void grantPermissionToUser(UserInfo userInfo, DataProduct dataProduct, Permission permission) throws Exception;
/**
* Revoke permission from the user for the given data product.
@@ -53,7 +54,7 @@ public interface SharingManager {
* @param dataProduct
* @param permission
*/
- void revokePermissionFromUser(UserInfo userInfo, DataProduct dataProduct, Permission permission);
+ void revokePermissionFromUser(UserInfo userInfo, DataProduct dataProduct, Permission permission) throws Exception;
/**
* Grant permission to the group for the given data product.
@@ -62,7 +63,7 @@ public interface SharingManager {
* @param dataProduct
* @param permission
*/
- void grantPermissionToGroup(GroupInfo groupInfo, DataProduct dataProduct, Permission permission);
+ void grantPermissionToGroup(GroupInfo groupInfo, DataProduct dataProduct, Permission permission) throws Exception;
/**
* Revoke permission from the group for the given data product.
@@ -71,7 +72,7 @@ public interface SharingManager {
* @param dataProduct
* @param permission
*/
- void revokePermissionFromGroup(GroupInfo groupInfo, DataProduct dataProduct, Permission permission);
+ void revokePermissionFromGroup(GroupInfo groupInfo, DataProduct dataProduct, Permission permission) throws Exception;
/**
* Return true if public access at the given permission is granted for the
@@ -82,7 +83,7 @@ public interface SharingManager {
* @param permission
* @return
*/
- boolean hasPublicAccess(DataProduct dataProduct, Permission permission);
+ boolean hasPublicAccess(DataProduct dataProduct, Permission permission) throws Exception;
/**
* Grant public access to the given data product.
@@ -90,7 +91,7 @@ public interface SharingManager {
* @param dataProduct
* @param permission
*/
- void grantPublicAccess(DataProduct dataProduct, Permission permission);
+ void grantPublicAccess(DataProduct dataProduct, Permission permission) throws Exception;
/**
* Revoke public access from the given data product.
@@ -98,5 +99,5 @@ public interface SharingManager {
* @param dataProduct
* @param permission
*/
- void revokePublicAccess(DataProduct dataProduct, Permission permission);
+ void revokePublicAccess(DataProduct dataProduct, Permission permission) throws Exception;
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManagerImpl.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManagerImpl.java
index 051bc35..7eab638 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManagerImpl.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManagerImpl.java
@@ -5,17 +5,23 @@ import org.apache.airavata.datacatalog.api.GroupInfo;
import org.apache.airavata.datacatalog.api.Permission;
import org.apache.airavata.datacatalog.api.UserInfo;
import org.apache.airavata.datacatalog.api.model.UserEntity;
-
+import org.apache.custos.sharing.core.exceptions.CustosSharingException;
import org.apache.custos.sharing.core.impl.SharingImpl;
+import org.apache.custos.sharing.core.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.ArrayList;
+import java.util.List;
+
@Component
-public class SharingManagerImpl implements SharingManager {
+public class SharingManagerImpl implements SharingManager {
@Autowired
SharingImpl custosSharingImpl;
+ private static final String PUBLIC_ACCESS_GROUP = "public_access_group";
+
@Override
public UserEntity resolveUser(UserInfo userInfo) {
@@ -23,8 +29,9 @@ public class SharingManagerImpl implements SharingManager {
}
@Override
- public boolean userHasAccess(UserInfo userInfo, DataProduct dataProduct, Permission permission) {
- return false;
+ public boolean userHasAccess(UserInfo userInfo, DataProduct dataProduct, Permission permission) throws CustosSharingException {
+ return custosSharingImpl.userHasAccess(userInfo.getTenantId(), dataProduct.getDataProductId(), permission.name(),
+ userInfo.getUserId());
}
@Override
@@ -33,37 +40,63 @@ public class SharingManagerImpl implements SharingManager {
}
@Override
- public void grantPermissionToUser(UserInfo userInfo, DataProduct dataProduct, Permission permission) {
+ public void grantPermissionToUser(UserInfo userInfo, DataProduct dataProduct, Permission permission) throws CustosSharingException {
+ List<String> userIds = new ArrayList<>();
+ userIds.add(userInfo.getUserId());
+ custosSharingImpl.shareEntity(userInfo.getTenantId(),
+ dataProduct.getDataProductId(), permission.name(), userIds, true, Constants.USER, null);
}
@Override
- public void revokePermissionFromUser(UserInfo userInfo, DataProduct dataProduct, Permission permission) {
+ public void revokePermissionFromUser(UserInfo userInfo, DataProduct dataProduct, Permission permission) throws CustosSharingException {
+
+ List<String> userIds = new ArrayList<>();
+ userIds.add(userInfo.getUserId());
+ custosSharingImpl.revokePermission(userInfo.getTenantId(),
+ dataProduct.getDataProductId(), permission.name(), userIds);
}
@Override
- public void grantPermissionToGroup(GroupInfo groupInfo, DataProduct dataProduct, Permission permission) {
+ public void grantPermissionToGroup(GroupInfo groupInfo, DataProduct dataProduct, Permission permission) throws CustosSharingException {
+ List<String> userIds = new ArrayList<>();
+ userIds.add(groupInfo.getGroupId());
+ custosSharingImpl.shareEntity(groupInfo.getTenantId(),
+ dataProduct.getDataProductId(), permission.name(), userIds, true, Constants.GROUP, null);
}
@Override
- public void revokePermissionFromGroup(GroupInfo groupInfo, DataProduct dataProduct, Permission permission) {
-
+ public void revokePermissionFromGroup(GroupInfo groupInfo, DataProduct dataProduct, Permission permission) throws CustosSharingException {
+ List<String> userIds = new ArrayList<>();
+ userIds.add(groupInfo.getGroupId());
+ custosSharingImpl.revokePermission(groupInfo.getTenantId(),
+ dataProduct.getDataProductId(), permission.name(), userIds);
}
@Override
- public boolean hasPublicAccess(DataProduct dataProduct, Permission permission) {
- return false;
+ public boolean hasPublicAccess(DataProduct dataProduct, Permission permission) throws CustosSharingException{
+ return custosSharingImpl.userHasAccess(dataProduct.getTenantId(), dataProduct.getDataProductId(), permission.name(),
+ PUBLIC_ACCESS_GROUP);
}
@Override
- public void grantPublicAccess(DataProduct dataProduct, Permission permission) {
+ public void grantPublicAccess(DataProduct dataProduct, Permission permission) throws CustosSharingException{
+
+ //TODO: create PUBLIC GROUP If not exists
+ List<String> userIds = new ArrayList<>();
+ userIds.add(PUBLIC_ACCESS_GROUP);
+ custosSharingImpl.shareEntity(dataProduct.getTenantId(),
+ dataProduct.getDataProductId(), permission.name(), userIds, true, Constants.GROUP, null);
}
@Override
- public void revokePublicAccess(DataProduct dataProduct, Permission permission) {
-
+ public void revokePublicAccess(DataProduct dataProduct, Permission permission) throws CustosSharingException{
+ List<String> userIds = new ArrayList<>();
+ userIds.add(PUBLIC_ACCESS_GROUP);
+ custosSharingImpl.revokePermission(dataProduct.getTenantId(),
+ dataProduct.getDataProductId(), permission.name(), userIds);
}
}
diff --git a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
index 779002c..476fb1a 100644
--- a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@ -62,6 +62,7 @@ message DataProduct {
optional string parent_data_product_id = 2;
string name = 3;
optional string metadata = 4;
+ string tenant_id = 5;
}
message DataProductCreateRequest {
[airavata-data-catalog] 34/36: Merge pull request #22 from apache/calcite
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 115764e78f48f9aa4b4821904c6e0b0154899f64
Merge: 5596701 ace3d89
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Mar 21 15:19:23 2023 -0400
Merge pull request #22 from apache/calcite
Calcite integration for SQL queries against a metadata schema
.../api/client/DataCatalogAPIClient.java | 47 ++++-
data-catalog-api/server/pom.xml | 10 +
.../exception/MetadataSchemaSqlParseException.java | 25 +++
.../MetadataSchemaSqlValidateException.java | 25 +++
.../api/query/MetadataSchemaQueryExecutor.java | 10 +
.../api/query/MetadataSchemaQueryResult.java | 9 +
.../api/query/MetadataSchemaQueryWriter.java | 21 ++
.../impl/MetadataSchemaQueryExecutorImpl.java | 215 +++++++++++++++++++++
.../PostgresqlMetadataSchemaQueryWriterImpl.java | 201 +++++++++++++++++++
.../api/service/DataCatalogAPIService.java | 62 ++++--
.../api/service/DataCatalogService.java | 6 +
.../api/service/impl/DataCatalogServiceImpl.java | 38 ++--
.../server/src/main/resources/logback.xml | 4 +
.../stubs/src/main/proto/DataCatalogAPI.proto | 42 ++--
14 files changed, 667 insertions(+), 48 deletions(-)
[airavata-data-catalog] 32/36: Error reporting added when sql fails to parse or validate
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit ac7d4acb1ba9eb6d8d937cbf7af47140b40e92ca
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Mar 21 14:44:15 2023 -0400
Error reporting added when sql fails to parse or validate
---
.../exception/MetadataSchemaSqlParseException.java | 25 ++++++++++++++++++++++
.../MetadataSchemaSqlValidateException.java | 25 ++++++++++++++++++++++
.../api/query/MetadataSchemaQueryExecutor.java | 6 +++++-
.../impl/MetadataSchemaQueryExecutorImpl.java | 15 +++++++------
.../api/service/DataCatalogAPIService.java | 20 +++++++++++++----
.../api/service/DataCatalogService.java | 5 ++++-
.../api/service/impl/DataCatalogServiceImpl.java | 5 ++++-
7 files changed, 87 insertions(+), 14 deletions(-)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/exception/MetadataSchemaSqlParseException.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/exception/MetadataSchemaSqlParseException.java
new file mode 100644
index 0000000..1717e5d
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/exception/MetadataSchemaSqlParseException.java
@@ -0,0 +1,25 @@
+package org.apache.airavata.datacatalog.api.exception;
+
+public class MetadataSchemaSqlParseException extends Exception {
+
+ public MetadataSchemaSqlParseException() {
+ }
+
+ public MetadataSchemaSqlParseException(String message) {
+ super(message);
+ }
+
+ public MetadataSchemaSqlParseException(Throwable cause) {
+ super(cause);
+ }
+
+ public MetadataSchemaSqlParseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public MetadataSchemaSqlParseException(String message, Throwable cause, boolean enableSuppression,
+ boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/exception/MetadataSchemaSqlValidateException.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/exception/MetadataSchemaSqlValidateException.java
new file mode 100644
index 0000000..ec7ea17
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/exception/MetadataSchemaSqlValidateException.java
@@ -0,0 +1,25 @@
+package org.apache.airavata.datacatalog.api.exception;
+
+public class MetadataSchemaSqlValidateException extends Exception {
+
+ public MetadataSchemaSqlValidateException() {
+ }
+
+ public MetadataSchemaSqlValidateException(String message) {
+ super(message);
+ }
+
+ public MetadataSchemaSqlValidateException(Throwable cause) {
+ super(cause);
+ }
+
+ public MetadataSchemaSqlValidateException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public MetadataSchemaSqlValidateException(String message, Throwable cause, boolean enableSuppression,
+ boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryExecutor.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryExecutor.java
index 6871553..dcf6a35 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryExecutor.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryExecutor.java
@@ -1,6 +1,10 @@
package org.apache.airavata.datacatalog.api.query;
+import org.apache.airavata.datacatalog.api.exception.MetadataSchemaSqlParseException;
+import org.apache.airavata.datacatalog.api.exception.MetadataSchemaSqlValidateException;
+
public interface MetadataSchemaQueryExecutor {
- MetadataSchemaQueryResult execute(String sql);
+ MetadataSchemaQueryResult execute(String sql)
+ throws MetadataSchemaSqlParseException, MetadataSchemaSqlValidateException;
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/impl/MetadataSchemaQueryExecutorImpl.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/impl/MetadataSchemaQueryExecutorImpl.java
index ab1202d..7643a50 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/impl/MetadataSchemaQueryExecutorImpl.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/impl/MetadataSchemaQueryExecutorImpl.java
@@ -8,6 +8,8 @@ import java.util.Map;
import org.apache.airavata.datacatalog.api.DataProduct;
import org.apache.airavata.datacatalog.api.FieldValueType;
+import org.apache.airavata.datacatalog.api.exception.MetadataSchemaSqlParseException;
+import org.apache.airavata.datacatalog.api.exception.MetadataSchemaSqlValidateException;
import org.apache.airavata.datacatalog.api.mapper.DataProductMapper;
import org.apache.airavata.datacatalog.api.model.DataProductEntity;
import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
@@ -66,7 +68,8 @@ public class MetadataSchemaQueryExecutorImpl implements MetadataSchemaQueryExecu
DataProductMapper dataProductMapper;
@Override
- public MetadataSchemaQueryResult execute(String sql) {
+ public MetadataSchemaQueryResult execute(String sql)
+ throws MetadataSchemaSqlParseException, MetadataSchemaSqlValidateException {
// Create a schema that contains the data_product table and all of the metadata
// schemas
@@ -174,21 +177,19 @@ public class MetadataSchemaQueryExecutorImpl implements MetadataSchemaQueryExecu
return validator;
}
- SqlNode parse(Planner planner, String sql) {
+ SqlNode parse(Planner planner, String sql) throws MetadataSchemaSqlParseException {
try {
return planner.parse(sql);
} catch (SqlParseException e) {
- // TODO: convert to a checked exception and add to interface
- throw new RuntimeException(e);
+ throw new MetadataSchemaSqlParseException(e);
}
}
- SqlNode validate(SqlValidator validator, SqlNode sqlNode) {
+ SqlNode validate(SqlValidator validator, SqlNode sqlNode) throws MetadataSchemaSqlValidateException {
try {
return validator.validate(sqlNode);
} catch (CalciteContextException e) {
- // TODO: convert to a checked exception and add to interface
- throw new RuntimeException(e);
+ throw new MetadataSchemaSqlValidateException(e);
}
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index 1e87293..4b7b383 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -37,6 +37,8 @@ import org.apache.airavata.datacatalog.api.MetadataSchemaFieldUpdateResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaGetRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaGetResponse;
import org.apache.airavata.datacatalog.api.exception.EntityNotFoundException;
+import org.apache.airavata.datacatalog.api.exception.MetadataSchemaSqlParseException;
+import org.apache.airavata.datacatalog.api.exception.MetadataSchemaSqlValidateException;
import org.apache.airavata.datacatalog.api.query.MetadataSchemaQueryResult;
import org.lognet.springboot.grpc.GRpcService;
import org.slf4j.Logger;
@@ -125,10 +127,20 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
public void searchDataProducts(DataProductSearchRequest request,
StreamObserver<DataProductSearchResponse> responseObserver) {
- MetadataSchemaQueryResult searchResult = dataCatalogService.searchDataProducts(request.getSql());
- List<DataProduct> dataProducts = searchResult.dataProducts();
- responseObserver.onNext(DataProductSearchResponse.newBuilder().addAllDataProducts(dataProducts).build());
- responseObserver.onCompleted();
+ try {
+ MetadataSchemaQueryResult searchResult = dataCatalogService.searchDataProducts(request.getSql());
+ List<DataProduct> dataProducts = searchResult.dataProducts();
+ responseObserver.onNext(DataProductSearchResponse.newBuilder().addAllDataProducts(dataProducts).build());
+ responseObserver.onCompleted();
+ } catch (MetadataSchemaSqlParseException e) {
+ responseObserver
+ .onError(Status.INVALID_ARGUMENT.withDescription("Failed to parse SQL query.").asException());
+ responseObserver.onCompleted();
+ } catch (MetadataSchemaSqlValidateException e) {
+ responseObserver
+ .onError(Status.INVALID_ARGUMENT.withDescription("Failed to validate SQL query.").asException());
+ responseObserver.onCompleted();
+ }
}
@Override
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java
index 093263a..0b6220d 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java
@@ -5,6 +5,8 @@ import java.util.List;
import org.apache.airavata.datacatalog.api.DataProduct;
import org.apache.airavata.datacatalog.api.MetadataSchema;
import org.apache.airavata.datacatalog.api.MetadataSchemaField;
+import org.apache.airavata.datacatalog.api.exception.MetadataSchemaSqlParseException;
+import org.apache.airavata.datacatalog.api.exception.MetadataSchemaSqlValidateException;
import org.apache.airavata.datacatalog.api.query.MetadataSchemaQueryResult;
/**
@@ -40,5 +42,6 @@ public interface DataCatalogService {
MetadataSchemaField updateMetadataSchemaField(MetadataSchemaField metadataSchemaField);
- MetadataSchemaQueryResult searchDataProducts(String sql);
+ MetadataSchemaQueryResult searchDataProducts(String sql)
+ throws MetadataSchemaSqlParseException, MetadataSchemaSqlValidateException;
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
index 59d1d94..dbce8bb 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
@@ -9,6 +9,8 @@ import org.apache.airavata.datacatalog.api.MetadataSchema;
import org.apache.airavata.datacatalog.api.MetadataSchemaField;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListResponse;
import org.apache.airavata.datacatalog.api.exception.EntityNotFoundException;
+import org.apache.airavata.datacatalog.api.exception.MetadataSchemaSqlParseException;
+import org.apache.airavata.datacatalog.api.exception.MetadataSchemaSqlValidateException;
import org.apache.airavata.datacatalog.api.mapper.DataProductMapper;
import org.apache.airavata.datacatalog.api.mapper.MetadataSchemaFieldMapper;
import org.apache.airavata.datacatalog.api.mapper.MetadataSchemaMapper;
@@ -115,7 +117,8 @@ public class DataCatalogServiceImpl implements DataCatalogService {
}
@Override
- public MetadataSchemaQueryResult searchDataProducts(String sql) {
+ public MetadataSchemaQueryResult searchDataProducts(String sql)
+ throws MetadataSchemaSqlParseException, MetadataSchemaSqlValidateException {
return metadataSchemaQueryExecutor.execute(sql);
}
[airavata-data-catalog] 04/36: Added mapping of metadata column to JSONB/JsonNode
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 6d8f0948e4ed5eb0226354657cff60c32a85e3d0
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Jan 23 17:42:05 2023 -0500
Added mapping of metadata column to JSONB/JsonNode
---
.../datacatalog/api/client/DataCatalogAPIClient.java | 3 ++-
data-catalog-api/server/pom.xml | 11 ++++++++++-
.../datacatalog/api/model/DataProductEntity.java | 17 +++++++++++++++++
.../datacatalog/api/service/DataCatalogAPIService.java | 14 +++++++++++++-
.../stubs/src/main/proto/DataCatalogAPI.proto | 1 +
5 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
index 5ba7ebc..4ba83e1 100644
--- a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
+++ b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
@@ -38,7 +38,8 @@ public class DataCatalogAPIClient {
ManagedChannel channel = ManagedChannelBuilder.forTarget(target).usePlaintext().build();
try {
DataCatalogAPIClient client = new DataCatalogAPIClient(channel);
- DataProduct dataProduct = DataProduct.newBuilder().setName("testing").build();
+ DataProduct dataProduct = DataProduct.newBuilder().setName("testing").setMetadata("{\"foo\": \"bar\"}")
+ .build();
DataProduct result = client.createDataProduct(dataProduct);
System.out.println(MessageFormat.format("Created data product with id [{0}]", result.getDataProductId()));
diff --git a/data-catalog-api/server/pom.xml b/data-catalog-api/server/pom.xml
index b3c9cf1..d2b0ce1 100644
--- a/data-catalog-api/server/pom.xml
+++ b/data-catalog-api/server/pom.xml
@@ -52,7 +52,16 @@
<artifactId>data-catalog-api-stubs</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
-
+ <dependency>
+ <groupId>io.hypersistence</groupId>
+ <artifactId>hypersistence-utils-hibernate-60</artifactId>
+ <version>3.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.module</groupId>
+ <artifactId>jackson-module-jakarta-xmlbind-annotations</artifactId>
+ <version>2.14.1</version>
+ </dependency>
</dependencies>
<build>
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
index 01aa429..c9a67d2 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
@@ -1,5 +1,10 @@
package org.apache.airavata.datacatalog.api.model;
+import org.hibernate.annotations.Type;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+import io.hypersistence.utils.hibernate.type.json.JsonType;
import jakarta.persistence.Basic;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
@@ -34,6 +39,10 @@ public class DataProductEntity {
@Column(name="name", nullable = false)
private String name;
+ @Type(JsonType.class)
+ @Column(name = "metadata", columnDefinition = "jsonb")
+ private JsonNode metadata;
+
public Long getDataProductId() {
return dataProductId;
}
@@ -66,6 +75,14 @@ public class DataProductEntity {
this.name = name;
}
+ public JsonNode getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(JsonNode metadata) {
+ this.metadata = metadata;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index d4e9589..fa979a6 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -3,7 +3,6 @@ package org.apache.airavata.datacatalog.api.service;
import java.util.UUID;
import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc;
-import org.apache.airavata.datacatalog.api.DataProduct;
import org.apache.airavata.datacatalog.api.DataProductCreateRequest;
import org.apache.airavata.datacatalog.api.DataProductCreateResponse;
import org.apache.airavata.datacatalog.api.model.DataProductEntity;
@@ -13,6 +12,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
import io.grpc.stub.StreamObserver;
@GRpcService
@@ -37,6 +40,15 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
.findByExternalId(request.getDataProduct().getParentDataProductId());
dataProductEntity.setParentDataProductEntity(parentDataProductEntity);
}
+ if (request.getDataProduct().hasMetadata()) {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ JsonNode metadata = mapper.readTree(request.getDataProduct().getMetadata());
+ dataProductEntity.setMetadata(metadata);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProductEntity);
DataProductCreateResponse.Builder responseBuilder = DataProductCreateResponse.newBuilder();
diff --git a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
index 0a2a083..43854f9 100644
--- a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@ -25,6 +25,7 @@ message DataProduct {
string data_product_id = 1;
optional string parent_data_product_id = 2;
string name = 3;
+ optional string metadata = 4;
}
message DataProductCreateRequest {
[airavata-data-catalog] 13/36: Adding custos sharing lib
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 454ca5a3b25738bdc2924b791bfedde5d5078c0a
Author: Isuru Ranawaka <ir...@gmail.com>
AuthorDate: Tue Feb 14 12:34:21 2023 -0500
Adding custos sharing lib
---
data-catalog-api/server/pom.xml | 15 +++++
.../api/DataCatalogApiServiceApplication.java | 7 +++
.../api/sharing/SharingManagerImpl.java | 69 ++++++++++++++++++++++
.../src/main/resources/application.properties | 2 +-
pom.xml | 2 +-
5 files changed, 93 insertions(+), 2 deletions(-)
diff --git a/data-catalog-api/server/pom.xml b/data-catalog-api/server/pom.xml
index d2b0ce1..e4462e6 100644
--- a/data-catalog-api/server/pom.xml
+++ b/data-catalog-api/server/pom.xml
@@ -52,6 +52,21 @@
<artifactId>data-catalog-api-stubs</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.custos</groupId>
+ <artifactId>sharing-core-impl</artifactId>
+ <version>1.1-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.mysql</groupId>
+ <artifactId>mysql-connector-j</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>jakarta.persistence</groupId>
+ <artifactId>jakarta.persistence-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-60</artifactId>
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/DataCatalogApiServiceApplication.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/DataCatalogApiServiceApplication.java
index 5b3fa8e..b330f6c 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/DataCatalogApiServiceApplication.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/DataCatalogApiServiceApplication.java
@@ -2,8 +2,15 @@ package org.apache.airavata.datacatalog.api;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+@ComponentScan(basePackages = {"org.apache.airavata.datacatalog.api","org.apache.custos.sharing.core"})
@SpringBootApplication
+@EnableJpaRepositories({"org.apache.custos.sharing.core.persistance.repository","org.apache.airavata.datacatalog.api.repository"})
+@EntityScan(basePackages = {"org.apache.airavata.datacatalog.api.model","org.apache.custos.sharing.core.persistance.model"})
public class DataCatalogApiServiceApplication {
public static void main(String[] args) {
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManagerImpl.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManagerImpl.java
new file mode 100644
index 0000000..051bc35
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/sharing/SharingManagerImpl.java
@@ -0,0 +1,69 @@
+package org.apache.airavata.datacatalog.api.sharing;
+
+import org.apache.airavata.datacatalog.api.DataProduct;
+import org.apache.airavata.datacatalog.api.GroupInfo;
+import org.apache.airavata.datacatalog.api.Permission;
+import org.apache.airavata.datacatalog.api.UserInfo;
+import org.apache.airavata.datacatalog.api.model.UserEntity;
+
+import org.apache.custos.sharing.core.impl.SharingImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SharingManagerImpl implements SharingManager {
+
+ @Autowired
+ SharingImpl custosSharingImpl;
+
+
+ @Override
+ public UserEntity resolveUser(UserInfo userInfo) {
+ return null;
+ }
+
+ @Override
+ public boolean userHasAccess(UserInfo userInfo, DataProduct dataProduct, Permission permission) {
+ return false;
+ }
+
+ @Override
+ public String getDataProductSharingView() {
+ return null;
+ }
+
+ @Override
+ public void grantPermissionToUser(UserInfo userInfo, DataProduct dataProduct, Permission permission) {
+
+ }
+
+ @Override
+ public void revokePermissionFromUser(UserInfo userInfo, DataProduct dataProduct, Permission permission) {
+
+ }
+
+ @Override
+ public void grantPermissionToGroup(GroupInfo groupInfo, DataProduct dataProduct, Permission permission) {
+
+ }
+
+ @Override
+ public void revokePermissionFromGroup(GroupInfo groupInfo, DataProduct dataProduct, Permission permission) {
+
+ }
+
+ @Override
+ public boolean hasPublicAccess(DataProduct dataProduct, Permission permission) {
+ return false;
+ }
+
+ @Override
+ public void grantPublicAccess(DataProduct dataProduct, Permission permission) {
+
+ }
+
+ @Override
+ public void revokePublicAccess(DataProduct dataProduct, Permission permission) {
+
+ }
+}
diff --git a/data-catalog-api/server/src/main/resources/application.properties b/data-catalog-api/server/src/main/resources/application.properties
index 2064c00..a3d7d14 100644
--- a/data-catalog-api/server/src/main/resources/application.properties
+++ b/data-catalog-api/server/src/main/resources/application.properties
@@ -1,4 +1,4 @@
-spring.datasource.url=jdbc:postgresql://localhost:5432/data_catalog
+spring.datasource.url=jdbc:postgresql://localhost:5431/data_catalog
spring.datasource.username=postgres
spring.datasource.password=example
spring.jpa.hibernate.ddl-auto=update
diff --git a/pom.xml b/pom.xml
index 2fd997b..c1f2d98 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,7 +43,7 @@ under the License.
<slf4j.version>2.0.6</slf4j.version>
<os.maven.plugin>1.6.2</os.maven.plugin>
<protobuf.maven.plugin>0.6.1</protobuf.maven.plugin>
- <protobuf.protoc.version>3.21.7</protobuf.protoc.version>
+ <protobuf.protoc.version>3.21.11</protobuf.protoc.version>
<grpc.version>1.52.1</grpc.version>
<protoc-gen-grpc-java.version>${grpc.version}</protoc-gen-grpc-java.version>
<tomcat.annotations-api.version>6.0.53</tomcat.annotations-api.version>
[airavata-data-catalog] 12/36: Initial work at implementing metadata schema management APIs
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 131ca0eabdfebb7573812614af75c6d4d12ff835
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Feb 13 17:01:28 2023 -0500
Initial work at implementing metadata schema management APIs
---
.../api/client/DataCatalogAPIClient.java | 62 ++++++++++-
.../api/mapper/MetadataSchemaFieldMapper.java | 36 +++++++
.../api/mapper/MetadataSchemaMapper.java | 19 ++++
.../api/model/MetadataSchemaEntity.java | 73 +++++++++++++
.../api/model/MetadataSchemaFieldEntity.java | 108 +++++++++++++++++++
.../repository/MetadataSchemaFieldRepository.java | 11 ++
.../api/repository/MetadataSchemaRepository.java | 9 ++
.../api/service/DataCatalogAPIService.java | 119 ++++++++++++++++++++-
.../stubs/src/main/proto/DataCatalogAPI.proto | 83 ++++++++++++++
9 files changed, 515 insertions(+), 5 deletions(-)
diff --git a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
index 8ae7d07..954f994 100644
--- a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
+++ b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
@@ -1,6 +1,7 @@
package org.apache.airavata.datacatalog.api.client;
import java.text.MessageFormat;
+import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc;
@@ -13,8 +14,15 @@ import org.apache.airavata.datacatalog.api.DataProductGetRequest;
import org.apache.airavata.datacatalog.api.DataProductGetResponse;
import org.apache.airavata.datacatalog.api.DataProductUpdateRequest;
import org.apache.airavata.datacatalog.api.DataProductUpdateResponse;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.airavata.datacatalog.api.FieldValueType;
+import org.apache.airavata.datacatalog.api.MetadataSchema;
+import org.apache.airavata.datacatalog.api.MetadataSchemaCreateRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaCreateResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchemaField;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldCreateRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldCreateResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListResponse;
import io.grpc.Channel;
import io.grpc.ManagedChannel;
@@ -22,8 +30,6 @@ import io.grpc.ManagedChannelBuilder;;
public class DataCatalogAPIClient {
- private static final Logger logger = LoggerFactory.getLogger(DataCatalogAPIClient.class);
-
private final DataCatalogAPIServiceBlockingStub blockingStub;
public DataCatalogAPIClient(Channel channel) {
@@ -54,6 +60,27 @@ public class DataCatalogAPIClient {
blockingStub.deleteDataProduct(request);
}
+ public MetadataSchema createMetadataSchema(MetadataSchema metadataSchema) {
+ MetadataSchemaCreateRequest request = MetadataSchemaCreateRequest.newBuilder().setMetadataSchema(metadataSchema)
+ .build();
+ MetadataSchemaCreateResponse response = blockingStub.createMetadataSchema(request);
+ return response.getMetadataSchema();
+ }
+
+ public MetadataSchemaField createMetadataSchemaField(MetadataSchemaField metadataSchemaField) {
+ MetadataSchemaFieldCreateRequest request = MetadataSchemaFieldCreateRequest.newBuilder()
+ .setMetadataSchemaField(metadataSchemaField).build();
+ MetadataSchemaFieldCreateResponse response = blockingStub.createMetadataSchemaField(request);
+ return response.getMetadataSchemaField();
+ }
+
+ public List<MetadataSchemaField> getMetadataSchemaFields(String schemaName) {
+ MetadataSchemaFieldListRequest request = MetadataSchemaFieldListRequest.newBuilder().setSchemaName(schemaName)
+ .build();
+ MetadataSchemaFieldListResponse response = blockingStub.getMetadataSchemaFields(request);
+ return response.getMetadataSchemaFieldsList();
+ }
+
public static void main(String[] args) throws InterruptedException {
String target = "localhost:6565";
@@ -88,6 +115,33 @@ public class DataCatalogAPIClient {
System.out.println(
MessageFormat.format("Deleted data product with id [{0}]", result2.getDataProductId()));
+ MetadataSchema metadataSchema = MetadataSchema.newBuilder().setSchemaName("my_schema").build();
+ metadataSchema = client.createMetadataSchema(metadataSchema);
+
+ System.out.println(
+ MessageFormat.format("Created metadata schema with name [{0}]", metadataSchema.getSchemaName()));
+
+ MetadataSchemaField field1 = MetadataSchemaField.newBuilder().setFieldName("field1")
+ .setJsonPath("$.field1").setValueType(FieldValueType.FLOAT)
+ .setSchemaName(metadataSchema.getSchemaName()).build();
+ field1 = client.createMetadataSchemaField(field1);
+ System.out.println(MessageFormat.format("Created metadata schema field [{0}] in schema [{1}]",
+ field1.getFieldName(), field1.getSchemaName()));
+
+ MetadataSchemaField field2 = MetadataSchemaField.newBuilder().setFieldName("field2")
+ .setJsonPath("$.field2").setValueType(FieldValueType.FLOAT)
+ .setSchemaName(metadataSchema.getSchemaName()).build();
+ field2 = client.createMetadataSchemaField(field2);
+ System.out.println(MessageFormat.format("Created metadata schema field [{0}] in schema [{1}]",
+ field2.getFieldName(), field2.getSchemaName()));
+
+ List<MetadataSchemaField> fields = client.getMetadataSchemaFields(metadataSchema.getSchemaName());
+ System.out.println(MessageFormat.format("Found {0} fields for schema {1}", fields.size(),
+ metadataSchema.getSchemaName()));
+ for (MetadataSchemaField field : fields) {
+ System.out.println(MessageFormat.format("-> field {0}", field.getFieldName()));
+ }
+
} finally {
channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/MetadataSchemaFieldMapper.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/MetadataSchemaFieldMapper.java
new file mode 100644
index 0000000..2a96ec4
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/MetadataSchemaFieldMapper.java
@@ -0,0 +1,36 @@
+package org.apache.airavata.datacatalog.api.mapper;
+
+import org.apache.airavata.datacatalog.api.MetadataSchemaField;
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaFieldEntity;
+import org.apache.airavata.datacatalog.api.repository.MetadataSchemaRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class MetadataSchemaFieldMapper {
+
+ @Autowired
+ MetadataSchemaRepository metadataSchemaRepository;
+
+ public void mapModelToEntity(MetadataSchemaField metadataSchemaField,
+ MetadataSchemaFieldEntity metadataSchemaFieldEntity) {
+
+ metadataSchemaFieldEntity.setFieldName(metadataSchemaField.getFieldName());
+ metadataSchemaFieldEntity.setFieldValueType(metadataSchemaField.getValueType());
+ metadataSchemaFieldEntity.setJsonPath(metadataSchemaField.getJsonPath());
+
+ MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository
+ .findBySchemaName(metadataSchemaField.getSchemaName());
+ metadataSchemaFieldEntity.setMetadataSchema(metadataSchemaEntity);
+ }
+
+ public void mapEntityToModel(MetadataSchemaFieldEntity metadataSchemaFieldEntity,
+ MetadataSchemaField.Builder metadataSchemaFieldBuilder) {
+
+ metadataSchemaFieldBuilder.setFieldName(metadataSchemaFieldEntity.getFieldName());
+ metadataSchemaFieldBuilder.setJsonPath(metadataSchemaFieldEntity.getJsonPath());
+ metadataSchemaFieldBuilder.setValueType(metadataSchemaFieldEntity.getFieldValueType());
+ metadataSchemaFieldBuilder.setSchemaName(metadataSchemaFieldEntity.getMetadataSchema().getSchemaName());
+ }
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/MetadataSchemaMapper.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/MetadataSchemaMapper.java
new file mode 100644
index 0000000..e7c6fcd
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/MetadataSchemaMapper.java
@@ -0,0 +1,19 @@
+package org.apache.airavata.datacatalog.api.mapper;
+
+import org.apache.airavata.datacatalog.api.MetadataSchema;
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
+import org.springframework.stereotype.Component;
+
+@Component
+public class MetadataSchemaMapper {
+
+ public void mapModelToEntity(MetadataSchema metadataSchema, MetadataSchemaEntity metadataSchemaEntity) {
+
+ metadataSchemaEntity.setSchemaName(metadataSchema.getSchemaName());
+ }
+
+ public void mapEntityToModel(MetadataSchemaEntity metadataSchemaEntity,
+ MetadataSchema.Builder metadataSchemaBuilder) {
+ metadataSchemaBuilder.setSchemaName(metadataSchemaEntity.getSchemaName());
+ }
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaEntity.java
new file mode 100644
index 0000000..8c1f6cd
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaEntity.java
@@ -0,0 +1,73 @@
+package org.apache.airavata.datacatalog.api.model;
+
+import java.util.Set;
+
+import jakarta.persistence.Basic;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.OneToMany;
+import jakarta.persistence.SequenceGenerator;
+import jakarta.persistence.Table;
+
+@Entity
+// TODO: unique constraint on schema_name, tenant
+@Table(name = "metadata_schema")
+public class MetadataSchemaEntity {
+
+ @Id
+ @SequenceGenerator(name = "metadata_schema_metadata_schema_id_seq", sequenceName = "metadata_schema_metadata_schema_id_seq", allocationSize = 1)
+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "metadata_schema_metadata_schema_id_seq")
+ @Column(name = "metadata_schema_id")
+ private Long metadataSchemaId;
+
+ @Basic
+ @Column(name = "schema_name", nullable = false)
+ private String schemaName;
+
+ @OneToMany(mappedBy = "metadataSchema")
+ private Set<MetadataSchemaFieldEntity> metadataSchemaFields;
+
+ public Long getMetadataSchemaId() {
+ return metadataSchemaId;
+ }
+
+ public void setMetadataSchemaId(Long metadataSchemaId) {
+ this.metadataSchemaId = metadataSchemaId;
+ }
+
+ public String getSchemaName() {
+ return schemaName;
+ }
+
+ public void setSchemaName(String schemaName) {
+ this.schemaName = schemaName;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((metadataSchemaId == null) ? 0 : metadataSchemaId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ MetadataSchemaEntity other = (MetadataSchemaEntity) obj;
+ if (metadataSchemaId == null) {
+ if (other.metadataSchemaId != null)
+ return false;
+ } else if (!metadataSchemaId.equals(other.metadataSchemaId))
+ return false;
+ return true;
+ }
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaFieldEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaFieldEntity.java
new file mode 100644
index 0000000..8f6a83a
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaFieldEntity.java
@@ -0,0 +1,108 @@
+package org.apache.airavata.datacatalog.api.model;
+
+import org.apache.airavata.datacatalog.api.FieldValueType;
+
+import jakarta.persistence.Basic;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.EnumType;
+import jakarta.persistence.Enumerated;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.JoinColumn;
+import jakarta.persistence.ManyToOne;
+import jakarta.persistence.SequenceGenerator;
+import jakarta.persistence.Table;
+
+@Entity
+@Table(name = "metadata_schema_field")
+public class MetadataSchemaFieldEntity {
+
+ @Id
+ @SequenceGenerator(name = "metadata_schema_field_metadata_schema_field_id", sequenceName = "metadata_schema_field_metadata_schema_field_id", allocationSize = 1)
+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "metadata_schema_field_metadata_schema_field_id")
+ @Column(name = "metadata_schema_field_id")
+ private Long metadataSchemaFieldId;
+
+ @Basic
+ @Column(name = "field_name", nullable = false)
+ private String fieldName;
+
+ @Basic
+ @Column(name = "json_path", nullable = false)
+ private String jsonPath;
+
+ @Enumerated(EnumType.STRING)
+ private FieldValueType fieldValueType;
+
+ @ManyToOne(optional = false)
+ @JoinColumn(name = "metadata_schema_id", nullable = false, updatable = false)
+ private MetadataSchemaEntity metadataSchema;
+
+ public Long getMetadataSchemaFieldId() {
+ return metadataSchemaFieldId;
+ }
+
+ public void setMetadataSchemaFieldId(Long metadataSchemaFieldId) {
+ this.metadataSchemaFieldId = metadataSchemaFieldId;
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ public String getJsonPath() {
+ return jsonPath;
+ }
+
+ public void setJsonPath(String jsonPath) {
+ this.jsonPath = jsonPath;
+ }
+
+ public FieldValueType getFieldValueType() {
+ return fieldValueType;
+ }
+
+ public void setFieldValueType(FieldValueType fieldValueType) {
+ this.fieldValueType = fieldValueType;
+ }
+
+ public MetadataSchemaEntity getMetadataSchema() {
+ return metadataSchema;
+ }
+
+ public void setMetadataSchema(MetadataSchemaEntity metadataSchema) {
+ this.metadataSchema = metadataSchema;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((metadataSchemaFieldId == null) ? 0 : metadataSchemaFieldId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ MetadataSchemaFieldEntity other = (MetadataSchemaFieldEntity) obj;
+ if (metadataSchemaFieldId == null) {
+ if (other.metadataSchemaFieldId != null)
+ return false;
+ } else if (!metadataSchemaFieldId.equals(other.metadataSchemaFieldId))
+ return false;
+ return true;
+ }
+
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaFieldRepository.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaFieldRepository.java
new file mode 100644
index 0000000..e237dac
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaFieldRepository.java
@@ -0,0 +1,11 @@
+package org.apache.airavata.datacatalog.api.repository;
+
+import java.util.List;
+
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaFieldEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface MetadataSchemaFieldRepository extends JpaRepository<MetadataSchemaFieldEntity, Long> {
+
+ List<MetadataSchemaFieldEntity> findByMetadataSchema_SchemaName(String schemaName);
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaRepository.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaRepository.java
new file mode 100644
index 0000000..28d0518
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaRepository.java
@@ -0,0 +1,9 @@
+package org.apache.airavata.datacatalog.api.repository;
+
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface MetadataSchemaRepository extends JpaRepository<MetadataSchemaEntity, Long> {
+
+ MetadataSchemaEntity findBySchemaName(String schemaName);
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index 65f92b7..3869ee5 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -1,20 +1,42 @@
package org.apache.airavata.datacatalog.api.service;
+import java.util.List;
import java.util.UUID;
import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc;
import org.apache.airavata.datacatalog.api.DataProduct;
+import org.apache.airavata.datacatalog.api.DataProductAddToMetadataSchemaRequest;
+import org.apache.airavata.datacatalog.api.DataProductAddToMetadataSchemaResponse;
import org.apache.airavata.datacatalog.api.DataProductCreateRequest;
import org.apache.airavata.datacatalog.api.DataProductCreateResponse;
import org.apache.airavata.datacatalog.api.DataProductDeleteRequest;
import org.apache.airavata.datacatalog.api.DataProductDeleteResponse;
import org.apache.airavata.datacatalog.api.DataProductGetRequest;
import org.apache.airavata.datacatalog.api.DataProductGetResponse;
+import org.apache.airavata.datacatalog.api.DataProductRemoveFromMetadataSchemaRequest;
+import org.apache.airavata.datacatalog.api.DataProductRemoveFromMetadataSchemaResponse;
import org.apache.airavata.datacatalog.api.DataProductUpdateRequest;
import org.apache.airavata.datacatalog.api.DataProductUpdateResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchemaCreateRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaCreateResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchemaField;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldCreateRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldCreateResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldDeleteRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldDeleteResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldUpdateRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldUpdateResponse;
import org.apache.airavata.datacatalog.api.mapper.DataProductMapper;
+import org.apache.airavata.datacatalog.api.mapper.MetadataSchemaFieldMapper;
+import org.apache.airavata.datacatalog.api.mapper.MetadataSchemaMapper;
import org.apache.airavata.datacatalog.api.model.DataProductEntity;
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaFieldEntity;
import org.apache.airavata.datacatalog.api.repository.DataProductRepository;
+import org.apache.airavata.datacatalog.api.repository.MetadataSchemaFieldRepository;
+import org.apache.airavata.datacatalog.api.repository.MetadataSchemaRepository;
import org.lognet.springboot.grpc.GRpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,7 +53,19 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
DataProductRepository dataProductRepository;
@Autowired
- DataProductMapper dataProductMapper = new DataProductMapper();
+ MetadataSchemaRepository metadataSchemaRepository;
+
+ @Autowired
+ MetadataSchemaFieldRepository metadataSchemaFieldRepository;
+
+ @Autowired
+ DataProductMapper dataProductMapper;
+
+ @Autowired
+ MetadataSchemaMapper metadataSchemaMapper;
+
+ @Autowired
+ MetadataSchemaFieldMapper metadataSchemaFieldMapper;
@Override
public void createDataProduct(DataProductCreateRequest request,
@@ -93,4 +127,87 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
responseObserver.onNext(responseBuilder.build());
responseObserver.onCompleted();
}
+
+ @Override
+ public void addDataProductToMetadataSchema(DataProductAddToMetadataSchemaRequest request,
+ StreamObserver<DataProductAddToMetadataSchemaResponse> responseObserver) {
+ // TODO Auto-generated method stub
+ super.addDataProductToMetadataSchema(request, responseObserver);
+ }
+
+ @Override
+ public void createMetadataSchema(MetadataSchemaCreateRequest request,
+ StreamObserver<MetadataSchemaCreateResponse> responseObserver) {
+
+ MetadataSchemaEntity metadataSchemaEntity = new MetadataSchemaEntity();
+ metadataSchemaMapper.mapModelToEntity(request.getMetadataSchema(), metadataSchemaEntity);
+ MetadataSchemaEntity savedMetadataSchemaEntity = metadataSchemaRepository.save(metadataSchemaEntity);
+
+ MetadataSchemaCreateResponse.Builder responseBuilder = MetadataSchemaCreateResponse.newBuilder();
+ metadataSchemaMapper.mapEntityToModel(savedMetadataSchemaEntity, responseBuilder.getMetadataSchemaBuilder());
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onCompleted();
+ }
+
+ @Override
+ public void createMetadataSchemaField(MetadataSchemaFieldCreateRequest request,
+ StreamObserver<MetadataSchemaFieldCreateResponse> responseObserver) {
+
+ MetadataSchemaFieldEntity metadataSchemaFieldEntity = new MetadataSchemaFieldEntity();
+ metadataSchemaFieldMapper.mapModelToEntity(request.getMetadataSchemaField(), metadataSchemaFieldEntity);
+ MetadataSchemaFieldEntity savedMetadataSchemaFieldEntity = metadataSchemaFieldRepository
+ .save(metadataSchemaFieldEntity);
+
+ MetadataSchemaFieldCreateResponse.Builder responseBuilder = MetadataSchemaFieldCreateResponse.newBuilder();
+ metadataSchemaFieldMapper.mapEntityToModel(savedMetadataSchemaFieldEntity,
+ responseBuilder.getMetadataSchemaFieldBuilder());
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onCompleted();
+ }
+
+ @Override
+ public void deleteMetadataSchema(MetadataSchemaCreateRequest request,
+ StreamObserver<MetadataSchemaCreateResponse> responseObserver) {
+ // TODO Auto-generated method stub
+ super.deleteMetadataSchema(request, responseObserver);
+ }
+
+ @Override
+ public void deleteMetadataSchemaField(MetadataSchemaFieldDeleteRequest request,
+ StreamObserver<MetadataSchemaFieldDeleteResponse> responseObserver) {
+ // TODO Auto-generated method stub
+ super.deleteMetadataSchemaField(request, responseObserver);
+ }
+
+ @Override
+ public void getMetadataSchemaFields(MetadataSchemaFieldListRequest request,
+ StreamObserver<MetadataSchemaFieldListResponse> responseObserver) {
+
+ // TODO: handle case where schema doesn't exist
+ List<MetadataSchemaFieldEntity> metadataSchemaFieldEntities = metadataSchemaFieldRepository
+ .findByMetadataSchema_SchemaName(request.getSchemaName());
+
+ MetadataSchemaFieldListResponse.Builder responseBuilder = MetadataSchemaFieldListResponse.newBuilder();
+ for (MetadataSchemaFieldEntity metadataSchemaFieldEntity : metadataSchemaFieldEntities) {
+ MetadataSchemaField.Builder builder = responseBuilder.addMetadataSchemaFieldsBuilder();
+ metadataSchemaFieldMapper.mapEntityToModel(metadataSchemaFieldEntity, builder);
+ }
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onError(null);
+ responseObserver.onCompleted();
+ }
+
+ @Override
+ public void removeDataProductFromMetadataSchema(DataProductRemoveFromMetadataSchemaRequest request,
+ StreamObserver<DataProductRemoveFromMetadataSchemaResponse> responseObserver) {
+ // TODO Auto-generated method stub
+ super.removeDataProductFromMetadataSchema(request, responseObserver);
+ }
+
+ @Override
+ public void updateMetadataSchemaField(MetadataSchemaFieldUpdateRequest request,
+ StreamObserver<MetadataSchemaFieldUpdateResponse> responseObserver) {
+ // TODO Auto-generated method stub
+ super.updateMetadataSchemaField(request, responseObserver);
+ }
}
diff --git a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
index 779002c..b1d40dd 100644
--- a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@ -64,6 +64,23 @@ message DataProduct {
optional string metadata = 4;
}
+enum FieldValueType {
+ STRING = 0;
+ INTEGER = 1;
+ FLOAT = 2;
+ BOOLEAN = 3;
+ DATESTRING = 4;
+}
+message MetadataSchema {
+ string schema_name = 1;
+}
+message MetadataSchemaField {
+ string schema_name = 1;
+ string field_name = 2;
+ string json_path = 3;
+ FieldValueType value_type = 4;
+}
+
message DataProductCreateRequest {
DataProduct data_product = 1;
}
@@ -88,9 +105,75 @@ message DataProductDeleteRequest {
message DataProductDeleteResponse {
}
+message MetadataSchemaCreateRequest {
+ UserInfo user_info = 1;
+ MetadataSchema metadata_schema = 2;
+}
+message MetadataSchemaCreateResponse {
+ MetadataSchema metadata_schema = 1;
+}
+message MetadataSchemaDeleteRequest {
+ UserInfo user_info = 1;
+ MetadataSchema metadata_schema = 2;
+}
+message MetadataSchemaDeleteResponse {
+}
+message MetadataSchemaFieldCreateRequest {
+ UserInfo user_info = 1;
+ MetadataSchemaField metadata_schema_field = 2;
+}
+message MetadataSchemaFieldCreateResponse {
+ MetadataSchemaField metadata_schema_field = 1;
+}
+message MetadataSchemaFieldUpdateRequest {
+ UserInfo user_info = 1;
+ MetadataSchemaField metadata_schema_field = 2;
+}
+message MetadataSchemaFieldUpdateResponse {
+ MetadataSchemaField metadata_schema_field = 1;
+}
+message MetadataSchemaFieldDeleteRequest {
+ UserInfo user_info = 1;
+ MetadataSchemaField metadata_schema_field = 2;
+}
+message MetadataSchemaFieldDeleteResponse {
+}
+message MetadataSchemaFieldListRequest {
+ UserInfo user_info = 1;
+ string schema_name = 2;
+}
+message MetadataSchemaFieldListResponse {
+ repeated MetadataSchemaField metadata_schema_fields = 1;
+}
+message DataProductAddToMetadataSchemaRequest {
+ UserInfo user_info = 1;
+ string data_product_id = 2;
+ string schema_name = 3;
+}
+message DataProductAddToMetadataSchemaResponse {
+ DataProduct data_product = 1;
+}
+message DataProductRemoveFromMetadataSchemaRequest {
+ UserInfo user_info = 1;
+ string data_product_id = 2;
+ string schema_name = 3;
+}
+message DataProductRemoveFromMetadataSchemaResponse {
+ DataProduct data_product = 1;
+}
+
+
service DataCatalogAPIService {
rpc createDataProduct(DataProductCreateRequest) returns (DataProductCreateResponse){}
rpc updateDataProduct(DataProductUpdateRequest) returns (DataProductUpdateResponse){}
rpc getDataProduct(DataProductGetRequest) returns (DataProductGetResponse){}
rpc deleteDataProduct(DataProductDeleteRequest) returns (DataProductDeleteResponse){}
+ rpc createMetadataSchema(MetadataSchemaCreateRequest) returns (MetadataSchemaCreateResponse){}
+ rpc deleteMetadataSchema(MetadataSchemaCreateRequest) returns (MetadataSchemaCreateResponse){}
+ rpc createMetadataSchemaField(MetadataSchemaFieldCreateRequest) returns (MetadataSchemaFieldCreateResponse){}
+ rpc updateMetadataSchemaField(MetadataSchemaFieldUpdateRequest) returns (MetadataSchemaFieldUpdateResponse){}
+ rpc deleteMetadataSchemaField(MetadataSchemaFieldDeleteRequest) returns (MetadataSchemaFieldDeleteResponse){}
+ rpc getMetadataSchemaFields(MetadataSchemaFieldListRequest) returns (MetadataSchemaFieldListResponse){}
+ rpc addDataProductToMetadataSchema(DataProductAddToMetadataSchemaRequest) returns (DataProductAddToMetadataSchemaResponse){}
+ rpc removeDataProductFromMetadataSchema(DataProductRemoveFromMetadataSchemaRequest) returns (DataProductRemoveFromMetadataSchemaResponse){}
}
[airavata-data-catalog] 18/36: Additional methods to manage metadata schemas
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 88be4d08bbbb4f233f04f98cb99b7b95bad52bc5
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Feb 15 15:57:25 2023 -0500
Additional methods to manage metadata schemas
---
.../repository/MetadataSchemaFieldRepository.java | 2 +
.../api/service/DataCatalogAPIService.java | 43 ++++++++++++++++++----
.../stubs/src/main/proto/DataCatalogAPI.proto | 2 +-
3 files changed, 38 insertions(+), 9 deletions(-)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaFieldRepository.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaFieldRepository.java
index e237dac..c8503db 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaFieldRepository.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaFieldRepository.java
@@ -8,4 +8,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
public interface MetadataSchemaFieldRepository extends JpaRepository<MetadataSchemaFieldEntity, Long> {
List<MetadataSchemaFieldEntity> findByMetadataSchema_SchemaName(String schemaName);
+
+ MetadataSchemaFieldEntity findByFieldNameAndSchema_SchemaName(String fieldName, String schemaName);
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index 7374def..d001e46 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -19,6 +19,8 @@ import org.apache.airavata.datacatalog.api.DataProductUpdateRequest;
import org.apache.airavata.datacatalog.api.DataProductUpdateResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaCreateRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaCreateResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchemaDeleteRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaDeleteResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaField;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldCreateRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldCreateResponse;
@@ -196,17 +198,30 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
}
@Override
- public void deleteMetadataSchema(MetadataSchemaCreateRequest request,
- StreamObserver<MetadataSchemaCreateResponse> responseObserver) {
- // TODO Auto-generated method stub
- super.deleteMetadataSchema(request, responseObserver);
+ public void deleteMetadataSchema(MetadataSchemaDeleteRequest request,
+ StreamObserver<MetadataSchemaDeleteResponse> responseObserver) {
+ // TODO: check that user has write access on metadata schema
+ // TODO: handle metadata schema not found
+ MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository
+ .findBySchemaName(request.getMetadataSchema().getSchemaName());
+ metadataSchemaRepository.delete(metadataSchemaEntity);
+ MetadataSchemaDeleteResponse.Builder responseBuilder = MetadataSchemaDeleteResponse.newBuilder();
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onCompleted();
}
@Override
public void deleteMetadataSchemaField(MetadataSchemaFieldDeleteRequest request,
StreamObserver<MetadataSchemaFieldDeleteResponse> responseObserver) {
- // TODO Auto-generated method stub
- super.deleteMetadataSchemaField(request, responseObserver);
+ // TODO: check that user has write access on metadata schema field
+ // TODO: handle metadata schema field not found
+ MetadataSchemaFieldEntity metadataSchemaFieldEntity = metadataSchemaFieldRepository
+ .findByFieldNameAndSchema_SchemaName(request.getMetadataSchemaField().getFieldName(),
+ request.getMetadataSchemaField().getSchemaName());
+ metadataSchemaFieldRepository.delete(metadataSchemaFieldEntity);
+ MetadataSchemaFieldDeleteResponse.Builder responseBuilder = MetadataSchemaFieldDeleteResponse.newBuilder();
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onCompleted();
}
@Override
@@ -248,7 +263,19 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
@Override
public void updateMetadataSchemaField(MetadataSchemaFieldUpdateRequest request,
StreamObserver<MetadataSchemaFieldUpdateResponse> responseObserver) {
- // TODO Auto-generated method stub
- super.updateMetadataSchemaField(request, responseObserver);
+
+ // TODO: check that user has write access on metadata schema field
+ // TODO: handle metadata schema field not found
+ MetadataSchemaFieldEntity metadataSchemaFieldEntity = metadataSchemaFieldRepository
+ .findByFieldNameAndSchema_SchemaName(request.getMetadataSchemaField().getFieldName(),
+ request.getMetadataSchemaField().getSchemaName());
+ metadataSchemaFieldMapper.mapModelToEntity(request.getMetadataSchemaField(), metadataSchemaFieldEntity);
+ metadataSchemaFieldRepository.save(metadataSchemaFieldEntity);
+
+ MetadataSchemaFieldUpdateResponse.Builder responseBuilder = MetadataSchemaFieldUpdateResponse.newBuilder();
+ metadataSchemaFieldMapper.mapEntityToModel(metadataSchemaFieldEntity,
+ responseBuilder.getMetadataSchemaFieldBuilder());
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onCompleted();
}
}
diff --git a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
index 7d91b8b..74261d1 100644
--- a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@ -178,7 +178,7 @@ service DataCatalogAPIService {
rpc deleteDataProduct(DataProductDeleteRequest) returns (DataProductDeleteResponse){}
rpc getMetadataSchema(MetadataSchemaGetRequest) returns (MetadataSchemaGetResponse){}
rpc createMetadataSchema(MetadataSchemaCreateRequest) returns (MetadataSchemaCreateResponse){}
- rpc deleteMetadataSchema(MetadataSchemaCreateRequest) returns (MetadataSchemaCreateResponse){}
+ rpc deleteMetadataSchema(MetadataSchemaDeleteRequest) returns (MetadataSchemaDeleteResponse){}
rpc createMetadataSchemaField(MetadataSchemaFieldCreateRequest) returns (MetadataSchemaFieldCreateResponse){}
rpc updateMetadataSchemaField(MetadataSchemaFieldUpdateRequest) returns (MetadataSchemaFieldUpdateResponse){}
rpc deleteMetadataSchemaField(MetadataSchemaFieldDeleteRequest) returns (MetadataSchemaFieldDeleteResponse){}
[airavata-data-catalog] 31/36: Implement basic data product search over metadata schemas
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 8a148e803559c5164dddf71201b7356b0db6bac7
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Mar 21 10:53:49 2023 -0400
Implement basic data product search over metadata schemas
---
.../api/client/DataCatalogAPIClient.java | 47 ++++-
data-catalog-api/server/pom.xml | 5 +
.../datacatalog/api/query/MetadataQueryParser.java | 147 --------------
.../api/query/MetadataSchemaQueryExecutor.java | 6 +
.../api/query/MetadataSchemaQueryResult.java | 9 +
.../api/query/MetadataSchemaQueryWriter.java | 21 ++
.../impl/MetadataSchemaQueryExecutorImpl.java | 214 +++++++++++++++++++++
.../PostgresqlMetadataSchemaQueryWriterImpl.java | 201 +++++++++++++++++++
.../api/service/DataCatalogAPIService.java | 39 ++--
.../api/service/DataCatalogService.java | 3 +
.../api/service/impl/DataCatalogServiceImpl.java | 34 ++--
.../server/src/main/resources/logback.xml | 4 +
.../stubs/src/main/proto/DataCatalogAPI.proto | 42 ++--
13 files changed, 582 insertions(+), 190 deletions(-)
diff --git a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
index f01554e..794147b 100644
--- a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
+++ b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
@@ -16,6 +16,8 @@ import org.apache.airavata.datacatalog.api.DataProductGetRequest;
import org.apache.airavata.datacatalog.api.DataProductGetResponse;
import org.apache.airavata.datacatalog.api.DataProductRemoveFromMetadataSchemaRequest;
import org.apache.airavata.datacatalog.api.DataProductRemoveFromMetadataSchemaResponse;
+import org.apache.airavata.datacatalog.api.DataProductSearchRequest;
+import org.apache.airavata.datacatalog.api.DataProductSearchResponse;
import org.apache.airavata.datacatalog.api.DataProductUpdateRequest;
import org.apache.airavata.datacatalog.api.DataProductUpdateResponse;
import org.apache.airavata.datacatalog.api.FieldValueType;
@@ -133,6 +135,12 @@ public class DataCatalogAPIClient {
return response.getDataProduct();
}
+ public List<DataProduct> searchDataProducts(String sql) {
+ DataProductSearchRequest request = DataProductSearchRequest.newBuilder().setSql(sql).build();
+ DataProductSearchResponse response = blockingStub.searchDataProducts(request);
+ return response.getDataProductsList();
+ }
+
public static void main(String[] args) throws InterruptedException {
String target = "localhost:6565";
@@ -211,6 +219,21 @@ public class DataCatalogAPIClient {
field2.getFieldName(), field2.getSchemaName()));
}
+ MetadataSchemaField field3 = MetadataSchemaField.newBuilder().setFieldName("field3")
+ .setJsonPath("$.field3").setValueType(FieldValueType.STRING)
+ .setSchemaName(metadataSchema.getSchemaName()).build();
+ MetadataSchemaField field3Exists = client.getMetadataSchemaField(field3.getSchemaName(),
+ field3.getFieldName());
+ if (field3Exists == null) {
+ field3 = client.createMetadataSchemaField(field3);
+ System.out.println(MessageFormat.format("Created metadata schema field [{0}] in schema [{1}]",
+ field3.getFieldName(), field3.getSchemaName()));
+ } else {
+ field3 = field3Exists;
+ System.out.println(MessageFormat.format("Found metadata schema field [{0}] in schema [{1}]",
+ field3.getFieldName(), field3.getSchemaName()));
+ }
+
List<MetadataSchemaField> fields = client.getMetadataSchemaFields(metadataSchema.getSchemaName());
System.out.println(MessageFormat.format("Found {0} fields for schema {1}", fields.size(),
metadataSchema.getSchemaName()));
@@ -230,7 +253,7 @@ public class DataCatalogAPIClient {
// Create data product that belongs to my_schema schema
DataProduct dataProduct3 = DataProduct.newBuilder()
.setName("testing 3")
- .setMetadata("{\"foo\": \"bar\"}")
+ .setMetadata("{\"field3\": \"bar\", \"field1\": 10}")
.addMetadataSchemas("my_schema")
.build();
DataProduct result3 = client.createDataProduct(dataProduct3);
@@ -238,6 +261,28 @@ public class DataCatalogAPIClient {
MessageFormat.format("Created third data product [{0}], supporting schemas [{1}]",
result3.getDataProductId(), result3.getMetadataSchemasList()));
+ // Create another data product that belongs to my_schema schema, but with
+ // different "field3" and "field1" values
+ DataProduct dataProduct4 = DataProduct.newBuilder()
+ .setName("testing 4")
+ .setMetadata("{\"field3\": \"baz\", \"field1\": 2}")
+ .addMetadataSchemas("my_schema")
+ .build();
+ client.createDataProduct(dataProduct4);
+
+ List<DataProduct> searchResults = client.searchDataProducts("""
+ select * from my_schema where field3 = 'bar'
+ """);
+ System.out.println(searchResults);
+
+ searchResults = client.searchDataProducts("""
+ select * from my_schema where (field1 < 5 or field3 = 'bar') and field1 > 0
+ and external_id = 'fff'
+ """);
+ // searchResults = client.searchDataProducts("""
+ // select * from my_schema where not (field1 < 5 or field3 = 'bar')
+ // """);
+ System.out.println(searchResults);
} finally {
channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
}
diff --git a/data-catalog-api/server/pom.xml b/data-catalog-api/server/pom.xml
index cdaf834..e2318e9 100644
--- a/data-catalog-api/server/pom.xml
+++ b/data-catalog-api/server/pom.xml
@@ -43,6 +43,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-devtools</artifactId>
+ <optional>true</optional>
+ </dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataQueryParser.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataQueryParser.java
deleted file mode 100644
index 995497e..0000000
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataQueryParser.java
+++ /dev/null
@@ -1,147 +0,0 @@
-package org.apache.airavata.datacatalog.api.query;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.Collections;
-
-import javax.sql.DataSource;
-
-import org.apache.calcite.adapter.jdbc.JdbcSchema;
-import org.apache.calcite.jdbc.CalciteConnection;
-import org.apache.calcite.plan.RelOptUtil;
-import org.apache.calcite.rel.RelNode;
-import org.apache.calcite.rel.RelRoot;
-import org.apache.calcite.schema.SchemaPlus;
-import org.apache.calcite.schema.impl.ViewTable;
-import org.apache.calcite.sql.SqlExplainFormat;
-import org.apache.calcite.sql.SqlExplainLevel;
-import org.apache.calcite.sql.SqlNode;
-import org.apache.calcite.sql.dialect.PostgresqlSqlDialect;
-import org.apache.calcite.sql.parser.SqlParseException;
-import org.apache.calcite.sql.parser.SqlParser;
-import org.apache.calcite.tools.FrameworkConfig;
-import org.apache.calcite.tools.Frameworks;
-import org.apache.calcite.tools.Planner;
-import org.apache.calcite.tools.RelConversionException;
-import org.apache.calcite.tools.RelRunner;
-import org.apache.calcite.tools.ValidationException;
-
-public class MetadataQueryParser {
- private static final String POSTGRESQL_SCHEMA = "PUBLIC";
-
- public static void main(String[] args)
- throws SqlParseException, SQLException, ValidationException, RelConversionException {
- // SqlParser parser = SqlParser.create(
- // "SELECT * FROM smilesdb WHERE created_date > '2020-01-01' AND absorb < 300.0
- // ORDER BY created_date desc LIMIT 10");
- // SqlNode query = parser.parseQuery();
- // System.out.println(query.toSqlString(PostgresqlSqlDialect.DEFAULT));
-
- // Properties props = new Properties();
- // props.setProperty("currentSchema", "data_catalog");
- // props.setProperty("password", "secret");
- // props.setProperty("ssl", "true");
- // Connection connection = DriverManager.getConnection("jdbc:calcite:", props);
- Connection connection = DriverManager.getConnection("jdbc:calcite:");
- // Set the default schema for the connection
- // connection.setSchema("data_catalog");
- // Unwrap our connection using the CalciteConnection
- CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
- // calciteConnection.setSchema("data_catalog");
-
- // Get a pointer to our root schema for our Calcite Connection
- SchemaPlus rootSchema = calciteConnection.getRootSchema();
- // SchemaPlus rootSchema = Frameworks.createRootSchema(false);
-
- // Instantiate a data source, this can be autowired in using Spring as well
- DataSource postgresDataSource = JdbcSchema.dataSource(
- "jdbc:postgresql://localhost/data_catalog",
- "org.postgresql.Driver", // Change this if you want to use something like MySQL, Oracle,
- // etc.
- "postgres", // username
- "example" // password
- );
- // JdbcSchema jdbcSchema = JdbcSchema.create(rootSchema, POSTGRESQL_SCHEMA,
- // postgresDataSource, null, null);
- // System.out.println("tables: " + jdbcSchema.getTableNames());
- // rootSchema.add(POSTGRESQL_SCHEMA,
- // JdbcSchema.create(rootSchema, POSTGRESQL_SCHEMA, postgresDataSource, null,
- // null));
- // rootSchema.add("data_product", jdbcSchema.getTable("data_product"));
- SchemaPlus dcSchema = rootSchema.add("data_catalog",
- JdbcSchema.create(rootSchema, "data_catalog", postgresDataSource, null, null));
- dcSchema.add("smilesdb", ViewTable.viewMacro(dcSchema,
- "select data_product_id, parent_data_product_id, external_id, metadata, name from \"data_catalog\".\"data_product\" where jsonb_path_exists(\"metadata\", '$.foo == \"bar\"')",
- Collections.emptyList(), Arrays.asList("data_catalog", "smilesdb"), false));
-
- System.out.println("subschemas: " + rootSchema.getSubSchemaNames());
-
- FrameworkConfig config = Frameworks.newConfigBuilder()
- .defaultSchema(rootSchema)
- .parserConfig(PostgresqlSqlDialect.DEFAULT.configureParser(SqlParser.config()))
- // .parserConfig(SqlParser.Config.DEFAULT.withCaseSensitive(false).withQuoting(Quoting.))
- .build();
- // String query = "SELECT * FROM public.\"data_product\" WHERE
- // \"data_product_id\" = 1";
- // String query = "SELECT * FROM data_catalog.data_product WHERE data_product_id
- // = 1";
- // String query = "SELECT * FROM data_product WHERE data_product_id = 1";
- // "smilesdb" view macro
- String query = "SELECT * FROM data_catalog.smilesdb WHERE data_product_id = 1";
- Planner planner = Frameworks.getPlanner(config);
- SqlNode parse = planner.parse(query);
-
- // Change unqualified table referenced into qualified
- // final SqlNode transformedNode = parse.accept(
- // new SqlShuttle() {
- // @Override
- // public SqlNode visit(SqlIdentifier id) {
- // System.out.println("id: " + id);
- // System.out.println("id.names: " + id.names);
- // if (id.names.equals(Collections.singletonList("data_product"))) {
- // return new SqlIdentifier(Arrays.asList("data_catalog", "data_product"),
- // id.getParserPosition());
- // }
- // return id;
- // }
- // });
- System.out.println(parse.toSqlString(PostgresqlSqlDialect.DEFAULT));
- // System.out.println(parse.toString());
-
- SqlNode validate = planner.validate(parse);
- RelRoot relRoot = planner.rel(validate);
- // RelNode rel = relRoot.project();
- RelNode rel = relRoot.rel;
- System.out.println(RelOptUtil.dumpPlan("", rel, SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES));
-
- final RelRunner runner = connection.unwrap(RelRunner.class);
- PreparedStatement ps = runner.prepareStatement(rel);
-
- ps.executeQuery();
-
- ResultSet resultSet = ps.getResultSet();
-
- final StringBuilder buf = new StringBuilder();
-
- while (resultSet.next()) {
-
- int columnCount = resultSet.getMetaData().getColumnCount();
-
- for (int i = 1; i <= columnCount; i++) {
-
- buf.append(i > 1 ? "; " : "")
- .append(resultSet.getMetaData().getColumnLabel(i))
- .append("=")
- .append(resultSet.getObject(i));
- }
-
- System.out.println("Entry: " + buf.toString());
-
- buf.setLength(0);
- }
- }
-}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryExecutor.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryExecutor.java
new file mode 100644
index 0000000..6871553
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryExecutor.java
@@ -0,0 +1,6 @@
+package org.apache.airavata.datacatalog.api.query;
+
+public interface MetadataSchemaQueryExecutor {
+
+ MetadataSchemaQueryResult execute(String sql);
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryResult.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryResult.java
new file mode 100644
index 0000000..9d2c0f6
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryResult.java
@@ -0,0 +1,9 @@
+package org.apache.airavata.datacatalog.api.query;
+
+import java.util.List;
+
+import org.apache.airavata.datacatalog.api.DataProduct;
+
+public record MetadataSchemaQueryResult(List<DataProduct> dataProducts) {
+
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryWriter.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryWriter.java
new file mode 100644
index 0000000..08ab745
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataSchemaQueryWriter.java
@@ -0,0 +1,21 @@
+package org.apache.airavata.datacatalog.api.query;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
+import org.apache.calcite.sql.SqlNode;
+
+public interface MetadataSchemaQueryWriter {
+
+ /**
+ * Rewrite the query as needed to filter against metadata schema fields.
+ *
+ * @param sqlNode
+ * @param metadataSchemas
+ * @param tableAliases
+ * @return
+ */
+ String rewriteQuery(SqlNode sqlNode, Collection<MetadataSchemaEntity> metadataSchemas,
+ Map<String, String> tableAliases);
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/impl/MetadataSchemaQueryExecutorImpl.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/impl/MetadataSchemaQueryExecutorImpl.java
new file mode 100644
index 0000000..ab1202d
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/impl/MetadataSchemaQueryExecutorImpl.java
@@ -0,0 +1,214 @@
+package org.apache.airavata.datacatalog.api.query.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.airavata.datacatalog.api.DataProduct;
+import org.apache.airavata.datacatalog.api.FieldValueType;
+import org.apache.airavata.datacatalog.api.mapper.DataProductMapper;
+import org.apache.airavata.datacatalog.api.model.DataProductEntity;
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaFieldEntity;
+import org.apache.airavata.datacatalog.api.query.MetadataSchemaQueryExecutor;
+import org.apache.airavata.datacatalog.api.query.MetadataSchemaQueryResult;
+import org.apache.airavata.datacatalog.api.query.MetadataSchemaQueryWriter;
+import org.apache.airavata.datacatalog.api.repository.MetadataSchemaRepository;
+import org.apache.calcite.avatica.util.Casing;
+import org.apache.calcite.config.CalciteConnectionConfig;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.prepare.CalciteCatalogReader;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeFactory.Builder;
+import org.apache.calcite.runtime.CalciteContextException;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.impl.AbstractTable;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.util.SqlShuttle;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorUtil;
+import org.apache.calcite.tools.FrameworkConfig;
+import org.apache.calcite.tools.Frameworks;
+import org.apache.calcite.tools.Planner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import jakarta.persistence.EntityManager;
+
+@Component
+public class MetadataSchemaQueryExecutorImpl implements MetadataSchemaQueryExecutor {
+
+ private static final Logger logger = LoggerFactory.getLogger(MetadataSchemaQueryExecutorImpl.class);
+
+ @Autowired
+ MetadataSchemaRepository metadataSchemaRepository;
+
+ @Autowired
+ MetadataSchemaQueryWriter metadataSchemaQueryWriter;
+
+ @Autowired
+ EntityManager entityManager;
+
+ @Autowired
+ DataProductMapper dataProductMapper;
+
+ @Override
+ public MetadataSchemaQueryResult execute(String sql) {
+
+ // Create a schema that contains the data_product table and all of the metadata
+ // schemas
+ SchemaPlus schema = Frameworks.createRootSchema(true);
+ schema.add("data_product", new AbstractTable() {
+ @Override
+ public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+ Builder builder = (Builder) typeFactory.builder();
+ return builder
+ .add("data_product_id", SqlTypeName.INTEGER)
+ .add("parent_data_product_id", SqlTypeName.INTEGER)
+ .add("external_id", SqlTypeName.VARCHAR)
+ .add("metadata", SqlTypeName.OTHER)
+ .build();
+ }
+ });
+
+ // TODO: limit by tenant id
+ List<MetadataSchemaEntity> metadataSchemas = metadataSchemaRepository.findAll();
+ for (MetadataSchemaEntity metadataSchema : metadataSchemas) {
+
+ schema.add(metadataSchema.getSchemaName(), new AbstractTable() {
+ @Override
+ public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+ Builder builder = (Builder) typeFactory.builder();
+
+ // Add all of the common fields
+ builder.add("data_product_id", SqlTypeName.INTEGER)
+ .add("parent_data_product_id", SqlTypeName.INTEGER)
+ .add("external_id", SqlTypeName.VARCHAR)
+ .add("metadata", SqlTypeName.OTHER);
+
+ // Add all of the schema specific metadata fields
+ for (MetadataSchemaFieldEntity metadataSchemaField : metadataSchema.getMetadataSchemaFields()) {
+ builder.add(metadataSchemaField.getFieldName(),
+ getSqlTypeName(metadataSchemaField.getFieldValueType()));
+ }
+
+ return builder.build();
+ }
+ });
+ }
+
+ FrameworkConfig config = Frameworks.newConfigBuilder()
+ .defaultSchema(schema)
+ .parserConfig(SqlParser.Config.DEFAULT.withUnquotedCasing(Casing.TO_LOWER))
+ .build();
+ Planner planner = Frameworks.getPlanner(config);
+
+ SqlNode sqlNode = parse(planner, sql);
+
+ SqlValidator validator = getValidator(schema, config, planner);
+
+ // Validate the query
+ SqlNode validatedSqlNode = validate(validator, sqlNode);
+
+ // create a mapping of table aliases to actual tables (metadata schemas)
+ // For example, if query is of the form "select * from smilesdb as sm", then
+ // create a mapping from sm -> smilesdb
+
+ // TODO: may not be a SqlSelect, might be an OrderBy for example
+ SqlSelect selectNode = (SqlSelect) validatedSqlNode;
+ Map<String, String> tableAliases = new HashMap<>();
+ selectNode.getFrom().accept(new SqlShuttle() {
+
+ @Override
+ public SqlNode visit(SqlCall call) {
+ if (call.isA(Collections.singleton(SqlKind.AS))) {
+
+ SqlIdentifier first = call.operand(0);
+ SqlIdentifier second = call.operand(1);
+ tableAliases.put(second.getSimple(), first.getSimple());
+ }
+ return super.visit(call);
+ }
+
+ });
+
+ String finalSql = metadataSchemaQueryWriter.rewriteQuery(validatedSqlNode, metadataSchemas, tableAliases);
+ logger.debug("Metadata schema query final sql: {}", finalSql);
+
+ List<DataProductEntity> dataProductEntities = entityManager.createNativeQuery(finalSql, DataProductEntity.class)
+ .getResultList();
+
+ List<DataProduct> dataProducts = new ArrayList<>();
+ for (DataProductEntity dataProductEntity : dataProductEntities) {
+
+ org.apache.airavata.datacatalog.api.DataProduct.Builder dpBuilder = DataProduct.newBuilder();
+ dataProductMapper.mapEntityToModel(dataProductEntity, dpBuilder);
+ dataProducts.add(dpBuilder.build());
+ }
+
+ return new MetadataSchemaQueryResult(dataProducts);
+ }
+
+ private SqlValidator getValidator(SchemaPlus schema, FrameworkConfig config, Planner planner) {
+ CalciteConnectionConfig connectionConfig = CalciteConnectionConfig.DEFAULT;
+ CalciteCatalogReader catalogReader = new CalciteCatalogReader(CalciteSchema.from(schema),
+ CalciteSchema.from(schema).path(null),
+ planner.getTypeFactory(), connectionConfig);
+
+ SqlValidator validator = SqlValidatorUtil.newValidator(SqlStdOperatorTable.instance(),
+ catalogReader, planner.getTypeFactory(),
+ config.getSqlValidatorConfig().withIdentifierExpansion(false));
+ return validator;
+ }
+
+ SqlNode parse(Planner planner, String sql) {
+ try {
+ return planner.parse(sql);
+ } catch (SqlParseException e) {
+ // TODO: convert to a checked exception and add to interface
+ throw new RuntimeException(e);
+ }
+ }
+
+ SqlNode validate(SqlValidator validator, SqlNode sqlNode) {
+ try {
+ return validator.validate(sqlNode);
+ } catch (CalciteContextException e) {
+ // TODO: convert to a checked exception and add to interface
+ throw new RuntimeException(e);
+ }
+ }
+
+ private SqlTypeName getSqlTypeName(FieldValueType fieldValueType) {
+
+ switch (fieldValueType) {
+ case BOOLEAN:
+ return SqlTypeName.BOOLEAN;
+ case FLOAT:
+ return SqlTypeName.FLOAT;
+ case INTEGER:
+ return SqlTypeName.INTEGER;
+ case STRING:
+ return SqlTypeName.VARCHAR;
+ case DATESTRING:
+ return SqlTypeName.TIMESTAMP;
+ default:
+ throw new RuntimeException(
+ "Unexpected fieldValueType, unable to convert to SqlTypeName: " + fieldValueType);
+ }
+ }
+
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/impl/PostgresqlMetadataSchemaQueryWriterImpl.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/impl/PostgresqlMetadataSchemaQueryWriterImpl.java
new file mode 100644
index 0000000..8ace28a
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/impl/PostgresqlMetadataSchemaQueryWriterImpl.java
@@ -0,0 +1,201 @@
+package org.apache.airavata.datacatalog.api.query.impl;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaFieldEntity;
+import org.apache.airavata.datacatalog.api.query.MetadataSchemaQueryWriter;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.dialect.PostgresqlSqlDialect;
+import org.apache.calcite.sql.util.SqlShuttle;
+import org.springframework.stereotype.Component;
+
+@Component
+public class PostgresqlMetadataSchemaQueryWriterImpl implements MetadataSchemaQueryWriter {
+
+ private static final class MetadataSchemaFieldFilterRewriter extends SqlShuttle {
+
+ final Collection<MetadataSchemaEntity> metadataSchemas;
+ final Map<String, String> tableAliases;
+ final StringBuilder sql = new StringBuilder();
+ // Maintain queue of binary logical operators so we know when to
+ // open/close parentheses and when to add "AND" and "OR" to the query
+ Deque<SqlCall> binaryLogicalOperatorNodes = new ArrayDeque<>();
+
+ MetadataSchemaFieldFilterRewriter(Collection<MetadataSchemaEntity> metadataSchemas,
+ Map<String, String> tableAliases) {
+ this.metadataSchemas = metadataSchemas;
+ this.tableAliases = tableAliases;
+ }
+
+ MetadataSchemaFieldEntity resolveMetadataSchemaField(SqlIdentifier sqlIdentifier) {
+
+ MetadataSchemaEntity metadataSchema = null;
+ String fieldName = null;
+ if (sqlIdentifier.names.size() == 2) {
+ String tableName = sqlIdentifier.names.get(0);
+ metadataSchema = resolveMetadataSchema(tableName);
+ fieldName = sqlIdentifier.names.get(1);
+ } else if (sqlIdentifier.names.size() == 1) {
+ // TODO: just pick the first one, but in general we would need
+ // to look through all of the metadata schemas to find the one
+ // that this field belongs to
+ metadataSchema = this.metadataSchemas.iterator().next();
+ fieldName = sqlIdentifier.names.get(0);
+ } else {
+ throw new RuntimeException("Unexpected sqlIdentifier: " + sqlIdentifier);
+ }
+
+ for (MetadataSchemaFieldEntity metadataSchemaField : metadataSchema.getMetadataSchemaFields()) {
+ if (metadataSchemaField.getFieldName().equals(fieldName)) {
+ return metadataSchemaField;
+ }
+ }
+ // If none matched, must not be a metadata schema field
+ return null;
+ }
+
+ MetadataSchemaEntity resolveMetadataSchema(String tableOrAliasName) {
+ String tableName = tableOrAliasName;
+ if (this.tableAliases.containsKey(tableOrAliasName)) {
+ tableName = this.tableAliases.get(tableOrAliasName);
+ }
+ return findMetadataSchema(tableName);
+ }
+
+ MetadataSchemaEntity findMetadataSchema(String schemaName) {
+ for (MetadataSchemaEntity metadataSchema : this.metadataSchemas) {
+ if (metadataSchema.getSchemaName().equals(schemaName)) {
+ return metadataSchema;
+ }
+ }
+ return null;
+ }
+
+ public String finalizeSql() {
+ while (!this.binaryLogicalOperatorNodes.isEmpty()) {
+ this.binaryLogicalOperatorNodes.pop();
+ this.sql.append(" ) ");
+ }
+ return this.sql.toString();
+ }
+
+ @Override
+ public SqlNode visit(SqlCall call) {
+ SqlCall currentOperator = this.binaryLogicalOperatorNodes.peek();
+ while (currentOperator != null
+ && !call.getParserPosition().overlaps(currentOperator.getParserPosition())) {
+ this.binaryLogicalOperatorNodes.remove();
+ currentOperator = this.binaryLogicalOperatorNodes.peek();
+ this.sql.append(" ) ");
+ this.sql.append(currentOperator.getOperator().toString());
+ this.sql.append(" ");
+ }
+ if (call.getKind() == SqlKind.NOT) {
+ this.sql.append(" NOT ");
+ } else if (call.getKind() == SqlKind.AND || call.getKind() == SqlKind.OR) {
+ this.binaryLogicalOperatorNodes.push(call);
+ this.sql.append("( ");
+ } else {
+ SqlNode sqlNode = call.getOperandList().get(0);
+ // TODO: this assumes that there would only ever be one metadata schema field
+ // and that it comes first and the second operand is a literal
+ if (sqlNode.isA(Set.of(SqlKind.IDENTIFIER))) {
+ SqlIdentifier sqlIdentifier = (SqlIdentifier) sqlNode;
+ MetadataSchemaFieldEntity metadataSchemaField = resolveMetadataSchemaField(sqlIdentifier);
+ if (metadataSchemaField != null) {
+ // TODO: assuming an alias
+ sql.append(sqlIdentifier.names.get(0));
+ sql.append(".");
+ sql.append("metadata @@ '");
+ sql.append(metadataSchemaField.getJsonPath());
+ sql.append(" ");
+ switch (call.getOperator().kind) {
+ case EQUALS:
+ sql.append(" == ");
+ break;
+ default:
+ sql.append(call.getOperator().kind.sql);
+ break;
+ }
+ sql.append(call.getOperandList().get(1).toSqlString(new PostgresqlSqlDialect(
+ PostgresqlSqlDialect.DEFAULT_CONTEXT.withLiteralQuoteString("\""))));
+ sql.append("'");
+ } else {
+ sql.append(call.toSqlString(PostgresqlSqlDialect.DEFAULT));
+ }
+ }
+
+ if (currentOperator != null && !(call.getParserPosition().getEndColumnNum() == currentOperator
+ .getParserPosition().getEndColumnNum()
+ && call.getParserPosition().getEndLineNum() == currentOperator.getParserPosition()
+ .getEndLineNum())) {
+ sql.append(" ");
+ sql.append(currentOperator.getOperator().toString());
+ sql.append(" ");
+ }
+ }
+ return super.visit(call);
+ }
+ }
+
+ @Override
+ public String rewriteQuery(SqlNode sqlNode, Collection<MetadataSchemaEntity> metadataSchemas,
+ Map<String, String> tableAliases) {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(writeCommonTableExpressions(metadataSchemas));
+ sb.append(" SELECT * FROM ");
+ sb.append(((SqlSelect) sqlNode).getFrom().toSqlString(PostgresqlSqlDialect.DEFAULT));
+ sb.append(" WHERE ");
+ sb.append(rewriteWhereClauseFilters(sqlNode, metadataSchemas, tableAliases));
+ return sb.toString();
+ }
+
+ private String rewriteWhereClauseFilters(SqlNode sqlNode, Collection<MetadataSchemaEntity> metadataSchemas,
+ Map<String, String> tableAliases) {
+ MetadataSchemaFieldFilterRewriter filterRewriter = new MetadataSchemaFieldFilterRewriter(metadataSchemas,
+ tableAliases);
+ sqlNode.accept(filterRewriter);
+ return filterRewriter.finalizeSql();
+ }
+
+ String writeCommonTableExpressions(Collection<MetadataSchemaEntity> metadataSchemas) {
+ StringBuilder sb = new StringBuilder();
+ List<String> commonTableExpressions = new ArrayList<>();
+ for (MetadataSchemaEntity metadataSchema : metadataSchemas) {
+ commonTableExpressions.add(writeCommonTableExpression(metadataSchema));
+ }
+ sb.append("WITH ");
+ sb.append(String.join(", ", commonTableExpressions));
+ return sb.toString();
+ }
+
+ String writeCommonTableExpression(MetadataSchemaEntity metadataSchemaEntity) {
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(metadataSchemaEntity.getSchemaName());
+ sb.append(" AS (");
+ sb.append("select dp_.data_product_id, dp_.parent_data_product_id, dp_.external_id, dp_.name, dp_.metadata ");
+ // for (MetadataSchemaFieldEntity field :
+ // metadataSchemaEntity.getMetadataSchemaFields()) {
+ // TODO: include each field as well?
+ // }
+ sb.append("from data_product dp_ ");
+ sb.append("inner join data_product_metadata_schema dpms_ on dpms_.data_product_id = dp_.data_product_id ");
+ sb.append("inner join metadata_schema ms_ on ms_.metadata_schema_id = dpms_.metadata_schema_id ");
+ sb.append("where ms_.metadata_schema_id = " + metadataSchemaEntity.getMetadataSchemaId());
+ sb.append(")");
+ return sb.toString();
+ }
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index b5686a2..1e87293 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -14,6 +14,8 @@ import org.apache.airavata.datacatalog.api.DataProductGetRequest;
import org.apache.airavata.datacatalog.api.DataProductGetResponse;
import org.apache.airavata.datacatalog.api.DataProductRemoveFromMetadataSchemaRequest;
import org.apache.airavata.datacatalog.api.DataProductRemoveFromMetadataSchemaResponse;
+import org.apache.airavata.datacatalog.api.DataProductSearchRequest;
+import org.apache.airavata.datacatalog.api.DataProductSearchResponse;
import org.apache.airavata.datacatalog.api.DataProductUpdateRequest;
import org.apache.airavata.datacatalog.api.DataProductUpdateResponse;
import org.apache.airavata.datacatalog.api.MetadataSchema;
@@ -35,6 +37,7 @@ import org.apache.airavata.datacatalog.api.MetadataSchemaFieldUpdateResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaGetRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaGetResponse;
import org.apache.airavata.datacatalog.api.exception.EntityNotFoundException;
+import org.apache.airavata.datacatalog.api.query.MetadataSchemaQueryResult;
import org.lognet.springboot.grpc.GRpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -105,6 +108,29 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
responseObserver.onCompleted();
}
+ @Override
+ public void removeDataProductFromMetadataSchema(DataProductRemoveFromMetadataSchemaRequest request,
+ StreamObserver<DataProductRemoveFromMetadataSchemaResponse> responseObserver) {
+
+ String dataProductId = request.getDataProductId();
+ String schemaName = request.getSchemaName();
+ DataProduct dataProduct = dataCatalogService.removeDataProductFromMetadataSchema(dataProductId, schemaName);
+
+ responseObserver
+ .onNext(DataProductRemoveFromMetadataSchemaResponse.newBuilder().setDataProduct(dataProduct).build());
+ responseObserver.onCompleted();
+ }
+
+ @Override
+ public void searchDataProducts(DataProductSearchRequest request,
+ StreamObserver<DataProductSearchResponse> responseObserver) {
+
+ MetadataSchemaQueryResult searchResult = dataCatalogService.searchDataProducts(request.getSql());
+ List<DataProduct> dataProducts = searchResult.dataProducts();
+ responseObserver.onNext(DataProductSearchResponse.newBuilder().addAllDataProducts(dataProducts).build());
+ responseObserver.onCompleted();
+ }
+
@Override
public void getMetadataSchema(MetadataSchemaGetRequest request,
StreamObserver<MetadataSchemaGetResponse> responseObserver) {
@@ -187,19 +213,6 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
responseObserver.onCompleted();
}
- @Override
- public void removeDataProductFromMetadataSchema(DataProductRemoveFromMetadataSchemaRequest request,
- StreamObserver<DataProductRemoveFromMetadataSchemaResponse> responseObserver) {
-
- String dataProductId = request.getDataProductId();
- String schemaName = request.getSchemaName();
- DataProduct dataProduct = dataCatalogService.removeDataProductFromMetadataSchema(dataProductId, schemaName);
-
- responseObserver
- .onNext(DataProductRemoveFromMetadataSchemaResponse.newBuilder().setDataProduct(dataProduct).build());
- responseObserver.onCompleted();
- }
-
@Override
public void updateMetadataSchemaField(MetadataSchemaFieldUpdateRequest request,
StreamObserver<MetadataSchemaFieldUpdateResponse> responseObserver) {
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java
index 2a41ead..093263a 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java
@@ -5,6 +5,7 @@ import java.util.List;
import org.apache.airavata.datacatalog.api.DataProduct;
import org.apache.airavata.datacatalog.api.MetadataSchema;
import org.apache.airavata.datacatalog.api.MetadataSchemaField;
+import org.apache.airavata.datacatalog.api.query.MetadataSchemaQueryResult;
/**
* Transactional service layer for CRUD operations on data catalog database.
@@ -38,4 +39,6 @@ public interface DataCatalogService {
DataProduct removeDataProductFromMetadataSchema(String dataProductId, String schemaName);
MetadataSchemaField updateMetadataSchemaField(MetadataSchemaField metadataSchemaField);
+
+ MetadataSchemaQueryResult searchDataProducts(String sql);
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
index 8e7ee79..59d1d94 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
@@ -15,6 +15,8 @@ import org.apache.airavata.datacatalog.api.mapper.MetadataSchemaMapper;
import org.apache.airavata.datacatalog.api.model.DataProductEntity;
import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
import org.apache.airavata.datacatalog.api.model.MetadataSchemaFieldEntity;
+import org.apache.airavata.datacatalog.api.query.MetadataSchemaQueryExecutor;
+import org.apache.airavata.datacatalog.api.query.MetadataSchemaQueryResult;
import org.apache.airavata.datacatalog.api.repository.DataProductRepository;
import org.apache.airavata.datacatalog.api.repository.MetadataSchemaFieldRepository;
import org.apache.airavata.datacatalog.api.repository.MetadataSchemaRepository;
@@ -47,6 +49,9 @@ public class DataCatalogServiceImpl implements DataCatalogService {
@Autowired
MetadataSchemaFieldMapper metadataSchemaFieldMapper;
+ @Autowired
+ MetadataSchemaQueryExecutor metadataSchemaQueryExecutor;
+
@Override
public DataProduct createDataProduct(DataProduct dataProduct) {
@@ -97,6 +102,23 @@ public class DataCatalogServiceImpl implements DataCatalogService {
return toDataProduct(savedDataProductEntity);
}
+ @Override
+ public DataProduct removeDataProductFromMetadataSchema(String dataProductId, String schemaName) {
+
+ // TODO: handle data product not found
+ DataProductEntity dataProduct = dataProductRepository.findByExternalId(dataProductId);
+ // TODO: handle metadata schema not found
+ MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
+ dataProduct.removeMetadataSchema(metadataSchemaEntity);
+ DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProduct);
+ return toDataProduct(savedDataProductEntity);
+ }
+
+ @Override
+ public MetadataSchemaQueryResult searchDataProducts(String sql) {
+ return metadataSchemaQueryExecutor.execute(sql);
+ }
+
@Override
public MetadataSchema getMetadataSchema(String schemaName) {
MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
@@ -169,18 +191,6 @@ public class DataCatalogServiceImpl implements DataCatalogService {
return fields;
}
- @Override
- public DataProduct removeDataProductFromMetadataSchema(String dataProductId, String schemaName) {
-
- // TODO: handle data product not found
- DataProductEntity dataProduct = dataProductRepository.findByExternalId(dataProductId);
- // TODO: handle metadata schema not found
- MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
- dataProduct.removeMetadataSchema(metadataSchemaEntity);
- DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProduct);
- return toDataProduct(savedDataProductEntity);
- }
-
@Override
public MetadataSchemaField updateMetadataSchemaField(MetadataSchemaField metadataSchemaField) {
diff --git a/data-catalog-api/server/src/main/resources/logback.xml b/data-catalog-api/server/src/main/resources/logback.xml
index 5cd56ea..3f5abdd 100644
--- a/data-catalog-api/server/src/main/resources/logback.xml
+++ b/data-catalog-api/server/src/main/resources/logback.xml
@@ -47,6 +47,10 @@
<logger name="org.apache.airavata" level="INFO"/>
<logger name="org.hibernate" level="INFO"/>
<logger name="net.schmizz.sshj" level="WARN"/>
+ <!-- <logger name="org.apache.airavata" level="DEBUG"/> -->
+ <!-- <logger name="org.springframework.transaction.interceptor" level="TRACE"/> -->
+ <!-- <logger name="org.springframework.transaction" level="TRACE"/> -->
+ <!-- <logger name="org.springframework.orm.jpa" level="TRACE"/> -->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="LOGFILE"/>
diff --git a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
index 2845271..a7a09c3 100644
--- a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@ -105,6 +105,30 @@ message DataProductDeleteRequest {
}
message DataProductDeleteResponse {
}
+message DataProductAddToMetadataSchemaRequest {
+ UserInfo user_info = 1;
+ string data_product_id = 2;
+ string schema_name = 3;
+}
+message DataProductAddToMetadataSchemaResponse {
+ DataProduct data_product = 1;
+}
+message DataProductRemoveFromMetadataSchemaRequest {
+ UserInfo user_info = 1;
+ string data_product_id = 2;
+ string schema_name = 3;
+}
+message DataProductRemoveFromMetadataSchemaResponse {
+ DataProduct data_product = 1;
+}
+message DataProductSearchRequest {
+ UserInfo user_info = 1;
+ string sql = 2;
+}
+message DataProductSearchResponse {
+ repeated DataProduct data_products = 1;
+}
+
message MetadataSchemaGetRequest {
UserInfo user_info = 1;
@@ -161,23 +185,6 @@ message MetadataSchemaFieldListRequest {
message MetadataSchemaFieldListResponse {
repeated MetadataSchemaField metadata_schema_fields = 1;
}
-message DataProductAddToMetadataSchemaRequest {
- UserInfo user_info = 1;
- string data_product_id = 2;
- string schema_name = 3;
-}
-message DataProductAddToMetadataSchemaResponse {
- DataProduct data_product = 1;
-}
-message DataProductRemoveFromMetadataSchemaRequest {
- UserInfo user_info = 1;
- string data_product_id = 2;
- string schema_name = 3;
-}
-message DataProductRemoveFromMetadataSchemaResponse {
- DataProduct data_product = 1;
-}
-
service DataCatalogAPIService {
rpc createDataProduct(DataProductCreateRequest) returns (DataProductCreateResponse){}
@@ -194,4 +201,5 @@ service DataCatalogAPIService {
rpc getMetadataSchemaFields(MetadataSchemaFieldListRequest) returns (MetadataSchemaFieldListResponse){}
rpc addDataProductToMetadataSchema(DataProductAddToMetadataSchemaRequest) returns (DataProductAddToMetadataSchemaResponse){}
rpc removeDataProductFromMetadataSchema(DataProductRemoveFromMetadataSchemaRequest) returns (DataProductRemoveFromMetadataSchemaResponse){}
+ rpc searchDataProducts(DataProductSearchRequest) returns (DataProductSearchResponse){}
}
[airavata-data-catalog] 19/36: Cascading metadata schema delete to fields
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 849b9267841aeaf0fa5841d24b689ceb2f819137
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Fri Feb 17 09:46:01 2023 -0500
Cascading metadata schema delete to fields
---
.../airavata/datacatalog/api/model/MetadataSchemaEntity.java | 8 ++++++++
.../airavata/datacatalog/api/service/DataCatalogAPIService.java | 1 +
2 files changed, 9 insertions(+)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaEntity.java
index 8c1f6cd..f1b038b 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaEntity.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaEntity.java
@@ -46,6 +46,14 @@ public class MetadataSchemaEntity {
this.schemaName = schemaName;
}
+ public Set<MetadataSchemaFieldEntity> getMetadataSchemaFields() {
+ return metadataSchemaFields;
+ }
+
+ public void setMetadataSchemaFields(Set<MetadataSchemaFieldEntity> metadataSchemaFields) {
+ this.metadataSchemaFields = metadataSchemaFields;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index d001e46..9076ce6 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -204,6 +204,7 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
// TODO: handle metadata schema not found
MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository
.findBySchemaName(request.getMetadataSchema().getSchemaName());
+ metadataSchemaFieldRepository.deleteAll(metadataSchemaEntity.getMetadataSchemaFields());
metadataSchemaRepository.delete(metadataSchemaEntity);
MetadataSchemaDeleteResponse.Builder responseBuilder = MetadataSchemaDeleteResponse.newBuilder();
responseObserver.onNext(responseBuilder.build());
[airavata-data-catalog] 28/36: Merge pull request #20 from lahirujayathilake/main
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit df2f1520753f97adcdffc5fe7272b00e05df0b5c
Merge: 4d3de78 a62b91a
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Mar 8 10:57:59 2023 -0500
Merge pull request #20 from lahirujayathilake/main
Metadata values were missing when retrieving a DataProduct
.../apache/airavata/datacatalog/api/mapper/DataProductMapper.java | 8 ++++++++
1 file changed, 8 insertions(+)
[airavata-data-catalog] 08/36: Adding the mandatory LICENSE and NOTICE files
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 0265694ad0eaa3098c358e12ac534e20bd6f031d
Author: Suresh Marru <sm...@apache.org>
AuthorDate: Thu Feb 2 11:47:15 2023 -0500
Adding the mandatory LICENSE and NOTICE files
---
LICENSE | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
NOTICE | 5 ++
2 files changed, 207 insertions(+)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..7a4a3ea
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
\ No newline at end of file
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..f76da91
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,5 @@
+Apache Airavata Data Catalog
+Copyright 2023 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
\ No newline at end of file
[airavata-data-catalog] 03/36: Adding PostgreSQL docker-compose script and README instructions
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 33bdc76af680871b800bf72baa5b16354e838d91
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Jan 23 15:48:44 2023 -0500
Adding PostgreSQL docker-compose script and README instructions
---
README.md | 25 +++++++++++++++++++++++++
docker-compose.yml | 18 ++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..0f57854
--- /dev/null
+++ b/README.md
@@ -0,0 +1,25 @@
+# Apache Airavata Data Catalog
+
+## Getting started
+
+Start the PostgreSQL database in a docker container
+
+```
+docker-compose up
+```
+
+Run the API server
+
+```
+mvn install
+cd data-catalog-api/server
+mvn spring-boot:run
+```
+
+Run the API client
+
+```
+mvn install
+cd data-catalog-api/client
+mvn exec:java -Dexec.mainClass=org.apache.airavata.datacatalog.api.client.DataCatalogAPIClient
+```
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..d7d84d8
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,18 @@
+# Use postgres/example user/password credentials
+version: "3.1"
+
+services:
+ db:
+ image: postgres
+ restart: always
+ environment:
+ POSTGRES_PASSWORD: example
+ POSTGRES_DB: data_catalog
+ ports:
+ - 5432:5432
+
+ adminer:
+ image: adminer
+ restart: always
+ ports:
+ - 8080:8080
[airavata-data-catalog] 11/36: Merge pull request #16 from apache:machristie/issue6
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit d1d40f5fe22b3c627c6d24b5c7bc4b74326b8d97
Merge: dd0e770 25a311a
Author: Marcus Christie <ma...@iu.edu>
AuthorDate: Thu Feb 9 12:30:12 2023 -0500
Merge pull request #16 from apache:machristie/issue6
Data Product CRUD API
.../api/client/DataCatalogAPIClient.java | 63 ++++++++++++++---
.../datacatalog/api/mapper/DataProductMapper.java | 54 +++++++++++++++
.../api/repository/DataProductRepository.java | 6 +-
.../api/service/DataCatalogAPIService.java | 81 ++++++++++++++--------
.../stubs/src/main/proto/DataCatalogAPI.proto | 20 ++++++
5 files changed, 187 insertions(+), 37 deletions(-)
[airavata-data-catalog] 17/36: Support creating data product for known metadata schemas
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 9d7f93b3229ac3665c94fef241fc2ca5bf588624
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Feb 15 15:45:45 2023 -0500
Support creating data product for known metadata schemas
---
.../datacatalog/api/client/DataCatalogAPIClient.java | 11 +++++++++++
.../datacatalog/api/mapper/DataProductMapper.java | 16 +++++++++++++++-
.../datacatalog/api/model/DataProductEntity.java | 3 ++-
.../stubs/src/main/proto/DataCatalogAPI.proto | 2 +-
4 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
index 3d59fdb..25495fd 100644
--- a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
+++ b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
@@ -195,6 +195,17 @@ public class DataCatalogAPIClient {
System.out.println(MessageFormat.format("Removed data product [{0}] from metadata schema [{1}]",
result.getDataProductId(), metadataSchema.getSchemaName()));
+ // Create data product that belongs to my_schema schema
+ DataProduct dataProduct3 = DataProduct.newBuilder()
+ .setName("testing 3")
+ .setMetadata("{\"foo\": \"bar\"}")
+ .addMetadataSchemas("my_schema")
+ .build();
+ DataProduct result3 = client.createDataProduct(dataProduct3);
+ System.out.println(
+ MessageFormat.format("Created third data product [{0}], supporting schemas [{1}]",
+ result3.getDataProductId(), result3.getMetadataSchemasList()));
+
} finally {
channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
index b03fe1d..b6817ea 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
@@ -4,6 +4,7 @@ import org.apache.airavata.datacatalog.api.DataProduct;
import org.apache.airavata.datacatalog.api.model.DataProductEntity;
import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
import org.apache.airavata.datacatalog.api.repository.DataProductRepository;
+import org.apache.airavata.datacatalog.api.repository.MetadataSchemaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -22,6 +23,9 @@ public class DataProductMapper {
@Autowired
DataProductRepository dataProductRepository;
+ @Autowired
+ MetadataSchemaRepository metadataSchemaRepository;
+
public void mapModelToEntity(DataProduct dataProduct, DataProductEntity dataProductEntity) {
dataProductEntity.setName(dataProduct.getName());
@@ -41,6 +45,16 @@ public class DataProductMapper {
throw new RuntimeException(e);
}
}
+
+ // Synchronize the list of metadata schemas
+ if (dataProductEntity.getMetadataSchemas() != null) {
+ dataProductEntity.getMetadataSchemas().clear();
+ }
+ for (String metadataSchemaName : dataProduct.getMetadataSchemasList()) {
+ // TODO: handle metadata schema not found
+ MetadataSchemaEntity metadataSchema = metadataSchemaRepository.findBySchemaName(metadataSchemaName);
+ dataProductEntity.addMetadataSchema(metadataSchema);
+ }
}
public void mapEntityToModel(DataProductEntity dataProductEntity, DataProduct.Builder dataProductBuilder) {
@@ -53,7 +67,7 @@ public class DataProductMapper {
}
if (dataProductEntity.getMetadataSchemas() != null) {
for (MetadataSchemaEntity metadataSchema : dataProductEntity.getMetadataSchemas()) {
- dataProductBuilder.addSchemaName(metadataSchema.getSchemaName());
+ dataProductBuilder.addMetadataSchemas(metadataSchema.getSchemaName());
}
}
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
index 68b615f..5e3802f 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
@@ -1,5 +1,6 @@
package org.apache.airavata.datacatalog.api.model;
+import java.util.HashSet;
import java.util.Set;
import org.hibernate.annotations.Type;
@@ -49,7 +50,7 @@ public class DataProductEntity {
@ManyToMany
@JoinTable(name = "data_product_metadata_schema", joinColumns = @JoinColumn(name = "data_product_id"), inverseJoinColumns = @JoinColumn(name = "metadata_schema_id"))
- private Set<MetadataSchemaEntity> metadataSchemas;
+ private Set<MetadataSchemaEntity> metadataSchemas = new HashSet<>();
// TODO: ManyToOne mapping to owner: UserEntity
public Long getDataProductId() {
diff --git a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
index cb03016..7d91b8b 100644
--- a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@ -62,7 +62,7 @@ message DataProduct {
optional string parent_data_product_id = 2;
string name = 3;
optional string metadata = 4;
- repeated string schema_name = 5;
+ repeated string metadata_schemas = 5;
}
enum FieldValueType {
[airavata-data-catalog] 35/36: Merge branch 'custos-integration' into main
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 4ae109c01015b3ce61dfe2e5408f0982eee04d3d
Merge: 5fbb510 115764e
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Mar 29 09:21:46 2023 -0400
Merge branch 'custos-integration' into main
.../api/client/DataCatalogAPIClient.java | 205 ++++++++++++++++-
data-catalog-api/server/pom.xml | 10 +
.../api/exception/EntityNotFoundException.java | 25 +++
.../exception/MetadataSchemaSqlParseException.java | 25 +++
.../MetadataSchemaSqlValidateException.java | 25 +++
.../datacatalog/api/mapper/DataProductMapper.java | 36 ++-
.../api/mapper/MetadataSchemaFieldMapper.java | 36 +++
.../api/mapper/MetadataSchemaMapper.java | 19 ++
.../datacatalog/api/model/DataProductEntity.java | 25 +++
.../api/model/MetadataSchemaEntity.java | 81 +++++++
.../api/model/MetadataSchemaFieldEntity.java | 110 ++++++++++
.../api/query/MetadataSchemaQueryExecutor.java | 10 +
.../api/query/MetadataSchemaQueryResult.java | 9 +
.../api/query/MetadataSchemaQueryWriter.java | 21 ++
.../impl/MetadataSchemaQueryExecutorImpl.java | 215 ++++++++++++++++++
.../PostgresqlMetadataSchemaQueryWriterImpl.java | 201 +++++++++++++++++
.../api/repository/DataProductRepository.java | 5 +-
.../repository/MetadataSchemaFieldRepository.java | 13 ++
.../api/repository/MetadataSchemaRepository.java | 9 +
.../api/service/DataCatalogAPIService.java | 244 +++++++++++++++++----
.../api/service/DataCatalogService.java | 47 ++++
.../api/service/impl/DataCatalogServiceImpl.java | 231 +++++++++++++++++++
.../server/src/main/resources/logback.xml | 4 +
.../api}/DataCatalogApiServerApplicationTests.java | 2 +-
.../stubs/src/main/proto/DataCatalogAPI.proto | 111 +++++++++-
25 files changed, 1669 insertions(+), 50 deletions(-)
diff --cc data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
index 476fb1a,a7a09c3..a32a714
--- a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@@ -62,7 -62,24 +62,25 @@@ message DataProduct
optional string parent_data_product_id = 2;
string name = 3;
optional string metadata = 4;
- string tenant_id = 5;
+ repeated string metadata_schemas = 5;
++ string tenant_id = 6;
+ }
+
+ enum FieldValueType {
+ STRING = 0;
+ INTEGER = 1;
+ FLOAT = 2;
+ BOOLEAN = 3;
+ DATESTRING = 4;
+ }
+ message MetadataSchema {
+ string schema_name = 1;
+ }
+ message MetadataSchemaField {
+ string schema_name = 1;
+ string field_name = 2;
+ string json_path = 3;
+ FieldValueType value_type = 4;
}
message DataProductCreateRequest {
[airavata-data-catalog] 06/36: Update .asf.yaml with GitHub metadata, enabling issues
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit ce008474ea895944f588c1de76fe1d75a2c0b794
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Jan 31 12:20:10 2023 -0500
Update .asf.yaml with GitHub metadata, enabling issues
---
.asf.yaml | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/.asf.yaml b/.asf.yaml
new file mode 100644
index 0000000..23a7f53
--- /dev/null
+++ b/.asf.yaml
@@ -0,0 +1,42 @@
+#
+# 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.
+#
+notifications:
+ commits: commits@airavata.apache.org
+ # Send all issue emails (new, closed, comments) to issues@
+ issues: issues@airavata.apache.org
+ # Send new/closed PR notifications to issues@
+ pullrequests_status: issues@airavata.apache.org
+ # Send individual PR comments/reviews to issues@
+ pullrequests_comment: issues@airavata.apache.org
+
+github:
+ description: "Apache Airavata Data Catalog"
+ homepage: https://airavata.apache.org
+ labels:
+ - airavata
+ - apache
+ - data-catalog
+ - metadata
+ - schema
+ - search
+
+ features:
+ wiki: false
+ issues: true
+ projects: true
[airavata-data-catalog] 27/36: included metadata values when mapping entity to a model
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit a62b91a6a3c5a238cc4d9b6903c486a14dc1d1c1
Author: Lahiru Jayathilake <la...@gmail.com>
AuthorDate: Wed Mar 8 20:19:22 2023 +0530
included metadata values when mapping entity to a model
---
.../apache/airavata/datacatalog/api/mapper/DataProductMapper.java | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
index b6817ea..bc8ad22 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
@@ -70,5 +70,13 @@ public class DataProductMapper {
dataProductBuilder.addMetadataSchemas(metadataSchema.getSchemaName());
}
}
+ if (dataProductEntity.getMetadata() != null) {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ dataProductBuilder.setMetadata(mapper.writeValueAsString(dataProductEntity.getMetadata()));
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
}
[airavata-data-catalog] 22/36: Transactional service layer for data catalog db operations
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 18a9563642c27947bf5eecb22fa22fb424a416dc
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Fri Feb 17 17:12:26 2023 -0500
Transactional service layer for data catalog db operations
---
.../api/exception/EntityNotFoundException.java | 25 +++
.../api/service/DataCatalogAPIService.java | 178 +++++-------------
.../api/service/DataCatalogService.java | 39 ++++
.../api/service/impl/DataCatalogServiceImpl.java | 205 +++++++++++++++++++++
4 files changed, 316 insertions(+), 131 deletions(-)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/exception/EntityNotFoundException.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/exception/EntityNotFoundException.java
new file mode 100644
index 0000000..7a58b41
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/exception/EntityNotFoundException.java
@@ -0,0 +1,25 @@
+package org.apache.airavata.datacatalog.api.exception;
+
+public class EntityNotFoundException extends RuntimeException {
+
+ public EntityNotFoundException() {
+ }
+
+ public EntityNotFoundException(String message) {
+ super(message);
+ }
+
+ public EntityNotFoundException(Throwable cause) {
+ super(cause);
+ }
+
+ public EntityNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public EntityNotFoundException(String message, Throwable cause, boolean enableSuppression,
+ boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index f7a7904..7df3e40 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -1,7 +1,6 @@
package org.apache.airavata.datacatalog.api.service;
import java.util.List;
-import java.util.UUID;
import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc;
import org.apache.airavata.datacatalog.api.DataProduct;
@@ -17,6 +16,7 @@ import org.apache.airavata.datacatalog.api.DataProductRemoveFromMetadataSchemaRe
import org.apache.airavata.datacatalog.api.DataProductRemoveFromMetadataSchemaResponse;
import org.apache.airavata.datacatalog.api.DataProductUpdateRequest;
import org.apache.airavata.datacatalog.api.DataProductUpdateResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchema;
import org.apache.airavata.datacatalog.api.MetadataSchemaCreateRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaCreateResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaDeleteRequest;
@@ -32,65 +32,32 @@ import org.apache.airavata.datacatalog.api.MetadataSchemaFieldUpdateRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldUpdateResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaGetRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaGetResponse;
-import org.apache.airavata.datacatalog.api.mapper.DataProductMapper;
-import org.apache.airavata.datacatalog.api.mapper.MetadataSchemaFieldMapper;
-import org.apache.airavata.datacatalog.api.mapper.MetadataSchemaMapper;
-import org.apache.airavata.datacatalog.api.model.DataProductEntity;
-import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
-import org.apache.airavata.datacatalog.api.model.MetadataSchemaFieldEntity;
-import org.apache.airavata.datacatalog.api.repository.DataProductRepository;
-import org.apache.airavata.datacatalog.api.repository.MetadataSchemaFieldRepository;
-import org.apache.airavata.datacatalog.api.repository.MetadataSchemaRepository;
+import org.apache.airavata.datacatalog.api.exception.EntityNotFoundException;
import org.lognet.springboot.grpc.GRpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
import io.grpc.Status;
import io.grpc.stub.StreamObserver;
@GRpcService
-@Transactional
public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalogAPIServiceImplBase {
private static final Logger logger = LoggerFactory.getLogger(DataCatalogAPIService.class);
@Autowired
- DataProductRepository dataProductRepository;
-
- @Autowired
- MetadataSchemaRepository metadataSchemaRepository;
-
- @Autowired
- MetadataSchemaFieldRepository metadataSchemaFieldRepository;
-
- @Autowired
- DataProductMapper dataProductMapper;
-
- @Autowired
- MetadataSchemaMapper metadataSchemaMapper;
-
- @Autowired
- MetadataSchemaFieldMapper metadataSchemaFieldMapper;
+ DataCatalogService dataCatalogService;
@Override
public void createDataProduct(DataProductCreateRequest request,
StreamObserver<DataProductCreateResponse> responseObserver) {
- // TODO: SharingManager.resolveUser
logger.info("Creating data product {}", request.getDataProduct());
- DataProductEntity dataProductEntity = new DataProductEntity();
- dataProductEntity.setExternalId(UUID.randomUUID().toString());
- dataProductMapper.mapModelToEntity(request.getDataProduct(), dataProductEntity);
- DataProductEntity savedDataProductEntity = dataProductRepository.saveAndFlush(dataProductEntity);
- // TODO: SharingManager.grantPermissionToUser(userInfo, dataProduct,
- // Permission.OWNER)
+ DataProduct result = dataCatalogService.createDataProduct(request.getDataProduct());
- DataProductCreateResponse.Builder responseBuilder = DataProductCreateResponse.newBuilder();
- dataProductMapper.mapEntityToModel(savedDataProductEntity, responseBuilder.getDataProductBuilder());
- responseObserver.onNext(responseBuilder.build());
+ responseObserver.onNext(DataProductCreateResponse.newBuilder().setDataProduct(result).build());
responseObserver.onCompleted();
}
@@ -99,29 +66,18 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
StreamObserver<DataProductUpdateResponse> responseObserver) {
// TODO: check that user has access to update data product record
- // TODO: handle data product does not exist
- DataProduct dataProduct = request.getDataProduct();
- DataProductEntity dataProductEntity = dataProductRepository
- .findByExternalId(dataProduct.getDataProductId());
- dataProductMapper.mapModelToEntity(dataProduct, dataProductEntity);
-
- DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProductEntity);
+ DataProduct savedDataProduct = dataCatalogService.updateDataProduct(request.getDataProduct());
- DataProductUpdateResponse.Builder responseBuilder = DataProductUpdateResponse.newBuilder();
- dataProductMapper.mapEntityToModel(savedDataProductEntity, responseBuilder.getDataProductBuilder());
- responseObserver.onNext(responseBuilder.build());
+ responseObserver.onNext(DataProductUpdateResponse.newBuilder().setDataProduct(savedDataProduct).build());
responseObserver.onCompleted();
}
@Override
public void getDataProduct(DataProductGetRequest request, StreamObserver<DataProductGetResponse> responseObserver) {
// TODO: check that user has READ access on data product record
- // TODO: handle data product does not exist
- DataProductEntity dataProductEntity = dataProductRepository
- .findByExternalId(request.getDataProductId());
- DataProductGetResponse.Builder responseBuilder = DataProductGetResponse.newBuilder();
- dataProductMapper.mapEntityToModel(dataProductEntity, responseBuilder.getDataProductBuilder());
- responseObserver.onNext(responseBuilder.build());
+ DataProduct dataProduct = dataCatalogService.getDataProduct(request.getDataProductId());
+
+ responseObserver.onNext(DataProductGetResponse.newBuilder().setDataProduct(dataProduct).build());
responseObserver.onCompleted();
}
@@ -129,9 +85,9 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
public void deleteDataProduct(DataProductDeleteRequest request,
StreamObserver<DataProductDeleteResponse> responseObserver) {
// TODO: check that user has WRITE access on data product record
- dataProductRepository.deleteByExternalId(request.getDataProductId());
- DataProductDeleteResponse.Builder responseBuilder = DataProductDeleteResponse.newBuilder();
- responseObserver.onNext(responseBuilder.build());
+ dataCatalogService.deleteDataProduct(request.getDataProductId());
+
+ responseObserver.onNext(DataProductDeleteResponse.newBuilder().build());
responseObserver.onCompleted();
}
@@ -139,45 +95,35 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
public void addDataProductToMetadataSchema(DataProductAddToMetadataSchemaRequest request,
StreamObserver<DataProductAddToMetadataSchemaResponse> responseObserver) {
String dataProductId = request.getDataProductId();
- // TODO: handle data product not found
- DataProductEntity dataProduct = dataProductRepository.findByExternalId(dataProductId);
String schemaName = request.getSchemaName();
- // TODO: handle metadata schema not found
- MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
- dataProduct.addMetadataSchema(metadataSchemaEntity);
-
- DataProductAddToMetadataSchemaResponse.Builder responseBuilder = DataProductAddToMetadataSchemaResponse
- .newBuilder();
- dataProductMapper.mapEntityToModel(dataProduct, responseBuilder.getDataProductBuilder());
- responseObserver.onNext(responseBuilder.build());
+ DataProduct dataProduct = dataCatalogService.addDataProductToMetadataSchema(dataProductId, schemaName);
+
+ responseObserver
+ .onNext(DataProductAddToMetadataSchemaResponse.newBuilder().setDataProduct(dataProduct).build());
responseObserver.onCompleted();
}
@Override
public void getMetadataSchema(MetadataSchemaGetRequest request,
StreamObserver<MetadataSchemaGetResponse> responseObserver) {
- MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(request.getSchemaName());
- if (metadataSchemaEntity == null) {
+ try {
+ MetadataSchema metadataSchema = dataCatalogService.getMetadataSchema(request.getSchemaName());
+
+ responseObserver.onNext(MetadataSchemaGetResponse.newBuilder().setMetadataSchema(metadataSchema).build());
+ responseObserver.onCompleted();
+ } catch (EntityNotFoundException e) {
responseObserver.onError(Status.NOT_FOUND.asException());
responseObserver.onCompleted();
}
- MetadataSchemaGetResponse.Builder responseBuilder = MetadataSchemaGetResponse.newBuilder();
- metadataSchemaMapper.mapEntityToModel(metadataSchemaEntity, responseBuilder.getMetadataSchemaBuilder());
- responseObserver.onNext(responseBuilder.build());
- responseObserver.onCompleted();
}
@Override
public void createMetadataSchema(MetadataSchemaCreateRequest request,
StreamObserver<MetadataSchemaCreateResponse> responseObserver) {
- MetadataSchemaEntity metadataSchemaEntity = new MetadataSchemaEntity();
- metadataSchemaMapper.mapModelToEntity(request.getMetadataSchema(), metadataSchemaEntity);
- MetadataSchemaEntity savedMetadataSchemaEntity = metadataSchemaRepository.save(metadataSchemaEntity);
+ MetadataSchema metadataSchema = dataCatalogService.createMetadataSchema(request.getMetadataSchema());
- MetadataSchemaCreateResponse.Builder responseBuilder = MetadataSchemaCreateResponse.newBuilder();
- metadataSchemaMapper.mapEntityToModel(savedMetadataSchemaEntity, responseBuilder.getMetadataSchemaBuilder());
- responseObserver.onNext(responseBuilder.build());
+ responseObserver.onNext(MetadataSchemaCreateResponse.newBuilder().setMetadataSchema(metadataSchema).build());
responseObserver.onCompleted();
}
@@ -185,15 +131,11 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
public void createMetadataSchemaField(MetadataSchemaFieldCreateRequest request,
StreamObserver<MetadataSchemaFieldCreateResponse> responseObserver) {
- MetadataSchemaFieldEntity metadataSchemaFieldEntity = new MetadataSchemaFieldEntity();
- metadataSchemaFieldMapper.mapModelToEntity(request.getMetadataSchemaField(), metadataSchemaFieldEntity);
- MetadataSchemaFieldEntity savedMetadataSchemaFieldEntity = metadataSchemaFieldRepository
- .save(metadataSchemaFieldEntity);
+ MetadataSchemaField metadataSchemaField = dataCatalogService
+ .createMetadataSchemaField(request.getMetadataSchemaField());
- MetadataSchemaFieldCreateResponse.Builder responseBuilder = MetadataSchemaFieldCreateResponse.newBuilder();
- metadataSchemaFieldMapper.mapEntityToModel(savedMetadataSchemaFieldEntity,
- responseBuilder.getMetadataSchemaFieldBuilder());
- responseObserver.onNext(responseBuilder.build());
+ responseObserver.onNext(
+ MetadataSchemaFieldCreateResponse.newBuilder().setMetadataSchemaField(metadataSchemaField).build());
responseObserver.onCompleted();
}
@@ -201,13 +143,9 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
public void deleteMetadataSchema(MetadataSchemaDeleteRequest request,
StreamObserver<MetadataSchemaDeleteResponse> responseObserver) {
// TODO: check that user has write access on metadata schema
- // TODO: handle metadata schema not found
- MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository
- .findBySchemaName(request.getMetadataSchema().getSchemaName());
- metadataSchemaFieldRepository.deleteAll(metadataSchemaEntity.getMetadataSchemaFields());
- metadataSchemaRepository.delete(metadataSchemaEntity);
- MetadataSchemaDeleteResponse.Builder responseBuilder = MetadataSchemaDeleteResponse.newBuilder();
- responseObserver.onNext(responseBuilder.build());
+ dataCatalogService.deleteMetadataSchema(request.getMetadataSchema());
+
+ responseObserver.onNext(MetadataSchemaDeleteResponse.newBuilder().build());
responseObserver.onCompleted();
}
@@ -215,13 +153,9 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
public void deleteMetadataSchemaField(MetadataSchemaFieldDeleteRequest request,
StreamObserver<MetadataSchemaFieldDeleteResponse> responseObserver) {
// TODO: check that user has write access on metadata schema field
- // TODO: handle metadata schema field not found
- MetadataSchemaFieldEntity metadataSchemaFieldEntity = metadataSchemaFieldRepository
- .findByFieldNameAndMetadataSchema_SchemaName(request.getMetadataSchemaField().getFieldName(),
- request.getMetadataSchemaField().getSchemaName());
- metadataSchemaFieldRepository.delete(metadataSchemaFieldEntity);
- MetadataSchemaFieldDeleteResponse.Builder responseBuilder = MetadataSchemaFieldDeleteResponse.newBuilder();
- responseObserver.onNext(responseBuilder.build());
+ dataCatalogService.deleteMetadataSchemaField(request.getMetadataSchemaField());
+
+ responseObserver.onNext(MetadataSchemaFieldDeleteResponse.newBuilder().build());
responseObserver.onCompleted();
}
@@ -229,16 +163,10 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
public void getMetadataSchemaFields(MetadataSchemaFieldListRequest request,
StreamObserver<MetadataSchemaFieldListResponse> responseObserver) {
- // TODO: handle case where schema doesn't exist
- List<MetadataSchemaFieldEntity> metadataSchemaFieldEntities = metadataSchemaFieldRepository
- .findByMetadataSchema_SchemaName(request.getSchemaName());
+ List<MetadataSchemaField> fields = dataCatalogService.getMetadataSchemaFields(request.getSchemaName());
- MetadataSchemaFieldListResponse.Builder responseBuilder = MetadataSchemaFieldListResponse.newBuilder();
- for (MetadataSchemaFieldEntity metadataSchemaFieldEntity : metadataSchemaFieldEntities) {
- MetadataSchemaField.Builder builder = responseBuilder.addMetadataSchemaFieldsBuilder();
- metadataSchemaFieldMapper.mapEntityToModel(metadataSchemaFieldEntity, builder);
- }
- responseObserver.onNext(responseBuilder.build());
+ responseObserver
+ .onNext(MetadataSchemaFieldListResponse.newBuilder().addAllMetadataSchemaFields(fields).build());
responseObserver.onCompleted();
}
@@ -247,17 +175,11 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
StreamObserver<DataProductRemoveFromMetadataSchemaResponse> responseObserver) {
String dataProductId = request.getDataProductId();
- // TODO: handle data product not found
- DataProductEntity dataProduct = dataProductRepository.findByExternalId(dataProductId);
String schemaName = request.getSchemaName();
- // TODO: handle metadata schema not found
- MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
- dataProduct.removeMetadataSchema(metadataSchemaEntity);
-
- DataProductRemoveFromMetadataSchemaResponse.Builder responseBuilder = DataProductRemoveFromMetadataSchemaResponse
- .newBuilder();
- dataProductMapper.mapEntityToModel(dataProduct, responseBuilder.getDataProductBuilder());
- responseObserver.onNext(responseBuilder.build());
+ DataProduct dataProduct = dataCatalogService.removeDataProductFromMetadataSchema(dataProductId, schemaName);
+
+ responseObserver
+ .onNext(DataProductRemoveFromMetadataSchemaResponse.newBuilder().setDataProduct(dataProduct).build());
responseObserver.onCompleted();
}
@@ -266,17 +188,11 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
StreamObserver<MetadataSchemaFieldUpdateResponse> responseObserver) {
// TODO: check that user has write access on metadata schema field
- // TODO: handle metadata schema field not found
- MetadataSchemaFieldEntity metadataSchemaFieldEntity = metadataSchemaFieldRepository
- .findByFieldNameAndMetadataSchema_SchemaName(request.getMetadataSchemaField().getFieldName(),
- request.getMetadataSchemaField().getSchemaName());
- metadataSchemaFieldMapper.mapModelToEntity(request.getMetadataSchemaField(), metadataSchemaFieldEntity);
- metadataSchemaFieldRepository.save(metadataSchemaFieldEntity);
-
- MetadataSchemaFieldUpdateResponse.Builder responseBuilder = MetadataSchemaFieldUpdateResponse.newBuilder();
- metadataSchemaFieldMapper.mapEntityToModel(metadataSchemaFieldEntity,
- responseBuilder.getMetadataSchemaFieldBuilder());
- responseObserver.onNext(responseBuilder.build());
+ MetadataSchemaField metadataSchemaField = dataCatalogService
+ .updateMetadataSchemaField(request.getMetadataSchemaField());
+
+ responseObserver.onNext(
+ MetadataSchemaFieldUpdateResponse.newBuilder().setMetadataSchemaField(metadataSchemaField).build());
responseObserver.onCompleted();
}
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java
new file mode 100644
index 0000000..9c4f1c9
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java
@@ -0,0 +1,39 @@
+package org.apache.airavata.datacatalog.api.service;
+
+import java.util.List;
+
+import org.apache.airavata.datacatalog.api.DataProduct;
+import org.apache.airavata.datacatalog.api.MetadataSchema;
+import org.apache.airavata.datacatalog.api.MetadataSchemaField;
+
+/**
+ * Transactional service layer for CRUD operations on data catalog database.
+ */
+public interface DataCatalogService {
+
+ DataProduct createDataProduct(DataProduct dataProduct);
+
+ DataProduct updateDataProduct(DataProduct dataProduct);
+
+ DataProduct getDataProduct(String dataProductId);
+
+ void deleteDataProduct(String dataProductId);
+
+ DataProduct addDataProductToMetadataSchema(String dataProductId, String schemaName);
+
+ MetadataSchema getMetadataSchema(String schemaName);
+
+ MetadataSchema createMetadataSchema(MetadataSchema metadataSchema);
+
+ MetadataSchemaField createMetadataSchemaField(MetadataSchemaField metadataSchemaField);
+
+ void deleteMetadataSchema(MetadataSchema metadataSchema);
+
+ void deleteMetadataSchemaField(MetadataSchemaField metadataSchemaField);
+
+ List<MetadataSchemaField> getMetadataSchemaFields(String schemaName);
+
+ DataProduct removeDataProductFromMetadataSchema(String dataProductId, String schemaName);
+
+ MetadataSchemaField updateMetadataSchemaField(MetadataSchemaField metadataSchemaField);
+}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
new file mode 100644
index 0000000..3aef542
--- /dev/null
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
@@ -0,0 +1,205 @@
+package org.apache.airavata.datacatalog.api.service.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.airavata.datacatalog.api.DataProduct;
+import org.apache.airavata.datacatalog.api.MetadataSchema;
+import org.apache.airavata.datacatalog.api.MetadataSchemaField;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListResponse;
+import org.apache.airavata.datacatalog.api.exception.EntityNotFoundException;
+import org.apache.airavata.datacatalog.api.mapper.DataProductMapper;
+import org.apache.airavata.datacatalog.api.mapper.MetadataSchemaFieldMapper;
+import org.apache.airavata.datacatalog.api.mapper.MetadataSchemaMapper;
+import org.apache.airavata.datacatalog.api.model.DataProductEntity;
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaFieldEntity;
+import org.apache.airavata.datacatalog.api.repository.DataProductRepository;
+import org.apache.airavata.datacatalog.api.repository.MetadataSchemaFieldRepository;
+import org.apache.airavata.datacatalog.api.repository.MetadataSchemaRepository;
+import org.apache.airavata.datacatalog.api.service.DataCatalogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional
+public class DataCatalogServiceImpl implements DataCatalogService {
+
+ // Repositories
+ @Autowired
+ DataProductRepository dataProductRepository;
+
+ @Autowired
+ MetadataSchemaRepository metadataSchemaRepository;
+
+ @Autowired
+ MetadataSchemaFieldRepository metadataSchemaFieldRepository;
+
+ // Mappers
+ @Autowired
+ DataProductMapper dataProductMapper;
+
+ @Autowired
+ MetadataSchemaMapper metadataSchemaMapper;
+
+ @Autowired
+ MetadataSchemaFieldMapper metadataSchemaFieldMapper;
+
+ @Override
+ public DataProduct createDataProduct(DataProduct dataProduct) {
+
+ // TODO: SharingManager.resolveUser
+ DataProductEntity dataProductEntity = new DataProductEntity();
+ dataProductEntity.setExternalId(UUID.randomUUID().toString());
+ dataProductMapper.mapModelToEntity(dataProduct, dataProductEntity);
+ DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProductEntity);
+
+ // TODO: SharingManager.grantPermissionToUser(userInfo, dataProduct,
+ // Permission.OWNER)
+
+ return toDataProduct(savedDataProductEntity);
+ }
+
+ @Override
+ public DataProduct updateDataProduct(DataProduct dataProduct) {
+
+ DataProductEntity dataProductEntity = dataProductRepository
+ .findByExternalId(dataProduct.getDataProductId());
+ dataProductMapper.mapModelToEntity(dataProduct, dataProductEntity);
+
+ DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProductEntity);
+
+ return toDataProduct(savedDataProductEntity);
+ }
+
+ @Override
+ public DataProduct getDataProduct(String dataProductId) {
+ // TODO: handle data product does not exist
+ DataProductEntity dataProductEntity = dataProductRepository.findByExternalId(dataProductId);
+ return toDataProduct(dataProductEntity);
+ }
+
+ @Override
+ public void deleteDataProduct(String dataProductId) {
+ dataProductRepository.deleteByExternalId(dataProductId);
+ }
+
+ @Override
+ public DataProduct addDataProductToMetadataSchema(String dataProductId, String schemaName) {
+ // TODO: handle data product not found
+ DataProductEntity dataProduct = dataProductRepository.findByExternalId(dataProductId);
+ // TODO: handle metadata schema not found
+ MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
+ dataProduct.addMetadataSchema(metadataSchemaEntity);
+ DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProduct);
+ return toDataProduct(savedDataProductEntity);
+ }
+
+ @Override
+ public MetadataSchema getMetadataSchema(String schemaName) {
+ MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
+ if (metadataSchemaEntity == null) {
+ throw new EntityNotFoundException("No schema found with name " + schemaName);
+ }
+ return toMetadataSchema(metadataSchemaEntity);
+ }
+
+ @Override
+ public MetadataSchema createMetadataSchema(MetadataSchema metadataSchema) {
+
+ MetadataSchemaEntity metadataSchemaEntity = new MetadataSchemaEntity();
+ metadataSchemaMapper.mapModelToEntity(metadataSchema, metadataSchemaEntity);
+ MetadataSchemaEntity savedMetadataSchemaEntity = metadataSchemaRepository.save(metadataSchemaEntity);
+ return toMetadataSchema(savedMetadataSchemaEntity);
+ }
+
+ @Override
+ public MetadataSchemaField createMetadataSchemaField(MetadataSchemaField metadataSchemaField) {
+
+ MetadataSchemaFieldEntity metadataSchemaFieldEntity = new MetadataSchemaFieldEntity();
+ metadataSchemaFieldMapper.mapModelToEntity(metadataSchemaField, metadataSchemaFieldEntity);
+ MetadataSchemaFieldEntity savedMetadataSchemaFieldEntity = metadataSchemaFieldRepository
+ .save(metadataSchemaFieldEntity);
+ return toMetadataSchemaField(savedMetadataSchemaFieldEntity);
+ }
+
+ @Override
+ public void deleteMetadataSchema(MetadataSchema metadataSchema) {
+ // TODO: check that user has write access on metadata schema
+ // TODO: handle metadata schema not found
+ MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository
+ .findBySchemaName(metadataSchema.getSchemaName());
+ metadataSchemaFieldRepository.deleteAll(metadataSchemaEntity.getMetadataSchemaFields());
+ metadataSchemaRepository.delete(metadataSchemaEntity);
+ }
+
+ @Override
+ public void deleteMetadataSchemaField(MetadataSchemaField metadataSchemaField) {
+ // TODO: handle metadata schema field not found
+ MetadataSchemaFieldEntity metadataSchemaFieldEntity = metadataSchemaFieldRepository
+ .findByFieldNameAndMetadataSchema_SchemaName(metadataSchemaField.getFieldName(),
+ metadataSchemaField.getSchemaName());
+ metadataSchemaFieldRepository.delete(metadataSchemaFieldEntity);
+ }
+
+ @Override
+ public List<MetadataSchemaField> getMetadataSchemaFields(String schemaName) {
+
+ // TODO: handle case where schema doesn't exist
+ List<MetadataSchemaFieldEntity> metadataSchemaFieldEntities = metadataSchemaFieldRepository
+ .findByMetadataSchema_SchemaName(schemaName);
+
+ List<MetadataSchemaField> fields = new ArrayList<>();
+ MetadataSchemaFieldListResponse.Builder responseBuilder = MetadataSchemaFieldListResponse.newBuilder();
+ for (MetadataSchemaFieldEntity metadataSchemaFieldEntity : metadataSchemaFieldEntities) {
+ fields.add(toMetadataSchemaField(metadataSchemaFieldEntity));
+ }
+ return fields;
+ }
+
+ @Override
+ public DataProduct removeDataProductFromMetadataSchema(String dataProductId, String schemaName) {
+
+ // TODO: handle data product not found
+ DataProductEntity dataProduct = dataProductRepository.findByExternalId(dataProductId);
+ // TODO: handle metadata schema not found
+ MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
+ dataProduct.removeMetadataSchema(metadataSchemaEntity);
+ DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProduct);
+ return toDataProduct(savedDataProductEntity);
+ }
+
+ @Override
+ public MetadataSchemaField updateMetadataSchemaField(MetadataSchemaField metadataSchemaField) {
+
+ // TODO: handle metadata schema field not found
+ MetadataSchemaFieldEntity metadataSchemaFieldEntity = metadataSchemaFieldRepository
+ .findByFieldNameAndMetadataSchema_SchemaName(metadataSchemaField.getFieldName(),
+ metadataSchemaField.getSchemaName());
+ metadataSchemaFieldMapper.mapModelToEntity(metadataSchemaField, metadataSchemaFieldEntity);
+ MetadataSchemaFieldEntity savedMetadataSchemaFieldEntity = metadataSchemaFieldRepository
+ .save(metadataSchemaFieldEntity);
+ return toMetadataSchemaField(savedMetadataSchemaFieldEntity);
+ }
+
+ private DataProduct toDataProduct(DataProductEntity savedDataProductEntity) {
+ DataProduct.Builder builder = DataProduct.newBuilder();
+ dataProductMapper.mapEntityToModel(savedDataProductEntity, builder);
+ return builder.build();
+ }
+
+ private MetadataSchema toMetadataSchema(MetadataSchemaEntity metadataSchemaEntity) {
+ MetadataSchema.Builder builder = MetadataSchema.newBuilder();
+ metadataSchemaMapper.mapEntityToModel(metadataSchemaEntity, builder);
+ return builder.build();
+ }
+
+ private MetadataSchemaField toMetadataSchemaField(MetadataSchemaFieldEntity metadataSchemaFieldEntity) {
+ MetadataSchemaField.Builder builder = MetadataSchemaField.newBuilder();
+ metadataSchemaFieldMapper.mapEntityToModel(metadataSchemaFieldEntity, builder);
+ return builder.build();
+ }
+
+}
[airavata-data-catalog] 24/36: Merge pull request #18 from apache/machristie/issue7
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 4d3de78cb73c73a9861dda966965c0f7f9ac7d2b
Merge: d1d40f5 5689e1a
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Feb 20 15:37:14 2023 -0500
Merge pull request #18 from apache/machristie/issue7
Metadata schema management APIs
.../api/client/DataCatalogAPIClient.java | 160 ++++++++++++++-
.../api/exception/EntityNotFoundException.java | 25 +++
.../datacatalog/api/mapper/DataProductMapper.java | 20 ++
.../api/mapper/MetadataSchemaFieldMapper.java | 36 ++++
.../api/mapper/MetadataSchemaMapper.java | 19 ++
.../datacatalog/api/model/DataProductEntity.java | 25 +++
.../api/model/MetadataSchemaEntity.java | 81 ++++++++
.../api/model/MetadataSchemaFieldEntity.java | 110 +++++++++++
.../api/repository/DataProductRepository.java | 1 +
.../repository/MetadataSchemaFieldRepository.java | 13 ++
.../api/repository/MetadataSchemaRepository.java | 9 +
.../api/service/DataCatalogAPIService.java | 193 ++++++++++++++----
.../api/service/DataCatalogService.java | 41 ++++
.../api/service/impl/DataCatalogServiceImpl.java | 215 +++++++++++++++++++++
.../api}/DataCatalogApiServerApplicationTests.java | 2 +-
.../stubs/src/main/proto/DataCatalogAPI.proto | 101 ++++++++++
16 files changed, 1008 insertions(+), 43 deletions(-)
[airavata-data-catalog] 20/36: Fixing query method name
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit c769547a23f7fa9de0e976e5f391a4df11ed3f66
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Fri Feb 17 09:53:16 2023 -0500
Fixing query method name
---
.../datacatalog/api/repository/MetadataSchemaFieldRepository.java | 2 +-
.../airavata/datacatalog/api/service/DataCatalogAPIService.java | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaFieldRepository.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaFieldRepository.java
index c8503db..7350e21 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaFieldRepository.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/MetadataSchemaFieldRepository.java
@@ -9,5 +9,5 @@ public interface MetadataSchemaFieldRepository extends JpaRepository<MetadataSch
List<MetadataSchemaFieldEntity> findByMetadataSchema_SchemaName(String schemaName);
- MetadataSchemaFieldEntity findByFieldNameAndSchema_SchemaName(String fieldName, String schemaName);
+ MetadataSchemaFieldEntity findByFieldNameAndMetadataSchema_SchemaName(String fieldName, String schemaName);
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index 9076ce6..f7a7904 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -217,7 +217,7 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
// TODO: check that user has write access on metadata schema field
// TODO: handle metadata schema field not found
MetadataSchemaFieldEntity metadataSchemaFieldEntity = metadataSchemaFieldRepository
- .findByFieldNameAndSchema_SchemaName(request.getMetadataSchemaField().getFieldName(),
+ .findByFieldNameAndMetadataSchema_SchemaName(request.getMetadataSchemaField().getFieldName(),
request.getMetadataSchemaField().getSchemaName());
metadataSchemaFieldRepository.delete(metadataSchemaFieldEntity);
MetadataSchemaFieldDeleteResponse.Builder responseBuilder = MetadataSchemaFieldDeleteResponse.newBuilder();
@@ -268,7 +268,7 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
// TODO: check that user has write access on metadata schema field
// TODO: handle metadata schema field not found
MetadataSchemaFieldEntity metadataSchemaFieldEntity = metadataSchemaFieldRepository
- .findByFieldNameAndSchema_SchemaName(request.getMetadataSchemaField().getFieldName(),
+ .findByFieldNameAndMetadataSchema_SchemaName(request.getMetadataSchemaField().getFieldName(),
request.getMetadataSchemaField().getSchemaName());
metadataSchemaFieldMapper.mapModelToEntity(request.getMetadataSchemaField(), metadataSchemaFieldEntity);
metadataSchemaFieldRepository.save(metadataSchemaFieldEntity);
[airavata-data-catalog] 07/36: Adding API documentation
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit fdebc4fcdf86d84a52badd043a1eeb244f9083b2
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Jan 31 17:45:59 2023 -0500
Adding API documentation
---
.../airavata/datacatalog/api/model/UserEntity.java | 4 ++++
.../stubs/src/main/proto/DataCatalogAPI.proto | 18 ++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/UserEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/UserEntity.java
index 0540ab2..99a642a 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/UserEntity.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/UserEntity.java
@@ -19,6 +19,10 @@ public class UserEntity {
@Column(name = "user_id")
private Long userId;
+ /**
+ * The identifier for the user. This external identifier comes from the user
+ * management service that data catalog is configured to use.
+ */
@Basic
@Column(name = "external_id", nullable = false)
private String externalId;
diff --git a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
index bc8f656..9508fff 100644
--- a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@ -21,12 +21,30 @@ option java_multiple_files = true;
option java_package = "org.apache.airavata.datacatalog.api";
message UserInfo {
+ /*
+ * This is an external identifier for the user, which identifies the user in
+ * whatever user management scheme data catalog is integrated with.
+ */
string user_id = 1;
+ /*
+ * This is an (optional) external identifier for the tenant, which
+ * identifies the tenant in whatever tenant management scheme data catalog
+ * is integrated with.
+ */
optional string tenant_id = 2;
}
message GroupInfo {
+ /*
+ * This is an external identifier for the group, which identifies the group in
+ * whatever group management scheme data catalog is integrated with.
+ */
string group_id = 1;
+ /*
+ * This is an (optional) external identifier for the tenant, which
+ * identifies the tenant in whatever tenant management scheme data catalog
+ * is integrated with.
+ */
optional string tenant_id = 2;
}
[airavata-data-catalog] 15/36: Implement adding/removing data product to/from metadata schema
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 584cff2099e105e4fd99549ac01799e058bf4fae
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Feb 15 15:31:19 2023 -0500
Implement adding/removing data product to/from metadata schema
---
.../api/client/DataCatalogAPIClient.java | 65 ++++++++++++++++++++--
.../datacatalog/api/mapper/DataProductMapper.java | 6 ++
.../datacatalog/api/model/DataProductEntity.java | 24 ++++++++
.../api/repository/DataProductRepository.java | 1 +
.../api/service/DataCatalogAPIService.java | 53 ++++++++++++++++--
.../stubs/src/main/proto/DataCatalogAPI.proto | 9 +++
6 files changed, 146 insertions(+), 12 deletions(-)
diff --git a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
index 954f994..3d59fdb 100644
--- a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
+++ b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
@@ -7,11 +7,15 @@ import java.util.concurrent.TimeUnit;
import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc;
import org.apache.airavata.datacatalog.api.DataCatalogAPIServiceGrpc.DataCatalogAPIServiceBlockingStub;
import org.apache.airavata.datacatalog.api.DataProduct;
+import org.apache.airavata.datacatalog.api.DataProductAddToMetadataSchemaRequest;
+import org.apache.airavata.datacatalog.api.DataProductAddToMetadataSchemaResponse;
import org.apache.airavata.datacatalog.api.DataProductCreateRequest;
import org.apache.airavata.datacatalog.api.DataProductCreateResponse;
import org.apache.airavata.datacatalog.api.DataProductDeleteRequest;
import org.apache.airavata.datacatalog.api.DataProductGetRequest;
import org.apache.airavata.datacatalog.api.DataProductGetResponse;
+import org.apache.airavata.datacatalog.api.DataProductRemoveFromMetadataSchemaRequest;
+import org.apache.airavata.datacatalog.api.DataProductRemoveFromMetadataSchemaResponse;
import org.apache.airavata.datacatalog.api.DataProductUpdateRequest;
import org.apache.airavata.datacatalog.api.DataProductUpdateResponse;
import org.apache.airavata.datacatalog.api.FieldValueType;
@@ -23,10 +27,14 @@ import org.apache.airavata.datacatalog.api.MetadataSchemaFieldCreateRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldCreateResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchemaGetRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaGetResponse;
import io.grpc.Channel;
import io.grpc.ManagedChannel;
-import io.grpc.ManagedChannelBuilder;;
+import io.grpc.ManagedChannelBuilder;
+import io.grpc.Status;
+import io.grpc.StatusRuntimeException;;
public class DataCatalogAPIClient {
@@ -67,6 +75,19 @@ public class DataCatalogAPIClient {
return response.getMetadataSchema();
}
+ public MetadataSchema getMetadataSchema(String schemaName) {
+ MetadataSchemaGetRequest request = MetadataSchemaGetRequest.newBuilder().setSchemaName(schemaName).build();
+ try {
+ MetadataSchemaGetResponse response = blockingStub.getMetadataSchema(request);
+ return response.getMetadataSchema();
+ } catch (StatusRuntimeException e) {
+ if (e.getStatus() == Status.NOT_FOUND) {
+ return null;
+ }
+ throw e;
+ }
+ }
+
public MetadataSchemaField createMetadataSchemaField(MetadataSchemaField metadataSchemaField) {
MetadataSchemaFieldCreateRequest request = MetadataSchemaFieldCreateRequest.newBuilder()
.setMetadataSchemaField(metadataSchemaField).build();
@@ -81,6 +102,21 @@ public class DataCatalogAPIClient {
return response.getMetadataSchemaFieldsList();
}
+ public DataProduct addDataProductToMetadataSchema(String dataProductId, String schemaName) {
+ DataProductAddToMetadataSchemaRequest request = DataProductAddToMetadataSchemaRequest.newBuilder()
+ .setDataProductId(dataProductId).setSchemaName(schemaName).build();
+ DataProductAddToMetadataSchemaResponse response = blockingStub.addDataProductToMetadataSchema(request);
+ return response.getDataProduct();
+ }
+
+ public DataProduct removeDataProductFromMetadataSchema(String dataProductId, String schemaName) {
+ DataProductRemoveFromMetadataSchemaRequest request = DataProductRemoveFromMetadataSchemaRequest.newBuilder()
+ .setDataProductId(dataProductId).setSchemaName(schemaName).build();
+ DataProductRemoveFromMetadataSchemaResponse response = blockingStub
+ .removeDataProductFromMetadataSchema(request);
+ return response.getDataProduct();
+ }
+
public static void main(String[] args) throws InterruptedException {
String target = "localhost:6565";
@@ -115,11 +151,19 @@ public class DataCatalogAPIClient {
System.out.println(
MessageFormat.format("Deleted data product with id [{0}]", result2.getDataProductId()));
- MetadataSchema metadataSchema = MetadataSchema.newBuilder().setSchemaName("my_schema").build();
- metadataSchema = client.createMetadataSchema(metadataSchema);
-
- System.out.println(
- MessageFormat.format("Created metadata schema with name [{0}]", metadataSchema.getSchemaName()));
+ // First check if metadata schema exists
+ MetadataSchema metadataSchema = client.getMetadataSchema("my_schema");
+ if (metadataSchema == null) {
+ metadataSchema = MetadataSchema.newBuilder().setSchemaName("my_schema").build();
+ metadataSchema = client.createMetadataSchema(metadataSchema);
+ System.out.println(
+ MessageFormat.format("Created metadata schema with name [{0}]",
+ metadataSchema.getSchemaName()));
+ } else {
+ System.out.println(
+ MessageFormat.format("Found metadata schema with name [{0}]",
+ metadataSchema.getSchemaName()));
+ }
MetadataSchemaField field1 = MetadataSchemaField.newBuilder().setFieldName("field1")
.setJsonPath("$.field1").setValueType(FieldValueType.FLOAT)
@@ -142,6 +186,15 @@ public class DataCatalogAPIClient {
System.out.println(MessageFormat.format("-> field {0}", field.getFieldName()));
}
+ result = client.addDataProductToMetadataSchema(result.getDataProductId(), metadataSchema.getSchemaName());
+ System.out.println(MessageFormat.format("Added data product [{0}] to metadata schema [{1}]",
+ result.getDataProductId(), metadataSchema.getSchemaName()));
+
+ result = client.removeDataProductFromMetadataSchema(result.getDataProductId(),
+ metadataSchema.getSchemaName());
+ System.out.println(MessageFormat.format("Removed data product [{0}] from metadata schema [{1}]",
+ result.getDataProductId(), metadataSchema.getSchemaName()));
+
} finally {
channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
index 8e1e155..b03fe1d 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
@@ -2,6 +2,7 @@ package org.apache.airavata.datacatalog.api.mapper;
import org.apache.airavata.datacatalog.api.DataProduct;
import org.apache.airavata.datacatalog.api.model.DataProductEntity;
+import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
import org.apache.airavata.datacatalog.api.repository.DataProductRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -50,5 +51,10 @@ public class DataProductMapper {
if (dataProductEntity.getParentDataProductEntity() != null) {
dataProductBuilder.setParentDataProductId(dataProductEntity.getParentDataProductEntity().getExternalId());
}
+ if (dataProductEntity.getMetadataSchemas() != null) {
+ for (MetadataSchemaEntity metadataSchema : dataProductEntity.getMetadataSchemas()) {
+ dataProductBuilder.addSchemaName(metadataSchema.getSchemaName());
+ }
+ }
}
}
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
index 65b24e7..68b615f 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
@@ -1,5 +1,7 @@
package org.apache.airavata.datacatalog.api.model;
+import java.util.Set;
+
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.databind.JsonNode;
@@ -12,6 +14,8 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
+import jakarta.persistence.JoinTable;
+import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
@@ -43,6 +47,10 @@ public class DataProductEntity {
@Column(name = "metadata", columnDefinition = "jsonb")
private JsonNode metadata;
+ @ManyToMany
+ @JoinTable(name = "data_product_metadata_schema", joinColumns = @JoinColumn(name = "data_product_id"), inverseJoinColumns = @JoinColumn(name = "metadata_schema_id"))
+ private Set<MetadataSchemaEntity> metadataSchemas;
+
// TODO: ManyToOne mapping to owner: UserEntity
public Long getDataProductId() {
return dataProductId;
@@ -84,6 +92,22 @@ public class DataProductEntity {
this.metadata = metadata;
}
+ public Set<MetadataSchemaEntity> getMetadataSchemas() {
+ return metadataSchemas;
+ }
+
+ public void setMetadataSchemas(Set<MetadataSchemaEntity> metadataSchemas) {
+ this.metadataSchemas = metadataSchemas;
+ }
+
+ public void addMetadataSchema(MetadataSchemaEntity metadataSchema) {
+ this.metadataSchemas.add(metadataSchema);
+ }
+
+ public void removeMetadataSchema(MetadataSchemaEntity metadataSchema) {
+ this.metadataSchemas.remove(metadataSchema);
+ }
+
@Override
public int hashCode() {
final int prime = 31;
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java
index acec036..426e4d4 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java
@@ -4,6 +4,7 @@ import org.apache.airavata.datacatalog.api.model.DataProductEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;
+@Transactional(readOnly = true)
public interface DataProductRepository extends JpaRepository<DataProductEntity, Long> {
DataProductEntity findByExternalId(String externalId);
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index 3869ee5..7374def 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -28,6 +28,8 @@ import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldUpdateRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldUpdateResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchemaGetRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaGetResponse;
import org.apache.airavata.datacatalog.api.mapper.DataProductMapper;
import org.apache.airavata.datacatalog.api.mapper.MetadataSchemaFieldMapper;
import org.apache.airavata.datacatalog.api.mapper.MetadataSchemaMapper;
@@ -41,10 +43,13 @@ import org.lognet.springboot.grpc.GRpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import io.grpc.Status;
import io.grpc.stub.StreamObserver;
@GRpcService
+@Transactional
public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalogAPIServiceImplBase {
private static final Logger logger = LoggerFactory.getLogger(DataCatalogAPIService.class);
@@ -76,7 +81,7 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
DataProductEntity dataProductEntity = new DataProductEntity();
dataProductEntity.setExternalId(UUID.randomUUID().toString());
dataProductMapper.mapModelToEntity(request.getDataProduct(), dataProductEntity);
- DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProductEntity);
+ DataProductEntity savedDataProductEntity = dataProductRepository.saveAndFlush(dataProductEntity);
// TODO: SharingManager.grantPermissionToUser(userInfo, dataProduct,
// Permission.OWNER)
@@ -131,8 +136,33 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
@Override
public void addDataProductToMetadataSchema(DataProductAddToMetadataSchemaRequest request,
StreamObserver<DataProductAddToMetadataSchemaResponse> responseObserver) {
- // TODO Auto-generated method stub
- super.addDataProductToMetadataSchema(request, responseObserver);
+ String dataProductId = request.getDataProductId();
+ // TODO: handle data product not found
+ DataProductEntity dataProduct = dataProductRepository.findByExternalId(dataProductId);
+ String schemaName = request.getSchemaName();
+ // TODO: handle metadata schema not found
+ MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
+ dataProduct.addMetadataSchema(metadataSchemaEntity);
+
+ DataProductAddToMetadataSchemaResponse.Builder responseBuilder = DataProductAddToMetadataSchemaResponse
+ .newBuilder();
+ dataProductMapper.mapEntityToModel(dataProduct, responseBuilder.getDataProductBuilder());
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onCompleted();
+ }
+
+ @Override
+ public void getMetadataSchema(MetadataSchemaGetRequest request,
+ StreamObserver<MetadataSchemaGetResponse> responseObserver) {
+ MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(request.getSchemaName());
+ if (metadataSchemaEntity == null) {
+ responseObserver.onError(Status.NOT_FOUND.asException());
+ responseObserver.onCompleted();
+ }
+ MetadataSchemaGetResponse.Builder responseBuilder = MetadataSchemaGetResponse.newBuilder();
+ metadataSchemaMapper.mapEntityToModel(metadataSchemaEntity, responseBuilder.getMetadataSchemaBuilder());
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onCompleted();
}
@Override
@@ -193,15 +223,26 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
metadataSchemaFieldMapper.mapEntityToModel(metadataSchemaFieldEntity, builder);
}
responseObserver.onNext(responseBuilder.build());
- responseObserver.onError(null);
responseObserver.onCompleted();
}
@Override
public void removeDataProductFromMetadataSchema(DataProductRemoveFromMetadataSchemaRequest request,
StreamObserver<DataProductRemoveFromMetadataSchemaResponse> responseObserver) {
- // TODO Auto-generated method stub
- super.removeDataProductFromMetadataSchema(request, responseObserver);
+
+ String dataProductId = request.getDataProductId();
+ // TODO: handle data product not found
+ DataProductEntity dataProduct = dataProductRepository.findByExternalId(dataProductId);
+ String schemaName = request.getSchemaName();
+ // TODO: handle metadata schema not found
+ MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
+ dataProduct.removeMetadataSchema(metadataSchemaEntity);
+
+ DataProductRemoveFromMetadataSchemaResponse.Builder responseBuilder = DataProductRemoveFromMetadataSchemaResponse
+ .newBuilder();
+ dataProductMapper.mapEntityToModel(dataProduct, responseBuilder.getDataProductBuilder());
+ responseObserver.onNext(responseBuilder.build());
+ responseObserver.onCompleted();
}
@Override
diff --git a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
index b1d40dd..cb03016 100644
--- a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@ -62,6 +62,7 @@ message DataProduct {
optional string parent_data_product_id = 2;
string name = 3;
optional string metadata = 4;
+ repeated string schema_name = 5;
}
enum FieldValueType {
@@ -105,6 +106,13 @@ message DataProductDeleteRequest {
message DataProductDeleteResponse {
}
+message MetadataSchemaGetRequest {
+ UserInfo user_info = 1;
+ string schema_name = 2;
+}
+message MetadataSchemaGetResponse {
+ MetadataSchema metadata_schema = 1;
+}
message MetadataSchemaCreateRequest {
UserInfo user_info = 1;
MetadataSchema metadata_schema = 2;
@@ -168,6 +176,7 @@ service DataCatalogAPIService {
rpc updateDataProduct(DataProductUpdateRequest) returns (DataProductUpdateResponse){}
rpc getDataProduct(DataProductGetRequest) returns (DataProductGetResponse){}
rpc deleteDataProduct(DataProductDeleteRequest) returns (DataProductDeleteResponse){}
+ rpc getMetadataSchema(MetadataSchemaGetRequest) returns (MetadataSchemaGetResponse){}
rpc createMetadataSchema(MetadataSchemaCreateRequest) returns (MetadataSchemaCreateResponse){}
rpc deleteMetadataSchema(MetadataSchemaCreateRequest) returns (MetadataSchemaCreateResponse){}
rpc createMetadataSchemaField(MetadataSchemaFieldCreateRequest) returns (MetadataSchemaFieldCreateResponse){}
[airavata-data-catalog] 29/36: handled data product not existing scenario
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 60901b5fbe44e8551fc9f421164d99f7695969ae
Author: Lahiru Jayathilake <la...@gmail.com>
AuthorDate: Sat Mar 11 16:17:00 2023 +0530
handled data product not existing scenario
---
.../datacatalog/api/mapper/DataProductMapper.java | 8 ++--
.../api/repository/DataProductRepository.java | 4 +-
.../api/service/DataCatalogAPIService.java | 49 +++++++++++++++-------
.../api/service/impl/DataCatalogServiceImpl.java | 18 ++++----
4 files changed, 53 insertions(+), 26 deletions(-)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
index bc8ad22..82b17f7 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/mapper/DataProductMapper.java
@@ -1,6 +1,7 @@
package org.apache.airavata.datacatalog.api.mapper;
import org.apache.airavata.datacatalog.api.DataProduct;
+import org.apache.airavata.datacatalog.api.exception.EntityNotFoundException;
import org.apache.airavata.datacatalog.api.model.DataProductEntity;
import org.apache.airavata.datacatalog.api.model.MetadataSchemaEntity;
import org.apache.airavata.datacatalog.api.repository.DataProductRepository;
@@ -30,10 +31,11 @@ public class DataProductMapper {
dataProductEntity.setName(dataProduct.getName());
- if (dataProduct.hasParentDataProductId()) {
- // TODO: handle parent data product not found
+ if (dataProduct.hasParentDataProductId() && !dataProduct.getParentDataProductId().isEmpty()) {
DataProductEntity parentDataProductEntity = dataProductRepository
- .findByExternalId(dataProduct.getParentDataProductId());
+ .findByExternalId(dataProduct.getParentDataProductId())
+ .orElseThrow(() -> new EntityNotFoundException("Could not find the parent data product with the ID: "
+ + dataProduct.getParentDataProductId()));
dataProductEntity.setParentDataProductEntity(parentDataProductEntity);
}
if (dataProduct.hasMetadata()) {
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java
index 426e4d4..64747b2 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/repository/DataProductRepository.java
@@ -4,10 +4,12 @@ import org.apache.airavata.datacatalog.api.model.DataProductEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;
+import java.util.Optional;
+
@Transactional(readOnly = true)
public interface DataProductRepository extends JpaRepository<DataProductEntity, Long> {
- DataProductEntity findByExternalId(String externalId);
+ Optional<DataProductEntity> findByExternalId(String externalId);
@Transactional
void deleteByExternalId(String externalId);
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index b5686a2..e4e4794 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -68,19 +68,29 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
StreamObserver<DataProductUpdateResponse> responseObserver) {
// TODO: check that user has access to update data product record
- DataProduct savedDataProduct = dataCatalogService.updateDataProduct(request.getDataProduct());
+ try {
+ DataProduct savedDataProduct = dataCatalogService.updateDataProduct(request.getDataProduct());
- responseObserver.onNext(DataProductUpdateResponse.newBuilder().setDataProduct(savedDataProduct).build());
- responseObserver.onCompleted();
+ responseObserver.onNext(DataProductUpdateResponse.newBuilder().setDataProduct(savedDataProduct).build());
+ responseObserver.onCompleted();
+ } catch (EntityNotFoundException e) {
+ responseObserver.onError(Status.NOT_FOUND.withDescription(e.getMessage()).asException());
+ responseObserver.onCompleted();
+ }
}
@Override
public void getDataProduct(DataProductGetRequest request, StreamObserver<DataProductGetResponse> responseObserver) {
// TODO: check that user has READ access on data product record
- DataProduct dataProduct = dataCatalogService.getDataProduct(request.getDataProductId());
+ try {
+ DataProduct dataProduct = dataCatalogService.getDataProduct(request.getDataProductId());
- responseObserver.onNext(DataProductGetResponse.newBuilder().setDataProduct(dataProduct).build());
- responseObserver.onCompleted();
+ responseObserver.onNext(DataProductGetResponse.newBuilder().setDataProduct(dataProduct).build());
+ responseObserver.onCompleted();
+ } catch (EntityNotFoundException e) {
+ responseObserver.onError(Status.NOT_FOUND.asException());
+ responseObserver.onCompleted();
+ }
}
@Override
@@ -96,13 +106,19 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
@Override
public void addDataProductToMetadataSchema(DataProductAddToMetadataSchemaRequest request,
StreamObserver<DataProductAddToMetadataSchemaResponse> responseObserver) {
+
String dataProductId = request.getDataProductId();
String schemaName = request.getSchemaName();
- DataProduct dataProduct = dataCatalogService.addDataProductToMetadataSchema(dataProductId, schemaName);
+ try {
+ DataProduct dataProduct = dataCatalogService.addDataProductToMetadataSchema(dataProductId, schemaName);
- responseObserver
- .onNext(DataProductAddToMetadataSchemaResponse.newBuilder().setDataProduct(dataProduct).build());
- responseObserver.onCompleted();
+ responseObserver
+ .onNext(DataProductAddToMetadataSchemaResponse.newBuilder().setDataProduct(dataProduct).build());
+ responseObserver.onCompleted();
+ } catch (EntityNotFoundException e) {
+ responseObserver.onError(Status.NOT_FOUND.withDescription(e.getMessage()).asException());
+ responseObserver.onCompleted();
+ }
}
@Override
@@ -193,11 +209,16 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
String dataProductId = request.getDataProductId();
String schemaName = request.getSchemaName();
- DataProduct dataProduct = dataCatalogService.removeDataProductFromMetadataSchema(dataProductId, schemaName);
+ try {
+ DataProduct dataProduct = dataCatalogService.removeDataProductFromMetadataSchema(dataProductId, schemaName);
- responseObserver
- .onNext(DataProductRemoveFromMetadataSchemaResponse.newBuilder().setDataProduct(dataProduct).build());
- responseObserver.onCompleted();
+ responseObserver
+ .onNext(DataProductRemoveFromMetadataSchemaResponse.newBuilder().setDataProduct(dataProduct).build());
+ responseObserver.onCompleted();
+ } catch (EntityNotFoundException e) {
+ responseObserver.onError(Status.NOT_FOUND.withDescription(e.getMessage()).asException());
+ responseObserver.onCompleted();
+ }
}
@Override
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
index 8e7ee79..1f43ec9 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
@@ -65,8 +65,7 @@ public class DataCatalogServiceImpl implements DataCatalogService {
@Override
public DataProduct updateDataProduct(DataProduct dataProduct) {
- DataProductEntity dataProductEntity = dataProductRepository
- .findByExternalId(dataProduct.getDataProductId());
+ DataProductEntity dataProductEntity = findDataProductEntity(dataProduct.getDataProductId());
dataProductMapper.mapModelToEntity(dataProduct, dataProductEntity);
DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProductEntity);
@@ -76,8 +75,7 @@ public class DataCatalogServiceImpl implements DataCatalogService {
@Override
public DataProduct getDataProduct(String dataProductId) {
- // TODO: handle data product does not exist
- DataProductEntity dataProductEntity = dataProductRepository.findByExternalId(dataProductId);
+ DataProductEntity dataProductEntity = findDataProductEntity(dataProductId);
return toDataProduct(dataProductEntity);
}
@@ -88,8 +86,7 @@ public class DataCatalogServiceImpl implements DataCatalogService {
@Override
public DataProduct addDataProductToMetadataSchema(String dataProductId, String schemaName) {
- // TODO: handle data product not found
- DataProductEntity dataProduct = dataProductRepository.findByExternalId(dataProductId);
+ DataProductEntity dataProduct = findDataProductEntity(dataProductId);
// TODO: handle metadata schema not found
MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
dataProduct.addMetadataSchema(metadataSchemaEntity);
@@ -172,8 +169,7 @@ public class DataCatalogServiceImpl implements DataCatalogService {
@Override
public DataProduct removeDataProductFromMetadataSchema(String dataProductId, String schemaName) {
- // TODO: handle data product not found
- DataProductEntity dataProduct = dataProductRepository.findByExternalId(dataProductId);
+ DataProductEntity dataProduct = findDataProductEntity(dataProductId);
// TODO: handle metadata schema not found
MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
dataProduct.removeMetadataSchema(metadataSchemaEntity);
@@ -212,4 +208,10 @@ public class DataCatalogServiceImpl implements DataCatalogService {
return builder.build();
}
+ private DataProductEntity findDataProductEntity(String dataProductId) {
+ return dataProductRepository
+ .findByExternalId(dataProductId)
+ .orElseThrow(() -> new EntityNotFoundException("Could not find a data product with the ID: " + dataProductId));
+ }
+
}
[airavata-data-catalog] 23/36: Check if metadata schema field exists first before creating
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 5689e1ac27a35068cd73399f6cb96264ee0aaa7c
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Feb 20 15:36:08 2023 -0500
Check if metadata schema field exists first before creating
---
.../api/client/DataCatalogAPIClient.java | 44 +++++++++++++++++++---
.../api/service/DataCatalogAPIService.java | 17 +++++++++
.../api/service/DataCatalogService.java | 2 +
.../api/service/impl/DataCatalogServiceImpl.java | 10 +++++
.../stubs/src/main/proto/DataCatalogAPI.proto | 9 +++++
5 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
index 25495fd..f01554e 100644
--- a/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
+++ b/data-catalog-api/client/src/main/java/org/apache/airavata/datacatalog/api/client/DataCatalogAPIClient.java
@@ -25,6 +25,8 @@ import org.apache.airavata.datacatalog.api.MetadataSchemaCreateResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaField;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldCreateRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldCreateResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldGetRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldGetResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaGetRequest;
@@ -88,6 +90,20 @@ public class DataCatalogAPIClient {
}
}
+ public MetadataSchemaField getMetadataSchemaField(String schemaName, String fieldName) {
+ MetadataSchemaFieldGetRequest request = MetadataSchemaFieldGetRequest.newBuilder().setSchemaName(schemaName)
+ .setFieldName(fieldName).build();
+ try {
+ MetadataSchemaFieldGetResponse response = blockingStub.getMetadataSchemaField(request);
+ return response.getMetadataSchemaField();
+ } catch (StatusRuntimeException e) {
+ if (e.getStatus() == Status.NOT_FOUND) {
+ return null;
+ }
+ throw e;
+ }
+ }
+
public MetadataSchemaField createMetadataSchemaField(MetadataSchemaField metadataSchemaField) {
MetadataSchemaFieldCreateRequest request = MetadataSchemaFieldCreateRequest.newBuilder()
.setMetadataSchemaField(metadataSchemaField).build();
@@ -168,16 +184,32 @@ public class DataCatalogAPIClient {
MetadataSchemaField field1 = MetadataSchemaField.newBuilder().setFieldName("field1")
.setJsonPath("$.field1").setValueType(FieldValueType.FLOAT)
.setSchemaName(metadataSchema.getSchemaName()).build();
- field1 = client.createMetadataSchemaField(field1);
- System.out.println(MessageFormat.format("Created metadata schema field [{0}] in schema [{1}]",
- field1.getFieldName(), field1.getSchemaName()));
+ MetadataSchemaField field1Exists = client.getMetadataSchemaField(field1.getSchemaName(),
+ field1.getFieldName());
+ if (field1Exists == null) {
+ field1 = client.createMetadataSchemaField(field1);
+ System.out.println(MessageFormat.format("Created metadata schema field [{0}] in schema [{1}]",
+ field1.getFieldName(), field1.getSchemaName()));
+ } else {
+ field1 = field1Exists;
+ System.out.println(MessageFormat.format("Found metadata schema field [{0}] in schema [{1}]",
+ field1.getFieldName(), field1.getSchemaName()));
+ }
MetadataSchemaField field2 = MetadataSchemaField.newBuilder().setFieldName("field2")
.setJsonPath("$.field2").setValueType(FieldValueType.FLOAT)
.setSchemaName(metadataSchema.getSchemaName()).build();
- field2 = client.createMetadataSchemaField(field2);
- System.out.println(MessageFormat.format("Created metadata schema field [{0}] in schema [{1}]",
- field2.getFieldName(), field2.getSchemaName()));
+ MetadataSchemaField field2Exists = client.getMetadataSchemaField(field2.getSchemaName(),
+ field2.getFieldName());
+ if (field2Exists == null) {
+ field2 = client.createMetadataSchemaField(field2);
+ System.out.println(MessageFormat.format("Created metadata schema field [{0}] in schema [{1}]",
+ field2.getFieldName(), field2.getSchemaName()));
+ } else {
+ field2 = field2Exists;
+ System.out.println(MessageFormat.format("Found metadata schema field [{0}] in schema [{1}]",
+ field2.getFieldName(), field2.getSchemaName()));
+ }
List<MetadataSchemaField> fields = client.getMetadataSchemaFields(metadataSchema.getSchemaName());
System.out.println(MessageFormat.format("Found {0} fields for schema {1}", fields.size(),
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index 7df3e40..b5686a2 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@ -26,6 +26,8 @@ import org.apache.airavata.datacatalog.api.MetadataSchemaFieldCreateRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldCreateResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldDeleteRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldDeleteResponse;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldGetRequest;
+import org.apache.airavata.datacatalog.api.MetadataSchemaFieldGetResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListRequest;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldListResponse;
import org.apache.airavata.datacatalog.api.MetadataSchemaFieldUpdateRequest;
@@ -127,6 +129,21 @@ public class DataCatalogAPIService extends DataCatalogAPIServiceGrpc.DataCatalog
responseObserver.onCompleted();
}
+ @Override
+ public void getMetadataSchemaField(MetadataSchemaFieldGetRequest request,
+ StreamObserver<MetadataSchemaFieldGetResponse> responseObserver) {
+ try {
+ MetadataSchemaField metadataSchemaField = dataCatalogService.getMetadataSchemaField(request.getSchemaName(),
+ request.getFieldName());
+ responseObserver.onNext(
+ MetadataSchemaFieldGetResponse.newBuilder().setMetadataSchemaField(metadataSchemaField).build());
+ responseObserver.onCompleted();
+ } catch (EntityNotFoundException e) {
+ responseObserver.onError(Status.NOT_FOUND.asException());
+ responseObserver.onCompleted();
+ }
+ }
+
@Override
public void createMetadataSchemaField(MetadataSchemaFieldCreateRequest request,
StreamObserver<MetadataSchemaFieldCreateResponse> responseObserver) {
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java
index 9c4f1c9..2a41ead 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogService.java
@@ -25,6 +25,8 @@ public interface DataCatalogService {
MetadataSchema createMetadataSchema(MetadataSchema metadataSchema);
+ MetadataSchemaField getMetadataSchemaField(String schemaName, String fieldName);
+
MetadataSchemaField createMetadataSchemaField(MetadataSchemaField metadataSchemaField);
void deleteMetadataSchema(MetadataSchema metadataSchema);
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
index 3aef542..8e7ee79 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
@@ -115,6 +115,16 @@ public class DataCatalogServiceImpl implements DataCatalogService {
return toMetadataSchema(savedMetadataSchemaEntity);
}
+ @Override
+ public MetadataSchemaField getMetadataSchemaField(String schemaName, String fieldName) {
+ MetadataSchemaFieldEntity metadataSchemaFieldEntity = metadataSchemaFieldRepository
+ .findByFieldNameAndMetadataSchema_SchemaName(fieldName, schemaName);
+ if (metadataSchemaFieldEntity == null) {
+ throw new EntityNotFoundException("No field found in schema " + schemaName + " with name " + fieldName);
+ }
+ return toMetadataSchemaField(metadataSchemaFieldEntity);
+ }
+
@Override
public MetadataSchemaField createMetadataSchemaField(MetadataSchemaField metadataSchemaField) {
diff --git a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
index 74261d1..2845271 100644
--- a/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
+++ b/data-catalog-api/stubs/src/main/proto/DataCatalogAPI.proto
@@ -126,6 +126,14 @@ message MetadataSchemaDeleteRequest {
}
message MetadataSchemaDeleteResponse {
}
+message MetadataSchemaFieldGetRequest {
+ UserInfo user_info = 1;
+ string schema_name = 2;
+ string field_name = 3;
+}
+message MetadataSchemaFieldGetResponse {
+ MetadataSchemaField metadata_schema_field = 1;
+}
message MetadataSchemaFieldCreateRequest {
UserInfo user_info = 1;
MetadataSchemaField metadata_schema_field = 2;
@@ -179,6 +187,7 @@ service DataCatalogAPIService {
rpc getMetadataSchema(MetadataSchemaGetRequest) returns (MetadataSchemaGetResponse){}
rpc createMetadataSchema(MetadataSchemaCreateRequest) returns (MetadataSchemaCreateResponse){}
rpc deleteMetadataSchema(MetadataSchemaDeleteRequest) returns (MetadataSchemaDeleteResponse){}
+ rpc getMetadataSchemaField(MetadataSchemaFieldGetRequest) returns (MetadataSchemaFieldGetResponse){}
rpc createMetadataSchemaField(MetadataSchemaFieldCreateRequest) returns (MetadataSchemaFieldCreateResponse){}
rpc updateMetadataSchemaField(MetadataSchemaFieldUpdateRequest) returns (MetadataSchemaFieldUpdateResponse){}
rpc deleteMetadataSchemaField(MetadataSchemaFieldDeleteRequest) returns (MetadataSchemaFieldDeleteResponse){}
[airavata-data-catalog] 30/36: Merge pull request #21 from lahirujayathilake/main
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 55967014471813e78e2d4b770d06ac3813772708
Merge: df2f152 60901b5
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Mar 20 14:37:29 2023 -0400
Merge pull request #21 from lahirujayathilake/main
Handled data product not existing scenarios
.../datacatalog/api/mapper/DataProductMapper.java | 8 ++--
.../api/repository/DataProductRepository.java | 4 +-
.../api/service/DataCatalogAPIService.java | 49 +++++++++++++++-------
.../api/service/impl/DataCatalogServiceImpl.java | 18 ++++----
4 files changed, 53 insertions(+), 26 deletions(-)
[airavata-data-catalog] 33/36: Merge branch 'main' into calcite
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit ace3d89e418bd3871b4e9c8f83b3e822a67576ec
Merge: ac7d4ac 5596701
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Mar 21 14:45:51 2023 -0400
Merge branch 'main' into calcite
.../datacatalog/api/mapper/DataProductMapper.java | 16 +++++--
.../api/repository/DataProductRepository.java | 4 +-
.../api/service/DataCatalogAPIService.java | 50 ++++++++++++++++------
.../api/service/impl/DataCatalogServiceImpl.java | 19 ++++----
4 files changed, 63 insertions(+), 26 deletions(-)
diff --cc data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
index 4b7b383,e4e4794..efadaf5
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/DataCatalogAPIService.java
@@@ -101,48 -106,21 +111,60 @@@ public class DataCatalogAPIService exte
@Override
public void addDataProductToMetadataSchema(DataProductAddToMetadataSchemaRequest request,
StreamObserver<DataProductAddToMetadataSchemaResponse> responseObserver) {
+
String dataProductId = request.getDataProductId();
String schemaName = request.getSchemaName();
- DataProduct dataProduct = dataCatalogService.addDataProductToMetadataSchema(dataProductId, schemaName);
-
- responseObserver
- .onNext(DataProductAddToMetadataSchemaResponse.newBuilder().setDataProduct(dataProduct).build());
- responseObserver.onCompleted();
+ try {
+ DataProduct dataProduct = dataCatalogService.addDataProductToMetadataSchema(dataProductId, schemaName);
+
+ responseObserver
+ .onNext(DataProductAddToMetadataSchemaResponse.newBuilder().setDataProduct(dataProduct).build());
+ responseObserver.onCompleted();
+ } catch (EntityNotFoundException e) {
+ responseObserver.onError(Status.NOT_FOUND.withDescription(e.getMessage()).asException());
+ responseObserver.onCompleted();
+ }
}
+ @Override
+ public void removeDataProductFromMetadataSchema(DataProductRemoveFromMetadataSchemaRequest request,
+ StreamObserver<DataProductRemoveFromMetadataSchemaResponse> responseObserver) {
+
+ String dataProductId = request.getDataProductId();
+ String schemaName = request.getSchemaName();
- DataProduct dataProduct = dataCatalogService.removeDataProductFromMetadataSchema(dataProductId, schemaName);
-
- responseObserver
- .onNext(DataProductRemoveFromMetadataSchemaResponse.newBuilder().setDataProduct(dataProduct).build());
- responseObserver.onCompleted();
++ try {
++ DataProduct dataProduct = dataCatalogService.removeDataProductFromMetadataSchema(dataProductId, schemaName);
++
++ responseObserver
++ .onNext(DataProductRemoveFromMetadataSchemaResponse.newBuilder().setDataProduct(dataProduct)
++ .build());
++ responseObserver.onCompleted();
++ } catch (EntityNotFoundException e) {
++ responseObserver.onError(Status.NOT_FOUND.withDescription(e.getMessage()).asException());
++ responseObserver.onCompleted();
++ }
+ }
+
+ @Override
+ public void searchDataProducts(DataProductSearchRequest request,
+ StreamObserver<DataProductSearchResponse> responseObserver) {
+
+ try {
+ MetadataSchemaQueryResult searchResult = dataCatalogService.searchDataProducts(request.getSql());
+ List<DataProduct> dataProducts = searchResult.dataProducts();
+ responseObserver.onNext(DataProductSearchResponse.newBuilder().addAllDataProducts(dataProducts).build());
+ responseObserver.onCompleted();
+ } catch (MetadataSchemaSqlParseException e) {
+ responseObserver
+ .onError(Status.INVALID_ARGUMENT.withDescription("Failed to parse SQL query.").asException());
+ responseObserver.onCompleted();
+ } catch (MetadataSchemaSqlValidateException e) {
+ responseObserver
+ .onError(Status.INVALID_ARGUMENT.withDescription("Failed to validate SQL query.").asException());
+ responseObserver.onCompleted();
+ }
+ }
+
@Override
public void getMetadataSchema(MetadataSchemaGetRequest request,
StreamObserver<MetadataSchemaGetResponse> responseObserver) {
diff --cc data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
index dbce8bb,1f43ec9..1f664a1
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/service/impl/DataCatalogServiceImpl.java
@@@ -104,24 -94,6 +101,23 @@@ public class DataCatalogServiceImpl imp
return toDataProduct(savedDataProductEntity);
}
+ @Override
+ public DataProduct removeDataProductFromMetadataSchema(String dataProductId, String schemaName) {
+
- // TODO: handle data product not found
- DataProductEntity dataProduct = dataProductRepository.findByExternalId(dataProductId);
++ DataProductEntity dataProduct = findDataProductEntity(dataProductId);
+ // TODO: handle metadata schema not found
+ MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
+ dataProduct.removeMetadataSchema(metadataSchemaEntity);
+ DataProductEntity savedDataProductEntity = dataProductRepository.save(dataProduct);
+ return toDataProduct(savedDataProductEntity);
+ }
+
+ @Override
+ public MetadataSchemaQueryResult searchDataProducts(String sql)
+ throws MetadataSchemaSqlParseException, MetadataSchemaSqlValidateException {
+ return metadataSchemaQueryExecutor.execute(sql);
+ }
+
@Override
public MetadataSchema getMetadataSchema(String schemaName) {
MetadataSchemaEntity metadataSchemaEntity = metadataSchemaRepository.findBySchemaName(schemaName);
@@@ -225,4 -208,10 +221,11 @@@
return builder.build();
}
+ private DataProductEntity findDataProductEntity(String dataProductId) {
+ return dataProductRepository
+ .findByExternalId(dataProductId)
- .orElseThrow(() -> new EntityNotFoundException("Could not find a data product with the ID: " + dataProductId));
++ .orElseThrow(() -> new EntityNotFoundException(
++ "Could not find a data product with the ID: " + dataProductId));
+ }
+
}
[airavata-data-catalog] 26/36: view macro attempt, but Calcite doesn't support PostgreSQL json functions
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit d6087eac4347bcbe7094d596dbacd680e9cab1c7
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Feb 27 09:44:55 2023 -0500
view macro attempt, but Calcite doesn't support PostgreSQL json functions
---
.../datacatalog/api/query/MetadataQueryParser.java | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataQueryParser.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataQueryParser.java
index 57d2b17..995497e 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataQueryParser.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/query/MetadataQueryParser.java
@@ -5,6 +5,8 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collections;
import javax.sql.DataSource;
@@ -14,6 +16,7 @@ import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.RelRoot;
import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.impl.ViewTable;
import org.apache.calcite.sql.SqlExplainFormat;
import org.apache.calcite.sql.SqlExplainLevel;
import org.apache.calcite.sql.SqlNode;
@@ -69,8 +72,11 @@ public class MetadataQueryParser {
// JdbcSchema.create(rootSchema, POSTGRESQL_SCHEMA, postgresDataSource, null,
// null));
// rootSchema.add("data_product", jdbcSchema.getTable("data_product"));
- JdbcSchema dcSchema = JdbcSchema.create(rootSchema, "data_catalog", postgresDataSource, null, null);
- rootSchema.add("data_catalog", dcSchema);
+ SchemaPlus dcSchema = rootSchema.add("data_catalog",
+ JdbcSchema.create(rootSchema, "data_catalog", postgresDataSource, null, null));
+ dcSchema.add("smilesdb", ViewTable.viewMacro(dcSchema,
+ "select data_product_id, parent_data_product_id, external_id, metadata, name from \"data_catalog\".\"data_product\" where jsonb_path_exists(\"metadata\", '$.foo == \"bar\"')",
+ Collections.emptyList(), Arrays.asList("data_catalog", "smilesdb"), false));
System.out.println("subschemas: " + rootSchema.getSubSchemaNames());
@@ -81,8 +87,11 @@ public class MetadataQueryParser {
.build();
// String query = "SELECT * FROM public.\"data_product\" WHERE
// \"data_product_id\" = 1";
- String query = "SELECT * FROM data_catalog.data_product WHERE data_product_id = 1";
+ // String query = "SELECT * FROM data_catalog.data_product WHERE data_product_id
+ // = 1";
// String query = "SELECT * FROM data_product WHERE data_product_id = 1";
+ // "smilesdb" view macro
+ String query = "SELECT * FROM data_catalog.smilesdb WHERE data_product_id = 1";
Planner planner = Frameworks.getPlanner(config);
SqlNode parse = planner.parse(query);
[airavata-data-catalog] 36/36: Merge pull request #17 from isururanawaka/main
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit b493b4f619b0054b0be41199d8d2eb32e8b30140
Merge: 115764e 4ae109c
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Mar 29 09:22:08 2023 -0400
Merge pull request #17 from isururanawaka/main
Adding custos sharing lib
.gitignore | 4 +
data-catalog-api/server/pom.xml | 15 +++
.../api/DataCatalogApiServiceApplication.java | 7 ++
.../datacatalog/api/sharing/SharingManager.java | 17 ++--
.../api/sharing/SharingManagerImpl.java | 102 +++++++++++++++++++++
.../src/main/resources/application.properties | 2 +-
.../stubs/src/main/proto/DataCatalogAPI.proto | 1 +
pom.xml | 2 +-
8 files changed, 140 insertions(+), 10 deletions(-)
[airavata-data-catalog] 21/36: Unique constraint on field name
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit a1ceaaa0a5d453bc52b8709ac0e4f6512e1b1213
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Fri Feb 17 09:53:27 2023 -0500
Unique constraint on field name
---
.../airavata/datacatalog/api/model/MetadataSchemaFieldEntity.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaFieldEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaFieldEntity.java
index 8f6a83a..3238f80 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaFieldEntity.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/MetadataSchemaFieldEntity.java
@@ -14,9 +14,11 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
+import jakarta.persistence.UniqueConstraint;
@Entity
-@Table(name = "metadata_schema_field")
+@Table(name = "metadata_schema_field", uniqueConstraints = {
+ @UniqueConstraint(columnNames = { "field_name", "metadata_schema_id" }) })
public class MetadataSchemaFieldEntity {
@Id
[airavata-data-catalog] 02/36: Add unique constraint to external_id
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch custos-integration
in repository https://gitbox.apache.org/repos/asf/airavata-data-catalog.git
commit 9ea7ae9b8d4679ed630e789075b368126f557b4b
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Jan 23 15:33:04 2023 -0500
Add unique constraint to external_id
---
.../org/apache/airavata/datacatalog/api/model/DataProductEntity.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
index 63af7e8..01aa429 100644
--- a/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
+++ b/data-catalog-api/server/src/main/java/org/apache/airavata/datacatalog/api/model/DataProductEntity.java
@@ -10,9 +10,10 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
+import jakarta.persistence.UniqueConstraint;
@Entity
-@Table(name="data_product")
+@Table(name = "data_product", uniqueConstraints = { @UniqueConstraint(columnNames = { "external_id" }) })
public class DataProductEntity {
@Id