| .. | .. |
|---|
| 225 | 225 | currentPack.setComments(pack.getComments()); |
|---|
| 226 | 226 | currentPack.setNumLicenses(pack.getNumLicenses()); |
|---|
| 227 | 227 | |
|---|
| 228 | | - em.persist(currentPack); |
|---|
| 229 | | - |
|---|
| 230 | 228 | Set<PackMetadata> newMD = pack.getMetadata(); |
|---|
| 231 | 229 | 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 | + } |
|---|
| 235 | 233 | } |
|---|
| 236 | 234 | |
|---|
| 237 | 235 | if (newMD != null) { |
|---|
| 236 | + Set<PackMetadata> oldMD = currentPack.getMetadata(); |
|---|
| 238 | 237 | 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 | + } |
|---|
| 241 | 244 | } |
|---|
| 242 | 245 | } |
|---|
| 243 | 246 | currentPack.setMetadata(newMD); |
|---|
| 244 | | - return Response.ok(pack).build(); |
|---|
| 247 | + em.merge(currentPack); |
|---|
| 248 | + |
|---|
| 249 | + return Response.ok(currentPack).build(); |
|---|
| 245 | 250 | } |
|---|
| 246 | 251 | |
|---|
| 247 | 252 | @POST |
|---|