Search in sources :

Example 91 with Pageable

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

the class LogRepositoryCustomImpl method getPageNumber.

@Override
public Integer getPageNumber(Long id, Filter filter, Pageable pageable) {
    Sort.Order order = ofNullable(pageable.getSort().getOrderFor(CRITERIA_LOG_TIME)).orElseThrow(() -> new ReportPortalException(ErrorType.INCORRECT_SORTING_PARAMETERS));
    OrderField<?> sortField = order.getDirection().isAscending() ? LOG.LOG_TIME.asc() : LOG.LOG_TIME.desc();
    return ofNullable(dsl.select(fieldName(ROW_NUMBER)).from(dsl.select(LOG.ID, DSL.rowNumber().over(DSL.orderBy(sortField)).as(ROW_NUMBER)).from(LOG).join(QueryBuilder.newBuilder(filter, QueryUtils.collectJoinFields(filter, pageable.getSort())).with(pageable.getSort()).build().asTable(DISTINCT_LOGS_TABLE)).on(LOG.ID.eq(fieldName(DISTINCT_LOGS_TABLE, ID).cast(Long.class)))).where(fieldName(ID).cast(Long.class).eq(id)).fetchAny()).map(r -> {
        Long rowNumber = r.into(Long.class);
        return BigDecimal.valueOf(rowNumber).divide(BigDecimal.valueOf(pageable.getPageSize()), RoundingMode.CEILING).intValue();
    }).orElseThrow(() -> new ReportPortalException(ErrorType.LOG_NOT_FOUND, id));
}
Also used : TimestampUtils(com.epam.ta.reportportal.dao.util.TimestampUtils) StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) CRITERIA_STATUS(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant.CRITERIA_STATUS) java.util(java.util) DSL(org.jooq.impl.DSL) RecordMappers(com.epam.ta.reportportal.dao.util.RecordMappers) QueryBuilder(com.epam.ta.reportportal.commons.querygen.QueryBuilder) LOG(com.epam.ta.reportportal.jooq.Tables.LOG) DSL.field(org.jooq.impl.DSL.field) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) JTestItem(com.epam.ta.reportportal.jooq.tables.JTestItem) NESTED_ITEM_FETCHER(com.epam.ta.reportportal.dao.util.ResultFetchers.NESTED_ITEM_FETCHER) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) LAUNCH(com.epam.ta.reportportal.jooq.Tables.LAUNCH) QueryUtils(com.epam.ta.reportportal.dao.util.QueryUtils) Log(com.epam.ta.reportportal.entity.log.Log) org.jooq(org.jooq) Duration(java.time.Duration) JooqFieldNameTransformer.fieldName(com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) Repository(org.springframework.stereotype.Repository) RoundingMode(java.math.RoundingMode) ATTACHMENT(com.epam.ta.reportportal.jooq.tables.JAttachment.ATTACHMENT) TEST_ITEM_RESULTS(com.epam.ta.reportportal.jooq.tables.JTestItemResults.TEST_ITEM_RESULTS) NestedItem(com.epam.ta.reportportal.entity.item.NestedItem) CLUSTERS(com.epam.ta.reportportal.jooq.Tables.CLUSTERS) Optional.ofNullable(java.util.Optional.ofNullable) Filter(com.epam.ta.reportportal.commons.querygen.Filter) Timestamp(java.sql.Timestamp) LogRepositoryConstants(com.epam.ta.reportportal.dao.constant.LogRepositoryConstants) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) PageableExecutionUtils(org.springframework.data.repository.support.PageableExecutionUtils) Page(org.springframework.data.domain.Page) ID(com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) TEST_ITEM(com.epam.ta.reportportal.jooq.tables.JTestItem.TEST_ITEM) Queryable(com.epam.ta.reportportal.commons.querygen.Queryable) NESTED(com.epam.ta.reportportal.dao.constant.TestItemRepositoryConstants.NESTED) JStatusEnum(com.epam.ta.reportportal.jooq.enums.JStatusEnum) CRITERIA_LOG_TIME(com.epam.ta.reportportal.commons.querygen.constant.LogCriteriaConstant.CRITERIA_LOG_TIME) IndexLog(com.epam.ta.reportportal.ws.model.analyzer.IndexLog) LOG_FETCHER(com.epam.ta.reportportal.dao.util.ResultFetchers.LOG_FETCHER) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Sort(org.springframework.data.domain.Sort)

