11package cz .geek .fio ;
22
33import lombok .NonNull ;
4+ import lombok .extern .slf4j .Slf4j ;
45import org .apache .hc .client5 .http .classic .HttpClient ;
56import org .apache .hc .client5 .http .config .ConnectionConfig ;
67import org .apache .hc .client5 .http .config .RequestConfig ;
2627/**
2728 * Fio Bank Client
2829 */
30+ @ Slf4j
2931public class FioClient {
3032
3133 private static final String ROOT = "/ib_api/rest/" ;
@@ -70,6 +72,7 @@ public FioClient(@NonNull FioClientSettings settings) {
7072 this .restTemplate = createRestTemplate (base , settings );
7173 this .jaxb2Converter = new NamespaceIgnoringJaxb2HttpMessageConverter ();
7274 this .conversionService = new FioConversionService ();
75+ log .info ("Fio client configured {}" , base .toUriString ());
7376 }
7477
7578 private RestTemplate createRestTemplate (final UriComponentsBuilder base , final FioClientSettings settings ) {
@@ -113,9 +116,12 @@ private HttpClientBuilder createHttpClientBuilder(final FioClientSettings settin
113116 public FioAccountStatement getStatement (final LocalDate start , final LocalDate end ) {
114117 notNull (start );
115118 notNull (end );
119+ String from = DATE_FORMATTER .format (start );
120+ String to = DATE_FORMATTER .format (end );
121+ log .info ("Getting statement from {} to {}" , from , to );
116122 return restTemplate .execute (STATEMENT_PERIODS , GET , null ,
117123 statementExtractor (jaxb2Converter , conversionService ),
118- token , DATE_FORMATTER . format ( start ), DATE_FORMATTER . format ( end ) , ExportFormat .xml );
124+ token , from , to , ExportFormat .xml );
119125 }
120126
121127 /**
@@ -130,8 +136,11 @@ public void exportStatement(final LocalDate start, final LocalDate end, final Ex
130136 notNull (start );
131137 notNull (end );
132138 notNull (format );
139+ String from = DATE_FORMATTER .format (start );
140+ String to = DATE_FORMATTER .format (end );
141+ log .info ("Exporting statement {} from {} to {}" , format , from , to );
133142 restTemplate .execute (STATEMENT_PERIODS , GET , null , new OutputStreamResponseExtractor (target ),
134- token , DATE_FORMATTER . format ( start ), DATE_FORMATTER . format ( end ) , format );
143+ token , from , to , format );
135144 }
136145
137146 /**
@@ -142,6 +151,7 @@ public void exportStatement(final LocalDate start, final LocalDate end, final Ex
142151 * @throws FioException
143152 */
144153 public FioAccountStatement getStatement (final int year , final int id ) {
154+ log .info ("Getting statement for year {} id {}" , year , id );
145155 return restTemplate .execute (STATEMENT_BY_ID , GET , null ,
146156 statementExtractor (jaxb2Converter , conversionService ),
147157 token , year , id , ExportFormat .xml );
@@ -157,6 +167,7 @@ public FioAccountStatement getStatement(final int year, final int id) {
157167 */
158168 public void exportStatement (final int year , final int id , final ExportFormat format , final OutputStream target ) {
159169 notNull (format );
170+ log .info ("Exporting statement {} for year {} id {}" , format , year , id );
160171 restTemplate .execute (STATEMENT_BY_ID , GET , null , new OutputStreamResponseExtractor (target ),
161172 token , year , id , format );
162173 }
@@ -167,6 +178,7 @@ public void exportStatement(final int year, final int id, final ExportFormat for
167178 * @throws FioException
168179 */
169180 public FioAccountStatement getStatement () {
181+ log .info ("Getting statement from the last download" );
170182 return restTemplate .execute (STATEMENT_LAST , GET , null ,
171183 statementExtractor (jaxb2Converter , conversionService ),
172184 token , ExportFormat .xml );
@@ -180,6 +192,7 @@ public FioAccountStatement getStatement() {
180192 */
181193 public void exportStatement (final ExportFormat format , final OutputStream target ) {
182194 notNull (format );
195+ log .info ("Exporting statement {} from the last download" , format );
183196 restTemplate .execute (STATEMENT_LAST , GET , null , new OutputStreamResponseExtractor (target ),
184197 token , format );
185198 }
@@ -201,6 +214,7 @@ public void setLast(final BigInteger id) {
201214 */
202215 public void setLast (final String id ) {
203216 notEmpty (id );
217+ log .info ("Setting last download from {}" , id );
204218 restTemplate .execute (LAST_ID , GET , null , null ,
205219 token , id );
206220 }
@@ -212,8 +226,10 @@ public void setLast(final String id) {
212226 */
213227 public void setLast (final LocalDate date ) {
214228 notNull (date );
229+ String last = DATE_FORMATTER .format (date );
230+ log .info ("Setting last download from {}" , date );
215231 restTemplate .execute (LAST_DATE , GET , null , null ,
216- token , DATE_FORMATTER . format ( date ) );
232+ token , last );
217233 }
218234
219235}
0 commit comments