@Override public void handle(Request request, Response response) throws Exception { userSession.checkLoggedIn().checkPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN); String name = request.mandatoryParam(PARAM_PROFILE_NAME); String language = request.mandatoryParam(PARAM_LANGUAGE); DbSession dbSession = dbClient.openSession(false); try { QProfileResult result = new QProfileResult(); QualityProfileDto profile = profileFactory.create(dbSession, QProfileName.createFor(language, name)); result.setProfile(profile); for (ProfileImporter importer : importers) { InputStream contentToImport = request.paramAsInputStream(getBackupParamName(importer.getKey())); if (contentToImport != null) { result.add(exporters.importXml(profile, importer.getKey(), contentToImport, dbSession)); } } dbSession.commit(); response.stream().setMediaType(request.getMediaType()); JsonWriter jsonWriter = JsonWriter.of(new OutputStreamWriter(response.stream().output(), StandardCharsets.UTF_8)); writeResult(jsonWriter, result); } finally { dbSession.close(); } }
@Override public void handle(Request request, Response response) throws Exception { String key = request.mandatoryParam("issue"); issueService.doTransition(key, request.mandatoryParam("transition")); responseWriter.write(key, request, response); }
@Override public void handle(Request request, Response response) throws Exception { String permission = request.mandatoryParam(PARAM_PERMISSION); String userLogin = request.mandatoryParam(PARAM_USER_LOGIN); permissionService.removePermission( new PermissionChange().setPermission(permission).setUser(userLogin)); response.noContent(); }
@Override public void handle(Request request, Response response) { String query = request.mandatoryParam(Param.TEXT_QUERY); if (query.length() < MINIMUM_SEARCH_CHARACTERS) { throw new IllegalArgumentException( String.format("Minimum search is %s characters", MINIMUM_SEARCH_CHARACTERS)); } String componentUuid = request.mandatoryParam(PARAM_COMPONENT_UUID); JsonWriter json = response.newJsonWriter(); json.beginObject(); DbSession session = dbClient.openSession(false); try { ComponentDto componentDto = componentFinder.getByUuid(session, componentUuid); userSession.checkProjectUuidPermission(UserRole.USER, componentDto.projectUuid()); Set<Long> projectIds = newLinkedHashSet( dbClient .componentIndexDao() .selectProjectIdsFromQueryAndViewOrSubViewUuid( session, query, componentDto.uuid())); Collection<Long> authorizedProjectIds = dbClient .authorizationDao() .keepAuthorizedProjectIds( session, projectIds, userSession.getUserId(), UserRole.USER); SearchOptions options = new SearchOptions(); options.setPage(request.mandatoryParamAsInt(PAGE), request.mandatoryParamAsInt(PAGE_SIZE)); Set<Long> pagedProjectIds = pagedProjectIds(authorizedProjectIds, options); List<ComponentDto> projects = dbClient.componentDao().selectByIds(session, pagedProjectIds); options.writeJson(json, authorizedProjectIds.size()); json.name("components").beginArray(); for (ComponentDto project : projects) { json.beginObject(); json.prop("uuid", project.uuid()); json.prop("name", project.name()); json.endObject(); } json.endArray(); } finally { MyBatis.closeQuietly(session); } json.endObject(); json.close(); }
@Override public void handle(Request wsRequest, Response wsResponse) throws Exception { userSession.checkAnyGlobalPermissions(AUTHORIZED_PERMISSIONS); String taskUuid = wsRequest.mandatoryParam(PARAM_TASK_UUID); DbSession dbSession = dbClient.openSession(false); try { WsCe.TaskResponse.Builder wsTaskResponse = WsCe.TaskResponse.newBuilder(); Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, taskUuid); if (queueDto.isPresent()) { wsTaskResponse.setTask(wsTaskFormatter.formatQueue(dbSession, queueDto.get())); } else { Optional<CeActivityDto> activityDto = dbClient.ceActivityDao().selectByUuid(dbSession, taskUuid); if (activityDto.isPresent()) { wsTaskResponse.setTask(wsTaskFormatter.formatActivity(dbSession, activityDto.get())); } else { throw new NotFoundException(); } } writeProtobuf(wsTaskResponse.build(), wsRequest, wsResponse); } finally { dbClient.closeSession(dbSession); } }
@Override public void handle(Request request, Response response) { QualityGateDto newQualityGate = qualityGates.copy( QGatesWs.parseId(request, QGatesWs.PARAM_ID), request.mandatoryParam(QGatesWs.PARAM_NAME)); JsonWriter writer = response.newJsonWriter(); QGatesWs.writeQualityGate(newQualityGate, writer).close(); }
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 request, Response response) throws Exception { userSession.checkPermission(GlobalPermissions.SYSTEM_ADMIN); String key = request.mandatoryParam(PARAM_KEY); preventDeletionOfDefaultOrganization(key, defaultOrganizationProvider.get()); try (DbSession dbSession = dbClient.openSession(false)) { dbClient.organizationDao().deleteByKey(dbSession, key); dbSession.commit(); response.noContent(); } }
@Override public void handle(Request request, Response response) { final String ruleKeyParam = request.mandatoryParam("key"); RuleKey ruleKey = RuleKey.parse(ruleKeyParam); Rule rule = findRule(ruleKey); if (rule == null) { throw new NotFoundException("Rule not found: " + ruleKey); } JsonWriter json = response.newJsonWriter(); json.beginObject().name("rule").beginObject(); writeRule(rule, json); writeTags(rule, json); json.endObject().endObject().close(); }
@Override public void handle(Request request, Response response) { String fileKey = request.mandatoryParam("resource"); UserSession.get().checkComponentPermission(UserRole.CODEVIEWER, fileKey); Integer from = request.mandatoryParamAsInt("from"); Integer to = request.paramAsInt("to"); try (DbSession session = dbClient.openSession(false)) { ComponentDto componentDto = dbClient.componentDao().getByKey(session, fileKey); List<String> lines = sourceService.getLinesAsTxt(componentDto.uuid(), from, to == null ? null : to - 1); JsonWriter json = response.newJsonWriter().beginArray().beginObject(); Integer lineCounter = from; for (String line : lines) { json.prop(lineCounter.toString(), line); lineCounter++; } json.endObject().endArray().close(); } }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkPermission(GlobalPermissions.PREVIEW_EXECUTION); final String moduleKey = request.mandatoryParam(PARAM_KEY); response.stream().setMediaType(MediaTypes.PROTOBUF); DbSession session = dbClient.openSession(false); try { ComponentDto component = componentFinder.getByKey(session, moduleKey); Map<String, String> keysByUUid = keysByUUid(session, component); BatchInput.ServerIssue.Builder issueBuilder = BatchInput.ServerIssue.newBuilder(); for (Iterator<IssueDoc> issueDocIterator = issueIndex.selectIssuesForBatch(component); issueDocIterator.hasNext(); ) { handleIssue(issueDocIterator.next(), issueBuilder, keysByUUid, response.stream().output()); } } finally { MyBatis.closeQuietly(session); } }
@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); } }
@Override public void handle(Request request, Response response) { String componentUuid = request.mandatoryParam(PARAM_UUID); JsonWriter json = response.newJsonWriter(); json.beginObject(); DbSession session = dbClient.openSession(false); try { ComponentDto component = componentFinder.getByUuid(session, componentUuid); userSession.checkComponentPermission(UserRole.USER, component.getKey()); Map<String, MeasureDto> measuresByMetricKey = measuresByMetricKey(component, session); appendComponent(json, component, userSession, session); appendPermissions(json, component, userSession); appendMeasures(json, measuresByMetricKey); } finally { MyBatis.closeQuietly(session); } json.endObject(); json.close(); }