|
| 1 | +/* |
| 2 | + * Copyright 2008-present MongoDB, Inc. |
| 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 | + * http://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.mongodb.client.model.vault; |
| 18 | + |
| 19 | +import com.mongodb.lang.Nullable; |
| 20 | +import org.bson.BsonDocument; |
| 21 | + |
| 22 | +/** |
| 23 | + * String options for a Queryable Encryption field that supports string queries (prefix, suffix, and substring). |
| 24 | + * |
| 25 | + * @since 5.9 |
| 26 | + * @mongodb.server.release 8.2 |
| 27 | + * @mongodb.driver.manual /core/queryable-encryption/ queryable encryption |
| 28 | + */ |
| 29 | +public class StringOptions { |
| 30 | + private boolean caseSensitive; |
| 31 | + private boolean diacriticSensitive; |
| 32 | + @Nullable |
| 33 | + private BsonDocument prefixOptions; |
| 34 | + @Nullable |
| 35 | + private BsonDocument suffixOptions; |
| 36 | + @Nullable |
| 37 | + private BsonDocument substringOptions; |
| 38 | + |
| 39 | + /** |
| 40 | + * Construct a new instance |
| 41 | + */ |
| 42 | + public StringOptions() { |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @return true if string indexes for this field are case sensitive. |
| 47 | + */ |
| 48 | + public boolean getCaseSensitive() { |
| 49 | + return caseSensitive; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Set case sensitivity |
| 54 | + * |
| 55 | + * @param caseSensitive true if string indexes are case sensitive |
| 56 | + * @return this |
| 57 | + */ |
| 58 | + public StringOptions caseSensitive(final boolean caseSensitive) { |
| 59 | + this.caseSensitive = caseSensitive; |
| 60 | + return this; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @return true if string indexes are diacritic sensitive |
| 65 | + */ |
| 66 | + public boolean getDiacriticSensitive() { |
| 67 | + return diacriticSensitive; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Set diacritic sensitivity |
| 72 | + * |
| 73 | + * @param diacriticSensitive true if string indexes are diacritic sensitive |
| 74 | + * @return this |
| 75 | + */ |
| 76 | + public StringOptions diacriticSensitive(final boolean diacriticSensitive) { |
| 77 | + this.diacriticSensitive = diacriticSensitive; |
| 78 | + return this; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Set the prefix options. |
| 83 | + * |
| 84 | + * <p>Expected to be a {@link BsonDocument} in the format of:</p> |
| 85 | + * |
| 86 | + * <pre> |
| 87 | + * {@code |
| 88 | + * { |
| 89 | + * // strMinQueryLength is the minimum allowed query length. Querying with a shorter string will error. |
| 90 | + * strMinQueryLength: BsonInt32, |
| 91 | + * // strMaxQueryLength is the maximum allowed query length. Querying with a longer string will error. |
| 92 | + * strMaxQueryLength: BsonInt32 |
| 93 | + * } |
| 94 | + * } |
| 95 | + * </pre> |
| 96 | + * |
| 97 | + * @param prefixOptions the prefix options or null |
| 98 | + * @return this |
| 99 | + */ |
| 100 | + public StringOptions prefixOptions(@Nullable final BsonDocument prefixOptions) { |
| 101 | + this.prefixOptions = prefixOptions; |
| 102 | + return this; |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * @see #prefixOptions(BsonDocument) |
| 107 | + * @return the prefix options document or null |
| 108 | + */ |
| 109 | + @Nullable |
| 110 | + public BsonDocument getPrefixOptions() { |
| 111 | + return prefixOptions; |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Set the suffix options. |
| 116 | + * |
| 117 | + * <p>Expected to be a {@link BsonDocument} in the format of:</p> |
| 118 | + * |
| 119 | + * <pre> |
| 120 | + * {@code |
| 121 | + * { |
| 122 | + * // strMinQueryLength is the minimum allowed query length. Querying with a shorter string will error. |
| 123 | + * strMinQueryLength: BsonInt32, |
| 124 | + * // strMaxQueryLength is the maximum allowed query length. Querying with a longer string will error. |
| 125 | + * strMaxQueryLength: BsonInt32 |
| 126 | + * } |
| 127 | + * } |
| 128 | + * </pre> |
| 129 | + * |
| 130 | + * @param suffixOptions the suffix options or null |
| 131 | + * @return this |
| 132 | + */ |
| 133 | + public StringOptions suffixOptions(@Nullable final BsonDocument suffixOptions) { |
| 134 | + this.suffixOptions = suffixOptions; |
| 135 | + return this; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * @see #suffixOptions(BsonDocument) |
| 140 | + * @return the suffix options document or null |
| 141 | + */ |
| 142 | + @Nullable |
| 143 | + public BsonDocument getSuffixOptions() { |
| 144 | + return suffixOptions; |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Set the substring options. |
| 149 | + * |
| 150 | + * <p>Expected to be a {@link BsonDocument} in the format of:</p> |
| 151 | + * |
| 152 | + * <pre> |
| 153 | + * {@code |
| 154 | + * { |
| 155 | + * // strMaxLength is the maximum allowed length to insert. Inserting longer strings will error. |
| 156 | + * strMaxLength: BsonInt32, |
| 157 | + * // strMinQueryLength is the minimum allowed query length. Querying with a shorter string will error. |
| 158 | + * strMinQueryLength: BsonInt32, |
| 159 | + * // strMaxQueryLength is the maximum allowed query length. Querying with a longer string will error. |
| 160 | + * strMaxQueryLength: BsonInt32 |
| 161 | + * } |
| 162 | + * } |
| 163 | + * </pre> |
| 164 | + * |
| 165 | + * @param substringOptions the substring options or null |
| 166 | + * @return this |
| 167 | + */ |
| 168 | + public StringOptions substringOptions(@Nullable final BsonDocument substringOptions) { |
| 169 | + this.substringOptions = substringOptions; |
| 170 | + return this; |
| 171 | + } |
| 172 | + |
| 173 | + /** |
| 174 | + * @see #substringOptions(BsonDocument) |
| 175 | + * @return the substring options document or null |
| 176 | + */ |
| 177 | + @Nullable |
| 178 | + public BsonDocument getSubstringOptions() { |
| 179 | + return substringOptions; |
| 180 | + } |
| 181 | + |
| 182 | + @Override |
| 183 | + public String toString() { |
| 184 | + return "StringOptions{" |
| 185 | + + "caseSensitive=" + caseSensitive |
| 186 | + + ", diacriticSensitive=" + diacriticSensitive |
| 187 | + + ", prefixOptions=" + prefixOptions |
| 188 | + + ", suffixOptions=" + suffixOptions |
| 189 | + + ", substringOptions=" + substringOptions |
| 190 | + + '}'; |
| 191 | + } |
| 192 | +} |
0 commit comments