1 package fr.paris.lutece.plugins.workflow.modules.eudonetrestdirectory.service;
2
3 import javax.ws.rs.core.MediaType;
4
5 import com.sun.jersey.api.client.Client;
6 import com.sun.jersey.api.client.ClientResponse;
7 import com.sun.jersey.api.client.WebResource;
8 import com.sun.jersey.api.client.config.ClientConfig;
9 import com.sun.jersey.api.client.config.DefaultClientConfig;
10 import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
11 import com.sun.jersey.api.json.JSONConfiguration;
12
13 public class EudonetClient
14 {
15 private static Client _client;
16 private static WebResource _webResource;
17 private static EudonetClient _singleton;
18
19 public EudonetClient( String baseUrl )
20 {
21 ClientConfig clientConfig = new DefaultClientConfig( );
22 clientConfig.getFeatures( ).put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE );
23 _client = Client.create( clientConfig );
24
25 _webResource = _client.resource( baseUrl );
26 }
27
28 public static EudonetClient getService( String baseUrl )
29 {
30 if ( _singleton == null )
31 {
32 _singleton = new EudonetClient( baseUrl );
33
34 return _singleton;
35 }
36
37 return _singleton;
38 }
39
40 public EudonetClient( String baseUrl, String userName, String password )
41 {
42 ClientConfig clientConfig = new DefaultClientConfig( );
43 clientConfig.getFeatures( ).put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE );
44 _client = Client.create( clientConfig );
45 _client.addFilter( new HTTPBasicAuthFilter( userName, password ) );
46 _webResource = _client.resource( baseUrl );
47 }
48
49
50
51
52
53
54
55
56 public ClientResponse getTokenAuthenticate( String strAuthenticateJson )
57 {
58 return _webResource.path( "Authenticate" ).path( "Token" ).type( MediaType.APPLICATION_JSON ).accept( MediaType.APPLICATION_JSON )
59 .post( ClientResponse.class, strAuthenticateJson );
60
61 }
62
63
64
65
66
67
68
69
70
71
72 public ClientResponse createRecord( String strAuthenticate, String strIdTable, String strBodyJson )
73 {
74 return _webResource.path( "CUD" ).path( strIdTable ).header( "x-auth", strAuthenticate ).type( MediaType.APPLICATION_JSON )
75 .accept( MediaType.APPLICATION_JSON ).post( ClientResponse.class, strBodyJson );
76 }
77
78
79
80
81
82
83
84
85
86
87
88 public ClientResponse updateRecord( String strAuthenticate, String strIdTable, String strBodyJson, String strIdRecord )
89 {
90 return _webResource.path( "CUD" ).path( strIdTable ).path( strIdRecord ).header( "x-auth", strAuthenticate ).type( MediaType.APPLICATION_JSON )
91 .accept( MediaType.APPLICATION_JSON ).post( ClientResponse.class, strBodyJson );
92 }
93
94
95
96
97
98
99
100
101
102
103 public ClientResponse deleteRecord( String strAuthenticate, String strIdTable, String strIdRecord )
104 {
105 return _webResource.path( "CUD" ).path( "Delete" ).path( strIdTable ).path( strIdRecord ).header( "x-auth", strAuthenticate )
106 .type( MediaType.APPLICATION_JSON ).accept( MediaType.APPLICATION_JSON ).delete( ClientResponse.class );
107 }
108
109
110
111
112
113
114
115
116
117
118 public ClientResponse searchRecordById( String strAuthenticate, String strIdTable, String strIdRecord )
119 {
120 return _webResource.path( "Search" ).path( strIdTable ).path( strIdRecord ).header( "x-auth", strAuthenticate ).type( MediaType.APPLICATION_JSON )
121 .accept( MediaType.APPLICATION_JSON ).get( ClientResponse.class );
122 }
123
124
125
126
127
128
129
130
131
132
133 public ClientResponse searchRecordByCrieria( String strAuthenticate, String strIdTable, String strBodyJson )
134 {
135 return _webResource.path( "Search" ).path( strIdTable ).header( "x-auth", strAuthenticate ).type( MediaType.APPLICATION_JSON )
136 .accept( MediaType.APPLICATION_JSON ).post( ClientResponse.class, strBodyJson );
137 }
138
139
140
141
142
143
144
145
146
147
148 public ClientResponse searchFastRecord( String strAuthenticate, String strIdTable, String strBodyJson )
149 {
150 return _webResource.path( "Search/Fast" ).path( strIdTable ).header( "x-auth", strAuthenticate ).type( MediaType.APPLICATION_JSON )
151 .accept( MediaType.APPLICATION_JSON ).post( ClientResponse.class, strBodyJson );
152 }
153
154
155
156
157
158
159
160
161
162 public ClientResponse addAnnexes( String strAuthenticate, String strBodyJson )
163 {
164 return _webResource.path( "Annexes/Add" ).header( "x-auth", strAuthenticate ).type( MediaType.APPLICATION_JSON ).accept( MediaType.APPLICATION_JSON )
165 .post( ClientResponse.class, strBodyJson );
166 }
167
168
169
170
171
172
173
174
175 public ClientResponse getAttributListMetaInfos( String strAuthenticate, String strBodyJson )
176 {
177 return _webResource.path( "MetaInfos" ).header( "x-auth", strAuthenticate ).type( MediaType.APPLICATION_JSON ).accept( MediaType.APPLICATION_JSON )
178 .post( ClientResponse.class, strBodyJson );
179 }
180
181
182
183
184
185
186
187 public ClientResponse getTableListMetaInfos( String strAuthenticate )
188 {
189 return _webResource.path( "MetaInfos" ).path( "ListTabs/" ).header( "x-auth", strAuthenticate ).type( MediaType.APPLICATION_JSON )
190 .accept( MediaType.APPLICATION_JSON ).get( ClientResponse.class );
191 }
192
193
194
195
196 public static Client getClient( )
197 {
198 return _client;
199 }
200
201
202
203
204 public static WebResource getWebResource( )
205 {
206 return _webResource;
207 }
208
209 }