use of org.sonar.api.measures.Metric.Level in project sonarqube by SonarSource.
the class ProjectMeasuresQueryFactory method processQualityGateStatus.
private static void processQualityGateStatus(Criterion criterion, ProjectMeasuresQuery query) {
checkOperator(criterion);
checkValue(criterion);
Operator operator = criterion.getOperator();
String value = criterion.getValue();
checkArgument(EQ.equals(operator), "Only equals operator is available for quality gate criteria");
Level qualityGate = Arrays.stream(Level.values()).filter(level -> level.name().equalsIgnoreCase(value)).findFirst().orElseThrow(() -> new IllegalArgumentException(format("Unknown quality gate status : '%s'", value)));
query.setQualityGateStatus(qualityGate);
}
use of org.sonar.api.measures.Metric.Level in project sonarqube by SonarSource.
the class QualityGateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
response.setHeader("Cache-Control", "no-cache");
response.stream().setMediaType(SVG);
try (DbSession dbSession = dbClient.openSession(false)) {
support.validateToken(request);
BranchDto branch = support.getBranch(dbSession, request);
Level qualityGateStatus = getQualityGate(dbSession, branch);
String result = svgGenerator.generateQualityGate(qualityGateStatus);
String eTag = getETag(result);
Optional<String> requestedETag = request.header("If-None-Match");
if (requestedETag.filter(eTag::equals).isPresent()) {
response.stream().setStatus(304);
return;
}
response.setHeader("ETag", eTag);
write(result, response.stream().output(), UTF_8);
} catch (ProjectBadgesException | ForbiddenException | NotFoundException e) {
// There is an issue, so do not return any ETag but make this response expire now
SimpleDateFormat sdf = new SimpleDateFormat(RFC1123_DATE, Locale.US);
response.setHeader("Expires", sdf.format(new Date()));
write(svgGenerator.generateError(e.getMessage()), response.stream().output(), UTF_8);
}
}
Aggregations