yuqi1129 commented on code in PR #14915: URL: https://github.com/apache/gravitino/pull/14915#discussion_r4585603275
########## api/src/main/java/org/apache/gravitino/glossary/GlossaryOperations.java: ########## @@ -0,0 +1,183 @@ +/* + * 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.glossary; + +import javax.annotation.Nullable; +import org.apache.gravitino.annotation.Evolving; +import org.apache.gravitino.exceptions.ForbiddenException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchTermException; +import org.apache.gravitino.exceptions.NotFoundException; +import org.apache.gravitino.exceptions.TermAlreadyExistsException; + +/** + * Interface for the glossary term operations of a metalake. + * + * <p>A term that the caller cannot see, for example a {@link GlossaryTerm.Status#DRAFT} term of + * another user, is left out of lists, and getting it throws {@link NoSuchTermException}. + * + * <p>In Step 1, {@code VIEW_DEFINITION} permits reading approved and deprecated terms. {@code + * CREATE_DEFINITION} includes view access and permits creating and maintaining terms owned by the + * caller. {@code MANAGE_DEFINITIONS} includes create and view access and permits managing all + * terms, including other owners' drafts. Ownership means the current owner, including group + * members; ownership alone does not replace effective create access. Expand allowed grant + * implications before applying explicit denies to each required capability. Every term read and + * write requires effective {@code VIEW_DEFINITION}; denying view hides terms from reads and blocks + * writes even for an owner with create access. Denying create prevents creation even with an allow + * on manage, but effective manage can still authorize edits. Denying manage removes the all-term + * path without removing effective create access to own terms. These privileges are granted on the + * metalake in Step 1. The metalake owner passes privilege checks, but remains subject to the Step 2 + * workflow and no-self-approval rule. + * + * <p>The write methods describe Step 1: changes take effect immediately, without review. Step 2 + * adds scoped management and review: new terms default to draft, and another authorized manage user + * must approve a submitted change. Neither management privileges nor a direct status update + * bypasses that workflow. Proposal and decision APIs are separate from these immediate-write + * operations. + */ +@Evolving +public interface GlossaryOperations { + + /** + * Lists the names of the terms in the metalake that are visible to the caller. + * + * @return The names of the terms. + * @throws NoSuchMetalakeException If the metalake does not exist. + */ + String[] listTerms() throws NoSuchMetalakeException; + + /** + * Lists the terms in the metalake that are visible to the caller, with details. + * + * @return The terms. + * @throws NoSuchMetalakeException If the metalake does not exist. + */ + GlossaryTerm[] listTermsInfo() throws NoSuchMetalakeException; + + /** + * Gets a term by its name. The name is compared by its normalized key, so case and extra spaces + * do not matter. + * + * @param name The name of the term. + * @return The term. + * @throws NoSuchTermException If the term does not exist or is not visible to the caller. + */ + GlossaryTerm getTerm(String name) throws NoSuchTermException; + + /** + * Creates a term in Step 1. The caller becomes its owner. Without a status, the server uses + * {@link GlossaryTerm.Status#APPROVED}; this does not mean that a human reviewed the term. + * + * <p>The caller needs effective {@code VIEW_DEFINITION}, effective {@code CREATE_DEFINITION}, and + * read access to each requested domain ({@code USE_DOMAIN}) and referenced broader or related + * term. Returned domains and relations follow the same visibility rules as reads. + * + * @param spec The content of the term. + * @return The created term. + * @throws TermAlreadyExistsException If a term with the same name or the same source reference + * already exists. + * @throws NoSuchTermException If a broader or related term does not exist or is not visible to + * the caller. + * @throws NotFoundException If a requested domain does not exist. + * @throws ForbiddenException If the caller lacks the required creation or domain privilege. + * @throws IllegalArgumentException If a synonym is the name of another term, or a relation is not + * allowed. + */ + GlossaryTerm createTerm(TermSpec spec) + throws TermAlreadyExistsException, NoSuchTermException, NotFoundException, ForbiddenException, + IllegalArgumentException; + + /** + * Alters a term in Step 1. All changes take effect immediately and together: if one fails, none + * is applied. The revision of the term increases by one. Use {@link + * TermChange#setStatus(GlossaryTerm.Status)} to change the status without an approval decision. + * + * <p>The caller needs effective {@code VIEW_DEFINITION}, plus effective {@code + * MANAGE_DEFINITIONS} or current ownership with effective {@code CREATE_DEFINITION}. Read access + * to referenced terms and domains is also required. Returned domains and relations follow the + * same visibility rules as reads. + * + * @param name The name of the term. + * @param changes The changes to apply. + * @return The altered term. + * @throws NoSuchTermException If the term, or a broader or related term in the changes, does not + * exist or is not visible to the caller. + * @throws TermAlreadyExistsException If the term is renamed to the name of another term, or its + * source reference is set to the one of another term. + * @throws NotFoundException If a domain to add does not exist. + * @throws ForbiddenException If the caller can see the term but lacks the required edit or domain + * privilege. + * @throws IllegalArgumentException If a change is not valid, for example a synonym that is the + * name of another term, or a broader term that would create a cycle or a chain longer than + * the depth limit. + */ + GlossaryTerm alterTerm(String name, TermChange... changes) + throws NoSuchTermException, TermAlreadyExistsException, NotFoundException, ForbiddenException, + IllegalArgumentException; + + /** + * Drops a term, with its synonyms, relations, domain links and bindings. An {@link + * GlossaryTerm.Status#APPROVED} term cannot be dropped; deprecate it first. Review Comment: Aligned the deletion contract: effective VIEW plus MANAGE permits deletion in any status, including APPROVED, without prior deprecation. Missing or hidden terms return false; a visible term without MANAGE throws `ForbiddenException`. This updates the public Javadoc consumed by downstream implementations; runtime authorization/cascade enforcement belongs to the core subtask. Addressed on [current head `717961f1f2`](https://github.com/apache/gravitino/pull/14915/commits/717961f1f2c56a5519995269b38df28e9bd4468f). <!-- glossary-api-review-reply:4583131557 --> ########## api/src/main/java/org/apache/gravitino/MetadataObjects.java: ########## @@ -49,7 +49,8 @@ public class MetadataObjects { MetadataObject.Type.JOB, MetadataObject.Type.JOB_TEMPLATE, MetadataObject.Type.POLICY, - MetadataObject.Type.DOMAIN); + MetadataObject.Type.DOMAIN, + MetadataObject.Type.GLOSSARY_TERM); Review Comment: Fixed `MetadataObjectDTO.setFullName` to treat `GLOSSARY_TERM` as a single-level name. Jackson regression tests check the full name, `name()`, null `parent()` and type for dotted/slashed names, including both JSON field orders. All five `TestMetadataObjectDTO` tests pass on this head. Addressed on [current head `717961f1f2`](https://github.com/apache/gravitino/pull/14915/commits/717961f1f2c56a5519995269b38df28e9bd4468f). <!-- glossary-api-review-reply:4583131563 --> -- 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]
