use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class CreateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn().checkIsSystemAdministrator();
String key = request.mandatoryParam(PARAM_KEY);
try (DbSession dbSession = dbClient.openSession(false)) {
MetricDto metricTemplate = newMetricTemplate(request);
MetricDto metricInDb = dbClient.metricDao().selectByKey(dbSession, key);
checkMetricInDbAndTemplate(dbSession, metricInDb, metricTemplate);
if (metricIsNotInDb(metricInDb)) {
metricInDb = insertNewMetric(dbSession, metricTemplate);
} else {
updateMetric(dbSession, metricInDb, metricTemplate);
}
JsonWriter json = response.newJsonWriter();
writeMetric(json, metricInDb);
json.close();
}
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
SearchOptions searchOptions = new SearchOptions().setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE));
Boolean isCustom = request.paramAsBoolean(PARAM_IS_CUSTOM);
try (DbSession dbSession = dbClient.openSession(false)) {
List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, isCustom, searchOptions.getOffset(), searchOptions.getLimit());
int nbMetrics = dbClient.metricDao().countEnabled(dbSession, isCustom);
JsonWriter json = response.newJsonWriter();
json.beginObject();
Set<String> desiredFields = desiredFields(request.paramAsStrings(Param.FIELDS));
writeMetrics(json, metrics, desiredFields);
searchOptions.writeJson(json, nbMetrics);
json.endObject();
json.close();
}
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class UpdateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn().checkIsSystemAdministrator();
int id = request.mandatoryParamAsInt(PARAM_ID);
try (DbSession dbSession = dbClient.openSession(false)) {
MetricDto metricTemplate = newMetricTemplate(request);
MetricDto metricInDb = dbClient.metricDao().selectById(dbSession, id);
checkMetricInDbAndTemplate(dbSession, metricInDb, metricTemplate);
updateMetricInDb(dbSession, metricInDb, metricTemplate);
JsonWriter json = response.newJsonWriter();
writeMetric(json, metricInDb);
json.close();
}
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class ComponentTreeDataLoader method searchMeasuresByComponentUuidAndMetric.
private Table<String, MetricDto, MeasureDto> searchMeasuresByComponentUuidAndMetric(DbSession dbSession, ComponentDto baseComponent, ComponentTreeQuery componentTreeQuery, List<ComponentDto> components, List<MetricDto> metrics, @Nullable Long developerId) {
Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId);
MeasureTreeQuery measureQuery = MeasureTreeQuery.builder().setStrategy(MeasureTreeQuery.Strategy.valueOf(componentTreeQuery.getStrategy().name())).setNameOrKeyQuery(componentTreeQuery.getNameOrKeyQuery()).setQualifiers(componentTreeQuery.getQualifiers()).setPersonId(developerId).setMetricIds(new ArrayList<>(metricsById.keySet())).build();
List<MeasureDto> measureDtos = dbClient.measureDao().selectTreeByQuery(dbSession, baseComponent, measureQuery);
Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric = HashBasedTable.create(components.size(), metrics.size());
for (MeasureDto measureDto : measureDtos) {
measuresByComponentUuidAndMetric.put(measureDto.getComponentUuid(), metricsById.get(measureDto.getMetricId()), measureDto);
}
addBestValuesToMeasures(measuresByComponentUuidAndMetric, components, metrics);
return measuresByComponentUuidAndMetric;
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class SearchHistoryAction method searchMeasures.
private List<MeasureDto> searchMeasures(DbSession dbSession, SearchHistoryRequest request, SearchHistoryResult result) {
Date from = parseStartingDateOrDateTime(request.getFrom());
Date to = parseEndingDateOrDateTime(request.getTo());
PastMeasureQuery dbQuery = new PastMeasureQuery(result.getComponent().uuid(), result.getMetrics().stream().map(MetricDto::getId).collect(Collectors.toList()), from == null ? null : from.getTime(), to == null ? null : (to.getTime() + 1_000L));
return dbClient.measureDao().selectPastMeasures(dbSession, dbQuery);
}
Aggregations