Search in sources :

Example 71 with ComponentDto

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

the class DuplicationsParser method parse.

public List<Block> parse(ComponentDto component, @Nullable String duplicationsData, DbSession session) {
    Map<String, ComponentDto> componentsByKey = newHashMap();
    List<Block> blocks = newArrayList();
    if (duplicationsData != null) {
        try {
            SMInputFactory inputFactory = initStax();
            SMHierarchicCursor root = inputFactory.rootElementCursor(new StringReader(duplicationsData));
            // <duplications>
            root.advance();
            SMInputCursor cursor = root.childElementCursor("g");
            while (cursor.getNext() != null) {
                List<Duplication> duplications = newArrayList();
                SMInputCursor bCursor = cursor.childElementCursor("b");
                while (bCursor.getNext() != null) {
                    String from = bCursor.getAttrValue("s");
                    String size = bCursor.getAttrValue("l");
                    String componentKey = bCursor.getAttrValue("r");
                    if (from != null && size != null && componentKey != null) {
                        duplications.add(createDuplication(componentsByKey, from, size, componentKey, session));
                    }
                }
                Collections.sort(duplications, new DuplicationComparator(component.uuid(), component.projectUuid()));
                blocks.add(new Block(duplications));
            }
            Collections.sort(blocks, new BlockComparator());
        } catch (XMLStreamException e) {
            throw new IllegalStateException("XML is not valid", e);
        }
    }
    return blocks;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SMInputFactory(org.codehaus.staxmate.SMInputFactory) SMInputCursor(org.codehaus.staxmate.in.SMInputCursor) SMHierarchicCursor(org.codehaus.staxmate.in.SMHierarchicCursor) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader)

Example 72 with ComponentDto

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

the class DuplicationsParser method createDuplication.

private Duplication createDuplication(Map<String, ComponentDto> componentsByKey, String from, String size, String componentKey, DbSession session) {
    ComponentDto component = componentsByKey.get(componentKey);
    if (component == null) {
        Optional<ComponentDto> componentDtoOptional = componentDao.selectByKey(session, componentKey);
        component = componentDtoOptional.isPresent() ? componentDtoOptional.get() : null;
        componentsByKey.put(componentKey, component);
    }
    return new Duplication(component, Integer.valueOf(from), Integer.valueOf(size));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto)

Example 73 with ComponentDto

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

the class IssueQueryService method findCreatedAfterFromComponentUuid.

@CheckForNull
private Date findCreatedAfterFromComponentUuid(DbSession dbSession, String uuid) {
    ComponentDto component = checkFoundWithOptional(dbClient.componentDao().selectByUuid(dbSession, uuid), "Component with id '%s' not found", uuid);
    Optional<SnapshotDto> snapshot = dbClient.snapshotDao().selectLastAnalysisByComponentUuid(dbSession, component.uuid());
    if (snapshot.isPresent()) {
        return longToDate(snapshot.get().getPeriodDate());
    }
    return null;
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) CheckForNull(javax.annotation.CheckForNull)

Example 74 with ComponentDto

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

the class FavoriteFinder method list.

/**
   * @return the list of favorite components of the authenticated user. Empty list if the user is not authenticated
   */
public List<ComponentDto> list() {
    if (!userSession.isLoggedIn()) {
        return emptyList();
    }
    try (DbSession dbSession = dbClient.openSession(false)) {
        PropertyQuery dbQuery = PropertyQuery.builder().setKey(PROP_FAVORITE_KEY).setUserId(userSession.getUserId()).build();
        Set<Long> componentIds = dbClient.propertiesDao().selectByQuery(dbQuery, dbSession).stream().map(PropertyDto::getResourceId).collect(Collectors.toSet());
        return dbClient.componentDao().selectByIds(dbSession, componentIds).stream().sorted(Comparator.comparing(ComponentDto::name)).collect(toList());
    }
}
Also used : DbSession(org.sonar.db.DbSession) PropertyQuery(org.sonar.db.property.PropertyQuery) ComponentDto(org.sonar.db.component.ComponentDto)

Example 75 with ComponentDto

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

the class ComponentTreeAction method buildResponse.

private static ComponentTreeWsResponse buildResponse(ComponentTreeWsRequest request, ComponentTreeData data, Paging paging) {
    ComponentTreeWsResponse.Builder response = ComponentTreeWsResponse.newBuilder();
    response.getPagingBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()).setTotal(paging.total()).build();
    response.setBaseComponent(componentDtoToWsComponent(data.getBaseComponent(), data.getMeasuresByComponentUuidAndMetric().row(data.getBaseComponent().uuid()), data.getReferenceComponentsByUuid()));
    for (ComponentDto componentDto : data.getComponents()) {
        response.addComponents(componentDtoToWsComponent(componentDto, data.getMeasuresByComponentUuidAndMetric().row(componentDto.uuid()), data.getReferenceComponentsByUuid()));
    }
    if (areMetricsInResponse(request)) {
        WsMeasures.Metrics.Builder metricsBuilder = response.getMetricsBuilder();
        for (MetricDto metricDto : data.getMetrics()) {
            metricsBuilder.addMetrics(metricDtoToWsMetric(metricDto));
        }
    }
    if (arePeriodsInResponse(request)) {
        response.getPeriodsBuilder().addAllPeriods(data.getPeriods());
    }
    return response.build();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTreeWsResponse(org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)

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