##### Coverage Report - com.ctrip.apollo.portal.controller.PortalNamespaceController

Classes in this File | Line Coverage | Branch Coverage | Complexity
PortalNamespaceController |
8% | 1/12
0% | 0/6
| 2.5;2.5

1 |  |
     package com.ctrip.apollo.portal.controller;
2 |  |
3 |  |
     import com.ctrip.apollo.core.dto.AppNamespaceDTO;
4 |  |
     import com.ctrip.apollo.core.dto.NamespaceDTO;
5 |  |
     import com.ctrip.apollo.core.enums.Env;
6 |  |
     import com.ctrip.apollo.core.exception.BadRequestException;
7 |  |
     import com.ctrip.apollo.core.utils.StringUtils;
8 |  |
     import com.ctrip.apollo.portal.entity.NamespaceVO;
9 |  |
     import com.ctrip.apollo.portal.service.PortalNamespaceService;
10 |  |
11 |  |
     import org.springframework.beans.factory.annotation.Autowired;
12 |  |
     import org.springframework.web.bind.annotation.PathVariable;
13 |  |
     import org.springframework.web.bind.annotation.RequestBody;
14 |  |
     import org.springframework.web.bind.annotation.RequestMapping;
15 |  |
     import org.springframework.web.bind.annotation.RequestMethod;
16 |  |
     import org.springframework.web.bind.annotation.RestController;
17 |  |
18 |  |
     import java.util.List;
19 |  |
20 |  |
     @RestController
21 | 1 |
     public class PortalNamespaceController {
22 |  |
23 |  |
       @Autowired
24 |  |
       private PortalNamespaceService namespaceService;
25 |  |
26 |  |
       @RequestMapping("/appnamespaces/public")
27 |  |
       public List<AppNamespaceDTO> findPublicAppNamespaces(){
28 | 0 |
         return namespaceService.findPublicAppNamespaces();
29 |  |
       }
30 |  |
31 |  |
       @RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces", method = RequestMethod.POST)
32 |  |
       public NamespaceDTO createNamespace(@PathVariable String env, @RequestBody NamespaceDTO namespace){
33 | 0 |
         if (StringUtils.isContainEmpty(env, namespace.getAppId(), namespace.getClusterName(), namespace.getNamespaceName())){
34 | 0 |
           throw new BadRequestException("request payload contains empty");
35 |  |
         }
36 | 0 |
         return namespaceService.createNamespace(Env.valueOf(env), namespace);
37 |  |
       }
38 |  |
39 |  |
       @RequestMapping(value = "/apps/{appId}/appnamespaces", method = RequestMethod.POST)
40 |  |
       public void createAppNamespace(@PathVariable String appId, @RequestBody AppNamespaceDTO appNamespace){
41 | 0 |
         if (StringUtils.isContainEmpty(appId, appNamespace.getAppId(), appNamespace.getName())){
42 | 0 |
           throw new BadRequestException("request payload contains empty");
43 |  |
         }
44 |  |
45 | 0 |
         namespaceService.createAppNamespace(appNamespace);
46 | 0 |
       }
47 |  |
48 |  |
       @RequestMapping("/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces")
49 |  |
       public List<NamespaceVO> findNamespaces(@PathVariable String appId, @PathVariable String env,
50 |  |
                                               @PathVariable String clusterName) {
51 | 0 |
         if (StringUtils.isContainEmpty(appId, env, clusterName)) {
52 | 0 |
           throw new BadRequestException("app id and cluster name can not be empty");
53 |  |
         }
54 |  |
55 | 0 |
         return namespaceService.findNampspaces(appId, Env.valueOf(env), clusterName);
56 |  |
       }
57 |  |
58 |  |
     }