Search in sources :

Example 1 with Level

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);
}
Also used : Operator(org.sonar.server.measure.index.ProjectMeasuresQuery.Operator) Level(org.sonar.api.measures.Metric.Level)

Example 2 with Level

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) BranchDto(org.sonar.db.component.BranchDto) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) NotFoundException(org.sonar.server.exceptions.NotFoundException) Level(org.sonar.api.measures.Metric.Level) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

Level (org.sonar.api.measures.Metric.Level)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 DbSession (org.sonar.db.DbSession)1 BranchDto (org.sonar.db.component.BranchDto)1 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)1 NotFoundException (org.sonar.server.exceptions.NotFoundException)1 Operator (org.sonar.server.measure.index.ProjectMeasuresQuery.Operator)1