View Javadoc
1   package fr.paris.lutece.plugins.rtu.service;
2   
3   import fr.paris.lutece.plugins.rtu.business.Entreprise;
4   import fr.paris.lutece.plugins.rtu.business.RetourApiAssociation;
5   import fr.paris.lutece.plugins.rtu.business.RetourApiEntreprise;
6   import fr.paris.lutece.plugins.rtu.business.RetourApiEtablissement;
7   import fr.paris.lutece.portal.service.util.AppLogService;
8   
9   // TODO: Auto-generated Javadoc
10  /**
11   * The Class ApiRTUService.
12   */
13  public class ApiRTUService extends AbstractRestClient<Entreprise>{
14  	
15  	/** The Constant API_STRUCTURE_NAME. */
16      private static final String API_ENTREPRISE_SIREN_NAME = "entreprises";
17      
18      /** The Constant API_ETABLISSEMENT_SIRET_NAME. */
19      private static final String API_ETABLISSEMENT_SIRET_NAME = "etablissements";
20      
21      /** The Constant API_ASSOCIATION_RNA_NAME. */
22      private static final String API_ASSOCIATION_RNA_NAME = "associations";
23      
24      /** The Constant API_VERSION. */
25      private static final String API_VERSION = "v2";
26  
27      /**
28       * Instantiates a new api asso service.
29       *
30       * @param classe
31       *            the classe
32       */
33      public ApiRTUService( Class<Entreprise> classe )
34      {
35          super( classe );
36      }
37  
38      /** The instance. */
39      private static ApiRTUService _instance;
40  
41      /** The str endpoint. */
42      private static String         _strEndpoint;
43  
44      /** The b proxy only. */
45      private static boolean        _bProxyOnly;
46  
47      /**
48       * Gets the single instance of ApiRTUService.
49       *
50       * @param endpoint
51       *            the endpoint
52       * @return single instance of ApiRTUService
53       */
54      public static ApiRTUService getInstance( String endpoint )
55      {
56          if ( _instance == null )
57          {
58              _instance = new ApiRTUService( Entreprise.class );
59          }
60          _strEndpoint = endpoint;
61          return _instance;
62      }
63  
64      /**
65       * Gets the single instance of ApiRTUService.
66       *
67       * @param endpoint
68       *            the endpoint
69       * @param proxyOnly
70       *            the proxy only
71       * @return single instance of ApiRTUService
72       */
73      public static ApiRTUService getInstance( String endpoint, boolean proxyOnly )
74      {
75          _bProxyOnly = proxyOnly;
76          return getInstance( endpoint );
77      }
78  
79      /**
80       * Gets the structure.
81       *
82       * @param siren the siren
83       * @param token the token
84       * @param context the context
85       * @param recipient the recipient
86       * @param object the object
87       * @return the structure
88       * @throws ApiRtuUnavailableException             the api Entreprise unavailable exception
89       */
90      public RetourApiEntreprise getEntrepriseSiren(String siren, String token, String context, String recipient, String object ) throws ApiRtuUnavailableException
91      {
92          if ( siren == null || "".equals( siren ) )
93          {
94              return new RetourApiEntreprise( );
95          }
96          RetourApiEntreprise ent = get( API_ENTREPRISE_SIREN_NAME,API_VERSION, siren, token,context, recipient, object  );
97          /*
98          if ( ent.getErreur( ) != null )
99          {
100             AppLogService.error( "Une balise erreur est contenue dans la réponse de l'api asso (activer le mode debug pour analyser la trame)" );
101             throw new ApiRtuUnavailableException( );
102         }
103         */
104         return ent;
105 
106     }
107 
108     /**
109      * Gets the structure.
110      *
111      * @param siret the siret
112      * @param token the token
113      * @param context the context
114      * @param recipient the recipient
115      * @param object the object
116      * @return the structure
117      * @throws ApiRtuUnavailableException             the api Entreprise unavailable exception
118      */
119     public RetourApiEtablissement getEtablissementSiret(String siret, String token, String context, String recipient, String object ) throws ApiRtuUnavailableException
120     {
121         if ( siret == null || "".equals( siret ) )
122         {
123             return new RetourApiEtablissement( );
124         }
125         RetourApiEtablissement ent = getEtablissement( API_ETABLISSEMENT_SIRET_NAME,API_VERSION, siret, token,context, recipient, object  );
126         /*
127         if ( ent.getErreur( ) != null )
128         {
129             AppLogService.error( "Une balise erreur est contenue dans la réponse de l'api asso (activer le mode debug pour analyser la trame)" );
130             throw new ApiRtuUnavailableException( );
131         }
132         */
133         return ent;
134 
135     }
136     
137     /**
138      * Gets the structure.
139      *
140      * @param rna the rna
141      * @param token the token
142      * @param context the context
143      * @param recipient the recipient
144      * @param object the object
145      * @return the structure
146      * @throws ApiRtuUnavailableException             the api Entreprise unavailable exception
147      */
148     public RetourApiAssociation getAssociationRNA(String rna, String token, String context, String recipient, String object ) throws ApiRtuUnavailableException
149     {
150         if ( rna == null || "".equals( rna ) )
151         {
152             return new RetourApiAssociation( );
153         }
154         RetourApiAssociation ent = getAssociation( API_ASSOCIATION_RNA_NAME,API_VERSION, rna, token,context, recipient, object  );
155         /*
156         if ( ent.getErreur( ) != null )
157         {
158             AppLogService.error( "Une balise erreur est contenue dans la réponse de l'api asso (activer le mode debug pour analyser la trame)" );
159             throw new ApiRtuUnavailableException( );
160         }
161         */
162         return ent;
163 
164     }
165     
166     /*
167      * (non-Javadoc)
168      * 
169      * @see fr.paris.lutece.plugins.parisassos.service.AbstractRestClient#getEndpoint()
170      */
171     @Override
172     public String getEndpoint( )
173     {
174         return _strEndpoint;
175     }
176 
177     /*
178      * (non-Javadoc)
179      * 
180      * @see fr.paris.lutece.plugins.parisassos.service.AbstractRestClient#isProxyOnly()
181      */
182     @Override
183     public boolean isProxyOnly( )
184     {
185         return _bProxyOnly;
186     }
187 
188 
189 }