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
35 package fr.paris.lutece.plugins.referentielbo.v1.rs;
36
37 import com.google.gson.reflect.TypeToken;
38 import fr.paris.lutece.plugins.referentielbo.v1.model.IndividuDto;
39 import fr.paris.lutece.plugins.referentielbo.v1.model.exception.ReferentielException;
40 import fr.paris.lutece.plugins.referentielbo.v1.model.profil.ProfilIndividuDto;
41 import fr.paris.lutece.plugins.utilitairesfo.utils.StringUtils;
42 import fr.paris.lutece.portal.service.util.AppLogService;
43 import fr.paris.lutece.util.httpaccess.HttpAccess;
44 import fr.paris.lutece.util.httpaccess.HttpAccessException;
45
46 import java.util.ArrayList;
47 import java.util.List;
48 import java.util.Map;
49 import java.util.Optional;
50
51 public class ReferentielIndividuService extends AbstractWSReferentiel implements IReferentielIndividuService
52 {
53
54 @Deprecated
55 public ReferentielIndividuService( String referentielBaseUrl )
56 {
57 super( referentielBaseUrl );
58 }
59 public ReferentielIndividuService( String referentielBaseUrl, String xGraviteeApiKey )
60 {
61 super( referentielBaseUrl, xGraviteeApiKey );
62 }
63
64 @Override
65 @Deprecated
66 public Optional<IndividuDto> recupererIndividuAvecGuid( String guid ) throws ReferentielException
67 {
68 if ( StringUtils.isBlank( guid ) )
69 {
70 throw new NullPointerException( "GUID null ou vide" );
71 }
72 HttpAccess httpAccess = new HttpAccess( );
73 try
74 {
75 String apiUrl = getReferentielBaseUrl( ) + Constants.RECUPERATION_INDIVIDU_AVEC_GUID_V1 + guid;
76 Map<String, String> mapHeadersRequest = genereHeaderGravitee( null );
77 String response = httpAccess.doGet( apiUrl, null, null, mapHeadersRequest );
78
79 gererErreur( response );
80
81 IndividuDto individuDto = getGson( ).fromJson( response, IndividuDto.class );
82 return Optional.ofNullable( individuDto );
83 }
84 catch( HttpAccessException e )
85 {
86 AppLogService.error("error during mapping response", e);
87 throw new ReferentielException( e );
88 }
89 }
90
91 @Override
92 @Deprecated
93 public Optional<IndividuDto> recupererIndividuAvecCuid( String cuid ) throws ReferentielException
94 {
95 if ( StringUtils.isBlank( cuid ) )
96 {
97 throw new NullPointerException( "CUID null ou vide" );
98 }
99 HttpAccess httpAccess = new HttpAccess( );
100 try
101 {
102 String apiUrl = getReferentielBaseUrl( ) + Constants.RECUPERATION_INDIVIDU_AVEC_CUID_V1 + cuid;
103 Map<String, String> mapHeadersRequest = genereHeaderGravitee( null );
104 String response = httpAccess.doGet(apiUrl, null ,null, mapHeadersRequest );
105
106 gererErreur( response );
107
108 IndividuDto individuDto = getGson( ).fromJson( response, IndividuDto.class );
109 return Optional.ofNullable( individuDto );
110 }
111 catch( HttpAccessException e )
112 {
113 AppLogService.error("erreur de mapping de la réponse", e);
114 throw new ReferentielException( e );
115 }
116 }
117
118 @Override
119 @Deprecated
120 public List<IndividuDto> recupererIndividusParEtablissement( Long idEtablissement ) throws ReferentielException
121 {
122 if ( idEtablissement == null )
123 {
124 throw new NullPointerException( "idEtablissement null" );
125 }
126 HttpAccess httpAccess = new HttpAccess( );
127 try
128 {
129 String apiUrl = getReferentielBaseUrl( ) + Constants.RECUPERATION_INDIVIDU_AVEC_ID_ETABLISSEMENT_V1 + idEtablissement;
130 Map<String, String> mapHeadersRequest = genereHeaderGravitee( null );
131 String response = httpAccess.doGet(apiUrl, null, null, mapHeadersRequest );
132
133 gererErreur( response );
134
135 return ( List<IndividuDto> ) Optional.ofNullable( getGson( ).fromJson( response, new TypeToken<ArrayList<IndividuDto>>( ) {}.getType( ) ) ).orElse( new ArrayList<>( ) );
136 }
137 catch( HttpAccessException e )
138 {
139 AppLogService.error("erreur de mapping de la réponse", e);
140 throw new ReferentielException( e );
141 }
142 }
143
144 @Override
145 @Deprecated
146 public Optional<IndividuDto> creerIndividu( ProfilIndividuDto profilIndividuDto ) throws ReferentielException
147 {
148 HttpAccess httpAccess = new HttpAccess( );
149 try
150 {
151 String apiUrl = getReferentielBaseUrl( ) + Constants.ENREGISTRER_INDIVIDU_V1;
152 String json = getGson( ).toJson( profilIndividuDto );
153 Map<String, String> mapHeadersRequest = genereHeaderGravitee( null );
154 String response = httpAccess.doPostJSON(apiUrl, json, mapHeadersRequest, null);
155
156 gererErreur( response );
157
158 IndividuDto individuDto = getGson( ).fromJson( response, IndividuDto.class );
159 return Optional.ofNullable( individuDto );
160 }
161 catch( HttpAccessException e )
162 {
163 AppLogService.error("erreur de mapping de la réponse", e);
164 throw new ReferentielException( e );
165 }
166 }
167
168 @Override
169 @Deprecated
170 public Optional<IndividuDto> modifierIndividu( ProfilIndividuDto profilIndividuDto ) throws ReferentielException
171 {
172 return creerIndividu( profilIndividuDto );
173 }
174 }