From efa3b414435a343ab9435e61e52a2ed1fcf1222a Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 3 Apr 2020 15:57:23 +0200 Subject: [PATCH] SONAR-13221 Set primary key of 'ISSUES' table to column 'KEE' and drop 'ID' * SONAR-13221 Set primary key of 'ISSUES' table to column 'KEE' and drop 'ID' * SONAR-13221 Move events migration in a dedicated package --- .../step/PersistIssuesStepTest.java | 4 +- .../java/org/sonar/db/issue/IssueDto.java | 10 ---- .../org/sonar/db/issue/IssueMapper.xml | 3 +- server/sonar-db-dao/src/schema/schema-sq.ddl | 3 +- .../java/org/sonar/db/issue/IssueDaoTest.java | 1 - .../org/sonar/db/issue/IssueMapperTest.java | 2 - .../db/migration/version/v83/DbVersion83.java | 11 ++++ ...ddPrimaryKeyOnUuidColumnOfEventsTable.java | 2 +- .../DropIdColumnOfEventsTable.java | 2 +- ...DropPrimaryKeyOnIdColumnOfEventsTable.java | 2 +- ...AddPrimaryKeyOnKeeColumnOfIssuesTable.java | 38 +++++++++++++ .../v83/issues/DropIdColumnOfIssuesTable.java | 41 ++++++++++++++ ...DropPrimaryKeyOnIdColumnOfIssuesTable.java | 41 ++++++++++++++ ...imaryKeyOnUuidColumnOfEventsTableTest.java | 2 +- .../DropIdColumnOfEventsTableTest.java | 2 +- ...PrimaryKeyOnIdColumnOfEventsTableTest.java | 2 +- ...rimaryKeyOnKeeColumnOfIssuesTableTest.java | 49 +++++++++++++++++ .../issues/DropIdColumnOfIssuesTableTest.java | 50 +++++++++++++++++ ...PrimaryKeyOnIdColumnOfIssuesTableTest.java | 55 +++++++++++++++++++ .../schema.sql | 0 .../DropIdColumnOfEventsTableTest/schema.sql | 0 .../schema.sql | 0 .../schema.sql | 38 +++++++++++++ .../DropIdColumnOfIssuesTableTest/schema.sql | 39 +++++++++++++ .../schema.sql | 39 +++++++++++++ .../server/issue/ws/ChangelogAction.java | 4 +- .../server/issue/IssuesFinderSortTest.java | 44 +++++++-------- 27 files changed, 434 insertions(+), 50 deletions(-) rename server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/{ => events}/AddPrimaryKeyOnUuidColumnOfEventsTable.java (95%) rename server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/{ => events}/DropIdColumnOfEventsTable.java (95%) rename server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/{ => events}/DropPrimaryKeyOnIdColumnOfEventsTable.java (95%) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/issues/AddPrimaryKeyOnKeeColumnOfIssuesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/issues/DropIdColumnOfIssuesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/issues/DropPrimaryKeyOnIdColumnOfIssuesTable.java rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/{ => events}/AddPrimaryKeyOnUuidColumnOfEventsTableTest.java (96%) rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/{ => events}/DropIdColumnOfEventsTableTest.java (96%) rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/{ => events}/DropPrimaryKeyOnIdColumnOfEventsTableTest.java (96%) create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/issues/AddPrimaryKeyOnKeeColumnOfIssuesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/issues/DropIdColumnOfIssuesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest.java rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/{ => events}/AddPrimaryKeyOnUuidColumnOfEventsTableTest/schema.sql (100%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/{ => events}/DropIdColumnOfEventsTableTest/schema.sql (100%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/{ => events}/DropPrimaryKeyOnIdColumnOfEventsTableTest/schema.sql (100%) create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/issues/AddPrimaryKeyOnKeeColumnOfIssuesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/issues/DropIdColumnOfIssuesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest/schema.sql diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java index 5941fe60b4e..71fae1ae36e 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java @@ -60,7 +60,6 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.MapEntry.entry; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -258,10 +257,9 @@ public class PersistIssuesStepTest extends BaseStepTest { ArgumentCaptor issueDtoCaptor = ArgumentCaptor.forClass(IssueDto.class); verify(conflictResolver).resolve(eq(defaultIssue), issueDtoCaptor.capture(), any(IssueMapper.class)); - assertThat(issueDtoCaptor.getValue().getId()).isEqualTo(issue.getId()); + assertThat(issueDtoCaptor.getValue().getKey()).isEqualTo(issue.getKey()); assertThat(context.getStatistics().getAll()).contains( entry("inserts", "0"), entry("updates", "1"), entry("merged", "1")); - } @Test diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java index 2c151d26e79..6ce462903ca 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java @@ -54,7 +54,6 @@ public final class IssueDto implements Serializable { private static final Joiner TAGS_JOINER = Joiner.on(TAGS_SEPARATOR).skipNulls(); private static final Splitter TAGS_SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings(); - private Long id; private int type; private String kee; private String componentUuid; @@ -190,15 +189,6 @@ public final class IssueDto implements Serializable { return getKee(); } - public Long getId() { - return id; - } - - public IssueDto setId(@Nullable Long id) { - this.id = id; - return this; - } - public String getKee() { return kee; } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml index cf6c1b87322..ad92cab0658 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml @@ -5,7 +5,6 @@ - i.id, i.kee as kee, i.rule_id as ruleId, i.severity as severity, @@ -99,7 +98,7 @@ - + INSERT INTO issues (kee, rule_id, severity, manual_severity, message, line, locations, gap, effort, status, tags, resolution, checksum, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date, diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 0af1d35bc97..74be76f621f 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -379,7 +379,6 @@ CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY"); CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE"); CREATE TABLE "ISSUES"( - "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), "KEE" VARCHAR(50) NOT NULL, "RULE_ID" INTEGER, "SEVERITY" VARCHAR(10), @@ -408,7 +407,7 @@ CREATE TABLE "ISSUES"( "ISSUE_TYPE" TINYINT, "FROM_HOTSPOT" BOOLEAN ); -ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("ID"); +ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE"); CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE"); CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID"); CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE"); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java index 0e5e3280444..daeba88d07e 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java @@ -79,7 +79,6 @@ public class IssueDaoTest { IssueDto issue = underTest.selectOrFailByKey(db.getSession(), ISSUE_KEY1); assertThat(issue.getKee()).isEqualTo(ISSUE_KEY1); - assertThat(issue.getId()).isGreaterThan(0L); assertThat(issue.getComponentUuid()).isEqualTo(FILE_UUID); assertThat(issue.getProjectUuid()).isEqualTo(PROJECT_UUID); assertThat(issue.getRuleId()).isEqualTo(RULE.getId()); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java index 8e7b4ab7b4c..cecef80eeca 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java @@ -93,7 +93,6 @@ public class IssueMapperTest { IssueDto result = underTest.selectByKey("ABCDE"); assertThat(result).isNotNull(); - assertThat(result.getId()).isNotNull(); assertThat(result.getKey()).isEqualTo("ABCDE"); assertThat(result.getComponentUuid()).isEqualTo(file.uuid()); assertThat(result.getProjectUuid()).isEqualTo(project.uuid()); @@ -153,7 +152,6 @@ public class IssueMapperTest { IssueDto result = underTest.selectByKey("ABCDE"); assertThat(result).isNotNull(); - assertThat(result.getId()).isNotNull(); assertThat(result.getKey()).isEqualTo("ABCDE"); assertThat(result.getComponentUuid()).isEqualTo(file.uuid()); assertThat(result.getProjectUuid()).isEqualTo(project.uuid()); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java index b5758075011..bf8d2d0a593 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java @@ -21,6 +21,12 @@ package org.sonar.server.platform.db.migration.version.v83; import org.sonar.server.platform.db.migration.step.MigrationStepRegistry; import org.sonar.server.platform.db.migration.version.DbVersion; +import org.sonar.server.platform.db.migration.version.v83.events.AddPrimaryKeyOnUuidColumnOfEventsTable; +import org.sonar.server.platform.db.migration.version.v83.events.DropIdColumnOfEventsTable; +import org.sonar.server.platform.db.migration.version.v83.events.DropPrimaryKeyOnIdColumnOfEventsTable; +import org.sonar.server.platform.db.migration.version.v83.issues.AddPrimaryKeyOnKeeColumnOfIssuesTable; +import org.sonar.server.platform.db.migration.version.v83.issues.DropIdColumnOfIssuesTable; +import org.sonar.server.platform.db.migration.version.v83.issues.DropPrimaryKeyOnIdColumnOfIssuesTable; import org.sonar.server.platform.db.migration.version.v83.notifications.AddPrimaryKeyOnUuidColumnOfNotificationTable; import org.sonar.server.platform.db.migration.version.v83.notifications.AddUuidAndCreatedAtColumnsToNotification; import org.sonar.server.platform.db.migration.version.v83.notifications.DropIdColumnOfNotificationTable; @@ -58,6 +64,11 @@ public class DbVersion83 implements DbVersion { .add(3407, "Add primary key on 'UUID' column of 'NOTIFICATIONS' table", AddPrimaryKeyOnUuidColumnOfNotificationTable.class) .add(3408, "Drop column 'ID' of 'NOTIFICATIONS' table", DropIdColumnOfNotificationTable.class) + // Migration on ISSUES table + .add(3409, "Drop primary key on 'ID' column of 'ISSUES' table", DropPrimaryKeyOnIdColumnOfIssuesTable.class) + .add(3410, "Add primary key on 'KEE' column of 'ISSUES' table", AddPrimaryKeyOnKeeColumnOfIssuesTable.class) + .add(3411, "Drop column 'ID' of 'ISSUES' table", DropIdColumnOfIssuesTable.class) + ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddPrimaryKeyOnUuidColumnOfEventsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/events/AddPrimaryKeyOnUuidColumnOfEventsTable.java similarity index 95% rename from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddPrimaryKeyOnUuidColumnOfEventsTable.java rename to server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/events/AddPrimaryKeyOnUuidColumnOfEventsTable.java index a615d0d4df6..cbf84c5f7fa 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddPrimaryKeyOnUuidColumnOfEventsTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/events/AddPrimaryKeyOnUuidColumnOfEventsTable.java @@ -17,7 +17,7 @@ * 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.v83; +package org.sonar.server.platform.db.migration.version.v83.events; import java.sql.SQLException; import org.sonar.db.Database; diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropIdColumnOfEventsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/events/DropIdColumnOfEventsTable.java similarity index 95% rename from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropIdColumnOfEventsTable.java rename to server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/events/DropIdColumnOfEventsTable.java index 0755264dfec..fddda4a7af0 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropIdColumnOfEventsTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/events/DropIdColumnOfEventsTable.java @@ -17,7 +17,7 @@ * 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.v83; +package org.sonar.server.platform.db.migration.version.v83.events; import java.sql.SQLException; import org.sonar.db.Database; diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropPrimaryKeyOnIdColumnOfEventsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/events/DropPrimaryKeyOnIdColumnOfEventsTable.java similarity index 95% rename from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropPrimaryKeyOnIdColumnOfEventsTable.java rename to server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/events/DropPrimaryKeyOnIdColumnOfEventsTable.java index a5ca4b0366c..9e4228868fc 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DropPrimaryKeyOnIdColumnOfEventsTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/events/DropPrimaryKeyOnIdColumnOfEventsTable.java @@ -17,7 +17,7 @@ * 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.v83; +package org.sonar.server.platform.db.migration.version.v83.events; import java.sql.SQLException; import org.sonar.db.Database; diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/issues/AddPrimaryKeyOnKeeColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/issues/AddPrimaryKeyOnKeeColumnOfIssuesTable.java new file mode 100644 index 00000000000..84e03c5c4f8 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/issues/AddPrimaryKeyOnKeeColumnOfIssuesTable.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.issues; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder; + +public class AddPrimaryKeyOnKeeColumnOfIssuesTable extends DdlChange { + + public AddPrimaryKeyOnKeeColumnOfIssuesTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddPrimaryKeyBuilder("issues", "kee").build()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/issues/DropIdColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/issues/DropIdColumnOfIssuesTable.java new file mode 100644 index 00000000000..462504e6d9f --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/issues/DropIdColumnOfIssuesTable.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.issues; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropIdColumnOfIssuesTable extends DdlChange { + + private Database db; + + public DropIdColumnOfIssuesTable(Database db) { + super(db); + this.db = db; + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropColumnsBuilder(db.getDialect(), "issues", "id").build()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/issues/DropPrimaryKeyOnIdColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/issues/DropPrimaryKeyOnIdColumnOfIssuesTable.java new file mode 100644 index 00000000000..bfef73c5af9 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/issues/DropPrimaryKeyOnIdColumnOfIssuesTable.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.issues; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator; + +public class DropPrimaryKeyOnIdColumnOfIssuesTable extends DdlChange { + + private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator; + + public DropPrimaryKeyOnIdColumnOfIssuesTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) { + super(db); + this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator; + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(dropPrimaryKeySqlGenerator.generate("issues", "issues","id")); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddPrimaryKeyOnUuidColumnOfEventsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/events/AddPrimaryKeyOnUuidColumnOfEventsTableTest.java similarity index 96% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddPrimaryKeyOnUuidColumnOfEventsTableTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/events/AddPrimaryKeyOnUuidColumnOfEventsTableTest.java index d8eb67b078d..a7d546f9842 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddPrimaryKeyOnUuidColumnOfEventsTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/events/AddPrimaryKeyOnUuidColumnOfEventsTableTest.java @@ -17,7 +17,7 @@ * 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.v83; +package org.sonar.server.platform.db.migration.version.v83.events; import java.sql.SQLException; import org.junit.Rule; diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropIdColumnOfEventsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/events/DropIdColumnOfEventsTableTest.java similarity index 96% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropIdColumnOfEventsTableTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/events/DropIdColumnOfEventsTableTest.java index e82c4579dca..220f09c2aa9 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropIdColumnOfEventsTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/events/DropIdColumnOfEventsTableTest.java @@ -17,7 +17,7 @@ * 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.v83; +package org.sonar.server.platform.db.migration.version.v83.events; import java.sql.SQLException; import org.junit.Rule; diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropPrimaryKeyOnIdColumnOfEventsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/events/DropPrimaryKeyOnIdColumnOfEventsTableTest.java similarity index 96% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropPrimaryKeyOnIdColumnOfEventsTableTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/events/DropPrimaryKeyOnIdColumnOfEventsTableTest.java index 17e262b4a9c..d9700105c0c 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DropPrimaryKeyOnIdColumnOfEventsTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/events/DropPrimaryKeyOnIdColumnOfEventsTableTest.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.platform.db.migration.version.v83; +package org.sonar.server.platform.db.migration.version.v83.events; import java.sql.SQLException; import org.junit.Rule; diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/issues/AddPrimaryKeyOnKeeColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/issues/AddPrimaryKeyOnKeeColumnOfIssuesTableTest.java new file mode 100644 index 00000000000..64a7512bdac --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/issues/AddPrimaryKeyOnKeeColumnOfIssuesTableTest.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.issues; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class AddPrimaryKeyOnKeeColumnOfIssuesTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnKeeColumnOfIssuesTableTest.class, "schema.sql"); + + private AddPrimaryKeyOnKeeColumnOfIssuesTable underTest = new AddPrimaryKeyOnKeeColumnOfIssuesTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertPrimaryKey("issues", "pk_issues", "kee"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/issues/DropIdColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/issues/DropIdColumnOfIssuesTableTest.java new file mode 100644 index 00000000000..877e66ffaae --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/issues/DropIdColumnOfIssuesTableTest.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.issues; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class DropIdColumnOfIssuesTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfIssuesTableTest.class, "schema.sql"); + + private DropIdColumnOfIssuesTable underTest = new DropIdColumnOfIssuesTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertColumnDoesNotExist("issues", "id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest.java new file mode 100644 index 00000000000..7acfaaef1ac --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.issues; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator; +import org.sonar.server.platform.db.migration.version.v83.util.GetConstraintHelper; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class DropPrimaryKeyOnIdColumnOfIssuesTableTest { + + private static final String TABLE_NAME = "issues"; + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfIssuesTableTest.class, "schema.sql"); + + private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new GetConstraintHelper(db.database())); + + private DropPrimaryKeyOnIdColumnOfIssuesTable underTest = new DropPrimaryKeyOnIdColumnOfIssuesTable(db.database(), dropPrimaryKeySqlGenerator); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertNoPrimaryKey(TABLE_NAME); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddPrimaryKeyOnUuidColumnOfEventsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/events/AddPrimaryKeyOnUuidColumnOfEventsTableTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddPrimaryKeyOnUuidColumnOfEventsTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/events/AddPrimaryKeyOnUuidColumnOfEventsTableTest/schema.sql diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropIdColumnOfEventsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/events/DropIdColumnOfEventsTableTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropIdColumnOfEventsTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/events/DropIdColumnOfEventsTableTest/schema.sql diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropPrimaryKeyOnIdColumnOfEventsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/events/DropPrimaryKeyOnIdColumnOfEventsTableTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropPrimaryKeyOnIdColumnOfEventsTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/events/DropPrimaryKeyOnIdColumnOfEventsTableTest/schema.sql diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/issues/AddPrimaryKeyOnKeeColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/issues/AddPrimaryKeyOnKeeColumnOfIssuesTableTest/schema.sql new file mode 100644 index 00000000000..c195339d1d7 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/issues/AddPrimaryKeyOnKeeColumnOfIssuesTableTest/schema.sql @@ -0,0 +1,38 @@ +CREATE TABLE "ISSUES"( + "ID" BIGINT NOT NULL, + "KEE" VARCHAR(50) NOT NULL, + "RULE_ID" INTEGER, + "SEVERITY" VARCHAR(10), + "MANUAL_SEVERITY" BOOLEAN NOT NULL, + "MESSAGE" VARCHAR(4000), + "LINE" INTEGER, + "GAP" DOUBLE, + "STATUS" VARCHAR(20), + "RESOLUTION" VARCHAR(20), + "CHECKSUM" VARCHAR(1000), + "REPORTER" VARCHAR(255), + "ASSIGNEE" VARCHAR(255), + "AUTHOR_LOGIN" VARCHAR(255), + "ACTION_PLAN_KEY" VARCHAR(50), + "ISSUE_ATTRIBUTES" VARCHAR(4000), + "EFFORT" INTEGER, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CREATION_DATE" BIGINT, + "ISSUE_UPDATE_DATE" BIGINT, + "ISSUE_CLOSE_DATE" BIGINT, + "TAGS" VARCHAR(4000), + "COMPONENT_UUID" VARCHAR(50), + "PROJECT_UUID" VARCHAR(50), + "LOCATIONS" BLOB, + "ISSUE_TYPE" TINYINT, + "FROM_HOTSPOT" BOOLEAN +); +CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE"); +CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID"); +CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE"); +CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE"); +CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID"); +CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION"); +CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID"); +CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/issues/DropIdColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/issues/DropIdColumnOfIssuesTableTest/schema.sql new file mode 100644 index 00000000000..92fadc6580c --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/issues/DropIdColumnOfIssuesTableTest/schema.sql @@ -0,0 +1,39 @@ +CREATE TABLE "ISSUES"( + "ID" BIGINT NOT NULL, + "KEE" VARCHAR(50) NOT NULL, + "RULE_ID" INTEGER, + "SEVERITY" VARCHAR(10), + "MANUAL_SEVERITY" BOOLEAN NOT NULL, + "MESSAGE" VARCHAR(4000), + "LINE" INTEGER, + "GAP" DOUBLE, + "STATUS" VARCHAR(20), + "RESOLUTION" VARCHAR(20), + "CHECKSUM" VARCHAR(1000), + "REPORTER" VARCHAR(255), + "ASSIGNEE" VARCHAR(255), + "AUTHOR_LOGIN" VARCHAR(255), + "ACTION_PLAN_KEY" VARCHAR(50), + "ISSUE_ATTRIBUTES" VARCHAR(4000), + "EFFORT" INTEGER, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CREATION_DATE" BIGINT, + "ISSUE_UPDATE_DATE" BIGINT, + "ISSUE_CLOSE_DATE" BIGINT, + "TAGS" VARCHAR(4000), + "COMPONENT_UUID" VARCHAR(50), + "PROJECT_UUID" VARCHAR(50), + "LOCATIONS" BLOB, + "ISSUE_TYPE" TINYINT, + "FROM_HOTSPOT" BOOLEAN +); +ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE"); +CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE"); +CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID"); +CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE"); +CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE"); +CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID"); +CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION"); +CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID"); +CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest/schema.sql new file mode 100644 index 00000000000..cf65bc42c84 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest/schema.sql @@ -0,0 +1,39 @@ +CREATE TABLE "ISSUES"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), + "KEE" VARCHAR(50) NOT NULL, + "RULE_ID" INTEGER, + "SEVERITY" VARCHAR(10), + "MANUAL_SEVERITY" BOOLEAN NOT NULL, + "MESSAGE" VARCHAR(4000), + "LINE" INTEGER, + "GAP" DOUBLE, + "STATUS" VARCHAR(20), + "RESOLUTION" VARCHAR(20), + "CHECKSUM" VARCHAR(1000), + "REPORTER" VARCHAR(255), + "ASSIGNEE" VARCHAR(255), + "AUTHOR_LOGIN" VARCHAR(255), + "ACTION_PLAN_KEY" VARCHAR(50), + "ISSUE_ATTRIBUTES" VARCHAR(4000), + "EFFORT" INTEGER, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CREATION_DATE" BIGINT, + "ISSUE_UPDATE_DATE" BIGINT, + "ISSUE_CLOSE_DATE" BIGINT, + "TAGS" VARCHAR(4000), + "COMPONENT_UUID" VARCHAR(50), + "PROJECT_UUID" VARCHAR(50), + "LOCATIONS" BLOB, + "ISSUE_TYPE" TINYINT, + "FROM_HOTSPOT" BOOLEAN +); +ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("ID"); +CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE"); +CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID"); +CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE"); +CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE"); +CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID"); +CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION"); +CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID"); +CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT"); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java index eccc9a86d1b..48a10c0e7a6 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java @@ -98,9 +98,9 @@ public class ChangelogAction implements IssuesWsAction { private boolean isMember(DbSession dbSession, IssueDto issue) { Optional project = dbClient.componentDao().selectByUuid(dbSession, issue.getProjectUuid()); - checkState(project.isPresent(), "Cannot find the project with uuid %s from issue.id %s", issue.getProjectUuid(), issue.getId()); + checkState(project.isPresent(), "Cannot find the project with uuid %s from issue with key %s", issue.getProjectUuid(), issue.getKey()); Optional organization = dbClient.organizationDao().selectByUuid(dbSession, project.get().getOrganizationUuid()); - checkState(organization.isPresent(), "Cannot find the organization with uuid %s from issue.id %s", project.get().getOrganizationUuid(), issue.getId()); + checkState(organization.isPresent(), "Cannot find the organization with uuid %s from issue with key %s", project.get().getOrganizationUuid(), issue.getKey()); return userSession.hasMembership(organization.get()); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssuesFinderSortTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssuesFinderSortTest.java index eac3db982c7..b0374d6497d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssuesFinderSortTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/IssuesFinderSortTest.java @@ -35,9 +35,9 @@ public class IssuesFinderSortTest { @Test public void should_sort_by_status() { - IssueDto issue1 = new IssueDto().setId(1L).setStatus("CLOSED"); - IssueDto issue2 = new IssueDto().setId(2L).setStatus("REOPENED"); - IssueDto issue3 = new IssueDto().setId(3L).setStatus("OPEN"); + IssueDto issue1 = new IssueDto().setKee("A").setStatus("CLOSED"); + IssueDto issue2 = new IssueDto().setKee("B").setStatus("REOPENED"); + IssueDto issue3 = new IssueDto().setKee("C").setStatus("OPEN"); List dtoList = newArrayList(issue1, issue2, issue3); IssueQuery query = IssueQuery.builder().sort(IssueQuery.SORT_BY_STATUS).asc(false).build(); @@ -53,9 +53,9 @@ public class IssuesFinderSortTest { @Test public void should_sort_by_severity() { - IssueDto issue1 = new IssueDto().setId(1L).setSeverity("INFO"); - IssueDto issue2 = new IssueDto().setId(2L).setSeverity("BLOCKER"); - IssueDto issue3 = new IssueDto().setId(3L).setSeverity("MAJOR"); + IssueDto issue1 = new IssueDto().setKee("A").setSeverity("INFO"); + IssueDto issue2 = new IssueDto().setKee("B").setSeverity("BLOCKER"); + IssueDto issue3 = new IssueDto().setKee("C").setSeverity("MAJOR"); List dtoList = newArrayList(issue1, issue2, issue3); IssueQuery query = IssueQuery.builder().sort(IssueQuery.SORT_BY_SEVERITY).asc(true).build(); @@ -71,9 +71,9 @@ public class IssuesFinderSortTest { @Test public void should_sort_by_desc_severity() { - IssueDto issue1 = new IssueDto().setId(1L).setSeverity("INFO"); - IssueDto issue2 = new IssueDto().setId(2L).setSeverity("BLOCKER"); - IssueDto issue3 = new IssueDto().setId(3L).setSeverity("MAJOR"); + IssueDto issue1 = new IssueDto().setKee("A").setSeverity("INFO"); + IssueDto issue2 = new IssueDto().setKee("B").setSeverity("BLOCKER"); + IssueDto issue3 = new IssueDto().setKee("C").setSeverity("MAJOR"); List dtoList = newArrayList(issue1, issue2, issue3); IssueQuery query = IssueQuery.builder().sort(IssueQuery.SORT_BY_SEVERITY).asc(false).build(); @@ -93,9 +93,9 @@ public class IssuesFinderSortTest { Date date1 = DateUtils.addDays(date, -3); Date date2 = DateUtils.addDays(date, -2); Date date3 = DateUtils.addDays(date, -1); - IssueDto issue1 = new IssueDto().setId(1L).setIssueCreationDate(date1); - IssueDto issue2 = new IssueDto().setId(2L).setIssueCreationDate(date3); - IssueDto issue3 = new IssueDto().setId(3L).setIssueCreationDate(date2); + IssueDto issue1 = new IssueDto().setKee("A").setIssueCreationDate(date1); + IssueDto issue2 = new IssueDto().setKee("B").setIssueCreationDate(date3); + IssueDto issue3 = new IssueDto().setKee("C").setIssueCreationDate(date2); List dtoList = newArrayList(issue1, issue2, issue3); IssueQuery query = IssueQuery.builder().sort(IssueQuery.SORT_BY_CREATION_DATE).asc(false).build(); @@ -115,9 +115,9 @@ public class IssuesFinderSortTest { Date date1 = DateUtils.addDays(date, -3); Date date2 = DateUtils.addDays(date, -2); Date date3 = DateUtils.addDays(date, -1); - IssueDto issue1 = new IssueDto().setId(1L).setIssueUpdateDate(date1); - IssueDto issue2 = new IssueDto().setId(2L).setIssueUpdateDate(date3); - IssueDto issue3 = new IssueDto().setId(3L).setIssueUpdateDate(date2); + IssueDto issue1 = new IssueDto().setKee("A").setIssueUpdateDate(date1); + IssueDto issue2 = new IssueDto().setKee("B").setIssueUpdateDate(date3); + IssueDto issue3 = new IssueDto().setKee("C").setIssueUpdateDate(date2); List dtoList = newArrayList(issue1, issue2, issue3); IssueQuery query = IssueQuery.builder().sort(IssueQuery.SORT_BY_UPDATE_DATE).asc(false).build(); @@ -137,9 +137,9 @@ public class IssuesFinderSortTest { Date date1 = DateUtils.addDays(date, -3); Date date2 = DateUtils.addDays(date, -2); Date date3 = DateUtils.addDays(date, -1); - IssueDto issue1 = new IssueDto().setId(1L).setIssueCloseDate(date1); - IssueDto issue2 = new IssueDto().setId(2L).setIssueCloseDate(date3); - IssueDto issue3 = new IssueDto().setId(3L).setIssueCloseDate(date2); + IssueDto issue1 = new IssueDto().setKee("A").setIssueCloseDate(date1); + IssueDto issue2 = new IssueDto().setKee("B").setIssueCloseDate(date3); + IssueDto issue3 = new IssueDto().setKee("C").setIssueCloseDate(date2); List dtoList = newArrayList(issue1, issue2, issue3); IssueQuery query = IssueQuery.builder().sort(IssueQuery.SORT_BY_CLOSE_DATE).asc(false).build(); @@ -155,10 +155,10 @@ public class IssuesFinderSortTest { @Test public void should_not_sort_with_null_sort() { - IssueDto issue1 = new IssueDto().setId(1L).setAssigneeUuid("perceval"); - IssueDto issue2 = new IssueDto().setId(2L).setAssigneeUuid("arthur"); - IssueDto issue3 = new IssueDto().setId(3L).setAssigneeUuid("vincent"); - IssueDto issue4 = new IssueDto().setId(4L).setAssigneeUuid(null); + IssueDto issue1 = new IssueDto().setKee("A").setAssigneeUuid("perceval"); + IssueDto issue2 = new IssueDto().setKee("B").setAssigneeUuid("arthur"); + IssueDto issue3 = new IssueDto().setKee("C").setAssigneeUuid("vincent"); + IssueDto issue4 = new IssueDto().setKee("D").setAssigneeUuid(null); List dtoList = newArrayList(issue1, issue2, issue3, issue4); IssueQuery query = IssueQuery.builder().sort(null).build(); -- 2.39.5