Search in sources :

Example 31 with QualityGateDto

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

the class ListAction method handle.

@Override
public void handle(Request request, Response response) {
    JsonWriter writer = response.newJsonWriter().beginObject().name("qualitygates").beginArray();
    for (QualityGateDto qgate : qualityGates.list()) {
        QualityGatesWs.writeQualityGate(qgate, writer);
    }
    writer.endArray();
    QualityGateDto defaultQgate = qualityGates.getDefault();
    if (defaultQgate != null) {
        writer.prop("default", defaultQgate.getId());
    }
    writer.endObject().close();
}
Also used : JsonWriter(org.sonar.api.utils.text.JsonWriter) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 32 with QualityGateDto

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

the class ShowAction method handle.

@Override
public void handle(Request request, Response response) {
    Long qGateId = request.paramAsLong(QualityGatesWsParameters.PARAM_ID);
    String qGateName = request.param(QualityGatesWsParameters.PARAM_NAME);
    checkOneOfIdOrNamePresent(qGateId, qGateName);
    QualityGateDto qGate = qGateId == null ? qualityGates.get(qGateName) : qualityGates.get(qGateId);
    qGateId = qGate.getId();
    JsonWriter writer = response.newJsonWriter().beginObject().prop(QualityGatesWsParameters.PARAM_ID, qGate.getId()).prop(QualityGatesWsParameters.PARAM_NAME, qGate.getName());
    Collection<QualityGateConditionDto> conditions = qualityGates.listConditions(qGateId);
    if (!conditions.isEmpty()) {
        writer.name("conditions").beginArray();
        for (QualityGateConditionDto condition : conditions) {
            QualityGatesWs.writeQualityGateCondition(condition, writer);
        }
        writer.endArray();
    }
    writer.endObject().close();
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) JsonWriter(org.sonar.api.utils.text.JsonWriter) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 33 with QualityGateDto

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

the class QualityGates method setDefault.

public void setDefault(DbSession dbSession, @Nullable Long idToUseAsDefault) {
    checkIsSystemAdministrator();
    if (idToUseAsDefault == null) {
        propertiesDao.deleteGlobalProperty(SONAR_QUALITYGATE_PROPERTY, dbSession);
    } else {
        QualityGateDto newDefault = getNonNullQgate(dbSession, idToUseAsDefault);
        propertiesDao.saveProperty(dbSession, new PropertyDto().setKey(SONAR_QUALITYGATE_PROPERTY).setValue(newDefault.getId().toString()));
    }
}
Also used : QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) PropertyDto(org.sonar.db.property.PropertyDto)

Example 34 with QualityGateDto

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

the class ComponentAction method writeQualityGate.

private void writeQualityGate(JsonWriter json, DbSession session, ComponentDto component) {
    Optional<QualityGateFinder.QualityGateData> qualityGateData = qualityGateFinder.getQualityGate(session, component.getId());
    if (!qualityGateData.isPresent()) {
        return;
    }
    QualityGateDto qualityGateDto = qualityGateData.get().getQualityGate();
    json.name("qualityGate").beginObject().prop("key", qualityGateDto.getId()).prop("name", qualityGateDto.getName()).prop("isDefault", qualityGateData.get().isDefault()).endObject();
}
Also used : QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 35 with QualityGateDto

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

the class QualityGatesTest method should_fail_rename_on_duplicate_name.

@Test(expected = BadRequestException.class)
public void should_fail_rename_on_duplicate_name() {
    long id = QUALITY_GATE_ID;
    String name = "SG-1";
    QualityGateDto existing = new QualityGateDto().setId(id).setName("Golden");
    when(dao.selectById(dbSession, id)).thenReturn(existing);
    when(dao.selectByName(dbSession, name)).thenReturn(new QualityGateDto().setId(666L).setName(name));
    underTest.rename(id, name);
}
Also used : QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

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