use of org.sonar.db.event.EventComponentChangeDto in project sonarqube by SonarSource.
the class SearchResponseBuilder method addQualityGateInformation.
private void addQualityGateInformation(EventDto event) {
wsQualityGate.clear();
List<EventComponentChangeDto> eventComponentChangeDtos = searchData.componentChangesByEventUuid.get(event.getUuid());
if (eventComponentChangeDtos.isEmpty()) {
return;
}
if (event.getData() != null) {
try {
Gson gson = new Gson();
Data data = gson.fromJson(event.getData(), Data.class);
wsQualityGate.setStillFailing(data.isStillFailing());
wsQualityGate.setStatus(data.getStatus());
} catch (JsonSyntaxException ex) {
LOGGER.error("Unable to retrieve data from event uuid=" + event.getUuid(), ex);
return;
}
}
wsQualityGate.addAllFailing(eventComponentChangeDtos.stream().map(SearchResponseBuilder::toFailing).collect(toList()));
wsEvent.setQualityGate(wsQualityGate.build());
}
use of org.sonar.db.event.EventComponentChangeDto in project sonarqube by SonarSource.
the class SearchResponseBuilder method addBranchChange.
private static Project addBranchChange(Collection<EventComponentChangeDto> changes) {
if (changes.size() != 2) {
throw new IllegalStateException(format("Too many changes on same project (%d) for eventComponentChange uuids : %s", changes.size(), changes.stream().map(EventComponentChangeDto::getUuid).collect(Collectors.joining(","))));
}
Optional<EventComponentChangeDto> addedChange = changes.stream().filter(c -> c.getCategory().equals(EventComponentChangeDto.ChangeCategory.ADDED)).findFirst();
Optional<EventComponentChangeDto> removedChange = changes.stream().filter(c -> c.getCategory().equals(EventComponentChangeDto.ChangeCategory.REMOVED)).findFirst();
if (!addedChange.isPresent() || !removedChange.isPresent() || addedChange.equals(removedChange)) {
Iterator<EventComponentChangeDto> iterator = changes.iterator();
// We are missing two different ADDED and REMOVED changes
EventComponentChangeDto firstChange = iterator.next();
EventComponentChangeDto secondChange = iterator.next();
throw new IllegalStateException(format("Incorrect changes : [uuid=%s change=%s, branch=%s] and [uuid=%s, change=%s, branch=%s]", firstChange.getUuid(), firstChange.getCategory().name(), firstChange.getComponentBranchKey(), secondChange.getUuid(), secondChange.getCategory().name(), secondChange.getComponentBranchKey()));
}
return new Project().setName(addedChange.get().getComponentName()).setKey(addedChange.get().getComponentKey()).setChangeType("BRANCH_CHANGED").setNewBranch(addedChange.get().getComponentBranchKey()).setOldBranch(removedChange.get().getComponentBranchKey());
}
use of org.sonar.db.event.EventComponentChangeDto in project sonarqube by SonarSource.
the class SearchActionTest method incorrect_eventcomponentchange_two_identical_changes_added_on_same_project.
@Test
public void incorrect_eventcomponentchange_two_identical_changes_added_on_same_project() {
ComponentDto application = db.components().insertPublicApplication();
userSession.registerApplication(toProjectDto(application, 1L));
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, ADDED, "My project", "app1", "master", uuidFactoryFast.create());
EventComponentChangeDto changeDto2 = generateEventComponentChange(event, ADDED, "My project", "app1", "master", uuidFactoryFast.create());
EventPurgeData eventPurgeData = new EventPurgeData(application.uuid(), firstAnalysis.getUuid());
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto1, eventPurgeData);
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto2, eventPurgeData);
db.getSession().commit();
List<Analysis> result = call(application.getDbKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
assertThat(events).extracting(Event::getName, Event::getCategory, Event::getKey).containsExactly(tuple("", DEFINITION_CHANGE.name(), "E11"));
assertThat(events.get(0).getDefinitionChange().getProjectsList()).isEmpty();
assertThat(logTester.getLogs(LoggerLevel.ERROR)).extracting(LogAndArguments::getFormattedMsg).containsExactly(format("Incorrect changes : [uuid=%s change=ADDED, branch=master] and [uuid=%s, change=ADDED, branch=master]", changeDto1.getUuid(), changeDto2.getUuid()));
}
use of org.sonar.db.event.EventComponentChangeDto in project sonarqube by SonarSource.
the class SearchActionTest method return_definition_change_events_on_application_analyses.
@Test
public void return_definition_change_events_on_application_analyses() {
ComponentDto application = db.components().insertPublicApplication();
userSession.registerApplication(toProjectDto(application, 1L));
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, ADDED, "My project", "app1", "master", uuidFactoryFast.create());
EventComponentChangeDto changeDto2 = generateEventComponentChange(event, REMOVED, "Another project", "app2", "master", uuidFactoryFast.create());
insertEventComponentChanges(application, firstAnalysis, changeDto1, changeDto2);
List<Analysis> result = call(application.getDbKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
assertThat(events).extracting(Event::getName, Event::getCategory, Event::getKey).containsExactly(tuple("", DEFINITION_CHANGE.name(), "E11"));
assertThat(events.get(0).getDefinitionChange().getProjectsList()).extracting(Project::getChangeType, Project::getName, Project::getKey, Project::getNewBranch, Project::getOldBranch).containsExactly(tuple("ADDED", "My project", "app1", "", ""), tuple("REMOVED", "Another project", "app2", "", ""));
}
use of org.sonar.db.event.EventComponentChangeDto in project sonarqube by SonarSource.
the class SearchActionTest method incorrect_eventcomponentchange_incorrect_category.
@Test
public void incorrect_eventcomponentchange_incorrect_category() {
ComponentDto application = db.components().insertPublicApplication();
userSession.registerApplication(toProjectDto(application, 1L));
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, FAILED_QUALITY_GATE, "My project", "app1", "master", uuidFactoryFast.create());
EventPurgeData eventPurgeData = new EventPurgeData(application.uuid(), firstAnalysis.getUuid());
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto1, eventPurgeData);
db.getSession().commit();
List<Analysis> result = call(application.getDbKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
assertThat(events).extracting(Event::getName, Event::getCategory, Event::getKey).containsExactly(tuple("", DEFINITION_CHANGE.name(), "E11"));
assertThat(events.get(0).getDefinitionChange().getProjectsList()).isEmpty();
assertThat(logTester.getLogs(LoggerLevel.ERROR)).extracting(LogAndArguments::getFormattedMsg).containsExactly("Unknown change FAILED_QUALITY_GATE for eventComponentChange uuid: " + changeDto1.getUuid());
}
Aggregations