use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class ComponentAction method doHandle.
private ComponentWsResponse doHandle(ComponentWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.getComponentId(), request.getComponentKey(), COMPONENT_ID_AND_KEY);
Long developerId = searchDeveloperId(dbSession, request);
Optional<ComponentDto> refComponent = getReferenceComponent(dbSession, component);
checkPermissions(component);
SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.projectUuid()).orElse(null);
List<MetricDto> metrics = searchMetrics(dbSession, request);
List<WsMeasures.Period> periods = snapshotToWsPeriods(analysis);
List<MeasureDto> measures = searchMeasures(dbSession, component, analysis, metrics, developerId);
return buildResponse(request, component, refComponent, measures, metrics, periods);
}
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class ComponentDtoToWsComponent method componentDtoToWsComponent.
static Component.Builder componentDtoToWsComponent(ComponentDto component, Map<MetricDto, MeasureDto> measuresByMetric, Map<String, ComponentDto> referenceComponentsByUuid) {
Component.Builder wsComponent = componentDtoToWsComponent(component);
ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyResourceUuid());
if (referenceComponent != null) {
wsComponent.setRefId(referenceComponent.uuid());
wsComponent.setRefKey(referenceComponent.key());
}
for (Map.Entry<MetricDto, MeasureDto> entry : measuresByMetric.entrySet()) {
wsComponent.addMeasures(measureDtoToWsMeasure(entry.getKey(), entry.getValue()));
}
return wsComponent;
}
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 {
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.metric.MetricDto in project sonarqube by SonarSource.
the class MetricsAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto project = componentFinder.getByUuidOrKey(dbSession, request.param(CreateAction.PARAM_PROJECT_ID), request.param(CreateAction.PARAM_PROJECT_KEY), PROJECT_ID_AND_KEY);
checkPermissions(userSession, project);
List<MetricDto> metrics = searchMetrics(dbSession, project);
writeResponse(response.newJsonWriter(), metrics);
}
}
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 {
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