xunliu commented on code in PR #4323:
URL: https://github.com/apache/gravitino/pull/4323#discussion_r1699553169


##########
core/src/main/java/org/apache/gravitino/authorization/OwnershipManager.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.authorization;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.EntityStore;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.exceptions.NotFoundException;
+import org.apache.gravitino.exceptions.OwnerNotFoundException;
+import org.apache.gravitino.meta.GroupEntity;
+import org.apache.gravitino.meta.UserEntity;
+import org.apache.gravitino.relation.Relation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OwnershipManager {
+  private static final Logger LOG = 
LoggerFactory.getLogger(OwnershipManager.class);
+  private final EntityStore store;
+
+  public OwnershipManager(EntityStore store) {
+    this.store = store;
+  }
+
+  public void setOwner(
+      NameIdentifier identifier, Entity.EntityType type, String ownerName, 
Owner.Type ownerType) {
+    try {
+      String metalake;
+      if (type == Entity.EntityType.METALAKE) {
+        metalake = identifier.name();
+      } else {
+        metalake = identifier.namespace().level(0);
+      }
+
+      if (ownerType == Owner.Type.USER) {
+        store
+            .relationOperations()
+            .insertRelation(
+                Relation.Type.OWNER_REL,
+                identifier,
+                type,
+                AuthorizationUtils.ofUser(metalake, ownerName),
+                Entity.EntityType.USER,
+                true);
+      } else if (ownerType == Owner.Type.GROUP) {
+        store
+            .relationOperations()
+            .insertRelation(
+                Relation.Type.OWNER_REL,
+                identifier,
+                type,
+                AuthorizationUtils.ofGroup(metalake, ownerName),
+                Entity.EntityType.GROUP,
+                true);
+      }
+    } catch (NoSuchEntityException nse) {
+      LOG.warn("Entity {} or owner {} is not found", identifier, ownerName, 
nse);
+      throw new NotFoundException(nse, "Entity %s or owner %s is not found", 
identifier, ownerName);
+    } catch (IOException ioe) {
+      LOG.info("Fail to set the owner {} of entity {}", ownerName, identifier, 
ioe);
+      throw new RuntimeException(ioe);
+    }
+  }
+
+  public Owner getOwner(NameIdentifier identifier, Entity.EntityType type) {
+    try {
+      OwnerImpl owner = new OwnerImpl();
+      List entities =

Review Comment:
   Better change to `List<Entity>`?



##########
core/src/main/java/org/apache/gravitino/authorization/OwnershipManager.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.authorization;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.EntityStore;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.exceptions.NotFoundException;
+import org.apache.gravitino.exceptions.OwnerNotFoundException;
+import org.apache.gravitino.meta.GroupEntity;
+import org.apache.gravitino.meta.UserEntity;
+import org.apache.gravitino.relation.Relation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OwnershipManager {

Review Comment:
   Please add comments for the class OwnershipManager.



##########
core/src/main/java/org/apache/gravitino/relation/Relation.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.relation;
+
+/** Relation is an abstraction which connects two entities. */
+public interface Relation {
+
+  enum Type {
+    OWNER_REL

Review Comment:
   Which means `REL`, Please add a comment.



##########
api/src/main/java/org/apache/gravitino/authorization/Owner.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.authorization;
+
+/**
+ * Every metadata object has owner. Every role, user or group has owner,too. 
The owner can have all

Review Comment:
   Please add a space in the `owner,too.`



##########
core/src/main/java/org/apache/gravitino/storage/relational/service/OwnerMetaService.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.storage.relational.service;
+
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
+import org.apache.gravitino.storage.relational.po.OwnerRelPO;
+import org.apache.gravitino.storage.relational.utils.POConverters;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+
+public class OwnerMetaService {

Review Comment:
   Please add a comment for OwnerMetaService.



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

To unsubscribe, e-mail: [email protected]

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

Reply via email to