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

Classes in this File | Line Coverage | Branch Coverage | Complexity
PortalConfigController |
2% | 1/34
0% | 0/18
| 4.6;4.6

1 |  |
     package com.ctrip.apollo.portal.controller;
2 |  |
3 |  |
4 |  |
     import com.ctrip.apollo.core.dto.ItemDTO;
5 |  |
     import com.ctrip.apollo.core.enums.Env;
6 |  |
     import com.ctrip.apollo.core.dto.ReleaseDTO;
7 |  |
     import com.ctrip.apollo.core.exception.BadRequestException;
8 |  |
     import com.ctrip.apollo.core.utils.StringUtils;
9 |  |
     import com.ctrip.apollo.portal.entity.ItemDiffs;
10 |  |
     import com.ctrip.apollo.portal.entity.form.NamespaceSyncModel;
11 |  |
     import com.ctrip.apollo.portal.entity.form.NamespaceTextModel;
12 |  |
     import com.ctrip.apollo.portal.entity.form.NamespaceReleaseModel;
13 |  |
     import com.ctrip.apollo.portal.service.PortalConfigService;
14 |  |
15 |  |
     import org.springframework.beans.factory.annotation.Autowired;
16 |  |
     import org.springframework.http.HttpStatus;
17 |  |
     import org.springframework.http.ResponseEntity;
18 |  |
     import org.springframework.web.bind.annotation.PathVariable;
19 |  |
     import org.springframework.web.bind.annotation.RequestBody;
20 |  |
     import org.springframework.web.bind.annotation.RequestMapping;
21 |  |
     import org.springframework.web.bind.annotation.RequestMethod;
22 |  |
     import org.springframework.web.bind.annotation.RestController;
23 |  |
24 |  |
     import java.util.List;
25 |  |
26 |  |
     @RestController
27 |  |
     @RequestMapping("")
28 | 1 |
     public class PortalConfigController {
29 |  |
30 |  |
       @Autowired
31 |  |
       private PortalConfigService configService;
32 |  |
33 |  |
       @RequestMapping(value = "/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items", method = RequestMethod.PUT, consumes = {
34 |  |
           "application/json"})
35 |  |
       public void modifyItems(@PathVariable String appId, @PathVariable String env,
36 |  |
           @PathVariable String clusterName, @PathVariable String namespaceName,
37 |  |
           @RequestBody NamespaceTextModel model) {
38 |  |
39 | 0 |
         if (model == null) {
40 | 0 |
           throw new BadRequestException("request payload shoud not be null");
41 |  |
         }
42 | 0 |
         model.setAppId(appId);
43 | 0 |
         model.setClusterName(clusterName);
44 | 0 |
         model.setEnv(env);
45 | 0 |
         model.setNamespaceName(namespaceName);
46 |  |
47 | 0 |
         if (model.isInvalid()) {
48 | 0 |
           throw new BadRequestException("request model is invalid");
49 |  |
         }
50 |  |
51 | 0 |
         configService.updateConfigItemByText(model);
52 | 0 |
       }
53 |  |
54 |  |
       @RequestMapping(value = "/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/release", method = RequestMethod.POST, consumes = {
55 |  |
           "application/json"})
56 |  |
       public ReleaseDTO createRelease(@PathVariable String appId,
57 |  |
           @PathVariable String env, @PathVariable String clusterName,
58 |  |
           @PathVariable String namespaceName, @RequestBody NamespaceReleaseModel model) {
59 | 0 |
         if (model == null) {
60 | 0 |
           throw new BadRequestException("request payload shoud not be null");
61 |  |
         }
62 | 0 |
         model.setAppId(appId);
63 | 0 |
         model.setClusterName(clusterName);
64 | 0 |
         model.setEnv(env);
65 | 0 |
         model.setNamespaceName(namespaceName);
66 |  |
67 | 0 |
         if (model.isInvalid()) {
68 | 0 |
           throw new BadRequestException("request model is invalid");
69 |  |
         }
70 |  |
71 | 0 |
         return configService.createRelease(model);
72 |  |
73 |  |
       }
74 |  |
75 |  |
       @RequestMapping(value = "/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items")
76 |  |
       public List<ItemDTO> findItems(@PathVariable String appId, @PathVariable String env,
77 |  |
                                      @PathVariable String clusterName, @PathVariable String namespaceName){
78 |  |
79 | 0 |
         if (StringUtils.isContainEmpty(appId, env, clusterName, namespaceName)){
80 | 0 |
           throw new BadRequestException("appid,env,cluster name,namespace name can not be null");
81 |  |
         }
82 |  |
83 | 0 |
         return configService.findItems(appId, Env.valueOf(env), clusterName, namespaceName);
84 |  |
       }
85 |  |
86 |  |
       @RequestMapping(value = "/namespaces/{namespaceName}/diff", method = RequestMethod.POST, consumes = {
87 |  |
           "application/json"})
88 |  |
       public List<ItemDiffs> diff(@RequestBody NamespaceSyncModel model){
89 | 0 |
         if (model == null){
90 | 0 |
           throw new BadRequestException("request payload shoud not be null");
91 |  |
         }
92 | 0 |
         if (model.isInvalid()) {
93 | 0 |
           throw new BadRequestException("request model is invalid");
94 |  |
         }
95 |  |
96 | 0 |
         return configService.compare(model.getSyncToNamespaces(), model.getSyncItems());
97 |  |
       }
98 |  |
99 |  |
       @RequestMapping(value = "/namespaces/{namespaceName}/items", method = RequestMethod.PUT, consumes = {
100 |  |
           "application/json"})
101 |  |
       public ResponseEntity<Void> update(@RequestBody NamespaceSyncModel model){
102 | 0 |
         if (model == null){
103 | 0 |
           throw new BadRequestException("request payload shoud not be null");
104 |  |
         }
105 | 0 |
         if (model.isInvalid()) {
106 | 0 |
           throw new BadRequestException("request model is invalid");
107 |  |
         }
108 | 0 |
         configService.syncItems(model.getSyncToNamespaces(), model.getSyncItems());
109 | 0 |
         return ResponseEntity.status(HttpStatus.OK).build();
110 |  |
       }
111 |  |
112 |  |
     }