##### Coverage Report - com.ctrip.framework.apollo.portal.listener.CreationListener

Classes in this File | Line Coverage | Branch Coverage | Complexity
CreationListener |
10% | 2/20
0% | 0/4
| 3.0;3

1 |  |
     package com.ctrip.framework.apollo.portal.listener;
2 |  |
3 |  |
     import com.ctrip.framework.apollo.common.utils.BeanUtils;
4 |  |
     import com.ctrip.framework.apollo.common.utils.ExceptionUtils;
5 |  |
     import com.ctrip.framework.apollo.core.dto.AppDTO;
6 |  |
     import com.ctrip.framework.apollo.core.dto.AppNamespaceDTO;
7 |  |
     import com.ctrip.framework.apollo.core.enums.Env;
8 |  |
     import com.ctrip.framework.apollo.portal.PortalSettings;
9 |  |
     import com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
10 |  |
11 |  |
     import org.slf4j.Logger;
12 |  |
     import org.slf4j.LoggerFactory;
13 |  |
     import org.springframework.beans.factory.annotation.Autowired;
14 |  |
     import org.springframework.context.event.EventListener;
15 |  |
     import org.springframework.stereotype.Component;
16 |  |
     import org.springframework.web.client.HttpStatusCodeException;
17 |  |
18 |  |
     import java.util.List;
19 |  |
20 |  |
     @Component
21 | 1 |
     public class CreationListener {
22 |  |
23 | 1 |
       private static Logger logger = LoggerFactory.getLogger(CreationListener.class);
24 |  |
25 |  |
       @Autowired
26 |  |
       private PortalSettings portalSettings;
27 |  |
       @Autowired
28 |  |
       private AdminServiceAPI.AppAPI appAPI;
29 |  |
       @Autowired
30 |  |
       private AdminServiceAPI.NamespaceAPI namespaceAPI;
31 |  |
32 |  |
       @EventListener
33 |  |
       public void onAppCreationEvent(AppCreationEvent event) {
34 | 0 |
         AppDTO appDTO = BeanUtils.transfrom(AppDTO.class, event.getApp());
35 | 0 |
         List<Env> envs = portalSettings.getActiveEnvs();
36 | 0 |
         for (Env env : envs) {
37 |  |
           try {
38 | 0 |
             appAPI.createApp(env, appDTO);
39 | 0 |
           } catch (HttpStatusCodeException e) {
40 | 0 |
             logger.error("call appAPI.createApp error.[{app}, {env}]", appDTO.getAppId(), env, e);
41 | 0 |
           }
42 | 0 |
         }
43 | 0 |
       }
44 |  |
45 |  |
       @EventListener
46 |  |
       public void onAppNamespaceCreationEvent(AppNamespaceCreationEvent event){
47 | 0 |
         AppNamespaceDTO dto = BeanUtils.transfrom(AppNamespaceDTO.class, event.getAppNamespace());
48 | 0 |
         List<Env> envs = portalSettings.getActiveEnvs();
49 | 0 |
         for (Env env : envs) {
50 |  |
           try {
51 | 0 |
             namespaceAPI.createOrUpdateAppNamespace(env, dto);
52 | 0 |
           } catch (HttpStatusCodeException e) {
53 | 0 |
             logger.error("call namespaceAPI.createOrUpdateAppNamespace error. [{app}, {env}]", dto.getAppId(), env, e);
54 | 0 |
           }
55 | 0 |
         }
56 | 0 |
       }
57 |  |
58 |  |
     }