View Javadoc
1   package fr.paris.lutece.plugins.crm.modules.form.service;
2   
3   import java.util.HashMap;
4   import java.util.List;
5   
6   import javax.servlet.http.HttpServletRequest;
7   
8   import org.apache.commons.lang.StringUtils;
9   
10  import fr.paris.lutece.plugins.crm.modules.form.business.CRMLocalParameters;
11  import fr.paris.lutece.plugins.crm.modules.form.util.Constants;
12  import fr.paris.lutece.plugins.form.business.Form;
13  import fr.paris.lutece.portal.service.spring.SpringContextService;
14  import fr.paris.lutece.portal.service.util.AppPropertiesService;
15  
16  /**
17   * 
18   * CRMParametersService
19   *
20   */
21  public class CRMParametersService implements ICRMParametersService {
22  
23  	//The MAP containing associations between form and crm parameters
24  	private HashMap<String , CRMLocalParameters> _mapLocalParameters;
25  	private static final String CRM_ENABLED_LOCAL_CRM_PARAMETERS="crm-form.enabledLocalCrmParameters";
26  	private boolean _bEnabledLocalCrmParameters ;
27  		
28  	
29  	/**
30       * {@inheritDoc}
31       */
32      @Override
33  	public  String getIdTypeDemande(HttpServletRequest request, Form form )
34  	{
35  		
36      	String strIdTypeDemande=null;
37  		
38  		if(!isEnabledLocalCrmParameters())
39  		{
40  			strIdTypeDemande =request.getParameter( Constants.PARAM_ID_DEMAND_TYPE );
41  			
42  		}
43  		else if ( form !=null && _mapLocalParameters.containsKey(Integer.toString(form.getIdForm())))
44  		{
45  			CRMLocalParameters crmLocalParameters=_mapLocalParameters.get(Integer.toString(form.getIdForm()));
46  			strIdTypeDemande=crmLocalParameters.getIdDemandeType();
47  		}
48  		
49  		
50  		return strIdTypeDemande;
51  		
52  	}
53  	
54      /**
55       * {@inheritDoc}
56       */
57      @Override
58  	public String  getCrmWebAppCode(HttpServletRequest request, Form form )
59  	
60  	{
61      	
62  		String strCrmWebAppCode=null;
63  		if(!isEnabledLocalCrmParameters())
64  		{
65  			strCrmWebAppCode=  request.getParameter( Constants.PARAM_CRM_WEBB_APP_CODE );
66  			
67  		}
68  		else if ( form !=null && _mapLocalParameters.containsKey(Integer.toString(form.getIdForm())))
69  		{
70  			CRMLocalParameters crmLocalParameters=_mapLocalParameters.get(Integer.toString(form.getIdForm()));
71  			
72  			strCrmWebAppCode=crmLocalParameters.getCRMWebAppCode();
73  		}
74  		return strCrmWebAppCode;
75  		
76  	}
77  	
78  	
79  	
80      /**
81       * {@inheritDoc}
82       */
83      @Override
84  	public boolean isEnabledLocalCrmParameters()
85  	{
86  		
87  		
88  		return _bEnabledLocalCrmParameters;
89  		
90  	}
91  	
92      /**
93       * {@inheritDoc}
94       */
95      @Override
96      public void  init()
97  	 {
98      	_bEnabledLocalCrmParameters=AppPropertiesService.getPropertyBoolean(CRM_ENABLED_LOCAL_CRM_PARAMETERS, false);
99  		 _mapLocalParameters=new HashMap<String, CRMLocalParameters>( );
100 		 List<CRMLocalParameters> listLocalParameters = SpringContextService.getBeansOfType( CRMLocalParameters.class );
101 		 for(CRMLocalParameters crmLocalParameters:listLocalParameters)
102 		 {
103 			 if( crmLocalParameters !=null && !StringUtils.isEmpty(crmLocalParameters.getIdForm() )  )
104 			 {
105 				 _mapLocalParameters.put( crmLocalParameters.getIdForm(), crmLocalParameters);
106 			 }
107 		 }
108 	}
109 	 
110 }