flyrain commented on code in PR #1104: URL: https://github.com/apache/polaris/pull/1104#discussion_r2015143484
########## polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java: ########## @@ -1821,4 +1826,155 @@ public Map<String, String> getInternalPropertyMap( // return the result return new ResolvedEntityResult(entity, entityVersions.getGrantRecordsVersion(), grantRecords); } + + @Override + public @Nonnull PolicyAttachmentResult attachPolicyToEntity( + @Nonnull PolarisCallContext callCtx, + @Nonnull List<PolarisEntityCore> targetCatalogPath, + @Nonnull PolarisEntityCore target, + @Nonnull List<PolarisEntityCore> policyCatalogPath, + @Nonnull PolicyEntity policy, + Map<String, String> parameters) { + // get metastore we should be using + BasePersistence ms = callCtx.getMetaStore(); + + return this.persistNewPolicyMappingRecord(callCtx, ms, target, policy, parameters); + } + + @Override + public @Nonnull PolicyAttachmentResult detachPolicyFromEntity( + @Nonnull PolarisCallContext callCtx, + @Nonnull List<PolarisEntityCore> catalogPath, + @Nonnull PolarisEntityCore target, + @Nonnull List<PolarisEntityCore> policyCatalogPath, + @Nonnull PolicyEntity policy) { + // get metastore we should be using + BasePersistence ms = callCtx.getMetaStore(); + + PolarisPolicyMappingRecord mappingRecord = + ms.lookupPolicyMappingRecord( + callCtx, + target.getCatalogId(), + target.getId(), + policy.getPolicyTypeCode(), + policy.getCatalogId(), + policy.getId()); + if (mappingRecord == null) { + return new PolicyAttachmentResult(BaseResult.ReturnStatus.POLICY_MAPPING_NOT_FOUND, null); + } + + ms.deleteFromPolicyMappingRecords(callCtx, mappingRecord); + + return new PolicyAttachmentResult(mappingRecord); + } + + @Override + public @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntity( + @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore target) { + // get metastore we should be using + BasePersistence ms = callCtx.getMetaStore(); + + PolarisBaseEntity entity = + ms.lookupEntity(callCtx, target.getCatalogId(), target.getId(), target.getTypeCode()); + if (entity == null) { + // Target entity does not exists + return new LoadPolicyMappingsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null); + } + + final List<PolarisPolicyMappingRecord> policyMappingRecords = + ms.loadAllPoliciesOnTarget(callCtx, target.getCatalogId(), target.getId()); + + List<PolarisBaseEntity> policyEntities = + loadPoliciesFromMappingRecords(callCtx, ms, policyMappingRecords); + return new LoadPolicyMappingsResult(policyMappingRecords, policyEntities); + } + + @Override + public @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntityByType( + @Nonnull PolarisCallContext callCtx, + @Nonnull PolarisEntityCore target, + @Nonnull PolicyType policyType) { + // get metastore we should be using + BasePersistence ms = callCtx.getMetaStore(); + + PolarisBaseEntity entity = + ms.lookupEntity(callCtx, target.getCatalogId(), target.getId(), target.getTypeCode()); + if (entity == null) { + // Target entity does not exists Review Comment: nit: exists -> exist ########## polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java: ########## @@ -1821,4 +1826,155 @@ public Map<String, String> getInternalPropertyMap( // return the result return new ResolvedEntityResult(entity, entityVersions.getGrantRecordsVersion(), grantRecords); } + + @Override + public @Nonnull PolicyAttachmentResult attachPolicyToEntity( + @Nonnull PolarisCallContext callCtx, + @Nonnull List<PolarisEntityCore> targetCatalogPath, + @Nonnull PolarisEntityCore target, + @Nonnull List<PolarisEntityCore> policyCatalogPath, + @Nonnull PolicyEntity policy, + Map<String, String> parameters) { + // get metastore we should be using + BasePersistence ms = callCtx.getMetaStore(); + + return this.persistNewPolicyMappingRecord(callCtx, ms, target, policy, parameters); + } + + @Override + public @Nonnull PolicyAttachmentResult detachPolicyFromEntity( + @Nonnull PolarisCallContext callCtx, + @Nonnull List<PolarisEntityCore> catalogPath, + @Nonnull PolarisEntityCore target, + @Nonnull List<PolarisEntityCore> policyCatalogPath, + @Nonnull PolicyEntity policy) { + // get metastore we should be using + BasePersistence ms = callCtx.getMetaStore(); + + PolarisPolicyMappingRecord mappingRecord = + ms.lookupPolicyMappingRecord( + callCtx, + target.getCatalogId(), + target.getId(), + policy.getPolicyTypeCode(), + policy.getCatalogId(), + policy.getId()); + if (mappingRecord == null) { + return new PolicyAttachmentResult(BaseResult.ReturnStatus.POLICY_MAPPING_NOT_FOUND, null); + } + + ms.deleteFromPolicyMappingRecords(callCtx, mappingRecord); + + return new PolicyAttachmentResult(mappingRecord); + } + + @Override + public @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntity( + @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore target) { + // get metastore we should be using + BasePersistence ms = callCtx.getMetaStore(); + + PolarisBaseEntity entity = + ms.lookupEntity(callCtx, target.getCatalogId(), target.getId(), target.getTypeCode()); + if (entity == null) { + // Target entity does not exists Review Comment: Nit: exists -> exist -- 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: issues-unsubscr...@polaris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org