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.geocode.v1.web.rs.service;
35
36 import fr.paris.lutece.plugins.geocode.v1.web.rs.dto.City;
37 import fr.paris.lutece.plugins.geocode.v1.web.rs.dto.Country;
38 import fr.paris.lutece.plugins.geocode.v1.web.rs.util.Constants;
39 import fr.paris.lutece.plugins.geocode.v1.web.service.IGeoCodeTransportProvider;
40 import fr.paris.lutece.plugins.geocode.v1.web.service.IHttpTransportProvider;
41 import org.apache.log4j.Logger;
42
43 import java.net.URLEncoder;
44 import java.nio.charset.StandardCharsets;
45 import java.text.SimpleDateFormat;
46 import java.util.Date;
47 import java.util.HashMap;
48 import java.util.List;
49 import java.util.Map;
50
51
52
53
54 public class GeoCodeTransportRest extends AbstractTransportRest implements IGeoCodeTransportProvider
55 {
56 SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd" );
57
58
59
60
61 private static Logger _logger = Logger.getLogger( GeoCodeTransportRest.class );
62
63
64 private String _strIdentityStoreQualityEndPoint;
65
66
67
68
69 public GeoCodeTransportRest( )
70 {
71 super( new HttpAccessTransport( ) );
72 }
73
74
75
76
77
78
79
80 public GeoCodeTransportRest( final IHttpTransportProvider httpTransport )
81 {
82 super( httpTransport );
83
84 _strIdentityStoreQualityEndPoint = httpTransport.getApiEndPointUrl( );
85 }
86
87
88
89
90 @Override
91 public City getCityByCodeAndDate( final String strCityCode, final Date dateRef ) throws Exception
92 {
93 _logger.debug( "Get City of " + strCityCode );
94 final Map<String, String> mapParams = new HashMap<>( );
95 mapParams.put( Constants.PARAM_DATE_VALIDITY, df.format( dateRef ) );
96
97 final String url = _strIdentityStoreQualityEndPoint + Constants.VERSION_PATH_V2 + Constants.CITIES_PATH + "/" + strCityCode;
98 return _httpTransport.doGet( url, mapParams,null, City.class, _mapper );
99 }
100
101
102
103
104 @Override
105 public List<City> getListCitesByNameAndDate( final String strCityName, final Date dateRef ) throws Exception
106 {
107 _logger.debug( "Get list City of name " + strCityName );
108 final Map<String, String> mapParams = new HashMap<>( );
109 mapParams.put( Constants.PARAM_SEARCH_NAME_CITY, strCityName );
110 mapParams.put( Constants.PARAM_DATE_VALIDITY, df.format( dateRef ) );
111
112 final String url = _strIdentityStoreQualityEndPoint + Constants.VERSION_PATH_V2 + Constants.CITIES_PATH;
113 return _httpTransport.doGetList( url, mapParams,null, City.class, _mapper );
114 }
115
116
117
118
119 @Override
120 public List<City> getListCitesByNameAndDateLike( final String strCityName, final Date dateRef ) throws Exception
121 {
122 _logger.debug( "Get list like City of name " + strCityName );
123 final Map<String, String> mapParams = new HashMap<>( );
124 mapParams.put( Constants.PARAM_SEARCH_NAME_CITY, strCityName );
125 mapParams.put( Constants.PARAM_DATE_VALIDITY, df.format( dateRef ) );
126
127 final String url = _strIdentityStoreQualityEndPoint + Constants.VERSION_PATH_V2 + Constants.CITIES_PATH + Constants.LIST_PATH;
128 return _httpTransport.doGetList( url, mapParams,null, City.class, _mapper );
129 }
130
131
132
133
134 @Override
135 public Country getCountryByCodeAndDate( final String strCountryCode, final Date dateRef ) throws Exception
136 {
137 _logger.debug( "Get Country of " + strCountryCode );
138 final Map<String, String> mapParams = new HashMap<>( );
139 mapParams.put( Constants.PARAM_DATE_VALIDITY, df.format( dateRef ) );
140
141 final String url = _strIdentityStoreQualityEndPoint + Constants.VERSION_PATH_V2 + Constants.COUNTRIES_PATH + "/" + strCountryCode;
142 return _httpTransport.doGet( url, mapParams,null, Country.class, _mapper );
143 }
144
145
146
147
148 @Override
149 public List<Country> getListCountriesByNameAndDate( final String strCountryName, final Date dateRef ) throws Exception
150 {
151 _logger.debug( "Get Country of " + strCountryName );
152 final Map<String, String> mapParams = new HashMap<>( );
153 mapParams.put( Constants.PARAM_DATE_VALIDITY, df.format( dateRef ) );
154
155 final String url = _strIdentityStoreQualityEndPoint + Constants.VERSION_PATH_V2 + Constants.COUNTRIES_PATH + Constants.SEARCH_PATH + "/" + URLEncoder.encode(strCountryName, StandardCharsets.UTF_8.toString());
156 return _httpTransport.doGetList( url, mapParams,null, Country.class, _mapper );
157 }
158 }