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;
}
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));
}
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;
}
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());
}
}
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();
}
Aggregations