rsanchez
2015-08-03 85aa3a5834bf381b603f63e9e769920c368fa53d
#0 fix - Fixed metadata management, now based on "key" to apply
modifications
2 files modified
changed files
securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/PackResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
....@@ -1,6 +1,7 @@
11 package net.curisit.securis.services;
22
33 import java.util.Date;
4
+import java.util.HashSet;
45 import java.util.List;
56 import java.util.Set;
67
....@@ -148,6 +149,16 @@
148149 return Response.ok(lt).build();
149150 }
150151
152
+ private Set<String> getMdKeys(Set<LicenseTypeMetadata> mds) {
153
+ Set<String> ids = new HashSet<String>();
154
+ if (mds != null) {
155
+ for (LicenseTypeMetadata md : mds) {
156
+ ids.add(md.getKey());
157
+ }
158
+ }
159
+ return ids;
160
+ }
161
+
151162 @PUT
152163 @POST
153164 @Path("/{ltid}")
....@@ -179,8 +190,9 @@
179190 currentlt.setDescription(lt.getDescription());
180191
181192 Set<LicenseTypeMetadata> newMD = lt.getMetadata();
193
+ Set<String> newMdKeys = getMdKeys(newMD);
182194 for (LicenseTypeMetadata currentMd : currentlt.getMetadata()) {
183
- if (newMD == null || !newMD.contains(currentMd)) {
195
+ if (!newMdKeys.contains(currentMd.getKey())) {
184196 em.remove(currentMd);
185197 LOG.info("Removing MD: {}", currentMd);
186198 }
....@@ -188,9 +200,10 @@
188200
189201 if (newMD != null) {
190202 Set<LicenseTypeMetadata> oldMD = currentlt.getMetadata();
203
+ Set<String> oldMdKeys = getMdKeys(oldMD);
191204
192205 for (LicenseTypeMetadata md : newMD) {
193
- if (oldMD.contains(md)) {
206
+ if (oldMdKeys.contains(md.getKey())) {
194207 em.merge(md);
195208 } else {
196209 md.setLicenseType(currentlt);
securis/src/main/java/net/curisit/securis/services/PackResource.java
....@@ -2,6 +2,7 @@
22
33 import java.security.Principal;
44 import java.util.Date;
5
+import java.util.HashSet;
56 import java.util.List;
67 import java.util.Set;
78
....@@ -236,6 +237,16 @@
236237 pack.setLicenseType(lt);
237238 }
238239
240
+ private Set<String> getMdKeys(Set<PackMetadata> mds) {
241
+ Set<String> ids = new HashSet<String>();
242
+ if (mds != null) {
243
+ for (PackMetadata md : mds) {
244
+ ids.add(md.getKey());
245
+ }
246
+ }
247
+ return ids;
248
+ }
249
+
239250 @PUT
240251 @POST
241252 @Path("/{packId}")
....@@ -271,16 +282,18 @@
271282 currentPack.setRenewValidPeriod(pack.getRenewValidPeriod());
272283
273284 Set<PackMetadata> newMD = pack.getMetadata();
285
+ Set<String> newMdKeys = getMdKeys(newMD);
274286 for (PackMetadata currentMd : currentPack.getMetadata()) {
275
- if (newMD == null || !newMD.contains(currentMd)) {
287
+ if (!newMdKeys.contains(currentMd.getKey())) {
276288 em.remove(currentMd);
277289 }
278290 }
279291
280292 if (newMD != null) {
281293 Set<PackMetadata> oldMD = currentPack.getMetadata();
294
+ Set<String> oldMdKeys = getMdKeys(newMD);
282295 for (PackMetadata md : newMD) {
283
- if (oldMD.contains(md)) {
296
+ if (oldMdKeys.contains(md.getKey())) {
284297 em.merge(md);
285298 } else {
286299 md.setPack(currentPack);