| 
 | 1 | +/*  | 
 | 2 | + * Copyright 2024 Google LLC  | 
 | 3 | + *  | 
 | 4 | + * Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 5 | + * you may not use this file except in compliance with the License.  | 
 | 6 | + * You may obtain a copy of the License at  | 
 | 7 | + *  | 
 | 8 | + *    https://www.apache.org/licenses/LICENSE-2.0  | 
 | 9 | + *  | 
 | 10 | + * Unless required by applicable law or agreed to in writing, software  | 
 | 11 | + * distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 13 | + * See the License for the specific language governing permissions and  | 
 | 14 | + * limitations under the License.  | 
 | 15 | + */  | 
 | 16 | + | 
 | 17 | +package com.google.cloud.bigtable.admin.v2.models;  | 
 | 18 | + | 
 | 19 | +import com.google.api.core.InternalApi;  | 
 | 20 | +import com.google.api.core.InternalExtensionOnly;  | 
 | 21 | +import com.google.bigtable.admin.v2.AuthorizedViewName;  | 
 | 22 | +import com.google.common.base.Objects;  | 
 | 23 | +import com.google.common.base.Preconditions;  | 
 | 24 | +import javax.annotation.Nonnull;  | 
 | 25 | + | 
 | 26 | +/**  | 
 | 27 | + * A class that wraps the {@link com.google.bigtable.admin.v2.AuthorizedView} protocol buffer  | 
 | 28 | + * object.  | 
 | 29 | + *  | 
 | 30 | + * <p>An AuthorizedView represents subsets of a particular table based on rules. The access to each  | 
 | 31 | + * AuthorizedView can be configured separately from the Table.  | 
 | 32 | + *  | 
 | 33 | + * <p>Users can perform read/write operation on an AuthorizedView by providing an authorizedView id  | 
 | 34 | + * besides a table id, in which case the semantics remain identical as reading/writing on a Table  | 
 | 35 | + * except that visibility is restricted to the subset of the Table that the AuthorizedView  | 
 | 36 | + * represents.  | 
 | 37 | + */  | 
 | 38 | +public final class AuthorizedView {  | 
 | 39 | +  private final com.google.bigtable.admin.v2.AuthorizedView proto;  | 
 | 40 | + | 
 | 41 | +  /**  | 
 | 42 | +   * Wraps the protobuf. This method is considered an internal implementation detail and not meant  | 
 | 43 | +   * to be used by applications.  | 
 | 44 | +   */  | 
 | 45 | +  @InternalApi  | 
 | 46 | +  public static AuthorizedView fromProto(  | 
 | 47 | +      @Nonnull com.google.bigtable.admin.v2.AuthorizedView proto) {  | 
 | 48 | +    return new AuthorizedView(proto);  | 
 | 49 | +  }  | 
 | 50 | + | 
 | 51 | +  private AuthorizedView(@Nonnull com.google.bigtable.admin.v2.AuthorizedView proto) {  | 
 | 52 | +    Preconditions.checkNotNull(proto);  | 
 | 53 | +    Preconditions.checkArgument(!proto.getName().isEmpty(), "AuthorizedView must have a name");  | 
 | 54 | +    Preconditions.checkArgument(  | 
 | 55 | +        proto.hasSubsetView(), "AuthorizedView must have a subset_view field");  | 
 | 56 | +    this.proto = proto;  | 
 | 57 | +  }  | 
 | 58 | + | 
 | 59 | +  /** Gets the authorized view's id. */  | 
 | 60 | +  public String getId() {  | 
 | 61 | +    // Constructor ensures that name is not null.  | 
 | 62 | +    AuthorizedViewName fullName = AuthorizedViewName.parse(proto.getName());  | 
 | 63 | + | 
 | 64 | +    //noinspection ConstantConditions  | 
 | 65 | +    return fullName.getAuthorizedView();  | 
 | 66 | +  }  | 
 | 67 | + | 
 | 68 | +  /** Gets the id of the table that owns this authorized view. */  | 
 | 69 | +  public String getTableId() {  | 
 | 70 | +    // Constructor ensures that name is not null.  | 
 | 71 | +    AuthorizedViewName fullName = AuthorizedViewName.parse(proto.getName());  | 
 | 72 | + | 
 | 73 | +    //noinspection ConstantConditions  | 
 | 74 | +    return fullName.getTable();  | 
 | 75 | +  }  | 
 | 76 | + | 
 | 77 | +  /** Returns whether this authorized view is deletion protected. */  | 
 | 78 | +  public boolean isDeletionProtected() {  | 
 | 79 | +    return proto.getDeletionProtection();  | 
 | 80 | +  }  | 
 | 81 | + | 
 | 82 | +  /** Gets the type of this authorized view, which currently can only be a subset view. */  | 
 | 83 | +  public AuthorizedViewType getAuthorizedViewType() {  | 
 | 84 | +    if (proto.hasSubsetView()) {  | 
 | 85 | +      return SubsetView.fromProto(proto.getSubsetView());  | 
 | 86 | +    } else {  | 
 | 87 | +      // Should never happen because the constructor verifies that one must exist.  | 
 | 88 | +      throw new IllegalStateException("This AuthorizedView doesn't have a valid type specified");  | 
 | 89 | +    }  | 
 | 90 | +  }  | 
 | 91 | + | 
 | 92 | +  /**  | 
 | 93 | +   * Creates the request protobuf. This method is considered an internal implementation detail and  | 
 | 94 | +   * not meant to be used by applications.  | 
 | 95 | +   */  | 
 | 96 | +  @InternalApi  | 
 | 97 | +  public com.google.bigtable.admin.v2.AuthorizedView toProto() {  | 
 | 98 | +    return proto;  | 
 | 99 | +  }  | 
 | 100 | + | 
 | 101 | +  @Override  | 
 | 102 | +  public boolean equals(Object o) {  | 
 | 103 | +    if (this == o) {  | 
 | 104 | +      return true;  | 
 | 105 | +    }  | 
 | 106 | +    if (o == null || getClass() != o.getClass()) {  | 
 | 107 | +      return false;  | 
 | 108 | +    }  | 
 | 109 | +    AuthorizedView that = (AuthorizedView) o;  | 
 | 110 | +    return Objects.equal(proto, that.proto);  | 
 | 111 | +  }  | 
 | 112 | + | 
 | 113 | +  @Override  | 
 | 114 | +  public int hashCode() {  | 
 | 115 | +    return Objects.hashCode(proto);  | 
 | 116 | +  }  | 
 | 117 | + | 
 | 118 | +  /**  | 
 | 119 | +   * Represents a subset of a Table. Please check the implementations of this interface for more  | 
 | 120 | +   * details.  | 
 | 121 | +   */  | 
 | 122 | +  @InternalExtensionOnly  | 
 | 123 | +  public interface AuthorizedViewType {}  | 
 | 124 | +}  | 
0 commit comments