rsanchez
2014-10-01 182ddf022ebb56af558c82dd466b206097fea7c9
#2021 config - Added Metadata hibernate entities
4 files added
3 files modified
changed files
securis/src/main/java/net/curisit/securis/SeCurisServer.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/beans/MetadataType.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/Application.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/ApplicationMetadata.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/LicenseType.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/LicenseTypeMetadata.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/PackMetadata.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/SeCurisServer.java
....@@ -118,7 +118,7 @@
118118 Properties props = new Properties();
119119 props.put("javax.persistence.jdbc.password", securisModule.getPassword());
120120 props.put("javax.persistence.jdbc.url", securisModule.getUrl(securisModule.getAppDir()));
121
- LOG.info("BD Url: {} {}", securisModule.getUrl(securisModule.getAppDir()), securisModule.getPassword());
121
+ //LOG.info("BD Url: {} {}", securisModule.getUrl(securisModule.getAppDir()), securisModule.getPassword());
122122 jpaPersistModule.properties(props);
123123
124124 injector = Guice.createInjector(securisModule, new RequestsModule(), jpaPersistModule);
....@@ -150,7 +150,13 @@
150150 QueuedThreadPool threadPool = new QueuedThreadPool();
151151 threadPool.setMaxThreads(50);
152152
153
- server = new Server(Config.getInt(Config.KEYS.SERVER_PORT, 9080));
153
+ server = new Server();
154
+
155
+ ServerConnector httpConnector = new ServerConnector(server);
156
+ httpConnector.setPort(Config.getInt(Config.KEYS.SERVER_PORT, 9080));
157
+ httpConnector.setHost(Config.get(Config.KEYS.SERVER_HOSTNAME, "0.0.0.0"));
158
+ server.addConnector(httpConnector);
159
+
154160 ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
155161 context.setContextPath("/");
156162 context.addEventListener(injector.getInstance(GuiceResteasyBootstrapServletContextListener.class));
....@@ -176,7 +182,6 @@
176182
177183 ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
178184 context.setErrorHandler(errorHandler);
179
- LOG.info("Error Handlers: " + context.getErrorHandler());
180185 ContextHandlerCollection contexts = new ContextHandlerCollection();
181186
182187 contexts.setHandlers(new Handler[] {
....@@ -204,7 +209,6 @@
204209 // sslContextFactory.setTrustStorePassword("curist3c");
205210 sslContextFactory.checkKeyStore();
206211 sslContextFactory.setNeedClientAuth(false);
207
- LOG.info("Protocol: {}", sslContextFactory.getProtocol());
208212
209213 ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config));
210214 sslConnector.setPort(Config.getInt(Config.KEYS.SERVER_SSL_PORT, 9443));
....@@ -217,6 +221,7 @@
217221 try {
218222 server.start();
219223 savePID();
224
+ CONSOLE.info("Server running in: {}", String.format("http://%s:%d", httpConnector.getHost(), httpConnector.getPort()));
220225 server.join();
221226 } catch (Exception e) {
222227 LOG.error("Error starting SeCurisServer", e);
securis/src/main/java/net/curisit/securis/beans/MetadataType.java
....@@ -0,0 +1,16 @@
1
+package net.curisit.securis.beans;
2
+
3
+public enum MetadataType {
4
+
5
+ NUMBER(1),
6
+ STRING(2),
7
+ BOOLEAN(3);
8
+
9
+ private final int id;
10
+ MetadataType(int id) {
11
+ this.id = id;
12
+ }
13
+ public int getId() {
14
+ return id;
15
+ }
16
+}
securis/src/main/java/net/curisit/securis/db/Application.java
....@@ -49,6 +49,12 @@
4949 @OneToMany(fetch = FetchType.LAZY, mappedBy = "application")
5050 private Set<LicenseType> licenseTypes;
5151
52
+ @JsonIgnore
53
+ // We don't include the referenced entities to limit the size of each row at
54
+ // the listing
55
+ @OneToMany(fetch = FetchType.LAZY, mappedBy = "application")
56
+ private Set<ApplicationMetadata> metadata;
57
+
5258 public int getId() {
5359 return id;
5460 }
....@@ -89,4 +95,12 @@
8995 this.licenseTypes = licenseTypes;
9096 }
9197
98
+ public Set<ApplicationMetadata> getApplicationMetadata() {
99
+ return metadata;
100
+ }
101
+
102
+ public void setApplicationMetadata(Set<ApplicationMetadata> metadata) {
103
+ this.metadata = metadata;
104
+ }
105
+
92106 }
securis/src/main/java/net/curisit/securis/db/ApplicationMetadata.java
....@@ -0,0 +1,123 @@
1
+package net.curisit.securis.db;
2
+
3
+import java.io.Serializable;
4
+import java.util.Date;
5
+import java.util.Set;
6
+
7
+import javax.persistence.Column;
8
+import javax.persistence.Entity;
9
+import javax.persistence.FetchType;
10
+import javax.persistence.GeneratedValue;
11
+import javax.persistence.Id;
12
+import javax.persistence.JoinColumn;
13
+import javax.persistence.ManyToOne;
14
+import javax.persistence.NamedQueries;
15
+import javax.persistence.NamedQuery;
16
+import javax.persistence.OneToMany;
17
+import javax.persistence.Table;
18
+
19
+import net.curisit.securis.beans.MetadataType;
20
+
21
+import org.codehaus.jackson.annotate.JsonAutoDetect;
22
+import org.codehaus.jackson.annotate.JsonIgnore;
23
+import org.codehaus.jackson.annotate.JsonProperty;
24
+import org.codehaus.jackson.map.annotate.JsonSerialize;
25
+
26
+/**
27
+ * Entity implementation class for Entity: application_metadata
28
+ *
29
+ */
30
+@JsonAutoDetect
31
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
32
+@Entity
33
+@Table(name = "application_metadata")
34
+@NamedQueries({
35
+ @NamedQuery(name = "list-application-metadata", query = "SELECT a FROM ApplicationMetadata a where a.application.id = :applicationId")
36
+})
37
+public class ApplicationMetadata implements Serializable {
38
+
39
+ private static final long serialVersionUID = 1L;
40
+
41
+ @Id
42
+ @GeneratedValue
43
+ private int id;
44
+
45
+ private String key;
46
+
47
+ private String description;
48
+
49
+ private MetadataType dataType;
50
+
51
+ @JsonIgnore
52
+ @ManyToOne
53
+ @JoinColumn(name = "application_id")
54
+ private Application application;
55
+
56
+ @Column(name = "creation_timestamp")
57
+ private Date creationTimestamp;
58
+
59
+ public int getId() {
60
+ return id;
61
+ }
62
+
63
+ public void setId(int id) {
64
+ this.id = id;
65
+ }
66
+
67
+ public String getKey() {
68
+ return key;
69
+ }
70
+
71
+ public void setKey(String key) {
72
+ this.key = key;
73
+ }
74
+
75
+ public String getDescription() {
76
+ return description;
77
+ }
78
+
79
+ public void setDescription(String description) {
80
+ this.description = description;
81
+ }
82
+
83
+ public MetadataType getDataType() {
84
+ return dataType;
85
+ }
86
+
87
+ public void setDataType(MetadataType dataType) {
88
+ this.dataType = dataType;
89
+ }
90
+
91
+ public Application getApplication() {
92
+ return application;
93
+ }
94
+
95
+ public void setApplication(Application application) {
96
+ this.application = application;
97
+ }
98
+
99
+ public Date getCreationTimestamp() {
100
+ return creationTimestamp;
101
+ }
102
+
103
+ public void setCreationTimestamp(Date creationTimestamp) {
104
+ this.creationTimestamp = creationTimestamp;
105
+ }
106
+
107
+
108
+ @JsonProperty("application_id")
109
+ public Integer getApplicationId() {
110
+ return application == null ? null : application.getId();
111
+ }
112
+
113
+ @JsonProperty("application_id")
114
+ public void setApplicationId(Integer idApplication) {
115
+ if (idApplication == null) {
116
+ application = null;
117
+ } else {
118
+ application = new Application();
119
+ application.setId(idApplication);
120
+ }
121
+ }
122
+
123
+}
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) {
securis/src/main/java/net/curisit/securis/db/LicenseTypeMetadata.java
....@@ -0,0 +1,116 @@
1
+package net.curisit.securis.db;
2
+
3
+import java.io.Serializable;
4
+import java.util.Date;
5
+
6
+import javax.persistence.Column;
7
+import javax.persistence.Entity;
8
+import javax.persistence.GeneratedValue;
9
+import javax.persistence.Id;
10
+import javax.persistence.JoinColumn;
11
+import javax.persistence.ManyToOne;
12
+import javax.persistence.NamedQueries;
13
+import javax.persistence.NamedQuery;
14
+import javax.persistence.Table;
15
+
16
+import net.curisit.securis.beans.MetadataType;
17
+
18
+import org.codehaus.jackson.annotate.JsonAutoDetect;
19
+import org.codehaus.jackson.annotate.JsonIgnore;
20
+import org.codehaus.jackson.annotate.JsonProperty;
21
+import org.codehaus.jackson.map.annotate.JsonSerialize;
22
+
23
+/**
24
+ * Entity implementation class for Entity: licensetype_metadata
25
+ *
26
+ */
27
+@JsonAutoDetect
28
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
29
+@Entity
30
+@Table(name = "licensetype_metadata")
31
+@NamedQueries({
32
+ @NamedQuery(name = "list-licensetype-metadata", query = "SELECT a FROM LicenseTypeMetadata a where a.licenseType.id = :licenseTypeId")
33
+})
34
+public class LicenseTypeMetadata implements Serializable {
35
+
36
+ private static final long serialVersionUID = 1L;
37
+
38
+ @Id
39
+ @GeneratedValue
40
+ private int id;
41
+
42
+ private String value;
43
+
44
+ @JsonIgnore
45
+ @ManyToOne
46
+ @JoinColumn(name = "metadata_id")
47
+ private ApplicationMetadata metadata;
48
+
49
+ @JsonIgnore
50
+ @ManyToOne
51
+ @JoinColumn(name = "licensetype_id")
52
+ private LicenseType licenseType;
53
+
54
+ public int getId() {
55
+ return id;
56
+ }
57
+
58
+ public void setId(int id) {
59
+ this.id = id;
60
+ }
61
+
62
+ @JsonProperty("licensetype_id")
63
+ public Integer getLicenseTypeId() {
64
+ return licenseType == null ? null : licenseType.getId();
65
+ }
66
+
67
+ @JsonProperty("licensetype_id")
68
+ public void setLicenseTypeId(Integer idLicenseType) {
69
+ if (idLicenseType == null) {
70
+ licenseType = null;
71
+ } else {
72
+ licenseType = new LicenseType();
73
+ licenseType.setId(idLicenseType);
74
+ }
75
+ }
76
+
77
+ @JsonProperty("metadata_id")
78
+ public Integer getMetadataId() {
79
+ return metadata == null ? null : metadata.getId();
80
+ }
81
+
82
+ @JsonProperty("metadata_id")
83
+ public void setMetadataId(Integer idMetadata) {
84
+ if (idMetadata == null) {
85
+ metadata = null;
86
+ } else {
87
+ metadata = new ApplicationMetadata();
88
+ metadata.setId(idMetadata);
89
+ }
90
+ }
91
+
92
+ public ApplicationMetadata getMetadata() {
93
+ return metadata;
94
+ }
95
+
96
+ public void setMetadata(ApplicationMetadata metadata) {
97
+ this.metadata = metadata;
98
+ }
99
+
100
+ public LicenseType getLicenseType() {
101
+ return licenseType;
102
+ }
103
+
104
+ public void setLicenseType(LicenseType licenseType) {
105
+ this.licenseType = licenseType;
106
+ }
107
+
108
+ public String getValue() {
109
+ return value;
110
+ }
111
+
112
+ public void setValue(String value) {
113
+ this.value = value;
114
+ }
115
+
116
+}
securis/src/main/java/net/curisit/securis/db/PackMetadata.java
....@@ -0,0 +1,114 @@
1
+package net.curisit.securis.db;
2
+
3
+import java.io.Serializable;
4
+import java.util.Date;
5
+
6
+import javax.persistence.Column;
7
+import javax.persistence.Entity;
8
+import javax.persistence.GeneratedValue;
9
+import javax.persistence.Id;
10
+import javax.persistence.JoinColumn;
11
+import javax.persistence.ManyToOne;
12
+import javax.persistence.NamedQueries;
13
+import javax.persistence.NamedQuery;
14
+import javax.persistence.Table;
15
+
16
+import org.codehaus.jackson.annotate.JsonAutoDetect;
17
+import org.codehaus.jackson.annotate.JsonIgnore;
18
+import org.codehaus.jackson.annotate.JsonProperty;
19
+import org.codehaus.jackson.map.annotate.JsonSerialize;
20
+
21
+/**
22
+ * Entity implementation class for Entity: pack_metadata
23
+ *
24
+ */
25
+@JsonAutoDetect
26
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
27
+@Entity
28
+@Table(name = "pack_metadata")
29
+@NamedQueries({
30
+ @NamedQuery(name = "list-pack-metadata", query = "SELECT a FROM PackMetadata a where a.pack.id = :packId")
31
+})
32
+public class PackMetadata implements Serializable {
33
+
34
+ private static final long serialVersionUID = 1L;
35
+
36
+ @Id
37
+ @GeneratedValue
38
+ private int id;
39
+
40
+ private String value;
41
+
42
+ @JsonIgnore
43
+ @ManyToOne
44
+ @JoinColumn(name = "metadata_id")
45
+ private ApplicationMetadata metadata;
46
+
47
+ @JsonIgnore
48
+ @ManyToOne
49
+ @JoinColumn(name = "pack_id")
50
+ private Pack pack;
51
+
52
+ public int getId() {
53
+ return id;
54
+ }
55
+
56
+ public void setId(int id) {
57
+ this.id = id;
58
+ }
59
+
60
+ @JsonProperty("pack_id")
61
+ public Integer getPackId() {
62
+ return pack == null ? null : pack.getId();
63
+ }
64
+
65
+ @JsonProperty("pack_id")
66
+ public void setLicenseTypeId(Integer idPack) {
67
+ if (idPack == null) {
68
+ pack = null;
69
+ } else {
70
+ pack = new Pack();
71
+ pack.setId(idPack);
72
+ }
73
+ }
74
+
75
+ @JsonProperty("metadata_id")
76
+ public Integer getMetadataId() {
77
+ return metadata == null ? null : metadata.getId();
78
+ }
79
+
80
+ @JsonProperty("metadata_id")
81
+ public void setMetadataId(Integer idMetadata) {
82
+ if (idMetadata == null) {
83
+ metadata = null;
84
+ } else {
85
+ metadata = new ApplicationMetadata();
86
+ metadata.setId(idMetadata);
87
+ }
88
+ }
89
+
90
+ public ApplicationMetadata getMetadata() {
91
+ return metadata;
92
+ }
93
+
94
+ public void setMetadata(ApplicationMetadata metadata) {
95
+ this.metadata = metadata;
96
+ }
97
+
98
+ public Pack getPack() {
99
+ return pack;
100
+ }
101
+
102
+ public void setPack(Pack pack) {
103
+ this.pack = pack;
104
+ }
105
+
106
+ public String getValue() {
107
+ return value;
108
+ }
109
+
110
+ public void setValue(String value) {
111
+ this.value = value;
112
+ }
113
+
114
+}