private Optional<String> loadQualityGateDetails(DbSession dbSession, ProjectAndSnapshot projectAndSnapshot, boolean onAnalysis) { if (onAnalysis) { if (!projectAndSnapshot.snapshotDto.isPresent()) { return Optional.empty(); } // get the gate status as it was computed during the specified analysis String analysisUuid = projectAndSnapshot.snapshotDto.get().getUuid(); return dbClient.measureDao().selectMeasure(dbSession, analysisUuid, projectAndSnapshot.project.projectUuid(), CoreMetrics.QUALITY_GATE_DETAILS_KEY) .map(MeasureDto::getData); } // do not restrict to a specified analysis, use the live measure Optional<LiveMeasureDto> measure = dbClient.liveMeasureDao().selectMeasure(dbSession, projectAndSnapshot.project.projectUuid(), CoreMetrics.QUALITY_GATE_DETAILS_KEY); return measure.map(LiveMeasureDto::getDataAsString); }
private Optional<MeasureDto> selectMeasure(String componentUuid, Metric metric) { return dbClient.measureDao().selectMeasure(db.getSession(), ANALYSIS_UUID, componentUuid, metric.getKey()); }
@Test public void test_selectMeasure() { MetricDto metric = db.measures().insertMetric(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); SnapshotDto lastAnalysis = insertAnalysis(project.uuid(), true); SnapshotDto pastAnalysis = insertAnalysis(project.uuid(), false); MeasureDto pastMeasure = MeasureTesting.newMeasureDto(metric, file, pastAnalysis); MeasureDto lastMeasure = MeasureTesting.newMeasureDto(metric, file, lastAnalysis); underTest.insert(db.getSession(), pastMeasure); underTest.insert(db.getSession(), lastMeasure); assertThat(underTest.selectMeasure(db.getSession(), lastAnalysis.getUuid(), file.uuid(), metric.getKey()).get()) .isEqualToComparingFieldByField(lastMeasure); assertThat(underTest.selectMeasure(db.getSession(), pastAnalysis.getUuid(), file.uuid(), metric.getKey()).get()) .isEqualToComparingFieldByField(pastMeasure); assertThat(underTest.selectMeasure(db.getSession(), "_missing_", file.uuid(), metric.getKey())).isEmpty(); assertThat(underTest.selectMeasure(db.getSession(), pastAnalysis.getUuid(), "_missing_", metric.getKey())).isEmpty(); assertThat(underTest.selectMeasure(db.getSession(), pastAnalysis.getUuid(), file.uuid(), "_missing_")).isEmpty(); }
private Optional<String> loadQualityGateDetails(DbSession dbSession, ProjectAndSnapshot projectAndSnapshot, boolean onAnalysis) { if (onAnalysis) { if (!projectAndSnapshot.snapshotDto.isPresent()) { return Optional.empty(); } // get the gate status as it was computed during the specified analysis String analysisUuid = projectAndSnapshot.snapshotDto.get().getUuid(); return dbClient.measureDao().selectMeasure(dbSession, analysisUuid, projectAndSnapshot.project.projectUuid(), CoreMetrics.QUALITY_GATE_DETAILS_KEY) .map(MeasureDto::getData); } // do not restrict to a specified analysis, use the live measure Optional<LiveMeasureDto> measure = dbClient.liveMeasureDao().selectMeasure(dbSession, projectAndSnapshot.project.projectUuid(), CoreMetrics.QUALITY_GATE_DETAILS_KEY); return measure.map(LiveMeasureDto::getDataAsString); }