Search in sources :

Example 51 with ComponentDto

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

the class ActivityAction method loadComponentUuids.

@CheckForNull
private List<String> loadComponentUuids(DbSession dbSession, ActivityWsRequest request) {
    String componentUuid = request.getComponentId();
    String componentQuery = request.getQuery();
    if (componentUuid != null) {
        return singletonList(componentUuid);
    }
    if (componentQuery != null) {
        ComponentQuery componentDtoQuery = ComponentQuery.builder().setNameOrKeyQuery(componentQuery).setQualifiers(POSSIBLE_QUALIFIERS.toArray(new String[0])).build();
        List<ComponentDto> componentDtos = dbClient.componentDao().selectByQuery(dbSession, componentDtoQuery, 0, CeTaskQuery.MAX_COMPONENT_UUIDS);
        return Lists.transform(componentDtos, ComponentDto::uuid);
    }
    return null;
}
Also used : ComponentQuery(org.sonar.db.component.ComponentQuery) ComponentDto(org.sonar.db.component.ComponentDto) StringUtils.defaultString(org.apache.commons.lang.StringUtils.defaultString) CheckForNull(javax.annotation.CheckForNull)

Example 52 with ComponentDto

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

the class IssuesAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    response.stream().setMediaType(MediaTypes.PROTOBUF);
    try (DbSession session = dbClient.openSession(false)) {
        String componentKey = request.mandatoryParam(PARAM_KEY);
        ComponentDto component = componentFinder.getByKey(session, componentKey);
        userSession.checkComponentPermission(USER, component);
        Map<String, String> keysByUUid = keysByUUid(session, component);
        ScannerInput.ServerIssue.Builder issueBuilder = ScannerInput.ServerIssue.newBuilder();
        for (Iterator<IssueDoc> issueDocIterator = issueIndex.selectIssuesForBatch(component); issueDocIterator.hasNext(); ) {
            handleIssue(issueDocIterator.next(), issueBuilder, keysByUUid, response.stream().output());
        }
    }
}
Also used : IssueDoc(org.sonar.server.issue.index.IssueDoc) DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto)

Example 53 with ComponentDto

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

the class ComponentAction method handle.

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto component = componentFinder.getByUuidOrKey(dbSession, wsRequest.param(PARAM_COMPONENT_ID), wsRequest.param(PARAM_COMPONENT_KEY), COMPONENT_ID_AND_KEY);
        userSession.checkComponentPermission(UserRole.USER, component);
        List<CeQueueDto> queueDtos = dbClient.ceQueueDao().selectByComponentUuid(dbSession, component.uuid());
        CeTaskQuery activityQuery = new CeTaskQuery().setComponentUuid(component.uuid()).setOnlyCurrents(true);
        List<CeActivityDto> activityDtos = dbClient.ceActivityDao().selectByQuery(dbSession, activityQuery, 0, 1);
        ProjectResponse.Builder wsResponseBuilder = ProjectResponse.newBuilder();
        wsResponseBuilder.addAllQueue(formatter.formatQueue(dbSession, queueDtos));
        if (activityDtos.size() == 1) {
            wsResponseBuilder.setCurrent(formatter.formatActivity(dbSession, activityDtos.get(0)));
        }
        writeProtobuf(wsResponseBuilder.build(), wsRequest, wsResponse);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ProjectResponse(org.sonarqube.ws.WsCe.ProjectResponse) CeActivityDto(org.sonar.db.ce.CeActivityDto) ComponentDto(org.sonar.db.component.ComponentDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTaskQuery(org.sonar.db.ce.CeTaskQuery)

Example 54 with ComponentDto

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

the class TaskAction method handle.

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    String taskUuid = wsRequest.mandatoryParam(PARAM_TASK_UUID);
    try (DbSession dbSession = dbClient.openSession(false)) {
        WsCe.TaskResponse.Builder wsTaskResponse = WsCe.TaskResponse.newBuilder();
        Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, taskUuid);
        if (queueDto.isPresent()) {
            Optional<ComponentDto> component = loadComponent(dbSession, queueDto.get().getComponentUuid());
            checkPermission(component);
            wsTaskResponse.setTask(wsTaskFormatter.formatQueue(dbSession, queueDto.get(), component));
        } else {
            CeActivityDto ceActivityDto = WsUtils.checkFoundWithOptional(dbClient.ceActivityDao().selectByUuid(dbSession, taskUuid), "No activity found for task '%s'", taskUuid);
            Optional<ComponentDto> component = loadComponent(dbSession, ceActivityDto.getComponentUuid());
            checkPermission(component);
            Set<AdditionalField> additionalFields = AdditionalField.getFromRequest(wsRequest);
            maskErrorStacktrace(ceActivityDto, additionalFields);
            wsTaskResponse.setTask(wsTaskFormatter.formatActivity(dbSession, ceActivityDto, component, extractScannerContext(dbSession, ceActivityDto, additionalFields)));
        }
        writeProtobuf(wsTaskResponse.build(), wsRequest, wsResponse);
    }
}
Also used : DbSession(org.sonar.db.DbSession) CeActivityDto(org.sonar.db.ce.CeActivityDto) ComponentDto(org.sonar.db.component.ComponentDto) CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 55 with ComponentDto

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

the class ComponentUpdater method createRootComponent.

private ComponentDto createRootComponent(DbSession session, NewComponent newComponent) {
    checkBranchFormat(newComponent.qualifier(), newComponent.branch());
    String keyWithBranch = ComponentKeys.createKey(newComponent.key(), newComponent.branch());
    checkRequest(!dbClient.componentDao().selectByKey(session, keyWithBranch).isPresent(), formatMessage("Could not create %s, key already exists: %s", newComponent.qualifier(), keyWithBranch));
    String uuid = Uuids.create();
    ComponentDto component = new ComponentDto().setOrganizationUuid(newComponent.getOrganizationUuid()).setUuid(uuid).setUuidPath(ComponentDto.UUID_PATH_OF_ROOT).setRootUuid(uuid).setModuleUuid(null).setModuleUuidPath(ComponentDto.UUID_PATH_SEPARATOR + uuid + ComponentDto.UUID_PATH_SEPARATOR).setProjectUuid(uuid).setKey(keyWithBranch).setDeprecatedKey(keyWithBranch).setName(newComponent.name()).setLongName(newComponent.name()).setScope(Scopes.PROJECT).setQualifier(newComponent.qualifier()).setCreatedAt(new Date(system2.now()));
    dbClient.componentDao().insert(session, component);
    return component;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Date(java.util.Date)

Aggregations

ComponentDto (org.sonar.db.component.ComponentDto)836 Test (org.junit.Test)661 OrganizationDto (org.sonar.db.organization.OrganizationDto)151 SnapshotDto (org.sonar.db.component.SnapshotDto)94 DbSession (org.sonar.db.DbSession)70 SearchOptions (org.sonar.server.es.SearchOptions)62 MetricDto (org.sonar.db.metric.MetricDto)49 IssueDto (org.sonar.db.issue.IssueDto)48 RuleDto (org.sonar.db.rule.RuleDto)47 GroupDto (org.sonar.db.user.GroupDto)39 UserDto (org.sonar.db.user.UserDto)38 WsTester (org.sonar.server.ws.WsTester)33 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)25 PropertyDto (org.sonar.db.property.PropertyDto)23 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)21 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)18 Date (java.util.Date)16 ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)14 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)14 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)13