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

* 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

* Expose pack id as JSON scalar. * * @return packId */ @JsonProperty("pack_id") public Integer getPackId() { return pack == null ? null : pack.getId(); } /** * setLicenseTypeId

* 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

* Return owning pack (entity). * * @return pack */ public Pack getPack() { return pack; } /** * setPack

* Set owning pack (entity). * * @param pack */ public void setPack(Pack pack) { this.pack = pack; } /** * getValue

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

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

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

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

* Return read-only flag. * * @return isReadonly */ public boolean isReadonly() { return readonly; } /** * setReadonly

* Set read-only flag. * * @param readonly */ public void setReadonly(boolean readonly) { this.readonly = readonly; } /** * isMandatory

* Return mandatory flag. * * @return isMandatory */ public boolean isMandatory() { return mandatory; } /** * setMandatory

* Set mandatory flag. * * @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("PackMD (%s: %s)", key, value); } /** * equals

* 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

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