private static Request toTreeWsRequest(org.sonar.api.server.ws.Request request) { return new Request() .setBaseComponentId(request.param(PARAM_COMPONENT_ID)) .setComponent(request.param(PARAM_COMPONENT)) .setBranch(request.param(PARAM_BRANCH)) .setPullRequest(request.param(PARAM_PULL_REQUEST)) .setStrategy(request.mandatoryParam(PARAM_STRATEGY)) .setQuery(request.param(Param.TEXT_QUERY)) .setQualifiers(request.paramAsStrings(PARAM_QUALIFIERS)) .setSort(request.mandatoryParamAsStrings(Param.SORT)) .setAsc(request.mandatoryParamAsBoolean(Param.ASCENDING)) .setPage(request.mandatoryParamAsInt(Param.PAGE)) .setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)); }
private static SetRequest toWsRequest(Request request) { SetRequest set = new SetRequest() .setKey(request.mandatoryParam(PARAM_KEY)) .setValue(request.param(PARAM_VALUE)) .setValues(request.multiParam(PARAM_VALUES)) .setFieldValues(request.multiParam(PARAM_FIELD_VALUES)) .setComponent(request.param(PARAM_COMPONENT)) .setBranch(request.param(PARAM_BRANCH)) .setPullRequest(request.param(PARAM_PULL_REQUEST)); checkArgument(isNotEmpty(set.getKey()), "Setting key is mandatory and must not be empty"); checkArgument(set.getValues() != null, "Setting values must not be null"); checkArgument(set.getFieldValues() != null, "Setting fields values must not be null"); return set; }
@Override public void handle(Request request, Response response) { throw new ServerException(HTTP_GONE, String.format("The web service '%s' doesn't exist anymore, please read its documentation to use alternatives", request.getPath())); }
/** * Returns a boolean value. To be used when parameter is required or has a default value. * * @throws java.lang.IllegalArgumentException is value is null or blank */ public boolean mandatoryParamAsBoolean(String key) { String s = mandatoryParam(key); return parseBoolean(key, s); }
private static List<String> getScmAccounts(Request request) { if (request.hasParam(PARAM_SCM_ACCOUNT)) { return request.multiParam(PARAM_SCM_ACCOUNT); } List<String> oldScmAccounts = request.paramAsStrings(PARAM_SCM_ACCOUNTS); return oldScmAccounts != null ? oldScmAccounts : Collections.emptyList(); }
@CheckForNull public Boolean paramAsBoolean(String key) { String value = param(key); return value == null ? null : parseBoolean(key, value); }
@Override public void handle(Request request, Response response) throws Exception { String componentKey = request.mandatoryParam(PARAM_COMPONENT); String branchKey = request.param(PARAM_BRANCH); String pullRequestKey = request.param(PARAM_PULL_REQUEST); checkRequest(branchKey == null || pullRequestKey == null, "Parameters '%s' and '%s' must not be specified at the same time", PARAM_BRANCH, PARAM_PULL_REQUEST); doHandle(request, response, componentKey, branchKey, pullRequestKey); }
private static BulkUpdateKeyRequest toWsRequest(Request request) { return BulkUpdateKeyRequest.builder() .setId(request.param(PARAM_PROJECT_ID)) .setKey(request.param(PARAM_PROJECT)) .setFrom(request.mandatoryParam(PARAM_FROM)) .setTo(request.mandatoryParam(PARAM_TO)) .setDryRun(request.mandatoryParamAsBoolean(PARAM_DRY_RUN)) .build(); }
private SearchRequest toSearchWsRequest(DbSession dbSession, Request request) { return new SearchRequest() .setAdditionalFields(request.paramAsStrings(PARAM_ADDITIONAL_FIELDS)) .setAsc(request.mandatoryParamAsBoolean(PARAM_ASC)) .setAssigned(request.paramAsBoolean(PARAM_ASSIGNED)) .setAssigneesUuid(getLogins(dbSession, request.paramAsStrings(PARAM_ASSIGNEES))) .setAuthors(request.paramAsStrings(PARAM_AUTHORS)) .setComponentKeys(request.paramAsStrings(PARAM_COMPONENT_KEYS)) .setComponentRootUuids(request.paramAsStrings(PARAM_COMPONENT_ROOT_UUIDS)) .setComponentRoots(request.paramAsStrings(PARAM_COMPONENT_ROOTS)) .setComponentUuids(request.paramAsStrings(PARAM_COMPONENT_UUIDS)) .setComponents(request.paramAsStrings(PARAM_COMPONENTS)) .setCreatedAfter(request.param(PARAM_CREATED_AFTER)) .setCreatedAt(request.param(PARAM_CREATED_AT)) .setCreatedBefore(request.param(PARAM_CREATED_BEFORE)) .setCreatedInLast(request.param(PARAM_CREATED_IN_LAST)) .setDirectories(request.paramAsStrings(PARAM_DIRECTORIES)) .setFacetMode(request.mandatoryParam(FACET_MODE)) .setFacets(request.paramAsStrings(Param.FACETS)) .setFileUuids(request.paramAsStrings(PARAM_FILE_UUIDS)) .setIssues(request.paramAsStrings(PARAM_ISSUES)) .setLanguages(request.paramAsStrings(PARAM_LANGUAGES)) .setModuleUuids(request.paramAsStrings(PARAM_MODULE_UUIDS)) .setOnComponentOnly(request.paramAsBoolean(PARAM_ON_COMPONENT_ONLY)) .setBranch(request.param(PARAM_BRANCH)) .setPullRequest(request.param(PARAM_PULL_REQUEST)) .setOrganization(request.param(PARAM_ORGANIZATION)) .setPage(request.mandatoryParamAsInt(Param.PAGE)) .setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)) .setProjectKeys(request.paramAsStrings(PARAM_PROJECTS))
private static SearchProjectsRequest toRequest(Request httpRequest) { RequestBuilder request = new RequestBuilder() .setOrganization(httpRequest.param(PARAM_ORGANIZATION)) .setFilter(httpRequest.param(PARAM_FILTER)) .setSort(httpRequest.mandatoryParam(Param.SORT)) .setAsc(httpRequest.mandatoryParamAsBoolean(Param.ASCENDING)) .setPage(httpRequest.mandatoryParamAsInt(Param.PAGE)) .setPageSize(httpRequest.mandatoryParamAsInt(Param.PAGE_SIZE)); if (httpRequest.hasParam(FACETS)) { request.setFacets(httpRequest.mandatoryParamAsStrings(FACETS)); } if (httpRequest.hasParam(FIELDS)) { List<String> paramsAsString = httpRequest.mandatoryParamAsStrings(FIELDS); if (paramsAsString.contains(ALL)) { request.setAdditionalFields(of(ORGANIZATIONS, ANALYSIS_DATE, LEAK_PERIOD_DATE)); } else { request.setAdditionalFields(paramsAsString); } } return request.build(); }
private static SearchHistoryRequest toWsRequest(Request request) { return SearchHistoryRequest.builder() .setComponent(request.mandatoryParam(PARAM_COMPONENT)) .setBranch(request.param(PARAM_BRANCH)) .setPullRequest(request.param(PARAM_PULL_REQUEST)) .setMetrics(request.mandatoryParamAsStrings(PARAM_METRICS)) .setFrom(request.param(PARAM_FROM)) .setTo(request.param(PARAM_TO)) .setPage(request.mandatoryParamAsInt(Param.PAGE)) .setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)) .build(); }
private static SearchUsersRequest buildRequest(Request request) { return SearchUsersRequest.builder() .setOrganization(request.param(PARAM_ORGANIZATION)) .setQualityProfile(request.mandatoryParam(PARAM_QUALITY_PROFILE)) .setLanguage(request.mandatoryParam(PARAM_LANGUAGE)) .setQuery(request.param(TEXT_QUERY)) .setSelected(request.mandatoryParam(SELECTED)) .setPage(request.mandatoryParamAsInt(PAGE)) .setPageSize(request.mandatoryParamAsInt(PAGE_SIZE)) .build(); }
query.setQueryText(request.param(WebService.Param.TEXT_QUERY)); query.setSeverities(request.paramAsStrings(PARAM_SEVERITIES)); query.setRepositories(request.paramAsStrings(PARAM_REPOSITORIES)); Date availableSince = request.paramAsDate(PARAM_AVAILABLE_SINCE); query.setAvailableSince(availableSince != null ? availableSince.getTime() : null); query.setStatuses(toEnums(request.paramAsStrings(PARAM_STATUSES), RuleStatus.class)); setCompareToProfile(dbSession, query, request); QProfileDto profile = query.getQProfile(); query.setLanguages(profile == null ? request.paramAsStrings(PARAM_LANGUAGES) : ImmutableList.of(profile.getLanguage())); if (wsSupport.areActiveRulesVisible(query.getOrganization())) { query.setActivation(request.paramAsBoolean(PARAM_ACTIVATION)); query.setTags(request.paramAsStrings(PARAM_TAGS)); query.setInheritance(request.paramAsStrings(PARAM_INHERITANCE)); query.setActiveSeverities(request.paramAsStrings(PARAM_ACTIVE_SEVERITIES)); query.setIsTemplate(request.paramAsBoolean(PARAM_IS_TEMPLATE)); query.setTemplateKey(request.param(PARAM_TEMPLATE_KEY)); query.setTypes(toEnums(request.paramAsStrings(PARAM_TYPES), RuleType.class)); query.setKey(request.param(PARAM_RULE_KEY)); String sortParam = request.param(WebService.Param.SORT); if (sortParam != null) { query.setSortField(sortParam); query.setAscendingSort(request.mandatoryParamAsBoolean(WebService.Param.ASCENDING));
private static Request toSearchWsRequest(org.sonar.api.server.ws.Request request) { Request activityWsRequest = new Request() .setComponentId(request.param(PARAM_COMPONENT_ID)) .setQ(defaultString(request.param(TEXT_QUERY), request.param(PARAM_COMPONENT_QUERY))) .setStatus(request.paramAsStrings(PARAM_STATUS)) .setType(request.param(PARAM_TYPE)) .setMinSubmittedAt(request.param(PARAM_MIN_SUBMITTED_AT)) .setMaxExecutedAt(request.param(PARAM_MAX_EXECUTED_AT)) .setOnlyCurrents(String.valueOf(request.paramAsBoolean(PARAM_ONLY_CURRENTS))) .setPs(String.valueOf(request.mandatoryParamAsInt(Param.PAGE_SIZE))); checkRequest(activityWsRequest.getComponentId() == null || activityWsRequest.getQ() == null, "%s and %s must not be set at the same time", PARAM_COMPONENT_ID, PARAM_COMPONENT_QUERY); return activityWsRequest; }
@Override public void handle(final Request request, final Response response) throws Exception { if (this.settings.getBoolean(BadgesPluginProperties.MEASURE_BADGES_ACTIVATION_KEY)) { final String key = request.mandatoryParam("key"); final String metric = request.mandatoryParam("metric"); final SVGImageTemplate template = request.mandatoryParamAsEnum("template", SVGImageTemplate.class); final boolean blinkingValueBackgroundColor = request.mandatoryParamAsBoolean("blinking"); final WsClient wsClient = WsClientFactories.getLocal() .newClient(request.localConnector()); LOGGER.debug("Retrieving measure for key '{}' and metric {}.", key, metric); MeasureHolder measureHolder;
private static AddCommentRequest toWsRequest(Request request) { AddCommentRequest wsRequest = new AddCommentRequest(request.mandatoryParam(PARAM_ISSUE), request.mandatoryParam(PARAM_TEXT)); checkArgument(!isNullOrEmpty(wsRequest.getText()), "Cannot add empty comment to an issue"); return wsRequest; }
private static SearchRequest toSearchRequest(Request request) { int pageSize = request.mandatoryParamAsInt(PAGE_SIZE); checkArgument(pageSize <= MAX_PAGE_SIZE, "The '%s' parameter must be less than %s", PAGE_SIZE, MAX_PAGE_SIZE); return SearchRequest.builder() .setQuery(request.param(TEXT_QUERY)) .setPage(request.mandatoryParamAsInt(PAGE)) .setPageSize(pageSize) .setPossibleFields(request.paramAsStrings(FIELDS)) .build(); }
private static ComponentRequest toComponentWsRequest(Request request) { ComponentRequest componentRequest = new ComponentRequest() .setComponentId(request.param(DEPRECATED_PARAM_COMPONENT_ID)) .setComponent(request.param(PARAM_COMPONENT)) .setBranch(request.param(PARAM_BRANCH)) .setPullRequest(request.param(PARAM_PULL_REQUEST)) .setAdditionalFields(request.paramAsStrings(PARAM_ADDITIONAL_FIELDS)) .setMetricKeys(request.mandatoryParamAsStrings(PARAM_METRIC_KEYS)); checkRequest(!componentRequest.getMetricKeys().isEmpty(), "At least one metric key must be provided"); return componentRequest; }
private static ValuesRequest from(Request request) { ValuesRequest result = new ValuesRequest() .setComponent(request.param(PARAM_COMPONENT)) .setBranch(request.param(PARAM_BRANCH)) .setPullRequest(request.param(PARAM_PULL_REQUEST)); if (request.hasParam(PARAM_KEYS)) { result.setKeys(request.paramAsStrings(PARAM_KEYS)); } return result; }
@Override public void handle(Request request, Response response) { String fileKey = request.mandatoryParam("key"); int from = Math.max(request.mandatoryParamAsInt("from"), 1); int to = (Integer) ObjectUtils.defaultIfNull(request.paramAsInt("to"), Integer.MAX_VALUE); boolean commitsByLine = request.mandatoryParamAsBoolean("commits_by_line"); try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto file = componentFinder.getByKey(dbSession, fileKey); userSession.checkComponentPermission(UserRole.CODEVIEWER, file); Iterable<DbFileSources.Line> sourceLines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "File '%s' has no sources", fileKey); try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); writeSource(sourceLines, commitsByLine, json); json.endObject().close(); } } }