xunliu commented on code in PR #5222: URL: https://github.com/apache/gravitino/pull/5222#discussion_r1812784652
########## authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerSecurableObjects.java: ########## @@ -49,11 +39,24 @@ private static class RangerSecurableObjectImpl extends MetadataObjectImpl * @param type The type of the metadata object */ public RangerSecurableObjectImpl( - String parent, String name, Type type, Set<RangerPrivilege> privileges) { + String parent, + String name, + RangerMetadataObject.Type type, + Set<RangerPrivilege> privileges) { super(parent, name, type); this.privileges = ImmutableList.copyOf(Sets.newHashSet(privileges)); } + @Override + public String fullName() { + return super.fullName(); + } + + @Override + public RangerMetadataObject.Type type() { + return super.type(); + } Review Comment: DONE. ########## authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerMetadataObjects.java: ########## @@ -0,0 +1,125 @@ +/* + * 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.authorization.ranger; + +import com.google.common.base.Joiner; +import com.google.common.base.Preconditions; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; +import java.util.List; +import org.apache.gravitino.MetadataObject; + +/** The helper class for {@link RangerMetadataObject}. */ +public class RangerMetadataObjects { + private static final Splitter DOT_SPLITTER = Splitter.on('.'); + + private static final Joiner DOT_JOINER = Joiner.on('.'); + + private RangerMetadataObjects() {} + + /** + * Get the parent full name of the given full name. + * + * @param names The names of the metadata object + * @return The parent full name if it exists, otherwise null + */ + public static String getParentFullName(List<String> names) { + if (names.size() <= 1) { + return null; + } + + return DOT_JOINER.join(names.subList(0, names.size() - 1)); + } + + static String getLastName(List<String> names) { + return names.get(names.size() - 1); Review Comment: DONE ########## authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationHivePlugin.java: ########## @@ -60,6 +60,37 @@ public static synchronized RangerAuthorizationHivePlugin getInstance(Map<String, return instance; } + /** Validate different Ranger metadata object */ + @Override + public void validateRangerMetadataObject(List<String> names, RangerMetadataObject.Type type) + throws IllegalArgumentException { + Preconditions.checkArgument( Review Comment: DONE ########## authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationHivePlugin.java: ########## @@ -60,6 +60,37 @@ public static synchronized RangerAuthorizationHivePlugin getInstance(Map<String, return instance; } + /** Validate different Ranger metadata object */ + @Override + public void validateRangerMetadataObject(List<String> names, RangerMetadataObject.Type type) + throws IllegalArgumentException { + Preconditions.checkArgument( + names != null, "Cannot create a Ranger metadata object with null names"); + Preconditions.checkArgument( + !names.isEmpty(), "Cannot create a Ranger metadata object with no names"); + Preconditions.checkArgument( + names.size() <= 3, + "Cannot create a Ranger metadata object with the name length which is greater than 3"); + Preconditions.checkArgument( + type != null, "Cannot create a Ranger metadata object with no type"); + + Preconditions.checkArgument( + names.size() != 1 || type == RangerMetadataObject.Type.SCHEMA, + "If the length of names is 1, it must be the SCHEMA type"); Review Comment: This code is right. -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org