From 182ddf022ebb56af558c82dd466b206097fea7c9 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Wed, 01 Oct 2014 18:18:12 +0000
Subject: [PATCH] #2021 config - Added Metadata hibernate entities

---
 securis/src/main/java/net/curisit/securis/db/LicenseType.java |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/db/LicenseType.java b/securis/src/main/java/net/curisit/securis/db/LicenseType.java
index c3e378c..a38deb9 100644
--- a/securis/src/main/java/net/curisit/securis/db/LicenseType.java
+++ b/securis/src/main/java/net/curisit/securis/db/LicenseType.java
@@ -2,15 +2,18 @@
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.Set;
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.FetchType;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
 import javax.persistence.Table;
 
 import org.apache.logging.log4j.LogManager;
@@ -31,10 +34,12 @@
 @Entity
 @Table(name = "license_type")
 @NamedQueries({
-    @NamedQuery(name = "list-license_types", query = "SELECT lt FROM LicenseType lt")
+    @NamedQuery(name = "list-license_types", query = "SELECT lt FROM LicenseType lt"),
+    @NamedQuery(name = "list-application-license_types", query = "SELECT lt FROM LicenseType lt where lt.application.id = :appId")
 })
 public class LicenseType implements Serializable {
 
+    @SuppressWarnings("unused")
     private static final Logger LOG = LogManager.getLogger(LicenseType.class);
     private static final long serialVersionUID = 1L;
 
@@ -53,6 +58,20 @@
     @ManyToOne
     @JoinColumn(name = "application_id")
     private Application application;
+
+    @JsonIgnore
+    // We don't include the referenced entities to limit the size of each row at
+    // the listing
+    @OneToMany(fetch = FetchType.LAZY, mappedBy = "license_type")
+    private Set<LicenseTypeMetadata> metadata;
+    
+    public Set<LicenseTypeMetadata> getMetadata() {
+        return metadata;
+    }
+
+    public void setMetadata(Set<LicenseTypeMetadata> metadata) {
+        this.metadata = metadata;
+    }
 
     public int getId() {
         return id;
@@ -91,21 +110,23 @@
     }
 
     @JsonProperty("application_name")
-    public String getParentOrgName() {
+    public String getApplicationName() {
         return application == null ? null : application.getName();
     }
 
     @JsonProperty("application_id")
     public Integer getApplicationId() {
-        LOG.info("application  " + application);
         return application == null ? null : application.getId();
     }
 
     @JsonProperty("application_id")
     public void setApplicationId(Integer appId) {
-        LOG.info("setApplicationId(Integer appId)  " + appId);
-        application = new Application();
-        application.setId(appId);
+        if (appId == null) {
+            application = null;
+        } else {
+            application = new Application();
+            application.setId(appId);
+        }
     }
 
     public void setApplication(Application application) {

--
Gitblit v1.3.2