diff options
author | Michal Duda <michal.duda@sonarsource.com> | 2020-09-18 17:08:48 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-09-29 20:07:42 +0000 |
commit | 0ecd8610552ccd59049308c1be46b03470c48538 (patch) | |
tree | d1da42fc9e90627a037696702cb30dd0e7442e6d /server/sonar-db-dao/src/main/java/org/sonar/db | |
parent | bc413ee3db73258a22059816bd4766bcea66a9ca (diff) | |
download | sonarqube-0ecd8610552ccd59049308c1be46b03470c48538.tar.gz sonarqube-0ecd8610552ccd59049308c1be46b03470c48538.zip |
SONAR-13862 Add a WS for dismissing analysis warning by the current user
Diffstat (limited to 'server/sonar-db-dao/src/main/java/org/sonar/db')
13 files changed, 273 insertions, 12 deletions
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 9a89ca6b267..205d02d18e2 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 @@ -86,6 +86,7 @@ import org.sonar.db.user.RoleDao; import org.sonar.db.user.SamlMessageIdDao; import org.sonar.db.user.SessionTokensDao; import org.sonar.db.user.UserDao; +import org.sonar.db.user.UserDismissedMessagesDao; import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserPropertiesDao; import org.sonar.db.user.UserTokenDao; @@ -159,6 +160,7 @@ public class DaoModule extends Module { SchemaMigrationDao.class, SessionTokensDao.class, UserDao.class, + UserDismissedMessagesDao.class, UserGroupDao.class, UserPermissionDao.class, UserPropertiesDao.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 022e0c4dc39..78d717373ed 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 @@ -84,6 +84,7 @@ import org.sonar.db.user.RoleDao; import org.sonar.db.user.SamlMessageIdDao; import org.sonar.db.user.SessionTokensDao; import org.sonar.db.user.UserDao; +import org.sonar.db.user.UserDismissedMessagesDao; import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserPropertiesDao; import org.sonar.db.user.UserTokenDao; @@ -164,6 +165,7 @@ public class DbClient { private final ProjectDao projectDao; private final SessionTokensDao sessionTokensDao; private final SamlMessageIdDao samlMessageIdDao; + private final UserDismissedMessagesDao userDismissedMessagesDao; public DbClient(Database database, MyBatis myBatis, DBSessions dbSessions, Dao... daos) { this.database = database; @@ -242,6 +244,7 @@ public class DbClient { projectDao = getDao(map, ProjectDao.class); sessionTokensDao = getDao(map, SessionTokensDao.class); samlMessageIdDao = getDao(map, SamlMessageIdDao.class); + userDismissedMessagesDao = getDao(map, UserDismissedMessagesDao.class); } public DbSession openSession(boolean batch) { @@ -534,4 +537,8 @@ public class DbClient { return samlMessageIdDao; } + public UserDismissedMessagesDao userDismissedMessagesDao() { + return userDismissedMessagesDao; + } + } 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 bc390ff1fb1..8c1f4a3b487 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 @@ -140,6 +140,7 @@ import org.sonar.db.user.GroupMembershipMapper; import org.sonar.db.user.RoleMapper; import org.sonar.db.user.SamlMessageIdMapper; import org.sonar.db.user.SessionTokenMapper; +import org.sonar.db.user.UserDismissedMessagesMapper; import org.sonar.db.user.UserDto; import org.sonar.db.user.UserGroupDto; import org.sonar.db.user.UserGroupMapper; @@ -287,6 +288,7 @@ public class MyBatis implements Startable { SchemaMigrationMapper.class, SessionTokenMapper.class, SnapshotMapper.class, + UserDismissedMessagesMapper.class, UserGroupMapper.class, UserMapper.class, UserPermissionMapper.class, diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDao.java index 6604c0bb682..39c4b8e2fad 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDao.java @@ -20,6 +20,7 @@ package org.sonar.db.ce; import java.util.List; +import java.util.Optional; import org.sonar.db.Dao; import org.sonar.db.DbSession; @@ -28,6 +29,10 @@ public class CeTaskMessageDao implements Dao { getMapper(dbSession).insert(dto); } + public Optional<CeTaskMessageDto> selectByUuid(DbSession dbSession, String uuid) { + return getMapper(dbSession).selectByUuid(uuid); + } + /** * @return the messages for the specific task, if any, in ascending order of column {@code CREATED_AT}. */ @@ -35,6 +40,10 @@ public class CeTaskMessageDao implements Dao { return getMapper(dbSession).selectByTask(taskUuid); } + public void deleteByType(DbSession session, CeTaskMessageType type) { + getMapper(session).deleteByType(type.name()); + } + private static CeTaskMessageMapper getMapper(DbSession dbSession) { return dbSession.getMapper(CeTaskMessageMapper.class); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDto.java index f31bcbc2530..3eb99a6dce4 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDto.java @@ -35,13 +35,13 @@ public class CeTaskMessageDto { */ private String message; /** - * Timestamp the message was created. Not null + * Type of the message */ - private long createdAt; + private CeTaskMessageType type; /** - * Information if this message can be dismissed by the user + * Timestamp the message was created. Not null */ - private boolean dismissible; + private long createdAt; public String getUuid() { return uuid; @@ -72,21 +72,21 @@ public class CeTaskMessageDto { return this; } - public long getCreatedAt() { - return createdAt; + public CeTaskMessageType getType() { + return type; } - public CeTaskMessageDto setCreatedAt(long createdAt) { - this.createdAt = createdAt; + public CeTaskMessageDto setType(CeTaskMessageType type) { + this.type = type; return this; } - public boolean isDismissible() { - return dismissible; + public long getCreatedAt() { + return createdAt; } - public CeTaskMessageDto setDismissible(boolean dismissible) { - this.dismissible = dismissible; + public CeTaskMessageDto setCreatedAt(long createdAt) { + this.createdAt = createdAt; return this; } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageMapper.java index 5ec953f3b1d..619cd743310 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageMapper.java @@ -20,11 +20,15 @@ package org.sonar.db.ce; import java.util.List; +import java.util.Optional; import org.apache.ibatis.annotations.Param; public interface CeTaskMessageMapper { void insert(@Param("dto") CeTaskMessageDto dto); + Optional<CeTaskMessageDto> selectByUuid(@Param("uuid") String uuid); + List<CeTaskMessageDto> selectByTask(@Param("taskUuid") String taskUuid); + void deleteByType(@Param("ceMessageType") String ceMessageType); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageType.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageType.java new file mode 100644 index 00000000000..52bd4b38038 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageType.java @@ -0,0 +1,35 @@ +/* + * 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.db.ce; + +public enum CeTaskMessageType { + GENERIC(false), + SUGGEST_DEVELOPER_EDITION_UPGRADE(true); + + private final boolean dismissible; + + CeTaskMessageType(boolean dismissible) { + this.dismissible = dismissible; + } + + public boolean isDismissible() { + return dismissible; + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java index 33abd185e2e..b11c7febd7f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java @@ -434,4 +434,11 @@ class PurgeCommands { profiler.stop(); } + void deleteUserDismissedMessages(String projectUuid) { + profiler.start("deleteUserDismissedMessages (user_dismissed_messages)"); + purgeMapper.deleteUserDismissedMessagesByProjectUuid(projectUuid); + session.commit(); + profiler.stop(); + } + } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java index e9a0af96f6d..bb39d91a389 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java @@ -224,6 +224,7 @@ public class PurgeDao implements Dao { commands.deleteComponents(rootUuid); commands.deleteComponentsByMainBranchProjectUuid(rootUuid); commands.deleteProject(rootUuid); + commands.deleteUserDismissedMessages(rootUuid); } /** diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java index 56f09dda6b6..840533516f9 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java @@ -150,4 +150,6 @@ public interface PurgeMapper { void deleteNewCodePeriodsByRootUuid(String rootUuid); void deleteProjectAlmSettingsByProjectUuid(@Param("projectUuid") String projectUuid); + + void deleteUserDismissedMessagesByProjectUuid(@Param("projectUuid") String projectUuid); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDismissedMessageDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDismissedMessageDto.java new file mode 100644 index 00000000000..96d0d3e8219 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDismissedMessageDto.java @@ -0,0 +1,92 @@ +/* + * 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.db.user; + +import org.sonar.db.ce.CeTaskMessageType; + +public class UserDismissedMessageDto { + + private String uuid; + /** + * Uuid of the user that dismissed the message type + */ + private String userUuid; + /** + * Uuid of the project for which the message type was dismissed + */ + private String projectUuid; + /** + * Message type of the dismissed message + */ + private CeTaskMessageType ceMessageType; + /** + * Technical creation date + */ + private long createdAt; + + public UserDismissedMessageDto() { + // nothing to do here + } + + public String getUuid() { + return uuid; + } + + public UserDismissedMessageDto setUuid(String uuid) { + this.uuid = uuid; + return this; + } + + public String getUserUuid() { + return userUuid; + } + + public UserDismissedMessageDto setUserUuid(String userUuid) { + this.userUuid = userUuid; + return this; + } + + public String getProjectUuid() { + return projectUuid; + } + + public UserDismissedMessageDto setProjectUuid(String projectUuid) { + this.projectUuid = projectUuid; + return this; + } + + public CeTaskMessageType getCeMessageType() { + return ceMessageType; + } + + public UserDismissedMessageDto setCeMessageType(CeTaskMessageType ceMessageType) { + this.ceMessageType = ceMessageType; + return this; + } + + public long getCreatedAt() { + return createdAt; + } + + public UserDismissedMessageDto setCreatedAt(long createdAt) { + this.createdAt = createdAt; + return this; + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDismissedMessagesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDismissedMessagesDao.java new file mode 100644 index 00000000000..16843bbd682 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDismissedMessagesDao.java @@ -0,0 +1,63 @@ +/* + * 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.db.user; + +import java.util.List; +import java.util.Optional; +import org.sonar.api.utils.System2; +import org.sonar.db.Dao; +import org.sonar.db.DbSession; +import org.sonar.db.ce.CeTaskMessageType; +import org.sonar.db.project.ProjectDto; + +public class UserDismissedMessagesDao implements Dao { + private final System2 system2; + + public UserDismissedMessagesDao(System2 system2) { + this.system2 = system2; + } + + public UserDismissedMessageDto insert(DbSession session, UserDismissedMessageDto dto) { + long now = system2.now(); + mapper(session).insert(dto.setCreatedAt(now)); + return dto; + } + + public Optional<UserDismissedMessageDto> selectByUserAndProjectAndMessageType(DbSession session, UserDto user, ProjectDto project, + CeTaskMessageType ceMessageType) { + return mapper(session).selectByUserUuidAndProjectUuidAndMessageType(user.getUuid(), project.getUuid(), ceMessageType.name()); + } + + public List<UserDismissedMessageDto> selectByUser(DbSession session, UserDto user) { + return mapper(session).selectByUserUuid(user.getUuid()); + } + + public void deleteByUser(DbSession session, UserDto user) { + mapper(session).deleteByUserUuid(user.getUuid()); + } + + public void deleteByType(DbSession session, CeTaskMessageType type) { + mapper(session).deleteByType(type.name()); + } + + private static UserDismissedMessagesMapper mapper(DbSession session) { + return session.getMapper(UserDismissedMessagesMapper.class); + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDismissedMessagesMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDismissedMessagesMapper.java new file mode 100644 index 00000000000..f1fbddbfdf8 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDismissedMessagesMapper.java @@ -0,0 +1,37 @@ +/* + * 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.db.user; + +import java.util.List; +import java.util.Optional; +import org.apache.ibatis.annotations.Param; + +public interface UserDismissedMessagesMapper { + void insert(@Param("dto") UserDismissedMessageDto dto); + + Optional<UserDismissedMessageDto> selectByUserUuidAndProjectUuidAndMessageType(@Param("userUuid") String userUuid, @Param("projectUuid") String projectUuid, + @Param("ceMessageType") String ceMessageType); + + List<UserDismissedMessageDto> selectByUserUuid(@Param("userUuid") String userUuid); + + void deleteByUserUuid(@Param("userUuid") String userUuid); + + void deleteByType(@Param("ceMessageType") String ceMessageType); +} |