Skip to content

Commit 4ae6284

Browse files
authored
Intern flight number string (#447)
* Intern flight number string * Ensure output directories are present
1 parent ef95780 commit 4ae6284

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ Main parameters:
4646
| avinor.timetable.period.back | Time window for which past flight data are imported |
4747

4848
## Workflow overview
49-
- For each whitelisted airport, Extime sends a query to the Avinor REST API and retrieves all departure for passenger flights over a given time period.
49+
- For each whitelisted airport, Extime sends a query to the Avinor REST API and retrieves all departures for passenger flights over a given time period.
5050
- The API returns a list of _Flight_ objects that represent a single departure.
51-
- The _Flight_ objects are successively mapped to _FlightEvent_ and _FlightLeg_ object.
51+
- The _Flight_ objects are successively mapped to _FlightEvent_ and _FlightLeg_ objects.
5252
- A heuristic searches among all _FlightLegs_ those that are part of a multi-leg flight:
5353
- they share the same airline and flight number,
5454
- a given leg arrives at the same airport as the one the next leg departs from,

src/main/java/no/rutebanken/extime/model/FlightEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
* @param departureAirport the departure airport IATA code.
1212
* @param arrivalAirport the arrival airport IATA code.
1313
* @param dateOfOperation the scheduled date of operation.
14-
* @param departureTime the departure time in the time zone of the operation day.
15-
* @param arrivalTime the arrival time in the time zone of the operation day.
14+
* @param departureTime the departure time in the time zone of the date of operation.
15+
* @param arrivalTime the arrival time in the time zone of the date of operation.
1616
*/
1717
public record FlightEvent(
1818
long flightId,

src/main/java/no/rutebanken/extime/model/FlightEventMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ public List<FlightEvent> mapToFlightEvent(Flights flightsInAirport) {
4141

4242
private static FlightEvent toFlightEvent(Flight flight) {
4343
AirlineIATA airline = AirlineIATA.valueOf(flight.getAirlineDesignator());
44+
String flightNumber = (airline.name() + flight.getFlightNumber()).intern();
4445
return new FlightEvent(
4546
flight.getId().longValue(),
46-
airline.name() + flight.getFlightNumber(),
47+
flightNumber,
4748
airline,
4849
AirportIATA.valueOf(flight.getDepartureStation()),
4950
AirportIATA.valueOf(flight.getArrivalStation()),

src/main/java/no/rutebanken/extime/util/AvinorTimetableUtils.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.Collection;
3333
import java.util.List;
3434
import java.util.Map;
35-
import java.util.function.Predicate;
3635
import java.util.stream.Stream;
3736

3837
@Component
@@ -146,23 +145,22 @@ private static String convertToAsciiChar(char ch) {
146145
}
147146

148147
public void compressNetexFiles(Exchange exchange, @Header(Exchange.FILE_NAME) String compressedFileName) {
149-
Path netexOutputPath = Paths.get(generatedOutputPath);
150-
Path zipOutputPath = Paths.get(compressedOutputPath);
151-
Path zipOutputFilePath = Paths.get(zipOutputPath.toString(), compressedFileName);
152-
PathMatcher matcher = netexOutputPath.getFileSystem().getPathMatcher(XML_GLOB);
153-
Predicate<Path> isRegularFile = path -> Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS);
154-
155-
if (!Files.exists(zipOutputPath)) {
156-
try {
157-
Files.createDirectory(zipOutputPath);
158-
} catch (IOException e) {
159-
throw new ExtimeException("Error while compressing NeTEx files", e);
160-
}
148+
Path netexOutputDirPath = Paths.get(generatedOutputPath);
149+
Path zipOutputDirPath = Paths.get(compressedOutputPath);
150+
try {
151+
Files.createDirectories(netexOutputDirPath);
152+
Files.createDirectories(zipOutputDirPath);
153+
} catch (IOException e) {
154+
throw new ExtimeException("Error while compressing NeTEx files", e);
161155
}
162156

163-
try (Stream<Path> stream = Files.list(netexOutputPath)) {
157+
Path zipOutputFilePath = zipOutputDirPath.resolve(compressedFileName);
158+
PathMatcher matcher = netexOutputDirPath.getFileSystem().getPathMatcher(XML_GLOB);
159+
160+
try (Stream<Path> stream = Files.list(netexOutputDirPath)) {
164161
File[] files = stream
165-
.filter(isRegularFile.and(path -> matcher.matches(path.getFileName())))
162+
.filter(path -> Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS))
163+
.filter(path -> matcher.matches(path.getFileName()))
166164
.map(Path::toFile)
167165
.toArray(File[]::new);
168166
ZipUtil.packEntries(files, zipOutputFilePath.toFile());

0 commit comments

Comments
 (0)