| 1 | |
package com.ctrip.apollo.biz.service; |
| 2 | |
|
| 3 | |
import java.util.Collections; |
| 4 | |
import java.util.List; |
| 5 | |
|
| 6 | |
import org.springframework.beans.factory.annotation.Autowired; |
| 7 | |
import org.springframework.stereotype.Service; |
| 8 | |
|
| 9 | |
import com.ctrip.apollo.biz.entity.Cluster; |
| 10 | |
import com.ctrip.apollo.biz.entity.Namespace; |
| 11 | |
import com.ctrip.apollo.biz.entity.Item; |
| 12 | |
import com.ctrip.apollo.biz.entity.Release; |
| 13 | |
import com.ctrip.apollo.biz.repository.ClusterRepository; |
| 14 | |
import com.ctrip.apollo.biz.repository.NamespaceRepository; |
| 15 | |
import com.ctrip.apollo.biz.repository.ItemRepository; |
| 16 | |
import com.ctrip.apollo.biz.repository.ReleaseRepository; |
| 17 | |
import com.google.common.base.Strings; |
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
@Service |
| 23 | 1 | public class ViewService { |
| 24 | |
|
| 25 | |
@Autowired |
| 26 | |
private ClusterRepository clusterRepository; |
| 27 | |
|
| 28 | |
@Autowired |
| 29 | |
private NamespaceRepository namespaceRepository; |
| 30 | |
|
| 31 | |
@Autowired |
| 32 | |
private ItemRepository itemRepository; |
| 33 | |
|
| 34 | |
@Autowired |
| 35 | |
private ReleaseRepository releaseRepository; |
| 36 | |
|
| 37 | |
public List<Cluster> findClusters(String appId) { |
| 38 | 3 | if (Strings.isNullOrEmpty(appId)) { |
| 39 | 0 | return Collections.emptyList(); |
| 40 | |
} |
| 41 | |
|
| 42 | 3 | List<Cluster> clusters = clusterRepository.findByAppId(appId); |
| 43 | 3 | if (clusters == null) { |
| 44 | 0 | return Collections.emptyList(); |
| 45 | |
} |
| 46 | 3 | return clusters; |
| 47 | |
} |
| 48 | |
|
| 49 | |
public List<Namespace> findNamespaces(String appId, String clusterName) { |
| 50 | 3 | List<Namespace> groups = namespaceRepository.findByAppIdAndClusterName(appId, clusterName); |
| 51 | 3 | if (groups == null) { |
| 52 | 0 | return Collections.emptyList(); |
| 53 | |
} |
| 54 | 3 | return groups; |
| 55 | |
} |
| 56 | |
|
| 57 | |
public List<Item> findItems(String appId, String clusterName, String namespaceName) { |
| 58 | 0 | Namespace group = namespaceRepository.findByAppIdAndClusterNameAndNamespaceName(appId, clusterName, |
| 59 | |
namespaceName); |
| 60 | 0 | if (group != null) { |
| 61 | 0 | return findItems(group.getId()); |
| 62 | |
} else { |
| 63 | 0 | return Collections.emptyList(); |
| 64 | |
} |
| 65 | |
} |
| 66 | |
|
| 67 | |
public List<Item> findItems(Long namespaceId) { |
| 68 | 0 | List<Item> items = itemRepository.findByNamespaceIdOrderByLineNumAsc(namespaceId); |
| 69 | 0 | if (items == null) { |
| 70 | 0 | return Collections.emptyList(); |
| 71 | |
} |
| 72 | 0 | return items; |
| 73 | |
} |
| 74 | |
|
| 75 | |
public List<Release> findReleases(String appId, String clusterName, String namespaceName) { |
| 76 | 0 | List<Release> releases = releaseRepository.findByAppIdAndClusterNameAndNamespaceName(appId, |
| 77 | |
clusterName, namespaceName); |
| 78 | 0 | if (releases == null) { |
| 79 | 0 | return Collections.emptyList(); |
| 80 | |
} |
| 81 | 0 | return releases; |
| 82 | |
} |
| 83 | |
|
| 84 | |
} |