| .. | .. |
|---|
| 44 | 44 | import net.curisit.securis.services.exception.SeCurisServiceException; |
|---|
| 45 | 45 | import net.curisit.securis.services.exception.SeCurisServiceException.ErrorCodes; |
|---|
| 46 | 46 | import net.curisit.securis.services.helpers.LicenseHelper; |
|---|
| 47 | +import net.curisit.securis.services.helpers.MetadataHelper; |
|---|
| 47 | 48 | import net.curisit.securis.utils.LicUtils; |
|---|
| 48 | 49 | import net.curisit.securis.utils.TokenHelper; |
|---|
| 49 | 50 | |
|---|
| .. | .. |
|---|
| 60 | 61 | |
|---|
| 61 | 62 | @Inject |
|---|
| 62 | 63 | TokenHelper tokenHelper; |
|---|
| 64 | + |
|---|
| 65 | + @Inject |
|---|
| 66 | + MetadataHelper metadataHelper; |
|---|
| 63 | 67 | |
|---|
| 64 | 68 | @Context |
|---|
| 65 | 69 | EntityManager em; |
|---|
| .. | .. |
|---|
| 273 | 277 | currentPack.setEndValidDate(pack.getEndValidDate()); |
|---|
| 274 | 278 | |
|---|
| 275 | 279 | Set<PackMetadata> newMD = pack.getMetadata(); |
|---|
| 276 | | - Set<String> newMdKeys = getMdKeys(newMD); |
|---|
| 277 | | - for (PackMetadata currentMd : currentPack.getMetadata()) { |
|---|
| 278 | | - if (!newMdKeys.contains(currentMd.getKey())) { |
|---|
| 279 | | - em.remove(currentMd); |
|---|
| 280 | | - } |
|---|
| 281 | | - } |
|---|
| 282 | | - |
|---|
| 283 | | - if (newMD != null) { |
|---|
| 284 | | - Set<String> oldMdKeys = getMdKeys(newMD); |
|---|
| 285 | | - for (PackMetadata md : newMD) { |
|---|
| 286 | | - if (oldMdKeys.contains(md.getKey())) { |
|---|
| 287 | | - em.merge(md); |
|---|
| 288 | | - } else { |
|---|
| 289 | | - md.setPack(currentPack); |
|---|
| 290 | | - em.persist(md); |
|---|
| 280 | + boolean metadataChanges = !metadataHelper.match(newMD, currentPack.getMetadata()); |
|---|
| 281 | + if (metadataChanges) { |
|---|
| 282 | + Set<String> newMdKeys = getMdKeys(newMD); |
|---|
| 283 | + for (PackMetadata currentMd : currentPack.getMetadata()) { |
|---|
| 284 | + if (!newMdKeys.contains(currentMd.getKey())) { |
|---|
| 285 | + em.remove(currentMd); |
|---|
| 291 | 286 | } |
|---|
| 292 | 287 | } |
|---|
| 288 | + |
|---|
| 289 | + if (newMD != null) { |
|---|
| 290 | + Set<String> oldMdKeys = getMdKeys(newMD); |
|---|
| 291 | + for (PackMetadata md : newMD) { |
|---|
| 292 | + if (oldMdKeys.contains(md.getKey())) { |
|---|
| 293 | + em.merge(md); |
|---|
| 294 | + } else { |
|---|
| 295 | + md.setPack(currentPack); |
|---|
| 296 | + em.persist(md); |
|---|
| 297 | + } |
|---|
| 298 | + } |
|---|
| 299 | + } |
|---|
| 300 | + currentPack.setMetadata(newMD); |
|---|
| 293 | 301 | } |
|---|
| 294 | | - currentPack.setMetadata(newMD); |
|---|
| 295 | 302 | em.merge(currentPack); |
|---|
| 296 | 303 | |
|---|
| 304 | + if (metadataChanges) { |
|---|
| 305 | + metadataHelper.markObsoleteMetadata(em, currentPack); |
|---|
| 306 | + } |
|---|
| 307 | + |
|---|
| 297 | 308 | return Response.ok(currentPack).build(); |
|---|
| 298 | 309 | } |
|---|
| 299 | 310 | |
|---|