From f8482d0403a363e057f1fc81d3dc5e4814296725 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 27 Aug 2013 17:49:59 +0200 Subject: [PATCH] Refactor projects search of project permission management in order to specify what this query do --- .../org/sonar/core/resource/ResourceDao.java | 28 +++-- .../sonar/core/resource/ResourceMapper.java | 5 +- .../sonar/core/resource/ResourceMapper.xml | 14 +++ .../sonar/core/resource/ResourceDaoTest.java | 17 ++- ...ical-project-and-not-finished-projects.xml | 111 ++++++++++++++++++ .../ResourceDaoTest/technical-project.xml | 9 -- .../component/DefaultComponentFinder.java | 41 ++----- .../DefaultRubyComponentService.java | 11 +- .../app/controllers/roles_controller.rb | 4 +- .../component/DefaultComponentFinderTest.java | 47 ++++---- .../DefaultRubyComponentServiceTest.java | 26 +++- 11 files changed, 230 insertions(+), 83 deletions(-) create mode 100644 sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture-including-technical-project-and-not-finished-projects.xml delete mode 100644 sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/technical-project.xml diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java index 6d68359fe07..db0ce0dca7b 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java @@ -207,12 +207,22 @@ public class ResourceDao { } SqlSession session = mybatis.openSession(); try { - List resourceDtos = session.getMapper(ResourceMapper.class).selectComponentsByQualifiers(qualifiers); - List components = newArrayList(); - for (ResourceDto resourceDto : resourceDtos) { - components.add(toComponent(resourceDto)); - } - return components; + return toComponents(session.getMapper(ResourceMapper.class).selectComponentsByQualifiers(qualifiers)); + } finally { + MyBatis.closeQuietly(session); + } + } + + /** + * Return enabled components including not completed ones, ie without snapshots or without snapshot having islast=true + */ + public List selectComponentsIncludingNotCompletedOnesByQualifiers(Collection qualifiers) { + if (qualifiers.isEmpty()) { + return Collections.emptyList(); + } + SqlSession session = mybatis.openSession(); + try { + return toComponents(session.getMapper(ResourceMapper.class).selectComponentsIncludingNotCompletedOnesByQualifiers(qualifiers)); } finally { MyBatis.closeQuietly(session); } @@ -227,10 +237,10 @@ public class ResourceDao { .setQualifier(resourceDto.getQualifier()); } - public static List toComponents(List resourceDto){ - return newArrayList(Iterables.transform(resourceDto, new Function() { + public static List toComponents(List resourceDto){ + return newArrayList(Iterables.transform(resourceDto, new Function() { @Override - public ComponentDto apply(@Nullable ResourceDto resourceDto) { + public Component apply(@Nullable ResourceDto resourceDto) { return resourceDto == null ? null : toComponent(resourceDto); } })); diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java index c8a811080fb..5b947c7bfa8 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java @@ -74,11 +74,10 @@ public interface ResourceMapper { List selectAuthorizedChildrenComponentIds(@Param("componentRootKeys") Collection componentRootKeys, @Param("userId") @Nullable Integer userId, @Param("role") String role); - /** - * @since 3.7 - */ List selectComponentsByQualifiers(@Param("qualifiers") Collection qualifier); + List selectComponentsIncludingNotCompletedOnesByQualifiers(@Param("qualifiers") Collection qualifier); + void insert(ResourceDto resource); void update(ResourceDto resource); diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml index d0978802a67..83f8185faea 100644 --- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml @@ -121,6 +121,20 @@ + +