private void addMetrics(GlobalRepositories ref, DbSession session) {
for (MetricDto metric : dbClient.metricDao().selectEnabled(session)) {
- Boolean optimizedBestValue = metric.isOptimizedBestValue();
ref.addMetric(
new org.sonar.batch.protocol.input.Metric(metric.getId(), metric.getKey(),
metric.getValueType(),
metric.isUserManaged(),
metric.getWorstValue(),
metric.getBestValue(),
- optimizedBestValue != null ? optimizedBestValue : false));
+ metric.isOptimizedBestValue()));
}
}
import org.sonar.server.db.migrations.v52.FeedDependenciesComponentUuids;
import org.sonar.server.db.migrations.v52.FeedEventsComponentUuid;
import org.sonar.server.db.migrations.v52.FeedFileSourcesDataType;
+import org.sonar.server.db.migrations.v52.FeedMetricsBooleans;
import org.sonar.server.db.migrations.v52.FeedProjectLinksComponentUuid;
import org.sonar.server.db.migrations.v52.MoveProjectProfileAssociation;
FeedDependenciesComponentUuids.class,
DropDependenciesComponentColumns.class,
FeedFileSourcesDataType.class,
+ FeedMetricsBooleans.class,
AddDependenciesColumns.class);
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.db.migrations.v52;
+
+import java.sql.SQLException;
+import org.sonar.core.persistence.Database;
+import org.sonar.server.db.migrations.BaseDataChange;
+
+public class FeedMetricsBooleans extends BaseDataChange {
+
+ public FeedMetricsBooleans(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.prepareUpsert("update metrics set OPTIMIZED_BEST_VALUE=?, HIDDEN=?, DELETE_HISTORICAL_DATA=? where user_managed=? or OPTIMIZED_BEST_VALUE is null or HIDDEN is null or DELETE_HISTORICAL_DATA is null")
+ .setBoolean(1, false)
+ .setBoolean(2, false)
+ .setBoolean(3, false)
+ .setBoolean(4, true)
+ .execute().commit();
+ }
+}
.setUserManaged(true)
.setDirection(0)
.setQualitative(false)
+ .setHidden(false)
+ .setOptimizedBestValue(false)
+ .setDeleteHistoricalData(false)
.setOrigin("GUI");
dbClient.metricDao().insert(dbSession, metric);
public void verify_count_of_added_MigrationStep_types() throws Exception {
ComponentContainer container = new ComponentContainer();
new MigrationStepModule().configure(container);
- assertThat(container.size()).isEqualTo(54);
+ assertThat(container.size()).isEqualTo(55);
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.db.migrations.v52;
+
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.server.db.migrations.MigrationStep;
+
+public class FeedMetricsBooleansTest {
+ @ClassRule
+ public static DbTester db = new DbTester().schema(FeedMetricsBooleansTest.class, "schema.sql");
+
+ MigrationStep migration;
+
+ @Before
+ public void setUp() {
+ db.executeUpdateSql("truncate table metrics");
+
+ migration = new FeedMetricsBooleans(db.database());
+ }
+
+ @Test
+ public void migrate_empty_db() throws Exception {
+ migration.execute();
+ }
+
+ @Test
+ public void migrate() throws Exception {
+ db.prepareDbUnit(this.getClass(), "migrate.xml");
+ migration.execute();
+ db.assertDbUnit(this.getClass(), "migrate-result.xml", "metrics");
+ }
+}
assertThat(result.isUserManaged()).isTrue();
assertThat(result.getWorstValue()).isNull();
assertThat(result.getBestValue()).isNull();
- assertThat(result.isOptimizedBestValue()).isNull();
- assertThat(result.isDeleteHistoricalData()).isNull();
- assertThat(result.isHidden()).isNull();
+ assertThat(result.isOptimizedBestValue()).isFalse();
+ assertThat(result.isDeleteHistoricalData()).isFalse();
+ assertThat(result.isHidden()).isFalse();
assertThat(result.isEnabled()).isTrue();
}
--- /dev/null
+<dataset>
+
+ <metrics id="1" user_managed="[true]" optimized_best_value="[false]" hidden="[false]" delete_historical_data="[false]" />
+ <metrics id="2" user_managed="[false]" optimized_best_value="[true]" hidden="[true]" delete_historical_data="[true]" />
+ <metrics id="3" user_managed="[false]" optimized_best_value="[false]" hidden="[false]" delete_historical_data="[false]"/>
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <metrics id="1" user_managed="[true]" optimized_best_value="[null]" hidden="[null]" delete_historical_data="[null]"/>
+ <metrics id="2" user_managed="[false]" optimized_best_value="[true]" hidden="[true]" delete_historical_data="[true]"/>
+ <metrics id="3" user_managed="[false]" optimized_best_value="[null]" hidden="[null]" delete_historical_data="[null]"/>
+
+</dataset>
--- /dev/null
+CREATE TABLE "METRICS" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN
+);
<dataset>
<metrics id="1" name="manual" val_type="INT" description="Manual metric" domain="" short_name="Manual metric"
- qualitative="[false]" enabled="[true]" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="[null]"
- origin="GUI" delete_historical_data="[null]" user_managed="[true]"/>
+ qualitative="[false]" enabled="[true]" worst_value="[null]" optimized_best_value="[false]" best_value="[null]" direction="0" hidden="[false]"
+ origin="GUI" delete_historical_data="[false]" user_managed="[true]"/>
</dataset>
--- /dev/null
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+#
+# SonarQube 5.2
+# SONAR-6571
+#
+class FeedMetricsBooleans < ActiveRecord::Migration
+
+ def self.up
+ execute_java_migration('org.sonar.server.db.migrations.v52.FeedMetricsBooleans')
+ end
+
+end
private Double bestValue;
- private Boolean optimizedBestValue;
+ private boolean optimizedBestValue;
private String origin;
- private Boolean hidden;
+ private boolean hidden;
- private Boolean deleteHistoricalData;
+ private boolean deleteHistoricalData;
private boolean enabled;
return this;
}
- /**
- * @return null for manual metrics
- */
- @CheckForNull
- public Boolean isOptimizedBestValue() {
+ public boolean isOptimizedBestValue() {
return optimizedBestValue;
}
- public MetricDto setOptimizedBestValue(@Nullable Boolean optimizedBestValue) {
+ public MetricDto setOptimizedBestValue(boolean optimizedBestValue) {
this.optimizedBestValue = optimizedBestValue;
return this;
}
return this;
}
- /**
- * @return null for manual metrics
- */
- @CheckForNull
- public Boolean isHidden() {
+ public boolean isHidden() {
return hidden;
}
- public MetricDto setHidden(@Nullable Boolean hidden) {
+ public MetricDto setHidden(boolean hidden) {
this.hidden = hidden;
return this;
}
- /**
- * @return null for manual metrics
- */
- @CheckForNull
- public Boolean isDeleteHistoricalData() {
+ public boolean isDeleteHistoricalData() {
return deleteHistoricalData;
}
- public MetricDto setDeleteHistoricalData(@Nullable Boolean deleteHistoricalData) {
+ public MetricDto setDeleteHistoricalData(boolean deleteHistoricalData) {
this.deleteHistoricalData = deleteHistoricalData;
return this;
}
@ServerSide
public class DatabaseVersion {
- public static final int LAST_VERSION = 915;
+ public static final int LAST_VERSION = 916;
/**
* List of all the tables.n
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('913');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('914');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('915');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('916');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;