/** * Returns a non-null value. To be used when parameter is required or has a default value. * * @throws java.lang.IllegalArgumentException is value is null or blank */ public String mandatoryParam(String key) { String value = param(key); checkArgument(value != null, format(MSG_PARAMETER_MISSING, key)); return value; }
/** * @deprecated to be dropped in 4.4. Default values must be declared in {@link org.sonar.api.server.ws.WebService} then * this method can be replaced by {@link #mandatoryParamAsLong(String)}. */ @Deprecated public long paramAsLong(String key, long defaultValue) { String s = param(key); return s == null ? defaultValue : parseLong(key, s); }
@CheckForNull public Boolean paramAsBoolean(String key) { String value = param(key); return value == null ? null : parseBoolean(key, value); }
@CheckForNull public Long paramAsLong(String key) { String s = param(key); return s == null ? null : parseLong(key, s); }
@CheckForNull public Date paramAsDate(String key) { String s = param(key); if (s == null) { return null; } try { return DateUtils.parseDate(s); } catch (RuntimeException notDateException) { throw new IllegalArgumentException(notDateException); } }
@CheckForNull String getAndCheckName(Request request) { String name = request.param(PARAM_NAME); if (name != null) { organizationValidation.checkName(name); } return name; }
private void bindOrganization(Request request, DbSession dbSession, OrganizationDto organization) { if (organizationAlmBinding == null) { return; } String installationId = request.param(PARAM_INSTALLATION_ID); if (installationId == null) { return; } organizationAlmBinding.bindOrganization(dbSession, organization, installationId); }
@CheckForNull private String getAndCheckKey(Request request) { String rqstKey = request.param(PARAM_KEY); if (rqstKey != null) { return organizationValidation.checkKey(rqstKey); } return rqstKey; }
public <T> Param<T> getParam(String key, BiFunction<Request, String, T> retrieveAndValidate) { String param = this.param(key); if (param != null) { return GenericParam.present(retrieveAndValidate.apply(this, key)); } return AbsentParam.absent(); }
@Override public void handle(Request request, Response response) throws Exception { String projectKey = request.param(PROJECT_KEY_PARAM); String organizationKey = request.param(ORGANIZATION_KEY_PARAM); userSession.checkLoggedIn(); try (DbSession dbSession = dbClient.openSession(true)) { List<WebhookDto> webhookDtos = doHandle(dbSession, organizationKey, projectKey); Map<String, WebhookDeliveryLiteDto> lastDeliveries = loadLastDeliveriesOf(dbSession, webhookDtos); writeResponse(request, response, webhookDtos, lastDeliveries); } }
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 void doHandle(JsonWriter json, Request request) { try (DbSession dbSession = dbClient.openSession(true)) { Optional<ComponentDto> component = loadComponent(dbSession, request); String key = request.param(PARAM_ID); List<PropertyDto> propertyDtos = loadProperties(dbSession, component, Optional.ofNullable(key)); new ResponseBuilder(propertyDtos).build(json); } }
private void setCompareToProfile(DbSession dbSession, RuleQuery query, Request request) { String compareToProfileUuid = request.param(PARAM_COMPARE_TO_PROFILE); if (compareToProfileUuid == null) { return; } QProfileDto profileOptional = dbClient.qualityProfileDao().selectByUuid(dbSession, compareToProfileUuid); QProfileDto profile = checkFound(profileOptional, "The specified qualityProfile '%s' does not exist", compareToProfileUuid); checkArgument(query.getOrganization().getUuid().equals(profile.getOrganizationUuid()), format("The specified quality profile '%s' is not part of the specified organization '%s'", profile.getKee(), query.getOrganization().getKey())); query.setCompareToQProfile(profile); } }
private ProjectTags.SearchResponse doHandle(Request request) { List<String> tags = index.searchTags(request.param(TEXT_QUERY), request.mandatoryParamAsInt(PAGE_SIZE)); return ProjectTags.SearchResponse.newBuilder().addAllTags(tags).build(); } }
private PermissionQuery buildQuery(Request wsRequest, PermissionTemplateDto template) { String textQuery = wsRequest.param(TEXT_QUERY); String permission = wsRequest.param(PARAM_PERMISSION); PermissionQuery.Builder query = PermissionQuery.builder() .setOrganizationUuid(template.getOrganizationUuid()) .setTemplate(template.getUuid()) .setPermission(permission != null ? requestValidator.validateProjectPermission(permission) : null) .setPageIndex(wsRequest.mandatoryParamAsInt(PAGE)) .setPageSize(wsRequest.mandatoryParamAsInt(PAGE_SIZE)) .setSearchQuery(textQuery); return query.build(); }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION)); JsonWriter json = response.newJsonWriter(); json.beginObject(); addPermissions(organization, json); addLanguages(json); addRuleRepositories(json, dbSession); json.endObject().close(); } }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION)); QProfileDto profile = wsSupport.getProfile(dbSession, organization, request.mandatoryParam(PARAM_QUALITY_PROFILE), request.mandatoryParam(PARAM_LANGUAGE)); wsSupport.checkCanEdit(dbSession, organization, profile); UserDto user = wsSupport.getUser(dbSession, organization, request.mandatoryParam(PARAM_LOGIN)); addUser(dbSession, profile, user); } response.noContent(); }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION)); QProfileDto profile = wsSupport.getProfile(dbSession, organization, request.mandatoryParam(PARAM_QUALITY_PROFILE), request.mandatoryParam(PARAM_LANGUAGE)); wsSupport.checkCanEdit(dbSession, organization, profile); UserDto user = wsSupport.getUser(dbSession, organization, request.mandatoryParam(PARAM_LOGIN)); removeUser(dbSession, profile, user); } response.noContent(); }