rsanchez
2014-10-01 182ddf022ebb56af558c82dd466b206097fea7c9
securis/src/main/java/net/curisit/securis/db/LicenseType.java
....@@ -2,15 +2,18 @@
22
33 import java.io.Serializable;
44 import java.util.Date;
5
+import java.util.Set;
56
67 import javax.persistence.Column;
78 import javax.persistence.Entity;
9
+import javax.persistence.FetchType;
810 import javax.persistence.GeneratedValue;
911 import javax.persistence.Id;
1012 import javax.persistence.JoinColumn;
1113 import javax.persistence.ManyToOne;
1214 import javax.persistence.NamedQueries;
1315 import javax.persistence.NamedQuery;
16
+import javax.persistence.OneToMany;
1417 import javax.persistence.Table;
1518
1619 import org.apache.logging.log4j.LogManager;
....@@ -31,10 +34,12 @@
3134 @Entity
3235 @Table(name = "license_type")
3336 @NamedQueries({
34
- @NamedQuery(name = "list-license_types", query = "SELECT lt FROM LicenseType lt")
37
+ @NamedQuery(name = "list-license_types", query = "SELECT lt FROM LicenseType lt"),
38
+ @NamedQuery(name = "list-application-license_types", query = "SELECT lt FROM LicenseType lt where lt.application.id = :appId")
3539 })
3640 public class LicenseType implements Serializable {
3741
42
+ @SuppressWarnings("unused")
3843 private static final Logger LOG = LogManager.getLogger(LicenseType.class);
3944 private static final long serialVersionUID = 1L;
4045
....@@ -53,6 +58,20 @@
5358 @ManyToOne
5459 @JoinColumn(name = "application_id")
5560 private Application application;
61
+
62
+ @JsonIgnore
63
+ // We don't include the referenced entities to limit the size of each row at
64
+ // the listing
65
+ @OneToMany(fetch = FetchType.LAZY, mappedBy = "license_type")
66
+ private Set<LicenseTypeMetadata> metadata;
67
+
68
+ public Set<LicenseTypeMetadata> getMetadata() {
69
+ return metadata;
70
+ }
71
+
72
+ public void setMetadata(Set<LicenseTypeMetadata> metadata) {
73
+ this.metadata = metadata;
74
+ }
5675
5776 public int getId() {
5877 return id;
....@@ -91,21 +110,23 @@
91110 }
92111
93112 @JsonProperty("application_name")
94
- public String getParentOrgName() {
113
+ public String getApplicationName() {
95114 return application == null ? null : application.getName();
96115 }
97116
98117 @JsonProperty("application_id")
99118 public Integer getApplicationId() {
100
- LOG.info("application " + application);
101119 return application == null ? null : application.getId();
102120 }
103121
104122 @JsonProperty("application_id")
105123 public void setApplicationId(Integer appId) {
106
- LOG.info("setApplicationId(Integer appId) " + appId);
107
- application = new Application();
108
- application.setId(appId);
124
+ if (appId == null) {
125
+ application = null;
126
+ } else {
127
+ application = new Application();
128
+ application.setId(appId);
129
+ }
109130 }
110131
111132 public void setApplication(Application application) {