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.referentielbo.v2.rs;
35
36 import com.google.gson.reflect.TypeToken;
37 import fr.paris.lutece.plugins.referentielbo.v2.model.exception.ReferentielException;
38 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielCategorieSocioProfessionnelle;
39 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielCivilite;
40 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielGenre;
41 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielMethodeCertification;
42 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielPieceJustificative;
43 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielQualite;
44 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielRegimeSocioProfessionnel;
45 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielStatutMarital;
46 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielTypeAdresse;
47 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielTypeLienIndividus;
48 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielTypePersonneMorale;
49 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielTypeRessourceFinanciere;
50 import fr.paris.lutece.plugins.referentielbo.v2.model.referentiel.ReferentielTypeTelephone;
51 import fr.paris.lutece.portal.service.util.AppLogService;
52 import fr.paris.lutece.util.httpaccess.HttpAccess;
53 import fr.paris.lutece.util.httpaccess.HttpAccessException;
54
55 import java.lang.reflect.Type;
56 import java.util.ArrayList;
57 import java.util.List;
58 import java.util.Map;
59 import java.util.Optional;
60
61 public class ReferentielTypesService extends AbstractWSReferentiel implements IReferentielTypesService
62 {
63
64
65 @Deprecated
66 public ReferentielTypesService( String referentielBaseUrl )
67 {
68 super( referentielBaseUrl );
69 }
70 public ReferentielTypesService( String referentielBaseUrl, String xGraviteeApiKey )
71 {
72 super( referentielBaseUrl, xGraviteeApiKey );
73 }
74
75 public List<ReferentielPieceJustificative> recupererReferentielPieceJustificative( ) throws ReferentielException
76 {
77 return ( List<ReferentielPieceJustificative> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_PIECES_JUSTIFICATIVE, new TypeToken<ArrayList<ReferentielPieceJustificative>>( ) {}.getType( ) );
78 }
79
80 public List<ReferentielTypeLienIndividus> recupererReferentielTypeLienIndividus( ) throws ReferentielException
81 {
82 return ( List<ReferentielTypeLienIndividus> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_TYPE_LIENS_INDIVIDUS, new TypeToken<ArrayList<ReferentielTypeLienIndividus>>( ) {}.getType( ) );
83 }
84
85 @Override
86 public List<ReferentielCategorieSocioProfessionnelle> recupererReferentielCategorieSocioProfessionnelle( ) throws ReferentielException
87 {
88 return ( List<ReferentielCategorieSocioProfessionnelle> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_CATEGORIE_SOCIO_PRO_PATH, new TypeToken<ArrayList<ReferentielCategorieSocioProfessionnelle>>( ) {}.getType( ) );
89 }
90
91 @Override
92 public List<ReferentielCivilite> recupererReferentielCivilite( ) throws ReferentielException
93 {
94 return ( List<ReferentielCivilite> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_CIVILITE_PATH, new TypeToken<ArrayList<ReferentielCivilite>>( ) {}.getType( ) );
95 }
96
97 @Override
98 public List<ReferentielGenre> recupererReferentielGenre( ) throws ReferentielException
99 {
100 return ( List<ReferentielGenre> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_GENRE_PATH, new TypeToken<ArrayList<ReferentielGenre>>( ) {}.getType( ) );
101 }
102
103 @Override
104 public List<ReferentielMethodeCertification> recupererReferentielMethodeCertification( ) throws ReferentielException
105 {
106 return ( List<ReferentielMethodeCertification> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_METHODE_CERTIFICATION_PATH, new TypeToken<ArrayList<ReferentielMethodeCertification>>( ) {}.getType( ) );
107 }
108
109 @Override
110 public List<ReferentielQualite> recupererReferentielQualite( ) throws ReferentielException
111 {
112 return ( List<ReferentielQualite> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_QUALITE_PATH, new TypeToken<ArrayList<ReferentielQualite>>( ) {}.getType( ) );
113 }
114
115 @Override
116 public List<ReferentielRegimeSocioProfessionnel> recupererReferentielRegimeSocioProfessionnel( ) throws ReferentielException
117 {
118 return ( List<ReferentielRegimeSocioProfessionnel> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_REGIME_SOCIO_PRO_PATH, new TypeToken<ArrayList<ReferentielRegimeSocioProfessionnel>>( ) {}.getType( ) );
119 }
120
121 @Override
122 public List<ReferentielStatutMarital> recupererReferentielStatutMarital( ) throws ReferentielException
123 {
124 return ( List<ReferentielStatutMarital> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_STATUT_MARITAL_PATH, new TypeToken<ArrayList<ReferentielStatutMarital>>( ) {}.getType( ) );
125 }
126
127 @Override
128 public List<ReferentielTypeAdresse> recupererReferentielTypeAdresse( ) throws ReferentielException
129 {
130 return ( List<ReferentielTypeAdresse> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_TYPE_ADRESSE_PATH, new TypeToken<ArrayList<ReferentielTypeAdresse>>( ) {}.getType( ) );
131 }
132
133 @Override
134 public List<ReferentielTypePersonneMorale> recupererReferentielTypePersonneMorale( ) throws ReferentielException
135 {
136 return ( List<ReferentielTypePersonneMorale> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_TYPE_PERSONNE_MORALE_PATH, new TypeToken<ArrayList<ReferentielTypePersonneMorale>>( ) {}.getType( ) );
137 }
138
139 @Override
140 public List<ReferentielTypeRessourceFinanciere> recupererReferentielTypeRessourceFinanciere( ) throws ReferentielException
141 {
142 return ( List<ReferentielTypeRessourceFinanciere> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_TYPE_RESSOURCE_FINANCIERE_PATH, new TypeToken<ArrayList<ReferentielTypeRessourceFinanciere>>( ) {}.getType( ) );
143 }
144
145 @Override
146 public List<ReferentielTypeTelephone> recupererReferentielTypeTelephone( ) throws ReferentielException
147 {
148 return ( List<ReferentielTypeTelephone> ) recupererReferentiel( Constants.RECUPERATION_REFERENTIEL_TYPE_TELEPHONE_PATH, new TypeToken<ArrayList<ReferentielTypeTelephone>>( ) {}.getType( ) );
149 }
150
151 private List<?> recupererReferentiel( String pathSpecifique, Type typeRetour ) throws ReferentielException
152 {
153 HttpAccess httpAccess = new HttpAccess( );
154 try
155 {
156 String apiUrl = getReferentielBaseUrl( ) + pathSpecifique;
157 Map<String, String> mapHeadersRequest = genereHeaderGravitee( null );
158 String response = appelDoGet( httpAccess, pathSpecifique, apiUrl, mapHeadersRequest );
159
160 gererErreur( response );
161
162 return ( List<?> ) Optional.ofNullable( getGson( ).fromJson( response, typeRetour ) ).orElse( new ArrayList<>( ) );
163 }
164 catch( HttpAccessException e )
165 {
166 AppLogService.error("erreur de mapping de la réponse", e);
167 throw new ReferentielException( e );
168 }
169 }
170 }