View Javadoc

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