Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#13236] fix(common): override rules() in CustomContentDTO to return customRules (#13237)

YangJie6f47cc24e1a4
diff --git a/common/src/main/java/org/apache/gravitino/dto/policy/PolicyContentDTO.java b/common/src/main/java/org/apache/gravitino/dto/policy/PolicyContentDTO.java
index c9d6cb0f4b..5bde7f9af1 100644
--- a/common/src/main/java/org/apache/gravitino/dto/policy/PolicyContentDTO.java
+++ b/common/src/main/java/org/apache/gravitino/dto/policy/PolicyContentDTO.java
@@ -63,6 +63,11 @@ public interface PolicyContentDTO extends PolicyContent {
return customRules;
}
+ @Override
+ public Map<String, Object> rules() {
+ return customRules;
+ }
+
@Override
public Set<MetadataObject.Type> supportedObjectTypes() {
return supportedObjectTypes;
diff --git a/common/src/test/java/org/apache/gravitino/dto/policy/TestPolicyContentDTO.java b/common/src/test/java/org/apache/gravitino/dto/policy/TestPolicyContentDTO.java
new file mode 100644
index 0000000000..1f37c74c72
--- /dev/null
+++ b/common/src/test/java/org/apache/gravitino/dto/policy/TestPolicyContentDTO.java
@@ -0,0 +1,45 @@
+/*
+ * 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.dto.policy;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.Map;
+import org.apache.gravitino.MetadataObject;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestPolicyContentDTO {
+
+ @Test
+ public void testCustomContentDtoRulesReturnsCustomRules() {
+ Map<String, Object> customRules = ImmutableMap.of("rule1", "value1");
+ PolicyContentDTO.CustomContentDTO content =
+ PolicyContentDTO.CustomContentDTO.builder()
+ .withCustomRules(customRules)
+ .withProperties(ImmutableMap.of("k", "v"))
+ .withSupportedObjectTypes(ImmutableSet.of(MetadataObject.Type.TABLE))
+ .build();
+
+ // Before the fix, CustomContentDTO inherited PolicyContent.rules() which throws
+ // UnsupportedOperationException, even though the domain CustomContent returns its
+ // customRules from rules().
+ Assertions.assertEquals(customRules, content.rules());
+ }
+}