1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.kaiserpfalzedv.commons.api.resources;
19
20 import java.io.Serializable;
21 import java.time.OffsetDateTime;
22 import java.util.Locale;
23 import java.util.Map;
24 import java.util.Optional;
25 import java.util.UUID;
26
27 import org.eclipse.microprofile.openapi.annotations.media.Schema;
28
29 import com.fasterxml.jackson.annotation.JsonIgnore;
30 import com.fasterxml.jackson.annotation.JsonProperty;
31
32 import jakarta.validation.constraints.NotNull;
33
34
35
36
37
38
39
40 public interface Metadata extends Serializable, Cloneable {
41
42
43
44 @Schema(
45 name = "selfLink",
46 description = "The local part of the URL to retrieve the resource.",
47 nullable = true,
48 readOnly = true,
49 example = "/api/resource/v1/default/name",
50 pattern = "/api/" + HasName.VALID_NAME_PATTERN
51 + "/" + HasApiVersion.VALID_VERSION_PATTERN
52 + "/" + HasName.VALID_NAME_PATTERN
53 + "/" + HasName.VALID_NAME_PATTERN,
54 minLength = 19,
55 maxLength = 318
56 )
57 @JsonProperty(value = "selfLink", access = JsonProperty.Access.READ_ONLY)
58 default String getSelfLink() {
59 return String.format("/api/%s/%s/%s/%s",
60 this.getKind().toLowerCase(Locale.getDefault()), this.getApiVersion().toLowerCase(Locale.getDefault()),
61 this.getNameSpace(), this.getName()
62 );
63 }
64
65 @JsonIgnore
66 Optional<OffsetDateTime> getDeletionTimestamp();
67
68 @JsonIgnore
69 Optional<Pointer> getOwningResource();
70
71
72
73
74
75
76
77 @JsonIgnore
78 default boolean isAnnotated(@NotNull final String name) {
79 return this.getAnnotations().containsKey(name);
80 }
81
82
83
84
85
86
87
88 @JsonIgnore
89 default Optional<String> getAnnotation(@NotNull final String name) {
90 return Optional.ofNullable(this.getAnnotations().get(name));
91 }
92
93
94
95
96
97
98
99 @JsonIgnore
100 default boolean isLabeled(final String name) {
101 return this.getLabels().containsKey(name);
102 }
103
104
105
106
107
108
109
110
111 @JsonIgnore
112 default Optional<String> getLabel(@NotNull final String name) {
113 return Optional.ofNullable(this.getLabels().get(name));
114 }
115
116 Metadata increaseGeneration();
117
118 @JsonIgnore
119 default String getKind() {
120 return this.getIdentity().getKind();
121 }
122
123 @JsonIgnore
124 default String getApiVersion() {
125 return this.getIdentity().getApiVersion();
126 }
127
128 @JsonIgnore
129 default String getNameSpace() {
130 return this.getIdentity().getNameSpace();
131 }
132
133 @JsonIgnore
134 default String getName() {
135 return this.getIdentity().getName();
136 }
137
138 Pointer getIdentity();
139
140 UUID getUid();
141
142 Integer getGeneration();
143
144 Pointer getOwner();
145
146 OffsetDateTime getCreated();
147
148 OffsetDateTime getModified();
149
150 OffsetDateTime getDeleted();
151
152 Map<String, String> getAnnotations();
153
154 Map<String, String> getLabels();
155 }