-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flightdata-skyalps: reimport /SkyalpsApplication.java
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...-collectors/flightdata-skyalps/src/main/java/it/fos/noibz/skyalps/SkyalpsApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package it.fos.noibz.skyalps; | ||
|
||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Collections; | ||
import java.util.Date; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.http.client.BufferingClientHttpRequestFactory; | ||
import org.springframework.http.client.SimpleClientHttpRequestFactory; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import it.fos.noibz.skyalps.dto.json.schedule.AeroCRSFlight; | ||
import it.fos.noibz.skyalps.dto.json.schedule.AeroCRSGetScheduleSuccess; | ||
import it.fos.noibz.skyalps.dto.json.schedule.AeroCRSGetScheduleSuccessResponse; | ||
import it.fos.noibz.skyalps.rest.AeroCRSRest; | ||
|
||
//@SpringBootApplication | ||
public class SkyalpsApplication { | ||
|
||
private static final DateFormat SDF_FORMAT = new SimpleDateFormat("yyyy/MM/dd"); | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(SkyalpsApplication.class); | ||
@Autowired | ||
private RestTemplate restTemplate; | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SkyalpsApplication.class, args); | ||
} | ||
|
||
@Bean(name = "appRestClient") | ||
public static RestTemplate getRestClient() { | ||
RestTemplate restClient = new RestTemplate( | ||
new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())); | ||
// Add one interceptor like in your example, except using anonymous class. | ||
restClient.setInterceptors(Collections.singletonList((request, body, execution) -> { | ||
LOG.debug("Intercepting..."); | ||
return execution.execute(request, body); | ||
})); | ||
return restClient; | ||
} | ||
|
||
@Bean | ||
public CommandLineRunner run(RestTemplate restTemplate) throws Exception { | ||
Date fltsFROMperiod = SDF_FORMAT.parse("2022/05/20"); | ||
Date fltsTOperiod = SDF_FORMAT.parse("2022/06/24"); | ||
return args -> { | ||
AeroCRSGetScheduleSuccessResponse result = AeroCRSRest.getSchedule(restTemplate, fltsFROMperiod, | ||
fltsTOperiod, "IATA", "BN", false, false); | ||
LOG.debug("Result: " + result); | ||
LOG.debug("Result AeroCRS: " + result.getAerocrs()); | ||
if (result.getAerocrs() instanceof AeroCRSGetScheduleSuccess) { | ||
AeroCRSGetScheduleSuccess success = (AeroCRSGetScheduleSuccess) result.getAerocrs(); | ||
LOG.debug("AeroCRSGetScheduleSuccess: " + success); | ||
if (success.isSuccess()) { | ||
for (AeroCRSFlight flight : success.getFlight()) { | ||
LOG.debug("Flight: " + flight); | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
} |