in rest-api/src/jetbrains/buildServer/server/rest/data/pages/problems/TestFailuresProblemEntriesCollector.java [91:183]
public PagedSearchResult<TestFailuresProblemEntry> getItems(@NotNull Locator locator) {
if (!locator.isAnyPresent(AFFECTED_PROJECT)) {
throw new BadRequestException(String.format("Dimension '%s' must be set.", AFFECTED_PROJECT.getName()));
}
if (!Boolean.TRUE.equals(locator.lookupSingleDimensionValueAsBoolean(CURRENTLY_INVESTIGATED)) && locator.isAnyPresent(ASSIGNEE)) {
// assignee is set, but currently investigated is false or any, does not make a lot of sense.
throw new BadRequestException(String.format("When '%s' is set, then '%s' must be set to 'true'.", ASSIGNEE.getName(), CURRENTLY_INVESTIGATED.getName()));
}
SProject project = myProjectFinder.getItem(locator.getSingleDimensionValue(AFFECTED_PROJECT));
SUser investigator = null;
if(locator.isUnused(ASSIGNEE)) {
investigator = myUserFinder.getItem(locator.getSingleDimensionValue(ASSIGNEE));
}
// Set defaults
if(!locator.isAnyPresent(CURRENTLY_FAILING)) {
locator.setDimension(CURRENTLY_FAILING, "true");
}
if(!locator.isAnyPresent(ORDER_BY)) {
locator.setDimension(ORDER_BY, "newFailure");
}
boolean returnOnlyFailing = Boolean.TRUE.equals(locator.lookupSingleDimensionValueAsBoolean(CURRENTLY_FAILING));
boolean returnOnlyNotFailing = Boolean.FALSE.equals(locator.lookupSingleDimensionValueAsBoolean(CURRENTLY_FAILING));
boolean returnOnlyMuted = Boolean.TRUE.equals(locator.lookupSingleDimensionValueAsBoolean(CURRENTLY_MUTED));
boolean returnOnlyNotMuted = Boolean.FALSE.equals(locator.getSingleDimensionValueAsBoolean(CURRENTLY_MUTED));
boolean returnOnlyInvestigated = Boolean.TRUE.equals(locator.lookupSingleDimensionValueAsBoolean(CURRENTLY_INVESTIGATED));
boolean returnOnlyNotInvestigated = Boolean.FALSE.equals(locator.getSingleDimensionValueAsBoolean(CURRENTLY_INVESTIGATED));
Map<Long, List<InvestigationWrapper>> investigations = new HashMap<>();
investigations.putAll(getInvestigations(project, investigator));
Map<Long, List<SingleTestMuteInfoView>> mutes = new HashMap<>();
mutes.putAll(getMutes(project));
Map<Long, List<STestRun>> failingTests = new HashMap<>();
failingTests.putAll(getFailingTests(project));
Set<Long> allTestNames = new HashSet<>();
allTestNames.addAll(investigations.keySet());
allTestNames.addAll(mutes.keySet());
allTestNames.addAll(failingTests.keySet());
LongFunction<STest> testResolver = getTestResolver(project);
Stream.Builder<TestFailuresProblemEntry> streamBuilder = Stream.builder();
for (Long testNameId : allTestNames) {
TestFailuresProblemEntry entry = new TestFailuresProblemEntry(testResolver);
if (returnOnlyMuted && !mutes.containsKey(testNameId) || returnOnlyNotMuted && mutes.containsKey(testNameId)) {
continue;
}
if (returnOnlyInvestigated && !investigations.containsKey(testNameId) || returnOnlyNotInvestigated && investigations.containsKey(testNameId)) {
continue;
}
if (returnOnlyFailing && !failingTests.containsKey(testNameId) || returnOnlyNotFailing && failingTests.containsKey(testNameId)) {
continue;
}
if (failingTests.containsKey(testNameId)) {
entry.setRecentFailures(failingTests.get(testNameId));
}
if (investigations.containsKey(testNameId)) {
entry.setInvestigations(investigations.get(testNameId));
}
if (mutes.containsKey(testNameId)) {
entry.setMutes(mutes.get(testNameId));
}
entry.setTestNameId(testNameId);
streamBuilder.add(entry);
}
Stream<TestFailuresProblemEntry> result = streamBuilder.build();
if (locator.isAnyPresent(ORDER_BY)) {
result = result.sorted(SUPPORTED_ORDERS.getComparator(locator.getSingleDimensionValue(ORDER_BY)));
}
long start = locator.getSingleDimensionValueAsLong(PAGER_START, 0L);
if(start < 0) {
throw new BadRequestException(String.format("'%s' must have non-negative value.", PAGER_START.getName()));
}
result = result.skip(start);
long count = locator.getSingleDimensionValueAsLong(PAGER_COUNT, DEFAULT_PAGE_SIZE);
if(count < 0) {
throw new BadRequestException(String.format("'%s' must have non-negative value.", PAGER_COUNT.getName()));
}
result = result.limit(count);
return new PagedSearchResult<>(result.collect(Collectors.toList()), start, (int) count);
}