View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.workflow.modules.eudonetrestdirectory.web;
35  
36  import fr.paris.lutece.plugins.directory.business.DirectoryHome;
37  import fr.paris.lutece.plugins.directory.business.EntryFilter;
38  import fr.paris.lutece.plugins.directory.business.IEntry;
39  import fr.paris.lutece.plugins.directory.service.DirectoryPlugin;
40  import fr.paris.lutece.plugins.directory.utils.DirectoryUtils;
41  import fr.paris.lutece.plugins.workflow.modules.eudonetrestdirectory.business.EudonetRestData;
42  import fr.paris.lutece.plugins.workflow.modules.eudonetrestdirectory.business.ReferenceItemSorted;
43  import fr.paris.lutece.plugins.workflow.modules.eudonetrestdirectory.business.TaskEudonetRestConfig;
44  import fr.paris.lutece.plugins.workflow.modules.eudonetrestdirectory.business.TaskEudonetRestConfigHome;
45  import fr.paris.lutece.plugins.workflow.modules.eudonetrestdirectory.service.EudonetClient;
46  import fr.paris.lutece.plugins.workflow.modules.eudonetrestdirectory.utils.EudonetRestDirctoryConstants;
47  import fr.paris.lutece.plugins.workflow.utils.WorkflowUtils;
48  import fr.paris.lutece.plugins.workflow.web.task.NoFormTaskComponent;
49  import fr.paris.lutece.plugins.workflowcore.service.config.ITaskConfigService;
50  import fr.paris.lutece.plugins.workflowcore.service.task.ITask;
51  import fr.paris.lutece.portal.service.admin.AdminUserService;
52  import fr.paris.lutece.portal.service.i18n.I18nService;
53  import fr.paris.lutece.portal.service.plugin.Plugin;
54  import fr.paris.lutece.portal.service.plugin.PluginService;
55  import fr.paris.lutece.portal.service.template.AppTemplateService;
56  import fr.paris.lutece.portal.service.util.AppLogService;
57  import fr.paris.lutece.util.ReferenceItem;
58  import fr.paris.lutece.util.ReferenceList;
59  import fr.paris.lutece.util.html.HtmlTemplate;
60  import net.sf.json.JSONArray;
61  import net.sf.json.JSONObject;
62  
63  import org.apache.commons.lang.StringUtils;
64  
65  import com.sun.jersey.api.client.ClientResponse;
66  
67  import java.util.ArrayList;
68  import java.util.Collections;
69  import java.util.HashMap;
70  import java.util.List;
71  import java.util.Locale;
72  import java.util.Map;
73  
74  import javax.inject.Inject;
75  import javax.inject.Named;
76  import javax.servlet.http.HttpServletRequest;
77  
78  /**
79   *
80   * EudonetTaskComponent
81   *
82   */
83  public class EudonetRestTaskComponent extends NoFormTaskComponent
84  {
85      // MARKS
86      private static final String MARKER_TASK_EUDONET_CONFIG = "taskConfig";
87      private static final String MARKER_LIST_ATTRIBUT_EUDONET = "list_attribut";
88      private static final String MARKER_LIST_TABLE_EUDONET = "list_tableEudonet";
89      private static final String MARKER_LIST_TABLE_EUDONET_LINK = "list_tableEudonet_link";
90      private static final String MARKER_ENTRY = "entries";
91  
92      // TEMPLATES
93      private static final String TEMPLATE_TASK_EUDONET = "admin/plugins/workflow/modules/eudonetrestdirectory/task_export_eudonet_config.html";
94  
95      // PARAMETERS
96      public static final String PARAMETER_ID_DIRECTORE = "id_directory";
97      public static final String PARAMETER_ID_TELESERVICE = "id_teleservice";
98      public static final String PARAMETER_ID_TABLE_EUDONET = "id_tableEudonet";
99      public static final String PARAMETER_ID_TABLE_EUDONET_LINK = "id_tableEudonet_link";
100     public static final String PARAMETER_ENTRY_DEFAULT_VALUE = "entry_default_value";
101     public static final String PARAMETER_BASE_URL = "base_url";
102     public static final String PARAMETER_SUBSCRIBER_LOGIN = "subscriber_login";
103     public static final String PARAMETER_SUBSCRIBER_PASSWORD = "subscriber_password";
104     public static final String PARAMETER_BASE_NAME = "base_name";
105     public static final String PARAMETER_USER_LOGIN = "user_login";
106     public static final String PARAMETER_USER_PASSWORD = "user_password";
107     public static final String PARAMETER_USER_LANG = "user_lang";
108     public static final String PARAMETER_PRODUCT_NAME = "product_name";
109     public static final String PARAMETER_CREAT_ENTRY = "apply";
110     public static final String PARAMETER_DELETE_ENTRY = "deleteEntry";
111     public static final String PARAMETER_CREATE_ENTRY = "createEntry";
112     public static final String PARAMETER_ORDER_ENTRY = "order_entry";
113     public static final String PARAMETER_EUDONET_ATTRIBUT = "eudonet_attribut";
114     public static final String PARAMETER_EUDONET_TABLE = "eudonet_table";
115     public static final String PARAMETER_ID_ENTRY = "id_entry";
116 
117     // Constants
118     private static final String CONSTANT_ENTRY_DATE_CREATION = "-2";
119     private static final String CONSTANT_ENTRY_DATE_MODIFICATION = "-3";
120 
121     public static final String CONSTANT_I18_LABEL_ENTRY_DATE_CREATION = "module.workflow.eudonetrestdirectory.task_eudonet_config.label.creation_date";
122     public static final String CONSTANT_I18_LABEL_ENTRY_DATE_MODIFICATION = "module.workflow.eudonetrestdirectory.task_eudonet_config.label.modification_date";
123 
124     // SERVICES
125     @Inject
126     @Named( EudonetRestDirctoryConstants.BEAN_EUDONET_DIRECTORY_CONFIG_SERVICE )
127     private ITaskConfigService _taskEudonetConfigService;
128 
129     private EudonetClient _client;
130     private TaskEudonetRestConfig _config;
131 
132     /**
133      * {@inheritDoc}
134      */
135     @Override
136     public String doSaveConfig( HttpServletRequest request, Locale locale, ITask task )
137     {
138         String idDirectory = request.getParameter( PARAMETER_ID_DIRECTORE );
139         String idTableEudonet = request.getParameter( PARAMETER_ID_TABLE_EUDONET ) == null ? "-1" : request.getParameter( PARAMETER_ID_TABLE_EUDONET );
140         String baseUrl = request.getParameter( PARAMETER_BASE_URL );
141         String subscriberLogin = request.getParameter( PARAMETER_SUBSCRIBER_LOGIN );
142         String subscriberPassword = request.getParameter( PARAMETER_SUBSCRIBER_PASSWORD );
143         String baseName = request.getParameter( PARAMETER_BASE_NAME );
144         String userLogin = request.getParameter( PARAMETER_USER_LOGIN );
145         String userPassword = request.getParameter( PARAMETER_USER_PASSWORD );
146         String userLang = request.getParameter( PARAMETER_USER_LANG );
147         String productName = request.getParameter( PARAMETER_PRODUCT_NAME );
148 
149         _config = _taskEudonetConfigService.findByPrimaryKey( task.getId( ) );
150         Boolean bCreate = false;
151 
152         if ( _config == null )
153         {
154             _config = new TaskEudonetRestConfig( );
155             _config.setIdTask( task.getId( ) );
156             bCreate = true;
157         }
158 
159         if ( ( ( request.getParameter( PARAMETER_CREAT_ENTRY ) != null ) && PARAMETER_CREATE_ENTRY.equals( request.getParameter( PARAMETER_CREAT_ENTRY ) ) )
160                 && ( Integer.parseInt( idDirectory ) != WorkflowUtils.CONSTANT_ID_NULL ) )
161         {
162             String ordreEntry = request.getParameter( PARAMETER_ORDER_ENTRY ).equals( "" ) ? "-1" : request.getParameter( PARAMETER_ORDER_ENTRY );
163             String eudonetAttribut = request.getParameter( PARAMETER_EUDONET_ATTRIBUT );
164             String eudonetTable = request.getParameter( PARAMETER_ID_TABLE_EUDONET );
165             String eudonetTableLink = request.getParameter( PARAMETER_ID_TABLE_EUDONET_LINK );
166             String eudonetEntryDefaulValue = request.getParameter( PARAMETER_ENTRY_DEFAULT_VALUE );
167 
168             EudonetRestData data = new EudonetRestData( );
169             data.setIdConfig( task.getId( ) );
170 
171             if ( eudonetEntryDefaulValue != null && !eudonetEntryDefaulValue.isEmpty( ) )
172             {
173                 data.setDefaultValue( eudonetEntryDefaulValue );
174             }
175             else
176             {
177                 data.setOrderEntry( Integer.parseInt( ordreEntry ) );
178             }
179 
180             data.setIdTable( eudonetTable );
181             data.setIdAttribut( eudonetAttribut );
182             data.setIdTableLink( eudonetTableLink );
183 
184             TaskEudonetRestConfigHome.creatEntry( data );
185 
186             return null;
187         }
188         else
189             if ( ( request.getParameter( PARAMETER_ID_ENTRY ) != null ) && ( request.getParameter( PARAMETER_CREAT_ENTRY ) != null )
190                     && PARAMETER_DELETE_ENTRY.equals( request.getParameter( PARAMETER_CREAT_ENTRY ) )
191                     && ( Integer.parseInt( idDirectory ) != WorkflowUtils.CONSTANT_ID_NULL ) )
192             {
193                 String idEntry = request.getParameter( PARAMETER_ID_ENTRY );
194                 TaskEudonetRestConfigHome.deleteEntry( Integer.parseInt( idEntry ) );
195 
196                 return null;
197             }
198 
199         _config.setIdDirectory( Integer.parseInt( idDirectory ) );
200         _config.setIdTableEudonet( idTableEudonet );
201         _config.setBaseUrl( baseUrl );
202         _config.setSubscriberLogin( subscriberLogin );
203         _config.setSubscriberPassword( subscriberPassword );
204         _config.setBaseName( baseName );
205         _config.setUserLogin( userLogin );
206         _config.setUserPassword( userPassword );
207         _config.setUserLang( userLang );
208         _config.setProductName( productName );
209 
210         if ( _client == null )
211         {
212             _client = new EudonetClient( _config.getBaseUrl( ) );
213         }
214 
215         if ( bCreate )
216         {
217             _taskEudonetConfigService.create( _config );
218         }
219         else
220         {
221             _taskEudonetConfigService.update( _config );
222         }
223 
224         return null;
225     }
226 
227     /**
228      * {@inheritDoc}
229      */
230     @Override
231     public String getDisplayConfigForm( HttpServletRequest request, Locale locale, ITask task )
232     {
233         Map<String, Object> model = new HashMap<String, Object>( );
234         String strIdTask = request.getParameter( EudonetRestDirctoryConstants.PARAMETER_ID_TASK );
235 
236         int nIdDirectory;
237 
238         if ( StringUtils.isNotBlank( request.getParameter( EudonetRestDirctoryConstants.PARAMETER_ID_DIRECTORY ) ) )
239         {
240             nIdDirectory = DirectoryUtils.convertStringToInt( request.getParameter( EudonetRestDirctoryConstants.PARAMETER_ID_DIRECTORY ) );
241         }
242         else
243         {
244             nIdDirectory = -1;
245         }
246 
247         if ( StringUtils.isNotBlank( strIdTask ) )
248         {
249             _config = _taskEudonetConfigService.findByPrimaryKey( DirectoryUtils.convertStringToInt( strIdTask ) );
250 
251             if ( _config != null )
252             {
253                 model.put( MARKER_TASK_EUDONET_CONFIG, _config );
254 
255                 List<EudonetRestData> entries = (List<EudonetRestData>) _config.getEntry( );
256 
257                 model.put( MARKER_ENTRY, entries );
258                 nIdDirectory = _config.getIdDirectory( );
259             }
260             else
261             {
262                 model.put( MARKER_TASK_EUDONET_CONFIG, new TaskEudonetRestConfig( ) );
263             }
264         }
265 
266         // ReferenceList tableList = getEudonetTables( );
267 
268         // ReferenceList attributList = getEudonetAttribut( );
269 
270         model.put( EudonetRestDirctoryConstants.MARK_DIRECTORY_LIST, getListDirectories( ) );
271         model.put( EudonetRestDirctoryConstants.MARK_LIST_ENTRIES, getListEntries( nIdDirectory, request ) );
272         model.put( MARKER_LIST_TABLE_EUDONET, getEudonetTables( ) );
273         model.put( MARKER_LIST_TABLE_EUDONET_LINK, getEudonetTables( ) );
274         model.put( MARKER_LIST_ATTRIBUT_EUDONET, getEudonetAttribut( ) );
275 
276         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_TASK_EUDONET, locale, model );
277 
278         return template.getHtml( );
279     }
280 
281     /**
282      * {@inheritDoc}
283      */
284     @Override
285     public String getDisplayTaskInformation( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
286     {
287         return null;
288     }
289 
290     /**
291      * {@inheritDoc}
292      */
293     @Override
294     public String getTaskInformationXml( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
295     {
296         return null;
297     }
298 
299     /**
300      * Get the list of directorise
301      * 
302      * @return a ReferenceList
303      */
304     private static ReferenceList getListDirectories( )
305     {
306         Plugin pluginDirectory = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
307         ReferenceList listDirectories = DirectoryHome.getDirectoryList( pluginDirectory );
308         ReferenceList refenreceListDirectories = new ReferenceList( );
309         refenreceListDirectories.addItem( DirectoryUtils.CONSTANT_ID_NULL, StringUtils.EMPTY );
310 
311         if ( listDirectories != null )
312         {
313             refenreceListDirectories.addAll( listDirectories );
314         }
315 
316         return refenreceListDirectories;
317     }
318 
319     /**
320      * Method to get eudonet attributs list
321      * 
322      * @return tables list
323      */
324     private List<ReferenceItemSorted> getEudonetTables( )
325     {
326         ReferenceList tableList = new ReferenceList( );
327 
328         List<ReferenceItemSorted> referenceList = new ArrayList<ReferenceItemSorted>( );
329 
330         ReferenceItemSorted referenceItemSorted = new ReferenceItemSorted( );
331         referenceItemSorted.setCode( "" );
332         referenceItemSorted.setName( "" );
333         referenceList.add( referenceItemSorted );
334 
335         if ( _config != null )
336         {
337             if ( _client == null )
338             {
339                 _client = new EudonetClient( _config.getBaseUrl( ) );
340             }
341 
342             String strToken = token( );
343             JSONArray tableListJson = getTableListJson( strToken );
344             tableList = getTableList( tableListJson );
345 
346             for ( ReferenceItem item : tableList )
347             {
348                 ReferenceItemSorted referenceItem = new ReferenceItemSorted( );
349                 referenceItem.setCode( item.getCode( ) + "-" + item.getName( ) );
350                 referenceItem.setName( item.getName( ) );
351                 referenceList.add( referenceItem );
352             }
353         }
354 
355         Collections.sort( referenceList );
356 
357         return referenceList;
358     }
359 
360     /**
361      * Method to get eudonet tables list
362      * 
363      * @return attributs list
364      */
365     private List<ReferenceItemSorted> getEudonetAttribut( )
366     {
367         List<ReferenceItemSorted> referenceList = new ArrayList<ReferenceItemSorted>( );
368 
369         ReferenceItemSorted referenceItemSorted = new ReferenceItemSorted( );
370         referenceItemSorted.setCode( "" );
371         referenceItemSorted.setName( "" );
372         referenceList.add( referenceItemSorted );
373 
374         ReferenceList attributList = new ReferenceList( );
375 
376         if ( _config != null )
377         {
378             if ( _client == null )
379             {
380                 _client = new EudonetClient( _config.getBaseUrl( ) );
381             }
382 
383             String strToken = token( );
384 
385             String strIdTableEudonet = _config.getIdTableEudonet( ).split( "-" ) [0];
386 
387             JSONArray attributListJson = getAttributListJson( strToken, strIdTableEudonet );
388 
389             attributList = getAttributList( attributListJson );
390 
391             for ( ReferenceItem item : attributList )
392             {
393                 boolean isContain = false;
394 
395                 for ( EudonetRestData ent : _config.getEntry( ) )
396                 {
397                     String strIdattEudonet = item.getCode( ) + "-" + item.getName( );
398                     if ( strIdattEudonet.equals( ent.getIdAttribut( ) ) )
399                     {
400                         isContain = true;
401 
402                         break;
403                     }
404                 }
405 
406                 if ( !isContain )
407                 {
408                     ReferenceItemSorted referenceItem = new ReferenceItemSorted( );
409                     referenceItem.setCode( item.getCode( ) + "-" + item.getName( ) );
410                     referenceItem.setName( item.getName( ) );
411                     referenceList.add( referenceItem );
412                 }
413             }
414         }
415 
416         Collections.sort( referenceList );
417 
418         return referenceList;
419     }
420 
421     /**
422      * Method to get directory entries list
423      * 
424      * @param nIdDirectory
425      *            id directory
426      * @param request
427      *            request
428      * @return ReferenceList entries list
429      */
430     private static List<ReferenceItemSorted> getListEntries( int nIdDirectory, HttpServletRequest request )
431     {
432         if ( nIdDirectory != -1 )
433         {
434             Plugin pluginDirectory = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
435             List<IEntry> listEntries = DirectoryUtils.getFormEntries( nIdDirectory, pluginDirectory, AdminUserService.getAdminUser( request ) );
436             List<ReferenceItemSorted> referenceList = new ArrayList<ReferenceItemSorted>( );
437 
438             ReferenceItemSorted referenceItemSorted = new ReferenceItemSorted( );
439             referenceItemSorted.setCode( "" );
440             referenceItemSorted.setName( "" );
441             referenceList.add( referenceItemSorted );
442 
443             ReferenceItemSorted referenceItemSortedCD = new ReferenceItemSorted( );
444             referenceItemSortedCD.setCode( CONSTANT_ENTRY_DATE_CREATION );
445             referenceItemSortedCD.setName( I18nService.getLocalizedString( CONSTANT_I18_LABEL_ENTRY_DATE_CREATION, request.getLocale( ) ) );
446             referenceList.add( referenceItemSortedCD );
447 
448             ReferenceItemSorted referenceItemSortedMD = new ReferenceItemSorted( );
449             referenceItemSortedMD.setCode( CONSTANT_ENTRY_DATE_MODIFICATION );
450             referenceItemSortedMD.setName( I18nService.getLocalizedString( CONSTANT_I18_LABEL_ENTRY_DATE_MODIFICATION, request.getLocale( ) ) );
451             referenceList.add( referenceItemSortedMD );
452 
453             for ( IEntry entry : listEntries )
454             {
455                 if ( entry.getEntryType( ).getComment( ) )
456                 {
457                     continue;
458                 }
459 
460                 if ( entry.getEntryType( ).getGroup( ) )
461                 {
462                     if ( entry.getChildren( ) != null )
463                     {
464                         for ( IEntry child : entry.getChildren( ) )
465                         {
466                             if ( child.getEntryType( ).getComment( ) )
467                             {
468                                 continue;
469                             }
470 
471                             ReferenceItemSorted referenceItem = new ReferenceItemSorted( );
472                             referenceItem.setCode( String.valueOf( child.getIdEntry( ) ) );
473                             referenceItem.setName( child.getTitle( ) );
474                             referenceList.add( referenceItem );
475                         }
476                     }
477                 }
478                 else
479                 {
480                     ReferenceItemSorted referenceItem = new ReferenceItemSorted( );
481                     referenceItem.setCode( String.valueOf( entry.getIdEntry( ) ) );
482                     referenceItem.setName( entry.getTitle( ) );
483                     referenceList.add( referenceItem );
484                 }
485             }
486 
487             Collections.sort( referenceList );
488 
489             return referenceList;
490         }
491         else
492         {
493             return new ArrayList<ReferenceItemSorted>( );
494         }
495     }
496 
497     public String getAuthenticateJsonBody( )
498     {
499         JSONObject jsonObject = new JSONObject( );
500         jsonObject.accumulate( "SubscriberLogin", _config.getSubscriberLogin( ) );
501         jsonObject.accumulate( "SubscriberPassword", _config.getSubscriberPassword( ) );
502         jsonObject.accumulate( "BaseName", _config.getBaseName( ) );
503         jsonObject.accumulate( "UserLogin", _config.getUserLogin( ) );
504         jsonObject.accumulate( "UserPassword", _config.getUserPassword( ) );
505         jsonObject.accumulate( "UserLang", _config.getUserLang( ) );
506         jsonObject.accumulate( "ProductName", _config.getProductName( ) );
507 
508         return jsonObject.toString( );
509     }
510 
511     public String getAttributListJsonBody( String strIdTable )
512     {
513         if ( strIdTable != null )
514         {
515             // int nIdTable = Integer.parseInt(strIdTable);
516             JSONObject jsonObject = new JSONObject( );
517             JSONArray jsonArray = new JSONArray( );
518             JSONObject jsonElement = new JSONObject( );
519             JSONArray jsonElementArray = new JSONArray( );
520 
521             jsonElementArray.add( Integer.parseInt( strIdTable ) );
522 
523             jsonElement.accumulate( "DescId", Integer.parseInt( strIdTable ) );
524             jsonElement.accumulate( "AllFields", true );
525             jsonElement.accumulate( "Fields", jsonElementArray );
526 
527             jsonArray.add( jsonElement );
528 
529             jsonObject.accumulate( "Tables", jsonArray );
530 
531             return jsonObject.toString( );
532         }
533 
534         return null;
535     }
536 
537     public String token( )
538     {
539         String strAuthenticateJson = getAuthenticateJsonBody( );
540         try
541         {
542             ClientResponse response = _client.getTokenAuthenticate( strAuthenticateJson );
543 
544             if ( response.getStatus( ) == 200 )
545             {
546                 String strResponse = response.getEntity( String.class );
547                 JSONObject jsonObject = new JSONObject( );
548                 jsonObject.accumulate( "object", strResponse );
549                 String strStatus = jsonObject.getJSONObject( "object" ).getJSONObject( "ResultInfos" ).getString( "Success" );
550                 if ( strStatus.equals( "true" ) )
551                 {
552                     return jsonObject.getJSONObject( "object" ).getJSONObject( "ResultData" ).getString( "Token" );
553                 }
554                 else
555                 {
556                     String strErrorMessage = jsonObject.getJSONObject( "object" ).getJSONObject( "ResultInfos" ).getString( "ErrorMessage" );
557                     AppLogService.error( "Error Eudonet : " + strErrorMessage );
558                 }
559             }
560         }
561         catch( Exception ex )
562         {
563             AppLogService.error( "Erreur to get a token", ex );
564         }
565 
566         return null;
567 
568     }
569 
570     public JSONArray getTableListJson( String strToken )
571     {
572         if ( strToken != null )
573         {
574             try
575             {
576                 ClientResponse response = _client.getTableListMetaInfos( strToken );
577                 if ( response.getStatus( ) == 200 )
578                 {
579                     String strResponse = response.getEntity( String.class );
580                     JSONObject jsonObject = new JSONObject( );
581                     jsonObject.accumulate( "object", strResponse );
582                     String strStatus = jsonObject.getJSONObject( "object" ).getJSONObject( "ResultInfos" ).getString( "Success" );
583                     if ( strStatus.equals( "true" ) )
584                     {
585                         return jsonObject.getJSONObject( "object" ).getJSONObject( "ResultMetaData" ).getJSONArray( "Tables" );
586                     }
587                     else
588                     {
589                         String strErrorMessage = jsonObject.getJSONObject( "object" ).getJSONObject( "ResultInfos" ).getString( "ErrorMessage" );
590                         AppLogService.error( "Error Eudonet : " + strErrorMessage );
591                     }
592                 }
593 
594             }
595             catch( Exception ex )
596             {
597                 AppLogService.error( "Erreur to generate the table list of eudonet", ex );
598             }
599         }
600 
601         return null;
602     }
603 
604     public JSONArray getAttributListJson( String strToken, String strIdTable )
605     {
606         if ( strToken != null )
607         {
608             try
609             {
610                 String strBody = getAttributListJsonBody( strIdTable );
611                 if ( strBody != null )
612                 {
613                     ClientResponse response = _client.getAttributListMetaInfos( strToken, strBody );
614                     if ( response.getStatus( ) == 200 )
615                     {
616                         String strResponse = response.getEntity( String.class );
617                         JSONObject jsonObject = new JSONObject( );
618                         jsonObject.accumulate( "object", strResponse );
619                         String strStatus = jsonObject.getJSONObject( "object" ).getJSONObject( "ResultInfos" ).getString( "Success" );
620                         if ( strStatus.equals( "true" ) )
621                         {
622                             return jsonObject.getJSONObject( "object" ).getJSONObject( "ResultMetaData" ).getJSONArray( "Tables" ).getJSONObject( 0 )
623                                     .getJSONArray( "Fields" );
624                         }
625                         else
626                         {
627                             String strErrorMessage = jsonObject.getJSONObject( "object" ).getJSONObject( "ResultInfos" ).getString( "ErrorMessage" );
628                             AppLogService.error( "Error Eudonet : " + strErrorMessage );
629                         }
630                     }
631 
632                 }
633             }
634             catch( Exception ex )
635             {
636                 AppLogService.error( "Erreur to generate the attribute list of eudonet", ex );
637             }
638         }
639 
640         return null;
641     }
642 
643     public ReferenceList getTableList( JSONArray jsonArray )
644     {
645         ReferenceList referenceList = new ReferenceList( );
646 
647         if ( jsonArray != null )
648         {
649             for ( int i = 0; i < jsonArray.size( ); i++ )
650             {
651                 ReferenceItem referenceItem = new ReferenceItem( );
652                 referenceItem.setCode( jsonArray.getJSONObject( i ).getString( "Descid" ) );
653                 referenceItem.setName( jsonArray.getJSONObject( i ).getString( "Label" ) );
654                 referenceList.add( referenceItem );
655             }
656         }
657 
658         return referenceList;
659     }
660 
661     public ReferenceList getAttributList( JSONArray jsonArray )
662     {
663         ReferenceList referenceList = new ReferenceList( );
664 
665         if ( jsonArray != null )
666         {
667             for ( int i = 0; i < jsonArray.size( ); i++ )
668             {
669                 ReferenceItem referenceItem = new ReferenceItem( );
670                 referenceItem.setCode( jsonArray.getJSONObject( i ).getString( "DescId" ) );
671                 referenceItem.setName( jsonArray.getJSONObject( i ).getString( "Label" ) );
672                 referenceList.add( referenceItem );
673             }
674         }
675 
676         return referenceList;
677     }
678 }