1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.crmclient.service.processor;
35
36 import fr.paris.lutece.plugins.crmclient.business.ICRMItem;
37 import fr.paris.lutece.plugins.crmclient.service.authenticator.AuthenticatorService;
38 import fr.paris.lutece.plugins.crmclient.util.CRMException;
39 import fr.paris.lutece.plugins.crmclient.util.http.HttpMethodEnum;
40 import fr.paris.lutece.plugins.crmclient.util.http.IWebServiceCaller;
41 import fr.paris.lutece.util.url.UrlItem;
42
43 import org.springframework.beans.factory.InitializingBean;
44
45 import org.springframework.util.Assert;
46
47 import java.util.ArrayList;
48 import java.util.List;
49 import java.util.Map.Entry;
50
51 import javax.inject.Inject;
52 import javax.inject.Named;
53
54
55
56
57
58
59 public class CRMClientWSProcessor implements ICRMClientProcessor, InitializingBean
60 {
61 private List<String> _listSignatureElements;
62 @Inject
63 @Named( "crmclient.webServiceCaller" )
64 private IWebServiceCaller _webServiceCaller;
65 @Inject
66 @Named( "crmclient.requestAuthenticatorService" )
67 private AuthenticatorService _authenticatorService;
68
69
70
71
72 @Override
73 public String doProcess( ICRMItem crmItem ) throws CRMException
74 {
75
76 List<String> listElements = buildListElements( crmItem );
77
78 return _webServiceCaller.callWebService( crmItem.getUrlForWS( ), crmItem.getParameters( ),
79 _authenticatorService.getRequestAuthenticatorForWs( crmItem.getCRMWebAppCode( ) ), listElements, HttpMethodEnum.POST );
80 }
81
82
83
84
85 @Override
86 public String getProcess( ICRMItem crmItem ) throws CRMException
87 {
88
89 List<String> listElements = buildListElements( crmItem );
90 UrlItem url = new UrlItem( crmItem.getUrlForWS( ) );
91
92 for ( Entry<String, String> parameter : crmItem.getParameters( ).entrySet( ) )
93 {
94 url.addParameter( parameter.getKey( ), parameter.getValue( ) );
95 }
96
97 return _webServiceCaller.callWebService( url.getUrl( ), crmItem.getParameters( ),
98 _authenticatorService.getRequestAuthenticatorForWs( crmItem.getCRMWebAppCode( ) ), listElements, HttpMethodEnum.GET );
99 }
100
101
102
103
104 @Override
105 public void afterPropertiesSet( ) throws Exception
106 {
107 Assert.notNull( _webServiceCaller, "The WebService Caller must be set." );
108 Assert.notNull( _listSignatureElements, "The list of signature elements must be set." );
109 }
110
111
112
113
114
115
116
117 public void setSignatureElements( List<String> listSignatureElements )
118 {
119 _listSignatureElements = listSignatureElements;
120 }
121
122
123
124
125
126
127
128 public void setWebServiceCaller( IWebServiceCaller webServiceCaller )
129 {
130 _webServiceCaller = webServiceCaller;
131 }
132
133
134
135
136
137
138
139
140 private List<String> buildListElements( ICRMItem crmItem )
141 {
142 List<String> listElements = new ArrayList<String>( );
143
144 for ( String signatureElement : _listSignatureElements )
145 {
146 if ( crmItem.getParameters( ).containsKey( signatureElement ) )
147 {
148 listElements.add( crmItem.getParameters( ).get( signatureElement ) );
149 }
150 }
151
152 return listElements;
153 }
154 }