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 */
020package org.sonarqube.ws.client.component;
021
022import com.google.common.base.Joiner;
023import org.sonarqube.ws.WsComponents.SearchWsResponse;
024import org.sonarqube.ws.WsComponents.ShowWsResponse;
025import org.sonarqube.ws.WsComponents.TreeWsResponse;
026import org.sonarqube.ws.client.BaseService;
027import org.sonarqube.ws.client.GetRequest;
028import org.sonarqube.ws.client.WsConnector;
029
030import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SHOW;
031import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_TREE;
032import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_ID;
033import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_KEY;
034import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ID;
035import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_KEY;
036import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS;
037import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_STRATEGY;
038
039public class ComponentsService extends BaseService {
040
041  public ComponentsService(WsConnector wsConnector) {
042    super(wsConnector, "api/components");
043  }
044
045  public SearchWsResponse search(SearchWsRequest request) {
046    GetRequest get = new GetRequest(path("search"))
047      .setParam("qualifiers", Joiner.on(",").join(request.getQualifiers()))
048      .setParam("p", request.getPage())
049      .setParam("ps", request.getPageSize())
050      .setParam("q", request.getQuery());
051    return call(get, SearchWsResponse.parser());
052  }
053
054  public TreeWsResponse tree(TreeWsRequest request) {
055    GetRequest get = new GetRequest(path(ACTION_TREE))
056      .setParam(PARAM_BASE_COMPONENT_ID, request.getBaseComponentId())
057      .setParam(PARAM_BASE_COMPONENT_KEY, request.getBaseComponentKey())
058      .setParam(PARAM_QUALIFIERS, inlineMultipleParamValue(request.getQualifiers()))
059      .setParam(PARAM_STRATEGY, request.getStrategy())
060      .setParam("p", request.getPage())
061      .setParam("ps", request.getPageSize())
062      .setParam("q", request.getQuery())
063      .setParam("s", request.getSort());
064    return call(get, TreeWsResponse.parser());
065  }
066
067  public ShowWsResponse show(ShowWsRequest request) {
068    GetRequest get = new GetRequest(path(ACTION_SHOW))
069      .setParam(PARAM_ID, request.getId())
070      .setParam(PARAM_KEY, request.getKey());
071    return call(get, ShowWsResponse.parser());
072  }
073}