use of com.epam.ta.reportportal.ws.model.TestItemResource 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.TestItemResource 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);
}
use of com.epam.ta.reportportal.ws.model.TestItemResource 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.model.TestItemResource 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);
}
use of com.epam.ta.reportportal.ws.model.TestItemResource in project service-api by reportportal.
the class GetTestItemHandlerImpl method getTestItem.
@Override
public TestItemResource getTestItem(String testItemId, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
TestItem testItem;
try {
testItem = testItemRepository.findById(Long.parseLong(testItemId)).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, testItemId));
} catch (NumberFormatException e) {
testItem = testItemRepository.findByUuid(testItemId).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, testItemId));
}
Launch launch = testItemService.getEffectiveLaunch(testItem);
launchAccessValidator.validate(launch.getId(), projectDetails, user);
List<ResourceUpdater<TestItemResource>> resourceUpdaters = getResourceUpdaters(projectDetails.getProjectId(), Collections.singletonList(testItem));
TestItemResource testItemResource = TestItemConverter.TO_RESOURCE.apply(testItem);
resourceUpdaters.forEach(updater -> updater.updateResource(testItemResource));
return testItemResource;
}
Aggregations