1 /* 2 * Copyright 2022 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.privacy.dlp.v2; 18 19 import com.google.api.core.BetaApi; 20 import com.google.api.pathtemplate.PathTemplate; 21 import com.google.api.pathtemplate.ValidationException; 22 import com.google.api.resourcenames.ResourceName; 23 import com.google.common.base.Preconditions; 24 import com.google.common.collect.ImmutableMap; 25 import java.util.Map; 26 import java.util.Objects; 27 import javax.annotation.Generated; 28 29 // AUTO-GENERATED DOCUMENTATION AND CLASS. 30 @Generated("by gapic-generator-java") 31 public class DeidentifyTemplateName implements ResourceName { 32 private static final PathTemplate ORGANIZATION_DEIDENTIFY_TEMPLATE = 33 PathTemplate.createWithoutUrlEncoding( 34 "organizations/{organization}/deidentifyTemplates/{deidentify_template}"); 35 private static final PathTemplate PROJECT_DEIDENTIFY_TEMPLATE = 36 PathTemplate.createWithoutUrlEncoding( 37 "projects/{project}/deidentifyTemplates/{deidentify_template}"); 38 private static final PathTemplate ORGANIZATION_LOCATION_DEIDENTIFY_TEMPLATE = 39 PathTemplate.createWithoutUrlEncoding( 40 "organizations/{organization}/locations/{location}/deidentifyTemplates/{deidentify_template}"); 41 private static final PathTemplate PROJECT_LOCATION_DEIDENTIFY_TEMPLATE = 42 PathTemplate.createWithoutUrlEncoding( 43 "projects/{project}/locations/{location}/deidentifyTemplates/{deidentify_template}"); 44 private volatile Map<String, String> fieldValuesMap; 45 private PathTemplate pathTemplate; 46 private String fixedValue; 47 private final String organization; 48 private final String deidentifyTemplate; 49 private final String project; 50 private final String location; 51 52 @Deprecated DeidentifyTemplateName()53 protected DeidentifyTemplateName() { 54 organization = null; 55 deidentifyTemplate = null; 56 project = null; 57 location = null; 58 } 59 DeidentifyTemplateName(Builder builder)60 private DeidentifyTemplateName(Builder builder) { 61 organization = Preconditions.checkNotNull(builder.getOrganization()); 62 deidentifyTemplate = Preconditions.checkNotNull(builder.getDeidentifyTemplate()); 63 project = null; 64 location = null; 65 pathTemplate = ORGANIZATION_DEIDENTIFY_TEMPLATE; 66 } 67 DeidentifyTemplateName(ProjectDeidentifyTemplateBuilder builder)68 private DeidentifyTemplateName(ProjectDeidentifyTemplateBuilder builder) { 69 project = Preconditions.checkNotNull(builder.getProject()); 70 deidentifyTemplate = Preconditions.checkNotNull(builder.getDeidentifyTemplate()); 71 organization = null; 72 location = null; 73 pathTemplate = PROJECT_DEIDENTIFY_TEMPLATE; 74 } 75 DeidentifyTemplateName(OrganizationLocationDeidentifyTemplateBuilder builder)76 private DeidentifyTemplateName(OrganizationLocationDeidentifyTemplateBuilder builder) { 77 organization = Preconditions.checkNotNull(builder.getOrganization()); 78 location = Preconditions.checkNotNull(builder.getLocation()); 79 deidentifyTemplate = Preconditions.checkNotNull(builder.getDeidentifyTemplate()); 80 project = null; 81 pathTemplate = ORGANIZATION_LOCATION_DEIDENTIFY_TEMPLATE; 82 } 83 DeidentifyTemplateName(ProjectLocationDeidentifyTemplateBuilder builder)84 private DeidentifyTemplateName(ProjectLocationDeidentifyTemplateBuilder builder) { 85 project = Preconditions.checkNotNull(builder.getProject()); 86 location = Preconditions.checkNotNull(builder.getLocation()); 87 deidentifyTemplate = Preconditions.checkNotNull(builder.getDeidentifyTemplate()); 88 organization = null; 89 pathTemplate = PROJECT_LOCATION_DEIDENTIFY_TEMPLATE; 90 } 91 getOrganization()92 public String getOrganization() { 93 return organization; 94 } 95 getDeidentifyTemplate()96 public String getDeidentifyTemplate() { 97 return deidentifyTemplate; 98 } 99 getProject()100 public String getProject() { 101 return project; 102 } 103 getLocation()104 public String getLocation() { 105 return location; 106 } 107 newBuilder()108 public static Builder newBuilder() { 109 return new Builder(); 110 } 111 112 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newOrganizationDeidentifyTemplateBuilder()113 public static Builder newOrganizationDeidentifyTemplateBuilder() { 114 return new Builder(); 115 } 116 117 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newProjectDeidentifyTemplateBuilder()118 public static ProjectDeidentifyTemplateBuilder newProjectDeidentifyTemplateBuilder() { 119 return new ProjectDeidentifyTemplateBuilder(); 120 } 121 122 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 123 public static OrganizationLocationDeidentifyTemplateBuilder newOrganizationLocationDeidentifyTemplateBuilder()124 newOrganizationLocationDeidentifyTemplateBuilder() { 125 return new OrganizationLocationDeidentifyTemplateBuilder(); 126 } 127 128 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 129 public static ProjectLocationDeidentifyTemplateBuilder newProjectLocationDeidentifyTemplateBuilder()130 newProjectLocationDeidentifyTemplateBuilder() { 131 return new ProjectLocationDeidentifyTemplateBuilder(); 132 } 133 toBuilder()134 public Builder toBuilder() { 135 return new Builder(this); 136 } 137 of(String organization, String deidentifyTemplate)138 public static DeidentifyTemplateName of(String organization, String deidentifyTemplate) { 139 return newBuilder() 140 .setOrganization(organization) 141 .setDeidentifyTemplate(deidentifyTemplate) 142 .build(); 143 } 144 145 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofOrganizationDeidentifyTemplateName( String organization, String deidentifyTemplate)146 public static DeidentifyTemplateName ofOrganizationDeidentifyTemplateName( 147 String organization, String deidentifyTemplate) { 148 return newBuilder() 149 .setOrganization(organization) 150 .setDeidentifyTemplate(deidentifyTemplate) 151 .build(); 152 } 153 154 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectDeidentifyTemplateName( String project, String deidentifyTemplate)155 public static DeidentifyTemplateName ofProjectDeidentifyTemplateName( 156 String project, String deidentifyTemplate) { 157 return newProjectDeidentifyTemplateBuilder() 158 .setProject(project) 159 .setDeidentifyTemplate(deidentifyTemplate) 160 .build(); 161 } 162 163 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofOrganizationLocationDeidentifyTemplateName( String organization, String location, String deidentifyTemplate)164 public static DeidentifyTemplateName ofOrganizationLocationDeidentifyTemplateName( 165 String organization, String location, String deidentifyTemplate) { 166 return newOrganizationLocationDeidentifyTemplateBuilder() 167 .setOrganization(organization) 168 .setLocation(location) 169 .setDeidentifyTemplate(deidentifyTemplate) 170 .build(); 171 } 172 173 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectLocationDeidentifyTemplateName( String project, String location, String deidentifyTemplate)174 public static DeidentifyTemplateName ofProjectLocationDeidentifyTemplateName( 175 String project, String location, String deidentifyTemplate) { 176 return newProjectLocationDeidentifyTemplateBuilder() 177 .setProject(project) 178 .setLocation(location) 179 .setDeidentifyTemplate(deidentifyTemplate) 180 .build(); 181 } 182 format(String organization, String deidentifyTemplate)183 public static String format(String organization, String deidentifyTemplate) { 184 return newBuilder() 185 .setOrganization(organization) 186 .setDeidentifyTemplate(deidentifyTemplate) 187 .build() 188 .toString(); 189 } 190 191 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatOrganizationDeidentifyTemplateName( String organization, String deidentifyTemplate)192 public static String formatOrganizationDeidentifyTemplateName( 193 String organization, String deidentifyTemplate) { 194 return newBuilder() 195 .setOrganization(organization) 196 .setDeidentifyTemplate(deidentifyTemplate) 197 .build() 198 .toString(); 199 } 200 201 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectDeidentifyTemplateName( String project, String deidentifyTemplate)202 public static String formatProjectDeidentifyTemplateName( 203 String project, String deidentifyTemplate) { 204 return newProjectDeidentifyTemplateBuilder() 205 .setProject(project) 206 .setDeidentifyTemplate(deidentifyTemplate) 207 .build() 208 .toString(); 209 } 210 211 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatOrganizationLocationDeidentifyTemplateName( String organization, String location, String deidentifyTemplate)212 public static String formatOrganizationLocationDeidentifyTemplateName( 213 String organization, String location, String deidentifyTemplate) { 214 return newOrganizationLocationDeidentifyTemplateBuilder() 215 .setOrganization(organization) 216 .setLocation(location) 217 .setDeidentifyTemplate(deidentifyTemplate) 218 .build() 219 .toString(); 220 } 221 222 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectLocationDeidentifyTemplateName( String project, String location, String deidentifyTemplate)223 public static String formatProjectLocationDeidentifyTemplateName( 224 String project, String location, String deidentifyTemplate) { 225 return newProjectLocationDeidentifyTemplateBuilder() 226 .setProject(project) 227 .setLocation(location) 228 .setDeidentifyTemplate(deidentifyTemplate) 229 .build() 230 .toString(); 231 } 232 parse(String formattedString)233 public static DeidentifyTemplateName parse(String formattedString) { 234 if (formattedString.isEmpty()) { 235 return null; 236 } 237 if (ORGANIZATION_DEIDENTIFY_TEMPLATE.matches(formattedString)) { 238 Map<String, String> matchMap = ORGANIZATION_DEIDENTIFY_TEMPLATE.match(formattedString); 239 return ofOrganizationDeidentifyTemplateName( 240 matchMap.get("organization"), matchMap.get("deidentify_template")); 241 } else if (PROJECT_DEIDENTIFY_TEMPLATE.matches(formattedString)) { 242 Map<String, String> matchMap = PROJECT_DEIDENTIFY_TEMPLATE.match(formattedString); 243 return ofProjectDeidentifyTemplateName( 244 matchMap.get("project"), matchMap.get("deidentify_template")); 245 } else if (ORGANIZATION_LOCATION_DEIDENTIFY_TEMPLATE.matches(formattedString)) { 246 Map<String, String> matchMap = 247 ORGANIZATION_LOCATION_DEIDENTIFY_TEMPLATE.match(formattedString); 248 return ofOrganizationLocationDeidentifyTemplateName( 249 matchMap.get("organization"), 250 matchMap.get("location"), 251 matchMap.get("deidentify_template")); 252 } else if (PROJECT_LOCATION_DEIDENTIFY_TEMPLATE.matches(formattedString)) { 253 Map<String, String> matchMap = PROJECT_LOCATION_DEIDENTIFY_TEMPLATE.match(formattedString); 254 return ofProjectLocationDeidentifyTemplateName( 255 matchMap.get("project"), matchMap.get("location"), matchMap.get("deidentify_template")); 256 } 257 throw new ValidationException( 258 "DeidentifyTemplateName.parse: formattedString not in valid format"); 259 } 260 isParsableFrom(String formattedString)261 public static boolean isParsableFrom(String formattedString) { 262 return ORGANIZATION_DEIDENTIFY_TEMPLATE.matches(formattedString) 263 || PROJECT_DEIDENTIFY_TEMPLATE.matches(formattedString) 264 || ORGANIZATION_LOCATION_DEIDENTIFY_TEMPLATE.matches(formattedString) 265 || PROJECT_LOCATION_DEIDENTIFY_TEMPLATE.matches(formattedString); 266 } 267 268 @Override getFieldValuesMap()269 public Map<String, String> getFieldValuesMap() { 270 if (fieldValuesMap == null) { 271 synchronized (this) { 272 if (fieldValuesMap == null) { 273 ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder(); 274 if (organization != null) { 275 fieldMapBuilder.put("organization", organization); 276 } 277 if (deidentifyTemplate != null) { 278 fieldMapBuilder.put("deidentify_template", deidentifyTemplate); 279 } 280 if (project != null) { 281 fieldMapBuilder.put("project", project); 282 } 283 if (location != null) { 284 fieldMapBuilder.put("location", location); 285 } 286 fieldValuesMap = fieldMapBuilder.build(); 287 } 288 } 289 } 290 return fieldValuesMap; 291 } 292 getFieldValue(String fieldName)293 public String getFieldValue(String fieldName) { 294 return getFieldValuesMap().get(fieldName); 295 } 296 297 @Override toString()298 public String toString() { 299 return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap()); 300 } 301 302 @Override equals(Object o)303 public boolean equals(Object o) { 304 if (o == this) { 305 return true; 306 } 307 if (o != null || getClass() == o.getClass()) { 308 DeidentifyTemplateName that = ((DeidentifyTemplateName) o); 309 return Objects.equals(this.organization, that.organization) 310 && Objects.equals(this.deidentifyTemplate, that.deidentifyTemplate) 311 && Objects.equals(this.project, that.project) 312 && Objects.equals(this.location, that.location); 313 } 314 return false; 315 } 316 317 @Override hashCode()318 public int hashCode() { 319 int h = 1; 320 h *= 1000003; 321 h ^= Objects.hashCode(fixedValue); 322 h *= 1000003; 323 h ^= Objects.hashCode(organization); 324 h *= 1000003; 325 h ^= Objects.hashCode(deidentifyTemplate); 326 h *= 1000003; 327 h ^= Objects.hashCode(project); 328 h *= 1000003; 329 h ^= Objects.hashCode(location); 330 return h; 331 } 332 333 /** Builder for organizations/{organization}/deidentifyTemplates/{deidentify_template}. */ 334 public static class Builder { 335 private String organization; 336 private String deidentifyTemplate; 337 Builder()338 protected Builder() {} 339 getOrganization()340 public String getOrganization() { 341 return organization; 342 } 343 getDeidentifyTemplate()344 public String getDeidentifyTemplate() { 345 return deidentifyTemplate; 346 } 347 setOrganization(String organization)348 public Builder setOrganization(String organization) { 349 this.organization = organization; 350 return this; 351 } 352 setDeidentifyTemplate(String deidentifyTemplate)353 public Builder setDeidentifyTemplate(String deidentifyTemplate) { 354 this.deidentifyTemplate = deidentifyTemplate; 355 return this; 356 } 357 Builder(DeidentifyTemplateName deidentifyTemplateName)358 private Builder(DeidentifyTemplateName deidentifyTemplateName) { 359 Preconditions.checkArgument( 360 Objects.equals(deidentifyTemplateName.pathTemplate, ORGANIZATION_DEIDENTIFY_TEMPLATE), 361 "toBuilder is only supported when DeidentifyTemplateName has the pattern of organizations/{organization}/deidentifyTemplates/{deidentify_template}"); 362 this.organization = deidentifyTemplateName.organization; 363 this.deidentifyTemplate = deidentifyTemplateName.deidentifyTemplate; 364 } 365 build()366 public DeidentifyTemplateName build() { 367 return new DeidentifyTemplateName(this); 368 } 369 } 370 371 /** Builder for projects/{project}/deidentifyTemplates/{deidentify_template}. */ 372 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 373 public static class ProjectDeidentifyTemplateBuilder { 374 private String project; 375 private String deidentifyTemplate; 376 ProjectDeidentifyTemplateBuilder()377 protected ProjectDeidentifyTemplateBuilder() {} 378 getProject()379 public String getProject() { 380 return project; 381 } 382 getDeidentifyTemplate()383 public String getDeidentifyTemplate() { 384 return deidentifyTemplate; 385 } 386 setProject(String project)387 public ProjectDeidentifyTemplateBuilder setProject(String project) { 388 this.project = project; 389 return this; 390 } 391 setDeidentifyTemplate(String deidentifyTemplate)392 public ProjectDeidentifyTemplateBuilder setDeidentifyTemplate(String deidentifyTemplate) { 393 this.deidentifyTemplate = deidentifyTemplate; 394 return this; 395 } 396 build()397 public DeidentifyTemplateName build() { 398 return new DeidentifyTemplateName(this); 399 } 400 } 401 402 /** 403 * Builder for 404 * organizations/{organization}/locations/{location}/deidentifyTemplates/{deidentify_template}. 405 */ 406 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 407 public static class OrganizationLocationDeidentifyTemplateBuilder { 408 private String organization; 409 private String location; 410 private String deidentifyTemplate; 411 OrganizationLocationDeidentifyTemplateBuilder()412 protected OrganizationLocationDeidentifyTemplateBuilder() {} 413 getOrganization()414 public String getOrganization() { 415 return organization; 416 } 417 getLocation()418 public String getLocation() { 419 return location; 420 } 421 getDeidentifyTemplate()422 public String getDeidentifyTemplate() { 423 return deidentifyTemplate; 424 } 425 setOrganization(String organization)426 public OrganizationLocationDeidentifyTemplateBuilder setOrganization(String organization) { 427 this.organization = organization; 428 return this; 429 } 430 setLocation(String location)431 public OrganizationLocationDeidentifyTemplateBuilder setLocation(String location) { 432 this.location = location; 433 return this; 434 } 435 setDeidentifyTemplate( String deidentifyTemplate)436 public OrganizationLocationDeidentifyTemplateBuilder setDeidentifyTemplate( 437 String deidentifyTemplate) { 438 this.deidentifyTemplate = deidentifyTemplate; 439 return this; 440 } 441 build()442 public DeidentifyTemplateName build() { 443 return new DeidentifyTemplateName(this); 444 } 445 } 446 447 /** 448 * Builder for projects/{project}/locations/{location}/deidentifyTemplates/{deidentify_template}. 449 */ 450 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 451 public static class ProjectLocationDeidentifyTemplateBuilder { 452 private String project; 453 private String location; 454 private String deidentifyTemplate; 455 ProjectLocationDeidentifyTemplateBuilder()456 protected ProjectLocationDeidentifyTemplateBuilder() {} 457 getProject()458 public String getProject() { 459 return project; 460 } 461 getLocation()462 public String getLocation() { 463 return location; 464 } 465 getDeidentifyTemplate()466 public String getDeidentifyTemplate() { 467 return deidentifyTemplate; 468 } 469 setProject(String project)470 public ProjectLocationDeidentifyTemplateBuilder setProject(String project) { 471 this.project = project; 472 return this; 473 } 474 setLocation(String location)475 public ProjectLocationDeidentifyTemplateBuilder setLocation(String location) { 476 this.location = location; 477 return this; 478 } 479 setDeidentifyTemplate( String deidentifyTemplate)480 public ProjectLocationDeidentifyTemplateBuilder setDeidentifyTemplate( 481 String deidentifyTemplate) { 482 this.deidentifyTemplate = deidentifyTemplate; 483 return this; 484 } 485 build()486 public DeidentifyTemplateName build() { 487 return new DeidentifyTemplateName(this); 488 } 489 } 490 } 491