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();
}
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();
}
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()));
}
}
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();
}
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);
}
Aggregations