• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.cloud.securitycenter.v1;
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.ArrayList;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Objects;
29 import javax.annotation.Generated;
30 
31 // AUTO-GENERATED DOCUMENTATION AND CLASS.
32 @Generated("by gapic-generator-java")
33 public class NotificationConfigName implements ResourceName {
34   private static final PathTemplate ORGANIZATION_NOTIFICATION_CONFIG =
35       PathTemplate.createWithoutUrlEncoding(
36           "organizations/{organization}/notificationConfigs/{notification_config}");
37   private static final PathTemplate FOLDER_NOTIFICATION_CONFIG =
38       PathTemplate.createWithoutUrlEncoding(
39           "folders/{folder}/notificationConfigs/{notification_config}");
40   private static final PathTemplate PROJECT_NOTIFICATION_CONFIG =
41       PathTemplate.createWithoutUrlEncoding(
42           "projects/{project}/notificationConfigs/{notification_config}");
43   private volatile Map<String, String> fieldValuesMap;
44   private PathTemplate pathTemplate;
45   private String fixedValue;
46   private final String organization;
47   private final String notificationConfig;
48   private final String folder;
49   private final String project;
50 
51   @Deprecated
NotificationConfigName()52   protected NotificationConfigName() {
53     organization = null;
54     notificationConfig = null;
55     folder = null;
56     project = null;
57   }
58 
NotificationConfigName(Builder builder)59   private NotificationConfigName(Builder builder) {
60     organization = Preconditions.checkNotNull(builder.getOrganization());
61     notificationConfig = Preconditions.checkNotNull(builder.getNotificationConfig());
62     folder = null;
63     project = null;
64     pathTemplate = ORGANIZATION_NOTIFICATION_CONFIG;
65   }
66 
NotificationConfigName(FolderNotificationConfigBuilder builder)67   private NotificationConfigName(FolderNotificationConfigBuilder builder) {
68     folder = Preconditions.checkNotNull(builder.getFolder());
69     notificationConfig = Preconditions.checkNotNull(builder.getNotificationConfig());
70     organization = null;
71     project = null;
72     pathTemplate = FOLDER_NOTIFICATION_CONFIG;
73   }
74 
NotificationConfigName(ProjectNotificationConfigBuilder builder)75   private NotificationConfigName(ProjectNotificationConfigBuilder builder) {
76     project = Preconditions.checkNotNull(builder.getProject());
77     notificationConfig = Preconditions.checkNotNull(builder.getNotificationConfig());
78     organization = null;
79     folder = null;
80     pathTemplate = PROJECT_NOTIFICATION_CONFIG;
81   }
82 
getOrganization()83   public String getOrganization() {
84     return organization;
85   }
86 
getNotificationConfig()87   public String getNotificationConfig() {
88     return notificationConfig;
89   }
90 
getFolder()91   public String getFolder() {
92     return folder;
93   }
94 
getProject()95   public String getProject() {
96     return project;
97   }
98 
newBuilder()99   public static Builder newBuilder() {
100     return new Builder();
101   }
102 
103   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
newOrganizationNotificationConfigBuilder()104   public static Builder newOrganizationNotificationConfigBuilder() {
105     return new Builder();
106   }
107 
108   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
newFolderNotificationConfigBuilder()109   public static FolderNotificationConfigBuilder newFolderNotificationConfigBuilder() {
110     return new FolderNotificationConfigBuilder();
111   }
112 
113   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
newProjectNotificationConfigBuilder()114   public static ProjectNotificationConfigBuilder newProjectNotificationConfigBuilder() {
115     return new ProjectNotificationConfigBuilder();
116   }
117 
toBuilder()118   public Builder toBuilder() {
119     return new Builder(this);
120   }
121 
of(String organization, String notificationConfig)122   public static NotificationConfigName of(String organization, String notificationConfig) {
123     return newBuilder()
124         .setOrganization(organization)
125         .setNotificationConfig(notificationConfig)
126         .build();
127   }
128 
129   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofOrganizationNotificationConfigName( String organization, String notificationConfig)130   public static NotificationConfigName ofOrganizationNotificationConfigName(
131       String organization, String notificationConfig) {
132     return newBuilder()
133         .setOrganization(organization)
134         .setNotificationConfig(notificationConfig)
135         .build();
136   }
137 
138   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofFolderNotificationConfigName( String folder, String notificationConfig)139   public static NotificationConfigName ofFolderNotificationConfigName(
140       String folder, String notificationConfig) {
141     return newFolderNotificationConfigBuilder()
142         .setFolder(folder)
143         .setNotificationConfig(notificationConfig)
144         .build();
145   }
146 
147   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofProjectNotificationConfigName( String project, String notificationConfig)148   public static NotificationConfigName ofProjectNotificationConfigName(
149       String project, String notificationConfig) {
150     return newProjectNotificationConfigBuilder()
151         .setProject(project)
152         .setNotificationConfig(notificationConfig)
153         .build();
154   }
155 
format(String organization, String notificationConfig)156   public static String format(String organization, String notificationConfig) {
157     return newBuilder()
158         .setOrganization(organization)
159         .setNotificationConfig(notificationConfig)
160         .build()
161         .toString();
162   }
163 
164   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatOrganizationNotificationConfigName( String organization, String notificationConfig)165   public static String formatOrganizationNotificationConfigName(
166       String organization, String notificationConfig) {
167     return newBuilder()
168         .setOrganization(organization)
169         .setNotificationConfig(notificationConfig)
170         .build()
171         .toString();
172   }
173 
174   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatFolderNotificationConfigName( String folder, String notificationConfig)175   public static String formatFolderNotificationConfigName(
176       String folder, String notificationConfig) {
177     return newFolderNotificationConfigBuilder()
178         .setFolder(folder)
179         .setNotificationConfig(notificationConfig)
180         .build()
181         .toString();
182   }
183 
184   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatProjectNotificationConfigName( String project, String notificationConfig)185   public static String formatProjectNotificationConfigName(
186       String project, String notificationConfig) {
187     return newProjectNotificationConfigBuilder()
188         .setProject(project)
189         .setNotificationConfig(notificationConfig)
190         .build()
191         .toString();
192   }
193 
parse(String formattedString)194   public static NotificationConfigName parse(String formattedString) {
195     if (formattedString.isEmpty()) {
196       return null;
197     }
198     if (ORGANIZATION_NOTIFICATION_CONFIG.matches(formattedString)) {
199       Map<String, String> matchMap = ORGANIZATION_NOTIFICATION_CONFIG.match(formattedString);
200       return ofOrganizationNotificationConfigName(
201           matchMap.get("organization"), matchMap.get("notification_config"));
202     } else if (FOLDER_NOTIFICATION_CONFIG.matches(formattedString)) {
203       Map<String, String> matchMap = FOLDER_NOTIFICATION_CONFIG.match(formattedString);
204       return ofFolderNotificationConfigName(
205           matchMap.get("folder"), matchMap.get("notification_config"));
206     } else if (PROJECT_NOTIFICATION_CONFIG.matches(formattedString)) {
207       Map<String, String> matchMap = PROJECT_NOTIFICATION_CONFIG.match(formattedString);
208       return ofProjectNotificationConfigName(
209           matchMap.get("project"), matchMap.get("notification_config"));
210     }
211     throw new ValidationException(
212         "NotificationConfigName.parse: formattedString not in valid format");
213   }
214 
parseList(List<String> formattedStrings)215   public static List<NotificationConfigName> parseList(List<String> formattedStrings) {
216     List<NotificationConfigName> list = new ArrayList<>(formattedStrings.size());
217     for (String formattedString : formattedStrings) {
218       list.add(parse(formattedString));
219     }
220     return list;
221   }
222 
toStringList(List<NotificationConfigName> values)223   public static List<String> toStringList(List<NotificationConfigName> values) {
224     List<String> list = new ArrayList<>(values.size());
225     for (NotificationConfigName value : values) {
226       if (value == null) {
227         list.add("");
228       } else {
229         list.add(value.toString());
230       }
231     }
232     return list;
233   }
234 
isParsableFrom(String formattedString)235   public static boolean isParsableFrom(String formattedString) {
236     return ORGANIZATION_NOTIFICATION_CONFIG.matches(formattedString)
237         || FOLDER_NOTIFICATION_CONFIG.matches(formattedString)
238         || PROJECT_NOTIFICATION_CONFIG.matches(formattedString);
239   }
240 
241   @Override
getFieldValuesMap()242   public Map<String, String> getFieldValuesMap() {
243     if (fieldValuesMap == null) {
244       synchronized (this) {
245         if (fieldValuesMap == null) {
246           ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
247           if (organization != null) {
248             fieldMapBuilder.put("organization", organization);
249           }
250           if (notificationConfig != null) {
251             fieldMapBuilder.put("notification_config", notificationConfig);
252           }
253           if (folder != null) {
254             fieldMapBuilder.put("folder", folder);
255           }
256           if (project != null) {
257             fieldMapBuilder.put("project", project);
258           }
259           fieldValuesMap = fieldMapBuilder.build();
260         }
261       }
262     }
263     return fieldValuesMap;
264   }
265 
getFieldValue(String fieldName)266   public String getFieldValue(String fieldName) {
267     return getFieldValuesMap().get(fieldName);
268   }
269 
270   @Override
toString()271   public String toString() {
272     return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap());
273   }
274 
275   @Override
equals(Object o)276   public boolean equals(Object o) {
277     if (o == this) {
278       return true;
279     }
280     if (o != null || getClass() == o.getClass()) {
281       NotificationConfigName that = ((NotificationConfigName) o);
282       return Objects.equals(this.organization, that.organization)
283           && Objects.equals(this.notificationConfig, that.notificationConfig)
284           && Objects.equals(this.folder, that.folder)
285           && Objects.equals(this.project, that.project);
286     }
287     return false;
288   }
289 
290   @Override
hashCode()291   public int hashCode() {
292     int h = 1;
293     h *= 1000003;
294     h ^= Objects.hashCode(fixedValue);
295     h *= 1000003;
296     h ^= Objects.hashCode(organization);
297     h *= 1000003;
298     h ^= Objects.hashCode(notificationConfig);
299     h *= 1000003;
300     h ^= Objects.hashCode(folder);
301     h *= 1000003;
302     h ^= Objects.hashCode(project);
303     return h;
304   }
305 
306   /** Builder for organizations/{organization}/notificationConfigs/{notification_config}. */
307   public static class Builder {
308     private String organization;
309     private String notificationConfig;
310 
Builder()311     protected Builder() {}
312 
getOrganization()313     public String getOrganization() {
314       return organization;
315     }
316 
getNotificationConfig()317     public String getNotificationConfig() {
318       return notificationConfig;
319     }
320 
setOrganization(String organization)321     public Builder setOrganization(String organization) {
322       this.organization = organization;
323       return this;
324     }
325 
setNotificationConfig(String notificationConfig)326     public Builder setNotificationConfig(String notificationConfig) {
327       this.notificationConfig = notificationConfig;
328       return this;
329     }
330 
Builder(NotificationConfigName notificationConfigName)331     private Builder(NotificationConfigName notificationConfigName) {
332       Preconditions.checkArgument(
333           Objects.equals(notificationConfigName.pathTemplate, ORGANIZATION_NOTIFICATION_CONFIG),
334           "toBuilder is only supported when NotificationConfigName has the pattern of organizations/{organization}/notificationConfigs/{notification_config}");
335       this.organization = notificationConfigName.organization;
336       this.notificationConfig = notificationConfigName.notificationConfig;
337     }
338 
build()339     public NotificationConfigName build() {
340       return new NotificationConfigName(this);
341     }
342   }
343 
344   /** Builder for folders/{folder}/notificationConfigs/{notification_config}. */
345   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
346   public static class FolderNotificationConfigBuilder {
347     private String folder;
348     private String notificationConfig;
349 
FolderNotificationConfigBuilder()350     protected FolderNotificationConfigBuilder() {}
351 
getFolder()352     public String getFolder() {
353       return folder;
354     }
355 
getNotificationConfig()356     public String getNotificationConfig() {
357       return notificationConfig;
358     }
359 
setFolder(String folder)360     public FolderNotificationConfigBuilder setFolder(String folder) {
361       this.folder = folder;
362       return this;
363     }
364 
setNotificationConfig(String notificationConfig)365     public FolderNotificationConfigBuilder setNotificationConfig(String notificationConfig) {
366       this.notificationConfig = notificationConfig;
367       return this;
368     }
369 
build()370     public NotificationConfigName build() {
371       return new NotificationConfigName(this);
372     }
373   }
374 
375   /** Builder for projects/{project}/notificationConfigs/{notification_config}. */
376   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
377   public static class ProjectNotificationConfigBuilder {
378     private String project;
379     private String notificationConfig;
380 
ProjectNotificationConfigBuilder()381     protected ProjectNotificationConfigBuilder() {}
382 
getProject()383     public String getProject() {
384       return project;
385     }
386 
getNotificationConfig()387     public String getNotificationConfig() {
388       return notificationConfig;
389     }
390 
setProject(String project)391     public ProjectNotificationConfigBuilder setProject(String project) {
392       this.project = project;
393       return this;
394     }
395 
setNotificationConfig(String notificationConfig)396     public ProjectNotificationConfigBuilder setNotificationConfig(String notificationConfig) {
397       this.notificationConfig = notificationConfig;
398       return this;
399     }
400 
build()401     public NotificationConfigName build() {
402       return new NotificationConfigName(this);
403     }
404   }
405 }
406