diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2015-03-31 16:55:55 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2015-04-03 11:55:08 +0200 |
commit | 7bb307b1ca7d20809b38cd9556b6b34300b9113b (patch) | |
tree | e04ee07a6f32e560b3e9c99aa72adfbfa1b5a45c /sonar-core | |
parent | 83da0fcf581c31768ba322246da4079d23fa20bd (diff) | |
download | sonarqube-7bb307b1ca7d20809b38cd9556b6b34300b9113b.tar.gz sonarqube-7bb307b1ca7d20809b38cd9556b6b34300b9113b.zip |
SONAR-5921 WS to list project/profile associations
Diffstat (limited to 'sonar-core')
4 files changed, 115 insertions, 1 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ProjectQprofileAssociationDto.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ProjectQprofileAssociationDto.java new file mode 100644 index 00000000000..e8f0d3c62b0 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ProjectQprofileAssociationDto.java @@ -0,0 +1,51 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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. + */ +package org.sonar.core.qualityprofile.db; + +import javax.annotation.CheckForNull; + +public class ProjectQprofileAssociationDto { + + private Long projectId; + private String projectUuid; + private String projectName; + private String profileKey; + + public Long getProjectId() { + return projectId; + } + + public String getProjectUuid() { + return projectUuid; + } + + public String getProjectName() { + return projectName; + } + + @CheckForNull + public String getProfileKey() { + return profileKey; + } + + public boolean isAssociated() { + return profileKey != null; + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java index 4e39c7d5d9d..81b7ddbf24b 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java @@ -30,6 +30,7 @@ import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import java.util.Date; import java.util.List; @@ -334,4 +335,23 @@ public class QualityProfileDao implements ServerComponent, DaoComponent { public void deleteAllProjectProfileAssociation(String profileKey, DbSession session) { session.getMapper(QualityProfileMapper.class).deleteAllProjectProfileAssociation(profileKey); } + + public List<ProjectQprofileAssociationDto> selectSelectedProjects(String profileKey, @Nullable String query, DbSession session) { + String nameQuery = sqlQueryString(query); + return session.getMapper(QualityProfileMapper.class).selectSelectedProjects(profileKey, nameQuery); + } + + public List<ProjectQprofileAssociationDto> selectDeselectedProjects(String profileKey, @Nullable String query, DbSession session) { + String nameQuery = sqlQueryString(query); + return session.getMapper(QualityProfileMapper.class).selectDeselectedProjects(profileKey, nameQuery); + } + + public List<ProjectQprofileAssociationDto> selectProjectAssociations(String profileKey, @Nullable String query, DbSession session) { + String nameQuery = sqlQueryString(query); + return session.getMapper(QualityProfileMapper.class).selectProjectAssociations(profileKey, nameQuery); + } + + private String sqlQueryString(String query) { + return query == null ? "%" : "%" + query.toUpperCase() + "%"; + } } diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java index bbfda6f5a9c..940c9adce99 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java @@ -78,4 +78,10 @@ public interface QualityProfileMapper { void deleteProjectProfileAssociation(@Param("projectUuid") String projectUuid, @Param("profileKey") String profileKey); void deleteAllProjectProfileAssociation(@Param("profileKey") String profileKey); + + List<ProjectQprofileAssociationDto> selectSelectedProjects(@Param("profileKey") String profileKey, @Param("nameQuery") String nameQuery); + + List<ProjectQprofileAssociationDto> selectDeselectedProjects(@Param("profileKey") String profileKey, @Param("nameQuery") String nameQuery); + + List<ProjectQprofileAssociationDto> selectProjectAssociations(@Param("profileKey") String profileKey, @Param("nameQuery") String nameQuery); } diff --git a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml index 1b244cf4011..3221d9bbf3d 100644 --- a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml @@ -92,7 +92,7 @@ AND p.language=#{language} </select> - <select id="selectProjects" parameterType="Integer" resultType="Component"> + <select id="selectProjects" resultType="Component"> SELECT projects.id as id, projects.name as name, projects.kee as kee, projects.uuid as uuid FROM projects projects JOIN project_qprofiles pp ON pp.project_uuid = projects.uuid @@ -103,6 +103,43 @@ </where> </select> + <select id="selectSelectedProjects" resultType="org.sonar.core.qualityprofile.db.ProjectQprofileAssociationDto"> + SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.name as projectName, pp.profile_key as profileKey + FROM projects pj + JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid + AND pp.profile_key = #{profileKey} + <where> + AND pj.scope='PRJ' AND pj.qualifier='TRK' + AND UPPER(pj.name) LIKE #{nameQuery} + </where> + ORDER BY pj.name ASC + </select> + + <select id="selectDeselectedProjects" resultType="org.sonar.core.qualityprofile.db.ProjectQprofileAssociationDto"> + SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.name as projectName, pp.profile_key as profileKey + FROM projects pj + LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid + AND pp.profile_key = #{profileKey} + <where> + AND pj.scope='PRJ' AND pj.qualifier='TRK' + AND UPPER(pj.name) LIKE #{nameQuery} + AND pp.profile_key IS NULL + </where> + ORDER BY pj.name ASC + </select> + + <select id="selectProjectAssociations" resultType="org.sonar.core.qualityprofile.db.ProjectQprofileAssociationDto"> + SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.name as projectName, pp.profile_key as profileKey + FROM projects pj + LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid + AND pp.profile_key = #{profileKey} + <where> + AND pj.scope='PRJ' AND pj.qualifier='TRK' + AND UPPER(pj.name) LIKE #{nameQuery} + </where> + ORDER BY pj.name ASC + </select> + <select id="countProjects" parameterType="Integer" resultType="Integer"> SELECT count(projects.id) FROM projects projects |