use of com.epam.ta.reportportal.ws.model.TestItemHistoryElement in project service-api by reportportal.
the class TestItemsHistoryHandlerImpl method buildHistoryElements.
private Iterable<TestItemHistoryElement> buildHistoryElements(Function<TestItemResource, String> groupingFunction, Page<TestItemHistory> testItemHistoryPage, Long projectId, Pageable pageable) {
List<TestItem> testItems = testItemRepository.findAllById(testItemHistoryPage.getContent().stream().flatMap(history -> history.getItemIds().stream()).collect(toList()));
List<ResourceUpdater<TestItemResource>> resourceUpdaters = getResourceUpdaters(projectId, testItems);
Map<String, Map<Long, TestItemResource>> itemsMapping = testItems.stream().map(item -> {
TestItemResource testItemResource = TestItemConverter.TO_RESOURCE.apply(item);
resourceUpdaters.forEach(updater -> updater.updateResource(testItemResource));
return testItemResource;
}).collect(groupingBy(groupingFunction, toMap(TestItemResource::getItemId, res -> res)));
List<TestItemHistoryElement> testItemHistoryElements = testItemHistoryPage.getContent().stream().map(history -> ofNullable(itemsMapping.get(history.getGroupingField())).map(mapping -> {
TestItemHistoryElement historyResource = new TestItemHistoryElement();
historyResource.setGroupingField(history.getGroupingField());
List<TestItemResource> resources = Lists.newArrayList();
ofNullable(history.getItemIds()).ifPresent(itemIds -> itemIds.forEach(itemId -> ofNullable(mapping.get(itemId)).ifPresent(resources::add)));
historyResource.setResources(resources);
return historyResource;
})).filter(Optional::isPresent).map(Optional::get).collect(toList());
return PagedResourcesAssembler.<TestItemHistoryElement>pageConverter().apply(PageableExecutionUtils.getPage(testItemHistoryElements, pageable, testItemHistoryPage::getTotalElements));
}
use of com.epam.ta.reportportal.ws.model.TestItemHistoryElement in project service-api by reportportal.
the class TestItemsHistoryHandlerImpl method getItemsHistory.
@Override
public Iterable<TestItemHistoryElement> getItemsHistory(ReportPortalUser.ProjectDetails projectDetails, Queryable filter, Pageable pageable, HistoryRequestParams historyRequestParams, ReportPortalUser user) {
validateHistoryDepth(historyRequestParams.getHistoryDepth());
CompositeFilter itemHistoryFilter = new CompositeFilter(Operator.AND, filter, Filter.builder().withTarget(filter.getTarget().getClazz()).withCondition(FilterCondition.builder().eq(CRITERIA_PROJECT_ID, String.valueOf(projectDetails.getProjectId())).build()).withCondition(FilterCondition.builder().eq(CRITERIA_LAUNCH_MODE, LaunchModeEnum.DEFAULT.name()).build()).withCondition(FilterCondition.builder().eq(CRITERIA_HAS_STATS, String.valueOf(Boolean.TRUE)).build()).build());
Page<TestItemHistory> testItemHistoryPage = historyProviderFactory.getProvider(historyRequestParams).orElseThrow(() -> new ReportPortalException(UNABLE_LOAD_TEST_ITEM_HISTORY, "Unable to find suitable history baseline provider")).provide(itemHistoryFilter, pageable, historyRequestParams, projectDetails, user, !oldHistory);
return buildHistoryElements(oldHistory ? TestItemResource::getUniqueId : testItemResource -> String.valueOf(testItemResource.getTestCaseHash()), testItemHistoryPage, projectDetails.getProjectId(), pageable);
}
Aggregations