yuqi1129 commented on code in PR #5023:
URL: https://github.com/apache/gravitino/pull/5023#discussion_r1776447171


##########
core/src/main/java/org/apache/gravitino/storage/relational/service/RoleMetaService.java:
##########
@@ -93,49 +78,41 @@ public List<RolePO> listRolesByUserId(Long userId) {
   }
 
   public List<RoleEntity> listRolesByMetadataObjectIdentAndType(
-      NameIdentifier metadataObjectIdent, Entity.EntityType 
metadataObjectType) {
+      NameIdentifier metadataObjectIdent, Entity.EntityType 
metadataObjectType, boolean allFields) {
     String metalake = NameIdentifierUtil.getMetalake(metadataObjectIdent);
     long metalakeId = 
MetalakeMetaService.getInstance().getMetalakeIdByName(metalake);
     MetadataObject metadataObject =
         NameIdentifierUtil.toMetadataObject(metadataObjectIdent, 
metadataObjectType);
     long metadataObjectId =
         MetadataObjectService.getMetadataObjectId(
             metalakeId, metadataObject.fullName(), metadataObject.type());
-    List<RolePO> rolePOs =
-        SessionUtils.getWithoutCommit(
-            RoleMetaMapper.class,
-            mapper ->
-                mapper.listRolesByMetadataObjectIdAndType(
-                    metadataObjectId, metadataObject.type().name()));
-    return rolePOs.stream()
-        .map(
-            po ->
-                POConverters.fromRolePO(
-                    po, listSecurableObjects(po), 
AuthorizationUtils.ofRoleNamespace(metalake)))
-        .collect(Collectors.toList());
-  }
-
-  private List<SecurableObject> listSecurableObjects(RolePO po) {
-    List<SecurableObjectPO> securableObjectPOs = 
listSecurableObjectsByRoleId(po.getRoleId());
-    List<SecurableObject> securableObjects = Lists.newArrayList();
-
-    for (SecurableObjectPO securableObjectPO : securableObjectPOs) {
-      String fullName =
-          MetadataObjectService.getMetadataObjectFullName(
-              securableObjectPO.getType(), 
securableObjectPO.getMetadataObjectId());
-      if (fullName != null) {
-        securableObjects.add(
-            POConverters.fromSecurableObjectPO(
-                fullName, securableObjectPO, 
getType(securableObjectPO.getType())));
-      } else {
-        LOG.info(
-            "The securable object {} {} may be deleted",
-            securableObjectPO.getMetadataObjectId(),
-            securableObjectPO.getType());
-      }
+    if (allFields) {
+      List<RolePO> rolePOs =
+          SessionUtils.getWithoutCommit(
+              RoleMetaMapper.class,
+              mapper ->
+                  mapper.listRolesByMetadataObjectIdAndType(
+                      metadataObjectId, metadataObject.type().name()));
+      return rolePOs.stream()
+          .map(
+              po ->
+                  POConverters.fromRolePO(
+                      po, listSecurableObjects(po), 
AuthorizationUtils.ofRoleNamespace(metalake)))
+          .collect(Collectors.toList());
+    } else {
+      List<RolePO> rolePOs =
+          SessionUtils.getWithoutCommit(
+              RoleMetaMapper.class,
+              mapper ->
+                  mapper.listRolesByMetadataObjectIdAndType(
+                      metadataObjectId, metadataObject.type().name()));
+      return rolePOs.stream()
+          .map(
+              po ->
+                  POConverters.fromRolePO(
+                      po, Collections.emptyList(), 
AuthorizationUtils.ofRoleNamespace(metalake)))
+          .collect(Collectors.toList());

Review Comment:
   ```suggestion   
    List<RolePO> rolePOs =
           SessionUtils.getWithoutCommit(
               RoleMetaMapper.class,
               mapper ->
                   mapper.listRolesByMetadataObjectIdAndType(
                       metadataObjectId, metadataObject.type().name()));
       return rolePOs.stream().map(po -> {
         if (allFields) {
           return POConverters.fromRolePO(
               po, listSecurableObjects(po), 
AuthorizationUtils.ofRoleNamespace(metalake));
         } else {
           return POConverters.fromRolePO(
               po, Collections.emptyList(), 
AuthorizationUtils.ofRoleNamespace(metalake));
         }
       }).collect(Collectors.toList());
   ```



##########
server/src/main/java/org/apache/gravitino/server/web/rest/ObjectRoleOperations.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.server.web.rest;
+
+import com.codahale.metrics.annotation.ResponseMetered;
+import com.codahale.metrics.annotation.Timed;
+import java.util.Locale;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import org.apache.gravitino.GravitinoEnv;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.MetadataObjects;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.authorization.AccessControlDispatcher;
+import org.apache.gravitino.dto.responses.NameListResponse;
+import org.apache.gravitino.lock.LockType;
+import org.apache.gravitino.lock.TreeLockUtils;
+import org.apache.gravitino.metrics.MetricNames;
+import org.apache.gravitino.server.authorization.NameBindings;
+import org.apache.gravitino.server.web.Utils;
+
+@NameBindings.AccessControlInterfaces
+@Path("/metalakes/{metalake}/objects/{type}/{fullName}/roles")
+public class ObjectRoleOperations {

Review Comment:
   Can we rename it to `MetadataObjectRoleOperations`?



##########
core/src/main/java/org/apache/gravitino/SupportsRelationOperations.java:
##########
@@ -48,8 +48,27 @@ enum Type {
    * @return The list of entities
    * @throws IOException When occurs storage issues, it will throw IOException.
    */
+  default <E extends Entity & HasIdentifier> List<E> listEntitiesByRelation(
+      Type relType, NameIdentifier nameIdentifier, Entity.EntityType 
identType) throws IOException {
+    return listEntitiesByRelation(relType, nameIdentifier, identType, true /* 
allFields*/);
+  }
+
+  /**
+   * List the entities according to a give entity in a specific relation.

Review Comment:
   typo: give-> given



##########
core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java:
##########
@@ -382,20 +380,23 @@ public <E extends Entity & HasIdentifier> List<E> 
listEntitiesByRelation(
       case METADATA_OBJECT_ROLE_REL:
         return (List<E>)
             RoleMetaService.getInstance()
-                .listRolesByMetadataObjectIdentAndType(nameIdentifier, 
identType);
+                .listRolesByMetadataObjectIdentAndType(nameIdentifier, 
identType, allFields);
       case ROLE_GROUP_REL:
         if (identType == Entity.EntityType.ROLE) {
           return (List<E>) 
GroupMetaService.getInstance().listGroupsByRoleIdent(nameIdentifier);
         } else {
           throw new IllegalArgumentException(
-              String.format("ROLE_GROUP_REL doesn't support type %s", 
identType.name()));
+              String.format(
+                  "ROLE_GROUP_REL doesn't support type %s or loading all 
fields",

Review Comment:
   Is it possible that ROLE_GROUP_REL does not support all fields? 



-- 
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: commits-unsubscr...@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to