title: Sonar WS : How to get the total unresolved bugs count using Sonar Webservice
body: <p>I am trying to get the total number of unresolved bugs and Vulnerabilities in the particular project using <code>sonar-ws-5.6.jar</code>.</p>
  
  <p>I tried to pass the <em>type</em> as BUG to the search query. But still I am getting all the unresolved stuff. It is not taking the parameter type.</p>
  
  <p>How to get the exact number of bugs and Vulnerabilities using Webservice?</p>
  
  <p>Here is my code to connect to sonar and get the data.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  import org.sonarqube.ws.Issues.SearchWsResponse;
  import org.sonarqube.ws.client.HttpConnector;
  import org.sonarqube.ws.client.WsClient;
  import org.sonarqube.ws.client.WsClientFactories;
  import org.sonarqube.ws.client.issue.SearchWsRequest;
  
  public class SonarTest {
      static String resourceKey = "com.company.projectname:parent";
      public static void main(String[] args) {                
          try {       
              // Get Issue
              HttpConnector httpConnector = HttpConnector.newBuilder().url("http://localhost:9000").credentials("admin", "admin").build();
              SearchWsRequest issueSearchRequest = new SearchWsRequest();
              issueSearchRequest.setPageSize(1000);
              issueSearchRequest.setResolved(false);
              List&lt;String&gt; bugTypesList = new ArrayList&lt;String&gt;();
              bugTypesList.add("BUG");
              issueSearchRequest.setTypes(bugTypesList);
              WsClient wsClient = WsClientFactories.getDefault().newClient(httpConnector);
              SearchWsResponse issuesResponse =  wsClient.issues().search(issueSearchRequest);
              System.out.println(issuesResponse.getIssuesList());
  
              System.out.println("DONE");
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Note: I am using sonarqube 5.6 with Java 1.8</p>
  
  <p>As of now I am iterating the response and getting the count</p>
  
  <pre><code>List&lt;Issue&gt; issueList = issuesResponse.getIssuesList();
  int bugCount = 0;
  for(Issue issue : issueList){
     if(issue.getType() == RuleType.BUG){
            bugCount ++;
     }
  }
  </code></pre>