Search in sources :

Example 86 with Pageable

use of org.springframework.data.domain.Pageable in project commons-dao by reportportal.

the class TestItemRepositoryCustomImpl method loadItemsHistoryPage.

@Override
public Page<TestItemHistory> loadItemsHistoryPage(Queryable filter, Pageable pageable, Long projectId, String launchName, int historyDepth, boolean usingHash) {
    SelectQuery<? extends Record> filteringQuery = QueryBuilder.newBuilder(filter, QueryUtils.collectJoinFields(filter, pageable.getSort())).with(pageable.getSort()).build();
    Field<?> historyGroupingField = usingHash ? TEST_ITEM.TEST_CASE_HASH : TEST_ITEM.UNIQUE_ID;
    Page<String> historyBaseline = loadHistoryBaseline(filteringQuery, historyGroupingField, LAUNCH.PROJECT_ID.eq(projectId).and(LAUNCH.NAME.eq(launchName)), pageable);
    List<TestItemHistory> itemHistories = historyBaseline.getContent().stream().map(value -> {
        List<Long> itemIds = loadHistoryItem(getHistoryFilter(filter, usingHash, value), pageable.getSort(), LAUNCH.PROJECT_ID.eq(projectId).and(LAUNCH.NAME.eq(launchName))).map(testItem -> getHistoryIds(testItem, usingHash, projectId, launchName, historyDepth - 1)).orElseGet(Collections::emptyList);
        return new TestItemHistory(value, itemIds);
    }).collect(Collectors.toList());
    return new PageImpl<>(itemHistories, pageable, historyBaseline.getTotalElements());
}
Also used : StatisticsField(com.epam.ta.reportportal.entity.statistics.StatisticsField) StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) DSL(org.jooq.impl.DSL) JIssueGroupEnum(com.epam.ta.reportportal.jooq.enums.JIssueGroupEnum) Autowired(org.springframework.beans.factory.annotation.Autowired) IndexTestItem(com.epam.ta.reportportal.ws.model.analyzer.IndexTestItem) TestItemCriteriaConstant(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant) Condition(org.jooq.Condition) CRITERIA_ID(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_ID) org.jooq(org.jooq) Duration(java.time.Duration) Pair(org.springframework.data.util.Pair) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) CRITERIA_LAUNCH_MODE(com.epam.ta.reportportal.commons.querygen.constant.LaunchCriteriaConstant.CRITERIA_LAUNCH_MODE) Repository(org.springframework.stereotype.Repository) CRITERIA_START_TIME(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_START_TIME) TEST_ITEM_RESULTS(com.epam.ta.reportportal.jooq.tables.JTestItemResults.TEST_ITEM_RESULTS) TestItemRepositoryConstants(com.epam.ta.reportportal.dao.constant.TestItemRepositoryConstants) Timestamp(java.sql.Timestamp) WidgetContentRepositoryConstants(com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants) QueryBuilder.retrieveOffsetAndApplyBoundaries(com.epam.ta.reportportal.commons.querygen.QueryBuilder.retrieveOffsetAndApplyBoundaries) PageableExecutionUtils(org.springframework.data.repository.support.PageableExecutionUtils) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) ITEM(com.epam.ta.reportportal.dao.constant.LogRepositoryConstants.ITEM) Strings(org.apache.logging.log4j.util.Strings) com.epam.ta.reportportal.entity.item(com.epam.ta.reportportal.entity.item) JStatusEnum(com.epam.ta.reportportal.jooq.enums.JStatusEnum) PageImpl(org.springframework.data.domain.PageImpl) FILTERED_QUERY(com.epam.ta.reportportal.commons.querygen.FilterTarget.FILTERED_QUERY) TimestampUtils(com.epam.ta.reportportal.dao.util.TimestampUtils) TestItemTypeEnum(com.epam.ta.reportportal.entity.enums.TestItemTypeEnum) java.util(java.util) RecordMappers(com.epam.ta.reportportal.dao.util.RecordMappers) TestItemHistory(com.epam.ta.reportportal.entity.item.history.TestItemHistory) JLaunchModeEnum(com.epam.ta.reportportal.jooq.enums.JLaunchModeEnum) LocalDateTime(java.time.LocalDateTime) FILTERED_ID(com.epam.ta.reportportal.commons.querygen.FilterTarget.FILTERED_ID) JTestItem(com.epam.ta.reportportal.jooq.tables.JTestItem) Statistics(com.epam.ta.reportportal.entity.statistics.Statistics) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Tables(com.epam.ta.reportportal.jooq.Tables) Lists(com.google.common.collect.Lists) QueryUtils(com.epam.ta.reportportal.dao.util.QueryUtils) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) JooqFieldNameTransformer.fieldName(com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName) ISSUE_TYPE(com.epam.ta.reportportal.jooq.tables.JIssueType.ISSUE_TYPE) LOGS(com.epam.ta.reportportal.dao.constant.LogRepositoryConstants.LOGS) ResultFetchers(com.epam.ta.reportportal.dao.util.ResultFetchers) JTestItemTypeEnum(com.epam.ta.reportportal.jooq.enums.JTestItemTypeEnum) Optional.ofNullable(java.util.Optional.ofNullable) LaunchModeEnum(com.epam.ta.reportportal.entity.enums.LaunchModeEnum) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) ID(com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID) Collectors.toList(java.util.stream.Collectors.toList) com.epam.ta.reportportal.commons.querygen(com.epam.ta.reportportal.commons.querygen) TEST_ITEM(com.epam.ta.reportportal.jooq.tables.JTestItem.TEST_ITEM) PageImpl(org.springframework.data.domain.PageImpl) Collectors.toList(java.util.stream.Collectors.toList) TestItemHistory(com.epam.ta.reportportal.entity.item.history.TestItemHistory)

