Search in sources :

Example 1 with TestItemHistoryElement

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));
}
Also used : CRITERIA_PROJECT_ID(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_PROJECT_ID) TestItem(com.epam.ta.reportportal.entity.item.TestItem) TestItemHistory(com.epam.ta.reportportal.entity.item.history.TestItemHistory) Autowired(org.springframework.beans.factory.annotation.Autowired) Operator(org.jooq.Operator) Function(java.util.function.Function) TestItemsHistoryHandler(com.epam.ta.reportportal.core.item.history.TestItemsHistoryHandler) Value(org.springframework.beans.factory.annotation.Value) MIN_HISTORY_DEPTH_BOUND(com.epam.ta.reportportal.ws.model.ValidationConstraints.MIN_HISTORY_DEPTH_BOUND) Lists(com.google.common.collect.Lists) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) TestItemResource(com.epam.ta.reportportal.ws.model.TestItemResource) Service(org.springframework.stereotype.Service) TestItemConverter(com.epam.ta.reportportal.ws.converter.converters.TestItemConverter) Map(java.util.Map) UNABLE_LOAD_TEST_ITEM_HISTORY(com.epam.ta.reportportal.ws.model.ErrorType.UNABLE_LOAD_TEST_ITEM_HISTORY) Pageable(org.springframework.data.domain.Pageable) CRITERIA_LAUNCH_MODE(com.epam.ta.reportportal.commons.querygen.constant.LaunchCriteriaConstant.CRITERIA_LAUNCH_MODE) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) CRITERIA_HAS_STATS(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant.CRITERIA_HAS_STATS) TestItemHistoryElement(com.epam.ta.reportportal.ws.model.TestItemHistoryElement) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) Predicate(java.util.function.Predicate) Optional.ofNullable(java.util.Optional.ofNullable) Filter(com.epam.ta.reportportal.commons.querygen.Filter) LaunchModeEnum(com.epam.ta.reportportal.entity.enums.LaunchModeEnum) TestItemUpdaterContent(com.epam.ta.reportportal.ws.converter.utils.item.content.TestItemUpdaterContent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) PageableExecutionUtils(org.springframework.data.repository.support.PageableExecutionUtils) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) PagedResourcesAssembler(com.epam.ta.reportportal.ws.converter.PagedResourcesAssembler) List(java.util.List) HistoryProviderFactory(com.epam.ta.reportportal.core.item.impl.history.provider.HistoryProviderFactory) Queryable(com.epam.ta.reportportal.commons.querygen.Queryable) Optional(java.util.Optional) CompositeFilter(com.epam.ta.reportportal.commons.querygen.CompositeFilter) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) MAX_HISTORY_DEPTH_BOUND(com.epam.ta.reportportal.ws.model.ValidationConstraints.MAX_HISTORY_DEPTH_BOUND) ResourceUpdater(com.epam.ta.reportportal.ws.converter.utils.ResourceUpdater) HistoryRequestParams(com.epam.ta.reportportal.core.item.impl.history.param.HistoryRequestParams) ResourceUpdaterProvider(com.epam.ta.reportportal.ws.converter.utils.ResourceUpdaterProvider) Optional(java.util.Optional) ResourceUpdater(com.epam.ta.reportportal.ws.converter.utils.ResourceUpdater) TestItemResource(com.epam.ta.reportportal.ws.model.TestItemResource) TestItemHistoryElement(com.epam.ta.reportportal.ws.model.TestItemHistoryElement) Map(java.util.Map) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Example 2 with TestItemHistoryElement

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);
}
Also used : CRITERIA_PROJECT_ID(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_PROJECT_ID) TestItem(com.epam.ta.reportportal.entity.item.TestItem) TestItemHistory(com.epam.ta.reportportal.entity.item.history.TestItemHistory) Autowired(org.springframework.beans.factory.annotation.Autowired) Operator(org.jooq.Operator) Function(java.util.function.Function) TestItemsHistoryHandler(com.epam.ta.reportportal.core.item.history.TestItemsHistoryHandler) Value(org.springframework.beans.factory.annotation.Value) MIN_HISTORY_DEPTH_BOUND(com.epam.ta.reportportal.ws.model.ValidationConstraints.MIN_HISTORY_DEPTH_BOUND) Lists(com.google.common.collect.Lists) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) TestItemResource(com.epam.ta.reportportal.ws.model.TestItemResource) Service(org.springframework.stereotype.Service) TestItemConverter(com.epam.ta.reportportal.ws.converter.converters.TestItemConverter) Map(java.util.Map) UNABLE_LOAD_TEST_ITEM_HISTORY(com.epam.ta.reportportal.ws.model.ErrorType.UNABLE_LOAD_TEST_ITEM_HISTORY) Pageable(org.springframework.data.domain.Pageable) CRITERIA_LAUNCH_MODE(com.epam.ta.reportportal.commons.querygen.constant.LaunchCriteriaConstant.CRITERIA_LAUNCH_MODE) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) CRITERIA_HAS_STATS(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant.CRITERIA_HAS_STATS) TestItemHistoryElement(com.epam.ta.reportportal.ws.model.TestItemHistoryElement) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) Predicate(java.util.function.Predicate) Optional.ofNullable(java.util.Optional.ofNullable) Filter(com.epam.ta.reportportal.commons.querygen.Filter) LaunchModeEnum(com.epam.ta.reportportal.entity.enums.LaunchModeEnum) TestItemUpdaterContent(com.epam.ta.reportportal.ws.converter.utils.item.content.TestItemUpdaterContent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) PageableExecutionUtils(org.springframework.data.repository.support.PageableExecutionUtils) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) PagedResourcesAssembler(com.epam.ta.reportportal.ws.converter.PagedResourcesAssembler) List(java.util.List) HistoryProviderFactory(com.epam.ta.reportportal.core.item.impl.history.provider.HistoryProviderFactory) Queryable(com.epam.ta.reportportal.commons.querygen.Queryable) Optional(java.util.Optional) CompositeFilter(com.epam.ta.reportportal.commons.querygen.CompositeFilter) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) MAX_HISTORY_DEPTH_BOUND(com.epam.ta.reportportal.ws.model.ValidationConstraints.MAX_HISTORY_DEPTH_BOUND) ResourceUpdater(com.epam.ta.reportportal.ws.converter.utils.ResourceUpdater) HistoryRequestParams(com.epam.ta.reportportal.core.item.impl.history.param.HistoryRequestParams) ResourceUpdaterProvider(com.epam.ta.reportportal.ws.converter.utils.ResourceUpdaterProvider) CompositeFilter(com.epam.ta.reportportal.commons.querygen.CompositeFilter) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) TestItemHistory(com.epam.ta.reportportal.entity.item.history.TestItemHistory)

