use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.
the class CustomMeasuresCopyStep method copy.
private void copy(Component component) {
for (CustomMeasureDto dto : loadCustomMeasures(component)) {
Metric metric = metricRepository.getById(dto.getMetricId());
// else metric is not found and an exception is raised
Measure measure = dtoToMeasure(dto, metric);
measureRepository.add(component, metric, measure);
}
}
use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.
the class CreateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String valueAsString = request.mandatoryParam(PARAM_VALUE);
String description = request.param(PARAM_DESCRIPTION);
long now = system.now();
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.param(PARAM_PROJECT_ID), request.param(PARAM_PROJECT_KEY), PROJECT_ID_AND_KEY);
MetricDto metric = searchMetric(dbSession, request);
checkPermissions(userSession, component);
checkIsProjectOrModule(component);
checkMeasureDoesNotExistAlready(dbSession, component, metric);
UserDto user = dbClient.userDao().selectOrFailByLogin(dbSession, userSession.getLogin());
CustomMeasureDto measure = new CustomMeasureDto().setComponentUuid(component.uuid()).setMetricId(metric.getId()).setDescription(description).setUserLogin(user.getLogin()).setCreatedAt(now).setUpdatedAt(now);
validator.setMeasureValue(measure, valueAsString, metric);
dbClient.customMeasureDao().insert(dbSession, measure);
dbSession.commit();
JsonWriter json = response.newJsonWriter();
customMeasureJsonWriter.write(json, measure, metric, component, user, true, CustomMeasureJsonWriter.OPTIONAL_FIELDS);
json.close();
}
}
use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.
the class CustomMeasureJsonWriter method write.
public void write(JsonWriter json, List<CustomMeasureDto> customMeasures, ComponentDto project, Map<Integer, MetricDto> metricsById, Map<String, UserDto> usersByLogin, @Nullable Long lastAnalysisTimestamp, Collection<String> fieldsToReturn) {
json.name("customMeasures");
json.beginArray();
for (CustomMeasureDto customMeasure : customMeasures) {
boolean pending = lastAnalysisTimestamp == null || lastAnalysisTimestamp < customMeasure.getUpdatedAt();
write(json, customMeasure, metricsById.get(customMeasure.getMetricId()), project, usersByLogin.get(customMeasure.getUserLogin()), pending, fieldsToReturn);
}
json.endArray();
}
use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.
the class DeleteAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
long id = request.mandatoryParamAsLong(PARAM_ID);
try (DbSession dbSession = dbClient.openSession(false)) {
CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectOrFail(dbSession, id);
checkPermission(dbSession, customMeasure);
dbClient.customMeasureDao().delete(dbSession, id);
dbSession.commit();
}
response.noContent();
}
use of org.sonar.db.measure.custom.CustomMeasureDto in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String projectUuid = request.param(PARAM_PROJECT_ID);
String projectKey = request.param(PARAM_PROJECT_KEY);
List<String> fieldsToReturn = request.paramAsStrings(WebService.Param.FIELDS);
SearchOptions searchOptions = new SearchOptions().setPage(request.mandatoryParamAsInt(WebService.Param.PAGE), request.mandatoryParamAsInt(WebService.Param.PAGE_SIZE));
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = componentFinder.getByUuidOrKey(dbSession, projectUuid, projectKey, PROJECT_ID_AND_KEY);
checkPermissions(userSession, component);
Long lastAnalysisDateMs = searchLastSnapshotDate(dbSession, component);
List<CustomMeasureDto> customMeasures = searchCustomMeasures(dbSession, component, searchOptions);
int nbCustomMeasures = countTotalOfCustomMeasures(dbSession, component);
Map<String, UserDto> usersByLogin = usersByLogin(dbSession, customMeasures);
Map<Integer, MetricDto> metricsById = metricsById(dbSession, customMeasures);
writeResponse(response, customMeasures, nbCustomMeasures, component, metricsById, usersByLogin, lastAnalysisDateMs, searchOptions, fieldsToReturn);
}
}
Aggregations