Example 87 with Pageable

use of org.springframework.data.domain.Pageable in project commons-dao by reportportal.

the class TestItemRepositoryCustomImpl method loadItemsHistoryPage.

@Override
public Page<TestItemHistory> loadItemsHistoryPage(Queryable filter, Pageable pageable, Long projectId, int historyDepth, boolean usingHash) {
    SelectQuery<? extends Record> filteringQuery = QueryBuilder.newBuilder(filter, QueryUtils.collectJoinFields(filter, pageable.getSort())).with(pageable.getSort()).build();
    Field<?> historyGroupingField = usingHash ? TEST_ITEM.TEST_CASE_HASH : TEST_ITEM.UNIQUE_ID;
    Page<String> historyBaseline = loadHistoryBaseline(filteringQuery, historyGroupingField, LAUNCH.PROJECT_ID.eq(projectId), pageable);
    List<TestItemHistory> itemHistories = historyBaseline.getContent().stream().map(value -> {
        List<Long> itemIds = loadHistoryItem(getHistoryFilter(filter, usingHash, value), pageable.getSort(), LAUNCH.PROJECT_ID.eq(projectId)).map(testItem -> getHistoryIds(testItem, usingHash, projectId, historyDepth - 1)).orElseGet(Collections::emptyList);
        return new TestItemHistory(value, itemIds);
    }).collect(Collectors.toList());
    return new PageImpl<>(itemHistories, pageable, historyBaseline.getTotalElements());
}
Also used : StatisticsField(com.epam.ta.reportportal.entity.statistics.StatisticsField) StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) DSL(org.jooq.impl.DSL) JIssueGroupEnum(com.epam.ta.reportportal.jooq.enums.JIssueGroupEnum) Autowired(org.springframework.beans.factory.annotation.Autowired) IndexTestItem(com.epam.ta.reportportal.ws.model.analyzer.IndexTestItem) TestItemCriteriaConstant(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant) Condition(org.jooq.Condition) CRITERIA_ID(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_ID) org.jooq(org.jooq) Duration(java.time.Duration) Pair(org.springframework.data.util.Pair) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) CRITERIA_LAUNCH_MODE(com.epam.ta.reportportal.commons.querygen.constant.LaunchCriteriaConstant.CRITERIA_LAUNCH_MODE) Repository(org.springframework.stereotype.Repository) CRITERIA_START_TIME(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_START_TIME) TEST_ITEM_RESULTS(com.epam.ta.reportportal.jooq.tables.JTestItemResults.TEST_ITEM_RESULTS) TestItemRepositoryConstants(com.epam.ta.reportportal.dao.constant.TestItemRepositoryConstants) Timestamp(java.sql.Timestamp) WidgetContentRepositoryConstants(com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants) QueryBuilder.retrieveOffsetAndApplyBoundaries(com.epam.ta.reportportal.commons.querygen.QueryBuilder.retrieveOffsetAndApplyBoundaries) PageableExecutionUtils(org.springframework.data.repository.support.PageableExecutionUtils) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) ITEM(com.epam.ta.reportportal.dao.constant.LogRepositoryConstants.ITEM) Strings(org.apache.logging.log4j.util.Strings) com.epam.ta.reportportal.entity.item(com.epam.ta.reportportal.entity.item) JStatusEnum(com.epam.ta.reportportal.jooq.enums.JStatusEnum) PageImpl(org.springframework.data.domain.PageImpl) FILTERED_QUERY(com.epam.ta.reportportal.commons.querygen.FilterTarget.FILTERED_QUERY) TimestampUtils(com.epam.ta.reportportal.dao.util.TimestampUtils) TestItemTypeEnum(com.epam.ta.reportportal.entity.enums.TestItemTypeEnum) java.util(java.util) RecordMappers(com.epam.ta.reportportal.dao.util.RecordMappers) TestItemHistory(com.epam.ta.reportportal.entity.item.history.TestItemHistory) JLaunchModeEnum(com.epam.ta.reportportal.jooq.enums.JLaunchModeEnum) LocalDateTime(java.time.LocalDateTime) FILTERED_ID(com.epam.ta.reportportal.commons.querygen.FilterTarget.FILTERED_ID) JTestItem(com.epam.ta.reportportal.jooq.tables.JTestItem) Statistics(com.epam.ta.reportportal.entity.statistics.Statistics) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Tables(com.epam.ta.reportportal.jooq.Tables) Lists(com.google.common.collect.Lists) QueryUtils(com.epam.ta.reportportal.dao.util.QueryUtils) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) JooqFieldNameTransformer.fieldName(com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName) ISSUE_TYPE(com.epam.ta.reportportal.jooq.tables.JIssueType.ISSUE_TYPE) LOGS(com.epam.ta.reportportal.dao.constant.LogRepositoryConstants.LOGS) ResultFetchers(com.epam.ta.reportportal.dao.util.ResultFetchers) JTestItemTypeEnum(com.epam.ta.reportportal.jooq.enums.JTestItemTypeEnum) Optional.ofNullable(java.util.Optional.ofNullable) LaunchModeEnum(com.epam.ta.reportportal.entity.enums.LaunchModeEnum) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) ID(com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID) Collectors.toList(java.util.stream.Collectors.toList) com.epam.ta.reportportal.commons.querygen(com.epam.ta.reportportal.commons.querygen) TEST_ITEM(com.epam.ta.reportportal.jooq.tables.JTestItem.TEST_ITEM) PageImpl(org.springframework.data.domain.PageImpl) Collectors.toList(java.util.stream.Collectors.toList) TestItemHistory(com.epam.ta.reportportal.entity.item.history.TestItemHistory)

