]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4301 Load componentRoot, assignee and reporter from db instead of getting it...
authorJulien Lancelot <julien.lancelot@gmail.com>
Fri, 31 May 2013 10:28:00 +0000 (12:28 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Fri, 31 May 2013 10:28:00 +0000 (12:28 +0200)
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java
sonar-plugin-api/src/main/java/org/sonar/api/component/RubyComponentService.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb
sonar-server/src/main/webapp/WEB-INF/app/views/issues/_sidebar.html.erb
sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java [new file with mode: 0644]

index 1c3502154ada686f26329eefd3c28bad25f260b9..c2af012c47acbf25ea335e71a8f7cb5788844601 100644 (file)
@@ -582,7 +582,7 @@ issue_filter.criteria.date_format=year-month-day (2013-01-31)
 issue_filter.criteria.project=Project
 issue_filter.criteria.reporter=Reporter
 issue_filter.criteria.resolution=Resolution
-issue_filter.criteria.severities=Severities
+issue_filter.criteria.severity=Severity
 issue_filter.criteria.status=Status
 issue_filter.max_results_reached=Only the first {0} issues matching the search criteria have been retrieved. Add some additional criteria to get fewer results to be able to sort this list.
 issue_filter.no_result=No matching issues found.
index 4901abda11cbce6a3aa8d892bef85006874a57ec..e893f2970f8e743a771eaa9e417ad04bedc3e42b 100644 (file)
@@ -154,6 +154,11 @@ public class ResourceDao {
     }
   }
 
