diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-08-04 14:28:41 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-08-04 14:33:19 +0200 |
commit | 324e7ea6fb166942a519dfac10647eae5af803cd (patch) | |
tree | c132452ed535e403b3c17b85f875ea836d85a805 /sonar-core | |
parent | 2124979c80e18d7c5c098bfe97e91671d75ec290 (diff) | |
download | sonarqube-324e7ea6fb166942a519dfac10647eae5af803cd.tar.gz sonarqube-324e7ea6fb166942a519dfac10647eae5af803cd.zip |
SONAR-5402 Fix issue on provisionned projects
Diffstat (limited to 'sonar-core')
6 files changed, 109 insertions, 44 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/component/AuthorizedComponentDto.java b/sonar-core/src/main/java/org/sonar/core/component/AuthorizedComponentDto.java new file mode 100644 index 00000000000..9ad6a40fd3a --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/component/AuthorizedComponentDto.java @@ -0,0 +1,80 @@ +/* + * 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.component; + +import org.sonar.core.persistence.Dto; + +/** + * Used to check that a project exists. Can return provisionned projects and projects from analysis. + * Warning, this component should not be retrieve from db using a join on snapshots, otherwise provisionned projects will not be returned anymore. + */ +public class AuthorizedComponentDto extends Dto<String> { + + private Long id; + private String kee; + + public Long getId() { + return id; + } + + public AuthorizedComponentDto setId(Long id) { + this.id = id; + return this; + } + + public String key() { + return kee; + } + + public AuthorizedComponentDto setKey(String key) { + this.kee = key; + return this; + } + + @Override + public String getKey() { + return kee; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + AuthorizedComponentDto that = (AuthorizedComponentDto) o; + + if (!id.equals(that.id)) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + return id.hashCode(); + } + +} diff --git a/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java b/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java index 1460e2034bc..569e8646269 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java +++ b/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java @@ -20,15 +20,12 @@ package org.sonar.core.component; import org.sonar.api.component.Component; -import org.sonar.core.persistence.Dto; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -public class ComponentDto extends Dto<String> implements Component { +public class ComponentDto extends AuthorizedComponentDto implements Component { - private Long id; - private String kee; private String path; private String name; private String longName; @@ -39,22 +36,13 @@ public class ComponentDto extends Dto<String> implements Component { private Long subProjectId; private boolean enabled = true; - public Long getId() { - return id; - } - public ComponentDto setId(Long id) { - this.id = id; + super.setId(id); return this; } - @Override - public String key() { - return kee; - } - public ComponentDto setKey(String key) { - this.kee = key; + super.setKey(key); return this; } @@ -146,32 +134,4 @@ public class ComponentDto extends Dto<String> implements Component { return this; } - @Override - public String getKey() { - return kee; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - ComponentDto that = (ComponentDto) o; - - if (!id.equals(that.id)) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - return id.hashCode(); - } - } diff --git a/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java b/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java index 8e925d67ca0..5561948dc8c 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java @@ -20,8 +20,11 @@ package org.sonar.core.component.db; import org.apache.ibatis.annotations.Param; +import org.sonar.core.component.AuthorizedComponentDto; import org.sonar.core.component.ComponentDto; +import javax.annotation.CheckForNull; + import java.util.List; /** @@ -29,12 +32,16 @@ import java.util.List; */ public interface ComponentMapper { + @CheckForNull ComponentDto selectByKey(String key); + @CheckForNull ComponentDto selectById(long id); + @CheckForNull ComponentDto selectRootProjectByKey(String key); + @CheckForNull ComponentDto selectParentModuleByKey(String key); /** @@ -44,5 +51,8 @@ public interface ComponentMapper { long countById(long id); + @CheckForNull + AuthorizedComponentDto selectAuthorizedComponentById(long id); + void insert(ComponentDto rule); } diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index e8a97e02518..3e9c9d2f5f4 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -34,6 +34,7 @@ import org.sonar.api.database.model.MeasureModel; import org.sonar.core.activity.db.ActivityDto; import org.sonar.core.activity.db.ActivityMapper; import org.sonar.core.cluster.WorkQueue; +import org.sonar.core.component.AuthorizedComponentDto; import org.sonar.core.component.ComponentDto; import org.sonar.core.component.db.ComponentMapper; import org.sonar.core.config.Logback; @@ -104,6 +105,7 @@ public class MyBatis implements BatchComponent, ServerComponent { loadAlias(conf, "ActiveDashboard", ActiveDashboardDto.class); loadAlias(conf, "Author", AuthorDto.class); loadAlias(conf, "Component", ComponentDto.class); + loadAlias(conf, "AuthorizedComponent", AuthorizedComponentDto.class); loadAlias(conf, "Dashboard", DashboardDto.class); loadAlias(conf, "Dependency", DependencyDto.class); loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class); diff --git a/sonar-core/src/main/java/org/sonar/core/user/UserDao.java b/sonar-core/src/main/java/org/sonar/core/user/UserDao.java index afcda180bea..c87c4eba046 100644 --- a/sonar-core/src/main/java/org/sonar/core/user/UserDao.java +++ b/sonar-core/src/main/java/org/sonar/core/user/UserDao.java @@ -102,7 +102,6 @@ public class UserDao implements BatchComponent, ServerComponent, DaoComponent { } } - @CheckForNull public UserDto insert(SqlSession session, UserDto dto) { session.getMapper(UserMapper.class).insert(dto); return dto; diff --git a/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml b/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml index b0fd329b070..77a9ad0a35d 100644 --- a/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml @@ -15,6 +15,11 @@ p.path as path </sql> + <sql id="authorizedComponentColumns"> + p.id, + p.kee as kee + </sql> + <select id="selectByKey" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p @@ -78,6 +83,15 @@ </where> </select> + <select id="selectAuthorizedComponentById" parameterType="long" resultType="AuthorizedComponent"> + SELECT <include refid="authorizedComponentColumns"/> + FROM projects p + <where> + AND p.enabled=${_true} + AND p.id=#{id} + </where> + </select> + <sql id="insertColumns"> (kee, name, long_name, qualifier, scope, language, root_id, path, created_at) </sql> |