aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src
diff options
context:
space:
mode:
authorSteve Marion <unknown>2023-07-20 15:17:54 +0200
committersonartech <sonartech@sonarsource.com>2023-08-02 20:03:03 +0000
commited50d0636f78948fdc36cdc086cabe5eafe54c2d (patch)
tree84b4c97622895d10cca7b1dc02d2bbe762486046 /server/sonar-db-dao/src
parent4f214cb37958b2cceddfe33c3bd10d7de260e219 (diff)
downloadsonarqube-ed50d0636f78948fdc36cdc086cabe5eafe54c2d.tar.gz
sonarqube-ed50d0636f78948fdc36cdc086cabe5eafe54c2d.zip
SONAR-19372 add anticipated_transitions table
Diffstat (limited to 'server/sonar-db-dao/src')
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/issue/AnticipatedTransitionDaoIT.java48
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java9
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionDao.java24
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionDto.java141
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionMapper.java31
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/issue/AnticipatedTransitionMapper.xml39
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl14
9 files changed, 311 insertions, 1 deletions
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
new file mode 100644
index 00000000000..417455f9b65
--- /dev/null
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/AnticipatedTransitionDaoIT.java
@@ -0,0 +1,48 @@
+package org.sonar.db.issue;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AnticipatedTransitionDaoIT {
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE);
+
+ private final AnticipatedTransitionDao underTest = db.getDbClient().anticipatedTransitionDao();
+
+ @Test
+ public void select_anticipated_transition() {
+ final String projectUuid = "project147852";
+ String atUuid = "uuid_123456";
+ AnticipatedTransitionDto transition = new AnticipatedTransitionDto(
+ atUuid,
+ projectUuid,
+ "userUuid",
+ "transition",
+ "status",
+ "comment",
+ 1,
+ "message",
+ "lineHash",
+ "ruleKey");
+
+ // insert one
+ underTest.insert(db.getSession(), transition);
+
+ // select all
+ var anticipatedTransitionDtos = underTest.selectByProjectUuid(db.getSession(), projectUuid);
+ assertThat(anticipatedTransitionDtos).hasSize(1);
+ assertThat(anticipatedTransitionDtos.get(0))
+ .extracting("uuid").isEqualTo(atUuid);
+
+ // delete one
+ underTest.delete(db.getSession(), atUuid);
+
+ // select all
+ var anticipatedTransitionDtosDeleted = underTest.selectByProjectUuid(db.getSession(), projectUuid);
+ assertThat(anticipatedTransitionDtosDeleted).isEmpty();
+ }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
index d350c97108f..3ba6682347b 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
@@ -43,6 +43,7 @@ import org.sonar.db.entity.EntityDao;
import org.sonar.db.es.EsQueueDao;
import org.sonar.db.event.EventComponentChangeDao;
import org.sonar.db.event.EventDao;
+import org.sonar.db.issue.AnticipatedTransitionDao;
import org.sonar.db.issue.IssueChangeDao;
import org.sonar.db.issue.IssueDao;
import org.sonar.db.measure.LiveMeasureDao;
@@ -106,6 +107,7 @@ public class DaoModule extends Module {
// =====================================================================
ActiveRuleDao.class,
AnalysisPropertiesDao.class,
+ AnticipatedTransitionDao.class,
AuthorizationDao.class,
ApplicationProjectsDao.class,
AuditDao.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
index f1b9fa30b15..47d6813b549 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
@@ -43,6 +43,7 @@ import org.sonar.db.entity.EntityDao;
import org.sonar.db.es.EsQueueDao;
import org.sonar.db.event.EventComponentChangeDao;
import org.sonar.db.event.EventDao;
+import org.sonar.db.issue.AnticipatedTransitionDao;
import org.sonar.db.issue.IssueChangeDao;
import org.sonar.db.issue.IssueDao;
import org.sonar.db.measure.LiveMeasureDao;
@@ -180,6 +181,7 @@ public class DbClient {
private final ScimUserDao scimUserDao;
private final ScimGroupDao scimGroupDao;
private final EntityDao entityDao;
+ private final AnticipatedTransitionDao anticipatedTransitionDao;
private final ReportScheduleDao reportScheduleDao;
private final ReportSubscriptionDao reportSubscriptionDao;
@@ -270,6 +272,7 @@ public class DbClient {
entityDao = getDao(map, EntityDao.class);
reportScheduleDao = getDao(map, ReportScheduleDao.class);
reportSubscriptionDao = getDao(map, ReportSubscriptionDao.class);
+ anticipatedTransitionDao = getDao(map, AnticipatedTransitionDao.class);
}
public DbSession openSession(boolean batch) {
@@ -590,12 +593,16 @@ public class DbClient {
return entityDao;
}
- public ReportScheduleDao reportScheduleDao(){
+ public ReportScheduleDao reportScheduleDao() {
return reportScheduleDao;
}
public ReportSubscriptionDao reportSubscriptionDao() {
return reportSubscriptionDao;
}
+
+ public AnticipatedTransitionDao anticipatedTransitionDao() {
+ return anticipatedTransitionDao;
+ }
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
index 16752dbcb0a..4d670509d67 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
@@ -70,6 +70,8 @@ import org.sonar.db.es.EsQueueMapper;
import org.sonar.db.event.EventComponentChangeMapper;
import org.sonar.db.event.EventDto;
import org.sonar.db.event.EventMapper;
+import org.sonar.db.issue.AnticipatedTransitionDto;
+import org.sonar.db.issue.AnticipatedTransitionMapper;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueChangeMapper;
import org.sonar.db.issue.IssueDto;
@@ -194,6 +196,7 @@ public class MyBatis {
confBuilder.loadAlias("ActiveRule", ActiveRuleDto.class);
confBuilder.loadAlias("ActiveRuleParam", ActiveRuleParamDto.class);
confBuilder.loadAlias("ApplicationProject", ApplicationProjectDto.class);
+ confBuilder.loadAlias("AnticipatedTransition", AnticipatedTransitionDto.class);
confBuilder.loadAlias("CeTaskCharacteristic", CeTaskCharacteristicDto.class);
confBuilder.loadAlias("Component", ComponentDto.class);
confBuilder.loadAlias("DuplicationUnit", DuplicationUnitDto.class);
@@ -256,6 +259,7 @@ public class MyBatis {
AlmPatMapper.class,
AlmSettingMapper.class,
AnalysisPropertiesMapper.class,
+ AnticipatedTransitionMapper.class,
ApplicationProjectsMapper.class,
AuditMapper.class,
AuthorizationMapper.class,
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
new file mode 100644
index 00000000000..6deb8bea985
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionDao.java
@@ -0,0 +1,24 @@
+package org.sonar.db.issue;
+
+import java.util.List;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class AnticipatedTransitionDao implements Dao {
+
+ public void insert(DbSession session, AnticipatedTransitionDto transition) {
+ mapper(session).insert(transition);
+ }
+
+ public void delete(DbSession session, String uuid) {
+ mapper(session).delete(uuid);
+ }
+
+ public List<AnticipatedTransitionDto> selectByProjectUuid(DbSession session, String projectUuid) {
+ return mapper(session).selectByProjectUuid(projectUuid);
+ }
+
+ private static AnticipatedTransitionMapper mapper(DbSession session) {
+ return session.getMapper(AnticipatedTransitionMapper.class);
+ }
+}
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
new file mode 100644
index 00000000000..7611d8dd8bd
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionDto.java
@@ -0,0 +1,141 @@
+/*
+ * 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 javax.annotation.Nullable;
+
+public class AnticipatedTransitionDto {
+ private String uuid;
+ private String projectUuid;
+ private String userUuid;
+ private String transition;
+ private String status;
+ private String comment;
+ private Integer line;
+ private String message;
+ private String lineHash;
+ private String ruleKey;
+ // TODO: private String filePath
+ // TODO: private Instant createdAt
+
+
+ public AnticipatedTransitionDto(
+ String uuid,
+ String projectUuid,
+ String userUuid,
+ String transition,
+ String status,
+ @Nullable String comment,
+ @Nullable Integer line,
+ @Nullable String message,
+ @Nullable String lineHash,
+ String ruleKey) {
+ this.uuid = uuid;
+ this.projectUuid = projectUuid;
+ this.userUuid = userUuid;
+ this.transition = transition;
+ this.status = status;
+ this.comment = comment;
+ this.line = line;
+ this.message = message;
+ this.lineHash = lineHash;
+ this.ruleKey = ruleKey;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public String getProjectUuid() {
+ return projectUuid;
+ }
+
+ public void setProjectUuid(String projectUuid) {
+ this.projectUuid = projectUuid;
+ }
+
+ public String getUserUuid() {
+ return userUuid;
+ }
+
+ public void setUserUuid(String userUuid) {
+ this.userUuid = userUuid;
+ }
+
+ public String getTransition() {
+ return transition;
+ }
+
+ public void setTransition(String transition) {
+ this.transition = transition;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+
+ public Integer getLine() {
+ return line;
+ }
+
+ public void setLine(Integer line) {
+ this.line = line;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getLineHash() {
+ return lineHash;
+ }
+
+ public void setLineHash(String lineHash) {
+ this.lineHash = lineHash;
+ }
+
+ public String getRuleKey() {
+ return ruleKey;
+ }
+
+ public void setRuleKey(String ruleKey) {
+ this.ruleKey = ruleKey;
+ }
+}
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
new file mode 100644
index 00000000000..dc8383557ee
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/AnticipatedTransitionMapper.java
@@ -0,0 +1,31 @@
+/*
+ * 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;
+import org.apache.ibatis.annotations.Param;
+
+public interface AnticipatedTransitionMapper {
+ void insert(AnticipatedTransitionDto anticipatedTransitionDto);
+
+ void delete(@Param("uuid") String uuid);
+
+ List<AnticipatedTransitionDto> 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
new file mode 100644
index 00000000000..3160d2d164a
--- /dev/null
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/AnticipatedTransitionMapper.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
+
+
+<mapper namespace="org.sonar.db.issue.AnticipatedTransitionMapper">
+
+ <sql id="anticipatedTransitionsColumns">
+ at.uuid as uuid,
+ at.project_uuid as projectUuid,
+ at.user_uuid as userUuid,
+ at.transition as transition,
+ at.status as status,
+ at.transition_comment as "comment",
+ at.line as line,
+ at.message as message,
+ at.line_hash as lineHash,
+ at.rule_key as ruleKey
+ </sql>
+
+ <insert id="insert" useGeneratedKeys="false" parameterType="AnticipatedTransition">
+ INSERT INTO anticipated_transitions (uuid, project_uuid, user_uuid, transition, status,
+ transition_comment, line, message, line_hash, rule_key)
+ VALUES (#{uuid,jdbcType=VARCHAR}, #{projectUuid,jdbcType=VARCHAR}, #{userUuid,jdbcType=VARCHAR},
+ #{transition,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{comment,jdbcType=VARCHAR},
+ #{line,jdbcType=INTEGER}, #{message,jdbcType=VARCHAR}, #{lineHash,jdbcType=VARCHAR}, #{ruleKey,jdbcType=VARCHAR})
+ </insert>
+
+ <delete id="delete" parameterType="string">
+ delete from anticipated_transitions where uuid=#{uuid}
+ </delete>
+
+ <select id="selectByProjectUuid" parameterType="string" resultType="AnticipatedTransition">
+ select
+ <include refid="anticipatedTransitionsColumns"/>
+ from anticipated_transitions at
+ where at.project_uuid=#{projectUuid,jdbcType=VARCHAR}
+ </select>
+</mapper>
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index f09fbe6fb2d..1ac97309e11 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -75,6 +75,20 @@ CREATE TABLE "ANALYSIS_PROPERTIES"(
ALTER TABLE "ANALYSIS_PROPERTIES" ADD CONSTRAINT "PK_ANALYSIS_PROPERTIES" PRIMARY KEY("UUID");
CREATE INDEX "ANALYSIS_PROPERTIES_ANALYSIS" ON "ANALYSIS_PROPERTIES"("ANALYSIS_UUID" NULLS FIRST);
+CREATE TABLE "ANTICIPATED_TRANSITIONS"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
+ "USER_UUID" CHARACTER VARYING(255) NOT NULL,
+ "TRANSITION" CHARACTER VARYING(20) NOT NULL,
+ "STATUS" CHARACTER VARYING(20) NOT NULL,
+ "TRANSITION_COMMENT" CHARACTER VARYING(4000),
+ "LINE" INTEGER,
+ "MESSAGE" CHARACTER VARYING(4000),
+ "LINE_HASH" CHARACTER VARYING(255),
+ "RULE_KEY" CHARACTER VARYING(200) NOT NULL
+);
+ALTER TABLE "ANTICIPATED_TRANSITIONS" ADD CONSTRAINT "PK_ANTICIPATED_TRANSITIONS" PRIMARY KEY("UUID");
+
CREATE TABLE "APP_BRANCH_PROJECT_BRANCH"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"APPLICATION_UUID" CHARACTER VARYING(40) NOT NULL,