private QualityGateDto getByNameOrId(DbSession dbSession, OrganizationDto organization, @Nullable String name, @Nullable Long id) { if (name != null) { return checkFound(dbClient.qualityGateDao().selectByOrganizationAndName(dbSession, organization, name), "No quality gate has been found for name %s", name); } if (id != null) { return qualityGateFinder.getByOrganizationAndId(dbSession, organization, id); } throw new IllegalArgumentException("No parameter has been set to identify a quality gate"); }
private QualityGateDto rename(DbSession dbSession, OrganizationDto organization, long id, String name) { QGateWithOrgDto qualityGate = qualityGateFinder.getByOrganizationAndId(dbSession, organization, id); wsSupport.checkCanEdit(qualityGate); checkArgument(!isNullOrEmpty(name), CANT_BE_EMPTY_MESSAGE, "Name"); checkNotAlreadyExists(dbSession, organization, qualityGate, name); qualityGate.setName(name); dbClient.qualityGateDao().update(qualityGate, dbSession); dbSession.commit(); return qualityGate; }
@Override public void handle(Request request, Response response) { long qualityGateId = request.mandatoryParamAsLong(QualityGatesWsParameters.PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QGateWithOrgDto qualityGate = finder.getByOrganizationAndId(dbSession, organization, qualityGateId); QualityGateDto defaultQualityGate = finder.getDefault(dbSession, organization); checkArgument(!defaultQualityGate.getId().equals(qualityGate.getId()), "The default quality gate cannot be removed"); wsSupport.checkCanEdit(qualityGate); dbClient.propertiesDao().deleteByKeyAndValue(dbSession, SONAR_QUALITYGATE_PROPERTY, String.valueOf(qualityGate.getId())); dbClient.qualityGateDao().delete(qualityGate, dbSession); dbSession.commit(); response.noContent(); } }
@Override public void handle(Request request, Response response) { Long id = parseId(request, PARAM_ID); String destinationName = request.mandatoryParam(PARAM_NAME); checkArgument(!destinationName.isEmpty(), "The 'name' parameter is empty"); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); userSession.checkPermission(ADMINISTER_QUALITY_GATES, organization); QualityGateDto qualityGate = qualityGateFinder.getByOrganizationAndId(dbSession, organization, id); QualityGateDto copy = qualityGateUpdater.copy(dbSession, organization, qualityGate, destinationName); dbSession.commit(); writeProtobuf(newBuilder() .setId(copy.getId()) .setName(copy.getName()) .build(), request, response); } } }
@Override public void handle(Request request, Response response) { Long id = parseId(request, PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); userSession.checkPermission(ADMINISTER_QUALITY_GATES, organization); QualityGateDto qualityGate = qualityGateFinder.getByOrganizationAndId(dbSession, organization, id); organization.setDefaultQualityGateUuid(qualityGate.getUuid()); dbClient.organizationDao().update(dbSession, organization); dbSession.commit(); } response.noContent(); }
@Override public void handle(Request request, Response response) { long gateId = request.mandatoryParamAsLong(PARAM_GATE_ID); String projectId = request.param(PARAM_PROJECT_ID); String projectKey = request.param(PARAM_PROJECT_KEY); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QGateWithOrgDto qualityGate = qualityGateFinder.getByOrganizationAndId(dbSession, organization, gateId); ComponentDto project = getProject(dbSession, organization, projectId, projectKey); wsSupport.checkCanAdminProject(organization, project); dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(SONAR_QUALITYGATE_PROPERTY) .setResourceId(project.getId()) .setValue(String.valueOf(qualityGate.getId()))); dbSession.commit(); } response.noContent(); }
@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) { 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); } }