/* * 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.Set; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; import jakarta.persistence.ManyToMany; import jakarta.persistence.NamedQueries; import jakarta.persistence.NamedQuery; import jakarta.persistence.OneToMany; 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.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.JsonManagedReference; import com.fasterxml.jackson.annotation.JsonProperty; /** * Application *

* JPA entity that represents an application registered in the licensing server. * Includes descriptive fields and relationships to LicenseType, * ApplicationMetadata and User. * * Mapping details: *

*/ @JsonAutoDetect @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) @Entity @Table(name = "application") @NamedQueries({ @NamedQuery(name = "list-applications", query = "SELECT a FROM Application a"), @NamedQuery(name = "list-applications-by_ids", query = "SELECT a FROM Application a where id in :list_ids") }) public class Application implements Serializable { private static final Logger LOG = LogManager.getLogger(Application.class); private static final long serialVersionUID = 1L; // ------------------------------------------------------------------ // Columns // ------------------------------------------------------------------ /** Surrogate primary key. */ @Id @GeneratedValue private Integer id; /** Unique short code for the application (business identifier). */ private String code; /** Human-friendly application name. */ private String name; /** Optional description. */ private String description; /** Default license file name suggested for downloads/exports. */ @Column(name = "license_filename") @JsonProperty("license_filename") private String licenseFilename; /** Creation timestamp (server-side). */ @Column(name = "creation_timestamp") @JsonProperty("creation_timestamp") private Date creationTimestamp; // ----------------------- Relationships --------------------------- /** * License types attached to this application (ignored in default JSON to keep listings small). * * We don't include the referenced entities to limit the size of each row at the listing */ @JsonIgnore @OneToMany(fetch = FetchType.LAZY, mappedBy = "application") private Set licenseTypes; /** * Metadata key/value entries for this application. */ @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "application") @JsonManagedReference private Set metadata; /** * Users that have access/relationship with this application (ignored in JSON listings). */ @JsonIgnore // We don't include the users to limit the size of each row a the listing @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) @JoinTable(name = "user_application", // joinColumns = { @JoinColumn(name = "application_id", referencedColumnName = "id") }, // inverseJoinColumns = { @JoinColumn(name = "username", referencedColumnName = "username") }) private Set users; // ------------------------------------------------------------------ // Getters & setters // ------------------------------------------------------------------ /** * getId

* Return the primary key. * * @return id */ public Integer getId() { return id; } /** * setId

* Set the primary key * * @param id */ public void setId(Integer id) { this.id = id; } /** * getName

* Get the name * * @return name */ public String getName() { return name; } /** * setName

* Set the name * * @param name */ public void setName(String name) { this.name = name; } /** * getDescription

* Get the description * * @return description */ public String getDescription() { return description; } /** * setDescription

* Set the description * * @param description */ public void setDescription(String description) { this.description = description; } /** * 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; } /** * getApplicationMetadata

* Set the application metadata * * @return appMetadata */ @JsonProperty("metadata") public Set getApplicationMetadata() { return metadata; } /** * setApplicationMetadata

* Set the application metadata * * @param metadata */ @JsonProperty("metadata") public void setApplicationMetadata(Set metadata) { this.metadata = metadata; } /** * getLicenseFilename

* Get the license file name * * @return licenseFilename */ public String getLicenseFilename() { return licenseFilename; } /** * setLicenseFilename

* Set the license file name * * @param licenseFilename */ public void setLicenseFilename(String licenseFilename) { this.licenseFilename = licenseFilename; } /** * getLicenseTypes

* Get the license types * * @return licenseTypes */ public Set getLicenseTypes() { LOG.info("Getting list license types!!!!"); return licenseTypes; } /** * setLicenseTypes

* Set the license types * * @param licenseTypes */ public void setLicenseTypes(Set licenseTypes) { this.licenseTypes = licenseTypes; } /** * getCode

* Get the application code * * @return code */ public String getCode() { return code; } /** * setCode

* Set the application code * * @param code */ public void setCode(String code) { this.code = code; } /** * equals

* Compares the current object with the given object * * @param object * @return isEquals */ @Override public boolean equals(Object obj) { if (!(obj instanceof Application)) return false; Application other = (Application) obj; return id.equals(other.id); } /** * hashCode

* Get the object hashCode * * @param hashCode */ @Override public int hashCode() { return (id == null ? 0 : id.hashCode()); } }