Example 92 with Pageable

use of org.springframework.data.domain.Pageable in project apollo by ctripcorp.

the class InstanceServiceTest method testFindActiveInstanceConfigs.

@Test
@Rollback
public void testFindActiveInstanceConfigs() throws Exception {
    long someInstanceId = 1;
    long anotherInstanceId = 2;
    String someConfigAppId = "someConfigAppId";
    String someConfigClusterName = "someConfigClusterName";
    String someConfigNamespaceName = "someConfigNamespaceName";
    Date someValidDate = new Date();
    Pageable pageable = PageRequest.of(0, 10);
    String someReleaseKey = "someReleaseKey";
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -2);
    Date someInvalidDate = calendar.getTime();
    prepareInstanceConfigForInstance(someInstanceId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someValidDate);
    prepareInstanceConfigForInstance(anotherInstanceId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someInvalidDate);
    Page<InstanceConfig> validInstanceConfigs = instanceService.findActiveInstanceConfigsByReleaseKey(someReleaseKey, pageable);
    assertEquals(1, validInstanceConfigs.getContent().size());
    assertEquals(someInstanceId, validInstanceConfigs.getContent().get(0).getInstanceId());
}
Also used : Pageable(org.springframework.data.domain.Pageable) InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) Calendar(java.util.Calendar) Date(java.util.Date) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Rollback(org.springframework.test.annotation.Rollback)

Example 93 with Pageable

use of org.springframework.data.domain.Pageable in project apollo by ctripcorp.

the class NamespaceServiceTest method testFindPublicAppNamespaceWithWrongNamespace.

@Test(expected = BadRequestException.class)
public void testFindPublicAppNamespaceWithWrongNamespace() {
    Pageable page = PageRequest.of(0, 10);
    when(appNamespaceService.findPublicNamespaceByName(testPublicAppNamespace)).thenReturn(null);
    namespaceService.findPublicAppNamespaceAllNamespaces(testPublicAppNamespace, page);
}
Also used : Pageable(org.springframework.data.domain.Pageable) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest)

Example 94 with Pageable

use of org.springframework.data.domain.Pageable in project apollo by ctripcorp.

the class InstanceConfigController method getByRelease.

