class ActiveRuleDaoIT {
private static final long NOW = 10_000_000L;
+ public static final String IMPACTS = "{\\“SECURITY\\”:\\”BLOCKER\\”,\\”MAINTAINABILITY\\”:\\”INFO\\”}";
private QProfileDto profile1;
private QProfileDto profile2;
ActiveRuleDto activeRule = createFor(profile1, rule1)
.setSeverity(BLOCKER)
.setInheritance(INHERITED)
+ .setImpacts(IMPACTS)
.setIsExternal(false)
.setCreatedAt(1000L)
.setUpdatedAt(2000L);
assertThat(result.getProfileUuid()).isEqualTo(profile1.getRulesProfileUuid());
assertThat(result.getSeverityString()).isEqualTo(BLOCKER);
assertThat(result.getInheritance()).isEqualTo(INHERITED);
+ assertThat(result.getImpacts()).isEqualTo(IMPACTS);
assertThat(result.isExternal()).isFalse();
assertThat(result.getCreatedAt()).isEqualTo(1000L);
assertThat(result.getUpdatedAt()).isEqualTo(2000L);
ActiveRuleDto activeRule = createFor(profile1, rule1)
.setSeverity(BLOCKER)
.setInheritance(INHERITED)
+ .setImpacts("{\"RELIABILITY\":\"INFO\"}")
.setCreatedAt(1000L)
.setUpdatedAt(2000L);
underTest.insert(dbSession, activeRule);
ActiveRuleDto activeRuleUpdated = activeRule
.setSeverity(MAJOR)
.setInheritance(OVERRIDES)
+ .setImpacts(IMPACTS)
// created at should not be updated
.setCreatedAt(3000L)
.setUpdatedAt(4000L);
assertThat(result.getProfileUuid()).isEqualTo(profile1.getRulesProfileUuid());
assertThat(result.getSeverityString()).isEqualTo(MAJOR);
assertThat(result.getInheritance()).isEqualTo(OVERRIDES);
+ assertThat(result.getImpacts()).isEqualTo(IMPACTS);
assertThat(result.getCreatedAt()).isEqualTo(1000L);
assertThat(result.getUpdatedAt()).isEqualTo(4000L);
}
private String ruleUuid;
private Integer severity;
private String inheritance;
+ private String impacts;
private long createdAt;
private long updatedAt;
private boolean prioritizedRule;
- // These fields do not exists in db, it's only retrieve by joins
+ // These fields do not exist in db, it's only retrieve by joins
private String repository;
private String ruleField;
private String ruleProfileUuid;
return this;
}
+ @CheckForNull
+ public String getImpacts() {
+ return impacts;
+ }
+
+ public ActiveRuleDto setImpacts(@Nullable String impacts) {
+ this.impacts = impacts;
+ return this;
+ }
+
public boolean isExternal() {
return this.isExternal;
}
return this;
}
- public boolean isPrioritizedRule(){
+ public boolean isPrioritizedRule() {
return prioritizedRule;
}
- public ActiveRuleDto setPrioritizedRule(boolean prioritizedRule){
+ public ActiveRuleDto setPrioritizedRule(boolean prioritizedRule) {
this.prioritizedRule = prioritizedRule;
return this;
}
a.rule_uuid as "ruleUuid",
a.failure_level as "severity",
a.inheritance as "inheritance",
+ a.impacts as "impacts",
r.plugin_rule_key as "rulefield",
r.plugin_name as "repository",
rp.uuid as "ruleProfileUuid",
a.rule_uuid as "ruleUuid",
a.failure_level as "severity",
a.inheritance as "inheritance",
+ a.impacts as "impacts",
a.prioritized_rule as "prioritizedRule",
r.plugin_rule_key as "rulefield",
r.plugin_name as "repository",
rule_uuid,
failure_level,
inheritance,
+ impacts,
prioritized_rule,
created_at,
updated_at
#{ruleUuid, jdbcType=VARCHAR},
#{severity, jdbcType=INTEGER},
#{inheritance, jdbcType=VARCHAR},
+ #{impacts, jdbcType=VARCHAR},
#{prioritizedRule, jdbcType=BOOLEAN},
#{createdAt, jdbcType=BIGINT},
#{updatedAt, jdbcType=BIGINT}
set
failure_level = #{severity, jdbcType=INTEGER},
inheritance = #{inheritance, jdbcType=VARCHAR},
+ impacts = #{impacts, jdbcType=VARCHAR},
prioritized_rule = #{prioritizedRule, jdbcType=BOOLEAN},
updated_at = #{updatedAt, jdbcType=BIGINT}
where
ar.uuid as "uuid",
ar.failure_level as "severity",
ar.inheritance as "inheritance",
+ ar.impacts as "impacts",
ar.prioritized_rule as "prioritizedRule",
r.uuid as "ruleUuid",
r.plugin_name as "repository",
"UPDATED_AT" BIGINT,
"PROFILE_UUID" CHARACTER VARYING(40) NOT NULL,
"RULE_UUID" CHARACTER VARYING(40) NOT NULL,
- "PRIORITIZED_RULE" BOOLEAN
+ "PRIORITIZED_RULE" BOOLEAN,
+ "IMPACTS" CHARACTER VARYING(500)
);
ALTER TABLE "ACTIVE_RULES" ADD CONSTRAINT "PK_ACTIVE_RULES" PRIMARY KEY("UUID");
CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_PROFILE_RULE_UUIDS" ON "ACTIVE_RULES"("PROFILE_UUID" NULLS FIRST, "RULE_UUID" NULLS FIRST);
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v108;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.db.DatabaseUtils.tableColumnExists;
+
+public class AddImpactsColumnInActiveRulesTable extends DdlChange {
+ static final String ACTIVE_RULES_TABLE_NAME = "active_rules";
+ static final String IMPACTS = "impacts";
+
+ public AddImpactsColumnInActiveRulesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (var connection = getDatabase().getDataSource().getConnection()) {
+ if (!tableColumnExists(connection, ACTIVE_RULES_TABLE_NAME, IMPACTS)) {
+ var columnDef = VarcharColumnDef.newVarcharColumnDefBuilder()
+ .setColumnName(IMPACTS)
+ .setIsNullable(true)
+ .setLimit(500)
+ .build();
+ context.execute(new AddColumnsBuilder(getDialect(), ACTIVE_RULES_TABLE_NAME)
+ .addColumn(columnDef)
+ .build());
+ }
+ }
+ }
+}
.add(10_8_012, "Drop 'measures_migrated' column on 'portfolios' table", DropMeasuresMigratedColumnInPortfoliosTable.class)
.add(10_8_013, "Drop index on 'project_branches.measures_migrated'", DropIndexOnProjectBranchesMeasuresMigrated.class)
.add(10_8_014, "Drop 'measures_migrated' column on 'project_branches' table", DropMeasuresMigratedColumnInProjectBranchesTable.class)
+ .add(10_8_015, "Add column 'impacts' in 'active_rules' table", AddImpactsColumnInActiveRulesTable.class)
;
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v108;
+
+import java.sql.SQLException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.sonar.db.MigrationDbTester;
+
+import static java.sql.Types.VARCHAR;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
+import static org.sonar.server.platform.db.migration.version.v108.AddImpactsColumnInActiveRulesTable.ACTIVE_RULES_TABLE_NAME;
+import static org.sonar.server.platform.db.migration.version.v108.AddImpactsColumnInActiveRulesTable.IMPACTS;
+
+class AddImpactsColumnInActiveRulesTableTest {
+
+ @RegisterExtension
+ public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(AddImpactsColumnInActiveRulesTable.class);
+
+ private final AddImpactsColumnInActiveRulesTable underTest = new AddImpactsColumnInActiveRulesTable(db.database());
+
+ @Test
+ void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException {
+ db.assertColumnDoesNotExist(ACTIVE_RULES_TABLE_NAME, IMPACTS);
+ underTest.execute();
+ assertColumnExists();
+ }
+
+ @Test
+ void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException {
+ underTest.execute();
+ assertColumnExists();
+ assertThatCode(underTest::execute).doesNotThrowAnyException();
+ }
+
+ private void assertColumnExists() {
+ db.assertColumnDefinition(ACTIVE_RULES_TABLE_NAME, IMPACTS, VARCHAR, 500, true);
+ }
+
+}