aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-06-09 17:45:52 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-06-10 14:30:41 +0200
commit55046a775d5a9fdc550745183b1f89cc5c927a78 (patch)
tree139a6dffb18e441f884f104bc3c2227033e4e045 /sonar-core
parente00296ce0ab054cba714f1a214cf312020495d42 (diff)
downloadsonarqube-55046a775d5a9fdc550745183b1f89cc5c927a78.tar.gz
sonarqube-55046a775d5a9fdc550745183b1f89cc5c927a78.zip
SONAR-6260 Remove snapshot and project persistence form batch
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java18
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java5
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/DefaultResourcePermissions.java102
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml5
-rw-r--r--sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java235
5 files changed, 12 insertions, 353 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
index 55eb5c74b03..1155e70c62d 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
@@ -21,23 +21,21 @@
package org.sonar.core.issue.db;
import com.google.common.collect.Lists;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.CheckForNull;
import org.apache.ibatis.session.ResultHandler;
import org.sonar.api.batch.BatchSide;
-import org.sonar.api.server.ServerSide;
import org.sonar.api.issue.internal.DefaultIssueComment;
import org.sonar.api.issue.internal.FieldDiffs;
+import org.sonar.api.server.ServerSide;
import org.sonar.core.persistence.DaoComponent;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
-import javax.annotation.CheckForNull;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
@@ -75,7 +73,7 @@ public class IssueChangeDao implements DaoComponent {
}
}
- public void selectChangelogOnNonClosedIssuesByModuleAndType(Integer componentId, ResultHandler handler) {
+ public void selectChangelogOnNonClosedIssuesByModuleAndType(long componentId, ResultHandler handler) {
DbSession session = mybatis.openSession(false);
try {
Map<String, Object> params = newHashMap();
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java
index 4ab8e2ecf97..1a0208b7756 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java
@@ -20,6 +20,7 @@
package org.sonar.core.issue.db;
+import javax.annotation.CheckForNull;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.batch.BatchSide;
@@ -27,8 +28,6 @@ import org.sonar.api.server.ServerSide;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
-import javax.annotation.CheckForNull;
-
/**
* @since 3.6
*/
@@ -52,7 +51,7 @@ public class IssueDao {
}
}
- public void selectNonClosedIssuesByModule(int componentId, ResultHandler handler) {
+ public void selectNonClosedIssuesByModule(long componentId, ResultHandler handler) {
SqlSession session = mybatis.openSession(false);
try {
session.select("org.sonar.core.issue.db.IssueMapper.selectNonClosedIssuesByModule", componentId, handler);
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/DefaultResourcePermissions.java b/sonar-core/src/main/java/org/sonar/core/resource/DefaultResourcePermissions.java
deleted file mode 100644
index b7de970bfb1..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/resource/DefaultResourcePermissions.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.resource;
-
-import org.sonar.api.resources.Resource;
-import org.sonar.api.security.ResourcePermissions;
-import org.sonar.core.permission.PermissionFacade;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.user.UserDto;
-import org.sonar.core.user.UserMapper;
-
-/**
- * @since 3.2
- */
-public class DefaultResourcePermissions implements ResourcePermissions {
-
- private final MyBatis myBatis;
- private final PermissionFacade permissionFacade;
-
- public DefaultResourcePermissions(MyBatis myBatis, PermissionFacade permissionFacade) {
- this.myBatis = myBatis;
- this.permissionFacade = permissionFacade;
- }
-
- @Override
- public boolean hasRoles(Resource resource) {
- DbSession session = myBatis.openSession(false);
- try {
- if (resource.getId() != null) {
- Long resourceId = Long.valueOf(resource.getId());
- return permissionFacade.countComponentPermissions(session, resourceId) > 0;
- }
- } finally {
- MyBatis.closeQuietly(session);
- }
- return false;
- }
-
- @Override
- public void grantUserRole(Resource resource, String login, String role) {
- if (resource.getId() != null) {
- DbSession session = myBatis.openSession(false);
- try {
- UserDto user = session.getMapper(UserMapper.class).selectUserByLogin(login);
- if (user != null) {
- permissionFacade.deleteUserPermission(Long.valueOf(resource.getId()), user.getId(), role, session);
- permissionFacade.insertUserPermission(Long.valueOf(resource.getId()), user.getId(), role, session);
- session.commit();
- }
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
- }
-
- @Override
- public void grantGroupRole(Resource resource, String groupName, String role) {
- if (resource.getId() != null) {
- DbSession session = myBatis.openSession(false);
- try {
- permissionFacade.deleteGroupPermission(Long.valueOf(resource.getId()), groupName, role, session);
- permissionFacade.insertGroupPermission(Long.valueOf(resource.getId()), groupName, role, session);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
- }
-
- public void grantDefaultRoles(DbSession session, Resource resource) {
- permissionFacade.grantDefaultRoles(session, Long.valueOf(resource.getId()), resource.getQualifier());
- }
-
- @Override
- public void grantDefaultRoles(Resource resource) {
- DbSession session = myBatis.openSession(false);
- try {
- grantDefaultRoles(session, resource);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-}
diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
index b15e9ec8ef4..c1bfead8323 100644
--- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
@@ -148,7 +148,7 @@
where i.kee=#{kee}
</select>
- <select id="selectNonClosedIssuesByModule" parameterType="int" resultType="Issue">
+ <select id="selectNonClosedIssuesByModule" parameterType="Long" resultType="Issue">
select
i.id,
i.kee as kee,
@@ -180,8 +180,7 @@
p.kee as componentKey,
root.kee as projectKey
from issues i
- inner join (select p.id, p.uuid,p.kee from projects p where (p.root_id=#{id} and p.qualifier &lt;&gt; 'BRC') or
- (p.id=#{id})) p on p.uuid=i.component_uuid
+ inner join (select p.id, p.uuid,p.kee from projects p where (p.root_id=#{id} and p.qualifier &lt;&gt; 'BRC') or (p.id=#{id})) p on p.uuid=i.component_uuid
inner join rules r on r.id=i.rule_id
left outer join projects root on root.uuid=i.project_uuid
where i.status &lt;&gt; 'CLOSED'
diff --git a/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java b/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java
deleted file mode 100644
index 0ccbedaadda..00000000000
--- a/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * 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.resource;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.security.DefaultGroups;
-import org.sonar.api.utils.System2;
-import org.sonar.core.permission.PermissionFacade;
-import org.sonar.core.permission.PermissionTemplateDao;
-import org.sonar.core.persistence.AbstractDaoTestCase;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.user.RoleDao;
-import org.sonar.core.user.UserDao;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultResourcePermissionsTest extends AbstractDaoTestCase {
-
- private final static Long PROJECT_ID = 123L;
-
- DbSession session;
- Resource project;
- Settings settings;
- DefaultResourcePermissions permissions;
- PermissionFacade permissionFacade;
-
- @Rule
- public ExpectedException throwable = ExpectedException.none();
-
- @Before
- public void initResourcePermissions() {
- session = getMyBatis().openSession(false);
- project = new Project("project").setId(PROJECT_ID.intValue());
- settings = new Settings();
- permissionFacade = new PermissionFacade(new RoleDao(), new UserDao(getMyBatis(), System2.INSTANCE), new ResourceDao(getMyBatis(), System2.INSTANCE),
- new PermissionTemplateDao(getMyBatis(), System2.INSTANCE), settings);
- permissions = new DefaultResourcePermissions(getMyBatis(), permissionFacade);
- }
-
- @After
- public void tearDown() {
- session.close();
- }
-
- @Test
- public void grantGroupRole() {
- setupData("grantGroupRole");
-
- permissions.grantGroupRole(project, "sonar-administrators", "admin");
-
- // do not insert duplicated rows
- permissions.grantGroupRole(project, "sonar-administrators", "admin");
-
- checkTables("grantGroupRole", new String[] {"id"}, "group_roles");
- }
-
- @Test
- public void grantGroupRole_anyone() {
- setupData("grantGroupRole_anyone");
-
- permissions.grantGroupRole(project, DefaultGroups.ANYONE, "admin");
-
- checkTables("grantGroupRole_anyone", "group_roles");
- }
-
- @Test
- public void grantGroupRole_ignore_if_group_not_found() {
- setupData("grantGroupRole_ignore_if_group_not_found");
-
- permissions.grantGroupRole(project, "not_found", "admin");
-
- checkTables("grantGroupRole_ignore_if_group_not_found", "group_roles");
- }
-
- @Test
- public void grantGroupRole_ignore_if_not_persisted() {
- setupData("grantGroupRole_ignore_if_not_persisted");
-
- Project resourceWithoutId = new Project("");
- permissions.grantGroupRole(resourceWithoutId, "sonar-users", "admin");
-
- checkTables("grantGroupRole_ignore_if_not_persisted", "group_roles");
- }
-
- @Test
- public void grantUserRole() {
- setupData("grantUserRole");
-
- permissions.grantUserRole(project, "marius", "admin");
-
- // do not insert duplicated rows
- permissions.grantUserRole(project, "marius", "admin");
-
- checkTables("grantUserRole", new String[] {"id"}, "user_roles");
- }
-
- @Test
- public void grantDefaultRoles_qualifier_independent() {
- setupData("grantDefaultRoles");
-
- settings.setProperty("sonar.permission.template.default", "default_template_20130101_010203");
-
- assertThat(permissionFacade.selectGroupPermissions(session, "sonar-administrators", PROJECT_ID)).isEmpty();
- assertThat(permissionFacade.selectGroupPermissions(session, "sonar-users", PROJECT_ID)).isEmpty();
- assertThat(permissionFacade.selectGroupPermissions(session, "Anyone", PROJECT_ID)).isEmpty();
- assertThat(permissionFacade.selectUserPermissions(session, "marius", PROJECT_ID)).isEmpty();
-
- permissions.grantDefaultRoles(session, project);
-
- assertThat(permissionFacade.selectGroupPermissions(session, "sonar-administrators", PROJECT_ID)).containsOnly("admin");
- assertThat(permissionFacade.selectGroupPermissions(session, "sonar-users", PROJECT_ID)).containsOnly("user", "codeviewer");
- assertThat(permissionFacade.selectGroupPermissions(session, "Anyone", PROJECT_ID)).containsOnly("user", "codeviewer");
-
- assertThat(permissionFacade.selectUserPermissions(session, "marius", PROJECT_ID)).isEmpty();
- }
-
- @Test
- public void grantDefaultRoles_pattern() {
- setupData("grantDefaultRolesPattern");
-
- settings.setProperty("sonar.permission.template.default", "default");
-
- permissions.grantDefaultRoles(project);
-
- checkTables("grantDefaultRolesPattern", "user_roles", "group_roles");
- }
-
- @Test
- public void grantDefaultRoles_several_matching_pattern() {
- setupData("grantDefaultRolesSeveralPattern");
-
- settings.setProperty("sonar.permission.template.default", "default");
-
- throwable.expect(IllegalStateException.class);
- throwable
- .expectMessage("The \"foo.project\" key matches multiple permission templates: \"Start with foo\", \"Start with foo again\". A system administrator must update these templates so that only one of them matches the key.");
-
- permissions.grantDefaultRoles(project);
- }
-
- @Test
- public void grantDefaultRoles_qualifier_specific() {
- setupData("grantDefaultRolesProject");
-
- settings.setProperty("sonar.permission.template.default", "default_20130101_010203");
- settings.setProperty("sonar.permission.template.TRK.default", "default_for_trk_20130101_010203");
-
- assertThat(permissionFacade.selectGroupPermissions(session, "sonar-administrators", PROJECT_ID)).isEmpty();
- assertThat(permissionFacade.selectGroupPermissions(session, "sonar-users", PROJECT_ID)).isEmpty();
- assertThat(permissionFacade.selectGroupPermissions(session, "Anyone", PROJECT_ID)).isEmpty();
- assertThat(permissionFacade.selectUserPermissions(session, "marius", PROJECT_ID)).isEmpty();
-
- permissions.grantDefaultRoles(session, project);
-
- assertThat(permissionFacade.selectGroupPermissions(session, "sonar-administrators", PROJECT_ID)).containsOnly("admin", "user", "codeviewer");
- assertThat(permissionFacade.selectGroupPermissions(session, "sonar-users", PROJECT_ID)).containsOnly("admin");
- assertThat(permissionFacade.selectGroupPermissions(session, "Anyone", PROJECT_ID)).containsOnly("codeviewer");
-
- assertThat(permissionFacade.selectUserPermissions(session, "marius", PROJECT_ID)).containsOnly("codeviewer");
- }
-
- @Test
- public void grantDefaultRoles_unknown_group() {
- setupData("grantDefaultRoles_unknown_group");
-
- settings.setProperty("sonar.permission.template.TRK.default", "default_template_20130101_010203");
- permissions.grantDefaultRoles(project);
-
- checkTables("grantDefaultRoles_unknown_group", "group_roles");
- }
-
- @Test
- public void grantDefaultRoles_users() {
- setupData("grantDefaultRoles_users");
-
- settings.setProperty("sonar.permission.template.TRK.default", "default_for_trk_20130101_010203");
- permissions.grantDefaultRoles(project);
-
- checkTables("grantDefaultRoles_users", "user_roles");
- }
-
- @Test
- public void hasRoles() {
- setupData("hasRoles");
-
- // no groups and at least one user
- assertThat(permissions.hasRoles(new Project("only_users").setId(1))).isTrue();
-
- // no users and at least one group
- assertThat(permissions.hasRoles(new Project("only_groups").setId(2))).isTrue();
-
- // groups and users
- assertThat(permissions.hasRoles(new Project("groups_and_users").setId(3))).isTrue();
-
- // no groups, no users
- assertThat(permissions.hasRoles(new Project("no_groups_no_users").setId(4))).isFalse();
-
- // does not exist
- assertThat(permissions.hasRoles(new Project("not_found"))).isFalse();
- }
-
- @Test
- public void fail_when_no_default_template_is_defined() {
- throwable.expect(IllegalStateException.class);
- throwable.expectMessage("At least one default permission template should be defined");
-
- setupData("fail_when_no_default_template_is_defined");
-
- permissions.grantDefaultRoles(project);
- }
-}