mchades commented on code in PR #7722:
URL: https://github.com/apache/gravitino/pull/7722#discussion_r2250315104


##########
core/src/main/java/org/apache/gravitino/storage/relational/service/PolicyMetaService.java:
##########
@@ -182,33 +191,201 @@ public boolean deletePolicy(NameIdentifier ident) {
   }
 
   public List<PolicyEntity> listPoliciesForMetadataObject(
-      NameIdentifier objectIdent, MetadataObject.Type objectType)
+      NameIdentifier objectIdent, Entity.EntityType objectType)
       throws NoSuchEntityException, IOException {
-    // todo: implement this method
-    throw new UnsupportedOperationException("Not implemented yet");
+    MetadataObject metadataObject = 
NameIdentifierUtil.toMetadataObject(objectIdent, objectType);
+    String metalake = objectIdent.namespace().level(0);
+
+    List<PolicyPO> PolicyPOs;
+    try {
+      Long metalakeId = 
MetalakeMetaService.getInstance().getMetalakeIdByName(metalake);
+      Long metadataObjectId =
+          MetadataObjectService.getMetadataObjectId(
+              metalakeId, metadataObject.fullName(), metadataObject.type());
+
+      PolicyPOs =
+          SessionUtils.doWithoutCommitAndFetchResult(
+              PolicyMetadataObjectRelMapper.class,
+              mapper ->
+                  mapper.listPolicyPOsByMetadataObjectIdAndType(
+                      metadataObjectId, metadataObject.type().toString()));
+    } catch (RuntimeException e) {
+      ExceptionUtils.checkSQLException(e, Entity.EntityType.POLICY, 
objectIdent.toString());
+      throw e;
+    }
+
+    return PolicyPOs.stream()
+        .map(PolicyPO -> POConverters.fromPolicyPO(PolicyPO, 
NamespaceUtil.ofPolicy(metalake)))
+        .collect(Collectors.toList());
   }
 
   public PolicyEntity getPolicyForMetadataObject(
-      NameIdentifier objectIdent, MetadataObject.Type objectType, 
NameIdentifier policyIdent)
+      NameIdentifier objectIdent, Entity.EntityType objectType, NameIdentifier 
policyIdent)
       throws NoSuchEntityException, IOException {
-    // todo: implement this method
-    throw new UnsupportedOperationException("Not implemented yet");
+    MetadataObject metadataObject = 
NameIdentifierUtil.toMetadataObject(objectIdent, objectType);
+    String metalake = objectIdent.namespace().level(0);
+
+    PolicyPO policyPO;
+    try {
+      Long metalakeId = 
MetalakeMetaService.getInstance().getMetalakeIdByName(metalake);
+      Long metadataObjectId =
+          MetadataObjectService.getMetadataObjectId(
+              metalakeId, metadataObject.fullName(), metadataObject.type());
+
+      policyPO =
+          SessionUtils.getWithoutCommit(
+              PolicyMetadataObjectRelMapper.class,
+              mapper ->
+                  mapper.getPolicyPOsByMetadataObjectAndPolicyName(
+                      metadataObjectId, metadataObject.type().toString(), 
policyIdent.name()));
+    } catch (RuntimeException e) {
+      ExceptionUtils.checkSQLException(e, Entity.EntityType.POLICY, 
policyIdent.toString());
+      throw e;
+    }
+
+    if (policyPO == null) {
+      throw new NoSuchEntityException(
+          NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+          Entity.EntityType.POLICY.name().toLowerCase(),
+          policyIdent.name());
+    }
+
+    return POConverters.fromPolicyPO(policyPO, 
NamespaceUtil.ofPolicy(metalake));
   }
 
   public List<MetadataObject> 
listAssociatedMetadataObjectsForPolicy(NameIdentifier policyIdent)

Review Comment:
   It will be used by `listPolicyInfosForMetadataObject` of `PolicyManager` in 
the next PR #7624 



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