use of com.ctrip.framework.apollo.common.dto.PageDTO in project apollo by ctripcorp.
the class SearchController method searchByItem.
private PageDTO<App> searchByItem(String itemKey, Pageable pageable) {
List<App> result = Lists.newLinkedList();
if (StringUtils.isEmpty(itemKey)) {
return new PageDTO<>(result, pageable, 0);
}
// use the env witch has the most namespace as page index.
final AtomicLong maxTotal = new AtomicLong(0);
List<Env> activeEnvs = portalSettings.getActiveEnvs();
activeEnvs.forEach(env -> {
PageDTO<NamespaceDTO> namespacePage = namespaceService.findNamespacesByItem(env, itemKey, pageable);
if (!namespacePage.hasContent()) {
return;
}
long currentEnvNSTotal = namespacePage.getTotal();
if (currentEnvNSTotal > maxTotal.get()) {
maxTotal.set(namespacePage.getTotal());
}
List<NamespaceDTO> namespaceDTOS = namespacePage.getContent();
namespaceDTOS.forEach(namespaceDTO -> {
String cluster = namespaceDTO.getClusterName();
String namespaceName = namespaceDTO.getNamespaceName();
App app = new App();
app.setAppId(namespaceDTO.getAppId());
app.setName(env.getName() + " / " + cluster + " / " + namespaceName);
app.setOrgId(env.getName() + "+" + cluster + "+" + namespaceName);
app.setOrgName("SearchByItem" + "+" + itemKey);
result.add(app);
});
});
return new PageDTO<>(result, pageable, maxTotal.get());
}
use of com.ctrip.framework.apollo.common.dto.PageDTO 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 com.ctrip.framework.apollo.common.dto.PageDTO in project apollo by ctripcorp.
the class SearchControllerTest method testSearchItemSwitch.
@Test
public void testSearchItemSwitch() {
String query = "timeout";
PageRequest request = PageRequest.of(0, 20);
PageDTO<App> apps = new PageDTO<>(Lists.newLinkedList(), request, 0);
when(appService.searchByAppIdOrAppName(query, request)).thenReturn(apps);
when(portalConfig.supportSearchByItem()).thenReturn(false);
PageDTO<App> result = searchController.search(query, request);
Assert.assertFalse(result.hasContent());
verify(appService, times(0)).findAll(request);
verify(appService, times(1)).searchByAppIdOrAppName(query, request);
}
use of com.ctrip.framework.apollo.common.dto.PageDTO in project apollo by ctripcorp.
the class SearchControllerTest method genPageApp.
private PageDTO<App> genPageApp(int size, Pageable pageable, int total) {
List<App> result = Lists.newLinkedList();
for (int i = 0; i < size; i++) {
App app = new App();
result.add(app);
}
return new PageDTO<>(result, pageable, total);
}
use of com.ctrip.framework.apollo.common.dto.PageDTO in project apollo by ctripcorp.
the class ReleaseHistoryController method transform2PageDTO.
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());
}
Aggregations