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


##########
core/src/main/java/org/apache/gravitino/policy/BasePolicy.java:
##########
@@ -0,0 +1,285 @@
+/*
+ * 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.policy;
+
+import com.google.common.base.Preconditions;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Audit;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.exceptions.IllegalPolicyException;
+
+public class BasePolicy implements Policy {
+  protected String name;
+
+  protected String type;
+
+  @Nullable protected String comment;
+
+  protected boolean enabled;
+
+  protected boolean exclusive;
+
+  protected boolean inheritable;
+
+  protected Set<MetadataObject.Type> supportedObjectTypes;
+
+  protected Content content;
+
+  protected Audit auditInfo;
+
+  public enum ContentType {

Review Comment:
   Move this inner class to the top of the class.



##########
core/src/main/java/org/apache/gravitino/storage/relational/po/PolicyPO.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.storage.relational.po;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import lombok.Getter;
+
+@Getter
+public class PolicyPO {
+  private Long policyId;
+  private String policyName;
+  private String policyType;
+  private Long metalakeId;
+  private boolean inheritable;
+  private boolean exclusive;
+  private String supportedObjectTypes;
+  private String auditInfo;
+  private Long currentVersion;
+  private Long lastVersion;
+  private Long deletedAt;
+  private PolicyVersionPO policyVersionPO;
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (!(o instanceof PolicyPO)) {
+      return false;
+    }
+    PolicyPO policyPO = (PolicyPO) o;
+    return Objects.equal(getPolicyId(), policyPO.policyId)
+        && Objects.equal(getPolicyName(), policyPO.policyName)
+        && Objects.equal(getPolicyType(), policyPO.policyType)
+        && Objects.equal(getMetalakeId(), policyPO.metalakeId)
+        && Objects.equal(isInheritable(), policyPO.inheritable)
+        && Objects.equal(isExclusive(), policyPO.exclusive)
+        && Objects.equal(getSupportedObjectTypes(), 
policyPO.supportedObjectTypes)
+        && Objects.equal(getAuditInfo(), policyPO.auditInfo)
+        && Objects.equal(getCurrentVersion(), policyPO.currentVersion)
+        && Objects.equal(getLastVersion(), policyPO.lastVersion)
+        && Objects.equal(getPolicyVersionPO(), policyPO.policyVersionPO)
+        && Objects.equal(getDeletedAt(), policyPO.deletedAt);

Review Comment:
   Shall we call the method or the variable, I think we should be consistent 
with other implementation.



##########
core/src/main/java/org/apache/gravitino/policy/BasePolicy.java:
##########
@@ -0,0 +1,285 @@
+/*
+ * 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.policy;
+
+import com.google.common.base.Preconditions;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Audit;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.exceptions.IllegalPolicyException;
+
+public class BasePolicy implements Policy {
+  protected String name;
+
+  protected String type;
+
+  @Nullable protected String comment;
+
+  protected boolean enabled;
+
+  protected boolean exclusive;
+
+  protected boolean inheritable;
+
+  protected Set<MetadataObject.Type> supportedObjectTypes;
+
+  protected Content content;
+
+  protected Audit auditInfo;
+
+  public enum ContentType {
+    // Non-built-in types are all custom types.
+    CUSTOM("custom", CustomPolicy.CustomContent.class);
+
+    private final String policyType;
+    private final Class<? extends Content> contentClass;
+
+    ContentType(String policyType, Class<? extends Content> contentClass) {
+      this.policyType = policyType;
+      this.contentClass = contentClass;
+    }
+
+    public static ContentType fromString(String policyType) {
+      Preconditions.checkArgument(StringUtils.isNotBlank(policyType), 
"policyType cannot be blank");
+      for (ContentType contentType : ContentType.values()) {
+        if (contentType.policyType.equalsIgnoreCase(policyType)) {
+          return contentType;
+        }
+      }
+      return CUSTOM;
+    }
+
+    public Class<? extends Content> contentClass() {
+      return contentClass;
+    }
+  }
+
+  @Override
+  public String name() {
+    return name;
+  }
+
+  @Override
+  public String type() {
+    return type;
+  }
+
+  @Override
+  public String comment() {
+    return comment;
+  }
+
+  @Override
+  public boolean enabled() {
+    return enabled;
+  }
+
+  @Override
+  public boolean exclusive() {
+    return exclusive;
+  }
+
+  @Override
+  public boolean inheritable() {
+    return inheritable;
+  }
+
+  @Override
+  public Set<MetadataObject.Type> supportedObjectTypes() {
+    return supportedObjectTypes;
+  }
+
+  @Override
+  public Content content() {
+    return content;
+  }
+
+  @Override
+  public Optional<Boolean> inherited() {
+    return Optional.empty();
+  }
+
+  @Override
+  public void validate() throws IllegalPolicyException {
+    Preconditions.checkArgument(StringUtils.isNotBlank(name), "Policy name 
cannot be blank");
+    Preconditions.checkArgument(StringUtils.isNotBlank(type), "Policy type 
cannot be blank");
+    Preconditions.checkArgument(content() != null, "Policy content cannot be 
null");

Review Comment:
   Shall we check the variable or the method?



##########
core/src/main/java/org/apache/gravitino/policy/CustomPolicy.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.policy;
+
+import com.google.common.base.Preconditions;
+import java.util.Map;
+import java.util.Objects;
+import org.apache.gravitino.exceptions.IllegalPolicyException;
+
+public class CustomPolicy extends BasePolicy {

Review Comment:
   IIUC, the user may also need to access this class?



##########
core/src/main/java/org/apache/gravitino/policy/BasePolicy.java:
##########
@@ -0,0 +1,285 @@
+/*
+ * 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.policy;
+
+import com.google.common.base.Preconditions;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Audit;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.exceptions.IllegalPolicyException;
+
+public class BasePolicy implements Policy {
+  protected String name;
+
+  protected String type;
+
+  @Nullable protected String comment;
+
+  protected boolean enabled;
+
+  protected boolean exclusive;
+
+  protected boolean inheritable;
+
+  protected Set<MetadataObject.Type> supportedObjectTypes;
+
+  protected Content content;
+
+  protected Audit auditInfo;
+
+  public enum ContentType {
+    // Non-built-in types are all custom types.
+    CUSTOM("custom", CustomPolicy.CustomContent.class);
+
+    private final String policyType;
+    private final Class<? extends Content> contentClass;
+
+    ContentType(String policyType, Class<? extends Content> contentClass) {
+      this.policyType = policyType;
+      this.contentClass = contentClass;
+    }
+
+    public static ContentType fromString(String policyType) {
+      Preconditions.checkArgument(StringUtils.isNotBlank(policyType), 
"policyType cannot be blank");
+      for (ContentType contentType : ContentType.values()) {
+        if (contentType.policyType.equalsIgnoreCase(policyType)) {
+          return contentType;
+        }
+      }
+      return CUSTOM;
+    }
+
+    public Class<? extends Content> contentClass() {

Review Comment:
   What is the usage of `contentClass`?



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