@CheckForNull private Integer getUserIdIfFilterOnMembership(Request request) { boolean filterOnAuthenticatedUser = request.mandatoryParamAsBoolean(PARAM_MEMBER); return (userSession.isLoggedIn() && filterOnAuthenticatedUser) ? userSession.getUserId() : null; } }
/** * Similar to {@link #createRuleQuery(DbSession, Request)} but sets additional fields which are only used * for the rule search WS. */ public RuleQuery createRuleSearchQuery(DbSession dbSession, Request request) { RuleQuery query = createRuleQuery(dbSession, request); query.setIncludeExternal(request.mandatoryParamAsBoolean(PARAM_INCLUDE_EXTERNAL)); return query; }
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 { checkState(context != null && !context.controllers().isEmpty(), "Web service controllers must be loaded before calling the action"); boolean includeInternals = request.mandatoryParamAsBoolean("include_internals"); JsonWriter writer = response.newJsonWriter(); writer.beginObject(); writer.name("webServices").beginArray(); // sort controllers by path Ordering<WebService.Controller> ordering = Ordering.natural().onResultOf(WebService.Controller::path); for (WebService.Controller controller : ordering.sortedCopy(context.controllers())) { writeController(writer, controller, includeInternals); } writer.endArray(); writer.endObject(); writer.close(); }
private ShowResponse buildResponse(DbSession dbSession, OrganizationDto organization, Request request, SearchAction.SearchResult searchResult) { ShowResponse.Builder responseBuilder = ShowResponse.newBuilder(); RuleDto rule = searchResult.getRules().get(0); responseBuilder.setRule(mapper.toWsRule(rule.getDefinition(), searchResult, Collections.emptySet(), rule.getMetadata(), ruleWsSupport.getUsersByUuid(dbSession, searchResult.getRules()))); if (request.mandatoryParamAsBoolean(PARAM_ACTIVES) && ruleWsSupport.areActiveRulesVisible(organization)) { activeRuleCompleter.completeShow(dbSession, organization, rule.getDefinition()).forEach(responseBuilder::addActives); } return responseBuilder.build(); }
@CheckForNull public CompareToSonarWay getSonarWay(Request request, DbSession dbSession, OrganizationDto organization, QProfileDto profile) { if (!request.mandatoryParamAsBoolean(PARAM_COMPARE_TO_SONAR_WAY) || profile.isBuiltIn()) { return null; } QProfileDto sonarWay = Stream.of(SONAR_WAY, SONARQUBE_WAY) .map(name -> dbClient.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, name, profile.getLanguage())) .filter(Objects::nonNull) .filter(QProfileDto::isBuiltIn) .findFirst() .orElse(null); if (sonarWay == null) { return null; } long missingRuleCount = ruleIndex.search( new RuleQuery().setQProfile(profile).setActivation(false).setCompareToQProfile(sonarWay), new SearchOptions().setLimit(1)) .getTotal(); return CompareToSonarWay.newBuilder() .setProfile(sonarWay.getKee()) .setProfileName(sonarWay.getName()) .setMissingRuleCount(missingRuleCount) .build(); }
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(); }
@Override public void handle(Request wsRequest, Response wsResponse) throws Exception { ProjectRepositories data = projectDataLoader.load(ProjectDataQuery.create() .setProjectKey(wsRequest.mandatoryParam(PARAM_KEY)) .setProfileName(wsRequest.param(PARAM_PROFILE)) .setIssuesMode(wsRequest.mandatoryParamAsBoolean(PARAM_ISSUES_MODE)) .setBranch(wsRequest.param(PARAM_BRANCH)) .setPullRequest(wsRequest.param(PARAM_PULL_REQUEST))); WsProjectResponse projectResponse = buildResponse(data); writeProtobuf(projectResponse, wsRequest, wsResponse); }
@Override public void handle(Request request, Response response) throws Exception { boolean onlyMembershipOrganizations = request.mandatoryParamAsBoolean(PARAM_MEMBER); if (onlyMembershipOrganizations) { userSession.checkLoggedIn(); } try (DbSession dbSession = dbClient.openSession(false)) { OrganizationQuery dbQuery = buildDbQuery(request); int total = dbClient.organizationDao().countByQuery(dbSession, dbQuery); Paging paging = buildWsPaging(request, total); List<OrganizationDto> organizations = dbClient.organizationDao().selectByQuery(dbSession, dbQuery, forPage(paging.getPageIndex()).andSize(paging.getPageSize())); Set<String> adminOrganizationUuids = searchOrganizationWithAdminPermission(dbSession); Set<String> provisionOrganizationUuids = searchOrganizationWithProvisionPermission(dbSession); Map<String, OrganizationAlmBindingDto> organizationAlmBindingByOrgUuid = dbClient.organizationAlmBindingDao().selectByOrganizations(dbSession, organizations) .stream().collect(MoreCollectors.uniqueIndex(OrganizationAlmBindingDto::getOrganizationUuid)); Organizations.SearchWsResponse wsResponse = buildOrganizations(organizations, adminOrganizationUuids, provisionOrganizationUuids, organizationAlmBindingByOrgUuid, onlyMembershipOrganizations, paging); writeProtobuf(wsResponse, request, response); } }
@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(); } } }
private static CreateRequest toWsRequest(Request request) { return CreateRequest.builder() .setLogin(request.mandatoryParam(PARAM_LOGIN)) .setPassword(request.param(PARAM_PASSWORD)) .setName(request.param(PARAM_NAME)) .setEmail(request.param(PARAM_EMAIL)) .setScmAccounts(getScmAccounts(request)) .setLocal(request.mandatoryParamAsBoolean(PARAM_LOCAL)) .build(); }
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(); }
@Override public void handle(Request request, Response response) throws Exception { ruleWsSupport.checkQProfileAdminPermissionOnDefaultOrganization(); String customKey = request.mandatoryParam(PARAM_CUSTOM_KEY); try (DbSession dbSession = dbClient.openSession(false)) { try { NewCustomRule newRule = NewCustomRule.createForCustomRule(customKey, RuleKey.parse(request.mandatoryParam(PARAM_TEMPLATE_KEY))) .setName(request.mandatoryParam(PARAM_NAME)) .setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION)) .setSeverity(request.mandatoryParam(PARAM_SEVERITY)) .setStatus(RuleStatus.valueOf(request.mandatoryParam(PARAM_STATUS))) .setPreventReactivation(request.mandatoryParamAsBoolean(PARAM_PREVENT_REACTIVATION)); String params = request.param(PARAMS); if (!isNullOrEmpty(params)) { newRule.setParameters(KeyValueFormat.parse(params)); } ofNullable(request.param(PARAM_TYPE)).ifPresent(t -> newRule.setType(RuleType.valueOf(t))); writeResponse(dbSession, request, response, ruleCreator.create(dbSession, newRule)); } catch (ReactivationException e) { response.stream().setStatus(HTTP_CONFLICT); writeResponse(dbSession, request, response, e.ruleKey()); } } }
private static SearchRequest toSearchWsRequest(Request request) { request.mandatoryParamAsBoolean(ASCENDING); return new SearchRequest() .setActiveSeverities(request.paramAsStrings(PARAM_ACTIVE_SEVERITIES)) .setF(request.paramAsStrings(FIELDS)) .setFacets(request.paramAsStrings(FACETS)) .setLanguages(request.paramAsStrings(PARAM_LANGUAGES)) .setP("" + request.mandatoryParamAsInt(PAGE)) .setPs("" + request.mandatoryParamAsInt(PAGE_SIZE)) .setRepositories(request.paramAsStrings(PARAM_REPOSITORIES)) .setSeverities(request.paramAsStrings(PARAM_SEVERITIES)) .setStatuses(request.paramAsStrings(PARAM_STATUSES)) .setTags(request.paramAsStrings(PARAM_TAGS)) .setTypes(request.paramAsStrings(PARAM_TYPES)); }
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 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 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)) .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(); }
if (sortParam != null) { query.setSortField(sortParam); query.setAscendingSort(request.mandatoryParamAsBoolean(WebService.Param.ASCENDING));
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))) .setResolved(request.paramAsBoolean(PARAM_RESOLVED)) .setRules(request.paramAsStrings(PARAM_RULES)) .setSinceLeakPeriod(request.mandatoryParamAsBoolean(PARAM_SINCE_LEAK_PERIOD)) .setSort(request.param(Param.SORT)) .setSeverities(request.paramAsStrings(PARAM_SEVERITIES))