aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-04-12 16:06:15 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-04-12 16:06:15 +0200
commitd96d5a6f582f863a89cf3fc7637401a05080bcd6 (patch)
tree962c463499c0d7a81036c9fe479a0f0fd0026832 /sonar-server
parent1c8317d80c0364b6c254665f7e1fc95c4392484d (diff)
downloadsonarqube-d96d5a6f582f863a89cf3fc7637401a05080bcd6.tar.gz
sonarqube-d96d5a6f582f863a89cf3fc7637401a05080bcd6.zip
SONAR-3755 refactor WS /api/issues
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java1
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/DefaultJRubyIssues.java47
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb91
-rw-r--r--sonar-server/src/test/java/org/sonar/server/ui/DefaultJRubyIssuesTest.java7
4 files changed, 67 insertions, 79 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index 18df11fb20b..2603f435907 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -259,7 +259,6 @@ public final class Platform {
servicesContainer.addSingleton(DryRunDatabaseFactory.class);
servicesContainer.addSingleton(DefaultResourcePermissions.class);
servicesContainer.addSingleton(Periods.class);
- servicesContainer.addSingleton(JRubyFacades.class);
servicesContainer.addSingleton(DefaultIssueFinder.class);
servicesContainer.addSingleton(DefaultJRubyIssues.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/DefaultJRubyIssues.java b/sonar-server/src/main/java/org/sonar/server/ui/DefaultJRubyIssues.java
index 7c3743f1330..2c5f3718be5 100644
--- a/sonar-server/src/main/java/org/sonar/server/ui/DefaultJRubyIssues.java
+++ b/sonar-server/src/main/java/org/sonar/server/ui/DefaultJRubyIssues.java
@@ -19,6 +19,8 @@
*/
package org.sonar.server.ui;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
import org.sonar.api.issue.IssueFinder;
import org.sonar.api.issue.IssueQuery;
import org.sonar.api.issue.JRubyIssues;
@@ -46,15 +48,42 @@ public class DefaultJRubyIssues implements JRubyIssues {
IssueQuery newQuery(Map<String, Object> props) {
IssueQuery.Builder builder = IssueQuery.builder();
- builder.keys((List<String>) props.get("keys"));
- builder.severities((List<String>) props.get("severities"));
- builder.statuses((List<String>) props.get("statuses"));
- builder.resolutions((List<String>) props.get("resolutions"));
- builder.components((List<String>) props.get("components"));
- builder.userLogins((List<String>) props.get("userLogins"));
- builder.assigneeLogins((List<String>) props.get("assigneeLogins"));
- builder.limit((Integer) props.get("limit"));
- builder.offset((Integer) props.get("offset"));
+ builder.keys(toStringList(props.get("keys")));
+ builder.severities(toStringList(props.get("severities")));
+ builder.statuses(toStringList(props.get("statuses")));
+ builder.resolutions(toStringList(props.get("resolutions")));
+ builder.components(toStringList(props.get("components")));
+ builder.userLogins(toStringList(props.get("userLogins")));
+ builder.assigneeLogins(toStringList(props.get("assigneeLogins")));
+ builder.limit(toInteger(props.get("limit")));
+ builder.offset(toInteger(props.get("offset")));
return builder.build();
}
+
+ List<String> toStringList(Object o) {
+ List<String> result = null;
+ if (o != null) {
+ if (o instanceof List) {
+ // assume that it contains only strings
+ result = (List) o;
+ } else if (o instanceof CharSequence) {
+ result = Lists.newArrayList(Splitter.on(',').omitEmptyStrings().split((CharSequence) o));
+ }
+ }
+ return result;
+ }
+
+ Integer toInteger(Object o) {
+ if (o instanceof Integer) {
+ return (Integer) o;
+ }
+ if (o instanceof String) {
+ return Integer.parseInt((String) o);
+ }
+ return null;
+ }
+
+ public void start() {
+ // used to force pico to instantiate the singleton at startup
+ }
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb
index a83fc4e1800..cf005721f21 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb
@@ -18,87 +18,40 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
#
-require "json"
-
class Api::IssuesController < Api::ApiController
- # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
- verify :method => :put, :only => [ :update ]
- verify :method => :post, :only => [ :create ]
- verify :method => :delete, :only => [ :destroy ]
-
- before_filter :admin_required, :only => [ :create, :update, :destroy ]
-
- # GET /api/issues
- def index
- map={}
- map['keys'] = params[:keys]
- map['severities'] = params[:severities]
- map['severityMin'] = params[:severityMin]
- map['status'] = params[:status]
- map['resolutions'] = params[:resolutions]
- map['components'] = params[:components]
- map['authors'] = params[:authors]
- map['assignees'] = params[:assignees]
- map['rules'] = params[:rules]
- map['limit'] = params[:limit]
-
- respond_to do |format|
- format.json { render :json => jsonp(issues_to_json(find_issues(map))) }
- format.xml { render :xml => xml_not_supported }
- end
- end
-
- #GET /api/issues/foo
- def show
- respond_to do |format|
- format.json { render :json => jsonp(issues_to_json([find_issue(params[:key])])) }
- format.xml { render :xml => xml_not_supported }
- end
+ # GET /api/issues/search?<parameters>
+ def search
+ results = find_issues(params)
+ render :json => jsonp(issues_to_json(results.issues))
end
-
- protected
+ private
def find_issues(map)
- issues_query.execute(map)
- end
-
- def find_issue(key)
- issues_query.execute(key)
- end
-
- def issues_query
- java_facade.getIssueFilter()
- end
-
- def issues_to_json(issues)
- json = []
- issues.each do |issue|
- json << issue_to_json(issue) if issue
- end
- json
+ Api.issues.find(map)
end
def issue_to_json(issue)
- {
+ json = {
:key => issue.key,
:component => issue.componentKey,
- :ruleKey => issue.ruleKey,
- :ruleRepositoryKey => issue.ruleRepositoryKey,
- :severity => issue.severity,
- :title => issue.title,
- :message => issue.message,
- :line => issue.line,
- :cost => issue.cost,
- :status => issue.status,
- :resolution => issue.resolution,
- :userLogin => issue.userLogin,
- :assigneeLogin => issue.assigneeLogin,
- :createdAt => to_date(issue.createdAt),
- :updatedAt => to_date(issue.updatedAt),
- :closedAt => to_date(issue.closedAt),
+ :ruleRepository => issue.ruleRepositoryKey,
+ :rule => issue.ruleKey,
}
+ json[:severity] = issue.severity if issue.severity
+ json[:title] = issue.title if issue.title
+ json[:message] = issue.message if issue.message
+ json[:line] = issue.line if issue.line
+ json[:cost] = issue.cost if issue.cost
+ json[:status] = issue.status if issue.status
+ json[:resolution] = issue.resolution if issue.resolution
+ json[:userLogin] = issue.userLogin if issue.userLogin
+ json[:assigneeLogin] = issue.assigneeLogin if issue.assigneeLogin
+ json[:createdAt] = to_date(issue.createdAt) if issue.createdAt
+ json[:updatedAt] = to_date(issue.updatedAt) if issue.updatedAt
+ json[:closedAt] = to_date(issue.closedAt) if issue.closedAt
+ json
end
def to_date(java_date)
diff --git a/sonar-server/src/test/java/org/sonar/server/ui/DefaultJRubyIssuesTest.java b/sonar-server/src/test/java/org/sonar/server/ui/DefaultJRubyIssuesTest.java
index b9320b66d09..0febd52cace 100644
--- a/sonar-server/src/test/java/org/sonar/server/ui/DefaultJRubyIssuesTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/ui/DefaultJRubyIssuesTest.java
@@ -34,6 +34,7 @@ import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
public class DefaultJRubyIssuesTest {
@@ -75,4 +76,10 @@ public class DefaultJRubyIssuesTest {
assertThat(query.offset()).isEqualTo(50);
}
+ @Test
+ public void should_start() throws Exception {
+ facade.start();
+ // nothing is done
+ verifyZeroInteractions(finder);
+ }
}