]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5958 Fix migration of issue filters
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 12 Jan 2015 08:10:58 +0000 (09:10 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 12 Jan 2015 10:42:08 +0000 (11:42 +0100)
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/RenameComponentRelatedParamsInIssueFilters.java
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/RenameComponentRelatedParamsInIssueFiltersMigrationTest/execute-result.xml
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/RenameComponentRelatedParamsInIssueFiltersMigrationTest/execute.xml

index 7c41be8b9f12c71b18fb320902c90093e45e4b79..e0b9516bb3f61b8e63ff5740c0f245d35b05c4c8 100644 (file)
  */
 package org.sonar.server.db.migrations.v51;
 
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.core.persistence.Database;
@@ -31,6 +34,7 @@ import org.sonar.server.db.migrations.SqlStatement;
 import java.sql.SQLException;
 import java.util.Date;
 import java.util.List;
+import java.util.SortedSet;
 
 public class RenameComponentRelatedParamsInIssueFilters extends BaseDataChange {
 
@@ -38,6 +42,7 @@ public class RenameComponentRelatedParamsInIssueFilters extends BaseDataChange {
   private static final String LIKE_PREFIX = "data like '%";
   private static final String LIKE_SUFFIX = "%' or ";
   private static final String COMPONENTS = "components=";
+  private static final String COMPONENT_UUIDS = "componentUuids=";
   private static final String PROJECTS = "projects=";
   private static final String COMPONENT_ROOTS = "componentRoots=";
   private static final String COMPONENT_ROOT_UUIDS = "componentRootUuids=";
@@ -76,17 +81,28 @@ public class RenameComponentRelatedParamsInIssueFilters extends BaseDataChange {
       String[] fields = StringUtils.split(data, FIELD_SEPARATOR);
 
       List<String> fieldsToKeep = Lists.newArrayList();
+      SortedSet<String> components = Sets.newTreeSet();
+      SortedSet<String> componentUuids = Sets.newTreeSet();
+      Splitter componentSplitter = Splitter.on(",");
+      Joiner componentJoiner = Joiner.on(",");
       for (String field : fields) {
-        if (field.startsWith(COMPONENTS) || field.startsWith(PROJECTS) || field.startsWith(COMPONENT_ROOTS) || field.startsWith(COMPONENT_ROOT_UUIDS)) {
-          fieldsToKeep.add(
-            field.replace(COMPONENTS, "componentKeys=")
-              .replace(PROJECTS, "projectKeys=")
-              .replace(COMPONENT_ROOTS, "moduleKeys=")
-              .replace(COMPONENT_ROOT_UUIDS, "moduleUuids="));
+        if (field.startsWith(COMPONENTS) || field.startsWith(COMPONENT_ROOTS)) {
+          components.addAll(Lists.newArrayList(componentSplitter.split(field.substring(field.indexOf("=") + 1))));
+        } else if (field.startsWith(COMPONENT_UUIDS) || field.startsWith(COMPONENT_ROOT_UUIDS)) {
+          componentUuids.addAll(Lists.newArrayList(componentSplitter.split(field.substring(field.indexOf("=") + 1))));
+        } else if (field.startsWith(PROJECTS)) {
+          fieldsToKeep.add(field.replace(PROJECTS, "projectKeys="));
         } else {
           fieldsToKeep.add(field);
         }
       }
+      if (!components.isEmpty()) {
+        fieldsToKeep.add("componentKeys=" + componentJoiner.join(components));
+      }
+      if (!componentUuids.isEmpty()) {
+        fieldsToKeep.add("componentUuids=" + componentJoiner.join(componentUuids));
+      }
+
       update.setString(1, StringUtils.join(fieldsToKeep, FIELD_SEPARATOR));
       update.setDate(2, now);
       update.setLong(3, row.getLong(1));
index b76ed6d9fd48a0ecd299af918009b66863329777..ffb355824b6d865cfffa794161d79b24130d7180 100644 (file)
@@ -26,7 +26,7 @@
       user_login="michael"
       shared="[false]"
       description="to be updated"
-      data="componentKeys=ABC|statuses=OPEN|sort=SEVERITY|asc=true"
+      data="statuses=OPEN|sort=SEVERITY|asc=true|componentKeys=ABC"
       created_at="2013-06-10"
       updated_at="2014-10-29 00:00:00.0"  />
 
@@ -36,7 +36,7 @@
       user_login="michael"
       shared="[false]"
       description="to be updated"
-      data="statuses=OPEN|sort=SEVERITY|asc=true|moduleKeys=ABC"
+      data="statuses=OPEN|sort=SEVERITY|asc=true|componentKeys=ABC"
       created_at="2013-06-10"
       updated_at="2014-10-29 00:00:00.0" />
 
       user_login="michael"
       shared="[false]"
       description="to be updated"
-      data="statuses=OPEN|sort=SEVERITY|moduleUuids=ABC|asc=true"
+      data="statuses=OPEN|sort=SEVERITY|asc=true|componentUuids=ABC"
       created_at="2013-06-10"
       updated_at="2014-10-29 00:00:00.0" />
 
+    <issue_filters
+      id="6"
+      name="Has all parameters"
+      user_login="michael"
+      shared="[false]"
+      description="to be updated"
+      data="statuses=OPEN|sort=SEVERITY|projectUuids=CDE|asc=true|componentUuids=ABC,BCD"
+      created_at="2013-06-10"
+      updated_at="2014-10-29 00:00:00.0" />
 </dataset>
index 8e23cdd0cc263569b7ec65fc275aa8fed3d8e9a5..bebd7d0a38717d22af85360e37fabec46d4a0bd6 100644 (file)
       created_at="2013-06-10"
       updated_at="2013-06-10" />
 
+    <issue_filters
+      id="6"
+      name="Has all parameters"
+      user_login="michael"
+      shared="[false]"
+      description="to be updated"
+      data="statuses=OPEN|sort=SEVERITY|componentUuids=BCD|componentRootUuids=ABC|projectUuids=CDE|asc=true"
+      created_at="2013-06-10"
+      updated_at="2013-06-10" />
+
 </dataset>