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