@GetMapping("/by-release")
public PageDTO<InstanceDTO> getByRelease(@RequestParam("releaseId") long releaseId, Pageable pageable) {
    Release release = releaseService.findOne(releaseId);
    if (release == null) {
        throw new NotFoundException(String.format("release not found for %s", releaseId));
    }
    Page<InstanceConfig> instanceConfigsPage = instanceService.findActiveInstanceConfigsByReleaseKey(release.getReleaseKey(), pageable);
    List<InstanceDTO> instanceDTOs = Collections.emptyList();
    if (instanceConfigsPage.hasContent()) {
        Multimap<Long, InstanceConfig> instanceConfigMap = HashMultimap.create();
        Set<String> otherReleaseKeys = Sets.newHashSet();
        for (InstanceConfig instanceConfig : instanceConfigsPage.getContent()) {
            instanceConfigMap.put(instanceConfig.getInstanceId(), instanceConfig);
            otherReleaseKeys.add(instanceConfig.getReleaseKey());
        }
        Set<Long> instanceIds = instanceConfigMap.keySet();
        List<Instance> instances = instanceService.findInstancesByIds(instanceIds);
        if (!CollectionUtils.isEmpty(instances)) {
            instanceDTOs = BeanUtils.batchTransform(InstanceDTO.class, instances);
        }
        for (InstanceDTO instanceDTO : instanceDTOs) {
            Collection<InstanceConfig> configs = instanceConfigMap.get(instanceDTO.getId());
            List<InstanceConfigDTO> configDTOs = configs.stream().map(instanceConfig -> {
                InstanceConfigDTO instanceConfigDTO = new InstanceConfigDTO();
                // to save some space
                instanceConfigDTO.setRelease(null);
                instanceConfigDTO.setReleaseDeliveryTime(instanceConfig.getReleaseDeliveryTime());
                instanceConfigDTO.setDataChangeLastModifiedTime(instanceConfig.getDataChangeLastModifiedTime());
                return instanceConfigDTO;
            }).collect(Collectors.toList());
            instanceDTO.setConfigs(configDTOs);
        }
    }
    return new PageDTO<>(instanceDTOs, pageable, instanceConfigsPage.getTotalElements());
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO) Multimap(com.google.common.collect.Multimap) BeanUtils(com.ctrip.framework.apollo.common.utils.BeanUtils) Strings(com.google.common.base.Strings) HashMultimap(com.google.common.collect.HashMultimap) InstanceConfigDTO(com.ctrip.framework.apollo.common.dto.InstanceConfigDTO) Instance(com.ctrip.framework.apollo.biz.entity.Instance) Map(java.util.Map) InstanceDTO(com.ctrip.framework.apollo.common.dto.InstanceDTO) GetMapping(org.springframework.web.bind.annotation.GetMapping) InstanceService(com.ctrip.framework.apollo.biz.service.InstanceService) Pageable(org.springframework.data.domain.Pageable) Splitter(com.google.common.base.Splitter) Collection(java.util.Collection) ReleaseService(com.ctrip.framework.apollo.biz.service.ReleaseService) InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) PageRequest(org.springframework.data.domain.PageRequest) Set(java.util.Set) Release(com.ctrip.framework.apollo.biz.entity.Release) Page(org.springframework.data.domain.Page) Maps(com.google.common.collect.Maps) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) PageDTO(com.ctrip.framework.apollo.common.dto.PageDTO) CollectionUtils(org.springframework.util.CollectionUtils) NotFoundException(com.ctrip.framework.apollo.common.exception.NotFoundException) Collections(java.util.Collections) PageDTO(com.ctrip.framework.apollo.common.dto.PageDTO) Instance(com.ctrip.framework.apollo.biz.entity.Instance) NotFoundException(com.ctrip.framework.apollo.common.exception.NotFoundException) InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) InstanceDTO(com.ctrip.framework.apollo.common.dto.InstanceDTO) InstanceConfigDTO(com.ctrip.framework.apollo.common.dto.InstanceConfigDTO) Release(com.ctrip.framework.apollo.biz.entity.Release) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 95 with Pageable

use of org.springframework.data.domain.Pageable in project goci by EBISPOT.

the class SolrIndexer method mapEfo.

Integer mapEfo() {
    Sort sort = new Sort(new Sort.Order("id"));
    Pageable pager = new PageRequest(0, pageSize, sort);
    Page<EfoTrait> efoTraitPage = efoTraitRepository.findAll(pager);
    efoMapper.map(efoTraitPage.getContent());
    while (efoTraitPage.hasNext()) {
        if (maxPages != -1 && efoTraitPage.getNumber() >= maxPages - 1) {
            break;
        }
        pager = pager.next();
        efoTraitPage = efoTraitRepository.findAll(pager);
        efoMapper.map(efoTraitPage.getContent());
        if (sysOutLogging) {
            System.out.print(".");
        }
    }
    return (int) efoTraitPage.getTotalElements();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) EfoTrait(uk.ac.ebi.spot.goci.model.EfoTrait)

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