rsanchez
2014-11-17 04f9a9d2dbd2d79bfffea9c5a6b7ba1b32c5f42b
securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
....@@ -132,8 +132,8 @@
132132
133133 lt.setCreationTimestamp(new Date());
134134 em.persist(lt);
135
- Set<LicenseTypeMetadata> newMD = lt.getMetadata();
136
-
135
+ Set<LicenseTypeMetadata> newMD = lt.getMetadata();
136
+
137137 if (newMD != null) {
138138 for (LicenseTypeMetadata md : newMD) {
139139 md.setLicenseType(lt);
....@@ -174,21 +174,29 @@
174174 currentlt.setCode(lt.getCode());
175175 currentlt.setName(lt.getName());
176176 currentlt.setDescription(lt.getDescription());
177
- em.persist(currentlt);
178
-
179
- Set<LicenseTypeMetadata> newMD = lt.getMetadata();
177
+
178
+ Set<LicenseTypeMetadata> newMD = lt.getMetadata();
180179 for (LicenseTypeMetadata currentMd : currentlt.getMetadata()) {
181
- if (newMD == null || !newMD.contains(currentMd));
180
+ if (newMD == null || !newMD.contains(currentMd)) {
182181 em.remove(currentMd);
182
+ LOG.info("Removing MD: {}", currentMd);
183
+ }
183184 }
184
-
185
+
185186 if (newMD != null) {
187
+ Set<LicenseTypeMetadata> oldMD = currentlt.getMetadata();
188
+
186189 for (LicenseTypeMetadata md : newMD) {
187
- md.setLicenseType(currentlt);
188
- em.persist(md);
190
+ if (oldMD.contains(md)) {
191
+ em.merge(md);
192
+ } else {
193
+ md.setLicenseType(currentlt);
194
+ em.persist(md);
195
+ }
189196 }
190197 }
191198 currentlt.setMetadata(newMD);
199
+ em.merge(currentlt);
192200
193201 return Response.ok(currentlt).build();
194202 }