rsanchez
2014-11-17 04f9a9d2dbd2d79bfffea9c5a6b7ba1b32c5f42b
securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
....@@ -154,22 +154,27 @@
154154 }
155155 currentapp.setName(app.getName());
156156 currentapp.setDescription(app.getDescription());
157
- em.persist(currentapp);
157
+ em.merge(currentapp);
158158
159159 Set<ApplicationMetadata> newMD = app.getApplicationMetadata();
160160 for (ApplicationMetadata currentMd : currentapp.getApplicationMetadata()) {
161
- if (newMD == null || !newMD.contains(currentMd))
162
- ;
163
- em.remove(currentMd);
161
+ if (newMD == null || !newMD.contains(currentMd)) {
162
+ em.remove(currentMd);
163
+ }
164164 }
165165
166166 if (newMD != null) {
167
+ Set<ApplicationMetadata> oldMD = currentapp.getApplicationMetadata();
167168 for (ApplicationMetadata md : newMD) {
168
- md.setApplication(app);
169
- if (md.getCreationTimestamp() == null) {
170
- md.setCreationTimestamp(app.getCreationTimestamp());
169
+ if (oldMD.contains(md)) {
170
+ em.merge(md);
171
+ } else {
172
+ md.setApplication(app);
173
+ if (md.getCreationTimestamp() == null) {
174
+ md.setCreationTimestamp(app.getCreationTimestamp());
175
+ }
176
+ em.persist(md);
171177 }
172
- em.persist(md);
173178 }
174179 }
175180 currentapp.setApplicationMetadata(app.getApplicationMetadata());