You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by dg...@apache.org on 2018/10/18 18:01:22 UTC

[2/2] incubator-unomi git commit: UNOMI-202 add sort to patches to execute patch in filename order

UNOMI-202 add sort to patches to execute patch in filename order


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/12f0cabc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/12f0cabc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/12f0cabc

Branch: refs/heads/master
Commit: 12f0cabcb12979fb9c1a8fe5e879bab3a6b0b02d
Parents: 04dd4fd
Author: dgaillard <dg...@jahia.com>
Authored: Thu Oct 18 20:01:10 2018 +0200
Committer: dgaillard <dg...@jahia.com>
Committed: Thu Oct 18 20:01:10 2018 +0200

----------------------------------------------------------------------
 .../unomi/services/services/PatchServiceImpl.java      | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/12f0cabc/services/src/main/java/org/apache/unomi/services/services/PatchServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/services/PatchServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/PatchServiceImpl.java
index 0ee58e0..7f6e36e 100644
--- a/services/src/main/java/org/apache/unomi/services/services/PatchServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/services/PatchServiceImpl.java
@@ -32,8 +32,7 @@ import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.net.URL;
-import java.util.Date;
-import java.util.Enumeration;
+import java.util.*;
 
 public class PatchServiceImpl implements PatchService, SynchronousBundleListener {
 
@@ -93,8 +92,14 @@ public class PatchServiceImpl implements PatchService, SynchronousBundleListener
         // First apply patches on existing items
         Enumeration<URL> urls = bundleContext.getBundle().findEntries("META-INF/cxs/patches", "*.json", true);
         if (urls != null) {
-            while (urls.hasMoreElements()) {
-                URL patchUrl = urls.nextElement();
+            List<URL> resources = Collections.list(urls);
+            resources.sort(new Comparator<URL>() {
+                @Override public int compare(URL o1, URL o2) {
+                    return o1.getFile().compareTo(o2.getFile());
+                }
+            });
+
+            for (URL patchUrl : resources) {
                 try {
                     Patch patch = CustomObjectMapper.getObjectMapper().readValue(patchUrl, Patch.class);
                     if (persistenceService.load(patch.getItemId(), Patch.class) == null) {