From: Dimitris Kavvathas Date: Thu, 20 Jul 2023 13:41:51 +0000 (+0200) Subject: SONAR-19372 add api/issues/anticipated_transitions endpoint X-Git-Tag: 10.2.0.77647~264 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bb784c0d359bdb37286c77d25897728b8ea85563;p=sonarqube.git SONAR-19372 add api/issues/anticipated_transitions endpoint --- diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/AnticipatedTransitionDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/AnticipatedTransitionDaoIT.java index 417455f9b65..a47126da22d 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/AnticipatedTransitionDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/AnticipatedTransitionDaoIT.java @@ -1,3 +1,22 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.db.issue; import org.junit.Rule; @@ -45,4 +64,44 @@ public class AnticipatedTransitionDaoIT { var anticipatedTransitionDtosDeleted = underTest.selectByProjectUuid(db.getSession(), projectUuid); assertThat(anticipatedTransitionDtosDeleted).isEmpty(); } + + @Test + public void deleteByProjectAndUser_shouldDeleteAllRelatedRecords() { + // given + final String projectUuid1 = "project1"; + final String projectUuid2 = "project2"; + String userUuid1 = "user1"; + String userUuid2 = "user2"; + + generateAndInsertAnticipatedTransition("uuid1", projectUuid1, userUuid1); // should be deleted + generateAndInsertAnticipatedTransition("uuid2", projectUuid1, userUuid1); // should be deleted + generateAndInsertAnticipatedTransition("uuid3", projectUuid2, userUuid1); + generateAndInsertAnticipatedTransition("uuid4", projectUuid1, userUuid2); + generateAndInsertAnticipatedTransition("uuid5", projectUuid2, userUuid2); + generateAndInsertAnticipatedTransition("uuid6", projectUuid1, userUuid1); // should be deleted + + // when + underTest.deleteByProjectAndUser(db.getSession(), projectUuid1, userUuid1); + + // then + assertThat(underTest.selectByProjectUuid(db.getSession(), projectUuid1)).hasSize(1); + assertThat(underTest.selectByProjectUuid(db.getSession(), projectUuid2)).hasSize(2); + } + + private void generateAndInsertAnticipatedTransition(String uuid, String projectUuid1, String userUuid1) { + AnticipatedTransitionDto transition = new AnticipatedTransitionDto( + uuid, + projectUuid1, + userUuid1, + "transition", + "status", + "comment", + 1, + "message", + "lineHash", + "ruleKey"); + + // insert one + underTest.insert(db.getSession(), transition); + } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionDao.java index 6deb8bea985..78c3b787c67 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionDao.java @@ -1,3 +1,22 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.db.issue; import java.util.List; @@ -14,6 +33,10 @@ public class AnticipatedTransitionDao implements Dao { mapper(session).delete(uuid); } + public void deleteByProjectAndUser(DbSession dbSession, String projectUuid, String userUuid) { + mapper(dbSession).deleteByProjectAndUser(projectUuid, userUuid); + } + public List selectByProjectUuid(DbSession session, String projectUuid) { return mapper(session).selectByProjectUuid(projectUuid); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionDto.java index 7611d8dd8bd..7991e06401d 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionDto.java @@ -20,6 +20,7 @@ package org.sonar.db.issue; import javax.annotation.Nullable; +import org.sonar.core.issue.AnticipatedTransition; public class AnticipatedTransitionDto { private String uuid; @@ -138,4 +139,18 @@ public class AnticipatedTransitionDto { public void setRuleKey(String ruleKey) { this.ruleKey = ruleKey; } + + public static AnticipatedTransitionDto toDto(AnticipatedTransition anticipatedTransition, String uuid, String projectUuid) { + return new AnticipatedTransitionDto( + uuid, + projectUuid, + anticipatedTransition.getUserUuid(), + anticipatedTransition.getTransition(), + anticipatedTransition.getStatus(), + anticipatedTransition.getComment(), + anticipatedTransition.getLine(), + anticipatedTransition.getMessage(), + anticipatedTransition.getLineHash(), + anticipatedTransition.getRuleKey().toString()); + } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionMapper.java index dc8383557ee..7459f316536 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionMapper.java @@ -27,5 +27,7 @@ public interface AnticipatedTransitionMapper { void delete(@Param("uuid") String uuid); + void deleteByProjectAndUser(@Param("projectUuid") String projectUuid, @Param("userUuid") String userUuid); + List selectByProjectUuid(@Param("projectUuid") String projectUuid); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/AnticipatedTransitionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/AnticipatedTransitionMapper.xml index 3160d2d164a..89a8c9e2181 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/AnticipatedTransitionMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/AnticipatedTransitionMapper.xml @@ -30,6 +30,10 @@ delete from anticipated_transitions where uuid=#{uuid} + + delete from anticipated_transitions where project_uuid=#{projectUuid,jdbcType=VARCHAR} and user_uuid=#{userUuid,jdbcType=VARCHAR} + +