Joaquín Reñé
2026-03-27 4ee50e257b32f6ec0f72907305d1f2b1212808a4
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
/*
* Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
*/
package net.curisit.securis.db;
import java.io.Serializable;
import java.util.Date;
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 org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonBackReference;
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;
/**
* ApplicationMetadata
* <p>
* Single metadata entry (key/value/mandatory) attached to an {@link Application}.
* Uses a composite PK: (application_id, key).
* <p>
* Mapping details:
* - Table: application_metadata
* - PK: application_id + key (two @Id fields).
* - application: @ManyToOne with @JsonBackReference to avoid JSON cycles.
* - creation_timestamp exposed as "creation_timestamp".
*
* @author JRA
* Last reviewed by JRA on Oct 7, 2025.
*/
@JsonAutoDetect
@JsonInclude(Include.NON_NULL)
@Entity
@Table(name = "application_metadata")
@JsonIgnoreProperties(ignoreUnknown = true)
@NamedQueries({
    @NamedQuery(name = "list-application-metadata",
                query = "SELECT a FROM ApplicationMetadata a where a.application.id = :applicationId")
})
public class ApplicationMetadata implements Serializable, Metadata {
    private static final Logger LOG = LogManager.getLogger(ApplicationMetadata.class);
    private static final long serialVersionUID = 1L;
    /** Part of PK: owning application. */
    @Id
    @ManyToOne
    @JoinColumn(name = "application_id")
    @JsonBackReference
    private Application application;
    /** Part of PK: metadata key (quoted column name). */
    @Id
    @Column(name = "\"key\"")
    private String key;
    /** Arbitrary metadata value. */
    private String value;
    /** Whether this key is required for the parent application. */
    private boolean mandatory;
    /** Server-side creation timestamp. */
    @Column(name = "creation_timestamp")
    @JsonProperty("creation_timestamp")
    private Date creationTimestamp;
    // ---------------------------------------------------------------------
    // Getters & setters
    // ---------------------------------------------------------------------
    /**
    * getKey<p>
    * Get the metadata key (PK part).
    *
    * @return key
    */
    public String getKey() { return key; }
    /**
    * setKey<p>
    * Set the metadata key (PK part).
    *
    * @param key
    */
    public void setKey(String key) { this.key = key; }
    /**
    * getApplication<p>
    * Get the owning application.
    *
    * @return application
    */
    public Application getApplication() {
        LOG.info("Getting application from app metadata: {}", application);
        return application;
    }
    /**
    * setApplication<p>
    * Set the owning application (PK part).
    *
   * @param application
    */
    public void setApplication(Application application) { this.application = application; }
    /**
    * getCreationTimestamp<p>
    * Get the creation timestamp.
    *
    * @return creationTimestamp
    */
    public Date getCreationTimestamp() { return creationTimestamp; }
    /**
    * setCreationTimestamp<p>
    * Set the creation timestamp.
    *
    * @param creationTimestamp
    */
    public void setCreationTimestamp(Date creationTimestamp) { this.creationTimestamp = creationTimestamp; }
    /**
    * getValue<p>
    * Get the metadata value.
    *
    * @return value
    */
    public String getValue() { return value; }
    /**
    * setValue<p>
    * Set the metadata value.
    *
    * @param value
    */
    public void setValue(String value) { this.value = value; }
    /**
    * isMandatory<p>
    * Whether this entry is required.
    *
    * @return mandatory
    */
    public boolean isMandatory() { return mandatory; }
    /**
    * setMandatory<p>
    * Mark this entry as required or optional.
    *
    * @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("AppMd (%s: %s)", this.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 ApplicationMetadata)) return false;
        ApplicationMetadata other = (ApplicationMetadata) obj;
        return Objects.equals(key, other.key) && Objects.equals(application, other.application);
    }
    /**
     * hashCode<p>
     * Get the object hashCode
     * 
     * @return hashCode
     */
    @Override
    public int hashCode() { return Objects.hash(key, application); }
}