use of org.sonar.server.issue.index.IssueQuery.PeriodStart in project sonarqube by SonarSource.
the class IssueQueryTest method build_query.
@Test
public void build_query() {
RuleDefinitionDto rule = new RuleDefinitionDto().setUuid(Uuids.createFast());
PeriodStart filterDate = new IssueQuery.PeriodStart(new Date(10_000_000_000L), false);
IssueQuery query = IssueQuery.builder().issueKeys(newArrayList("ABCDE")).severities(newArrayList(Severity.BLOCKER)).statuses(Lists.newArrayList(Issue.STATUS_RESOLVED)).resolutions(newArrayList(Issue.RESOLUTION_FALSE_POSITIVE)).projectUuids(newArrayList("PROJECT")).componentUuids(newArrayList("org/struts/Action.java")).moduleUuids(newArrayList("org.struts:core")).rules(newArrayList(rule)).assigneeUuids(newArrayList("gargantua")).languages(newArrayList("xoo")).tags(newArrayList("tag1", "tag2")).types(newArrayList("RELIABILITY", "SECURITY")).owaspTop10(newArrayList("a1", "a2")).sansTop25(newArrayList("insecure-interaction", "porous-defenses")).cwe(newArrayList("12", "125")).branchUuid("my_branch").createdAfterByProjectUuids(ImmutableMap.of("PROJECT", filterDate)).assigned(true).createdAfter(new Date()).createdBefore(new Date()).createdAt(new Date()).resolved(true).sort(IssueQuery.SORT_BY_CREATION_DATE).asc(true).build();
assertThat(query.issueKeys()).containsOnly("ABCDE");
assertThat(query.severities()).containsOnly(Severity.BLOCKER);
assertThat(query.statuses()).containsOnly(Issue.STATUS_RESOLVED);
assertThat(query.resolutions()).containsOnly(Issue.RESOLUTION_FALSE_POSITIVE);
assertThat(query.projectUuids()).containsOnly("PROJECT");
assertThat(query.componentUuids()).containsOnly("org/struts/Action.java");
assertThat(query.moduleUuids()).containsOnly("org.struts:core");
assertThat(query.assignees()).containsOnly("gargantua");
assertThat(query.languages()).containsOnly("xoo");
assertThat(query.tags()).containsOnly("tag1", "tag2");
assertThat(query.types()).containsOnly("RELIABILITY", "SECURITY");
assertThat(query.owaspTop10()).containsOnly("a1", "a2");
assertThat(query.sansTop25()).containsOnly("insecure-interaction", "porous-defenses");
assertThat(query.cwe()).containsOnly("12", "125");
assertThat(query.branchUuid()).isEqualTo("my_branch");
assertThat(query.createdAfterByProjectUuids()).containsOnly(entry("PROJECT", filterDate));
assertThat(query.assigned()).isTrue();
assertThat(query.rules()).containsOnly(rule);
assertThat(query.createdAfter()).isNotNull();
assertThat(query.createdBefore()).isNotNull();
assertThat(query.createdAt()).isNotNull();
assertThat(query.resolved()).isTrue();
assertThat(query.sort()).isEqualTo(IssueQuery.SORT_BY_CREATION_DATE);
assertThat(query.asc()).isTrue();
}
use of org.sonar.server.issue.index.IssueQuery.PeriodStart in project sonarqube by SonarSource.
the class IssueIndex method getCreatedAtFacet.
private Optional<AggregationBuilder> getCreatedAtFacet(IssueQuery query, TopAggregationHelper aggregationHelper, AllFilters allFilters) {
long startTime;
boolean startInclusive;
PeriodStart createdAfter = query.createdAfter();
if (createdAfter == null) {
OptionalLong minDate = getMinCreatedAt(allFilters);
if (!minDate.isPresent()) {
return Optional.empty();
}
startTime = minDate.getAsLong();
startInclusive = true;
} else {
startTime = createdAfter.date().getTime();
startInclusive = createdAfter.inclusive();
}
Date createdBefore = query.createdBefore();
long endTime = createdBefore == null ? system.now() : createdBefore.getTime();
Duration timeSpan = new Duration(startTime, endTime);
DateHistogramInterval bucketSize = computeDateHistogramBucketSize(timeSpan);
FilterAggregationBuilder topAggregation = aggregationHelper.buildTopAggregation(CREATED_AT.getName(), CREATED_AT.getTopAggregationDef(), NO_EXTRA_FILTER, t -> {
AggregationBuilder dateHistogram = AggregationBuilders.dateHistogram(CREATED_AT.getName()).field(CREATED_AT.getFieldName()).dateHistogramInterval(bucketSize).minDocCount(0L).format(DateUtils.DATETIME_FORMAT).timeZone(Optional.ofNullable(query.timeZone()).orElse(system.getDefaultTimeZone().toZoneId())).extendedBounds(new LongBounds(startInclusive ? startTime : (startTime + 1), endTime - 1L));
addEffortAggregationIfNeeded(query, dateHistogram);
t.subAggregation(dateHistogram);
});
return Optional.of(topAggregation);
}
use of org.sonar.server.issue.index.IssueQuery.PeriodStart in project sonarqube by SonarSource.
the class IssueIndex method addDatesFilter.
private void addDatesFilter(AllFilters filters, IssueQuery query) {
PeriodStart createdAfter = query.createdAfter();
Date createdBefore = query.createdBefore();
validateCreationDateBounds(createdBefore, createdAfter != null ? createdAfter.date() : null);
if (createdAfter != null) {
filters.addFilter("__createdAfter", CREATED_AT.getFilterScope(), QueryBuilders.rangeQuery(FIELD_ISSUE_FUNC_CREATED_AT).from(BaseDoc.dateToEpochSeconds(createdAfter.date()), createdAfter.inclusive()));
}
if (createdBefore != null) {
filters.addFilter("__createdBefore", CREATED_AT.getFilterScope(), QueryBuilders.rangeQuery(FIELD_ISSUE_FUNC_CREATED_AT).lt(BaseDoc.dateToEpochSeconds(createdBefore)));
}
Date createdAt = query.createdAt();
if (createdAt != null) {
filters.addFilter("__createdAt", CREATED_AT.getFilterScope(), termQuery(FIELD_ISSUE_FUNC_CREATED_AT, BaseDoc.dateToEpochSeconds(createdAt)));
}
}
use of org.sonar.server.issue.index.IssueQuery.PeriodStart in project sonarqube by SonarSource.
the class IssueIndex method addCreatedAfterByProjectsFilter.
private static void addCreatedAfterByProjectsFilter(AllFilters allFilters, IssueQuery query) {
Map<String, PeriodStart> createdAfterByProjectUuids = query.createdAfterByProjectUuids();
BoolQueryBuilder boolQueryBuilder = boolQuery();
createdAfterByProjectUuids.forEach((projectOrProjectBranchUuid, createdAfterDate) -> boolQueryBuilder.should(boolQuery().filter(termQuery(FIELD_ISSUE_BRANCH_UUID, projectOrProjectBranchUuid)).filter(rangeQuery(FIELD_ISSUE_FUNC_CREATED_AT).from(BaseDoc.dateToEpochSeconds(createdAfterDate.date()), createdAfterDate.inclusive()))));
allFilters.addFilter("__created_after_by_project_uuids", new SimpleFieldFilterScope("createdAfterByProjectUuids"), boolQueryBuilder);
}
Aggregations