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;
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) {
}
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);
}
}, 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;
}
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;