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));
}
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());
}
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);
}
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());
}
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();
}
Aggregations