Coverage Report - com.ctrip.apollo.adminservice.controller.ReleaseController
 
Classes in this File Line Coverage Branch Coverage Complexity
ReleaseController
21%
3/14
0%
0/4
2
 
 1  
 package com.ctrip.apollo.adminservice.controller;
 2  
 
 3  
 import java.util.List;
 4  
 
 5  
 import org.springframework.beans.factory.annotation.Autowired;
 6  
 import org.springframework.web.bind.annotation.PathVariable;
 7  
 import org.springframework.web.bind.annotation.RequestMapping;
 8  
 import org.springframework.web.bind.annotation.RequestMethod;
 9  
 import org.springframework.web.bind.annotation.RequestParam;
 10  
 import org.springframework.web.bind.annotation.RestController;
 11  
 
 12  
 import com.ctrip.apollo.biz.entity.Release;
 13  
 import com.ctrip.apollo.biz.service.ConfigService;
 14  
 import com.ctrip.apollo.biz.service.ReleaseService;
 15  
 import com.ctrip.apollo.biz.service.ViewService;
 16  
 import com.ctrip.apollo.common.utils.BeanUtils;
 17  
 import com.ctrip.apollo.core.dto.ReleaseDTO;
 18  
 import com.ctrip.apollo.core.exception.NotFoundException;
 19  
 
 20  
 @RestController
 21  1
 public class ReleaseController {
 22  
 
 23  
   @Autowired
 24  
   private ViewService viewSerivce;
 25  
 
 26  
   @Autowired
 27  
   private ReleaseService releaseService;
 28  
 
 29  
   @Autowired
 30  
   private ConfigService configService;
 31  
 
 32  
   @RequestMapping("/release/{releaseId}")
 33  
   public ReleaseDTO get(@PathVariable("releaseId") long releaseId) {
 34  0
     Release release = releaseService.findOne(releaseId);
 35  0
     if (release == null)
 36  0
       throw new NotFoundException(String.format("release not found for %s", releaseId));
 37  0
     return BeanUtils.transfrom(ReleaseDTO.class, release);
 38  
   }
 39  
 
 40  
   @RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases")
 41  
   public List<ReleaseDTO> find(@PathVariable("appId") String appId,
 42  
       @PathVariable("clusterName") String clusterName,
 43  
       @PathVariable("namespaceName") String namespaceName) {
 44  0
     List<Release> releases = viewSerivce.findReleases(appId, clusterName, namespaceName);
 45  0
     return BeanUtils.batchTransform(ReleaseDTO.class, releases);
 46  
   }
 47  
 
 48  
   @RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest")
 49  
   public ReleaseDTO getLatest(@PathVariable("appId") String appId,
 50  
                               @PathVariable("clusterName") String clusterName,
 51  
                               @PathVariable("namespaceName") String namespaceName) {
 52  0
     Release release = configService.findRelease(appId, clusterName, namespaceName);
 53  0
     if (release == null) {
 54  0
       throw new NotFoundException(
 55  0
           String.format("latest release not found for %s %s %s", appId, clusterName, namespaceName));
 56  
     } else {
 57  0
       return BeanUtils.transfrom(ReleaseDTO.class, release);
 58  
     }
 59  
   }
 60  
 
 61  
   @RequestMapping(path = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases", method = RequestMethod.POST)
 62  
   public ReleaseDTO buildRelease(@PathVariable("appId") String appId,
 63  
       @PathVariable("clusterName") String clusterName,
 64  
       @PathVariable("namespaceName") String namespaceName, @RequestParam("name") String name,
 65  
       @RequestParam(name = "comment", required = false) String comment) {
 66  1
     Release release = releaseService.buildRelease(name, comment, appId, clusterName, namespaceName);
 67  1
     return BeanUtils.transfrom(ReleaseDTO.class, release);
 68  
   }
 69  
 }