Java Code Examples for org.springframework.data.domain.Page.hasContent()

The following are Jave code examples for showing how to use hasContent() of the org.springframework.data.domain.Page class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: apollo-custom   File: InstanceService.java   Source Code and License Vote up 5 votes
public Page<Instance> findInstancesByNamespace(String appId, String clusterName, String
    namespaceName, Pageable pageable) {
  Page<InstanceConfig> instanceConfigs = instanceConfigRepository.
      findByConfigAppIdAndConfigClusterNameAndConfigNamespaceNameAndDataChangeLastModifiedTimeAfter(appId, clusterName,
          namespaceName, getValidInstanceConfigDate(), pageable);

  List<Instance> instances = Collections.emptyList();
  if (instanceConfigs.hasContent()) {
    Set<Long> instanceIds = instanceConfigs.getContent().stream().map
        (InstanceConfig::getInstanceId).collect(Collectors.toSet());
    instances = findInstancesByIds(instanceIds);
  }

  return new PageImpl<>(instances, pageable, instanceConfigs.getTotalElements());
}
 
Example 2
Project: apollo-custom   File: InstanceService.java   Source Code and License Vote up 5 votes
public Page<Instance> findInstancesByNamespaceAndInstanceAppId(String instanceAppId, String
    appId, String clusterName, String
                                                                   namespaceName, Pageable
                                                                   pageable) {
  Page<Object[]> instanceIdResult = instanceConfigRepository
      .findInstanceIdsByNamespaceAndInstanceAppId(instanceAppId, appId, clusterName,
          namespaceName, getValidInstanceConfigDate(), pageable);

  List<Instance> instances = Collections.emptyList();
  if (instanceIdResult.hasContent()) {
    Set<Long> instanceIds = instanceIdResult.getContent().stream().map((Object o) -> {
      if (o == null) {
        return null;
      }

      if (o instanceof Integer) {
        return ((Integer)o).longValue();
      }

      if (o instanceof Long) {
        return (Long) o;
      }

      //for h2 test
      if (o instanceof BigInteger) {
        return ((BigInteger) o).longValue();
      }

      return null;
    }).filter((Long value) -> value != null).collect(Collectors.toSet());
    instances = findInstancesByIds(instanceIds);
  }

  return new PageImpl<>(instances, pageable, instanceIdResult.getTotalElements());
}
 
Example 3
Project: apollo-custom   File: ReleaseHistoryController.java   Source Code and License Vote up 5 votes
private PageDTO<ReleaseHistoryDTO> transform2PageDTO(Page<ReleaseHistory> releaseHistoriesPage, Pageable pageable){
  if (!releaseHistoriesPage.hasContent()) {
    return null;
  }

  List<ReleaseHistory> releaseHistories = releaseHistoriesPage.getContent();
  List<ReleaseHistoryDTO> releaseHistoryDTOs = new ArrayList<>(releaseHistories.size());
  for (ReleaseHistory releaseHistory : releaseHistories) {
    releaseHistoryDTOs.add(transformReleaseHistory2DTO(releaseHistory));
  }

  return new PageDTO<>(releaseHistoryDTOs, pageable, releaseHistoriesPage.getTotalElements());
}
 
Example 4
Project: apollo-custom   File: InstanceConfigController.java   Source Code and License Vote up 4 votes
@RequestMapping(value = "/by-release", method = RequestMethod.GET)
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());
}