flyrain commented on code in PR #1294:
URL: https://github.com/apache/polaris/pull/1294#discussion_r2028149356


##########
service/common/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalog.java:
##########
@@ -0,0 +1,287 @@
+/*
+ * 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.polaris.service.catalog.policy;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.exceptions.BadRequestException;
+import org.apache.polaris.core.PolarisCallContext;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.core.entity.CatalogEntity;
+import org.apache.polaris.core.entity.PolarisEntity;
+import org.apache.polaris.core.entity.PolarisEntitySubType;
+import org.apache.polaris.core.entity.PolarisEntityType;
+import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
+import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
+import org.apache.polaris.core.persistence.dao.entity.BaseResult;
+import org.apache.polaris.core.persistence.dao.entity.DropEntityResult;
+import org.apache.polaris.core.persistence.dao.entity.EntityResult;
+import 
org.apache.polaris.core.persistence.resolver.PolarisResolutionManifestCatalogView;
+import org.apache.polaris.core.policy.PolicyEntity;
+import org.apache.polaris.core.policy.PolicyType;
+import org.apache.polaris.core.policy.exceptions.NoSuchPolicyException;
+import 
org.apache.polaris.core.policy.exceptions.PolicyVersionMismatchException;
+import org.apache.polaris.core.policy.validator.PolicyValidators;
+import org.apache.polaris.service.types.Policy;
+import org.apache.polaris.service.types.PolicyIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PolicyCatalog {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(PolicyCatalog.class);
+
+  private final CallContext callContext;
+  private final PolarisResolutionManifestCatalogView resolvedEntityView;
+  private final CatalogEntity catalogEntity;
+  private long catalogId = -1;
+  private PolarisMetaStoreManager metaStoreManager;
+
+  public PolicyCatalog(
+      PolarisMetaStoreManager metaStoreManager,
+      CallContext callContext,
+      PolarisResolutionManifestCatalogView resolvedEntityView) {
+    this.callContext = callContext;
+    this.resolvedEntityView = resolvedEntityView;
+    this.catalogEntity =
+        
CatalogEntity.of(resolvedEntityView.getResolvedReferenceCatalogEntity().getRawLeafEntity());
+    this.catalogId = catalogEntity.getId();
+    this.metaStoreManager = metaStoreManager;
+  }
+
+  public Policy createPolicy(
+      PolicyIdentifier policyIdentifier, String type, String description, 
String content) {
+    PolarisResolvedPathWrapper resolvedParent =
+        resolvedEntityView.getResolvedPath(policyIdentifier.getNamespace());
+    if (resolvedParent == null) {
+      // Illegal state because the namespace should've already been in the 
static resolution set.
+      throw new IllegalStateException(
+          String.format("Failed to fetch resolved parent for Policy '%s'", 
policyIdentifier));
+    }
+
+    List<PolarisEntity> catalogPath = resolvedParent.getRawFullPath();
+
+    PolarisResolvedPathWrapper resolvedPolicyEntities =
+        resolvedEntityView.getPassthroughResolvedPath(
+            policyIdentifier, PolarisEntityType.POLICY, 
PolarisEntitySubType.NULL_SUBTYPE);
+
+    PolicyEntity entity =
+        PolicyEntity.of(
+            resolvedPolicyEntities == null ? null : 
resolvedPolicyEntities.getRawLeafEntity());
+
+    if (entity == null) {
+      PolicyType policyType = PolicyType.fromName(type);

Review Comment:
   That's a good idea to avoid null check. Not a blocker to me though.



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

Reply via email to