private MetricDto searchMetric(DbSession dbSession, Request request) { Integer metricId = request.paramAsInt(PARAM_METRIC_ID); String metricKey = request.param(PARAM_METRIC_KEY); checkArgument(metricId != null ^ metricKey != null, "Either the metric id or the metric key must be provided"); if (metricId == null) { MetricDto metric = dbClient.metricDao().selectByKey(dbSession, metricKey); checkArgument(metric != null, "Metric with key '%s' does not exist", metricKey); return metric; } MetricDto metric = dbClient.metricDao().selectById(dbSession, metricId); checkArgument(metric != null, "Metric with id '%s' does not exist", metricId); return metric; } }
public GroupDto findGroupDto(DbSession dbSession, Request request) { Integer id = request.paramAsInt(PARAM_GROUP_ID); String organizationKey = request.param(PARAM_ORGANIZATION_KEY); String name = request.param(PARAM_GROUP_NAME); return findGroupDto(dbSession, GroupWsRef.create(id, organizationKey, name)); }
public GroupIdOrAnyone findGroup(DbSession dbSession, Request request) { Integer groupId = request.paramAsInt(PARAM_GROUP_ID); String orgKey = request.param(PARAM_ORGANIZATION); String groupName = request.param(PARAM_GROUP_NAME); GroupWsRef groupRef = GroupWsRef.create(groupId, orgKey, groupName); return groupWsSupport.findGroupOrAnyone(dbSession, groupRef); }
@Override public void handle(Request request, Response response) { String fileKey = request.mandatoryParam("key"); int from = Math.max(request.paramAsInt("from"), 1); int to = (Integer) ObjectUtils.defaultIfNull(request.paramAsInt("to"), Integer.MAX_VALUE); try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto file = componentFinder.getByKey(dbSession, fileKey); userSession.checkComponentPermission(UserRole.CODEVIEWER, file); Iterable<String> linesHtml = checkFoundWithOptional(sourceService.getLinesAsHtml(dbSession, file.uuid(), from, to), "No source found for file '%s'", fileKey); try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); writeSource(linesHtml, from, json); json.endObject(); } } }
@Override public void handle(Request request, Response response) { String fileKey = request.mandatoryParam("resource"); int from = request.mandatoryParamAsInt("from"); Integer to = request.paramAsInt("to"); try (DbSession session = dbClient.openSession(false)) { ComponentDto component = componentFinder.getByKey(session, fileKey); userSession.checkComponentPermission(UserRole.CODEVIEWER, component); Optional<Iterable<String>> lines = sourceService.getLinesAsRawText(session, component.uuid(), from, to == null ? Integer.MAX_VALUE : (to - 1)); try (JsonWriter json = response.newJsonWriter()) { json.beginArray().beginObject(); if (lines.isPresent()) { int lineCounter = from; for (String line : lines.get()) { json.prop(String.valueOf(lineCounter), line); lineCounter++; } } json.endObject().endArray(); } } } }
@Override public void handle(Request request, Response response) { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto file = loadComponent(dbSession, request); Supplier<Optional<Long>> periodDateSupplier = () -> dbClient.snapshotDao() .selectLastAnalysisByComponentUuid(dbSession, file.projectUuid()) .map(SnapshotDto::getPeriodDate); userSession.checkComponentPermission(UserRole.CODEVIEWER, file); int from = request.mandatoryParamAsInt(PARAM_FROM); int to = MoreObjects.firstNonNull(request.paramAsInt(PARAM_TO), Integer.MAX_VALUE); Iterable<DbFileSources.Line> lines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "No source found for file '%s'", file.getDbKey()); try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); writeSource(lines, json, isMemberOfOrganization(dbSession, file), periodDateSupplier); json.endObject(); } } }
.setMetricSort(request.param(PARAM_METRIC_SORT)) .setMetricSortFilter(request.mandatoryParam(PARAM_METRIC_SORT_FILTER)) .setMetricPeriodSort(request.paramAsInt(PARAM_METRIC_PERIOD_SORT)) .setDeveloperId(request.param(PARAM_DEVELOPER_ID)) .setDeveloperKey(request.param(PARAM_DEVELOPER_KEY))
@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(); } } }
@Override public void handle(Request request, Response response) { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, request.mandatoryParamAsLong(PARAM_GATE_ID)); Association associations = find(dbSession, ProjectQgateAssociationQuery.builder() .qualityGate(qualityGate) .membership(request.param(PARAM_QUERY) == null ? request.param(SELECTED) : ANY) .projectSearch(request.param(PARAM_QUERY)) .pageIndex(request.paramAsInt(PARAM_PAGE)) .pageSize(request.paramAsInt(PARAM_PAGE_SIZE)) .build()); Qualitygates.SearchResponse.Builder createResponse = Qualitygates.SearchResponse.newBuilder() .setMore(associations.hasMoreResults()); for (ProjectQgateAssociation project : associations.projects()) { createResponse.addResultsBuilder() .setId(project.id()) .setName(project.name()) .setSelected(project.isMember()); } writeProtobuf(createResponse.build(), request, response); } }
private MetricDto searchMetric(DbSession dbSession, Request request) { Integer metricId = request.paramAsInt(PARAM_METRIC_ID); String metricKey = request.param(PARAM_METRIC_KEY); checkArgument(metricId != null ^ metricKey != null, "Either the metric id or the metric key must be provided"); if (metricId == null) { MetricDto metric = dbClient.metricDao().selectByKey(dbSession, metricKey); checkArgument(metric != null, "Metric with key '%s' does not exist", metricKey); return metric; } MetricDto metric = dbClient.metricDao().selectById(dbSession, metricId); checkArgument(metric != null, "Metric with id '%s' does not exist", metricId); return metric; } }
public GroupIdOrAnyone findGroup(DbSession dbSession, Request request) { Integer groupId = request.paramAsInt(PARAM_GROUP_ID); String orgKey = request.param(PARAM_ORGANIZATION); String groupName = request.param(PARAM_GROUP_NAME); GroupWsRef groupRef = GroupWsRef.create(groupId, orgKey, groupName); return groupWsSupport.findGroupOrAnyone(dbSession, groupRef); }
public GroupDto findGroupDto(DbSession dbSession, Request request) { Integer id = request.paramAsInt(PARAM_GROUP_ID); String organizationKey = request.param(PARAM_ORGANIZATION_KEY); String name = request.param(PARAM_GROUP_NAME); return findGroupDto(dbSession, GroupWsRef.create(id, organizationKey, name)); }
@Override public void handle(Request request, Response response) { String fileKey = request.mandatoryParam("key"); int from = Math.max(request.paramAsInt("from"), 1); int to = (Integer) ObjectUtils.defaultIfNull(request.paramAsInt("to"), Integer.MAX_VALUE); try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto file = componentFinder.getByKey(dbSession, fileKey); userSession.checkComponentPermission(UserRole.CODEVIEWER, file); Iterable<String> linesHtml = checkFoundWithOptional(sourceService.getLinesAsHtml(dbSession, file.uuid(), from, to), "No source found for file '%s'", fileKey); try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); writeSource(linesHtml, from, json); json.endObject(); } } }
@Override public void handle(Request request, Response response) { String fileKey = request.mandatoryParam("resource"); int from = request.mandatoryParamAsInt("from"); Integer to = request.paramAsInt("to"); try (DbSession session = dbClient.openSession(false)) { ComponentDto component = componentFinder.getByKey(session, fileKey); userSession.checkComponentPermission(UserRole.CODEVIEWER, component); Optional<Iterable<String>> lines = sourceService.getLinesAsRawText(session, component.uuid(), from, to == null ? Integer.MAX_VALUE : (to - 1)); try (JsonWriter json = response.newJsonWriter()) { json.beginArray().beginObject(); if (lines.isPresent()) { int lineCounter = from; for (String line : lines.get()) { json.prop(String.valueOf(lineCounter), line); lineCounter++; } } json.endObject().endArray(); } } } }
@Override public void handle(Request request, Response response) { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto file = loadComponent(dbSession, request); userSession.checkComponentPermission(UserRole.CODEVIEWER, file); int from = request.mandatoryParamAsInt(PARAM_FROM); int to = MoreObjects.firstNonNull(request.paramAsInt(PARAM_TO), Integer.MAX_VALUE); Iterable<DbFileSources.Line> lines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "No source found for file '%s'", file.getDbKey()); try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); writeSource(lines, json); json.endObject(); } } }
.setMetricSort(request.param(PARAM_METRIC_SORT)) .setMetricSortFilter(request.mandatoryParam(PARAM_METRIC_SORT_FILTER)) .setMetricPeriodSort(request.paramAsInt(PARAM_METRIC_PERIOD_SORT)) .setDeveloperId(request.param(PARAM_DEVELOPER_ID)) .setDeveloperKey(request.param(PARAM_DEVELOPER_KEY))
@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(); } } }
@Override public void handle(Request request, Response response) { int gateId = request.mandatoryParamAsInt(PARAM_GATE_ID); String metric = request.mandatoryParam(PARAM_METRIC); String operator = request.mandatoryParam(PARAM_OPERATOR); String warning = request.param(PARAM_WARNING); String error = request.param(PARAM_ERROR); Integer period = request.paramAsInt(PARAM_PERIOD); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QGateWithOrgDto qualityGate = qualityGateFinder.getByOrganizationAndId(dbSession, organization, gateId); wsSupport.checkCanEdit(qualityGate); QualityGateConditionDto condition = qualityGateConditionsUpdater.createCondition(dbSession, qualityGate, metric, operator, emptyToNull(warning), emptyToNull(error), period); CreateConditionResponse.Builder createConditionResponse = CreateConditionResponse.newBuilder() .setId(condition.getId()) .setMetric(condition.getMetricKey()) .setOp(condition.getOperator()); setNullable(condition.getWarningThreshold(), createConditionResponse::setWarning); setNullable(condition.getErrorThreshold(), createConditionResponse::setError); setNullable(condition.getPeriod(), createConditionResponse::setPeriod); writeProtobuf(createConditionResponse.build(), request, response); dbSession.commit(); } }
@Override public void handle(Request request, Response response) { int id = request.mandatoryParamAsInt(PARAM_ID); String metric = request.mandatoryParam(PARAM_METRIC); String operator = request.mandatoryParam(PARAM_OPERATOR); String warning = request.param(PARAM_WARNING); String error = request.param(PARAM_ERROR); Integer period = request.paramAsInt(PARAM_PERIOD); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QualityGateConditionDto condition = wsSupport.getCondition(dbSession, id); QGateWithOrgDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndId(dbSession, organization, condition.getQualityGateId()); checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", id, condition.getQualityGateId()); wsSupport.checkCanEdit(qualityGateDto); QualityGateConditionDto updatedCondition = qualityGateConditionsUpdater.updateCondition(dbSession, condition, metric, operator, emptyToNull(warning), emptyToNull(error), period); UpdateConditionResponse.Builder updateConditionResponse = UpdateConditionResponse.newBuilder() .setId(updatedCondition.getId()) .setMetric(updatedCondition.getMetricKey()) .setOp(updatedCondition.getOperator()); setNullable(updatedCondition.getWarningThreshold(), updateConditionResponse::setWarning); setNullable(updatedCondition.getErrorThreshold(), updateConditionResponse::setError); setNullable(updatedCondition.getPeriod(), updateConditionResponse::setPeriod); writeProtobuf(updateConditionResponse.build(), request, response); dbSession.commit(); } } }
@Override public void handle(Request request, Response response) { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QGateWithOrgDto qualityGate = qualityGateFinder.getByOrganizationAndId(dbSession, organization, request.mandatoryParamAsLong(PARAM_GATE_ID)); Association associations = find(dbSession, ProjectQgateAssociationQuery.builder() .qualityGate(qualityGate) .membership(request.param(PARAM_QUERY) == null ? request.param(SELECTED) : ANY) .projectSearch(request.param(PARAM_QUERY)) .pageIndex(request.paramAsInt(PARAM_PAGE)) .pageSize(request.paramAsInt(PARAM_PAGE_SIZE)) .build()); Qualitygates.SearchResponse.Builder createResponse = Qualitygates.SearchResponse.newBuilder() .setMore(associations.hasMoreResults()); for (ProjectQgateAssociation project : associations.projects()) { createResponse.addResultsBuilder() .setId(project.id()) .setName(project.name()) .setSelected(project.isMember()); } writeProtobuf(createResponse.build(), request, response); } }