]> source.dussan.org Git - sonarqube.git/commitdiff
Merge branch-5.0
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 19 Feb 2015 14:39:38 +0000 (15:39 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 19 Feb 2015 14:39:38 +0000 (15:39 +0100)
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java

index 25ca83d377aeffb42e43ce035caa5f8d1849cc69..13314c2e0bae7cfe96990d53005fac8b46359684 100644 (file)
@@ -23,6 +23,7 @@ import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.System2;
 import org.sonar.core.persistence.Database;
 import org.sonar.server.db.migrations.BaseDataChange;
@@ -56,6 +57,9 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration
   private static final String SECURITY_KEY = "SECURITY";
   private static final String USABILITY_KEY = "USABILITY";
 
+  private static final String ERROR_SUFFIX = "Please restore your DB backup, start the previous version of SonarQube " +
+    "and update your SQALE model to fix this issue before trying again to run the migration.";
+
   private final System2 system;
 
   public AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration(Database db, System2 system) {
@@ -135,7 +139,7 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration
   }
 
   private void createSubCharacteristic(CharacteristicsContext characteristicsContext,
-                                       String subCharacteristicKey, String subCharacteristicName, String parentKey) throws SQLException {
+    String subCharacteristicKey, String subCharacteristicName, String parentKey) throws SQLException {
     Characteristic parent = characteristicsContext.findCharacteristicByKey(parentKey);
     if (parent != null) {
       Characteristic subCharacteristic = characteristicsContext.findSubCharacteristicByKey(subCharacteristicKey, parent);
@@ -233,7 +237,7 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration
         }
       }, null);
       if (characteristic != null && characteristic.getParentId() != null) {
-        throw new IllegalStateException(String.format("'%s' must be a characteristic", characteristic.getName()));
+        throw MessageException.of(String.format("'%s' must be a characteristic. " + ERROR_SUFFIX, characteristic.getName()));
       }
       return characteristic;
     }
@@ -249,9 +253,9 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration
       if (characteristic != null) {
         Integer parentId = characteristic.getParentId();
         if (parentId == null) {
-          throw new IllegalStateException(String.format("'%s' must be a sub-characteristic", characteristic.getName()));
-        } else if (!parentId.equals(parent.getId())) {
-          throw new IllegalStateException(String.format("'%s' must be defined under '%s'", characteristic.getName(), parent.getName()));
+          throw MessageException.of(String.format("'%s' must be a sub-characteristic. " + ERROR_SUFFIX, characteristic.getName()));
+        } else if (!characteristic.getParentId().equals(parent.getId())) {
+          throw MessageException.of(String.format("'%s' must be defined under '%s'. " + ERROR_SUFFIX, characteristic.getName(), parent.getName()));
         }
       }
       return characteristic;