@Test public void create_minimal_query() { ComponentTreeQuery query = ComponentTreeQuery.builder() .setBaseUuid(BASE_UUID) .setStrategy(CHILDREN) .build(); assertThat(query.getBaseUuid()).isEqualTo(BASE_UUID); assertThat(query.getStrategy()).isEqualTo(CHILDREN); assertThat(query.getQualifiers()).isNull(); assertThat(query.getNameOrKeyQuery()).isNull(); assertThat(query.getNameOrKeyUpperLikeQuery()).isNull(); }
@Test public void test_getUuidPath() { assertThat(ComponentTreeQuery.builder().setBaseUuid(BASE_UUID).setStrategy(CHILDREN) .build().getUuidPath(newPrivateProjectDto(newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT_UUID."); assertThat(ComponentTreeQuery.builder().setBaseUuid(BASE_UUID).setStrategy(LEAVES) .build().getUuidPath(newPrivateProjectDto(newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%"); }
public ComponentTreeQuery build() { requireNonNull(baseUuid); return new ComponentTreeQuery(this); }
/** * Select the children or the leaves of a base component, given by its UUID. The components that are not present in last * analysis are ignored. * <p> * An empty list is returned if the base component does not exist or if the base component is a leaf. */ public List<ComponentDto> selectDescendants(DbSession dbSession, ComponentTreeQuery query) { Optional<ComponentDto> componentOpt = selectByUuid(dbSession, query.getBaseUuid()); if (!componentOpt.isPresent()) { return emptyList(); } ComponentDto component = componentOpt.get(); return mapper(dbSession).selectDescendants(query, componentOpt.get().uuid(), query.getUuidPath(component)); }
private Table<String, MetricDto, ComponentTreeData.Measure> searchMeasuresByComponentUuidAndMetric(DbSession dbSession, ComponentDto baseComponent, ComponentTreeQuery componentTreeQuery, List<ComponentDto> components, List<MetricDto> metrics) { Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId); MeasureTreeQuery measureQuery = MeasureTreeQuery.builder() .setStrategy(MeasureTreeQuery.Strategy.valueOf(componentTreeQuery.getStrategy().name())) .setNameOrKeyQuery(componentTreeQuery.getNameOrKeyQuery()) .setQualifiers(componentTreeQuery.getQualifiers()) .setMetricIds(new ArrayList<>(metricsById.keySet())) .build(); Table<String, MetricDto, ComponentTreeData.Measure> measuresByComponentUuidAndMetric = HashBasedTable.create(components.size(), metrics.size()); dbClient.liveMeasureDao().selectTreeByQuery(dbSession, baseComponent, measureQuery, result -> { LiveMeasureDto measureDto = result.getResultObject(); measuresByComponentUuidAndMetric.put( measureDto.getComponentUuid(), metricsById.get(measureDto.getMetricId()), ComponentTreeData.Measure.createFromMeasureDto(measureDto)); }); addBestValuesToMeasures(measuresByComponentUuidAndMetric, components, metrics); return measuresByComponentUuidAndMetric; }
private static ComponentTreeQuery.Builder newTreeQuery(String baseUuid) { return ComponentTreeQuery.builder() .setBaseUuid(baseUuid) .setStrategy(CHILDREN); }
private List<ComponentDto> searchComponents(DbSession dbSession, ComponentTreeQuery componentTreeQuery) { Collection<String> qualifiers = componentTreeQuery.getQualifiers(); if (qualifiers != null && qualifiers.isEmpty()) { return Collections.emptyList(); } return dbClient.componentDao().selectDescendants(dbSession, componentTreeQuery); }
private void deleteDataOfComponentsWithoutHistoricalData(DbSession dbSession, String rootUuid, Collection<String> scopesWithoutHistoricalData, PurgeCommands purgeCommands) { if (scopesWithoutHistoricalData.isEmpty()) { return; } List<String> analysisUuids = purgeCommands.selectSnapshotUuids( new PurgeSnapshotQuery() .setComponentUuid(rootUuid) .setIslast(false) .setNotPurged(true)); List<String> componentWithoutHistoricalDataUuids = componentDao .selectDescendants( dbSession, ComponentTreeQuery.builder() .setBaseUuid(rootUuid) .setScopes(scopesWithoutHistoricalData) .setStrategy(Strategy.LEAVES) .build()) .stream().map(ComponentDto::uuid) .collect(MoreCollectors.toList()); purgeCommands.deleteComponentMeasures(analysisUuids, componentWithoutHistoricalDataUuids); }
private Table<String, MetricDto, ComponentTreeData.Measure> searchMeasuresByComponentUuidAndMetric(DbSession dbSession, ComponentDto baseComponent, ComponentTreeQuery componentTreeQuery, List<ComponentDto> components, List<MetricDto> metrics) { Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId); MeasureTreeQuery measureQuery = MeasureTreeQuery.builder() .setStrategy(MeasureTreeQuery.Strategy.valueOf(componentTreeQuery.getStrategy().name())) .setNameOrKeyQuery(componentTreeQuery.getNameOrKeyQuery()) .setQualifiers(componentTreeQuery.getQualifiers()) .setMetricIds(new ArrayList<>(metricsById.keySet())) .build(); Table<String, MetricDto, ComponentTreeData.Measure> measuresByComponentUuidAndMetric = HashBasedTable.create(components.size(), metrics.size()); dbClient.liveMeasureDao().selectTreeByQuery(dbSession, baseComponent, measureQuery, result -> { LiveMeasureDto measureDto = result.getResultObject(); measuresByComponentUuidAndMetric.put( measureDto.getComponentUuid(), metricsById.get(measureDto.getMetricId()), ComponentTreeData.Measure.createFromMeasureDto(measureDto)); }); addBestValuesToMeasures(measuresByComponentUuidAndMetric, components, metrics); return measuresByComponentUuidAndMetric; }
/** * Select the children or the leaves of a base component, given by its UUID. The components that are not present in last * analysis are ignored. * * An empty list is returned if the base component does not exist or if the base component is a leaf. */ public List<ComponentDto> selectDescendants(DbSession dbSession, ComponentTreeQuery query) { Optional<ComponentDto> componentOpt = selectByUuid(dbSession, query.getBaseUuid()); if (!componentOpt.isPresent()) { return emptyList(); } ComponentDto component = componentOpt.get(); return mapper(dbSession).selectDescendants(query, componentOpt.get().uuid(), query.getUuidPath(component)); }
private List<ComponentDto> searchComponents(DbSession dbSession, ComponentTreeQuery componentTreeQuery) { Collection<String> qualifiers = componentTreeQuery.getQualifiers(); if (qualifiers != null && qualifiers.isEmpty()) { return Collections.emptyList(); } return dbClient.componentDao().selectDescendants(dbSession, componentTreeQuery); }
@Test public void create_query() { ComponentTreeQuery query = ComponentTreeQuery.builder() .setBaseUuid(BASE_UUID) .setStrategy(CHILDREN) .setQualifiers(asList("FIL", "DIR")) .setNameOrKeyQuery("teSt") .build(); assertThat(query.getBaseUuid()).isEqualTo(BASE_UUID); assertThat(query.getStrategy()).isEqualTo(CHILDREN); assertThat(query.getQualifiers()).containsOnly("FIL", "DIR"); assertThat(query.getNameOrKeyQuery()).isEqualTo("teSt"); assertThat(query.getNameOrKeyUpperLikeQuery()).isEqualTo("%TEST%"); }
private ComponentTreeQuery toComponentTreeQuery(Request request, ComponentDto baseComponent) { List<String> childrenQualifiers = childrenQualifiers(request, baseComponent.qualifier()); ComponentTreeQuery.Builder query = ComponentTreeQuery.builder() .setBaseUuid(baseComponent.uuid()) .setStrategy(STRATEGIES.get(request.getStrategy())); if (request.getQuery() != null) { query.setNameOrKeyQuery(request.getQuery()); } if (childrenQualifiers != null) { query.setQualifiers(childrenQualifiers); } return query.build(); }
public ComponentTreeQuery build() { requireNonNull(baseUuid); return new ComponentTreeQuery(this); }
private ComponentTreeQuery toComponentTreeQuery(ComponentTreeRequest wsRequest, ComponentDto baseComponent) { List<String> childrenQualifiers = childrenQualifiers(wsRequest, baseComponent.qualifier()); ComponentTreeQuery.Builder componentTreeQueryBuilder = ComponentTreeQuery.builder() .setBaseUuid(baseComponent.uuid()) .setStrategy(STRATEGIES.get(wsRequest.getStrategy())); if (wsRequest.getQuery() != null) { componentTreeQueryBuilder.setNameOrKeyQuery(wsRequest.getQuery()); } if (childrenQualifiers != null) { componentTreeQueryBuilder.setQualifiers(childrenQualifiers); } return componentTreeQueryBuilder.build(); }
@Test public void fail_when_no_base_uuid() { expectedException.expect(NullPointerException.class); ComponentTreeQuery.builder() .setStrategy(CHILDREN) .build(); }
@Test public void fail_when_no_strategy() { expectedException.expect(NullPointerException.class); ComponentTreeQuery.builder() .setBaseUuid(BASE_UUID) .build(); } }
private ComponentTreeQuery toComponentTreeQuery(Request request, ComponentDto baseComponent) { List<String> childrenQualifiers = childrenQualifiers(request, baseComponent.qualifier()); ComponentTreeQuery.Builder query = ComponentTreeQuery.builder() .setBaseUuid(baseComponent.uuid()) .setStrategy(STRATEGIES.get(request.getStrategy())); if (request.getQuery() != null) { query.setNameOrKeyQuery(request.getQuery()); } if (childrenQualifiers != null) { query.setQualifiers(childrenQualifiers); } return query.build(); }
private void deleteDataOfComponentsWithoutHistoricalData(DbSession dbSession, String rootUuid, String[] scopesWithoutHistoricalData, PurgeCommands purgeCommands) { if (scopesWithoutHistoricalData.length == 0) { return; } List<String> analysisUuids = purgeCommands.selectSnapshotUuids( new PurgeSnapshotQuery() .setComponentUuid(rootUuid) .setIslast(false) .setNotPurged(true)); List<String> componentWithoutHistoricalDataUuids = componentDao .selectDescendants( dbSession, ComponentTreeQuery.builder() .setBaseUuid(rootUuid) .setQualifiers(Arrays.asList(scopesWithoutHistoricalData)) .setStrategy(Strategy.LEAVES) .build()) .stream().map(ComponentDto::uuid) .collect(Collectors.toList()); purgeCommands.deleteComponentMeasures(analysisUuids, componentWithoutHistoricalDataUuids); }
private ComponentTreeQuery toComponentTreeQuery(ComponentTreeRequest wsRequest, ComponentDto baseComponent) { List<String> childrenQualifiers = childrenQualifiers(wsRequest, baseComponent.qualifier()); ComponentTreeQuery.Builder componentTreeQueryBuilder = ComponentTreeQuery.builder() .setBaseUuid(baseComponent.uuid()) .setStrategy(STRATEGIES.get(wsRequest.getStrategy())); if (wsRequest.getQuery() != null) { componentTreeQueryBuilder.setNameOrKeyQuery(wsRequest.getQuery()); } if (childrenQualifiers != null) { componentTreeQueryBuilder.setQualifiers(childrenQualifiers); } return componentTreeQueryBuilder.build(); }