securis/src/main/java/net/curisit/securis/db/LicenseType.java
.. .. @@ -45,7 +45,7 @@ 45 45 46 46 @Id 47 47 @GeneratedValue 48 - private int id;48 + private Integer id;49 49 50 50 private String code; 51 51 private String name; .. .. @@ -138,4 +138,17 @@ 138 138 this.creationTimestamp = creationTimestamp; 139 139 } 140 140 141 + @Override142 + public boolean equals(Object obj) {143 + if (!(obj instanceof LicenseType))144 + return false;145 + LicenseType other = (LicenseType)obj;146 + return id.equals(other.id);147 + }148 +149 + @Override150 + public int hashCode() {151 +152 + return (id == null ? 0 : id.hashCode());153 + }141 154 } securis/src/main/java/net/curisit/securis/db/LicenseTypeMetadata.java
.. .. @@ -32,25 +32,15 @@ 32 32 private static final long serialVersionUID = 1L; 33 33 34 34 @Id 35 - @GeneratedValue36 - private int id;37 -38 - private String key;39 -40 - private String value;41 -42 35 @JsonIgnore 43 36 @ManyToOne 44 37 @JoinColumn(name = "license_type_id") 45 38 private LicenseType licenseType; 46 39 47 - public int getId() {48 - return id;49 - }40 + @Id41 + private String key;50 42 51 - public void setId(int id) {52 - this.id = id;53 - }43 + private String value;54 44 55 45 @JsonProperty("licensetype_id") 56 46 public Integer getLicenseTypeId() { .. .. @@ -91,4 +81,17 @@ 91 81 this.key = key; 92 82 } 93 83 84 + @Override85 + public boolean equals(Object obj) {86 + if (!(obj instanceof LicenseTypeMetadata))87 + return false;88 + LicenseTypeMetadata other = (LicenseTypeMetadata)obj;89 + return key.equals(other.key) && (licenseType == null || licenseType.equals(other.licenseType));90 + }91 +92 + @Override93 + public int hashCode() {94 +95 + return key.hashCode() + (licenseType == null ? 0 : licenseType.hashCode());96 + }94 97 } securis/src/main/java/net/curisit/securis/db/Pack.java
.. .. @@ -42,7 +42,7 @@ 42 42 43 43 @Id 44 44 @GeneratedValue 45 - private int id;45 + private Integer id;46 46 47 47 private String code; 48 48 .. .. @@ -263,4 +263,25 @@ 263 263 this.licensePreactivation = licensePreactivation; 264 264 } 265 265 266 + public Set<PackMetadata> getMetadata() {267 + return metadata;268 + }269 +270 + public void setMetadata(Set<PackMetadata> metadata) {271 + this.metadata = metadata;272 + }273 +274 + @Override275 + public boolean equals(Object obj) {276 + if (!(obj instanceof Pack))277 + return false;278 + Pack other = (Pack)obj;279 + return id.equals(other.id);280 + }281 +282 + @Override283 + public int hashCode() {284 +285 + return (id == null ? 0 : id.hashCode());286 + }266 287 } securis/src/main/java/net/curisit/securis/db/PackMetadata.java
.. .. @@ -32,27 +32,18 @@ 32 32 private static final long serialVersionUID = 1L; 33 33 34 34 @Id 35 - @GeneratedValue36 - private int id;35 + @JsonIgnore36 + @ManyToOne37 + @JoinColumn(name = "pack_id")38 + private Pack pack;37 39 40 + @Id38 41 private String key; 39 42 40 43 private String value; 41 44 42 45 private boolean readonly; 43 46 44 - @JsonIgnore45 - @ManyToOne46 - @JoinColumn(name = "pack_id")47 - private Pack pack;48 -49 - public int getId() {50 - return id;51 - }52 -53 - public void setId(int id) {54 - this.id = id;55 - }56 47 57 48 @JsonProperty("pack_id") 58 49 public Integer getPackId() { .. .. @@ -100,5 +91,19 @@ 100 91 public void setReadonly(boolean readonly) { 101 92 this.readonly = readonly; 102 93 } 94 +95 + @Override96 + public boolean equals(Object obj) {97 + if (!(obj instanceof PackMetadata))98 + return false;99 + PackMetadata other = (PackMetadata)obj;100 + return key.equals(other.key) && (pack == null || pack.equals(other.pack));101 + }102 +103 + @Override104 + public int hashCode() {105 +106 + return key.hashCode() + (pack == null ? 0 : pack.hashCode());107 + }103 108 104 109 } securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
.. .. @@ -2,6 +2,7 @@ 2 2 3 3 import java.util.Date; 4 4 import java.util.List; 5 +import java.util.Set;5 6 6 7 import javax.inject.Inject; 7 8 import javax.inject.Provider; .. .. @@ -26,7 +27,9 @@ 26 27 import net.curisit.securis.DefaultExceptionHandler; 27 28 import net.curisit.securis.SeCurisException; 28 29 import net.curisit.securis.db.Application; 30 +import net.curisit.securis.db.ApplicationMetadata;29 31 import net.curisit.securis.db.LicenseType; 32 +import net.curisit.securis.db.LicenseTypeMetadata;30 33 import net.curisit.securis.utils.TokenHelper; 31 34 32 35 import org.apache.logging.log4j.LogManager; .. .. @@ -123,6 +126,15 @@ 123 126 124 127 lt.setCreationTimestamp(new Date()); 125 128 em.persist(lt); 129 + Set<LicenseTypeMetadata> newMD = lt.getMetadata();130 +131 + if (newMD != null) {132 + for (LicenseTypeMetadata md : newMD) {133 + md.setLicenseType(lt);134 + em.persist(md);135 + }136 + }137 + lt.setMetadata(newMD);126 138 127 139 return Response.ok(lt).build(); 128 140 } .. .. @@ -155,6 +167,20 @@ 155 167 currentlt.setName(lt.getName()); 156 168 currentlt.setDescription(lt.getDescription()); 157 169 em.persist(currentlt); 170 +171 + Set<LicenseTypeMetadata> newMD = lt.getMetadata();172 + for (LicenseTypeMetadata currentMd : currentlt.getMetadata()) {173 + if (newMD == null || !newMD.contains(currentMd));174 + em.remove(currentMd);175 + }176 +177 + if (newMD != null) {178 + for (LicenseTypeMetadata md : newMD) {179 + md.setLicenseType(currentlt);180 + em.persist(md);181 + }182 + }183 + currentlt.setMetadata(newMD);158 184 159 185 return Response.ok(currentlt).build(); 160 186 } securis/src/main/java/net/curisit/securis/services/PackResource.java
.. .. @@ -3,6 +3,7 @@ 3 3 import java.security.Principal; 4 4 import java.util.Date; 5 5 import java.util.List; 6 +import java.util.Set;6 7 7 8 import javax.annotation.security.RolesAllowed; 8 9 import javax.inject.Inject; .. .. @@ -26,8 +27,10 @@ 26 27 import net.curisit.securis.DefaultExceptionHandler; 27 28 import net.curisit.securis.SeCurisException; 28 29 import net.curisit.securis.db.LicenseType; 30 +import net.curisit.securis.db.PackMetadata;29 31 import net.curisit.securis.db.Organization; 30 32 import net.curisit.securis.db.Pack; 33 +import net.curisit.securis.db.PackMetadata;31 34 import net.curisit.securis.db.User; 32 35 import net.curisit.securis.security.BasicSecurityContext; 33 36 import net.curisit.securis.security.Securable; .. .. @@ -155,7 +158,15 @@ 155 158 pack.setCreatedBy(user); 156 159 pack.setCreationTimestamp(new Date()); 157 160 em.persist(pack); 158 -161 + Set<PackMetadata> newMD = pack.getMetadata();162 +163 + if (newMD != null) {164 + for (PackMetadata md : newMD) {165 + md.setPack(pack);166 + em.persist(md);167 + }168 + }169 + pack.setMetadata(newMD);159 170 return Response.ok(pack).build(); 160 171 } 161 172 .. .. @@ -205,6 +216,19 @@ 205 216 206 217 em.persist(currentPack); 207 218 219 + Set<PackMetadata> newMD = pack.getMetadata();220 + for (PackMetadata currentMd : currentPack.getMetadata()) {221 + if (newMD == null || !newMD.contains(currentMd));222 + em.remove(currentMd);223 + }224 +225 + if (newMD != null) {226 + for (PackMetadata md : newMD) {227 + md.setPack(currentPack);228 + em.persist(md);229 + }230 + }231 + currentPack.setMetadata(newMD);208 232 return Response.ok(pack).build(); 209 233 } 210 234 securis/src/main/resources/db/schema.sql
.. .. @@ -48,11 +48,10 @@ 48 48 49 49 drop table IF EXISTS licensetype_metadata; 50 50 CREATE TABLE IF NOT EXISTS licensetype_metadata ( 51 - id INT NOT NULL auto_increment,52 51 license_type_id INT NOT NULL , 53 52 key VARCHAR(100) NOT NULL , 54 53 value VARCHAR(200) NULL , 55 - PRIMARY KEY (id));54 + PRIMARY KEY (license_type_id, key));56 55 57 56 drop table IF EXISTS organization; 58 57 CREATE TABLE IF NOT EXISTS organization ( .. .. @@ -85,12 +84,11 @@ 85 84 86 85 drop table IF EXISTS pack_metadata; 87 86 CREATE TABLE IF NOT EXISTS pack_metadata ( 88 - id INT NOT NULL auto_increment,89 87 pack_id INT NOT NULL , 90 88 key VARCHAR(100) NOT NULL , 91 89 value VARCHAR(200) NULL , 92 90 readonly BOOlEAN NOT NULL default false, 93 - PRIMARY KEY (id));91 + PRIMARY KEY (pack_id, key));94 92 95 93 96 94 drop table IF EXISTS license; securis/src/main/resources/static/admin.html
.. .. @@ -52,8 +52,8 @@ 52 52 <p ng-switch-when="readonly" class="form-control-static">{{formu[field.name]}}</p> 53 53 <p ng-switch-when="readonly_date" class="form-control-static">{{formu[field.name] | date:'medium'}}</p> 54 54 <select ng-switch-when="select" class="form-control" ng-required="field.mandatory" ng-model="formu[field.name]" 55 - ng-options="o.id as o.label for o in refs[field.name]" >56 - <option selected="true" ng-if="!field.mandatory" value=""></option>55 + ng-options="o.id as o.label for o in refs[field.name]" ng-change="selectFieldChanged(field.onchange)">56 + <option value="-1" selected></option>57 57 </select> 58 58 <select chosen multiple ng-switch-when="multiselect" class="form-control" ng-required="field.mandatory" ng-model="formu[field.name]" 59 59 ng-options="o.id as o.label for o in refs[field.name]" data-placeholder="..."> securis/src/main/resources/static/js/admin.js
.. .. @@ -66,7 +66,7 @@ 66 66 $scope.edit = function(data) { 67 67 $scope.showForm = true; 68 68 $scope.isNew = false; 69 - // Next line is a wirkaround due to some issues with values with ID == 069 + // Next line is a workaround due to some issues with values with ID == 070 70 $('select').val(null); 71 71 $scope.formu = {} 72 72 var fields = Catalogs.getMetadata().fields; .. .. @@ -130,6 +130,10 @@ 130 130 $scope.$parent.showForm = true; 131 131 $('select').val(null); 132 132 $scope.$parent.formu = {}; 133 +134 + console.log("Refs:");135 + console.log($scope.refs);136 +133 137 setTimeout(function() { 134 138 $('#'+Catalogs.getFFF()).focus(); 135 139 }, 0); .. .. @@ -165,6 +169,11 @@ 165 169 } 166 170 } 167 171 172 + $scope.selectFieldChanged = function(onchangehandler) {173 + if (onchangehandler) {174 + $scope[onchangehandler]();175 + }176 + }168 177 // Metadata management 169 178 170 179 $scope.createMetadataRow = function() { .. .. @@ -176,6 +185,14 @@ 176 185 $scope.removeMetadataKey = function(row_md) { 177 186 $scope.formu.metadata.splice( $scope.formu.metadata.indexOf(row_md), 1 ); 178 187 } 188 + $scope.updateMetadata = function() {189 + // Called when Application ID change in current field190 + var newAppId = $scope.formu['application_id'];191 + console.log('Ready to get metadata from application: ' + newAppId);192 + Catalogs.getResource('application').get({appId: newAppId}).$promise.then(function(app) {193 + $scope.formu.metadata = app.metadata;194 + });195 + }179 196 180 197 } ]); 181 198 securis/src/main/resources/static/js/catalogs.json
.. .. @@ -67,7 +67,8 @@ 67 67 "display" : "Application", 68 68 "resource" : "application", 69 69 "mandatory" : true, 70 - "type" : "select"70 + "type" : "select",71 + "onchange": "updateMetadata"71 72 }, { 72 73 "name" : "creationTimestamp", 73 74 "display" : "Creation date", securis/src/main/resources/static/licenses.html
.. .. @@ -88,8 +88,7 @@ 88 88 ng-required="mandatory.license_type_id" 89 89 ng-model="pack.license_type_id" 90 90 ng-options="o.id as o.label for o in refs.license_type_id"> 91 - <option selected="true" ng-if="!mandatory.license_type_id"92 - value=""></option>91 +93 92 </select> 94 93 <div class="alert inline-alert alert-warning" 95 94 ng-show="packForm.license_type_id.$invalid"> .. .. @@ -106,8 +105,6 @@ 106 105 <select class="form-control" ng-required="field.mandatory" 107 106 ng-model="pack.organization_id" 108 107 ng-options="o.id as o.label for o in refs.organization_id"> 109 - <option selected="true" ng-if="!mandatory.organization_id"110 - value=""></option>111 108 </select> 112 109 <div class="alert inline-alert alert-warning" 113 110 ng-show="packForm.organization_id.$invalid"> securis/src/main/resources/static/main.html
.. .. @@ -41,7 +41,7 @@ 41 41 <script type="text/javascript" 42 42 src="/js/vendor/bootstrap-dialog.js"></script> 43 43 <script type="text/javascript" 44 - src="/js/angular/angular.min.js"></script>44 + src="/js/angular/angular.js"></script>45 45 <script type="text/javascript" 46 46 src="/js/angular/angular-route.min.js"></script> 47 47 <script type="text/javascript"