1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.kaiserpfalzedv.commons.core.resources;
19
20 import java.util.Collection;
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.Map;
24 import java.util.StringJoiner;
25
26 import org.eclipse.microprofile.openapi.annotations.media.Schema;
27
28 import com.fasterxml.jackson.annotation.JsonIgnore;
29 import com.fasterxml.jackson.annotation.JsonInclude;
30
31 import de.kaiserpfalzedv.commons.api.resources.DefaultResourceSpec;
32 import de.kaiserpfalzedv.commons.api.resources.Pointer;
33 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
34 import lombok.AllArgsConstructor;
35 import lombok.Builder;
36 import lombok.EqualsAndHashCode;
37 import lombok.NoArgsConstructor;
38 import lombok.ToString;
39 import lombok.experimental.SuperBuilder;
40 import lombok.extern.jackson.Jacksonized;
41
42
43
44
45
46
47
48 @SuppressFBWarnings(value = "EI_EXPOSE_REF2", justification = "Use of lombok provided builder.")
49 @Jacksonized
50 @SuperBuilder(toBuilder = true)
51 @AllArgsConstructor
52 @NoArgsConstructor
53 @ToString(onlyExplicitlyIncluded = true)
54 @EqualsAndHashCode(onlyExplicitlyIncluded = true)
55 @JsonInclude(JsonInclude.Include.NON_ABSENT)
56 @Schema(name = "DefaultResourceSpec", description = "A standardized resource.")
57 public class DefaultResourceSpecImpl implements DefaultResourceSpec {
58
59 private static final long serialVersionUID = 0L;
60
61 @SuppressWarnings("FieldMayBeFinal")
62 @SuppressFBWarnings(value = "EI_EXPOSE_REF2", justification = "Use of lombok provided builder.")
63 @Schema(name = "properties", description = "A map of plugin properties for spec.")
64 @Builder.Default
65 @ToString.Include
66 @EqualsAndHashCode.Include
67 private Map<String, String> properties = new HashMap<>();
68
69 @Override
70 public Map<String, String> getProperties() {
71 return Collections.unmodifiableMap(this.properties);
72 }
73
74 @Override
75 @JsonIgnore
76 public Pointer convertStringToResourcePointer(final String property) {
77 final String[] data = property.split("/", 4);
78 if (data.length != 5) {
79 throw new IllegalStateException("Invalid property for resource pointers: " + property);
80 }
81
82 return PointerImpl.builder()
83 .kind(data[0])
84 .apiVersion(data[1])
85
86 .nameSpace(data[2])
87 .name(data[3])
88
89 .build();
90 }
91
92 @Override
93 @JsonIgnore
94 public void saveResourcePointers(final String key, final Collection<Pointer> pointers) {
95 if (pointers != null) {
96 final StringJoiner data = new StringJoiner(",");
97
98 pointers.forEach(p -> data.add(this.convertResourcePointerToString(p)));
99
100 this.properties.put(key, data.toString());
101 }
102 }
103
104 @SuppressWarnings("MethodDoesntCallSuperMethod")
105 @SuppressFBWarnings(value = "CN_IDIOM_NO_SUPER_CALL", justification = "We are using the lombok builder here.")
106 @Override
107 public DefaultResourceSpecImpl clone() {
108 return this.toBuilder().build();
109 }
110 }