View Javadoc
1   package fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.service;
2   
3   import java.util.HashMap;
4   import java.util.List;
5   import java.util.Locale;
6   import java.util.stream.Collectors;
7   
8   import fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.business.FastDeployEnvironment;
9   import fr.paris.lutece.portal.service.i18n.I18nService;
10  import fr.paris.lutece.portal.service.spring.SpringContextService;
11  import fr.paris.lutece.util.ReferenceList;
12  
13  public abstract class  AbstractFastDeployEnvironmentService implements IFastDeployEnvironmentService
14  {
15  
16      
17   // private static IEnvironmentService _singleton;
18      private static HashMap<String, FastDeployEnvironment> _hashEnvironements;
19      public static String[] tabEnvIndice= {"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","v","w","x","y","z"};
20    
21  
22      public void initService( )
23      {
24          List<FastDeployEnvironment> listEnvironment = SpringContextService.getBeansOfType( FastDeployEnvironment.class );
25          _hashEnvironements = new HashMap<String, FastDeployEnvironment>( );
26  
27          if ( listEnvironment != null )
28          {
29              for ( FastDeployEnvironment environment : listEnvironment )
30              {
31              	if(environment.getCode().contains("x"))
32              	{
33                    String strCode;
34                    FastDeployEnvironment clone;
35              	  for (int i = 0; i < tabEnvIndice.length; i++) {
36              		clone=(FastDeployEnvironment)environment.clone();  
37              		strCode=clone.getCode().replace("x", tabEnvIndice[i]);  
38              		clone.setCode(strCode);
39              		Object[] params= {tabEnvIndice[i]};
40              		clone.setName(I18nService.getLocalizedString(environment.getI18nKeyName( ),params, Locale.FRENCH));
41              		
42              		_hashEnvironements.put( strCode, clone );
43  				  }
44              	}
45              	else
46              	  {
47              		   environment.setName(I18nService.getLocalizedString(environment.getI18nKeyName( ),Locale.FRENCH));
48              		  _hashEnvironements.put( environment.getCode(), environment );
49              		  
50              	  }
51              	  
52                    
53              	}
54              }
55          }
56      
57  
58      /*
59       * (non-Javadoc)
60       * 
61       * @see fr.paris.lutece.plugins.deployment.service.IEnvironmentService#getEnvironment (java.lang.String)
62       */
63      public FastDeployEnvironment getEnvironment( String strCode, Locale locale )
64      {
65          FastDeployEnvironment environment = _hashEnvironements.get( strCode );
66          return environment;
67      }
68  
69      public ReferenceList getEnvironmentRefList( Locale locale )
70      {
71  
72          ReferenceList refListEnv = new ReferenceList( );
73          
74          for ( FastDeployEnvironment environment : _hashEnvironements.values( ) )
75          {
76              refListEnv.addItem( environment.getCode( ), environment.getName() );
77          }
78          return refListEnv;
79      }
80      @Override
81      public List<FastDeployEnvironment> getListEnvironmentsByType( String strCodeApplication, Locale locale, String strType )
82      {
83          // TODO Auto-generated method stub
84          List<FastDeployEnvironment> listFastDeployEnvironment=getListEnvironments( strCodeApplication, locale );
85          if(listFastDeployEnvironment!=null)
86          {
87              return listFastDeployEnvironment.stream( ).filter( x -> x.getEnvType( ).equals( strType ) ).collect( Collectors.toList( ) );
88              
89          }
90          return null;
91      }
92  
93  }