Search in sources :

Example 1 with ComponentLinkDto

use of org.sonar.db.component.ComponentLinkDto in project sonarqube by SonarSource.

the class SearchMyProjectsDataLoader method load.

SearchMyProjectsData load(DbSession dbSession, SearchMyProjectsRequest request) {
    SearchMyProjectsData.Builder data = builder();
    ProjectsResult searchResult = searchProjects(dbSession, request);
    List<ComponentDto> projects = searchResult.projects;
    List<String> projectUuids = Lists.transform(projects, ComponentDto::projectUuid);
    List<ComponentLinkDto> projectLinks = dbClient.componentLinkDao().selectByComponentUuids(dbSession, projectUuids);
    List<SnapshotDto> snapshots = dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, projectUuids);
    MetricDto gateStatusMetric = dbClient.metricDao().selectOrFailByKey(dbSession, CoreMetrics.ALERT_STATUS_KEY);
    MeasureQuery measureQuery = MeasureQuery.builder().setProjectUuids(projectUuids).setMetricId(gateStatusMetric.getId()).build();
    List<MeasureDto> qualityGates = dbClient.measureDao().selectByQuery(dbSession, measureQuery);
    data.setProjects(projects).setProjectLinks(projectLinks).setSnapshots(snapshots).setQualityGates(qualityGates).setTotalNbOfProjects(searchResult.total);
    return data.build();
}
Also used : ComponentLinkDto(org.sonar.db.component.ComponentLinkDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) MeasureDto(org.sonar.db.measure.MeasureDto) MetricDto(org.sonar.db.metric.MetricDto) MeasureQuery(org.sonar.db.measure.MeasureQuery)

Example 2 with ComponentLinkDto

use of org.sonar.db.component.ComponentLinkDto in project sonarqube by SonarSource.

the class CreateAction method doHandle.

private CreateWsResponse doHandle(CreateWsRequest createWsRequest) {
    validateRequest(createWsRequest);
    String name = createWsRequest.getName();
    String url = createWsRequest.getUrl();
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto component = getComponentByUuidOrKey(dbSession, createWsRequest);
        userSession.checkComponentPermission(UserRole.ADMIN, component);
        ComponentLinkDto link = new ComponentLinkDto().setComponentUuid(component.uuid()).setName(name).setHref(url).setType(nameToType(name));
        dbClient.componentLinkDao().insert(dbSession, link);
        dbSession.commit();
        return buildResponse(link);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentLinkDto(org.sonar.db.component.ComponentLinkDto) ComponentDto(org.sonar.db.component.ComponentDto)

Example 3 with ComponentLinkDto

use of org.sonar.db.component.ComponentLinkDto in project sonarqube by SonarSource.

the class SearchAction method doHandle.

private SearchWsResponse doHandle(SearchWsRequest searchWsRequest) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto component = getComponentByUuidOrKey(dbSession, searchWsRequest);
        List<ComponentLinkDto> links = dbClient.componentLinkDao().selectByComponentUuid(dbSession, component.uuid());
        return buildResponse(links);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentLinkDto(org.sonar.db.component.ComponentLinkDto) ComponentDto(org.sonar.db.component.ComponentDto)

Example 4 with ComponentLinkDto

use of org.sonar.db.component.ComponentLinkDto in project sonarqube by SonarSource.

the class SearchActionTest method response_fields.

@Test
public void response_fields() throws IOException {
    ComponentDto project = insertProject();
    ComponentLinkDto homepageLink = insertHomepageLink(project.uuid());
    ComponentLinkDto customLink = insertCustomLink(project.uuid());
    logInAsProjectAdministrator(project);
    SearchWsResponse response = callByKey(project.key());
    assertThat(response.getLinksCount()).isEqualTo(2);
    assertThat(response.getLinksList()).extracting(Link::getId, Link::getName, Link::getType, Link::getUrl).containsOnlyOnce(tuple(homepageLink.getIdAsString(), homepageLink.getName(), homepageLink.getType(), homepageLink.getHref()), tuple(customLink.getIdAsString(), customLink.getName(), customLink.getType(), customLink.getHref()));
}
Also used : ComponentLinkDto(org.sonar.db.component.ComponentLinkDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchWsResponse(org.sonarqube.ws.WsProjectLinks.SearchWsResponse) Test(org.junit.Test)

Example 5 with ComponentLinkDto

use of org.sonar.db.component.ComponentLinkDto in project sonarqube by SonarSource.

the class SearchActionTest method several_projects.

@Test
public void several_projects() throws IOException {
    ComponentDto project1 = insertProject();
    ComponentDto project2 = insertProject("another", "abcd");
    ComponentLinkDto customLink1 = insertCustomLink(project1.uuid());
    insertCustomLink(project2.uuid());
    userSession.logIn().setRoot();
    SearchWsResponse response = callByKey(project1.key());
    assertThat(response.getLinksCount()).isEqualTo(1);
    assertThat(response.getLinks(0).getId()).isEqualTo(customLink1.getIdAsString());
}
Also used : ComponentLinkDto(org.sonar.db.component.ComponentLinkDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchWsResponse(org.sonarqube.ws.WsProjectLinks.SearchWsResponse) Test(org.junit.Test)

Aggregations

ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)20 ComponentDto (org.sonar.db.component.ComponentDto)14 Test (org.junit.Test)11 DbSession (org.sonar.db.DbSession)3 SnapshotDto (org.sonar.db.component.SnapshotDto)2 SearchWsResponse (org.sonarqube.ws.WsProjectLinks.SearchWsResponse)2 InputStream (java.io.InputStream)1 MeasureDto (org.sonar.db.measure.MeasureDto)1 MeasureQuery (org.sonar.db.measure.MeasureQuery)1 MetricDto (org.sonar.db.metric.MetricDto)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 TestResponse (org.sonar.server.ws.TestResponse)1 WsProjectLinks (org.sonarqube.ws.WsProjectLinks)1