View Javadoc
1   package fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.service;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import org.apache.commons.lang.StringUtils;
7   
8   import fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.business.FastDeployApplicationData;
9   import fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.util.ConstanteUtils;
10  import fr.paris.lutece.portal.service.spring.SpringContextService;
11  
12  public class DeploymentFactory
13  {
14      
15     private static final  String BEAN_ACTION_SERVICE="appcenter-fastdeployapplication.ActionService";
16     private static final  String BEAN_SERVER_APPLICATION_SERVICE="appcenter-fastdeployapplication.ServerApplicationService";
17     private static final  String BEAN_ENVIRONMENT_SERVICE="appcenter-fastdeployapplication.EnvironmentService";
18     private static final  String BEAN_DATABASE_SERVICE="appcenter-fastdeployapplication.DatabaseService";
19     private static final  String BEAN_FTP_SERVICE="appcenter-fastdeployapplication.FtpService";
20        
21      
22     
23      private static Map<String,IActionService> _mapActionService;
24      private static Map<String,IFastDeployEnvironmentService> _mapEnvironmentService;
25      private static Map<String,IServerApplicationService> _mapServerApplicationService;
26      private static Map<String,IDatabaseService> _mapDatabaseService;
27      private static Map<String,IFtpService> _mapFtpService;
28      
29      
30      
31      private static DeploymentFactory _instance;
32      
33      public IServerApplicationService getServerApplicationService(String strApplicationType)
34      {
35          
36          IServerApplicationService serverApplicationService=null;
37          if(!StringUtils.isEmpty( strApplicationType ))
38          {
39              serverApplicationService= _mapServerApplicationService.get( strApplicationType );
40              
41          }
42          
43          if( serverApplicationService == null)
44          {
45              
46              serverApplicationService= _mapServerApplicationService.get( FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR );
47              
48          }
49          
50          return serverApplicationService;
51      }
52      
53      public IFastDeployEnvironmentService getEnvironmentService(String strApplicationType)
54      {
55          
56          IFastDeployEnvironmentService environmentService=null;
57          if(!StringUtils.isEmpty( strApplicationType ))
58          {
59              environmentService= _mapEnvironmentService.get( strApplicationType );
60              
61          }
62          
63          if( environmentService == null)
64          {
65              
66              environmentService= _mapEnvironmentService.get( FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR );
67              
68          }
69          
70          return environmentService;
71          
72      }
73      
74      
75      public IActionService getActionService(String strApplicationType)
76      {
77          
78          IActionService actionService=null;
79          if(!StringUtils.isEmpty( strApplicationType ))
80          {
81              actionService= _mapActionService.get( strApplicationType );
82              
83          }
84          
85          if( actionService == null)
86          {
87              
88              actionService= _mapActionService.get( FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR );
89              
90          }
91          
92          return actionService;
93          
94      }
95      
96      public IDatabaseService  getDatabaseService(String strApplicationType)
97      {
98          
99          IDatabaseService databaseService=null;
100         if(!StringUtils.isEmpty( strApplicationType ))
101         {
102             databaseService= _mapDatabaseService.get( strApplicationType );
103             
104         }
105         
106         if( databaseService == null)
107         {
108             
109             databaseService= _mapDatabaseService.get( FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR );
110             
111         }
112         
113         return databaseService;
114     }
115     
116     public IFtpService  getFtpService(String strApplicationType)
117     {
118         
119         IFtpService ftpServiceService=null;
120         if(!StringUtils.isEmpty( strApplicationType ))
121         {
122             ftpServiceService= _mapFtpService.get( strApplicationType );
123             
124         }
125         
126         if( ftpServiceService == null)
127         {
128             
129             ftpServiceService= _mapFtpService.get( FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR );
130             
131         }
132         
133         return ftpServiceService;
134     }
135     
136    
137     
138     public static DeploymentFactory getInstance()
139     {
140         
141         if(_instance==null)
142         {
143            _instance= new DeploymentFactory( );
144             _instance.initServices( );
145         }
146        
147         return _instance;
148     }
149     
150     
151     private  void initServices()
152     {
153         //init action Service
154         _mapActionService=new HashMap<>();
155          IActionService actionService=SpringContextService.getBean( BEAN_ACTION_SERVICE+"."+FastDeployApplicationData.APPLICATION_TYPE_ANSIBLE);
156         actionService.initService( );
157         _mapActionService.put( FastDeployApplicationData.APPLICATION_TYPE_ANSIBLE, actionService );
158         actionService=SpringContextService.getBean( BEAN_ACTION_SERVICE+"."+FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR);
159         actionService.initService( );
160         _mapActionService.put( FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR, actionService );
161         
162         //init environment Service
163         _mapEnvironmentService=new HashMap<>( );
164          IFastDeployEnvironmentService environmentService=SpringContextService.getBean( BEAN_ENVIRONMENT_SERVICE+"."+FastDeployApplicationData.APPLICATION_TYPE_ANSIBLE);
165          environmentService.initService( );
166         _mapEnvironmentService.put( FastDeployApplicationData.APPLICATION_TYPE_ANSIBLE, environmentService );
167           environmentService=SpringContextService.getBean( BEAN_ENVIRONMENT_SERVICE+"."+FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR);
168           environmentService.initService( );
169          _mapEnvironmentService.put( FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR, environmentService );
170          
171          //init Server Application Service
172         _mapServerApplicationService=new HashMap<>( );
173         IServerApplicationService serverApplicationService=SpringContextService.getBean( BEAN_SERVER_APPLICATION_SERVICE+"."+FastDeployApplicationData.APPLICATION_TYPE_ANSIBLE);
174         serverApplicationService.initService( );
175         _mapServerApplicationService.put( FastDeployApplicationData.APPLICATION_TYPE_ANSIBLE, serverApplicationService );
176         serverApplicationService=SpringContextService.getBean( BEAN_SERVER_APPLICATION_SERVICE+"."+FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR);
177         serverApplicationService.initService( );
178         _mapServerApplicationService.put( FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR, serverApplicationService );
179    
180       //init Ftp Service
181         _mapFtpService=new HashMap<>( );
182         IFtpService ftpService=SpringContextService.getBean( BEAN_FTP_SERVICE+"."+FastDeployApplicationData.APPLICATION_TYPE_ANSIBLE);
183         _mapFtpService.put( FastDeployApplicationData.APPLICATION_TYPE_ANSIBLE, ftpService );
184         ftpService=SpringContextService.getBean( BEAN_FTP_SERVICE+"."+FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR);
185         _mapFtpService.put( FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR, ftpService );
186     
187        //init Database Service
188         _mapDatabaseService=new HashMap<>( );
189         IDatabaseService databaseService=SpringContextService.getBean( BEAN_DATABASE_SERVICE+"."+FastDeployApplicationData.APPLICATION_TYPE_ANSIBLE);
190         _mapDatabaseService.put( FastDeployApplicationData.APPLICATION_TYPE_ANSIBLE, databaseService );
191         databaseService=SpringContextService.getBean( BEAN_DATABASE_SERVICE+"."+FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR);
192         _mapDatabaseService.put( FastDeployApplicationData.APPLICATION_TYPE_CLOUDMGR, databaseService );
193    
194           
195     }
196     
197     
198 
199 }