{"action":"created","comment":{"url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/comments/49832644","id":49832644,"diff_hunk":"@@ -0,0 +1,218 @@\n+/*\n+ * SonarQube :: Server\n+ * Copyright (C) 2009-2016 SonarSource SA\n+ * mailto:contact AT sonarsource DOT com\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 3 of the License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ * Lesser General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Lesser General Public License\n+ * along with this program; if not, write to the Free Software Foundation,\n+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n+ */\n+package org.sonar.server.measure.ws;\n+\n+import com.google.common.base.Joiner;\n+import com.google.common.collect.Lists;\n+import com.google.common.collect.Maps;\n+import com.google.common.collect.Sets;\n+import java.util.LinkedHashSet;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Set;\n+import javax.annotation.Nullable;\n+import org.sonar.api.resources.Qualifiers;\n+import org.sonar.api.server.ws.Request;\n+import org.sonar.api.server.ws.Response;\n+import org.sonar.api.server.ws.WebService;\n+import org.sonar.api.web.UserRole;\n+import org.sonar.core.permission.GlobalPermissions;\n+import org.sonar.db.DbClient;\n+import org.sonar.db.DbSession;\n+import org.sonar.db.component.ComponentDto;\n+import org.sonar.db.component.SnapshotDto;\n+import org.sonar.db.measure.MeasureDto;\n+import org.sonar.db.measure.MeasureDtoFunctions;\n+import org.sonar.db.metric.MetricDto;\n+import org.sonar.db.metric.MetricDtoFunctions;\n+import org.sonar.server.component.ComponentFinder;\n+import org.sonar.server.exceptions.NotFoundException;\n+import org.sonar.server.measure.ws.MetricDtoWithBestValue.MetricDtoToMetricDtoWithBestValueFunction;\n+import org.sonar.server.user.UserSession;\n+import org.sonarqube.ws.WsMeasures;\n+import org.sonarqube.ws.WsMeasures.ComponentWsResponse;\n+import org.sonarqube.ws.client.measure.ComponentWsRequest;\n+\n+import static com.google.common.base.Objects.firstNonNull;\n+import static com.google.common.collect.FluentIterable.from;\n+import static com.google.common.collect.Sets.newHashSet;\n+import static java.lang.String.format;\n+import static java.util.Collections.emptyList;\n+import static java.util.Collections.singletonList;\n+import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;\n+import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_KEY;\n+import static org.sonar.server.measure.ws.ComponentDtoToWsComponent.componentDtoToWsComponent;\n+import static org.sonar.server.measure.ws.MetricDtoToWsMetric.metricDtoToWsMetric;\n+import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriods.snapshotsToPeriods;\n+import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;\n+import static org.sonar.server.ws.WsUtils.checkRequest;\n+import static org.sonar.server.ws.WsUtils.writeProtobuf;\n+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT;\n+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_ID;\n+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_KEY;\n+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS;\n+\n+public class ComponentAction implements MeasuresWsAction {\n+  private static final Set<String> QUALIFIERS_ELIGIBLE_FOR_BEST_VALUE = newHashSet(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE);\n+\n+  private final DbClient dbClient;\n+  private final ComponentFinder componentFinder;\n+  private final UserSession userSession;\n+\n+  public ComponentAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession) {\n+    this.dbClient = dbClient;\n+    this.componentFinder = componentFinder;\n+    this.userSession = userSession;\n+  }\n+\n+  @Override\n+  public void define(WebService.NewController context) {\n+    WebService.NewAction action = context.createAction(ACTION_COMPONENT)\n+      .setDescription(format(\"Return component with specified measures. The %s or the %s parameter must be provided.<br>\" +\n+        \"Requires one of the following permissions:\" +\n+        \"<ul>\" +\n+        \"<li>'Administer System'</li>\" +\n+        \"<li>'Administer' rights on the specified project</li>\" +\n+        \"<li>'Browse' on the specified project</li>\" +\n+        \"</ul>\",\n+        PARAM_COMPONENT_ID, PARAM_COMPONENT_KEY))\n+      .setResponseExample(getClass().getResource(\"component-example.json\"))\n+      .setSince(\"5.4\")\n+      .setHandler(this);\n+\n+    action.createParam(PARAM_COMPONENT_ID)\n+      .setDescription(\"Component id\")\n+      .setExampleValue(UUID_EXAMPLE_01);\n+\n+    action.createParam(PARAM_COMPONENT_KEY)\n+      .setDescription(\"Component key\")\n+      .setExampleValue(\"MY_PROJECT\");","path":"server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java","position":106,"original_position":106,"commit_id":"dc5ed8a0a30f55bcdb03cf3a1d00219f0312b3ac","original_commit_id":"dc5ed8a0a30f55bcdb03cf3a1d00219f0312b3ac","user":{"login":"simonbrandhof","id":414010,"avatar_url":"https://avatars.githubusercontent.com/u/414010?v=3","gravatar_id":"","url":"https://api.github.com/users/simonbrandhof","html_url":"https://github.com/simonbrandhof","followers_url":"https://api.github.com/users/simonbrandhof/followers","following_url":"https://api.github.com/users/simonbrandhof/following{/other_user}","gists_url":"https://api.github.com/users/simonbrandhof/gists{/gist_id}","starred_url":"https://api.github.com/users/simonbrandhof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonbrandhof/subscriptions","organizations_url":"https://api.github.com/users/simonbrandhof/orgs","repos_url":"https://api.github.com/users/simonbrandhof/repos","events_url":"https://api.github.com/users/simonbrandhof/events{/privacy}","received_events_url":"https://api.github.com/users/simonbrandhof/received_events","type":"User","site_admin":false},"body":"Isn't there a constant for that ? (other PR I think...). Should be \"my_project\".","created_at":"2016-01-15T09:02:47Z","updated_at":"2016-01-15T09:02:47Z","html_url":"https://github.com/SonarSource/sonarqube/pull/711#discussion_r49832644","pull_request_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/711","_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/comments/49832644"},"html":{"href":"https://github.com/SonarSource/sonarqube/pull/711#discussion_r49832644"},"pull_request":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/711"}}},"pull_request":{"url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/711","id":55747177,"html_url":"https://github.com/SonarSource/sonarqube/pull/711","diff_url":"https://github.com/SonarSource/sonarqube/pull/711.diff","patch_url":"https://github.com/SonarSource/sonarqube/pull/711.patch","issue_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/711","number":711,"state":"open","locked":false,"title":"SONAR-7134 WS api/measures/component","user":{"login":"teryk","id":1247713,"avatar_url":"https://avatars.githubusercontent.com/u/1247713?v=3","gravatar_id":"","url":"https://api.github.com/users/teryk","html_url":"https://github.com/teryk","followers_url":"https://api.github.com/users/teryk/followers","following_url":"https://api.github.com/users/teryk/following{/other_user}","gists_url":"https://api.github.com/users/teryk/gists{/gist_id}","starred_url":"https://api.github.com/users/teryk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teryk/subscriptions","organizations_url":"https://api.github.com/users/teryk/orgs","repos_url":"https://api.github.com/users/teryk/repos","events_url":"https://api.github.com/users/teryk/events{/privacy}","received_events_url":"https://api.github.com/users/teryk/received_events","type":"User","site_admin":false},"body":"Review the last commit only WS api/measures/component","created_at":"2016-01-12T11:46:48Z","updated_at":"2016-01-15T09:02:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7aaa771b447f1688f5226eed7be35a7edad3ce02","assignee":{"login":"simonbrandhof","id":414010,"avatar_url":"https://avatars.githubusercontent.com/u/414010?v=3","gravatar_id":"","url":"https://api.github.com/users/simonbrandhof","html_url":"https://github.com/simonbrandhof","followers_url":"https://api.github.com/users/simonbrandhof/followers","following_url":"https://api.github.com/users/simonbrandhof/following{/other_user}","gists_url":"https://api.github.com/users/simonbrandhof/gists{/gist_id}","starred_url":"https://api.github.com/users/simonbrandhof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonbrandhof/subscriptions","organizations_url":"https://api.github.com/users/simonbrandhof/orgs","repos_url":"https://api.github.com/users/simonbrandhof/repos","events_url":"https://api.github.com/users/simonbrandhof/events{/privacy}","received_events_url":"https://api.github.com/users/simonbrandhof/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/711/commits","review_comments_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/711/comments","review_comment_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/711/comments","statuses_url":"https://api.github.com/repos/SonarSource/sonarqube/statuses/dc5ed8a0a30f55bcdb03cf3a1d00219f0312b3ac","head":{"label":"SonarSource:feature/tb/measures_component","ref":"feature/tb/measures_component","sha":"dc5ed8a0a30f55bcdb03cf3a1d00219f0312b3ac","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":1222504,"name":"sonarqube","full_name":"SonarSource/sonarqube","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/sonarqube","description":"Put your technical debt under control","fork":false,"url":"https://api.github.com/repos/SonarSource/sonarqube","forks_url":"https://api.github.com/repos/SonarSource/sonarqube/forks","keys_url":"https://api.github.com/repos/SonarSource/sonarqube/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonarqube/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonarqube/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonarqube/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonarqube/events","assignees_url":"https://api.github.com/repos/SonarSource/sonarqube/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonarqube/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonarqube/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonarqube/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonarqube/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonarqube/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonarqube/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonarqube/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonarqube/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonarqube/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonarqube/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonarqube/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonarqube/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonarqube/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonarqube/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonarqube/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonarqube/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonarqube/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonarqube/merges","archive_url":"https://api.github.com/repos/SonarSource/sonarqube/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonarqube/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonarqube/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonarqube/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonarqube/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonarqube/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonarqube/releases{/id}","created_at":"2011-01-05T11:05:17Z","updated_at":"2016-01-14T12:55:11Z","pushed_at":"2016-01-15T08:59:03Z","git_url":"git://github.com/SonarSource/sonarqube.git","ssh_url":"git@github.com:SonarSource/sonarqube.git","clone_url":"https://github.com/SonarSource/sonarqube.git","svn_url":"https://github.com/SonarSource/sonarqube","homepage":"http://www.sonarqube.org","size":131927,"stargazers_count":892,"watchers_count":892,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":422,"mirror_url":null,"open_issues_count":9,"forks":422,"open_issues":9,"watchers":892,"default_branch":"master"}},"base":{"label":"SonarSource:master","ref":"master","sha":"06120a4fe2557d7a2716a2c85ad7aaa078a72aad","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":1222504,"name":"sonarqube","full_name":"SonarSource/sonarqube","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/sonarqube","description":"Put your technical debt under control","fork":false,"url":"https://api.github.com/repos/SonarSource/sonarqube","forks_url":"https://api.github.com/repos/SonarSource/sonarqube/forks","keys_url":"https://api.github.com/repos/SonarSource/sonarqube/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonarqube/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonarqube/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonarqube/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonarqube/events","assignees_url":"https://api.github.com/repos/SonarSource/sonarqube/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonarqube/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonarqube/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonarqube/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonarqube/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonarqube/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonarqube/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonarqube/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonarqube/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonarqube/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonarqube/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonarqube/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonarqube/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonarqube/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonarqube/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonarqube/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonarqube/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonarqube/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonarqube/merges","archive_url":"https://api.github.com/repos/SonarSource/sonarqube/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonarqube/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonarqube/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonarqube/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonarqube/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonarqube/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonarqube/releases{/id}","created_at":"2011-01-05T11:05:17Z","updated_at":"2016-01-14T12:55:11Z","pushed_at":"2016-01-15T08:59:03Z","git_url":"git://github.com/SonarSource/sonarqube.git","ssh_url":"git@github.com:SonarSource/sonarqube.git","clone_url":"https://github.com/SonarSource/sonarqube.git","svn_url":"https://github.com/SonarSource/sonarqube","homepage":"http://www.sonarqube.org","size":131927,"stargazers_count":892,"watchers_count":892,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":422,"mirror_url":null,"open_issues_count":9,"forks":422,"open_issues":9,"watchers":892,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/711"},"html":{"href":"https://github.com/SonarSource/sonarqube/pull/711"},"issue":{"href":"https://api.github.com/repos/SonarSource/sonarqube/issues/711"},"comments":{"href":"https://api.github.com/repos/SonarSource/sonarqube/issues/711/comments"},"review_comments":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/711/comments"},"review_comment":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/711/commits"},"statuses":{"href":"https://api.github.com/repos/SonarSource/sonarqube/statuses/dc5ed8a0a30f55bcdb03cf3a1d00219f0312b3ac"}}}}