Joaquín Reñé
2025-10-07 146a0fb8b0e90f9196e569152f649baf60d6cc8f
securis/src/main/java/net/curisit/securis/db/PackMetadata.java
....@@ -1,3 +1,6 @@
1
+/*
2
+* Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
3
+*/
14 package net.curisit.securis.db;
25
36 import java.io.Serializable;
....@@ -22,106 +25,201 @@
2225 import net.curisit.securis.db.common.Metadata;
2326
2427 /**
25
- * Entity implementation class for Entity: pack_metadata
26
- *
27
- */
28
+* PackMetadata
29
+* <p>
30
+* Single metadata entry (key/value/flags) attached to a {@link Pack}.
31
+* Uses composite PK: (pack_id, key).
32
+*
33
+* Mapping details:
34
+* - Table: pack_metadata
35
+* - PK: pack_id + key (two @Id fields)
36
+* - 'pack' is @JsonIgnore to reduce payload size in list views
37
+* - NamedQuery: list-pack-metadata by pack id
38
+*
39
+* Flags:
40
+* - readonly: UI hint to prevent edits
41
+* - mandatory: requires value on pack creation/updates
42
+*
43
+* @author JRA
44
+* Last reviewed by JRA on Oct 5, 2025.
45
+*/
2846 @JsonAutoDetect
2947 @JsonInclude(Include.NON_NULL)
3048 @Entity
3149 @Table(name = "pack_metadata")
3250 @JsonIgnoreProperties(ignoreUnknown = true)
33
-@NamedQueries({ @NamedQuery(name = "list-pack-metadata", query = "SELECT a FROM PackMetadata a where a.pack.id = :packId") })
51
+@NamedQueries({
52
+ @NamedQuery(name = "list-pack-metadata",
53
+ query = "SELECT a FROM PackMetadata a where a.pack.id = :packId")
54
+})
3455 public class PackMetadata implements Serializable, Metadata {
3556
36
- private static final long serialVersionUID = 1L;
57
+ private static final long serialVersionUID = 1L;
3758
38
- @Id
39
- @JsonIgnore
40
- @ManyToOne
41
- @JoinColumn(name = "pack_id")
42
- private Pack pack;
59
+ /** PK part: owning pack (ignored in JSON). */
60
+ @Id
61
+ @JsonIgnore
62
+ @ManyToOne
63
+ @JoinColumn(name = "pack_id")
64
+ private Pack pack;
4365
44
- @Id
45
- @Column(name = "\"key\"")
46
- private String key;
66
+ /** PK part: metadata key (quoted column name). */
67
+ @Id
68
+ @Column(name = "\"key\"")
69
+ private String key;
4770
48
- private String value;
71
+ /** Metadata value. */
72
+ private String value;
4973
50
- private boolean readonly;
74
+ /** Whether this field can be edited by clients. */
75
+ private boolean readonly;
5176
52
- private boolean mandatory;
77
+ /** Whether this field is required. */
78
+ private boolean mandatory;
5379
54
- @JsonProperty("pack_id")
55
- public Integer getPackId() {
56
- return pack == null ? null : pack.getId();
57
- }
80
+ // -------- JSON helpers to expose pack id --------
5881
59
- @JsonProperty("pack_id")
60
- public void setLicenseTypeId(Integer idPack) {
61
- if (idPack == null) {
62
- pack = null;
63
- } else {
64
- pack = new Pack();
65
- pack.setId(idPack);
66
- }
67
- }
82
+ /**
83
+ * getPackId<p>
84
+ * Expose pack id as JSON scalar.
85
+ *
86
+ * @return packId
87
+ */
88
+ @JsonProperty("pack_id")
89
+ public Integer getPackId() {
90
+ return pack == null ? null : pack.getId();
91
+ }
6892
69
- public Pack getPack() {
70
- return pack;
71
- }
93
+ /**
94
+ * setLicenseTypeId<p>
95
+ * Setter by id (creates shallow Pack).
96
+ *
97
+ * @param packId
98
+ */
99
+ @JsonProperty("pack_id")
100
+ public void setLicenseTypeId(Integer idPack) {
101
+ if (idPack == null) {
102
+ pack = null;
103
+ } else {
104
+ pack = new Pack();
105
+ pack.setId(idPack);
106
+ }
107
+ }
72108
73
- public void setPack(Pack pack) {
74
- this.pack = pack;
75
- }
109
+ // -------- Getters & setters --------
76110
77
- public String getValue() {
78
- return value;
79
- }
111
+ /**
112
+ * getPack<p>
113
+ * Return owning pack (entity).
114
+ *
115
+ * @return pack
116
+ */
117
+ public Pack getPack() { return pack; }
80118
81
- public void setValue(String value) {
82
- this.value = value;
83
- }
119
+ /**
120
+ * setPack<p>
121
+ * Set owning pack (entity).
122
+ *
123
+ * @param pack
124
+ */
125
+ public void setPack(Pack pack) { this.pack = pack; }
84126
85
- public String getKey() {
86
- return key;
87
- }
127
+ /**
128
+ * getValue<p>
129
+ * Return metadata value.
130
+ *
131
+ * @return metadataValue
132
+ */
133
+ public String getValue() { return value; }
88134
89
- public void setKey(String key) {
90
- this.key = key;
91
- }
135
+ /**
136
+ * setValue<p>
137
+ * Set the metadata value.
138
+ *
139
+ * @param metadataValue
140
+ */
141
+ public void setValue(String value) { this.value = value; }
92142
93
- public boolean isReadonly() {
94
- return readonly;
95
- }
143
+ /**
144
+ * getKey<p>
145
+ * Return metadata key (PK part).
146
+ *
147
+ * @return key
148
+ */
149
+ public String getKey() { return key; }
96150
97
- public void setReadonly(boolean readonly) {
98
- this.readonly = readonly;
99
- }
151
+ /**
152
+ * setKey<p>
153
+ * Set metadata key (PK part).
154
+ *
155
+ * @param key
156
+ */
157
+ public void setKey(String key) { this.key = key; }
100158
101
- public boolean isMandatory() {
102
- return mandatory;
103
- }
159
+ /**
160
+ * isReadonly<p>
161
+ * Return read-only flag.
162
+ *
163
+ * @return isReadonly
164
+ */
165
+ public boolean isReadonly() { return readonly; }
104166
105
- public void setMandatory(boolean mandatory) {
106
- this.mandatory = mandatory;
107
- }
167
+ /**
168
+ * setReadonly<p>
169
+ * Set read-only flag.
170
+ *
171
+ * @param readonly
172
+ */
173
+ public void setReadonly(boolean readonly) { this.readonly = readonly; }
108174
109
- @Override
110
- public String toString() {
111
- return String.format("PackMD (%s: %s)", key, value);
112
- }
175
+ /**
176
+ * isMandatory<p>
177
+ * Return mandatory flag.
178
+ *
179
+ * @return isMandatory
180
+ */
181
+ public boolean isMandatory() { return mandatory; }
113182
114
- @Override
115
- public boolean equals(Object obj) {
116
- if (!(obj instanceof PackMetadata))
117
- return false;
118
- PackMetadata other = (PackMetadata) obj;
119
- return Objects.equals(key, other.key) && Objects.equals(pack, other.pack);
120
- }
183
+ /**
184
+ * setMandatory<p>
185
+ * Set mandatory flag.
186
+ *
187
+ * @param mandatory
188
+ */
189
+ public void setMandatory(boolean mandatory) { this.mandatory = mandatory; }
121190
122
- @Override
123
- public int hashCode() {
124
- return Objects.hash(key, pack);
125
- }
191
+ // -------- Object methods --------
126192
193
+ /**
194
+ * toString<p>
195
+ * Get the string describing the current object
196
+ *
197
+ * @return object string
198
+ */
199
+ @Override
200
+ public String toString() { return String.format("PackMD (%s: %s)", key, value); }
201
+
202
+ /**
203
+ * equals<p>
204
+ * Compare the current object with the given object
205
+ *
206
+ * @param object
207
+ * @return isEquals
208
+ */
209
+ @Override
210
+ public boolean equals(Object obj) {
211
+ if (!(obj instanceof PackMetadata)) return false;
212
+ PackMetadata other = (PackMetadata) obj;
213
+ return Objects.equals(key, other.key) && Objects.equals(pack, other.pack);
214
+ }
215
+
216
+ /**
217
+ * hashCode<p>
218
+ * Get the object hashCode
219
+ *
220
+ * @return hashCode
221
+ */
222
+ @Override
223
+ public int hashCode() { return Objects.hash(key, pack); }
127224 }
225
+