##### Coverage Report - com.ctrip.framework.apollo.adminservice.controller.NamespaceLockController

Classes in this File | Line Coverage | Branch Coverage | Complexity
NamespaceLockController |
10% | 1/10
0% | 0/6
| 7.0;7

1 |  |
     package com.ctrip.framework.apollo.adminservice.controller;
2 |  |
3 |  |
     import com.ctrip.framework.apollo.biz.entity.Namespace;
4 |  |
     import com.ctrip.framework.apollo.biz.entity.NamespaceLock;
5 |  |
     import com.ctrip.framework.apollo.biz.service.NamespaceLockService;
6 |  |
     import com.ctrip.framework.apollo.biz.service.NamespaceService;
7 |  |
     import com.ctrip.framework.apollo.biz.utils.ApolloSwitcher;
8 |  |
     import com.ctrip.framework.apollo.common.utils.BeanUtils;
9 |  |
     import com.ctrip.framework.apollo.core.dto.NamespaceLockDTO;
10 |  |
     import com.ctrip.framework.apollo.core.exception.BadRequestException;
11 |  |
     import com.ctrip.framework.apollo.core.exception.NotFoundException;
12 |  |
13 |  |
     import org.springframework.beans.factory.annotation.Autowired;
14 |  |
     import org.springframework.web.bind.annotation.PathVariable;
15 |  |
     import org.springframework.web.bind.annotation.RequestMapping;
16 |  |
     import org.springframework.web.bind.annotation.RestController;
17 |  |
18 |  |
     @RestController
19 | 1 |
     public class NamespaceLockController {
20 |  |
21 |  |
22 |  |
       @Autowired
23 |  |
       private NamespaceLockService namespaceLockService;
24 |  |
       @Autowired
25 |  |
       private NamespaceService namespaceService;
26 |  |
       @Autowired
27 |  |
       private ApolloSwitcher apolloSwitcher;
28 |  |
29 |  |
       @RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock")
30 |  |
       public NamespaceLockDTO getNamespaceLockOwner(@PathVariable String appId, @PathVariable String clusterName,
31 |  |
                                                     @PathVariable String namespaceName) {
32 | 0 |
         Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
33 | 0 |
         if (namespace == null) {
34 | 0 |
           throw new BadRequestException("namespace not exist.");
35 |  |
         }
36 |  |
37 | 0 |
         if (apolloSwitcher.isNamespaceLockSwitchOff()) {
38 | 0 |
           throw new NotFoundException(namespaceName + " is not locked");
39 |  |
         }
40 |  |
41 | 0 |
         NamespaceLock lock = namespaceLockService.findLock(namespace.getId());
42 |  |
43 | 0 |
         if (lock == null) {
44 | 0 |
           throw new NotFoundException(namespaceName + " is not locked");
45 |  |
         }
46 |  |
47 | 0 |
         return BeanUtils.transfrom(NamespaceLockDTO.class, lock);
48 |  |
       }
49 |  |
50 |  |
     }