use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class MeasureAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
response.setHeader("Cache-Control", "no-cache");
response.stream().setMediaType(SVG);
String metricKey = request.mandatoryParam(PARAM_METRIC);
try (DbSession dbSession = dbClient.openSession(false)) {
support.validateToken(request);
BranchDto branch = support.getBranch(dbSession, request);
MetricDto metric = dbClient.metricDao().selectByKey(dbSession, metricKey);
checkState(metric != null && metric.isEnabled(), "Metric '%s' hasn't been found", metricKey);
LiveMeasureDto measure = getMeasure(dbSession, branch, metricKey);
String result = generateSvg(metric, measure);
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);
}
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class SearchEventsAction method computeQualityGateChangeEvents.
private Stream<Event> computeQualityGateChangeEvents(DbSession dbSession, Map<String, ComponentDto> projectsByUuid, Map<String, BranchDto> branchesByUuids, List<SnapshotDto> analyses) {
Map<String, EventDto> eventsByComponentUuid = new HashMap<>();
dbClient.eventDao().selectByAnalysisUuids(dbSession, analyses.stream().map(SnapshotDto::getUuid).collect(toList(analyses.size()))).stream().sorted(comparing(EventDto::getDate)).filter(e -> EventCategory.QUALITY_GATE.getLabel().equals(e.getCategory())).forEach(e -> eventsByComponentUuid.put(e.getComponentUuid(), e));
Predicate<EventDto> branchPredicate = e -> branchesByUuids.get(e.getComponentUuid()).getBranchType() == BRANCH;
return eventsByComponentUuid.values().stream().sorted(comparing(EventDto::getDate)).filter(branchPredicate).map(e -> {
BranchDto branch = branchesByUuids.get(e.getComponentUuid());
ComponentDto project = projectsByUuid.get(branch.getProjectUuid());
checkState(project != null, "Found event '%s', for a component that we did not search for", e.getUuid());
return Event.newBuilder().setCategory(EventCategory.fromLabel(e.getCategory()).name()).setProject(project.getKey()).setMessage(branch.isMain() ? format("Quality Gate status of project '%s' changed to '%s'", project.name(), e.getName()) : format("Quality Gate status of project '%s' on branch '%s' changed to '%s'", project.name(), branch.getKey(), e.getName())).setLink(computeDashboardLink(project, branch)).setDate(formatDateTime(e.getDate())).build();
});
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class SetAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String projectKey = request.getParam(PARAM_PROJECT).emptyAsNull().or(() -> null);
String branchKey = request.getParam(PARAM_BRANCH).emptyAsNull().or(() -> null);
if (projectKey == null && branchKey != null) {
throw new IllegalArgumentException("If branch key is specified, project key needs to be specified too");
}
try (DbSession dbSession = dbClient.openSession(false)) {
String typeStr = request.mandatoryParam(PARAM_TYPE);
String valueStr = request.getParam(PARAM_VALUE).emptyAsNull().or(() -> null);
boolean isCommunityEdition = editionProvider.get().filter(t -> t == EditionProvider.Edition.COMMUNITY).isPresent();
NewCodePeriodType type = validateType(typeStr, projectKey == null, branchKey != null || isCommunityEdition);
NewCodePeriodDto dto = new NewCodePeriodDto();
dto.setType(type);
ProjectDto project = null;
BranchDto branch = null;
if (projectKey != null) {
project = getProject(dbSession, projectKey);
userSession.checkProjectPermission(UserRole.ADMIN, project);
if (branchKey != null) {
branch = getBranch(dbSession, project, branchKey);
dto.setBranchUuid(branch.getUuid());
} else if (isCommunityEdition) {
// in CE set main branch value instead of project value
branch = getMainBranch(dbSession, project);
dto.setBranchUuid(branch.getUuid());
}
dto.setProjectUuid(project.getUuid());
} else {
userSession.checkIsSystemAdministrator();
}
setValue(dbSession, dto, type, project, branch, valueStr);
newCodePeriodDao.upsert(dbSession, dto);
dbSession.commit();
}
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class SetAction method checkAnalysis.
private void checkAnalysis(DbSession dbSession, ProjectDto project, BranchDto branch, SnapshotDto analysis) {
BranchDto analysisBranch = dbClient.branchDao().selectByUuid(dbSession, analysis.getComponentUuid()).orElse(null);
boolean analysisMatchesProjectBranch = analysisBranch != null && analysisBranch.getUuid().equals(branch.getUuid());
checkArgument(analysisMatchesProjectBranch, "Analysis '%s' does not belong to branch '%s' of project '%s'", analysis.getUuid(), branch.getKey(), project.getKey());
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class IndexIssuesStepTest method execute_on_already_indexed_branch.
@Test
public void execute_on_already_indexed_branch() {
BranchDto branchDto = new BranchDto().setBranchType(BRANCH).setKey("branchName").setUuid(BRANCH_UUID).setProjectUuid("project_uuid").setNeedIssueSync(false);
dbClient.branchDao().insert(dbTester.getSession(), branchDto);
dbTester.commit();
underTest.execute(() -> null);
verify(issueIndexer, times(0)).indexOnAnalysis(BRANCH_UUID);
}
Aggregations