From: Julien Lancelot Date: Tue, 21 May 2013 12:14:58 +0000 (+0200) Subject: SONAR-4301 Replace issues.severity column type from String to Integer X-Git-Tag: 3.6~327 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2c2728075a1c142965bf6c018ba94919955f80d8;p=sonarqube.git SONAR-4301 Replace issues.severity column type from String to Integer --- diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java index e45a749a33d..170bf467e3c 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java @@ -43,7 +43,6 @@ import org.sonar.core.issue.db.IssueDto; import org.sonar.core.issue.workflow.IssueWorkflow; import java.util.Collection; -import java.util.Map; @DependedUpon(DecoratorBarriers.END_OF_ISSUES_UPDATES) public class IssueTrackingDecorator implements Decorator { @@ -148,11 +147,11 @@ public class IssueTrackingDecorator implements Decorator { // fields to update with current values if (ref.isManualSeverity()) { issue.setManualSeverity(true); - issue.setSeverity(ref.getSeverity()); + issue.setSeverity(ref.getSeverityLabel()); } else { // Emulate change of severity in the current scan. String severity = issue.severity(); - issue.setSeverity(ref.getSeverity()); + issue.setSeverity(ref.getSeverityLabel()); updater.setSeverity(issue, severity, changeContext); } Integer line = issue.line(); diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java index de545172be5..8bf64abc1a3 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java @@ -21,14 +21,18 @@ package org.sonar.core.issue.db; import com.google.common.base.Objects; import com.google.common.base.Preconditions; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.rule.RuleKey; +import org.sonar.api.rule.Severity; import org.sonar.api.utils.KeyValueFormat; import org.sonar.core.issue.DefaultIssue; import javax.annotation.CheckForNull; import javax.annotation.Nullable; + import java.util.Date; /** @@ -40,7 +44,7 @@ public final class IssueDto { private String kee; private Integer resourceId; private Integer ruleId; - private String severity; + private Integer severity; private boolean manualSeverity; private String message; private Integer line; @@ -115,11 +119,11 @@ public final class IssueDto { } @CheckForNull - public String getSeverity() { + public Integer getSeverity() { return severity; } - public IssueDto setSeverity(@Nullable String severity) { + public IssueDto setSeverity(@Nullable Integer severity) { this.severity = severity; return this; } @@ -288,6 +292,11 @@ public final class IssueDto { return componentKey; } + @CheckForNull + public String getSeverityLabel() { + return severity != null ? Severity.ALL.get(severity - 1) : null; + } + /** * Only for unit tests */ @@ -310,6 +319,18 @@ public final class IssueDto { return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); } + private static Integer toSeverityIndex(final String severity){ + if (severity != null) { + return Iterables.indexOf(Severity.ALL, new Predicate() { + @Override + public boolean apply(String currentSeverity) { + return currentSeverity.equals(severity); + } + }) + 1; + } + return null; + } + public static IssueDto toDtoForInsert(DefaultIssue issue, Integer componentId, Integer ruleId, Date now) { return new IssueDto() .setKee(issue.key()) @@ -318,7 +339,7 @@ public final class IssueDto { .setEffortToFix(issue.effortToFix()) .setResolution(issue.resolution()) .setStatus(issue.status()) - .setSeverity(issue.severity()) + .setSeverity(toSeverityIndex(issue.severity())) .setChecksum(issue.getChecksum()) .setManualSeverity(issue.manualSeverity()) .setReporter(issue.reporter()) @@ -345,7 +366,7 @@ public final class IssueDto { .setEffortToFix(issue.effortToFix()) .setResolution(issue.resolution()) .setStatus(issue.status()) - .setSeverity(issue.severity()) + .setSeverity(toSeverityIndex(issue.severity())) .setChecksum(issue.getChecksum()) .setManualSeverity(issue.manualSeverity()) .setReporter(issue.reporter()) @@ -367,7 +388,7 @@ public final class IssueDto { issue.setMessage(message); issue.setEffortToFix(effortToFix); issue.setLine(line); - issue.setSeverity(severity); + issue.setSeverity(getSeverityLabel()); issue.setReporter(reporter); issue.setAssignee(assignee); issue.setAttributes(KeyValueFormat.parse(Objects.firstNonNull(attributes, ""))); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index aafefbd4286..39fdd04cd98 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -32,7 +32,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 397; + public static final int LAST_VERSION = 399; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index 9717a2417cf..01991164893 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -210,9 +210,9 @@ #{key} - + and i.severity in - #{severity} + #{severity} diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 6b3fcd5313f..2311cec80a3 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -159,9 +159,9 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('388'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('391'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('392'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('394'); -INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('395'); -INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('396'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('397'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('398'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('399'); 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', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 640817337a5..e7bcf22855a 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -521,7 +521,7 @@ CREATE TABLE "ISSUES" ( "KEE" VARCHAR(50) UNIQUE NOT NULL, "RESOURCE_ID" INTEGER NOT NULL, "RULE_ID" INTEGER, - "SEVERITY" VARCHAR(10), + "SEVERITY" INTEGER, "MANUAL_SEVERITY" BOOLEAN NOT NULL, "MESSAGE" VARCHAR(4000), "LINE" INTEGER, diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java index cfb30567f21..3c962585f19 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java @@ -51,7 +51,7 @@ public class IssueDaoTest extends AbstractDaoTestCase { assertThat(issue.getId()).isEqualTo(100L); assertThat(issue.getResourceId()).isEqualTo(401); assertThat(issue.getRuleId()).isEqualTo(500); - assertThat(issue.getSeverity()).isEqualTo("BLOCKER"); + assertThat(issue.getSeverity()).isEqualTo(5); assertThat(issue.isManualSeverity()).isFalse(); assertThat(issue.getMessage()).isNull(); assertThat(issue.getLine()).isEqualTo(200); @@ -227,9 +227,9 @@ public class IssueDaoTest extends AbstractDaoTestCase { IssueQuery query = IssueQuery.builder().sort(IssueQuery.Sort.SEVERITY).asc(true).build(); List results = newArrayList(dao.select(query)); assertThat(results).hasSize(3); - assertThat(results.get(0).getSeverity()).isEqualTo("BLOCKER"); - assertThat(results.get(1).getSeverity()).isEqualTo("MAJOR"); - assertThat(results.get(2).getSeverity()).isEqualTo("MINOR"); + assertThat(results.get(0).getSeverityLabel()).isEqualTo("MINOR"); + assertThat(results.get(1).getSeverityLabel()).isEqualTo("MAJOR"); + assertThat(results.get(2).getSeverityLabel()).isEqualTo("BLOCKER"); } @Test diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java index 9598b8c796d..551dc0926e3 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java @@ -63,7 +63,7 @@ public class IssueDtoTest { .setResolution(Issue.RESOLUTION_FALSE_POSITIVE) .setEffortToFix(15.0) .setLine(6) - .setSeverity("BLOCKER") + .setSeverity(5) .setMessage("message") .setManualSeverity(true) .setReporter("arthur") diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java index d606a87080d..7767c139710 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java @@ -46,7 +46,7 @@ public class IssueMapperTest extends AbstractDaoTestCase { dto.setEffortToFix(3.14); dto.setResolution("FIXED"); dto.setStatus("RESOLVED"); - dto.setSeverity("BLOCKER"); + dto.setSeverity(5); dto.setReporter("emmerik"); dto.setAuthorLogin("morgan"); dto.setAssignee("karadoc"); @@ -79,7 +79,7 @@ public class IssueMapperTest extends AbstractDaoTestCase { dto.setEffortToFix(3.14); dto.setResolution("FIXED"); dto.setStatus("RESOLVED"); - dto.setSeverity("BLOCKER"); + dto.setSeverity(5); dto.setReporter("emmerik"); dto.setAuthorLogin("morgan"); dto.setAssignee("karadoc"); diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanStatsDaoTest/should_find_by_project.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanStatsDaoTest/should_find_by_project.xml index f960ecd1b62..af6e601bb18 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanStatsDaoTest/should_find_by_project.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanStatsDaoTest/should_find_by_project.xml @@ -8,7 +8,7 @@ kee="ABCDE" resource_id="400" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -32,7 +32,7 @@ kee="ABCDF" resource_id="400" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -56,7 +56,7 @@ kee="ABCDG" resource_id="400" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_all.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_all.xml index 3d7bd96af21..fb1aedd7222 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_all.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_all.xml @@ -6,7 +6,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -30,7 +30,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -56,7 +56,7 @@ kee="ABCDE-3" resource_id="401" rule_id="501" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_action_plans.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_action_plans.xml index 5655372b58e..de78e71414d 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_action_plans.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_action_plans.xml @@ -6,7 +6,7 @@ resource_id="401" rule_id="500" action_plan_key="ABC" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -31,7 +31,7 @@ resource_id="401" rule_id="500" action_plan_key="ABC" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -57,7 +57,7 @@ resource_id="401" rule_id="501" action_plan_key="DEF" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml index f25c1c9e8ea..1d3d7943d7e 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml @@ -6,7 +6,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -30,7 +30,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -56,7 +56,7 @@ kee="ABCDE-3" resource_id="401" rule_id="501" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_component_root.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_component_root.xml index 34f07c20209..2319088e7f0 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_component_root.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_component_root.xml @@ -5,7 +5,7 @@ kee="100" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -29,7 +29,7 @@ kee="101" resource_id="402" rule_id="501" - severity="MAJOR" + severity="3" manual_severity="[false]" message="[null]" line="120" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml index 9b6f20c96ca..c1fddd480d3 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml @@ -5,7 +5,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -29,7 +29,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_ids.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_ids.xml index 3d6ad15c5a0..d6f85f325c4 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_ids.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_ids.xml @@ -6,7 +6,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -30,7 +30,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -56,7 +56,7 @@ kee="ABCDE" resource_id="401" rule_id="501" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_key.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_key.xml index d01f5342d87..88ca9ebd960 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_key.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_key.xml @@ -5,7 +5,7 @@ kee="ABCDE" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_planned.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_planned.xml index ded6b072043..9aa1641068b 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_planned.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_planned.xml @@ -6,7 +6,7 @@ resource_id="401" rule_id="500" action_plan_key="ABC" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -31,7 +31,7 @@ resource_id="401" rule_id="500" action_plan_key="ABC" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -57,7 +57,7 @@ resource_id="401" rule_id="501" action_plan_key="[null]" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_query.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_query.xml index 816742b954b..557be9b7ba5 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_query.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_query.xml @@ -5,7 +5,7 @@ kee="ABCDE" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_resolved.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_resolved.xml index 371d3da3f4f..886fb14e175 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_resolved.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_resolved.xml @@ -5,7 +5,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -29,7 +29,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -53,7 +53,7 @@ kee="ABCDE-3" resource_id="401" rule_id="501" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_rules.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_rules.xml index d2af6661a9e..d20560f0811 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_rules.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_rules.xml @@ -6,7 +6,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -30,7 +30,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -56,7 +56,7 @@ kee="ABCDE-3" resource_id="401" rule_id="501" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_and_component_ids.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_and_component_ids.xml index 3d7bd96af21..fb1aedd7222 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_and_component_ids.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_and_component_ids.xml @@ -6,7 +6,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -30,7 +30,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -56,7 +56,7 @@ kee="ABCDE-3" resource_id="401" rule_id="501" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_open_issues.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_open_issues.xml index 12f7036120e..8b3a9f44ca3 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_open_issues.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_open_issues.xml @@ -5,7 +5,7 @@ kee="100" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -29,7 +29,7 @@ kee="101" resource_id="402" rule_id="501" - severity="MAJOR" + severity="3" manual_severity="[false]" message="[null]" line="120" @@ -53,7 +53,7 @@ kee="102" resource_id="402" rule_id="501" - severity="MAJOR" + severity="3" manual_severity="[false]" message="[null]" line="120" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_assignee.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_assignee.xml index 41a97ef98b8..2f902a85565 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_assignee.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_assignee.xml @@ -6,7 +6,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -30,7 +30,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -56,7 +56,7 @@ kee="ABCDE-3" resource_id="401" rule_id="501" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_close_date.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_close_date.xml index b27051ff207..9339d6e437e 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_close_date.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_close_date.xml @@ -6,7 +6,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -30,7 +30,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -56,7 +56,7 @@ kee="ABCDE-3" resource_id="401" rule_id="501" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_creation_date.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_creation_date.xml index d84b71fa09b..b4c6ba44d29 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_creation_date.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_creation_date.xml @@ -5,7 +5,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -29,7 +29,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -53,7 +53,7 @@ kee="ABCDE-3" resource_id="401" rule_id="501" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_severity.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_severity.xml index 9dae4080973..e5ffc2e5fda 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_severity.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_severity.xml @@ -5,7 +5,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="MINOR" + severity="2" manual_severity="[false]" message="[null]" line="200" @@ -29,7 +29,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -53,7 +53,7 @@ kee="ABCDE-3" resource_id="401" rule_id="501" - severity="MAJOR" + severity="3" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_status.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_status.xml index b510a5c447a..4e12d924be8 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_status.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_status.xml @@ -6,7 +6,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -30,7 +30,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -56,7 +56,7 @@ kee="ABCDE-3" resource_id="401" rule_id="501" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_update_date.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_update_date.xml index 769bae1454d..a74da66a8c8 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_update_date.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result_by_update_date.xml @@ -5,7 +5,7 @@ kee="ABCDE-1" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -29,7 +29,7 @@ kee="ABCDE-2" resource_id="401" rule_id="500" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" @@ -53,7 +53,7 @@ kee="ABCDE-3" resource_id="401" rule_id="501" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="[null]" line="200" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testInsert-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testInsert-result.xml index 69e5160f962..e32f7d9f30c 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testInsert-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testInsert-result.xml @@ -4,7 +4,7 @@ kee="ABCDE" resource_id="123" rule_id="200" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="the message" line="500" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml index 57bc88451ea..7bcccd58b05 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml @@ -23,7 +23,7 @@ kee="ABCDE" resource_id="123" rule_id="200" - severity="BLOCKER" + severity="5" manual_severity="[false]" message="the message" line="500" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate.xml index 06ee1af1b50..9e13008d3db 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate.xml @@ -23,7 +23,7 @@ kee="ABCDE" resource_id="123" rule_id="200" - severity="INFO" + severity="1" manual_severity="[false]" message="old" line="[null]" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml index 97ca9b21656..0a10ae36591 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml @@ -1,5 +1,5 @@ - - - - severitiesIndexSql; + private IssueQuery(Builder builder) { this.issueKeys = builder.issueKeys; this.severities = builder.severities; @@ -89,6 +98,8 @@ public class IssueQuery { this.pageSize = builder.pageSize; this.pageIndex = builder.pageIndex; this.requiredRole = builder.requiredRole; + + this.severitiesIndexSql = severitiesIndexSql(severities); } public Collection issueKeys() { @@ -181,6 +192,23 @@ public class IssueQuery { return new Builder(); } + private Collection severitiesIndexSql(@Nullable Collection severities) { + if (severities != null) { + return newArrayList(Iterables.transform(severities, new Function() { + @Override + public Integer apply(final String currentSeverity) { + return Iterables.indexOf(Severity.ALL, new Predicate() { + @Override + public boolean apply(String severity) { + return severity.equals(currentSeverity); + } + }) + 1; + }; + })); + } + return null; + } + public static class Builder { private Collection issueKeys; private Collection severities; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java index fb972c40cee..938c5ff56f9 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java @@ -71,6 +71,7 @@ public class IssueQueryTest { assertThat(query.pageSize()).isEqualTo(10); assertThat(query.pageIndex()).isEqualTo(2); assertThat(query.requiredRole()).isEqualTo(UserRole.CODEVIEWER); + assertThat(query.severitiesIndexSql).containsOnly(5); } @Test diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/395_create_issues.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/395_create_issues.rb deleted file mode 100644 index 2733202a82e..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/395_create_issues.rb +++ /dev/null @@ -1,66 +0,0 @@ -# -# Sonar, entreprise quality control tool. -# Copyright (C) 2008-2013 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. -# - -# -# Sonar 3.6 -# -class CreateIssues < ActiveRecord::Migration - - def self.up - create_table :issues do |t| - t.column :kee, :string, :null => false, :limit => 50 - t.column :resource_id, :integer, :null => false - t.column :rule_id, :integer, :null => true - t.column :severity, :string, :null => true, :limit => 10 - t.column :manual_severity, :boolean, :null => false - t.column :message, :string, :null => true, :limit => 4000 - t.column :line, :integer, :null => true - t.column :effort_to_fix, :decimal, :null => true, :precision => 30, :scale => 20 - t.column :status, :string , :null => true, :limit => 20 - t.column :resolution, :string , :null => true, :limit => 20 - t.column :checksum, :string , :null => true, :limit => 1000 - t.column :reporter, :string, :null => true, :limit => 40 - t.column :assignee, :string, :null => true, :limit => 40 - t.column :author_login, :string, :null => true, :limit => 100 - t.column :action_plan_key, :string, :null => true, :limit => 50 - t.column :attributes, :string, :null => true, :limit => 4000 - - # functional dates - t.column :issue_creation_date, :datetime, :null => true - t.column :issue_close_date, :datetime, :null => true - t.column :issue_update_date, :datetime, :null => true - - # technical dates - t.column :created_at, :datetime, :null => true - t.column :updated_at, :datetime, :null => true - end - - add_index :issues, :kee, :name => 'issues_kee', :unique => true - add_index :issues, :resource_id, :name => 'issues_resource_id' - add_index :issues, :rule_id, :name => 'issues_rule_id' - add_index :issues, :severity, :name => 'issues_severity' - add_index :issues, :status, :name => 'issues_status' - add_index :issues, :assignee, :name => 'issues_assignee' - add_index :issues, :action_plan_key, :name => 'issues_action_plan_key' - add_index :issues, :issue_creation_date, :name => 'issues_creation_date' - end - -end - diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/396_create_issue_changes.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/396_create_issue_changes.rb deleted file mode 100644 index 016380cf8f6..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/396_create_issue_changes.rb +++ /dev/null @@ -1,42 +0,0 @@ -# -# Sonar, entreprise quality control tool. -# Copyright (C) 2008-2013 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. -# - -# -# Sonar 3.6 -# -class CreateIssueChanges < ActiveRecord::Migration - - def self.up - create_table :issue_changes do |t| - t.column :kee, :string, :null => true, :limit => 50 - t.column :issue_key, :string, :null => false, :limit => 50 - t.column :user_login, :string, :null => true, :limit => 40 - t.column :change_type, :string, :null => true, :limit => 20 - t.column :change_data, :text, :null => true - t.column :created_at, :datetime, :null => true - t.column :updated_at, :datetime, :null => true - end - - add_index :issue_changes, :kee, :name => 'issue_changes_kee' - add_index :issue_changes, :issue_key, :name => 'issue_changes_issue_key' - end - -end - diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/398_create_issues.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/398_create_issues.rb new file mode 100644 index 00000000000..7a262906d3d --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/398_create_issues.rb @@ -0,0 +1,66 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2013 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. +# + +# +# Sonar 3.6 +# +class CreateIssues < ActiveRecord::Migration + + def self.up + create_table :issues do |t| + t.column :kee, :string, :null => false, :limit => 50 + t.column :resource_id, :integer, :null => false + t.column :rule_id, :integer, :null => true + t.column :severity, :integer, :null => true + t.column :manual_severity, :boolean, :null => false + t.column :message, :string, :null => true, :limit => 4000 + t.column :line, :integer, :null => true + t.column :effort_to_fix, :decimal, :null => true, :precision => 30, :scale => 20 + t.column :status, :string , :null => true, :limit => 20 + t.column :resolution, :string , :null => true, :limit => 20 + t.column :checksum, :string , :null => true, :limit => 1000 + t.column :reporter, :string, :null => true, :limit => 40 + t.column :assignee, :string, :null => true, :limit => 40 + t.column :author_login, :string, :null => true, :limit => 100 + t.column :action_plan_key, :string, :null => true, :limit => 50 + t.column :attributes, :string, :null => true, :limit => 4000 + + # functional dates + t.column :issue_creation_date, :datetime, :null => true + t.column :issue_close_date, :datetime, :null => true + t.column :issue_update_date, :datetime, :null => true + + # technical dates + t.column :created_at, :datetime, :null => true + t.column :updated_at, :datetime, :null => true + end + + add_index :issues, :kee, :name => 'issues_kee', :unique => true + add_index :issues, :resource_id, :name => 'issues_resource_id' + add_index :issues, :rule_id, :name => 'issues_rule_id' + add_index :issues, :severity, :name => 'issues_severity' + add_index :issues, :status, :name => 'issues_status' + add_index :issues, :assignee, :name => 'issues_assignee' + add_index :issues, :action_plan_key, :name => 'issues_action_plan_key' + add_index :issues, :issue_creation_date, :name => 'issues_creation_date' + end + +end + diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/399_create_issue_changes.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/399_create_issue_changes.rb new file mode 100644 index 00000000000..016380cf8f6 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/399_create_issue_changes.rb @@ -0,0 +1,42 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2013 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. +# + +# +# Sonar 3.6 +# +class CreateIssueChanges < ActiveRecord::Migration + + def self.up + create_table :issue_changes do |t| + t.column :kee, :string, :null => true, :limit => 50 + t.column :issue_key, :string, :null => false, :limit => 50 + t.column :user_login, :string, :null => true, :limit => 40 + t.column :change_type, :string, :null => true, :limit => 20 + t.column :change_data, :text, :null => true + t.column :created_at, :datetime, :null => true + t.column :updated_at, :datetime, :null => true + end + + add_index :issue_changes, :kee, :name => 'issue_changes_kee' + add_index :issue_changes, :issue_key, :name => 'issue_changes_issue_key' + end + +end +