Search in sources :

Example 1 with EventDto

use of org.sonar.db.event.EventDto in project sonarqube by SonarSource.

the class CreateEventAction method insertDbEvent.

private EventDto insertDbEvent(DbSession dbSession, CreateEventRequest request, SnapshotDto analysis) {
    EventDto dbEvent = dbClient.eventDao().insert(dbSession, toDbEvent(request, analysis));
    if (VERSION.equals(request.getCategory())) {
        analysis.setVersion(request.getName());
        dbClient.snapshotDao().update(dbSession, analysis);
    }
    dbSession.commit();
    return dbEvent;
}
Also used : EventDto(org.sonar.db.event.EventDto)

Example 2 with EventDto

use of org.sonar.db.event.EventDto in project sonarqube by SonarSource.

the class CreateEventAction method doHandle.

private CreateEventResponse doHandle(CreateEventRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        SnapshotDto analysis = getAnalysis(dbSession, request);
        checkExistingDbEvents(dbSession, request, analysis);
        EventDto dbEvent = insertDbEvent(dbSession, request, analysis);
        return toCreateEventResponse(dbEvent);
    }
}
Also used : DbSession(org.sonar.db.DbSession) SnapshotDto(org.sonar.db.component.SnapshotDto) EventDto(org.sonar.db.event.EventDto)

Example 3 with EventDto

use of org.sonar.db.event.EventDto in project sonarqube by SonarSource.

the class CreateEventActionTest method create_event_in_db.

@Test
public void create_event_in_db() {
    ComponentDto project = newProjectDto(db.organizations().insert());
    SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
    CreateEventRequest.Builder request = CreateEventRequest.builder().setAnalysis(analysis.getUuid()).setCategory(VERSION).setName("5.6.3");
    when(system.now()).thenReturn(123_456_789L);
    logInAsProjectAdministrator(project);
    CreateEventResponse result = call(request);
    List<EventDto> dbEvents = dbClient.eventDao().selectByComponentUuid(dbSession, analysis.getComponentUuid());
    assertThat(dbEvents).hasSize(1);
    EventDto dbEvent = dbEvents.get(0);
    assertThat(dbEvent.getName()).isEqualTo("5.6.3");
    assertThat(dbEvent.getCategory()).isEqualTo(VERSION.getLabel());
    assertThat(dbEvent.getDescription()).isNull();
    assertThat(dbEvent.getAnalysisUuid()).isEqualTo(analysis.getUuid());
    assertThat(dbEvent.getComponentUuid()).isEqualTo(analysis.getComponentUuid());
    assertThat(dbEvent.getUuid()).isEqualTo(result.getEvent().getKey());
    assertThat(dbEvent.getCreatedAt()).isEqualTo(123_456_789L);
    assertThat(dbEvent.getDate()).isEqualTo(analysis.getCreatedAt());
}
Also used : CreateEventRequest(org.sonarqube.ws.client.projectanalysis.CreateEventRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) CreateEventResponse(org.sonarqube.ws.ProjectAnalyses.CreateEventResponse) Test(org.junit.Test)

Example 4 with EventDto

use of org.sonar.db.event.EventDto in project sonarqube by SonarSource.

the class UpdateEventActionTest method ws_response_with_updated_name.

@Test
public void ws_response_with_updated_name() {
    SnapshotDto analysis = createAnalysisAndLogInAsProjectAdministrator("5.6");
    EventDto originalEvent = db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name"));
    ProjectAnalyses.Event result = call("E1", "name").getEvent();
    assertThat(result.getName()).isEqualTo("name");
    assertThat(result.hasDescription()).isFalse();
    assertThat(result.getCategory()).isEqualTo(OTHER.name());
    assertThat(result.getAnalysis()).isEqualTo(originalEvent.getAnalysisUuid());
    assertThat(result.getKey()).isEqualTo("E1");
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) EventDto(org.sonar.db.event.EventDto) ProjectAnalyses(org.sonarqube.ws.ProjectAnalyses) Test(org.junit.Test)

Example 5 with EventDto

use of org.sonar.db.event.EventDto in project sonarqube by SonarSource.

the class SearchActionTest method return_events.

@Test
public void return_events() {
    OrganizationDto organizationDto = db.organizations().insert();
    ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto).setKey("P1"));
    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
    SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
    SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(newProjectDto(organizationDto)).setUuid("A42"));
    EventDto e1 = db.events().insertEvent(newEvent(a1).setUuid("E1").setName("N1").setCategory(EventCategory.QUALITY_GATE.getLabel()).setDescription("D1"));
    EventDto e2 = db.events().insertEvent(newEvent(a1).setUuid("E2").setName("N2").setCategory(VERSION.getLabel()).setDescription("D2"));
    db.events().insertEvent(newEvent(a42));
    List<Analysis> result = call("P1").getAnalysesList();
    assertThat(result).hasSize(1);
    List<Event> events = result.get(0).getEventsList();
    assertThat(events).hasSize(2);
    assertThat(events).extracting(Event::getKey, wsToDbCategory(), Event::getName, Event::getDescription).containsOnly(tuple(e1.getUuid(), e1.getCategory(), e1.getName(), e1.getDescription()), tuple(e2.getUuid(), e2.getCategory(), e2.getName(), e2.getDescription()));
}
Also used : SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) Analysis(org.sonarqube.ws.ProjectAnalyses.Analysis) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) EventTesting.newEvent(org.sonar.db.event.EventTesting.newEvent) Event(org.sonarqube.ws.ProjectAnalyses.Event) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

EventDto (org.sonar.db.event.EventDto)9 SnapshotDto (org.sonar.db.component.SnapshotDto)8 Test (org.junit.Test)7 ComponentDto (org.sonar.db.component.ComponentDto)4 CreateEventRequest (org.sonarqube.ws.client.projectanalysis.CreateEventRequest)2 DbSession (org.sonar.db.DbSession)1 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)1 EventTesting.newEvent (org.sonar.db.event.EventTesting.newEvent)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 ProjectAnalyses (org.sonarqube.ws.ProjectAnalyses)1 Analysis (org.sonarqube.ws.ProjectAnalyses.Analysis)1 CreateEventResponse (org.sonarqube.ws.ProjectAnalyses.CreateEventResponse)1 Event (org.sonarqube.ws.ProjectAnalyses.Event)1