Search in sources :

Example 1 with PageDTO

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());
}
Also used : App(com.ctrip.framework.apollo.common.entity.App) AtomicLong(java.util.concurrent.atomic.AtomicLong) NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) PageDTO(com.ctrip.framework.apollo.common.dto.PageDTO) Env(com.ctrip.framework.apollo.portal.environment.Env)

Example 2 with PageDTO

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());
}
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 3 with PageDTO

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);
}
Also used : App(com.ctrip.framework.apollo.common.entity.App) PageRequest(org.springframework.data.domain.PageRequest) PageDTO(com.ctrip.framework.apollo.common.dto.PageDTO) Test(org.junit.Test)

Example 4 with PageDTO

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);
}
Also used : App(com.ctrip.framework.apollo.common.entity.App) PageDTO(com.ctrip.framework.apollo.common.dto.PageDTO)

Example 5 with PageDTO

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());
}
Also used : ReleaseHistoryDTO(com.ctrip.framework.apollo.common.dto.ReleaseHistoryDTO) PageDTO(com.ctrip.framework.apollo.common.dto.PageDTO) ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) ArrayList(java.util.ArrayList)

Aggregations

PageDTO (com.ctrip.framework.apollo.common.dto.PageDTO)7 App (com.ctrip.framework.apollo.common.entity.App)4 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)3 PageRequest (org.springframework.data.domain.PageRequest)3 Test (org.junit.Test)2 Instance (com.ctrip.framework.apollo.biz.entity.Instance)1 InstanceConfig (com.ctrip.framework.apollo.biz.entity.InstanceConfig)1 Release (com.ctrip.framework.apollo.biz.entity.Release)1 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)1 InstanceService (com.ctrip.framework.apollo.biz.service.InstanceService)1 ReleaseService (com.ctrip.framework.apollo.biz.service.ReleaseService)1 InstanceConfigDTO (com.ctrip.framework.apollo.common.dto.InstanceConfigDTO)1 InstanceDTO (com.ctrip.framework.apollo.common.dto.InstanceDTO)1 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)1 ReleaseHistoryDTO (com.ctrip.framework.apollo.common.dto.ReleaseHistoryDTO)1 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)1 BeanUtils (com.ctrip.framework.apollo.common.utils.BeanUtils)1 Env (com.ctrip.framework.apollo.portal.environment.Env)1 Splitter (com.google.common.base.Splitter)1 Strings (com.google.common.base.Strings)1