View Javadoc
1   /*
2    * Copyright (c) 2022-2023. Roland T. Lichti, Kaiserpfalz EDV-Service.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16   */
17  
18  package de.kaiserpfalzedv.commons.core.resources;
19  
20  import org.eclipse.microprofile.openapi.annotations.media.Schema;
21  
22  import com.fasterxml.jackson.annotation.JsonInclude;
23  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
24  
25  import de.kaiserpfalzedv.commons.api.resources.HasApiVersion;
26  import de.kaiserpfalzedv.commons.api.resources.HasName;
27  import de.kaiserpfalzedv.commons.api.resources.Pointer;
28  import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
29  import jakarta.validation.constraints.NotNull;
30  import jakarta.validation.constraints.Pattern;
31  import jakarta.validation.constraints.Size;
32  import lombok.AllArgsConstructor;
33  import lombok.Builder;
34  import lombok.EqualsAndHashCode;
35  import lombok.Getter;
36  import lombok.NoArgsConstructor;
37  import lombok.ToString;
38  import lombok.experimental.SuperBuilder;
39  import lombok.extern.jackson.Jacksonized;
40  
41  /**
42   * Pointer -- A single resource definition pointing to a unique resource on the server.
43   *
44   * @author klenkes74 {@literal <rlichti@kaiserpfalz-edv.de>}
45   * @since 2.0.0  2021-05-24
46   */
47  @Jacksonized
48  @SuperBuilder(toBuilder = true)
49  @AllArgsConstructor
50  @NoArgsConstructor
51  @Getter
52  @ToString(onlyExplicitlyIncluded = true)
53  @EqualsAndHashCode(onlyExplicitlyIncluded = true)
54  @JsonInclude(JsonInclude.Include.NON_ABSENT)
55  @JsonPropertyOrder({"kind", "apiVersion", "namespace", "name", "selfLink"})
56  @Schema(
57          description = "A full pointer to a resource.",
58          example = """
59                  {
60                      "kind": "Resource",
61                      "apiVersion": "v1",
62                      "nameSpace": "namespace",
63                      "name": "name",
64                      "selfLink": "/api/v1/Resource/namespace/name"
65                  }"""
66  )
67  public class PointerImpl implements Pointer {
68      /** serial class version */
69      private static final long serialVersionUID = 0L;
70  
71      @Schema(
72              name = "kind",
73              description = "The type of the resource",
74              required = true,
75              example = HasName.VALID_NAME_EXAMPLE,
76              pattern = HasName.VALID_NAME_PATTERN,
77              minLength = HasName.VALID_NAME_MIN_LENGTH,
78              maxLength = HasName.VALID_NAME_MAX_LENGTH
79      )
80      @ToString.Include
81      @EqualsAndHashCode.Include
82      @NotNull
83      @Size(min = HasName.VALID_NAME_MIN_LENGTH, max = HasName.VALID_NAME_MAX_LENGTH, message = HasName.VALID_NAME_LENGTH_MSG)
84      @Pattern(regexp = HasName.VALID_NAME_PATTERN, message = HasName.VALID_NAME_PATTERN_MSG)
85      private String kind;
86  
87      @Schema(
88              name = "apiVersion",
89              description = "The version of this resource",
90              required = true,
91              example = HasApiVersion.VALID_VERSION_EXAMPLE,
92              defaultValue = HasApiVersion.VALID_VERSION_EXAMPLE,
93              minLength = HasApiVersion.VALID_VERSION_MIN_LENGTH,
94              maxLength = HasApiVersion.VALID_VERSION_MAX_LENGTH
95      )
96      @Builder.Default
97      @Size(min = HasApiVersion.VALID_VERSION_MIN_LENGTH, max = HasApiVersion.VALID_VERSION_MAX_LENGTH, message = HasApiVersion.VALID_VERSION_LENGTH_MSG)
98      @Pattern(regexp = HasApiVersion.VALID_VERSION_PATTERN, message = HasApiVersion.VALID_VERSION_PATTERN_MSG)
99      private String apiVersion = HasApiVersion.VALID_VERSION_EXAMPLE;
100 
101     @Schema(
102             name = "nameSpace",
103             description = "The namespace (group) of this resource",
104             required = true,
105             example = HasName.VALID_NAME_EXAMPLE,
106             pattern = HasName.VALID_NAME_PATTERN,
107             minLength = HasName.VALID_NAME_MIN_LENGTH,
108             maxLength = HasName.VALID_NAME_MAX_LENGTH
109     )
110     @ToString.Include
111     @EqualsAndHashCode.Include
112     @NotNull
113     @Size(min = HasName.VALID_NAME_MIN_LENGTH, max = HasName.VALID_NAME_MAX_LENGTH, message = HasName.VALID_NAME_LENGTH_MSG)
114     @Pattern(regexp = HasName.VALID_NAME_PATTERN, message = HasName.VALID_NAME_PATTERN_MSG)
115     private String nameSpace;
116 
117     @Schema(
118             name = "name",
119             description = "The unique name of this resource within the namespace",
120             required = true,
121             example = HasName.VALID_NAME_EXAMPLE,
122             minLength = HasName.VALID_NAME_MIN_LENGTH,
123             maxLength = HasName.VALID_NAME_MAX_LENGTH
124     )
125     @ToString.Include
126     @EqualsAndHashCode.Include
127     @Size(min = HasName.VALID_NAME_MIN_LENGTH, max = HasName.VALID_NAME_MAX_LENGTH, message = HasName.VALID_NAME_LENGTH_MSG)
128     @Pattern(regexp = HasName.VALID_NAME_PATTERN, message = HasName.VALID_NAME_PATTERN_MSG)
129     private String name;
130 
131 
132     @SuppressWarnings("MethodDoesntCallSuperMethod")
133     @SuppressFBWarnings(value = "CN_IDIOM_NO_SUPER_CALL", justification = "Using the lombok builder.")
134     @Override
135     public PointerImpl clone() {
136         return this.toBuilder().build();
137     }
138 }