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.ce;
022
023import org.sonarqube.ws.WsCe;
024import org.sonarqube.ws.WsCe.ActivityResponse;
025import org.sonarqube.ws.WsCe.TaskTypesWsResponse;
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.ce.CeWsParameters.PARAM_COMPONENT_ID;
031import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_KEY;
032import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MAX_EXECUTED_AT;
033import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_MIN_SUBMITTED_AT;
034import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_ONLY_CURRENTS;
035import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_STATUS;
036import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_TYPE;
037
038/**
039 * Maps web service {@code api/ce} (Compute Engine).
040 */
041public class CeService extends BaseService {
042
043  public CeService(WsConnector wsConnector) {
044    super(wsConnector, "api/ce");
045  }
046
047  public ActivityResponse activity(ActivityWsRequest request) {
048    return call(
049      new GetRequest(path("activity"))
050        .setParam(PARAM_COMPONENT_ID, request.getComponentId())
051        .setParam("q", request.getQuery())
052        .setParam(PARAM_STATUS, inlineMultipleParamValue(request.getStatus()))
053        .setParam(PARAM_TYPE, request.getType())
054        .setParam(PARAM_MAX_EXECUTED_AT, request.getMaxExecutedAt())
055        .setParam(PARAM_MIN_SUBMITTED_AT, request.getMinSubmittedAt())
056        .setParam(PARAM_ONLY_CURRENTS, request.getOnlyCurrents())
057        .setParam("p", request.getPage())
058        .setParam("ps", request.getPageSize()),
059      ActivityResponse.parser());
060  }
061
062  public TaskTypesWsResponse taskTypes() {
063    return call(new GetRequest(path("task_types")), TaskTypesWsResponse.parser());
064  }
065
066  /**
067   * Gets details of a Compute Engine task.
068   *
069   * @throws org.sonarqube.ws.client.HttpException if HTTP status code is not 2xx.
070   * @since 5.5
071   */
072  public WsCe.TaskResponse task(String id) {
073    return call(new GetRequest(path("task")).setParam("id", id), WsCe.TaskResponse.parser());
074  }
075
076  public WsCe.ActivityStatusWsResponse activityStatus(ActivityStatusWsRequest request) {
077    return call(
078      new GetRequest(path("activity_status"))
079        .setParam(PARAM_COMPONENT_ID, request.getComponentId())
080        .setParam(PARAM_COMPONENT_KEY, request.getComponentKey()),
081      WsCe.ActivityStatusWsResponse.parser());
082  }
083
084}