private static MetricDto newMetricTemplate(Request request) { int id = request.mandatoryParamAsInt(PARAM_ID); String key = request.param(PARAM_KEY); if (key != null) { MetricKeyValidator.checkMetricKeyFormat(key); } String type = request.param(PARAM_TYPE); String name = request.param(PARAM_NAME); String domain = request.param(PARAM_DOMAIN); String description = request.param(PARAM_DESCRIPTION); MetricDto metricTemplate = new MetricDto().setId(id); if (key != null) { metricTemplate.setKey(key); } if (type != null) { metricTemplate.setValueType(type); } if (name != null) { metricTemplate.setShortName(name); } if (domain != null) { metricTemplate.setDomain(domain); } if (description != null) { metricTemplate.setDescription(description); } return metricTemplate; }
private static BulkApplyTemplateWsRequest toBulkApplyTemplateWsRequest(Request request) { return new BulkApplyTemplateWsRequest() .setTemplateId(request.param(PARAM_TEMPLATE_ID)) .setOrganization(request.param(PARAM_ORGANIZATION_KEY)) .setTemplateName(request.param(PARAM_TEMPLATE_NAME)) .setQualifier(request.param(PARAM_QUALIFIER)) .setQuery(request.param(Param.TEXT_QUERY)); }
private OrganizationDto createOrganizationDto(Request request, String name, String key) { return new OrganizationDto() .setUuid(uuidFactory.create()) .setName(name) .setKey(key) .setDescription(request.param(PARAM_DESCRIPTION)) .setUrl(request.param(PARAM_URL)) .setAvatarUrl(request.param(PARAM_AVATAR_URL)); }
private static RemoveProjectCreatorFromTemplateWsRequest toWsRequest(Request request) { RemoveProjectCreatorFromTemplateWsRequest wsRequest = RemoveProjectCreatorFromTemplateWsRequest.builder() .setPermission(request.mandatoryParam(PARAM_PERMISSION)) .setTemplateId(request.param(PARAM_TEMPLATE_ID)) .setTemplateName(request.param(PARAM_TEMPLATE_NAME)) .build(); validateProjectPermission(wsRequest.getPermission()); return wsRequest; }
@Override public void handle(Request wsRequest, Response wsResponse) throws Exception { String name = wsRequest.mandatoryParam(PARAM_TEMPLATE_NAME); String description = wsRequest.param(PARAM_TEMPLATE_DESCRIPTION); String projectPattern = wsRequest.param(PARAM_TEMPLATE_PATTERN); DbSession dbSession = dbClient.openSession(false); try { checkGlobalAdminUser(userSession); validateTemplateNameForCreation(dbSession, name); validateProjectPattern(projectPattern); PermissionTemplateDto permissionTemplate = insertTemplate(dbSession, name, description, projectPattern); Permissions.CreatePermissionTemplateResponse response = buildResponse(permissionTemplate); writeProtobuf(response, wsRequest, wsResponse); } finally { dbClient.closeSession(dbSession); } }
private static ActivityWsRequest toSearchWsRequest(Request request) { ActivityWsRequest activityWsRequest = new ActivityWsRequest() .setComponentId(request.param(PARAM_COMPONENT_ID)) .setQuery( defaultString( request.param(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(request.paramAsBoolean(PARAM_ONLY_CURRENTS)) .setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)); checkRequest( activityWsRequest.getComponentId() == null || activityWsRequest.getQuery() == null, "%s and %s must not be set at the same time", PARAM_COMPONENT_ID, PARAM_COMPONENT_QUERY); checkRequest( activityWsRequest.getPageSize() <= MAX_PAGE_SIZE, "The '%s' parameter must be less than %d", Param.PAGE_SIZE, MAX_PAGE_SIZE); return activityWsRequest; }
@CheckForNull private static String getAndCheckKey(Request request) { String rqstKey = request.param(PARAM_KEY); if (rqstKey != null) { checkArgument( rqstKey.length() >= KEY_MIN_LENGTH, "Key '%s' must be at least %s chars long", rqstKey, KEY_MIN_LENGTH); checkArgument( rqstKey.length() <= KEY_MAX_LENGTH, "Key '%s' must be at most %s chars long", rqstKey, KEY_MAX_LENGTH); checkArgument( slugify(rqstKey).equals(rqstKey), "Key '%s' contains at least one invalid char", rqstKey); } return rqstKey; }