]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5958 Migrate issue filters 75/head
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 6 Feb 2015 16:34:11 +0000 (17:34 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 9 Feb 2015 08:55:09 +0000 (09:55 +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 e0b9516bb3f61b8e63ff5740c0f245d35b05c4c8..b74b5ac3d979521a85957f9187c857d8d752d223 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;
@@ -34,17 +31,13 @@ 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 {
 
   private static final char FIELD_SEPARATOR = '|';
   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=";
 
   private final System2 system;
@@ -59,9 +52,7 @@ public class RenameComponentRelatedParamsInIssueFilters extends BaseDataChange {
     final Date now = new Date(system.now());
     MassUpdate massUpdate = context.prepareMassUpdate();
     massUpdate.select("select id,data from issue_filters where " +
-      LIKE_PREFIX + COMPONENTS + LIKE_SUFFIX +
-      LIKE_PREFIX + PROJECTS + LIKE_SUFFIX +
-      LIKE_PREFIX + COMPONENT_ROOTS + LIKE_SUFFIX +
+      LIKE_PREFIX + COMPONENT_UUIDS + LIKE_SUFFIX +
       LIKE_PREFIX + COMPONENT_ROOT_UUIDS + "%'");
     massUpdate.update("update issue_filters set data=?, updated_at=? where id=?");
     massUpdate.rowPluralName("issue filters");
@@ -81,28 +72,15 @@ 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(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="));
+        if (field.startsWith(COMPONENT_UUIDS) || field.startsWith(COMPONENT_ROOT_UUIDS)) {
+          fieldsToKeep.add(
+            field.replace(COMPONENT_UUIDS, "fileUuids=")
+              .replace(COMPONENT_ROOT_UUIDS, "moduleUuids="));
         } 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 ffb355824b6d865cfffa794161d79b24130d7180..a8697260c074f1299c8bc01e7d104526627d0526 100644 (file)
@@ -1,6 +1,7 @@
 <dataset>
 
-     <issue_filters
+    <!-- Not updated, no concerned field -->
+    <issue_filters
       id="1"
       name="No concerned field"
       user_login="stephane"
       created_at="2013-06-10"
       updated_at="2013-06-10" />
 
+    <!-- Not updated, projectUuids is left as is -->
     <issue_filters
       id="2"
       name="Has projects"
       user_login="michael"
       shared="[false]"
       description="to be updated"
-      data="statuses=OPEN|sort=SEVERITY|asc=true|projectKeys=ABC"
+      data="statuses=OPEN|sort=SEVERITY|asc=true|projectUuids=ABC"
       created_at="2013-06-10"
-      updated_at="2014-10-29 00:00:00.0" />
+      updated_at="2013-06-10 00:00:00.0" />
 
+    <!-- componentUuids replaced by fileUuids -->
     <issue_filters
       id="3"
       name="Has components"
       user_login="michael"
       shared="[false]"
       description="to be updated"
-      data="statuses=OPEN|sort=SEVERITY|asc=true|componentKeys=ABC"
+      data="fileUuids=ABC|statuses=OPEN|sort=SEVERITY|asc=true"
       created_at="2013-06-10"
       updated_at="2014-10-29 00:00:00.0"  />
 
+    <!-- componentRootUuids replaced by moduleUuids -->
     <issue_filters
       id="4"
       name="Has componentRoots"
       user_login="michael"
       shared="[false]"
       description="to be updated"
-      data="statuses=OPEN|sort=SEVERITY|asc=true|componentKeys=ABC"
+      data="statuses=OPEN|sort=SEVERITY|asc=true|moduleUuids=ABC"
       created_at="2013-06-10"
       updated_at="2014-10-29 00:00:00.0" />
 
+    <!-- componentRootUuids replaced by moduleUuids (in the middle of the string) -->
     <issue_filters
       id="5"
       name="Has projects"
       user_login="michael"
       shared="[false]"
       description="to be updated"
-      data="statuses=OPEN|sort=SEVERITY|asc=true|componentUuids=ABC"
+      data="statuses=OPEN|sort=SEVERITY|moduleUuids=ABC|asc=true"
       created_at="2013-06-10"
       updated_at="2014-10-29 00:00:00.0" />
 
+    <!-- componentUuidss replaced by fileUuids, componentRootUuids replaced by moduleUuids -->
     <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"
+      data="statuses=OPEN|sort=SEVERITY|fileUuids=BCD|moduleUuids=ABC|projectUuids=CDE|asc=true"
       created_at="2013-06-10"
       updated_at="2014-10-29 00:00:00.0" />
 </dataset>
index bebd7d0a38717d22af85360e37fabec46d4a0bd6..e88294d599c227dd0295f236fccfb1fbc2a79b4c 100644 (file)
@@ -1,5 +1,6 @@
 <dataset>
 
+    <!-- Not updated, no concerned field -->
     <issue_filters
       id="1"
       name="No concerned field"
       created_at="2013-06-10"
       updated_at="2013-06-10" />
 
+    <!-- Not updated, projectUuids is left as is -->
     <issue_filters
       id="2"
       name="Has projects"
       user_login="michael"
       shared="[false]"
       description="to be updated"
-      data="statuses=OPEN|sort=SEVERITY|asc=true|projects=ABC"
+      data="statuses=OPEN|sort=SEVERITY|asc=true|projectUuids=ABC"
       created_at="2013-06-10"
       updated_at="2013-06-10" />
 
+    <!-- componentUuids replaced by fileUuids -->
     <issue_filters
       id="3"
       name="Has components"
       user_login="michael"
       shared="[false]"
       description="to be updated"
-      data="components=ABC|statuses=OPEN|sort=SEVERITY|asc=true"
+      data="componentUuids=ABC|statuses=OPEN|sort=SEVERITY|asc=true"
       created_at="2013-06-10"
       updated_at="2013-06-10" />
 
+    <!-- componentRootUuids replaced by moduleUuids -->
     <issue_filters
       id="4"
       name="Has componentRoots"
       user_login="michael"
       shared="[false]"
       description="to be updated"
-      data="statuses=OPEN|sort=SEVERITY|asc=true|componentRoots=ABC"
+      data="statuses=OPEN|sort=SEVERITY|asc=true|componentRootUuids=ABC"
       created_at="2013-06-10"
       updated_at="2013-06-10" />
 
+    <!-- componentRootUuids replaced by moduleUuids (in the middle of the string) -->
     <issue_filters
       id="5"
       name="Has projects"
@@ -50,6 +55,7 @@
       created_at="2013-06-10"
       updated_at="2013-06-10" />
 
+    <!-- componentUuidss replaced by fileUuids, componentRootUuids replaced by moduleUuids -->
     <issue_filters
       id="6"
       name="Has all parameters"