jerryshao commented on code in PR #7796:
URL: https://github.com/apache/gravitino/pull/7796#discussion_r2255804183


##########
core/src/main/java/org/apache/gravitino/policy/PolicyManager.java:
##########
@@ -222,17 +229,71 @@ public boolean deletePolicy(String metalake, String 
policyName) {
 
   @Override
   public MetadataObject[] listMetadataObjectsForPolicy(String metalake, String 
policyName) {
-    throw new UnsupportedOperationException("Not implemented yet");
-  }
+    NameIdentifier policyIdent = NameIdentifierUtil.ofPolicy(metalake, 
policyName);
+    checkMetalake(NameIdentifier.of(metalake), entityStore);
 
-  @Override
-  public String[] listPoliciesForMetadataObject(String metalake, 
MetadataObject metadataObject) {
-    throw new UnsupportedOperationException("Not implemented yet");
+    return TreeLockUtils.doWithTreeLock(
+        policyIdent,
+        LockType.READ,
+        () -> {
+          try {
+            if (!entityStore.exists(policyIdent, Entity.EntityType.POLICY)) {
+              throw new NoSuchPolicyException(
+                  "Policy with name %s under metalake %s does not exist", 
policyName, metalake);
+            }
+
+            List<GenericEntity> entities =
+                entityStore
+                    .relationOperations()
+                    .listEntitiesByRelation(
+                        
SupportsRelationOperations.Type.POLICY_METADATA_OBJECT_REL,
+                        policyIdent,
+                        Entity.EntityType.POLICY);
+            return MetadataObjectService.fromGenericEntities(entities)
+                .toArray(new MetadataObject[0]);
+          } catch (IOException e) {
+            LOG.error("Failed to list metadata objects for policy {}", 
policyName, e);
+            throw new RuntimeException(e);
+          }
+        });
   }
 
   @Override
   public Policy[] listPolicyInfosForMetadataObject(String metalake, 
MetadataObject metadataObject) {
-    throw new UnsupportedOperationException("Not implemented yet");
+    NameIdentifier entityIdent = MetadataObjectUtil.toEntityIdent(metalake, 
metadataObject);
+    Entity.EntityType entityType = 
MetadataObjectUtil.toEntityType(metadataObject);
+
+    MetadataObjectUtil.checkMetadataObject(metalake, metadataObject);
+    Preconditions.checkArgument(
+        Policy.SUPPORTS_ALL_OBJECT_TYPES.contains(metadataObject.type()),
+        "Cannot list policies for unsupported metadata object type %s",
+        metadataObject.type());
+    checkMetalake(NameIdentifier.of(metalake), entityStore);
+
+    return TreeLockUtils.doWithTreeLock(
+        entityIdent,
+        LockType.READ,
+        () -> {
+          try {
+            return entityStore.relationOperations()
+                .listEntitiesByRelation(
+                    SupportsRelationOperations.Type.POLICY_METADATA_OBJECT_REL,
+                    entityIdent,
+                    entityType,
+                    true /* allFields */)
+                .stream()
+                .map(entity -> (PolicyEntity) entity)
+                .toArray(PolicyEntity[]::new);
+          } catch (NoSuchEntityException e) {
+            throw new NoSuchMetadataObjectException(
+                e,
+                "Failed to list policies for metadata object %s due to not 
found",
+                metadataObject);
+          } catch (IOException e) {
+            LOG.error("Failed to list policies for metadata object {}", 
metadataObject, e);
+            throw new RuntimeException(e);
+          }
+        });

Review Comment:
   Where do you handle the logic about the inherited policies and others?



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