/* * 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 *

* Single metadata entry (key/value/mandatory) attached to an {@link Application}. * Uses a composite PK: (application_id, key). *

* 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

* Get the metadata key (PK part). * * @return key */ public String getKey() { return key; } /** * setKey

* Set the metadata key (PK part). * * @param key */ public void setKey(String key) { this.key = key; } /** * getApplication

* Get the owning application. * * @return application */ public Application getApplication() { LOG.info("Getting application from app metadata: {}", application); return application; } /** * setApplication

* Set the owning application (PK part). * * @param application */ public void setApplication(Application application) { this.application = application; } /** * getCreationTimestamp

* Get the creation timestamp. * * @return creationTimestamp */ public Date getCreationTimestamp() { return creationTimestamp; } /** * setCreationTimestamp

* Set the creation timestamp. * * @param creationTimestamp */ public void setCreationTimestamp(Date creationTimestamp) { this.creationTimestamp = creationTimestamp; } /** * getValue

* Get the metadata value. * * @return value */ public String getValue() { return value; } /** * setValue

* Set the metadata value. * * @param value */ public void setValue(String value) { this.value = value; } /** * isMandatory

* Whether this entry is required. * * @return mandatory */ public boolean isMandatory() { return mandatory; } /** * setMandatory

* Mark this entry as required or optional. * * @param mandatory */ public void setMandatory(boolean mandatory) { this.mandatory = mandatory; } // --------------------------------------------------------------------- // Object methods // --------------------------------------------------------------------- /** * toString

* Get the string describing the current object * * @return object string */ @Override public String toString() { return String.format("AppMd (%s: %s)", this.key, value); } /** * equals

* 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

* Get the object hashCode * * @return hashCode */ @Override public int hashCode() { return Objects.hash(key, application); } }