karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [1/2] karaf-cave git commit: Avoid duplicate resources
Date Thu, 07 May 2015 15:35:23 GMT
Repository: karaf-cave
Updated Branches:
  refs/heads/master e5d35cfb2 -> 48e7e98e5


Avoid duplicate resources

Project: http://git-wip-us.apache.org/repos/asf/karaf-cave/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-cave/commit/d46963e5
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cave/tree/d46963e5
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cave/diff/d46963e5

Branch: refs/heads/master
Commit: d46963e559af3132580ff052ffb43aa891138f7f
Parents: e5d35cf
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Thu May 7 17:34:38 2015 +0200
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Thu May 7 17:34:38 2015 +0200

----------------------------------------------------------------------
 .../cave/server/storage/CaveRepositoryImpl.java    | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cave/blob/d46963e5/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryImpl.java
b/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryImpl.java
index 86fda7c..a0f3397 100644
--- a/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryImpl.java
+++ b/server/storage/src/main/java/org/apache/karaf/cave/server/storage/CaveRepositoryImpl.java
@@ -43,6 +43,7 @@ import org.apache.karaf.cave.server.api.CaveRepository;
 import org.apache.karaf.features.internal.resolver.ResolverUtil;
 import org.apache.karaf.features.internal.resolver.ResourceBuilder;
 import org.apache.karaf.features.internal.resolver.ResourceImpl;
+import org.apache.karaf.features.internal.resolver.ResourceUtils;
 import org.jsoup.Jsoup;
 import org.jsoup.UnsupportedMimeTypeException;
 import org.jsoup.nodes.Document;
@@ -169,7 +170,21 @@ public class CaveRepositoryImpl implements CaveRepository {
 
     private void addResources(List<Resource> resources) throws IOException, XMLStreamException
{
         if (!resources.isEmpty()) {
-            repository.addResourcesAndSave(resources);
+            Map<String, Resource> ids = new HashMap<>();
+            for (Resource resource : repository.getResources()) {
+                ids.put(ResourceUtils.getUri(resource), resource);
+            }
+            List<Resource> toAdd = new ArrayList<>();
+            for (Resource resource : resources) {
+                String uri = ResourceUtils.getUri(resource);
+                if (!ids.containsKey(uri)) {
+                    toAdd.add(resource);
+                    ids.put(uri, resource);
+                }
+            }
+            if (!toAdd.isEmpty()) {
+                repository.addResourcesAndSave(resources);
+            }
         }
     }
 


Mime
View raw message