| .. | .. |
|---|
| 1 | +/* |
|---|
| 2 | +* Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved. |
|---|
| 3 | +*/ |
|---|
| 1 | 4 | package net.curisit.securis.db; |
|---|
| 2 | 5 | |
|---|
| 3 | 6 | import java.io.Serializable; |
|---|
| .. | .. |
|---|
| 26 | 29 | import net.curisit.securis.db.common.Metadata; |
|---|
| 27 | 30 | |
|---|
| 28 | 31 | /** |
|---|
| 29 | | - * Entity implementation class for Entity: application_metadata |
|---|
| 30 | | - * |
|---|
| 31 | | - */ |
|---|
| 32 | +* ApplicationMetadata |
|---|
| 33 | +* <p> |
|---|
| 34 | +* Single metadata entry (key/value/mandatory) attached to an {@link Application}. |
|---|
| 35 | +* Uses a composite PK: (application_id, key). |
|---|
| 36 | +* <p> |
|---|
| 37 | +* Mapping details: |
|---|
| 38 | +* - Table: application_metadata |
|---|
| 39 | +* - PK: application_id + key (two @Id fields). |
|---|
| 40 | +* - application: @ManyToOne with @JsonBackReference to avoid JSON cycles. |
|---|
| 41 | +* - creation_timestamp exposed as "creation_timestamp". |
|---|
| 42 | +* |
|---|
| 43 | +* @author JRA |
|---|
| 44 | +* Last reviewed by JRA on Oct 7, 2025. |
|---|
| 45 | +*/ |
|---|
| 32 | 46 | @JsonAutoDetect |
|---|
| 33 | 47 | @JsonInclude(Include.NON_NULL) |
|---|
| 34 | 48 | @Entity |
|---|
| 35 | 49 | @Table(name = "application_metadata") |
|---|
| 36 | 50 | @JsonIgnoreProperties(ignoreUnknown = true) |
|---|
| 37 | | -@NamedQueries({ @NamedQuery(name = "list-application-metadata", query = "SELECT a FROM ApplicationMetadata a where a.application.id = :applicationId") }) |
|---|
| 51 | +@NamedQueries({ |
|---|
| 52 | + @NamedQuery(name = "list-application-metadata", |
|---|
| 53 | + query = "SELECT a FROM ApplicationMetadata a where a.application.id = :applicationId") |
|---|
| 54 | +}) |
|---|
| 38 | 55 | public class ApplicationMetadata implements Serializable, Metadata { |
|---|
| 39 | 56 | |
|---|
| 40 | | - private static final Logger LOG = LogManager.getLogger(ApplicationMetadata.class); |
|---|
| 57 | + private static final Logger LOG = LogManager.getLogger(ApplicationMetadata.class); |
|---|
| 41 | 58 | |
|---|
| 42 | | - private static final long serialVersionUID = 1L; |
|---|
| 59 | + private static final long serialVersionUID = 1L; |
|---|
| 43 | 60 | |
|---|
| 44 | | - @Id |
|---|
| 45 | | - @ManyToOne |
|---|
| 46 | | - @JoinColumn(name = "application_id") |
|---|
| 47 | | - @JsonBackReference |
|---|
| 48 | | - private Application application; |
|---|
| 61 | + /** Part of PK: owning application. */ |
|---|
| 62 | + @Id |
|---|
| 63 | + @ManyToOne |
|---|
| 64 | + @JoinColumn(name = "application_id") |
|---|
| 65 | + @JsonBackReference |
|---|
| 66 | + private Application application; |
|---|
| 49 | 67 | |
|---|
| 50 | | - @Id |
|---|
| 51 | | - @Column(name = "\"key\"") |
|---|
| 52 | | - private String key; |
|---|
| 68 | + /** Part of PK: metadata key (quoted column name). */ |
|---|
| 69 | + @Id |
|---|
| 70 | + @Column(name = "\"key\"") |
|---|
| 71 | + private String key; |
|---|
| 53 | 72 | |
|---|
| 54 | | - private String value; |
|---|
| 73 | + /** Arbitrary metadata value. */ |
|---|
| 74 | + private String value; |
|---|
| 55 | 75 | |
|---|
| 56 | | - private boolean mandatory; |
|---|
| 76 | + /** Whether this key is required for the parent application. */ |
|---|
| 77 | + private boolean mandatory; |
|---|
| 57 | 78 | |
|---|
| 58 | | - @Column(name = "creation_timestamp") |
|---|
| 59 | | - @JsonProperty("creation_timestamp") |
|---|
| 60 | | - private Date creationTimestamp; |
|---|
| 79 | + /** Server-side creation timestamp. */ |
|---|
| 80 | + @Column(name = "creation_timestamp") |
|---|
| 81 | + @JsonProperty("creation_timestamp") |
|---|
| 82 | + private Date creationTimestamp; |
|---|
| 61 | 83 | |
|---|
| 62 | | - public String getKey() { |
|---|
| 63 | | - return key; |
|---|
| 64 | | - } |
|---|
| 84 | + // --------------------------------------------------------------------- |
|---|
| 85 | + // Getters & setters |
|---|
| 86 | + // --------------------------------------------------------------------- |
|---|
| 65 | 87 | |
|---|
| 66 | | - public void setKey(String key) { |
|---|
| 67 | | - this.key = key; |
|---|
| 68 | | - } |
|---|
| 88 | + /** |
|---|
| 89 | + * getKey<p> |
|---|
| 90 | + * Get the metadata key (PK part). |
|---|
| 91 | + * |
|---|
| 92 | + * @return key |
|---|
| 93 | + */ |
|---|
| 94 | + public String getKey() { return key; } |
|---|
| 69 | 95 | |
|---|
| 70 | | - public Application getApplication() { |
|---|
| 71 | | - LOG.info("Getting application from app metadata: {}", application); |
|---|
| 72 | | - return application; |
|---|
| 73 | | - } |
|---|
| 96 | + /** |
|---|
| 97 | + * setKey<p> |
|---|
| 98 | + * Set the metadata key (PK part). |
|---|
| 99 | + * |
|---|
| 100 | + * @param key |
|---|
| 101 | + */ |
|---|
| 102 | + public void setKey(String key) { this.key = key; } |
|---|
| 74 | 103 | |
|---|
| 75 | | - public void setApplication(Application application) { |
|---|
| 76 | | - this.application = application; |
|---|
| 77 | | - } |
|---|
| 104 | + /** |
|---|
| 105 | + * getApplication<p> |
|---|
| 106 | + * Get the owning application. |
|---|
| 107 | + * |
|---|
| 108 | + * @return application |
|---|
| 109 | + */ |
|---|
| 110 | + public Application getApplication() { |
|---|
| 111 | + LOG.info("Getting application from app metadata: {}", application); |
|---|
| 112 | + return application; |
|---|
| 113 | + } |
|---|
| 78 | 114 | |
|---|
| 79 | | - public Date getCreationTimestamp() { |
|---|
| 80 | | - return creationTimestamp; |
|---|
| 81 | | - } |
|---|
| 115 | + /** |
|---|
| 116 | + * setApplication<p> |
|---|
| 117 | + * Set the owning application (PK part). |
|---|
| 118 | + * |
|---|
| 119 | + * @param application |
|---|
| 120 | + */ |
|---|
| 121 | + public void setApplication(Application application) { this.application = application; } |
|---|
| 82 | 122 | |
|---|
| 83 | | - public void setCreationTimestamp(Date creationTimestamp) { |
|---|
| 84 | | - this.creationTimestamp = creationTimestamp; |
|---|
| 85 | | - } |
|---|
| 123 | + /** |
|---|
| 124 | + * getCreationTimestamp<p> |
|---|
| 125 | + * Get the creation timestamp. |
|---|
| 126 | + * |
|---|
| 127 | + * @return creationTimestamp |
|---|
| 128 | + */ |
|---|
| 129 | + public Date getCreationTimestamp() { return creationTimestamp; } |
|---|
| 86 | 130 | |
|---|
| 87 | | - public String getValue() { |
|---|
| 88 | | - return value; |
|---|
| 89 | | - } |
|---|
| 131 | + /** |
|---|
| 132 | + * setCreationTimestamp<p> |
|---|
| 133 | + * Set the creation timestamp. |
|---|
| 134 | + * |
|---|
| 135 | + * @param creationTimestamp |
|---|
| 136 | + */ |
|---|
| 137 | + public void setCreationTimestamp(Date creationTimestamp) { this.creationTimestamp = creationTimestamp; } |
|---|
| 90 | 138 | |
|---|
| 91 | | - public void setValue(String value) { |
|---|
| 92 | | - this.value = value; |
|---|
| 93 | | - } |
|---|
| 139 | + /** |
|---|
| 140 | + * getValue<p> |
|---|
| 141 | + * Get the metadata value. |
|---|
| 142 | + * |
|---|
| 143 | + * @return value |
|---|
| 144 | + */ |
|---|
| 145 | + public String getValue() { return value; } |
|---|
| 94 | 146 | |
|---|
| 95 | | - public boolean isMandatory() { |
|---|
| 96 | | - return mandatory; |
|---|
| 97 | | - } |
|---|
| 147 | + /** |
|---|
| 148 | + * setValue<p> |
|---|
| 149 | + * Set the metadata value. |
|---|
| 150 | + * |
|---|
| 151 | + * @param value |
|---|
| 152 | + */ |
|---|
| 153 | + public void setValue(String value) { this.value = value; } |
|---|
| 98 | 154 | |
|---|
| 99 | | - public void setMandatory(boolean mandatory) { |
|---|
| 100 | | - this.mandatory = mandatory; |
|---|
| 101 | | - } |
|---|
| 155 | + /** |
|---|
| 156 | + * isMandatory<p> |
|---|
| 157 | + * Whether this entry is required. |
|---|
| 158 | + * |
|---|
| 159 | + * @return mandatory |
|---|
| 160 | + */ |
|---|
| 161 | + public boolean isMandatory() { return mandatory; } |
|---|
| 102 | 162 | |
|---|
| 103 | | - @Override |
|---|
| 104 | | - public String toString() { |
|---|
| 163 | + /** |
|---|
| 164 | + * setMandatory<p> |
|---|
| 165 | + * Mark this entry as required or optional. |
|---|
| 166 | + * |
|---|
| 167 | + * @param mandatory |
|---|
| 168 | + */ |
|---|
| 169 | + public void setMandatory(boolean mandatory) { this.mandatory = mandatory; } |
|---|
| 105 | 170 | |
|---|
| 106 | | - return String.format("AppMd (%s: %s)", this.key, value); |
|---|
| 107 | | - } |
|---|
| 171 | + // --------------------------------------------------------------------- |
|---|
| 172 | + // Object methods |
|---|
| 173 | + // --------------------------------------------------------------------- |
|---|
| 108 | 174 | |
|---|
| 109 | | - @Override |
|---|
| 110 | | - public boolean equals(Object obj) { |
|---|
| 111 | | - if (!(obj instanceof ApplicationMetadata)) |
|---|
| 112 | | - return false; |
|---|
| 113 | | - ApplicationMetadata other = (ApplicationMetadata) obj; |
|---|
| 114 | | - return Objects.equals(key, other.key) && Objects.equals(application, other.application); |
|---|
| 115 | | - } |
|---|
| 175 | + /** |
|---|
| 176 | + * toString<p> |
|---|
| 177 | + * Get the string describing the current object |
|---|
| 178 | + * |
|---|
| 179 | + * @return object string |
|---|
| 180 | + */ |
|---|
| 181 | + @Override |
|---|
| 182 | + public String toString() { return String.format("AppMd (%s: %s)", this.key, value); } |
|---|
| 116 | 183 | |
|---|
| 117 | | - @Override |
|---|
| 118 | | - public int hashCode() { |
|---|
| 119 | | - return Objects.hash(key, application); |
|---|
| 120 | | - } |
|---|
| 184 | + /** |
|---|
| 185 | + * equals<p> |
|---|
| 186 | + * Compare the current object with the given object |
|---|
| 187 | + * |
|---|
| 188 | + * @param object |
|---|
| 189 | + * @return isEquals |
|---|
| 190 | + */ |
|---|
| 191 | + @Override |
|---|
| 192 | + public boolean equals(Object obj) { |
|---|
| 193 | + if (!(obj instanceof ApplicationMetadata)) return false; |
|---|
| 194 | + ApplicationMetadata other = (ApplicationMetadata) obj; |
|---|
| 195 | + return Objects.equals(key, other.key) && Objects.equals(application, other.application); |
|---|
| 196 | + } |
|---|
| 121 | 197 | |
|---|
| 198 | + /** |
|---|
| 199 | + * hashCode<p> |
|---|
| 200 | + * Get the object hashCode |
|---|
| 201 | + * |
|---|
| 202 | + * @return hashCode |
|---|
| 203 | + */ |
|---|
| 204 | + @Override |
|---|
| 205 | + public int hashCode() { return Objects.hash(key, application); } |
|---|
| 122 | 206 | } |
|---|
| 207 | + |
|---|