Aggregations

ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 CompositeFilter (com.epam.ta.reportportal.commons.querygen.CompositeFilter)2 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 FilterCondition (com.epam.ta.reportportal.commons.querygen.FilterCondition)2 Queryable (com.epam.ta.reportportal.commons.querygen.Queryable)2 CRITERIA_PROJECT_ID (com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_PROJECT_ID)2 CRITERIA_LAUNCH_MODE (com.epam.ta.reportportal.commons.querygen.constant.LaunchCriteriaConstant.CRITERIA_LAUNCH_MODE)2 CRITERIA_HAS_STATS (com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant.CRITERIA_HAS_STATS)2 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)2 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)2 TestItemsHistoryHandler (com.epam.ta.reportportal.core.item.history.TestItemsHistoryHandler)2 HistoryRequestParams (com.epam.ta.reportportal.core.item.impl.history.param.HistoryRequestParams)2 HistoryProviderFactory (com.epam.ta.reportportal.core.item.impl.history.provider.HistoryProviderFactory)2 TestItemRepository (com.epam.ta.reportportal.dao.TestItemRepository)2 LaunchModeEnum (com.epam.ta.reportportal.entity.enums.LaunchModeEnum)2 TestItem (com.epam.ta.reportportal.entity.item.TestItem)2 TestItemHistory (com.epam.ta.reportportal.entity.item.history.TestItemHistory)2 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 PagedResourcesAssembler (com.epam.ta.reportportal.ws.converter.PagedResourcesAssembler)2 TestItemConverter (com.epam.ta.reportportal.ws.converter.converters.TestItemConverter)2