Example 88 with Pageable

use of org.springframework.data.domain.Pageable in project commons-dao by reportportal.

the class TestItemRepositoryCustomImpl method loadItemsHistoryPage.

@Override
public Page<TestItemHistory> loadItemsHistoryPage(Queryable filter, Pageable pageable, Long projectId, List<Long> launchIds, int historyDepth, boolean usingHash) {
    SelectQuery<? extends Record> filteringQuery = QueryBuilder.newBuilder(filter, QueryUtils.collectJoinFields(filter, pageable.getSort())).with(pageable.getSort()).addCondition(LAUNCH.ID.in(launchIds).and(LAUNCH.PROJECT_ID.eq(projectId))).build();
    Field<?> historyGroupingField = usingHash ? TEST_ITEM.TEST_CASE_HASH : TEST_ITEM.UNIQUE_ID;
    Page<String> historyBaseline = loadHistoryBaseline(filteringQuery, historyGroupingField, LAUNCH.ID.in(launchIds).and(LAUNCH.PROJECT_ID.eq(projectId)), pageable);
    List<TestItemHistory> itemHistories = historyBaseline.getContent().stream().map(value -> {
        List<Long> itemIds = loadHistoryItem(getHistoryFilter(filter, usingHash, value), pageable.getSort(), LAUNCH.ID.in(launchIds).and(LAUNCH.PROJECT_ID.eq(projectId))).map(testItem -> getHistoryIds(testItem, usingHash, projectId, historyDepth - 1)).orElseGet(Collections::emptyList);
        return new TestItemHistory(value, itemIds);
    }).collect(Collectors.toList());
    return new PageImpl<>(itemHistories, pageable, historyBaseline.getTotalElements());
}
Also used : StatisticsField(com.epam.ta.reportportal.entity.statistics.StatisticsField) StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) DSL(org.jooq.impl.DSL) JIssueGroupEnum(com.epam.ta.reportportal.jooq.enums.JIssueGroupEnum) Autowired(org.springframework.beans.factory.annotation.Autowired) IndexTestItem(com.epam.ta.reportportal.ws.model.analyzer.IndexTestItem) TestItemCriteriaConstant(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant) Condition(org.jooq.Condition) CRITERIA_ID(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_ID) org.jooq(org.jooq) Duration(java.time.Duration) Pair(org.springframework.data.util.Pair) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) CRITERIA_LAUNCH_MODE(com.epam.ta.reportportal.commons.querygen.constant.LaunchCriteriaConstant.CRITERIA_LAUNCH_MODE) Repository(org.springframework.stereotype.Repository) CRITERIA_START_TIME(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_START_TIME) TEST_ITEM_RESULTS(com.epam.ta.reportportal.jooq.tables.JTestItemResults.TEST_ITEM_RESULTS) TestItemRepositoryConstants(com.epam.ta.reportportal.dao.constant.TestItemRepositoryConstants) Timestamp(java.sql.Timestamp) WidgetContentRepositoryConstants(com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants) QueryBuilder.retrieveOffsetAndApplyBoundaries(com.epam.ta.reportportal.commons.querygen.QueryBuilder.retrieveOffsetAndApplyBoundaries) PageableExecutionUtils(org.springframework.data.repository.support.PageableExecutionUtils) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) ITEM(com.epam.ta.reportportal.dao.constant.LogRepositoryConstants.ITEM) Strings(org.apache.logging.log4j.util.Strings) com.epam.ta.reportportal.entity.item(com.epam.ta.reportportal.entity.item) JStatusEnum(com.epam.ta.reportportal.jooq.enums.JStatusEnum) PageImpl(org.springframework.data.domain.PageImpl) FILTERED_QUERY(com.epam.ta.reportportal.commons.querygen.FilterTarget.FILTERED_QUERY) TimestampUtils(com.epam.ta.reportportal.dao.util.TimestampUtils) TestItemTypeEnum(com.epam.ta.reportportal.entity.enums.TestItemTypeEnum) java.util(java.util) RecordMappers(com.epam.ta.reportportal.dao.util.RecordMappers) TestItemHistory(com.epam.ta.reportportal.entity.item.history.TestItemHistory) JLaunchModeEnum(com.epam.ta.reportportal.jooq.enums.JLaunchModeEnum) LocalDateTime(java.time.LocalDateTime) FILTERED_ID(com.epam.ta.reportportal.commons.querygen.FilterTarget.FILTERED_ID) JTestItem(com.epam.ta.reportportal.jooq.tables.JTestItem) Statistics(com.epam.ta.reportportal.entity.statistics.Statistics) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Tables(com.epam.ta.reportportal.jooq.Tables) Lists(com.google.common.collect.Lists) QueryUtils(com.epam.ta.reportportal.dao.util.QueryUtils) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) JooqFieldNameTransformer.fieldName(com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName) ISSUE_TYPE(com.epam.ta.reportportal.jooq.tables.JIssueType.ISSUE_TYPE) LOGS(com.epam.ta.reportportal.dao.constant.LogRepositoryConstants.LOGS) ResultFetchers(com.epam.ta.reportportal.dao.util.ResultFetchers) JTestItemTypeEnum(com.epam.ta.reportportal.jooq.enums.JTestItemTypeEnum) Optional.ofNullable(java.util.Optional.ofNullable) LaunchModeEnum(com.epam.ta.reportportal.entity.enums.LaunchModeEnum) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) ID(com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID) Collectors.toList(java.util.stream.Collectors.toList) com.epam.ta.reportportal.commons.querygen(com.epam.ta.reportportal.commons.querygen) TEST_ITEM(com.epam.ta.reportportal.jooq.tables.JTestItem.TEST_ITEM) PageImpl(org.springframework.data.domain.PageImpl) Collectors.toList(java.util.stream.Collectors.toList) TestItemHistory(com.epam.ta.reportportal.entity.item.history.TestItemHistory)