+  public Component findByKey(String key) {
+    ResourceDto resourceDto = getResource(ResourceQuery.create().setKey(key));
+    return resourceDto != null ? toComponent(resourceDto) : null;
+  }
+
   public List<Integer> findChildrenComponentIds(Collection<String> componentRootKeys){
     if (componentRootKeys.isEmpty()) {
       return Collections.emptyList();
index 00102831f4e78fc943d61a14e3564508c3b993d5..458dd84f42364afffc4a8670e4de3cd378964459 100644 (file)
@@ -259,4 +259,13 @@ public class ResourceDaoTest extends AbstractDaoTestCase {
     assertThat(dao.findChildrenComponentIds(newArrayList("unknown"))).isEmpty();
     assertThat(dao.findChildrenComponentIds(Collections.<String>emptyList())).isEmpty();
   }
+
+  @Test
+  public void should_find_component_by_key(){
+    setupData("fixture");
+
+    assertThat(dao.findByKey("org.struts:struts")).isNotNull();
+    assertThat(dao.findByKey("org.struts:struts:org.struts.RequestContext")).isNotNull();
+    assertThat(dao.findByKey("unknown")).isNull();
+  }
 }
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/RubyComponentService.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/RubyComponentService.java
new file mode 100644 (file)
index 0000000..b110cce
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.api.component;
+
+import org.sonar.api.ServerComponent;
+
+import javax.annotation.CheckForNull;
+
+/**
+ * @since 3.6
+ */
+public interface RubyComponentService extends ServerComponent {
+
+  @CheckForNull
+  Component findByKey(String key);
+
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java b/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java
new file mode 100644 (file)
index 0000000..da91394
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.server.component;
+
+import org.sonar.api.component.Component;
+import org.sonar.api.component.RubyComponentService;
+import org.sonar.core.resource.ResourceDao;
+
+public class DefaultRubyComponentService implements RubyComponentService {
+
+  private final ResourceDao resourceDao;
+
+  public DefaultRubyComponentService(ResourceDao resourceDao) {
+    this.resourceDao = resourceDao;
+  }
+
+  @Override
+  public Component findByKey(String key) {
+    return resourceDao.findByKey(key);
+  }
+
+}
index aeba75ab896acd2b3d298c3b5f0444f79ebe2275..eec7008c300a36588d289a5d869d9bebae6038dd 100644 (file)
@@ -68,6 +68,7 @@ import org.sonar.jpa.session.DatabaseSessionProvider;
 import org.sonar.jpa.session.DefaultDatabaseConnector;
 import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
 import org.sonar.server.charts.ChartFactory;
+import org.sonar.server.component.DefaultRubyComponentService;
 import org.sonar.server.configuration.Backup;
 import org.sonar.server.configuration.ProfilesManager;
 import org.sonar.server.database.EmbeddedDatabaseFactory;
@@ -253,6 +254,8 @@ public final class Platform {
     servicesContainer.addSingleton(DefaultUserFinder.class);
     servicesContainer.addSingleton(DefaultRubyUserService.class);
 
+    // components
+    servicesContainer.addSingleton(DefaultRubyComponentService.class);
 
     // issues
     servicesContainer.addSingleton(ServerIssueStorage.class);
index 11241ff6379f289982c18da874c152ae756f60fa..fb03745307942bbe5d091ce168d10e31789e2a77 100644 (file)
@@ -30,8 +30,6 @@ class IssuesController < ApplicationController
     @filter = IssueFilter.new
     @filter.criteria=criteria_params
     @filter.execute
-
-    @selected_project = @filter.issues_result.projects.first if @filter.issues && @filter.criteria('componentRoots')
   end
 
 
index fc6cd765ab3d4d9d64a8204085833b8c66e1d24c..df3c18a1884e0fd9f033644ba3ad32ca7bc335bd 100644 (file)
@@ -42,6 +42,10 @@ class Internal
     component(Java::OrgSonarApiUser::RubyUserService.java_class)
   end
 
+  def self.component_api
+    component(Java::OrgSonarApiComponent::RubyComponentService.java_class)
+  end
+
   private
   def self.component(component_java_class)
     Java::OrgSonarServerPlatform::Platform.component(component_java_class)
index 9a6a66ede1dfd6fae180bd0e3e01434da9daca89..b726f192374a55219efb8bd33c06d1f40a05ac5c 100644 (file)
@@ -9,8 +9,9 @@
     </li>
     <li id="criteria-project" class="marginbottom5">
       <%= message 'issue_filter.criteria.project' -%>:
+      <% selected_componentRoot = Internal.component_api.findByKey(@filter.criteria('componentRoots')) %>
       <%= component_select_tag 'componentRoots', :resource_type_property => 'supportsGlobalDashboards', :width => '100%',
-                              :selected_resource => @selected_project,
+                              :selected_resource => selected_componentRoot,
                               :display_key => true,
                               :placeholder => message('issue_filter.criteria.project'),
                               :html_id => 'select-project',
@@ -18,9 +19,9 @@
       -%>
     </li>
     <li id="criteria-severity" class="marginbottom5">
-      <%= message 'issue_filter.criteria.severities' -%>:
+      <%= message 'issue_filter.criteria.severity' -%>:
       <%= dropdown_tag 'severities[]', options_for_select(RulesConfigurationController::RULE_PRIORITIES, @filter.criteria('severities')),
-                       {:width => '100%', :placeholder => message('issue_filter.criteria.severities')},
+                       {:width => '100%', :placeholder => message('issue_filter.criteria.severity')},
                        {:id => 'select-severities', :multiple => true}-%>
     </li>
     <li id="criteria-status" class="marginbottom5">
     </li>
     <li>
       <%= message 'issue_filter.criteria.assignee' -%>:
-      <% selected_assignee = @filter.issues_result.user(@filter.criteria('assignees')) if @filter.issues_result %>
+      <% selected_assignee = Api.users.findByLogin(@filter.criteria('assignees')) %>
       <%= user_select_tag('assignees', {:selected_user => selected_assignee, :width => '100%', :placeholder => message('issue_filter.criteria.assignee'),
                         :html_id => 'select-assignee', :open => false, :allow_clear => true}) -%>
     </li>
     <li>
       <%= message 'issue_filter.criteria.reporter' -%>:
-      <% selected_reporter = @filter.issues_result.user(@filter.criteria('reporters')) if @filter.issues_result %>
+      <% selected_reporter = Api.users.findByLogin(@filter.criteria('reporters')) %>
       <%= user_select_tag('reporters', {:selected_user => selected_reporter, :width => '100%', :placeholder => message('issue_filter.criteria.reporter'),
                                         :html_id => 'select-reporter', :open => false, :allow_clear => true}) -%>
     </li>
diff --git a/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java b/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java
new file mode 100644 (file)
index 0000000..d9911b3
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.server.component;
+
+import org.junit.Before;
+import org.sonar.api.component.Component;
+import org.sonar.core.resource.ResourceDao;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DefaultRubyComponentServiceTest {
+
+  private ResourceDao resourceDao;
+  private DefaultRubyComponentService componentService;
+
+  @Before
+  public void before(){
+    resourceDao = mock(ResourceDao.class);
+    componentService = new DefaultRubyComponentService(resourceDao);
+  }
+
+  @Before
+  public void should_find_by_key() {
+    Component component = mock(Component.class);
+    when(resourceDao.findByKey("struts")).thenReturn(component);
+
+    assertThat(componentService.findByKey("struts")).isEqualTo(component);
+  }
+}