001/*
002 * SonarQube
003 * Copyright (C) 2009-2016 SonarSource SA
004 * mailto:contact AT sonarsource DOT com
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020
021package org.sonarqube.ws.client.rule;
022
023import org.sonarqube.ws.Rules.SearchResponse;
024import org.sonarqube.ws.client.BaseService;
025import org.sonarqube.ws.client.GetRequest;
026import org.sonarqube.ws.client.WsConnector;
027
028import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_ACTIVATION;
029import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_ACTIVE_SEVERITIES;
030import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_AVAILABLE_SINCE;
031import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_INHERITANCE;
032import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_IS_TEMPLATE;
033import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_LANGUAGES;
034import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_QPROFILE;
035import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_REPOSITORIES;
036import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_RULE_KEY;
037import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_SEVERITIES;
038import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_STATUSES;
039import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_TAGS;
040import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_TEMPLATE_KEY;
041import static org.sonarqube.ws.client.rule.RulesWsParameters.PARAM_TYPES;
042
043public class RulesService extends BaseService {
044
045  public RulesService(WsConnector wsConnector) {
046    super(wsConnector, "api/rules");
047  }
048
049  public SearchResponse search(SearchWsRequest request) {
050    return call(
051      new GetRequest(path("search"))
052        .setParam(PARAM_ACTIVATION, request.getActivation())
053        .setParam(PARAM_ACTIVE_SEVERITIES, inlineMultipleParamValue(request.getActiveSeverities()))
054        .setParam("asc", request.getAsc())
055        .setParam(PARAM_AVAILABLE_SINCE, request.getAvailableSince())
056        .setParam("f", inlineMultipleParamValue(request.getFields()))
057        .setParam("facets", inlineMultipleParamValue(request.getFacets()))
058        .setParam(PARAM_INHERITANCE, inlineMultipleParamValue(request.getInheritance()))
059        .setParam(PARAM_IS_TEMPLATE, request.getIsTemplate())
060        .setParam(PARAM_LANGUAGES, inlineMultipleParamValue(request.getLanguages()))
061        .setParam("p", request.getPage())
062        .setParam("ps", request.getPageSize())
063        .setParam("q", request.getQuery())
064        .setParam(PARAM_QPROFILE, request.getQProfile())
065        .setParam(PARAM_REPOSITORIES, inlineMultipleParamValue(request.getRepositories()))
066        .setParam(PARAM_RULE_KEY, request.getRuleKey())
067        .setParam("s", request.getSort())
068        .setParam(PARAM_SEVERITIES, inlineMultipleParamValue(request.getSeverities()))
069        .setParam(PARAM_STATUSES, inlineMultipleParamValue(request.getStatuses()))
070        .setParam(PARAM_TAGS, inlineMultipleParamValue(request.getTags()))
071        .setParam(PARAM_TEMPLATE_KEY, request.getTemplateKey())
072        .setParam(PARAM_TYPES, inlineMultipleParamValue(request.getTypes())),
073      SearchResponse.parser());
074  }
075}