Search in sources :

Example 6 with QualityGateDto

use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.

the class QualityGates method rename.

public QualityGateDto rename(long idToRename, String name) {
    checkIsSystemAdministrator();
    try (DbSession dbSession = dbClient.openSession(false)) {
        QualityGateDto toRename = getNonNullQgate(idToRename);
        validateQualityGate(dbSession, idToRename, name);
        toRename.setName(name);
        dao.update(toRename, dbSession);
        dbSession.commit();
        return toRename;
    }
}
Also used : DbSession(org.sonar.db.DbSession) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 7 with QualityGateDto

use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.

the class QualityGates method copy.

public QualityGateDto copy(long sourceId, String destinationName) {
    checkIsSystemAdministrator();
    getNonNullQgate(sourceId);
    try (DbSession dbSession = dbClient.openSession(false)) {
        validateQualityGate(dbSession, null, destinationName);
        QualityGateDto destinationGate = new QualityGateDto().setName(destinationName);
        dao.insert(dbSession, destinationGate);
        for (QualityGateConditionDto sourceCondition : conditionDao.selectForQualityGate(dbSession, sourceId)) {
            conditionDao.insert(new QualityGateConditionDto().setQualityGateId(destinationGate.getId()).setMetricId(sourceCondition.getMetricId()).setOperator(sourceCondition.getOperator()).setWarningThreshold(sourceCondition.getWarningThreshold()).setErrorThreshold(sourceCondition.getErrorThreshold()).setPeriod(sourceCondition.getPeriod()), dbSession);
        }
        dbSession.commit();
        return destinationGate;
    }
}
Also used : DbSession(org.sonar.db.DbSession) QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 8 with QualityGateDto

use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.

the class RegisterQualityGates method createBuiltinQualityGate.

private void createBuiltinQualityGate(DbSession dbSession) {
    String ratingAValue = Integer.toString(RatingGrid.Rating.A.getIndex());
    QualityGateDto builtin = qualityGateUpdater.create(dbSession, BUILTIN_QUALITY_GATE);
    qualityGateConditionsUpdater.createCondition(dbSession, builtin.getId(), NEW_SECURITY_RATING_KEY, OPERATOR_GREATER_THAN, null, ratingAValue, LEAK_PERIOD);
    qualityGateConditionsUpdater.createCondition(dbSession, builtin.getId(), NEW_RELIABILITY_RATING_KEY, OPERATOR_GREATER_THAN, null, ratingAValue, LEAK_PERIOD);
    qualityGateConditionsUpdater.createCondition(dbSession, builtin.getId(), NEW_MAINTAINABILITY_RATING_KEY, OPERATOR_GREATER_THAN, null, ratingAValue, LEAK_PERIOD);
    qualityGateConditionsUpdater.createCondition(dbSession, builtin.getId(), NEW_COVERAGE_KEY, OPERATOR_LESS_THAN, null, "80", LEAK_PERIOD);
    qualityGates.setDefault(dbSession, builtin.getId());
}
Also used : QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 9 with QualityGateDto

use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.

the class CopyAction method handle.

@Override
public void handle(Request request, Response response) {
    QualityGateDto newQualityGate = qualityGates.copy(QualityGatesWs.parseId(request, PARAM_ID), request.mandatoryParam(PARAM_NAME));
    JsonWriter writer = response.newJsonWriter();
    QualityGatesWs.writeQualityGate(newQualityGate, writer).close();
}
Also used : JsonWriter(org.sonar.api.utils.text.JsonWriter) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 10 with QualityGateDto

use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.

the class GetByProjectAction method buildResponse.

private static GetByProjectWsResponse buildResponse(Optional<QualityGateData> data) {
    if (!data.isPresent()) {
        return GetByProjectWsResponse.getDefaultInstance();
    }
    QualityGateDto qualityGate = data.get().getQualityGate();
    GetByProjectWsResponse.Builder response = GetByProjectWsResponse.newBuilder();
    response.getQualityGateBuilder().setId(String.valueOf(qualityGate.getId())).setName(qualityGate.getName()).setDefault(data.get().isDefault());
    return response.build();
}
Also used : GetByProjectWsResponse(org.sonarqube.ws.WsQualityGates.GetByProjectWsResponse) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Aggregations

QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)51 Test (org.junit.Test)33 ComponentDto (org.sonar.db.component.ComponentDto)12 DbSession (org.sonar.db.DbSession)6 PropertyDto (org.sonar.db.property.PropertyDto)6 GetByProjectWsResponse (org.sonarqube.ws.WsQualityGates.GetByProjectWsResponse)6 QualityGateConditionDto (org.sonar.db.qualitygate.QualityGateConditionDto)5 JsonWriter (org.sonar.api.utils.text.JsonWriter)4 OrganizationDto (org.sonar.db.organization.OrganizationDto)2 WsQualityGates (org.sonarqube.ws.WsQualityGates)2 CreateWsResponse (org.sonarqube.ws.WsQualityGates.CreateWsResponse)2 Matchers.anyString (org.mockito.Matchers.anyString)1 SnapshotDto (org.sonar.db.component.SnapshotDto)1 MetricDto (org.sonar.db.metric.MetricDto)1 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)1 UserDto (org.sonar.db.user.UserDto)1