BulkChangeData(DbSession dbSession, Request request) { this.sendNotification = request.mandatoryParamAsBoolean(PARAM_SEND_NOTIFICATIONS); this.propertiesByActions = toPropertiesByActions(request); List<String> issueKeys = request.mandatoryParamAsStrings(PARAM_ISSUES); checkArgument(issueKeys.size() <= MAX_LIMIT, "Number of issues is limited to %s", MAX_LIMIT); List<IssueDto> allIssues = dbClient.issueDao().selectByKeys(dbSession, issueKeys); List<ComponentDto> allProjects = getComponents(dbSession, allIssues.stream().map(IssueDto::getProjectUuid).collect(MoreCollectors.toSet())); this.projectsByUuid = getAuthorizedProjects(allProjects).stream().collect(uniqueIndex(ComponentDto::uuid, identity())); this.issues = getAuthorizedIssues(allIssues); this.componentsByUuid = getComponents(dbSession, issues.stream().map(DefaultIssue::componentUuid).collect(MoreCollectors.toSet())).stream() .collect(uniqueIndex(ComponentDto::uuid, identity())); this.rulesByKey = dbClient.ruleDao().selectDefinitionByKeys(dbSession, issues.stream().map(DefaultIssue::ruleKey).collect(MoreCollectors.toSet())).stream() .collect(uniqueIndex(RuleDefinitionDto::getKey, identity())); this.availableActions = actions.stream() .filter(action -> propertiesByActions.containsKey(action.key())) .filter(action -> action.verify(getProperties(action.key()), issues, userSession)) .collect(MoreCollectors.toList()); }
@Override public void handle(Request request, Response response) throws Exception { String projectKey = request.mandatoryParam(PARAM_PROJECT); List<String> tags = request.mandatoryParamAsStrings(PARAM_TAGS).stream() .filter(StringUtils::isNotBlank) .map(t -> t.toLowerCase(Locale.ENGLISH)) .map(SetAction::checkTag) .distinct() .collect(MoreCollectors.toList()); try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto project = componentFinder.getByKey(dbSession, projectKey); checkRequest(PROJECT.equals(project.qualifier()), "Component '%s' is not a project", project.getDbKey()); userSession.checkComponentPermission(UserRole.ADMIN, project); project.setTags(tags); dbClient.componentDao().updateTags(dbSession, project); projectIndexers.commitAndIndex(dbSession, singletonList(project), PROJECT_TAGS_UPDATE); } response.noContent(); }
private SearchRequest createRequest() { request = SearchRequest.builder() .setMetricKeys(httpRequest.mandatoryParamAsStrings(PARAM_METRIC_KEYS)) .setProjectKeys(httpRequest.paramAsStrings(PARAM_PROJECT_KEYS)) .build(); return request; }
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 ResetRequest toWsRequest(Request request) { return new ResetRequest() .setKeys(request.mandatoryParamAsStrings(PARAM_KEYS)) .setComponent(request.param(PARAM_COMPONENT)) .setBranch(request.param(PARAM_BRANCH)) .setPullRequest(request.param(PARAM_PULL_REQUEST)); }
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 SearchRequest toSearchWsRequest(org.sonar.api.server.ws.Request request) { return new SearchRequest() .setOrganization(request.param(PARAM_ORGANIZATION)) .setQualifiers(request.mandatoryParamAsStrings(PARAM_QUALIFIERS)) .setLanguage(request.param(PARAM_LANGUAGE)) .setQuery(request.param(Param.TEXT_QUERY)) .setPage(request.mandatoryParamAsInt(Param.PAGE)) .setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)); }
private static ComponentTreeRequest toComponentTreeWsRequest(Request request) { List<String> metricKeys = request.mandatoryParamAsStrings(PARAM_METRIC_KEYS); checkArgument(metricKeys.size() <= MAX_METRIC_KEYS, "Number of metrics keys is limited to %s, got %s", MAX_METRIC_KEYS, metricKeys.size()); ComponentTreeRequest componentTreeRequest = new ComponentTreeRequest()
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 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 BulkApplyTemplateRequest toBulkApplyTemplateWsRequest(Request request) { return new BulkApplyTemplateRequest() .setOrganization(request.param(PARAM_ORGANIZATION)) .setTemplateId(request.param(PARAM_TEMPLATE_ID)) .setTemplateName(request.param(PARAM_TEMPLATE_NAME)) .setQualifiers(request.mandatoryParamAsStrings(PARAM_QUALIFIERS)) .setQuery(request.param(Param.TEXT_QUERY)) .setVisibility(request.param(PARAM_VISIBILITY)) .setOnProvisionedOnly(request.mandatoryParamAsBoolean(PARAM_ON_PROVISIONED_ONLY)) .setAnalyzedBefore(request.param(PARAM_ANALYZED_BEFORE)) .setProjects(request.paramAsStrings(PARAM_PROJECTS)); }
private static SearchRequest toSearchWsRequest(Request request) { return SearchRequest.builder() .setOrganization(request.param(PARAM_ORGANIZATION)) .setQualifiers(request.mandatoryParamAsStrings(PARAM_QUALIFIERS)) .setQuery(request.param(Param.TEXT_QUERY)) .setVisibility(request.param(PARAM_VISIBILITY)) .setAnalyzedBefore(request.param(PARAM_ANALYZED_BEFORE)) .setOnProvisionedOnly(request.mandatoryParamAsBoolean(PARAM_ON_PROVISIONED_ONLY)) .setProjects(restrictTo1000Values(request.paramAsStrings(PARAM_PROJECTS))) .setProjectIds(restrictTo1000Values(request.paramAsStrings(PARAM_PROJECT_IDS))) .build(); }
private static SearchRequest toSearchWsRequest(Request request) { return SearchRequest.builder() .setOrganization(request.param(PARAM_ORGANIZATION)) .setQualifiers(request.mandatoryParamAsStrings(PARAM_QUALIFIERS)) .setQuery(request.param(Param.TEXT_QUERY)) .setPage(request.mandatoryParamAsInt(Param.PAGE)) .setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)) .setVisibility(request.param(PARAM_VISIBILITY)) .setAnalyzedBefore(request.param(PARAM_ANALYZED_BEFORE)) .setOnProvisionedOnly(request.mandatoryParamAsBoolean(PARAM_ON_PROVISIONED_ONLY)) .setProjects(request.paramAsStrings(PARAM_PROJECTS)) .setProjectIds(request.paramAsStrings(PARAM_PROJECT_IDS)) .build(); }
private SearchRequest createRequest() { request = SearchRequest.builder() .setMetricKeys(httpRequest.mandatoryParamAsStrings(PARAM_METRIC_KEYS)) .setProjectKeys(httpRequest.paramAsStrings(PARAM_PROJECT_KEYS)) .build(); return request; }
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 ResetRequest toWsRequest(Request request) { return new ResetRequest() .setKeys(request.mandatoryParamAsStrings(PARAM_KEYS)) .setComponent(request.param(PARAM_COMPONENT)) .setBranch(request.param(PARAM_BRANCH)) .setPullRequest(request.param(PARAM_PULL_REQUEST)); }
private static SearchRequest toSearchWsRequest(org.sonar.api.server.ws.Request request) { return new SearchRequest() .setOrganization(request.param(PARAM_ORGANIZATION)) .setQualifiers(request.mandatoryParamAsStrings(PARAM_QUALIFIERS)) .setLanguage(request.param(PARAM_LANGUAGE)) .setQuery(request.param(Param.TEXT_QUERY)) .setPage(request.mandatoryParamAsInt(Param.PAGE)) .setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)); }
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 BulkApplyTemplateRequest toBulkApplyTemplateWsRequest(Request request) { return new BulkApplyTemplateRequest() .setOrganization(request.param(PARAM_ORGANIZATION)) .setTemplateId(request.param(PARAM_TEMPLATE_ID)) .setTemplateName(request.param(PARAM_TEMPLATE_NAME)) .setQualifiers(request.mandatoryParamAsStrings(PARAM_QUALIFIERS)) .setQuery(request.param(Param.TEXT_QUERY)) .setVisibility(request.param(PARAM_VISIBILITY)) .setOnProvisionedOnly(request.mandatoryParamAsBoolean(PARAM_ON_PROVISIONED_ONLY)) .setAnalyzedBefore(request.param(PARAM_ANALYZED_BEFORE)) .setProjects(request.paramAsStrings(PARAM_PROJECTS)); }
private static SearchRequest toSearchWsRequest(Request request) { return SearchRequest.builder() .setOrganization(request.param(PARAM_ORGANIZATION)) .setQualifiers(request.mandatoryParamAsStrings(PARAM_QUALIFIERS)) .setQuery(request.param(Param.TEXT_QUERY)) .setVisibility(request.param(PARAM_VISIBILITY)) .setAnalyzedBefore(request.param(PARAM_ANALYZED_BEFORE)) .setOnProvisionedOnly(request.mandatoryParamAsBoolean(PARAM_ON_PROVISIONED_ONLY)) .setProjects(restrictTo1000Values(request.paramAsStrings(PARAM_PROJECTS))) .setProjectIds(restrictTo1000Values(request.paramAsStrings(PARAM_PROJECT_IDS))) .build(); }