From 85aa3a5834bf381b603f63e9e769920c368fa53d Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Mon, 03 Aug 2015 09:58:35 +0000
Subject: [PATCH] #0 fix - Fixed metadata management, now based on "key" to apply modifications

---
 securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java b/securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
index c1b8a39..aea9199 100644
--- a/securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
+++ b/securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
@@ -1,6 +1,7 @@
 package net.curisit.securis.services;
 
 import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -148,6 +149,16 @@
         return Response.ok(lt).build();
     }
 
+    private Set<String> getMdKeys(Set<LicenseTypeMetadata> mds) {
+        Set<String> ids = new HashSet<String>();
+        if (mds != null) {
+            for (LicenseTypeMetadata md : mds) {
+                ids.add(md.getKey());
+            }
+        }
+        return ids;
+    }
+
     @PUT
     @POST
     @Path("/{ltid}")
@@ -179,8 +190,9 @@
         currentlt.setDescription(lt.getDescription());
 
         Set<LicenseTypeMetadata> newMD = lt.getMetadata();
+        Set<String> newMdKeys = getMdKeys(newMD);
         for (LicenseTypeMetadata currentMd : currentlt.getMetadata()) {
-            if (newMD == null || !newMD.contains(currentMd)) {
+            if (!newMdKeys.contains(currentMd.getKey())) {
                 em.remove(currentMd);
                 LOG.info("Removing MD: {}", currentMd);
             }
@@ -188,9 +200,10 @@
 
         if (newMD != null) {
             Set<LicenseTypeMetadata> oldMD = currentlt.getMetadata();
+            Set<String> oldMdKeys = getMdKeys(oldMD);
 
             for (LicenseTypeMetadata md : newMD) {
-                if (oldMD.contains(md)) {
+                if (oldMdKeys.contains(md.getKey())) {
                     em.merge(md);
                 } else {
                     md.setLicenseType(currentlt);

--
Gitblit v1.3.2