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.referentielfo.v1.rs;
35
36 import com.fasterxml.jackson.core.JsonProcessingException;
37 import com.fasterxml.jackson.databind.JsonMappingException;
38 import com.fasterxml.jackson.databind.ObjectMapper;
39 import fr.paris.lutece.plugins.referentielfo.v1.model.ArrondissementDto;
40 import fr.paris.lutece.plugins.referentielfo.v1.model.exception.ReferentielException;
41 import fr.paris.lutece.portal.service.util.AppLogService;
42 import fr.paris.lutece.util.httpaccess.HttpAccess;
43 import fr.paris.lutece.util.httpaccess.HttpAccessException;
44
45 import java.util.Collections;
46 import java.util.List;
47 import java.util.Map;
48
49 public class ReferentielArrondissementService extends AbstractWSReferentiel implements IReferentielArrondissementService
50 {
51 @Deprecated
52 public ReferentielArrondissementService( String referentielBaseUrl )
53 {
54 super( referentielBaseUrl );
55 }
56 public ReferentielArrondissementService( String referentielBaseUrl, String xGraviteeApiKey )
57 {
58 super( referentielBaseUrl, xGraviteeApiKey );
59 }
60
61 @Override
62 public List<ArrondissementDto> recuperationArrondissements( ) throws ReferentielException
63 {
64 HttpAccess httpAccess = new HttpAccess( );
65 try
66 {
67 String apiUrl = getReferentielBaseUrl( ) + Constants.RECUPERATION_ARRONDISSEMENTS;
68 Map<String, String> mapHeadersRequest = genereHeaderGravitee( null );
69 String response = httpAccess.doGet( apiUrl, null, null, mapHeadersRequest );
70
71 gererErreur( response );
72
73 return Collections.singletonList( getGson( ).fromJson( response, ArrondissementDto.class ) );
74 }
75 catch( HttpAccessException e )
76 {
77 AppLogService.error("error during mapping response", e);
78 throw new ReferentielException( e );
79 }
80 }
81
82 @Override
83 public ArrondissementDto recupererArrondissementParId( String id ) throws ReferentielException
84 {
85 HttpAccess httpAccess = new HttpAccess( );
86 try
87 {
88 String apiUrl = getReferentielBaseUrl( ) + Constants.RECUPERATION_ARRONDISSEMENT_PAR_ID + id;
89 Map<String, String> mapHeadersRequest = genereHeaderGravitee( null );
90 String response = httpAccess.doGet( apiUrl, null, null, mapHeadersRequest );
91
92 gererErreur( response );
93
94 ObjectMapper mapper = new ObjectMapper();
95
96 return mapper.readValue(response, ArrondissementDto.class);
97 }
98 catch( HttpAccessException e )
99 {
100 AppLogService.error("error during mapping response", e);
101 throw new ReferentielException( e );
102 }
103 catch ( JsonProcessingException e )
104 {
105 throw new ReferentielException( e );
106 }
107 }
108
109 @Override
110 public ArrondissementDto recuperationArrondissementParSecteurId( String id ) throws ReferentielException
111 {
112 HttpAccess httpAccess = new HttpAccess( );
113 try
114 {
115 String apiUrl = getReferentielBaseUrl( ) + Constants.RECUPERATION_ARRONDISSEMENT_PAR_SECTEUR_ID + id;
116 Map<String, String> mapHeadersRequest = genereHeaderGravitee( null );
117 String response = httpAccess.doGet( apiUrl, null, null, mapHeadersRequest );
118
119 gererErreur( response );
120
121 ObjectMapper mapper = new ObjectMapper();
122
123 return mapper.readValue(response, ArrondissementDto.class);
124 }
125 catch( HttpAccessException e )
126 {
127 AppLogService.error("error during mapping response", e);
128 throw new ReferentielException( e );
129 }
130 catch ( JsonProcessingException e )
131 {
132 throw new ReferentielException( e );
133 }
134 }
135 }