rsanchez
2014-11-17 04f9a9d2dbd2d79bfffea9c5a6b7ba1b32c5f42b
securis/src/main/java/net/curisit/securis/services/PackResource.java
....@@ -225,23 +225,28 @@
225225 currentPack.setComments(pack.getComments());
226226 currentPack.setNumLicenses(pack.getNumLicenses());
227227
228
- em.persist(currentPack);
229
-
230228 Set<PackMetadata> newMD = pack.getMetadata();
231229 for (PackMetadata currentMd : currentPack.getMetadata()) {
232
- if (newMD == null || !newMD.contains(currentMd))
233
- ;
234
- em.remove(currentMd);
230
+ if (newMD == null || !newMD.contains(currentMd)) {
231
+ em.remove(currentMd);
232
+ }
235233 }
236234
237235 if (newMD != null) {
236
+ Set<PackMetadata> oldMD = currentPack.getMetadata();
238237 for (PackMetadata md : newMD) {
239
- md.setPack(currentPack);
240
- em.persist(md);
238
+ if (oldMD.contains(md)) {
239
+ em.merge(md);
240
+ } else {
241
+ md.setPack(currentPack);
242
+ em.persist(md);
243
+ }
241244 }
242245 }
243246 currentPack.setMetadata(newMD);
244
- return Response.ok(pack).build();
247
+ em.merge(currentPack);
248
+
249
+ return Response.ok(currentPack).build();
245250 }
246251
247252 @POST