use of com.epam.ta.reportportal.ws.converter.PagedResourcesAssembler 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.converter.PagedResourcesAssembler in project service-api by reportportal.
the class GetTestItemHandlerImpl method getTestItems.
@Override
public Iterable<TestItemResource> getTestItems(Queryable filter, Pageable pageable, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user, @Nullable Long launchId, @Nullable Long filterId, boolean isLatest, int launchesLimit) {
Optional<Long> launchIdOptional = Optional.ofNullable(launchId);
Optional<Long> filterIdOptional = Optional.ofNullable(filterId);
Page<TestItem> testItemPage = filterIdOptional.map(launchFilterId -> {
validateProjectRole(projectDetails, user);
return getItemsWithLaunchesFiltering(filter, pageable, projectDetails, launchFilterId, isLatest, launchesLimit);
}).orElseGet(() -> launchIdOptional.map(id -> {
launchAccessValidator.validate(id, projectDetails, user);
return testItemRepository.findByFilter(filter, pageable);
}).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Neither launch nor filter id specified.")));
return PagedResourcesAssembler.<TestItem, TestItemResource>pageMultiConverter(items -> {
List<ResourceUpdater<TestItemResource>> resourceUpdaters = getResourceUpdaters(projectDetails.getProjectId(), testItemPage.getContent());
return items.stream().map(item -> {
TestItemResource testItemResource = TestItemConverter.TO_RESOURCE.apply(item);
resourceUpdaters.forEach(updater -> updater.updateResource(testItemResource));
return testItemResource;
}).collect(toList());
}).apply(testItemPage);
}
use of com.epam.ta.reportportal.ws.converter.PagedResourcesAssembler in project service-api by reportportal.
the class GetTestItemHandlerImpl method getTestItemsByProvider.
@Override
public Iterable<TestItemResource> getTestItemsByProvider(Queryable filter, Pageable pageable, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user, Map<String, String> params) {
DataProviderType dataProviderType = DataProviderType.findByName(params.get(PROVIDER_TYPE_PARAM)).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Test item data provider base is not specified. Allowed data provider {}", DataProviderType.values()));
Page<TestItem> testItemPage = testItemDataProviders.get(dataProviderType).getTestItems(filter, pageable, projectDetails, user, params);
return PagedResourcesAssembler.<TestItem, TestItemResource>pageMultiConverter(items -> {
List<ResourceUpdater<TestItemResource>> resourceUpdaters = getResourceUpdaters(projectDetails.getProjectId(), testItemPage.getContent());
return items.stream().map(item -> {
TestItemResource testItemResource = TestItemConverter.TO_RESOURCE.apply(item);
resourceUpdaters.forEach(updater -> updater.updateResource(testItemResource));
return testItemResource;
}).collect(toList());
}).apply(testItemPage);
}
Aggregations