Example 89 with Pageable

use of org.springframework.data.domain.Pageable in project commons-dao by reportportal.

the class ClusterRepositoryTest method shouldDeleteByLaunchId.

@Test
void shouldDeleteByLaunchId() {
    final int removed = clusterRepository.deleteAllByLaunchId(LAUNCH_ID);
    assertEquals(3, removed);
    final Pageable pageable = PageRequest.of(0, 3, Sort.by(Sort.Order.by(CRITERIA_ID)));
    final Page<Cluster> clusters = clusterRepository.findAllByLaunchId(LAUNCH_ID, pageable);
    assertTrue(clusters.isEmpty());
}
Also used : Pageable(org.springframework.data.domain.Pageable) Cluster(com.epam.ta.reportportal.entity.cluster.Cluster) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 90 with Pageable

use of org.springframework.data.domain.Pageable in project commons-dao by reportportal.

the class ClusterRepositoryTest method shouldFindByLaunchId.

@Test
void shouldFindByLaunchId() {
    final Pageable pageable = PageRequest.of(0, 3, Sort.by(Sort.Order.by(CRITERIA_ID)));
    final Page<Cluster> clusters = clusterRepository.findAllByLaunchId(LAUNCH_ID, pageable);
    assertFalse(clusters.isEmpty());
    assertEquals(3, clusters.getContent().size());
    clusters.getContent().forEach(cluster -> assertEquals(LAUNCH_ID, cluster.getLaunchId()));
}
Also used : Pageable(org.springframework.data.domain.Pageable) Cluster(com.epam.ta.reportportal.entity.cluster.Cluster) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

Pageable (org.springframework.data.domain.Pageable)172 PageRequest (org.springframework.data.domain.PageRequest)91 Sort (org.springframework.data.domain.Sort)79 Test (org.junit.Test)39 PageImpl (org.springframework.data.domain.PageImpl)24 Collectors (java.util.stream.Collectors)17 Page (org.springframework.data.domain.Page)16 ArrayList (java.util.ArrayList)14 Autowired (org.springframework.beans.factory.annotation.Autowired)14 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 List (java.util.List)11 UUID (java.util.UUID)10 ApiOperation (io.swagger.annotations.ApiOperation)9 Calendar (java.util.Calendar)9 Test (org.junit.jupiter.api.Test)9 java.util (java.util)8 Lists (com.google.common.collect.Lists)7 Map (java.util.Map)6 Transactional (org.springframework.transaction.annotation.Transactional)6