diff --git a/back-end/.classpath b/back-end/.classpath deleted file mode 100755 index 5e8a55f..0000000 --- a/back-end/.classpath +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/back-end/.gitignore b/back-end/.gitignore index 4fdbedb..9256101 100755 --- a/back-end/.gitignore +++ b/back-end/.gitignore @@ -11,7 +11,6 @@ target/ .mtj.tmp/ # Package Files # -*.jar *.war *.nar *.ear @@ -20,4 +19,7 @@ target/ *.rar # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* \ No newline at end of file +hs_err_pid* + +# IntelliJ +.idea/ \ No newline at end of file diff --git a/back-end/.mvn/wrapper/maven-wrapper.jar b/back-end/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..5fd4d50 Binary files /dev/null and b/back-end/.mvn/wrapper/maven-wrapper.jar differ diff --git a/back-end/.project b/back-end/.project deleted file mode 100755 index 83401ec..0000000 --- a/back-end/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - back-end - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.springframework.ide.eclipse.boot.validation.springbootbuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - diff --git a/back-end/.settings/org.eclipse.core.resources.prefs b/back-end/.settings/org.eclipse.core.resources.prefs deleted file mode 100755 index f9fe345..0000000 --- a/back-end/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,4 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/main/java=UTF-8 -encoding//src/test/java=UTF-8 -encoding/=UTF-8 diff --git a/back-end/.settings/org.eclipse.jdt.core.prefs b/back-end/.settings/org.eclipse.jdt.core.prefs deleted file mode 100755 index 9c81ef9..0000000 --- a/back-end/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.methodParameters=generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/back-end/.settings/org.eclipse.m2e.core.prefs b/back-end/.settings/org.eclipse.m2e.core.prefs deleted file mode 100755 index f897a7f..0000000 --- a/back-end/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/back-end/.settings/org.springframework.ide.eclipse.prefs b/back-end/.settings/org.springframework.ide.eclipse.prefs deleted file mode 100755 index a12794d..0000000 --- a/back-end/.settings/org.springframework.ide.eclipse.prefs +++ /dev/null @@ -1,2 +0,0 @@ -boot.validation.initialized=true -eclipse.preferences.version=1 diff --git a/back-end/pom.xml b/back-end/pom.xml index c47dc14..b60bf62 100755 --- a/back-end/pom.xml +++ b/back-end/pom.xml @@ -10,7 +10,7 @@ org.springframework.boot spring-boot-starter-parent - 2.0.5.RELEASE + 2.1.3.RELEASE @@ -48,6 +48,11 @@ mysql-connector-java 8.0.15 + + org.apache.commons + commons-csv + 1.6 + diff --git a/back-end/src/main/java/converters/CsvConverter.java b/back-end/src/main/java/converters/CsvConverter.java index fc3b3bf..a8ef341 100755 --- a/back-end/src/main/java/converters/CsvConverter.java +++ b/back-end/src/main/java/converters/CsvConverter.java @@ -1,299 +1,356 @@ package converters; +import java.io.IOException; +import java.io.StringWriter; import java.util.ArrayList; import java.util.List; -import models.Airport; -import models.Carrier; -import models.ExtraStatistic; -import models.Statistic; +import models.*; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVParser; +import org.apache.commons.csv.CSVPrinter; +import org.apache.commons.csv.CSVRecord; public class CsvConverter implements DataConverter { public CsvConverter() { - } @Override - public String AirportsToString(List airports) { - String csv; - - // Header record. - csv = "code, name\n"; + public String airportsToString(List airports) throws IOException { + StringWriter stringWriter = new StringWriter(); + CSVPrinter csvPrinter = new CSVPrinter(stringWriter, CSVFormat.DEFAULT.withHeader("airportCode", "airportName")); for (Airport airport : airports) { - csv += airport.getCode() + ", \"" + airport.getName() + "\"\n"; + csvPrinter.printRecord(airport.getCode(), airport.getName()); } - - return csv; + + csvPrinter.close(); + + return stringWriter.toString(); } @Override - public String CarriersToString(List carriers) { - String csv; - - // Header record. - csv = "code, name\n"; + public String carriersToString(List carriers) throws IOException { + StringWriter stringWriter = new StringWriter(); + CSVPrinter csvPrinter = new CSVPrinter(stringWriter, CSVFormat.DEFAULT.withHeader("carrierCode", "carrierName")); for (Carrier carrier : carriers) { - csv += carrier.getCode() + ", \"" + carrier.getName() + "\"\n"; + csvPrinter.printRecord(carrier.getCode(), carrier.getName()); } - - return csv; - } - - @Override - public String StatisticToString(Statistic statistic, boolean airport, boolean carrier, boolean yearMonth) { - List statistics = new ArrayList<>(); - statistics.add(statistic); - - return StatisticsToString(statistics, airport, carrier, yearMonth); + + csvPrinter.close(); + + return stringWriter.toString(); } @Override - public String StatisticsToString(List statistics, boolean airport, boolean carrier, boolean yearMonth) { - String csv = ""; + public String statisticsToString(List statistics, StatisticDataSelectorHelper includedData) throws IOException { + StringWriter stringWriter = new StringWriter(); + + List headerColumns = new ArrayList<>(); + + if (includedData.withAirport()) { + headerColumns.add("airportCode"); + headerColumns.add("airportName"); + } - // Header record. - if (airport) { - csv += "airportCode, airportName "; + if (includedData.withCarrier()) { + headerColumns.add("carrierCode"); + headerColumns.add("carrierName"); } - - if (carrier) { - csv += "carrierCode, carrierName, "; + + if (includedData.withYear()) { + headerColumns.add("year"); } - - if (yearMonth) { - csv += "year, month, "; + + if (includedData.withMonth()) { + headerColumns.add("month"); } - - csv += "cancelledFlightCount, onTimeFlightCount, delayedFlightCount, divertedFlightCount, totalFlightCount, " - + "lateAircraftDelayCount, carrierDelayCount, weatherDelayCount, securityDelayCount, nationalAviationSystemDelayCount, " - + "lateAircraftDelayTime, carrierDelayTime, weatherDelayTime, securityDelayTime, nationalAviationSystemDelayTime, totalDelayTime\n"; - - // Records. - for (Statistic statistic : statistics) { - if (airport) { - csv += statistic.getAirport().getCode() + ", " + statistic.getAirport().getName() + ", "; + + if (includedData.withFlightData()) { + if (includedData.withCancelledCount()) { + headerColumns.add("cancelledCount"); } - - if (carrier) { - csv += statistic.getCarrier().getCode() + ", " + statistic.getCarrier().getName() + ", "; + + if (includedData.withOnTimeCount()) { + headerColumns.add("onTimeCount"); } - - if (yearMonth) { - csv += statistic.getYearMonth().getYear() + ", " + statistic.getYearMonth().getMonthValue() + ", ";; + + if (includedData.withDelayedCount()) { + headerColumns.add("delayedCount"); } - - csv += statistic.getCancelledFlightCount() + ", " + statistic.getOnTimeFlightCount() + ", " + statistic.getDelayedFlightCount() + ", " + statistic.getDivertedFlightCount() + ", " + statistic.getTotalFlightCount() + ", " - + statistic.getLateAircraftDelayCount() + ", " + statistic.getCarrierDelayCount() + ", " + statistic.getWeatherDelayCount() + ", " + statistic.getSecurityDelayCount() + ", " - + statistic.getNationalAviationSystemDelayCount() + ", " + statistic.getLateAircraftDelayTime() + ", " + statistic.getCarrierDelayTime() + ", " + statistic.getWeatherDelayTime() + ", " - + statistic.getSecurityDelayTime() + ", " + statistic.getNationalAviationSystemDelayTime() + ", " + statistic.getTotalDelayTime() + "\n"; - } - - return csv; - } - @Override - public String StatisticToFlightString(Statistic statistic, boolean airport, boolean carrier, boolean yearMonth, - boolean cancelledFlightCount, boolean onTimeFlightCount, boolean delayedFlightCount, - boolean divertedFlightCount, boolean totalFlightCount) { - List statistics = new ArrayList<>(); - statistics.add(statistic); - - return StatisticsToFlightString(statistics, airport, carrier, yearMonth); - return null; - } + if (includedData.withDivertedCount()) { + headerColumns.add("divertedCount"); + } - @Override - public String StatisticsToFlightString(List statistics, boolean airport, boolean carrier, - boolean yearMonth, boolean cancelledFlightCount, boolean onTimeFlightCount, boolean delayedFlightCount, - boolean divertedFlightCount, boolean totalFlightCount) { - String csv = ""; - - // Header record. - if (airport) { - csv += "airportCode, airportName "; + if (includedData.withTotalCount()) { + headerColumns.add("totalCount"); + } } - if (carrier) { - csv += "carrierCode, carrierName, "; - } + if (includedData.withDelayData()) { + if (includedData.withLateAircraftCount()) { + headerColumns.add("lateAircraftCount"); + } + + if (includedData.withCarrierCount()) { + headerColumns.add("carrierCount"); + } + + if (includedData.withWeatherCount()) { + headerColumns.add("weatherCount"); + } + + if (includedData.withSecurityCount()) { + headerColumns.add("securityCount"); + } - if (yearMonth) { - csv += "year, month, "; + if (includedData.withNationalAviationSystemCount()) { + headerColumns.add("nationalAviationSystemCount"); + } } - csv += "cancelledFlightCount, onTimeFlightCount, delayedFlightCount, divertedFlightCount, totalFlightCount\n"; + if (includedData.withDelayTimeData()) { + if (includedData.withLateAircraftTime()) { + headerColumns.add("lateAircraftTime"); + } - // Records. - for (Statistic statistic : statistics) { - if (airport) { - csv += statistic.getAirport().getCode() + ", " + statistic.getAirport().getName() + ", "; + if (includedData.withCarrierTime()) { + headerColumns.add("carrierTime"); + } + + if (includedData.withWeatherTime()) { + headerColumns.add("weatherTime"); } - if (carrier) { - csv += statistic.getCarrier().getCode() + ", " + statistic.getCarrier().getName() + ", "; + if (includedData.withSecurityTime()) { + headerColumns.add("securityTime"); } - if (yearMonth) { - csv += statistic.getYearMonth().getYear() + ", " + statistic.getYearMonth().getMonthValue() + ", ";; + if (includedData.withNationalAviationSystemTime()) { + headerColumns.add("nationalAviationSystemTime"); } - csv += statistic.getCancelledFlightCount() + ", " + statistic.getOnTimeFlightCount() + ", " + statistic.getDelayedFlightCount() + ", " - + statistic.getDivertedFlightCount() + ", " + statistic.getTotalFlightCount() + "\n"; + if (includedData.withTotalTime()) { + headerColumns.add("totalTime"); + } } - return csv; + String[] header = headerColumns.toArray(new String[0]); - } + CSVPrinter csvPrinter = new CSVPrinter(stringWriter, CSVFormat.DEFAULT.withHeader(header)); - @Override - public String StatisticToDelayString(Statistic statistic, boolean airport, boolean carrier, boolean yearMonth, - boolean lateAircraftDelayCount, boolean carrierDelayCount, boolean weatherDelayCount, - boolean securityDelayCount, boolean nationalAviationSystemDelayCount) { - List statistics = new ArrayList<>(); - statistics.add(statistic); + for (Statistic statistic : statistics) { + if (includedData.withAirport()) { + csvPrinter.print(statistic.getAirport().getCode()); + csvPrinter.print(statistic.getAirport().getName()); + } - return StatisticsToDelayString(statistics, airport, carrier, yearMonth); + if (includedData.withCarrier()) { + csvPrinter.print(statistic.getCarrier().getCode()); + csvPrinter.print(statistic.getCarrier().getName()); + } - } + if (includedData.withYear()) { + csvPrinter.print(statistic.getYear()); + } - @Override - public String StatisticsToDelayString(List statistics, boolean airport, boolean carrier, - boolean yearMonth, boolean lateAircraftDelayCount, boolean carrierDelayCount, boolean weatherDelayCount, - boolean securityDelayCount, boolean nationalAviationSystemDelayCount) { - String csv = ""; - - // Header record. - if (airport) { - csv += "airportCode, airportName "; - } + if (includedData.withMonth()) { + csvPrinter.print(statistic.getMonth()); + } - if (carrier) { - csv += "carrierCode, carrierName, "; - } + if (includedData.withFlightData()) { + FlightData flightData = statistic.getFlightData(); - if (yearMonth) { - csv += "year, month, "; - } + if (includedData.withCancelledCount()) { + csvPrinter.print(flightData.getCancelledCount()); + } - csv += "lateAircraftDelayCount, carrierDelayCount, weatherDelayCount, securityDelayCount, nationalAviationSystemDelayCount\n"; + if (includedData.withOnTimeCount()) { + csvPrinter.print(flightData.getOnTimeCount()); + } - // Records. - for (Statistic statistic : statistics) { - if (airport) { - csv += statistic.getAirport().getCode() + ", " + statistic.getAirport().getName() + ", "; + if (includedData.withDelayedCount()) { + csvPrinter.print(flightData.getDelayedCount()); + } + + if (includedData.withDivertedCount()) { + csvPrinter.print(flightData.getDivertedCount()); + } + + if (includedData.withTotalCount()) { + csvPrinter.print(flightData.getTotalCount()); + } } - if (carrier) { - csv += statistic.getCarrier().getCode() + ", " + statistic.getCarrier().getName() + ", "; + if (includedData.withDelayData()) { + DelayData delayData = statistic.getDelayData(); + + if (includedData.withLateAircraftCount()) { + csvPrinter.print(delayData.getLateAircraftCount()); + } + + if (includedData.withCarrierCount()) { + csvPrinter.print(delayData.getCarrierCount()); + } + + if (includedData.withWeatherCount()) { + csvPrinter.print(delayData.getWeatherCount()); + } + + if (includedData.withSecurityCount()) { + csvPrinter.print(delayData.getSecurityCount()); + } + + if (includedData.withNationalAviationSystemCount()) { + csvPrinter.print(delayData.getNationalAviationSystemCount()); + } } - if (yearMonth) { - csv += statistic.getYearMonth().getYear() + ", " + statistic.getYearMonth().getMonthValue() + ", ";; + if (includedData.withDelayTimeData()) { + DelayTimeData delayTimeData = statistic.getDelayTimeData(); + + if (includedData.withLateAircraftTime()) { + csvPrinter.print(delayTimeData.getLateAircraftTime()); + } + + if (includedData.withCarrierTime()) { + csvPrinter.print(delayTimeData.getCarrierTime()); + } + + if (includedData.withWeatherTime()) { + csvPrinter.print(delayTimeData.getWeatherTime()); + } + + if (includedData.withSecurityTime()) { + csvPrinter.print(delayTimeData.getSecurityTime()); + } + + if (includedData.withNationalAviationSystemTime()) { + csvPrinter.print(delayTimeData.getNationalAviationSystemTime()); + } + + if (includedData.withTotalTime()) { + csvPrinter.print(delayTimeData.getTotalTime()); + } } - csv += statistic.getLateAircraftDelayCount() + ", " + statistic.getCarrierDelayCount() + ", " + statistic.getWeatherDelayCount() + ", " - + statistic.getSecurityDelayCount() + ", " + statistic.getNationalAviationSystemDelayCount() + "\n"; + csvPrinter.println(); } - return csv; - + csvPrinter.close(); + return stringWriter.toString(); } @Override - public String StatisticToDelayTimeString(Statistic statistic, boolean airport, boolean carrier, boolean yearMonth, - boolean lateAircraftDelayTime, boolean carrierDelayTime, boolean weatherDelayTime, - boolean securityDelayTime, boolean nationalAviationSystemDelayTime, boolean totalDelayTime) { - List statistics = new ArrayList<>(); - statistics.add(statistic); - - return StatisticsToDelayTimeString(statistics, airport, carrier, yearMonth); - } + public List stringToStatistics(String statisticData, Airport airport, Carrier carrier, Integer year, + Integer month) throws Exception { + List statistics = new ArrayList<>(); - @Override - public String StatisticsToDelayTimeString(List statistics, boolean airport, boolean carrier, - boolean yearMonth, boolean lateAircraftDelayTime, boolean carrierDelayTime, boolean weatherDelayTime, - boolean securityDelayTime, boolean nationalAviationSystemDelayTime, boolean totalDelayTime) { - String csv = ""; - - // Header record. - if (airport) { - csv += "airportCode, airportName "; - } - - if (carrier) { - csv += "carrierCode, carrierName, "; - } - - if (yearMonth) { - csv += "year, month, "; - } - - csv += "lateAircraftDelayTime, carrierDelayTime, weatherDelayTime, securityDelayTime, nationalAviationSystemDelayTime, totalDelayTime\n"; - - // Records. - for (Statistic statistic : statistics) { - if (airport) { - csv += statistic.getAirport().getCode() + ", " + statistic.getAirport().getName() + ", "; + CSVParser csvParser = CSVParser.parse(statisticData, CSVFormat.DEFAULT.withHeader()); + List records = csvParser.getRecords(); + + Airport tempAirport = airport; + Carrier tempCarrier = carrier; + Integer tempYear = year; + Integer tempMonth = month; + + for (CSVRecord record : records) { + if (airport == null) { + tempAirport = new Airport(record.get("airportCode"), null); } - - if (carrier) { - csv += statistic.getCarrier().getCode() + ", " + statistic.getCarrier().getName() + ", "; + + if (carrier == null) { + tempCarrier = new Carrier(record.get("carrierCode"), null); } - - if (yearMonth) { - csv += statistic.getYearMonth().getYear() + ", " + statistic.getYearMonth().getMonthValue() + ", ";; + + if (year == null) { + tempYear = Integer.parseInt(record.get("year")); } - - csv += statistic.getLateAircraftDelayTime() + ", " + statistic.getCarrierDelayTime() + ", " + statistic.getWeatherDelayTime() + ", " - + statistic.getSecurityDelayTime() + ", " + statistic.getNationalAviationSystemDelayTime() + ", " + statistic.getTotalDelayTime() + "\n"; + + if (month == null) { + tempMonth = Integer.parseInt(record.get("month")); + } + + int flightCount = Integer.parseInt(record.get("cancelledCount")); + int onTimeCount = Integer.parseInt(record.get("onTimeCount")); + int delayedCount = Integer.parseInt(record.get("delayedCount")); + int divertedCount = Integer.parseInt(record.get("divertedCount")); + int totalCount = Integer.parseInt(record.get("totalCount")); + FlightData flightData = new FlightData(flightCount, onTimeCount, delayedCount, divertedCount, totalCount); + + int lateAircraftCount = Integer.parseInt(record.get("lateAircraftCount")); + int carrierCount = Integer.parseInt(record.get("carrierCount")); + int weatherCount = Integer.parseInt(record.get("weatherCount")); + int securityCount = Integer.parseInt(record.get("securityCount")); + int nationalAviationSystemCount = Integer.parseInt(record.get("nationalAviationSystemCount")); + DelayData delayData = new DelayData(lateAircraftCount, carrierCount, weatherCount, securityCount, + nationalAviationSystemCount); + + int lateAircraftTime = Integer.parseInt(record.get("lateAircraftTime")); + int carrierTime = Integer.parseInt(record.get("carrierTime")); + int weatherTime = Integer.parseInt(record.get("weatherTime")); + int securityTime = Integer.parseInt(record.get("securityTime")); + int nationalAviationSystemTime = Integer.parseInt(record.get("nationalAviationSystemTime")); + int totalTime = Integer.parseInt(record.get("totalTime")); + DelayTimeData delayTimeData = new DelayTimeData(lateAircraftTime, carrierTime, weatherTime, securityTime, + nationalAviationSystemTime, totalTime); + + Statistic statistic = new Statistic(tempAirport, tempCarrier, tempYear, tempMonth, flightData, delayData, + delayTimeData); + + statistics.add(statistic); } - - return csv; + + return statistics; } @Override - public String ExtraStatisticsToString(List extraStatistics, boolean airport1, boolean airport2, boolean carrier) { - String csv = ""; + public String extraStatisticsToString(List extraStatistics, boolean withCarrier) + throws IOException { + StringWriter stringWriter = new StringWriter(); - // Header record. - if (airport1) { - csv += "airportCode, airportName "; - } + List headerColumns = new ArrayList<>(); - if (airport2) { - csv += "airportCode, airportName "; + if (withCarrier) { + headerColumns.add("carrierCode"); + headerColumns.add("carrierName"); } - if (carrier) { - csv += "carrierCode, carrierName, "; - } + headerColumns.add("lateAircraftTimeMean"); + headerColumns.add("lateAircraftTimeMedian"); + headerColumns.add("lateAircraftTimeSd"); - csv += "lateAircraftDelaysTimedMean, lateAircraftDelaysTimedMed, lateAircraftDelaysTimedSd, carrierAircraftDelaysTimedMean, carrierAircraftDelaysTimedMed, carrierAircraftDelaysTimedSd\n"; + headerColumns.add("carrierTimeMean"); + headerColumns.add("carrierTimeMedian"); + headerColumns.add("carrierTimeSd"); - // Records. - for (ExtraStatistic extraStatistic : extraStatistics) { - if (airport1) { - csv += extraStatistic.getAirport1().getCode() + ", " + extraStatistic.getAirport1().getName() + ", "; - } + String[] header = headerColumns.toArray(new String[0]); - if (airport2) { - csv += extraStatistic.getAirport2().getCode() + ", " + extraStatistic.getAirport2().getName() + ", "; - } + CSVPrinter csvPrinter = new CSVPrinter(stringWriter, CSVFormat.DEFAULT.withHeader(header)); - if (carrier) { - csv += extraStatistic.getCarrier().getCode() + ", " + extraStatistic.getCarrier().getName() + ", "; + for (ExtraStatistic extraStatistic : extraStatistics) { + if (withCarrier) { + csvPrinter.print(extraStatistic.getCarrier().getCode()); + csvPrinter.print(extraStatistic.getCarrier().getName()); } - csv += extraStatistic.getLateAircraftDelaysTimedMean() + ", " + extraStatistic.getLateAircraftDelaysTimedMed() + ", " + extraStatistic.getLateAircraftDelaysTimedSd() + ", " - + extraStatistic.getCarrierAircraftDelaysTimedMean() + ", " + extraStatistic.getCarrierAircraftDelaysTimedMed() + "," + extraStatistic.getCarrierAircraftDelaysTimedSd() + "\n"; - } + csvPrinter.print(extraStatistic.getLateAircraftTimeMean()); + csvPrinter.print(extraStatistic.getLateAircraftTimeMedian()); + csvPrinter.print(extraStatistic.getLateAircraftTimeSd()); - return csv; + csvPrinter.print(extraStatistic.getCarrierTimeMean()); + csvPrinter.print(extraStatistic.getCarrierTimeMedian()); + csvPrinter.print(extraStatistic.getCarrierTimeSd()); + + csvPrinter.println(); + } + csvPrinter.close(); + return stringWriter.toString(); } } diff --git a/back-end/src/main/java/converters/DataConverter.java b/back-end/src/main/java/converters/DataConverter.java index 1b67dc4..c3be079 100755 --- a/back-end/src/main/java/converters/DataConverter.java +++ b/back-end/src/main/java/converters/DataConverter.java @@ -1,36 +1,17 @@ package converters; -import java.util.List; +import models.*; -import models.Airport; -import models.Carrier; -import models.Statistic; +import java.util.List; public interface DataConverter { - public String AirportsToString(List airports); - public String CarriersToString(List carriers); - - public String StatisticToString(Statistic statistic, boolean airport, boolean carrier, boolean yearMonth); - public String StatisticsToString(List statistics, boolean airport, boolean carrier, boolean yearMonth); - - public String StatisticToFlightString(Statistic statistic, boolean airport, boolean carrier, boolean yearMonth, - boolean cancelledFlightCount, boolean onTimeFlightCount, boolean delayedFlightCount, - boolean divertedFlightCount, boolean totalFlightCount); - public String StatisticsToFlightString(List statistics, boolean airport, boolean carrier, boolean yearMonth, - boolean cancelledFlightCount, boolean onTimeFlightCount, boolean delayedFlightCount, - boolean divertedFlightCount, boolean totalFlightCount); - - public String StatisticToDelayString(Statistic statistic, boolean airport, boolean carrier, boolean yearMonth, - boolean lateAircraftDelayCount, boolean carrierDelayCount, boolean weatherDelayCount, - boolean securityDelayCount, boolean nationalAviationSystemDelayCount); - public String StatisticsToDelayString(List statistics, boolean airport, boolean carrier, boolean yearMonth, - boolean lateAircraftDelayCount, boolean carrierDelayCount, boolean weatherDelayCount, - boolean securityDelayCount, boolean nationalAviationSystemDelayCount); - - public String StatisticToDelayTimeString(Statistic statistic, boolean airport, boolean carrier, boolean yearMonth, - boolean lateAircraftDelayTime, boolean carrierDelayTime, boolean weatherDelayTime, - boolean securityDelayTime, boolean nationalAviationSystemDelayTime, boolean totalDelayTime); - public String StatisticsToDelayTimeString(List statistics, boolean airport, boolean carrier, boolean yearMonth, - boolean lateAircraftDelayTime, boolean carrierDelayTime, boolean weatherDelayTime, - boolean securityDelayTime, boolean nationalAviationSystemDelayTime, boolean totalDelayTime); + String airportsToString(List airports) throws Exception; + String carriersToString(List carriers) throws Exception; + + String statisticsToString(List statistics, StatisticDataSelectorHelper includedData) throws Exception; + + List stringToStatistics(String statisticsData, Airport airport, Carrier carrier, Integer year, + Integer month) throws Exception; + + String extraStatisticsToString(List extraStatistics, boolean withCarrier) throws Exception; } diff --git a/back-end/src/main/java/converters/JsonConverter.java b/back-end/src/main/java/converters/JsonConverter.java index 5b607a7..038a2df 100755 --- a/back-end/src/main/java/converters/JsonConverter.java +++ b/back-end/src/main/java/converters/JsonConverter.java @@ -1,16 +1,11 @@ package converters; +import java.util.ArrayList; import java.util.List; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -import models.Airport; -import models.Carrier; -import models.ExtraStatistic; -import models.Statistic; +import com.google.gson.*; +import models.*; +import rest.MainRestController; public class JsonConverter implements DataConverter { private Gson gson; @@ -20,347 +15,257 @@ public JsonConverter() { } @Override - public String AirportsToString(List airports) { + public String airportsToString(List airports) { return gson.toJson(airports); } - @Override - public String CarriersToString(List carriers) { - return gson.toJson(carriers); - } - - @Override - public String StatisticToString(Statistic statistic, boolean airport, boolean carrier, boolean yearMonth) { - JsonObject jsonObject = gson.toJsonTree(statistic).getAsJsonObject(); - - if (!airport) { - jsonObject.remove("airport"); - } + public String airportsToStringWithLinks(List airports, String baseHref) { + JsonArray jsonArray = new JsonArray(); - if (!carrier) { - jsonObject.remove("carrier"); - } + for (Airport airport : airports) { + JsonObject jsonObject = new JsonObject(); - if (!yearMonth) { - jsonObject.remove("yearMonth"); - } + jsonObject.add("airport", gson.toJsonTree(airport)); - return jsonObject.toString(); - } + Link link = new Link(baseHref + airport.getCode() + "/", "airport", "GET"); + List links = new ArrayList<>(); + links.add(link); - @Override - public String StatisticsToString(List statistics, boolean airport, boolean carrier, boolean yearMonth) { - JsonArray jsonArray = gson.toJsonTree(statistics).getAsJsonArray(); + jsonObject.add("links", gson.toJsonTree(links)); - for (JsonElement jsonElement : jsonArray) { - JsonObject jsonObject = jsonElement.getAsJsonObject(); - - if (!airport) { - jsonObject.remove("airport"); - } - - if (!carrier) { - jsonObject.remove("carrier"); - } - - if (!yearMonth) { - jsonObject.remove("yearMonth"); - } + jsonArray.add(jsonObject); } return jsonArray.toString(); } @Override - public String StatisticToFlightString(Statistic statistic, boolean airport, boolean carrier, boolean yearMonth, - boolean cancelledFlightCount, boolean onTimeFlightCount, boolean delayedFlightCount, - boolean divertedFlightCount, boolean totalFlightCount) { - JsonObject jsonObject = gson.toJsonTree(statistic).getAsJsonObject(); + public String carriersToString(List carriers) { + return gson.toJson(carriers); + } - if (!airport) { - jsonObject.remove("airport"); - } + public String carriersToStringWithLinks(List carriers, String baseHref) { + JsonArray jsonArray = new JsonArray(); - if (!carrier) { - jsonObject.remove("carrier"); - } + for (Carrier carrier : carriers) { + JsonObject jsonObject = new JsonObject(); - if (!yearMonth) { - jsonObject.remove("yearMonth"); - } + jsonObject.add("carrier", gson.toJsonTree(carrier)); - if (!cancelledFlightCount) { - jsonObject.remove("cancelledFlightCount"); - } + Link link = new Link(baseHref + carrier.getCode() + "/", "carrier", "GET"); + List links = new ArrayList<>(); + links.add(link); - if (!onTimeFlightCount) { - jsonObject.remove("onTimeFlightCount"); - } - - if (!delayedFlightCount) { - jsonObject.remove("delayedFlightCount"); - } + jsonObject.add("links", gson.toJsonTree(links)); - if (!divertedFlightCount) { - jsonObject.remove("divertedFlightCount"); + jsonArray.add(jsonObject); } - if (!totalFlightCount) { - jsonObject.remove("totalFlightCount"); - } - return jsonObject.toString(); - + return jsonArray.toString(); } @Override - public String StatisticsToFlightString(List statistics, boolean airport, boolean carrier, - boolean yearMonth, boolean cancelledFlightCount, boolean onTimeFlightCount, boolean delayedFlightCount, - boolean divertedFlightCount, boolean totalFlightCount) { - JsonArray jsonArray = gson.toJsonTree(statistics).getAsJsonArray(); - - for (JsonElement jsonElement : jsonArray) { - JsonObject jsonObject = jsonElement.getAsJsonObject(); - - if (!airport) { - jsonObject.remove("airport"); - } - - if (!carrier) { - jsonObject.remove("carrier"); - } - - if (!yearMonth) { - jsonObject.remove("yearMonth"); - } + public String statisticsToString(List statistics, StatisticDataSelectorHelper includedData) { + JsonArray jsonArray = new JsonArray(); - if (!cancelledFlightCount) { - jsonObject.remove("cancelledFlightCount"); - } + for (Statistic statistic : statistics) { + JsonObject jsonObject = new JsonObject(); - if (!onTimeFlightCount) { - jsonObject.remove("onTimeFlightCount"); + if (includedData.withAirport()) { + jsonObject.add("airport", gson.toJsonTree(statistic.getAirport())); } - if (!delayedFlightCount) { - jsonObject.remove("delayedFlightCount"); + if (includedData.withCarrier()) { + jsonObject.add("carrier", gson.toJsonTree(statistic.getCarrier())); } - if (!divertedFlightCount) { - jsonObject.remove("divertedFlightCount"); + if (includedData.withYear()) { + jsonObject.addProperty("year", statistic.getYear()); } - if (!totalFlightCount) { - jsonObject.remove("totalFlightCount"); + if (includedData.withMonth()) { + jsonObject.addProperty("month", statistic.getMonth()); } - return jsonObject.toString(); - - } - } - - @Override - public String StatisticToDelayString(Statistic statistic, boolean airport, boolean carrier, boolean yearMonth, - boolean lateAircraftDelayCount, boolean carrierDelayCount, boolean weatherDelayCount, - boolean securityDelayCount, boolean nationalAviationSystemDelayCount) { - JsonObject jsonObject = gson.toJsonTree(statistic).getAsJsonObject(); - - if (!airport) { - jsonObject.remove("airport"); - } - - if (!carrier) { - jsonObject.remove("carrier"); - } - if (!yearMonth) { - jsonObject.remove("yearMonth"); - } - - if (!lateAircraftDelayCount) { - jsonObject.remove("lateAircraftDelayCount"); - } + if (includedData.withFlightData()) { + FlightData flightData = statistic.getFlightData(); + JsonObject flightDataJson = new JsonObject(); - if (!carrierDelayCount) { - jsonObject.remove("carrierDelayCount"); - } - if (!weatherDelayCount) { - jsonObject.remove("weatherDelayCount"); - } - - if (!securityDelayCount) { - jsonObject.remove("securityDelayCount"); - } + if (includedData.withCancelledCount()) { + flightDataJson.addProperty("cancelledCount", flightData.getCancelledCount()); + } - if (!nationalAviationSystemDelayCount) { - jsonObject.remove("nationalAviationSystemDelayCount"); - } - return jsonObject.toString(); - } + if (includedData.withOnTimeCount()) { + flightDataJson.addProperty("onTimeCount", flightData.getOnTimeCount()); + } + if (includedData.withDelayedCount()) { + flightDataJson.addProperty("delayedCount", flightData.getDelayedCount()); + } - @Override - public String StatisticsToDelayString(List statistics, boolean airport, boolean carrier, boolean yearMonth, - boolean lateAircraftDelayCount, boolean carrierDelayCount, boolean weatherDelayCount, - boolean securityDelayCount, boolean nationalAviationSystemDelayCount) { - JsonArray jsonArray = gson.toJsonTree(statistics).getAsJsonArray(); + if (includedData.withDivertedCount()) { + flightDataJson.addProperty("divertedCount", flightData.getDivertedCount()); + } - for (JsonElement jsonElement : jsonArray) { - JsonObject jsonObject = jsonElement.getAsJsonObject(); + if (includedData.withTotalCount()) { + flightDataJson.addProperty("totalCount", flightData.getTotalCount()); + } - if (!airport) { - jsonObject.remove("airport"); + jsonObject.add("flightData", flightDataJson); } - if (!carrier) { - jsonObject.remove("carrier"); - } + if (includedData.withDelayData()) { + DelayData delayData = statistic.getDelayData(); + JsonObject delayDataJson = new JsonObject(); - if (!yearMonth) { - jsonObject.remove("yearMonth"); - } + if (includedData.withLateAircraftCount()) { + delayDataJson.addProperty("lateAircraftCount", delayData.getLateAircraftCount()); + } - if (!lateAircraftDelayCount) { - jsonObject.remove("lateAircraftDelayCount"); - } + if (includedData.withCarrierCount()) { + delayDataJson.addProperty("carrierCount", delayData.getCarrierCount()); + } - if (!carrierDelayCount) { - jsonObject.remove("carrierDelayCount"); - } + if (includedData.withWeatherCount()) { + delayDataJson.addProperty("weatherCount", delayData.getWeatherCount()); + } - if (!weatherDelayCount) { - jsonObject.remove("weatherDelayCount"); - } + if (includedData.withSecurityCount()) { + delayDataJson.addProperty("securityCount", delayData.getSecurityCount()); + } - if (!securityDelayCount) { - jsonObject.remove("securityDelayCount"); - } + if (includedData.withNationalAviationSystemCount()) { + delayDataJson.addProperty("nationalAviationSystemCount", + delayData.getNationalAviationSystemCount()); + } - if (!nationalAviationSystemDelayCount) { - jsonObject.remove("nationalAviationSystemDelayCount"); + jsonObject.add("delayData", delayDataJson); } - return jsonObject.toString(); - } - } + if (includedData.withDelayTimeData()) { + DelayTimeData delayTimeData = statistic.getDelayTimeData(); + JsonObject delayTimeDataJson = new JsonObject(); - @Override - public String StatisticToDelayTimeString(Statistic statistic, boolean airport, boolean carrier, - boolean yearMonth, boolean lateAircraftDelayTime, boolean carrierDelayTime, boolean weatherDelayTime, - boolean securityDelayTime, boolean nationalAviationSystemDelayTime, boolean totalDelayTime) { - JsonObject jsonObject = gson.toJsonTree(statistic).getAsJsonObject(); + if (includedData.withLateAircraftTime()) { + delayTimeDataJson.addProperty("lateAircraftTime", delayTimeData.getLateAircraftTime()); + } - if (!airport) { - jsonObject.remove("airport"); - } + if (includedData.withCarrierTime()) { + delayTimeDataJson.addProperty("carrierTime", delayTimeData.getCarrierTime()); + } - if (!carrier) { - jsonObject.remove("carrier"); - } + if (includedData.withWeatherTime()) { + delayTimeDataJson.addProperty("weatherTime", delayTimeData.getWeatherTime()); + } - if (!yearMonth) { - jsonObject.remove("yearMonth"); - } + if (includedData.withSecurityTime()) { + delayTimeDataJson.addProperty("securityTime", delayTimeData.getSecurityTime()); + } - if (!lateAircraftDelayTime) { - jsonObject.remove("lateAircraftDelayCount"); - } + if (includedData.withNationalAviationSystemTime()) { + delayTimeDataJson.addProperty("nationalAviationSystemTime", + delayTimeData.getNationalAviationSystemTime()); + } - if (!carrierDelayTime) { - jsonObject.remove("carrierDelayCount"); - } + if (includedData.withTotalTime()) { + delayTimeDataJson.addProperty("totalTime", delayTimeData.getTotalTime()); + } - if (!weatherDelayTime) { - jsonObject.remove("weatherDelayCount"); - } - - if (!securityDelayTime) { - jsonObject.remove("securityDelayCount"); - } + jsonObject.add("delayTimeData", delayTimeDataJson); - if (!nationalAviationSystemDelayTime) { - jsonObject.remove("nationalAviationSystemDelayCount"); - } + } - if (!totalDelayTime) { - jsonObject.remove("totalDelayTime") + jsonArray.add(jsonObject); } - return jsonObject.toString(); - + return jsonArray.toString(); } @Override - public String StatisticsToDelayTimeString(List statistics, boolean airport, boolean carrier, - boolean yearMonth, boolean lateAircraftDelayTime, boolean carrierDelayTime, boolean weatherDelayTime, - boolean securityDelayTime, boolean nationalAviationSystemDelayTime, boolean totalDelayTime) { - JsonArray jsonArray = gson.toJsonTree(statistics).getAsJsonArray(); + public List stringToStatistics(String statisticsData, Airport airport, Carrier carrier, Integer year, + Integer month) { + List statistics = new ArrayList<>(); + JsonArray jsonArray = gson.fromJson(statisticsData, JsonArray.class); + + Airport tempAirport = airport; + Carrier tempCarrier = carrier; + Integer tempYear = year; + Integer tempMonth = month; for (JsonElement jsonElement : jsonArray) { JsonObject jsonObject = jsonElement.getAsJsonObject(); - if (!airport) { - jsonObject.remove("airport"); - } - - if (!carrier) { - jsonObject.remove("carrier"); - } - - if (!yearMonth) { - jsonObject.remove("yearMonth"); + if (airport == null) { + tempAirport = new Airport(jsonObject.get("airport").getAsJsonObject().get("code").getAsString(), null); } - if (!lateAircraftDelayTime) { - jsonObject.remove("lateAircraftDelayTime"); + if (carrier == null) { + tempCarrier = new Carrier(jsonObject.get("carrier").getAsJsonObject().get("code").getAsString(), null); } - if (!carrierDelayTime) { - jsonObject.remove("carrierDelayTime"); + if (year == null) { + tempYear = jsonObject.get("year").getAsInt(); } - if (!weatherDelayTime) { - jsonObject.remove("weatherDelayTime"); + if (month == null) { + tempMonth = jsonObject.get("month").getAsInt(); } - if (!securityDelayTime) { - jsonObject.remove("securityDelayTime"); - } + FlightData flightData = gson.fromJson(jsonObject.get("flightData"), FlightData.class); + DelayData delayData = gson.fromJson(jsonObject.get("delayData"), DelayData.class); + DelayTimeData delayTimeData = gson.fromJson(jsonObject.get("delayTimeData"), DelayTimeData.class); - if (!nationalAviationSystemDelayTime) { - jsonObject.remove("nationalAviationSystemDelayTime"); + if (flightData == null || delayData == null || delayTimeData == null) { + throw new JsonParseException("Missing data in JSON string."); } - if (!totalDelayTime) { - jsonObject.remove("totalDelayTime") - } + Statistic statistic = new Statistic(tempAirport, tempCarrier, tempYear, tempMonth, flightData, delayData, + delayTimeData); + statistics.add(statistic); } - return jsonArray.toString(); + return statistics; } @Override - public String ExtraStatisticsToString(List extraStatistics, boolean airport1, boolean airport2, boolean carrier) { - JsonArray jsonArray = gson.toJsonTree(extraStatistics).getAsJsonArray(); + public String extraStatisticsToString(List extraStatistics, boolean withCarrier) { + JsonArray jsonArray = new JsonArray(); - for (JsonElement jsonElement : jsonArray) { - JsonObject jsonObject = jsonElement.getAsJsonObject(); + for (ExtraStatistic extraStatistic : extraStatistics) { + JsonObject jsonObject = new JsonObject(); - if (!airport1) { - jsonObject.remove("airport"); + if (withCarrier) { + jsonObject.add("carrier", gson.toJsonTree(extraStatistic.getCarrier())); } - if (!airport2) { - jsonObject.remove("airport"); - } + jsonObject.addProperty("lateAircraftTimeMean", extraStatistic.getLateAircraftTimeMean()); + jsonObject.addProperty("lateAircraftTimeMedian", extraStatistic.getLateAircraftTimeMedian()); + jsonObject.addProperty("lateAircraftTimeSd", extraStatistic.getLateAircraftTimeSd()); - if (!carrier) { - jsonObject.remove("carrier"); - } + jsonObject.addProperty("carrierTimeMean", extraStatistic.getCarrierTimeMean()); + jsonObject.addProperty("carrierTimeMedian", extraStatistic.getCarrierTimeMedian()); + jsonObject.addProperty("carrierTimeSd", extraStatistic.getCarrierTimeSd()); + jsonArray.add(jsonObject); } return jsonArray.toString(); } + public String mergeLinksAndJson(List links, String json) { + JsonObject jsonObject = new JsonObject(); + if (json != null) { + JsonElement jsonElement = gson.fromJson(json, JsonElement.class); + jsonObject.add("content", jsonElement); + } + + if (links != null) { + JsonArray jsonLinks = gson.toJsonTree(links).getAsJsonArray(); + jsonObject.add("links", jsonLinks); + } + + return jsonObject.toString(); + } } diff --git a/back-end/src/main/java/converters/StatisticDataSelectorHelper.java b/back-end/src/main/java/converters/StatisticDataSelectorHelper.java new file mode 100644 index 0000000..abf5449 --- /dev/null +++ b/back-end/src/main/java/converters/StatisticDataSelectorHelper.java @@ -0,0 +1,194 @@ +package converters; + +public class StatisticDataSelectorHelper { + private boolean airport; + private boolean carrier; + private boolean year; + private boolean month; + + private boolean flightData; + private boolean cancelledCount; + private boolean onTimeCount; + private boolean delayedCount; + private boolean divertedCount; + private boolean totalCount; + + private boolean delayData; + private boolean lateAircraftCount; + private boolean carrierCount; + private boolean weatherCount; + private boolean securityCount; + private boolean nationalAviationSystemCount; + + private boolean delayTimeData; + private boolean lateAircraftTime; + private boolean carrierTime; + private boolean weatherTime; + private boolean securityTime; + private boolean nationalAviationSystemTime; + private boolean totalTime; + + public StatisticDataSelectorHelper(boolean airport, boolean carrier, boolean year, boolean month) { + this.airport = airport; + this.carrier = carrier; + this.year = year; + this.month = month; + } + + public void setFlightDataTrue() { + flightData = true; + + cancelledCount = true; + onTimeCount = true; + delayedCount = true; + divertedCount = true; + totalCount = true; + } + + public void setDelayDataTrue() { + delayData = true; + + lateAircraftCount = true; + carrierCount = true; + weatherCount = true; + securityCount = true; + nationalAviationSystemCount = true; + } + + public void setDelayDataTimeTrue() { + delayTimeData = true; + + lateAircraftTime = true; + carrierTime = true; + weatherTime = true; + securityTime = true; + nationalAviationSystemTime = true; + totalTime = true; + } + + public void setFlightData(boolean cancelledCount, boolean onTimeCount, boolean delayedCount, boolean divertedCount, + boolean totalCount) { + flightData = true; + + this.cancelledCount = cancelledCount; + this.onTimeCount = onTimeCount; + this.delayedCount = delayedCount; + this.divertedCount = divertedCount; + this.totalCount = totalCount; + } + + public void setDelayData(boolean lateAircraftCount, boolean carrierCount, boolean weatherCount, + boolean securityCount, boolean nationalAviationSystemCount) { + delayData = true; + + this.lateAircraftCount = lateAircraftCount; + this.carrierCount = carrierCount; + this.weatherCount = weatherCount; + this.securityCount = securityCount; + this.nationalAviationSystemCount = nationalAviationSystemCount; + } + + public void setDelayTimeData(boolean lateAircraftTime, boolean carrierTime, boolean weatherTime, + boolean securityTime, boolean nationalAviationSystemTime, boolean totalTime) { + delayTimeData = true; + + this.lateAircraftTime = lateAircraftTime; + this.carrierTime = carrierTime; + this.weatherTime = weatherTime; + this.securityTime = securityTime; + this.nationalAviationSystemTime = nationalAviationSystemTime; + this.totalTime = totalTime; + } + + public boolean withAirport() { + return airport; + } + + public boolean withCarrier() { + return carrier; + } + + public boolean withYear() { + return year; + } + + public boolean withMonth() { + return month; + } + + public boolean withFlightData() { + return flightData; + } + + public boolean withCancelledCount() { + return cancelledCount; + } + + public boolean withOnTimeCount() { + return onTimeCount; + } + + public boolean withDelayedCount() { + return delayedCount; + } + + public boolean withDivertedCount() { + return divertedCount; + } + + public boolean withTotalCount() { + return totalCount; + } + + public boolean withDelayData() { + return delayData; + } + + public boolean withLateAircraftCount() { + return lateAircraftCount; + } + + public boolean withCarrierCount() { + return carrierCount; + } + + public boolean withWeatherCount() { + return weatherCount; + } + + public boolean withSecurityCount() { + return securityCount; + } + + public boolean withNationalAviationSystemCount() { + return nationalAviationSystemCount; + } + + public boolean withDelayTimeData() { + return delayTimeData; + } + + public boolean withLateAircraftTime() { + return lateAircraftTime; + } + + public boolean withCarrierTime() { + return carrierTime; + } + + public boolean withWeatherTime() { + return weatherTime; + } + + public boolean withSecurityTime() { + return securityTime; + } + + public boolean withNationalAviationSystemTime() { + return nationalAviationSystemTime; + } + + public boolean withTotalTime() { + return totalTime; + } +} diff --git a/back-end/src/main/java/database/DatabaseConnector.java b/back-end/src/main/java/database/DatabaseConnector.java index 89cdf8a..77cb99b 100755 --- a/back-end/src/main/java/database/DatabaseConnector.java +++ b/back-end/src/main/java/database/DatabaseConnector.java @@ -1,31 +1,29 @@ package database; -import java.beans.PropertyVetoException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.time.YearMonth; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import com.mchange.v2.c3p0.ComboPooledDataSource; -import models.Airport; -import models.Carrier; -import models.ExtraStatistic; -import models.Statistic; +import converters.StatisticDataSelectorHelper; +import models.*; public class DatabaseConnector { // Database URL, and database credentials. - private final String DB_URL = "jdbc:mysql://192.168.178.22:3306/webengdb"; + private final String DB_URL = "jdbc:mysql://localhost:3306/webengdb?serverTimezone=" + TimeZone.getDefault().getID(); private final String USER = "webenguser"; private final String PASS = "webengpass123"; - ComboPooledDataSource cpds; + private Map airports; + private Map carriers; - public DatabaseConnector() throws PropertyVetoException, SQLException { + private ComboPooledDataSource cpds; + + public DatabaseConnector() throws SQLException { cpds = new ComboPooledDataSource(); cpds.setJdbcUrl(DB_URL); cpds.setUser(USER); @@ -35,16 +33,26 @@ public DatabaseConnector() throws PropertyVetoException, SQLException { createCarriersTable(); createStatsTable(); createExtraStatsTable(); + + airports = new HashMap<>(); + for (Airport airport : getAirports()) { + airports.put(airport.getCode(), airport.getName()); + } + + carriers = new HashMap<>(); + for (Carrier carrier : getCarriers()) { + carriers.put(carrier.getCode(), carrier.getName()); + } } private void createAirportsTable() throws SQLException { Connection conn = null; Statement stmt = null; - String query = "CREATE TABLE IF NOT EXISTS airports (" - + "code CHAR(3) PRIMARY KEY," - + "name VARCHAR(255)" - + ");"; + String query = "CREATE TABLE IF NOT EXISTS airports (" + + "code CHAR(3) PRIMARY KEY, " + + "name VARCHAR(255)" + + ");"; try { // Get connection from pool. @@ -53,9 +61,6 @@ private void createAirportsTable() throws SQLException { // Execute query. stmt = conn.createStatement(); stmt.executeUpdate(query); - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -76,10 +81,10 @@ private void createCarriersTable() throws SQLException { Connection conn = null; Statement stmt = null; - String query = "CREATE TABLE IF NOT EXISTS carriers (" - + "code CHAR(2) PRIMARY KEY," - + "name VARCHAR(255)" - + ");"; + String query = "CREATE TABLE IF NOT EXISTS carriers (" + + "code CHAR(2) PRIMARY KEY," + + "name VARCHAR(255)" + + ");"; try { // Get connection from pool. @@ -88,9 +93,6 @@ private void createCarriersTable() throws SQLException { // Execute query. stmt = conn.createStatement(); stmt.executeUpdate(query); - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -111,33 +113,33 @@ private void createStatsTable() throws SQLException { Connection conn = null; Statement stmt = null; - String query = "CREATE TABLE IF NOT EXISTS stats (" - + "airport CHAR(3)," - + "carrier CHAR(2)," - + "year YEAR," - + "month TINYINT(2) UNSIGNED," - - + "cancelledFlightCount MEDIUMINT UNSIGNED NOT NULL," - + "onTimeFlightCount MEDIUMINT UNSIGNED NOT NULL," - + "delayedFlightCount MEDIUMINT UNSIGNED NOT NULL," - + "divertedFlightCount MEDIUMINT UNSIGNED NOT NULL," - + "totalFlightCount MEDIUMINT UNSIGNED NOT NULL," - - + "lateAircraftDelayCount MEDIUMINT UNSIGNED NOT NULL," - + "weatherDelayCount MEDIUMINT UNSIGNED NOT NULL," - + "securityDelayCount MEDIUMINT UNSIGNED NOT NULL," - + "nationalAviationSystemDelayCount MEDIUMINT UNSIGNED NOT NULL," - + "carrierDelayCount MEDIUMINT UNSIGNED NOT NULL," - - + "lateAircraftDelayTime MEDIUMINT UNSIGNED NOT NULL," - + "weatherDelayTime MEDIUMINT UNSIGNED NOT NULL," - + "securityDelayTime MEDIUMINT UNSIGNED NOT NULL," - + "nationalAviationSystemDelayTime MEDIUMINT UNSIGNED NOT NULL," - + "carrierDelayTime MEDIUMINT UNSIGNED NOT NULL," - + "totalDelayTime MEDIUMINT UNSIGNED NOT NULL," - - + "PRIMARY KEY (airport, carrier, year, month)" - + ");"; + String query = "CREATE TABLE IF NOT EXISTS stats (" + + "airport CHAR(3)," + + "carrier CHAR(2)," + + "year YEAR," + + "month TINYINT(2) UNSIGNED," + + + "cancelledCount MEDIUMINT UNSIGNED NOT NULL," + + "onTimeCount MEDIUMINT UNSIGNED NOT NULL," + + "delayedCount MEDIUMINT UNSIGNED NOT NULL," + + "divertedCount MEDIUMINT UNSIGNED NOT NULL," + + "totalCount MEDIUMINT UNSIGNED NOT NULL," + + + "lateAircraftCount MEDIUMINT UNSIGNED NOT NULL," + + "carrierCount MEDIUMINT UNSIGNED NOT NULL," + + "weatherCount MEDIUMINT UNSIGNED NOT NULL," + + "securityCount MEDIUMINT UNSIGNED NOT NULL," + + "nationalAviationSystemCount MEDIUMINT UNSIGNED NOT NULL," + + + "lateAircraftTime MEDIUMINT UNSIGNED NOT NULL," + + "carrierTime MEDIUMINT UNSIGNED NOT NULL," + + "weatherTime MEDIUMINT UNSIGNED NOT NULL," + + "securityTime MEDIUMINT UNSIGNED NOT NULL," + + "nationalAviationSystemTime MEDIUMINT UNSIGNED NOT NULL," + + "totalTime MEDIUMINT UNSIGNED NOT NULL," + + + "PRIMARY KEY (airport, carrier, year, month)" + + ");"; try { // Get connection from pool. @@ -146,9 +148,6 @@ private void createStatsTable() throws SQLException { // Execute query. stmt = conn.createStatement(); stmt.executeUpdate(query); - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -169,22 +168,21 @@ private void createExtraStatsTable() throws SQLException { Connection conn = null; Statement stmt = null; - String query = "CREATE TABLE IF NOT EXISTS extraStats (" - + "airport1 CHAR(3)," - + "airport2 CHAR(3)," - + "carrier CHAR(2)," - + "year YEAR," - + "month TINYINT(2) UNSIGNED," + String query = "CREATE TABLE IF NOT EXISTS extraStats (" + + "airport1 CHAR(3)," + + "airport2 CHAR(3)," + + "carrier CHAR(2)," + - + "lateAircraftDelaysTimedMean SMALLINT UNSIGNED NOT NULL," - + "lateAircraftDelaysTimedMed SMALLINT UNSIGNED NOT NULL," - + "lateAircraftDelaysTimedSd FLOAT UNSIGNED NOT NULL," - + "carrierAircraftDelaysTimedMean SMALLINT UNSIGNED NOT NULL," - + "carrierAircraftDelaysTimedMed SMALLINT UNSIGNED NOT NULL," - + "carrierAircraftDelaysTimedSd FLOAT UNSIGNED NOT NULL," + "lateAircraftTimeMean FLOAT UNSIGNED NOT NULL," + + "lateAircraftTimeMedian MEDIUMINT UNSIGNED NOT NULL," + + "lateAircraftTimeSd FLOAT UNSIGNED NOT NULL," + - + "PRIMARY KEY (airport1, airport2, carrier, year, month)" - + ");"; + "carrierTimeMean FLOAT UNSIGNED NOT NULL," + + "carrierTimeMedian MEDIUMINT UNSIGNED NOT NULL," + + "carrierTimeSd FLOAT UNSIGNED NOT NULL," + + + "PRIMARY KEY (airport1, airport2, carrier)" + + ");"; try { // Get connection from pool. @@ -193,9 +191,6 @@ private void createExtraStatsTable() throws SQLException { // Execute query. stmt = conn.createStatement(); stmt.executeUpdate(query); - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -212,18 +207,12 @@ private void createExtraStatsTable() throws SQLException { } } - public void addAirport(Airport airport) throws SQLException { - List airports = new ArrayList<>(); - airports.add(airport); - addAirports(airports); - } - public void addAirports(List airports) throws SQLException { Connection conn = null; PreparedStatement stmt = null; - String query = "INSERT INTO airports (code, name)" - + "VALUES (?, ?);"; + String query = "INSERT INTO airports (code, name) " + + "VALUES (?, ?);"; try { // Get connection from pool. @@ -244,9 +233,6 @@ public void addAirports(List airports) throws SQLException { stmt.executeBatch(); } } - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -266,11 +252,11 @@ public void addAirports(List airports) throws SQLException { public List getAirports() throws SQLException { Connection conn = null; PreparedStatement stmt = null; - ResultSet rs = null; + ResultSet rs; List airports = new ArrayList<>(); - String query = "SELECT * " - + "FROM airports;"; + String query = "SELECT * " + + "FROM airports;"; try { // Get connection from pool. @@ -286,9 +272,6 @@ public List getAirports() throws SQLException { Airport airport = new Airport(code, name); airports.add(airport); } - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -307,19 +290,12 @@ public List getAirports() throws SQLException { return airports; } - - public void addCarrier(Carrier carrier) throws SQLException { - List carriers = new ArrayList<>(); - carriers.add(carrier); - addCarriers(carriers); - } - public void addCarriers(List carriers) throws SQLException { Connection conn = null; PreparedStatement stmt = null; - String query = "INSERT INTO carriers (code, name)" - + "VALUES (?, ?);"; + String query = "INSERT INTO carriers (code, name) " + + "VALUES (?, ?);"; try { // Get connection from pool. @@ -340,9 +316,6 @@ public void addCarriers(List carriers) throws SQLException { stmt.executeBatch(); } } - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -362,11 +335,11 @@ public void addCarriers(List carriers) throws SQLException { public List getCarriers() throws SQLException { Connection conn = null; PreparedStatement stmt = null; - ResultSet rs = null; + ResultSet rs; List carriers = new ArrayList<>(); - String query = "SELECT * " - + "FROM carriers;"; + String query = "SELECT * " + + "FROM carriers;"; try { // Get connection from pool. @@ -382,9 +355,6 @@ public List getCarriers() throws SQLException { Carrier carrier = new Carrier(code, name); carriers.add(carrier); } - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -403,17 +373,25 @@ public List getCarriers() throws SQLException { return carriers; } + public boolean hasAirport(Airport airport) { + return airports.containsKey(airport.getCode()); + } + + public boolean hasCarrier(Carrier carrier) { + return carriers.containsKey(carrier.getCode()); + } + public List getCarriersAtAirport(Airport airport) throws SQLException { Connection conn = null; PreparedStatement stmt = null; - ResultSet rs = null; + ResultSet rs; List carriers = new ArrayList<>(); - String query = "SELECT DISTINCT carriers.code, carriers.name " - + "FROM carriers " - + "INNER JOIN stats " - + "ON carriers.code = stats.carrier " - + "WHERE stats.airport = ?;"; + String query = "SELECT DISTINCT carriers.code, carriers.name " + + "FROM carriers " + + "INNER JOIN stats " + + "ON carriers.code = stats.carrier " + + "WHERE stats.airport = ?;"; try { // Get connection from pool. @@ -430,9 +408,6 @@ public List getCarriersAtAirport(Airport airport) throws SQLException { Carrier carrier = new Carrier(code, name); carriers.add(carrier); } - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -451,21 +426,15 @@ public List getCarriersAtAirport(Airport airport) throws SQLException { return carriers; } - public void addStatistic(Statistic statistic) throws SQLException { - List statistics = new ArrayList<>(); - statistics.add(statistic); - addStatistics(statistics); - } - public void addStatistics(List statistics) throws SQLException { Connection conn = null; PreparedStatement stmt = null; - String query = "INSERT INTO stats (airport, carrier, year, month," - + "cancelledFlightCount, onTimeFlightCount, delayedFlightCount, divertedFlightCount, totalFlightCount," - + "lateAircraftDelayCount, weatherDelayCount, securityDelayCount, nationalAviationSystemDelayCount, carrierDelayCount," - + "lateAircraftDelayTime, weatherDelayTime, securityDelayTime, nationalAviationSystemDelayTime, carrierDelayTime, totalDelayTime)" - + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; + String query = "INSERT INTO stats (airport, carrier, year, month, cancelledCount, onTimeCount, delayedCount, " + + "divertedCount, totalCount, lateAircraftCount, carrierCount, weatherCount, securityCount, " + + "nationalAviationSystemCount, lateAircraftTime, carrierTime, weatherTime, securityTime, " + + "nationalAviationSystemTime, totalTime) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; try { // Get connection from pool. @@ -476,29 +445,43 @@ public void addStatistics(List statistics) throws SQLException { int i = 0; for (Statistic statistic : statistics) { + if (!hasAirport(statistic.getAirport())) { + // Airport doesn't exist. + throw new SQLException(); + } + + if (!hasCarrier(statistic.getCarrier())) { + // Carrier doesn't exist. + throw new SQLException(); + } + + FlightData flightData = statistic.getFlightData(); + DelayData delayData = statistic.getDelayData(); + DelayTimeData delayTimeData = statistic.getDelayTimeData(); + stmt.setString(1, statistic.getAirport().getCode()); stmt.setString(2, statistic.getCarrier().getCode()); - stmt.setInt(3, statistic.getYearMonth().getYear()); - stmt.setInt(4, statistic.getYearMonth().getMonthValue()); + stmt.setInt(3, statistic.getYear()); + stmt.setInt(4, statistic.getMonth()); - stmt.setInt(5, statistic.getCancelledFlightCount()); - stmt.setInt(6, statistic.getOnTimeFlightCount()); - stmt.setInt(7, statistic.getDelayedFlightCount()); - stmt.setInt(8, statistic.getDivertedFlightCount()); - stmt.setInt(9, statistic.getTotalFlightCount()); + stmt.setInt(5, flightData.getCancelledCount()); + stmt.setInt(6, flightData.getOnTimeCount()); + stmt.setInt(7, flightData.getDelayedCount()); + stmt.setInt(8, flightData.getDivertedCount()); + stmt.setInt(9, flightData.getTotalCount()); - stmt.setInt(10, statistic.getLateAircraftDelayCount()); - stmt.setInt(11, statistic.getWeatherDelayCount()); - stmt.setInt(12, statistic.getSecurityDelayCount()); - stmt.setInt(13, statistic.getNationalAviationSystemDelayCount()); - stmt.setInt(14, statistic.getCarrierDelayCount()); + stmt.setInt(10, delayData.getLateAircraftCount()); + stmt.setInt(11, delayData.getCarrierCount()); + stmt.setInt(12, delayData.getWeatherCount()); + stmt.setInt(13, delayData.getSecurityCount()); + stmt.setInt(14, delayData.getNationalAviationSystemCount()); - stmt.setInt(15, statistic.getLateAircraftDelayTime()); - stmt.setInt(16, statistic.getWeatherDelayTime()); - stmt.setInt(17, statistic.getSecurityDelayTime()); - stmt.setInt(18, statistic.getNationalAviationSystemDelayTime()); - stmt.setInt(19, statistic.getCarrierDelayTime()); - stmt.setInt(20, statistic.getTotalDelayTime()); + stmt.setInt(15, delayTimeData.getLateAircraftTime()); + stmt.setInt(16, delayTimeData.getCarrierTime()); + stmt.setInt(17, delayTimeData.getWeatherTime()); + stmt.setInt(18, delayTimeData.getSecurityTime()); + stmt.setInt(19, delayTimeData.getNationalAviationSystemTime()); + stmt.setInt(20, delayTimeData.getTotalTime()); stmt.addBatch(); i++; @@ -507,9 +490,6 @@ public void addStatistics(List statistics) throws SQLException { stmt.executeBatch(); } } - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -526,127 +506,126 @@ public void addStatistics(List statistics) throws SQLException { } } - public void updateStatistic(Statistic statistic) throws SQLException { - List statistics = new ArrayList<>(); - statistics.add(statistic); - updateStatistics(statistics); - } - - public void updateStatistics(List statistics) throws SQLException { + public List getStatistics(Airport airport, Carrier carrier, Integer year, Integer month, + StatisticDataSelectorHelper dataSelector) throws SQLException { Connection conn = null; PreparedStatement stmt = null; + ResultSet rs; - String query = "UPDATE stats " - + "SET cancelledFlightCount = ?, onTimeFlightCount = ?, delayedFlightCount = ?, divertedFlightCount = ?, totalFlightCount = ?," - + "lateAircraftDelayCount = ?, weatherDelayCount = ?, securityDelayCount = ?, nationalAviationSystemDelayCount = ?, carrierDelayCount = ?," - + "lateAircraftDelayTime = ?, weatherDelayTime = ?, securityDelayTime = ?, nationalAviationSystemDelayTime = ?, carrierDelayTime = ?, totalDelayTime = ? " - + "WHERE airport = ? AND carrier = ? AND year = ? AND month = ?;"; + List statistics = new ArrayList<>(); - try { - // Get connection from pool. - conn = cpds.getConnection(); + String query = "SELECT "; - // Execute query. - stmt = conn.prepareStatement(query); + if (dataSelector.withAirport() && airport == null) { + query += "airport, "; + } - int i = 0; - for (Statistic statistic : statistics) { - stmt.setInt(1, statistic.getCancelledFlightCount()); - stmt.setInt(2, statistic.getOnTimeFlightCount()); - stmt.setInt(3, statistic.getDelayedFlightCount()); - stmt.setInt(4, statistic.getDivertedFlightCount()); - stmt.setInt(5, statistic.getTotalFlightCount()); - - stmt.setInt(6, statistic.getLateAircraftDelayCount()); - stmt.setInt(7, statistic.getWeatherDelayCount()); - stmt.setInt(8, statistic.getSecurityDelayCount()); - stmt.setInt(9, statistic.getNationalAviationSystemDelayCount()); - stmt.setInt(10, statistic.getCarrierDelayCount()); - - stmt.setInt(11, statistic.getLateAircraftDelayTime()); - stmt.setInt(12, statistic.getWeatherDelayTime()); - stmt.setInt(13, statistic.getSecurityDelayTime()); - stmt.setInt(14, statistic.getNationalAviationSystemDelayTime()); - stmt.setInt(15, statistic.getCarrierDelayTime()); - stmt.setInt(16, statistic.getTotalDelayTime()); - - stmt.setString(17, statistic.getAirport().getCode()); - stmt.setString(18, statistic.getCarrier().getCode()); - stmt.setInt(19, statistic.getYearMonth().getYear()); - stmt.setInt(20, statistic.getYearMonth().getMonthValue()); + if (dataSelector.withCarrier() && carrier == null) { + query += "carrier, "; + } - stmt.addBatch(); - i++; + if (dataSelector.withYear() && year == null) { + query += "year, "; + } - if (i % 1000 == 0 || i == statistics.size()) { - stmt.executeBatch(); - } + if (dataSelector.withMonth() && month == null) { + query += "month, "; + } + + if (dataSelector.withFlightData()) { + if (dataSelector.withCancelledCount()) { + query += "cancelledCount, "; } - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; - } finally { - // finally block used to close resources. - try { - if (stmt != null) stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); + + if (dataSelector.withOnTimeCount()) { + query += "onTimeCount, "; } - try { - if (conn != null) conn.close(); - } catch (SQLException e) { - e.printStackTrace(); + if (dataSelector.withDelayedCount()) { + query += "delayedCount, "; + } + + if (dataSelector.withDivertedCount()) { + query += "divertedCount, "; + } + + if (dataSelector.withTotalCount()) { + query += "totalCount, "; } } - } - public void deleteStatistic(Airport airport, Carrier carrier, YearMonth yearMonth) throws SQLException { - Connection conn = null; - PreparedStatement stmt = null; + if (dataSelector.withDelayData()) { + if (dataSelector.withLateAircraftCount()) { + query += "lateAircraftCount, "; + } - String query = "DELETE FROM stats " - + "WHERE airport = ? AND carrier = ? AND year = ? AND month = ?;"; + if (dataSelector.withCarrierCount()) { + query += "carrierCount, "; + } - try { - // Get connection from pool. - conn = cpds.getConnection(); + if (dataSelector.withWeatherCount()) { + query += "weatherCount, "; + } - // Execute query. - stmt = conn.prepareStatement(query); - stmt.setString(1, airport.getCode()); - stmt.setString(2, carrier.getCode()); - stmt.setInt(3, yearMonth.getYear()); - stmt.setInt(4, yearMonth.getMonthValue()); - stmt.executeUpdate(); - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; - } finally { - // finally block used to close resources. - try { - if (stmt != null) stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); + if (dataSelector.withSecurityCount()) { + query += "securityCount, "; } - try { - if (conn != null) conn.close(); - } catch (SQLException e) { - e.printStackTrace(); + if (dataSelector.withNationalAviationSystemCount()) { + query += "nationalAviationSystemCount, "; } } - } - public void deleteStatistics(List statistics) throws SQLException { - Connection conn = null; - PreparedStatement stmt = null; + if (dataSelector.withDelayTimeData()) { + if (dataSelector.withLateAircraftTime()) { + query += "lateAircraftTime, "; + } - String query = "DELETE FROM stats " - + "SET cancelledFlightCount = ?, onTimeFlightCount = ?, delayedFlightCount = ?, divertedFlightCount = ?, totalFlightCount = ?," - + "lateAircraftDelayCount = ?, weatherDelayCount = ?, securityDelayCount = ?, nationalAviationSystemDelayCount = ?, carrierDelayCount = ?," - + "lateAircraftDelayTime = ?, weatherDelayTime = ?, securityDelayTime = ?, nationalAviationSystemDelayTime = ?, carrierDelayTime = ?, totalDelayTime = ? " - + "WHERE airport = ? AND carrier = ? AND year = ? AND month = ?;"; + if (dataSelector.withCarrierTime()) { + query += "carrierTime, "; + } + + if (dataSelector.withWeatherTime()) { + query += "weatherTime, "; + } + + if (dataSelector.withSecurityTime()) { + query += "securityTime, "; + } + + if (dataSelector.withNationalAviationSystemTime()) { + query += "nationalAviationSystemTime, "; + } + + if (dataSelector.withTotalTime()) { + query += "totalTime, "; + } + } + + // Remove last space and comma from string. + query = query.substring(0, query.length() - 2); + + query += " FROM stats WHERE "; + + if (airport != null) { + query += "airport = ? AND "; + } + + if (carrier != null) { + query += "carrier = ? AND "; + } + + if (year != null) { + query += "year = ? AND "; + } + + if (month != null) { + query += "month = ?"; + } else { + // Remove space and AND. + query = query.substring(0, query.length() - 5); + query += ";"; + } try { // Get connection from pool. @@ -655,42 +634,156 @@ public void deleteStatistics(List statistics) throws SQLException { // Execute query. stmt = conn.prepareStatement(query); - int i = 0; - for (Statistic statistic : statistics) { - stmt.setInt(1, statistic.getCancelledFlightCount()); - stmt.setInt(2, statistic.getOnTimeFlightCount()); - stmt.setInt(3, statistic.getDelayedFlightCount()); - stmt.setInt(4, statistic.getDivertedFlightCount()); - stmt.setInt(5, statistic.getTotalFlightCount()); - - stmt.setInt(6, statistic.getLateAircraftDelayCount()); - stmt.setInt(7, statistic.getWeatherDelayCount()); - stmt.setInt(8, statistic.getSecurityDelayCount()); - stmt.setInt(9, statistic.getNationalAviationSystemDelayCount()); - stmt.setInt(10, statistic.getCarrierDelayCount()); - - stmt.setInt(11, statistic.getLateAircraftDelayTime()); - stmt.setInt(12, statistic.getWeatherDelayTime()); - stmt.setInt(13, statistic.getSecurityDelayTime()); - stmt.setInt(14, statistic.getNationalAviationSystemDelayTime()); - stmt.setInt(15, statistic.getCarrierDelayTime()); - stmt.setInt(16, statistic.getTotalDelayTime()); - - stmt.setString(17, statistic.getAirport().getCode()); - stmt.setString(18, statistic.getCarrier().getCode()); - stmt.setInt(19, statistic.getYearMonth().getYear()); - stmt.setInt(20, statistic.getYearMonth().getMonthValue()); + int i = 1; - stmt.addBatch(); - i++; + if (airport != null) { + stmt.setString(i++, airport.getCode()); + } - if (i % 1000 == 0 || i == statistics.size()) { - stmt.executeBatch(); + if (carrier != null) { + stmt.setString(i++, carrier.getCode()); + } + + if (year != null) { + stmt.setInt(i++, year); + } + + if (month != null) { + stmt.setInt(i, month); + } + + rs = stmt.executeQuery(); + + Airport tempAirport = (dataSelector.withAirport()) ? airport : null; + Carrier tempCarrier = (dataSelector.withCarrier()) ? carrier : null; + Integer tempYear = (dataSelector.withYear()) ? year : null; + Integer tempMonth = (dataSelector.withMonth()) ? month : null; + + while (rs.next()) { + FlightData flightData = null; + DelayData delayData = null; + DelayTimeData delayTimeData = null; + + if (dataSelector.withAirport() && airport == null) { + String code = rs.getString("airport"); + tempAirport = new Airport(code, airports.get(code)); + } + + if (dataSelector.withCarrier() && carrier == null) { + String code = rs.getString("carrier"); + tempCarrier = new Carrier(code, carriers.get(code)); + } + + if (dataSelector.withYear() && year == null) { + tempYear = rs.getInt("year"); + } + + if (dataSelector.withMonth() && month == null) { + tempMonth = rs.getInt("month"); + } + + if (dataSelector.withFlightData()) { + int cancelledCount = 0; + int onTimeCount = 0; + int delayedCount = 0; + int divertedCount = 0; + int totalCount = 0; + + if (dataSelector.withCancelledCount()) { + cancelledCount = rs.getInt("cancelledCount"); + } + + if (dataSelector.withOnTimeCount()) { + onTimeCount = rs.getInt("onTimeCount"); + } + + if (dataSelector.withDelayedCount()) { + delayedCount = rs.getInt("delayedCount"); + } + + if (dataSelector.withDivertedCount()) { + divertedCount = rs.getInt("divertedCount"); + } + + if (dataSelector.withTotalCount()) { + totalCount = rs.getInt("totalCount"); + } + + flightData = new FlightData(cancelledCount, onTimeCount, delayedCount, divertedCount, totalCount); } + + if (dataSelector.withDelayData()) { + int lateAircraftCount = 0; + int carrierCount = 0; + int weatherCount = 0; + int securityCount = 0; + int nationalAviationSystemCount = 0; + + if (dataSelector.withLateAircraftCount()) { + lateAircraftCount = rs.getInt("lateAircraftCount"); + } + + if (dataSelector.withCarrierCount()) { + carrierCount = rs.getInt("carrierCount"); + } + + if (dataSelector.withWeatherCount()) { + weatherCount = rs.getInt("weatherCount"); + } + + if (dataSelector.withSecurityCount()) { + securityCount = rs.getInt("securityCount"); + } + + if (dataSelector.withNationalAviationSystemCount()) { + nationalAviationSystemCount = rs.getInt("nationalAviationSystemCount"); + } + + delayData = new DelayData(lateAircraftCount, carrierCount, weatherCount, securityCount, + nationalAviationSystemCount); + } + + if (dataSelector.withDelayTimeData()) { + int lateAircraftTime = 0; + int carrierTime = 0; + int weatherTime = 0; + int securityTime = 0; + int nationalAviationSystemTime = 0; + int totalTime = 0; + + if (dataSelector.withLateAircraftTime()) { + lateAircraftTime = rs.getInt("lateAircraftTime"); + } + + if (dataSelector.withCarrierTime()) { + carrierTime = rs.getInt("carrierTime"); + } + + if (dataSelector.withWeatherTime()) { + weatherTime = rs.getInt("weatherTime"); + } + + if (dataSelector.withSecurityTime()) { + securityTime = rs.getInt("securityTime"); + } + + if (dataSelector.withNationalAviationSystemTime()) { + nationalAviationSystemTime = rs.getInt("nationalAviationSystemTime"); + } + + if (dataSelector.withTotalTime()) { + totalTime = rs.getInt("totalTime"); + } + + delayTimeData = new DelayTimeData(lateAircraftTime, carrierTime, weatherTime, securityTime, + nationalAviationSystemTime, totalTime); + } + + Statistic statistic = new Statistic(tempAirport, tempCarrier, tempYear, tempMonth, flightData, delayData, + delayTimeData); + + statistics.add(statistic); } - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -705,80 +798,97 @@ public void deleteStatistics(List statistics) throws SQLException { e.printStackTrace(); } } + + return statistics; } - - private List getStatistics(Airport airport, Carrier carrier, Integer year, Integer month) throws SQLException { + + public void updateStatistics(List statistics) throws SQLException { Connection conn = null; PreparedStatement stmt = null; - ResultSet rs = null; - List statistics = new ArrayList<>(); - String query; - - if (year != null && month != null) { - query = "SELECT * " - + "FROM stats " - + "WHERE airport = ? AND carrier = ? AND year = ? AND month = ?;"; - } else if (year != null) { - query = "SELECT * " - + "FROM stats " - + "WHERE airport = ? AND carrier = ? AND year = ?;"; - } else if (month != null) { - query = "SELECT * " - + "FROM stats " - + "WHERE airport = ? AND carrier = ? AND month = ?;"; - } else { - query = "SELECT * " - + "FROM stats " - + "WHERE airport = ? AND carrier = ?;"; - } - - try { + String query = "INSERT INTO stats (airport, carrier, year, month, cancelledCount, onTimeCount, delayedCount, " + + "divertedCount, totalCount, lateAircraftCount, carrierCount, weatherCount, securityCount, " + + "nationalAviationSystemCount, lateAircraftTime, carrierTime, weatherTime, securityTime, " + + "nationalAviationSystemTime, totalTime) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" + + "ON DUPLICATE KEY UPDATE cancelledCount = ?, onTimeCount = ?, delayedCount = ?, divertedCount = ?, " + + "totalCount = ?, lateAircraftCount = ?, carrierCount = ?, weatherCount = ?, securityCount = ?, " + + "nationalAviationSystemCount = ?, lateAircraftTime = ?, carrierTime = ?, weatherTime = ?, " + + "securityTime = ?, nationalAviationSystemTime = ?, totalTime = ?;"; + + try { // Get connection from pool. conn = cpds.getConnection(); // Execute query. stmt = conn.prepareStatement(query); - stmt.setString(1, airport.getCode()); - stmt.setString(2, carrier.getCode()); - - if (year != null) stmt.setInt(3, year); - if (month != null && year == null) { - stmt.setInt(3, month); - } else if (month != null) { - stmt.setInt(4, month); - } - - rs = stmt.executeQuery(); - while (rs.next()) { - YearMonth yearMonth = YearMonth.of(rs.getInt("year"), rs.getInt("month")); - Statistic statistic = new Statistic(airport, carrier, yearMonth); - - statistic.setCancelledFlightCount(rs.getInt("cancelledFlightCount")); - statistic.setOnTimeFlightCount(rs.getInt("onTimeFlightCount")); - statistic.setDelayedFlightCount(rs.getInt("delayedFlightCount")); - statistic.setDivertedFlightCount(rs.getInt("divertedFlightCount")); - statistic.setTotalFlightCount(rs.getInt("totalFlightCount")); - - statistic.setLateAircraftDelayCount(rs.getInt("lateAircraftDelayCount")); - statistic.setWeatherDelayCount(rs.getInt("weatherDelayCount")); - statistic.setSecurityDelayCount(rs.getInt("securityDelayCount")); - statistic.setNationalAviationSystemDelayCount(rs.getInt("nationalAviationSystemDelayCount")); - statistic.setCarrierDelayCount(rs.getInt("carrierDelayCount")); - - statistic.setLateAircraftDelayTime(rs.getInt("lateAircraftDelayTime")); - statistic.setWeatherDelayTime(rs.getInt("weatherDelayTime")); - statistic.setSecurityDelayTime(rs.getInt("securityDelayTime")); - statistic.setNationalAviationSystemDelayTime(rs.getInt("nationalAviationSystemDelayTime")); - statistic.setCarrierDelayTime(rs.getInt("carrierDelayTime")); - statistic.setTotalDelayTime(rs.getInt("totalDelayTime")); + int i = 0; + for (Statistic statistic : statistics) { + if (!airports.containsKey(statistic.getAirport().getCode())) { + // Airport doesn't exist. + throw new SQLException(); + } - statistics.add(statistic); + if (!carriers.containsKey(statistic.getCarrier().getCode())) { + // Carrier doesn't exist. + throw new SQLException(); + } + + FlightData flightData = statistic.getFlightData(); + DelayData delayData = statistic.getDelayData(); + DelayTimeData delayTimeData = statistic.getDelayTimeData(); + + stmt.setString(1, statistic.getAirport().getCode()); + stmt.setString(2, statistic.getCarrier().getCode()); + stmt.setInt(3, statistic.getYear()); + stmt.setInt(4, statistic.getMonth()); + + stmt.setInt(5, flightData.getCancelledCount()); + stmt.setInt(6, flightData.getOnTimeCount()); + stmt.setInt(7, flightData.getDelayedCount()); + stmt.setInt(8, flightData.getDivertedCount()); + stmt.setInt(9, flightData.getTotalCount()); + + stmt.setInt(10, delayData.getLateAircraftCount()); + stmt.setInt(11, delayData.getCarrierCount()); + stmt.setInt(12, delayData.getWeatherCount()); + stmt.setInt(13, delayData.getSecurityCount()); + stmt.setInt(14, delayData.getNationalAviationSystemCount()); + + stmt.setInt(15, delayTimeData.getLateAircraftTime()); + stmt.setInt(16, delayTimeData.getCarrierTime()); + stmt.setInt(17, delayTimeData.getWeatherTime()); + stmt.setInt(18, delayTimeData.getSecurityTime()); + stmt.setInt(19, delayTimeData.getNationalAviationSystemTime()); + stmt.setInt(20, delayTimeData.getTotalTime()); + + stmt.setInt(21, flightData.getCancelledCount()); + stmt.setInt(22, flightData.getOnTimeCount()); + stmt.setInt(23, flightData.getDelayedCount()); + stmt.setInt(24, flightData.getDivertedCount()); + stmt.setInt(25, flightData.getTotalCount()); + + stmt.setInt(26, delayData.getLateAircraftCount()); + stmt.setInt(27, delayData.getCarrierCount()); + stmt.setInt(28, delayData.getWeatherCount()); + stmt.setInt(29, delayData.getSecurityCount()); + stmt.setInt(30, delayData.getNationalAviationSystemCount()); + + stmt.setInt(31, delayTimeData.getLateAircraftTime()); + stmt.setInt(32, delayTimeData.getCarrierTime()); + stmt.setInt(33, delayTimeData.getWeatherTime()); + stmt.setInt(34, delayTimeData.getSecurityTime()); + stmt.setInt(35, delayTimeData.getNationalAviationSystemTime()); + stmt.setInt(36, delayTimeData.getTotalTime()); + + stmt.addBatch(); + i++; + + if (i % 1000 == 0 || i == statistics.size()) { + stmt.executeBatch(); + } } - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -793,54 +903,25 @@ private List getStatistics(Airport airport, Carrier carrier, Integer e.printStackTrace(); } } - - return statistics; } - public Statistic getStatistic(Airport airport, Carrier carrier, YearMonth yearMonth) throws SQLException { - List statistics = getStatistics(airport, carrier, yearMonth.getYear(), yearMonth.getMonthValue()); - Statistic statistic = statistics.get(0); - - return statistic; - } - - public List getStatisticsInYear(Airport airport, Carrier carrier, int year) throws SQLException { - return getStatistics(airport, carrier, year, null); - } - - public List getStatisticsInMonth(Airport airport, Carrier carrier, int month) throws SQLException { - return getStatistics(airport, carrier, null, month); - } - - public List getStatistics(Airport airport, Carrier carrier) throws SQLException { - return getStatistics(airport, carrier, null, null); - } - - - private List getStatisticsFlights(Airport airport, Carrier carrier, Integer year, Integer month) throws SQLException { + public void deleteStatistics(Airport airport, Carrier carrier, Integer year, Integer month) throws SQLException { Connection conn = null; PreparedStatement stmt = null; - ResultSet rs = null; - List statistics = new ArrayList<>(); String query; - if (year != null && month != null) { - query = "SELECT flights " - + "FROM stats " - + "WHERE airport = ? AND carrier = ? AND year = ? AND month = ? AND reason = ?;"; + query = "DELETE FROM stats " + + "WHERE airport = ? AND carrier = ? AND year = ? AND month = ?;"; } else if (year != null) { - query = "SELECT flights " - + "FROM stats " - + "WHERE airport = ? AND carrier = ? AND year = ? AND reason = ?;"; + query = "DELETE FROM stats " + + "WHERE airport = ? AND carrier = ? AND year = ?;"; } else if (month != null) { - query = "SELECT flights " - + "FROM stats " - + "WHERE airport = ? AND carrier = ? AND month = ? AND reason = ?;"; + query = "DELETE FROM stats " + + "WHERE airport = ? AND carrier = ? AND month = ?;"; } else { - query = "SELECT flights " - + "FROM stats " - + "WHERE airport = ? AND carrier = ? AND reason = ?;"; + query = "DELETE FROM stats " + + "WHERE airport = ? AND carrier = ?;"; } try { @@ -851,29 +932,13 @@ private List getStatisticsFlights(Airport airport, Carrier carrier, I stmt = conn.prepareStatement(query); stmt.setString(1, airport.getCode()); stmt.setString(2, carrier.getCode()); - if (year != null) stmt.setInt(3, year); if (month != null && year == null) { stmt.setInt(3, month); } else if (month != null) { stmt.setInt(4, month); } - - rs = stmt.executeQuery(); - - while (rs.next()) { - YearMonth yearMonth = YearMonth.of(rs.getInt("year"), rs.getInt("month")); - Statistic statistic = new Statistic(airport, carrier, yearMonth); - - statistic.setCancelledFlightCount(rs.getInt("cancelledFlightCount")); - statistic.setOnTimeFlightCount(rs.getInt("onTimeFlightCount")); - statistic.setDelayedFlightCount(rs.getInt("delayedFlightCount")); - statistic.setDivertedFlightCount(rs.getInt("divertedFlightCount")); - statistic.setTotalFlightCount(rs.getInt("totalFlightCount")); - - - statistics.add(statistic); - } + stmt.executeUpdate(); } catch (SQLException e) { // Handle errors for JDBC. throw e; @@ -891,54 +956,15 @@ private List getStatisticsFlights(Airport airport, Carrier carrier, I e.printStackTrace(); } } - - return statistics; } - public Statistic getStatisticFlights(Airport airport, Carrier carrier, YearMonth yearMonth) throws SQLException { - List statistics = getStatisticsFlights(airport, carrier, yearMonth.getYear(), yearMonth.getMonthValue()); - Statistic statistic = statistics.get(0); - - return statistic; - } - - public List getStatisticsInYearFlights(Airport airport, Carrier carrier, int year) throws SQLException { - return getStatisticsFlights(airport, carrier, year, null); - } - - public List getStatisticsInMonthFlights(Airport airport, Carrier carrier, int month) throws SQLException { - return getStatisticsFlights(airport, carrier, null, month); - } - - public List getStatisticsFlights(Airport airport, Carrier carrier) throws SQLException { - return getStatisticsFlights(airport, carrier, null, null); - } - - private List getStatisticsDelayTimes(Airport airport, Carrier carrier, Integer year, Integer month) throws SQLException { + public void addExtraStatistics(List extraStatistics) throws SQLException { Connection conn = null; PreparedStatement stmt = null; - ResultSet rs = null; - List statistics = new ArrayList<>(); - String query; - - if (year != null && month != null) { - query = "SELECT minutes-delayed " - + "FROM stats " - + "WHERE airport = ? AND carrier = ? AND year = ? AND month = ? AND reason = ?;"; - } else if (year != null) { - query = "SELECT minutes-delayed" - + "FROM stats " - + "WHERE airport = ? AND carrier = ? AND year = ? AND reason = ?;"; - } else if (month != null) { - query = "SELECT minutes-delayed " - + "FROM stats " - + "WHERE airport = ? AND carrier = ? AND month = ? AND reason = ?;"; - } else { - query = "SELECT minutes-delayed " - + "FROM stats " - + "WHERE airport = ? AND carrier = ? AND reason = ?;"; - } + String query = "INSERT INTO extraStats (airport1, airport2, carrier, lateAircraftTimeMean, " + + "lateAircraftTimeMedian, lateAircraftTimeSd, carrierTimeMean, carrierTimeMedian, carrierTimeSd) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"; try { // Get connection from pool. @@ -946,35 +972,38 @@ private List getStatisticsDelayTimes(Airport airport, Carrier carrier // Execute query. stmt = conn.prepareStatement(query); - stmt.setString(1, airport.getCode()); - stmt.setString(2, carrier.getCode()); - if (year != null) stmt.setInt(3, year); - if (month != null && year == null) { - stmt.setInt(3, month); - } else if (month != null) { - stmt.setInt(4, month); - } + int i = 0; + for (ExtraStatistic extraStatistic : extraStatistics) { + if (!hasAirport(extraStatistic.getAirport1()) || !hasAirport(extraStatistic.getAirport2())) { + // Airport 1 or 2 doesn't exist. + throw new SQLException(); + } - rs = stmt.executeQuery(); + if (!hasCarrier(extraStatistic.getCarrier())) { + // Carrier doesn't exist. + throw new SQLException(); + } - while (rs.next()) { - YearMonth yearMonth = YearMonth.of(rs.getInt("year"), rs.getInt("month")); - Statistic statistic = new Statistic(airport, carrier, yearMonth); + stmt.setString(1, extraStatistic.getAirport1().getCode()); + stmt.setString(2, extraStatistic.getAirport2().getCode()); + stmt.setString(3, extraStatistic.getCarrier().getCode()); - statistic.setLateAircraftDelayTime(rs.getInt("lateAircraftDelayTime")); - statistic.setWeatherDelayTime(rs.getInt("weatherDelayTime")); - statistic.setSecurityDelayTime(rs.getInt("securityDelayTime")); - statistic.setNationalAviationSystemDelayTime(rs.getInt("nationalAviationSystemDelayTime")); - statistic.setCarrierDelayTime(rs.getInt("carrierDelayTime")); - statistic.setTotalDelayTime(rs.getInt("totalDelayTime")); + stmt.setFloat(4, extraStatistic.getLateAircraftTimeMean()); + stmt.setFloat(5, extraStatistic.getLateAircraftTimeMedian()); + stmt.setFloat(6, extraStatistic.getLateAircraftTimeSd()); + stmt.setFloat(7, extraStatistic.getCarrierTimeMean()); + stmt.setFloat(8, extraStatistic.getCarrierTimeMedian()); + stmt.setFloat(9, extraStatistic.getCarrierTimeSd()); - statistics.add(statistic); + stmt.addBatch(); + i++; + + if (i % 1000 == 0 || i == extraStatistics.size()) { + stmt.executeBatch(); + } } - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { @@ -989,48 +1018,30 @@ private List getStatisticsDelayTimes(Airport airport, Carrier carrier e.printStackTrace(); } } - - return statistics; - } - - public Statistic getStatisticDelayTimes(Airport airport, Carrier carrier, YearMonth yearMonth) throws SQLException { - List statistics = getStatisticsFlights(airport, carrier, yearMonth.getYear(), yearMonth.getMonthValue()); - Statistic statistic = statistics.get(0); - - return statistic; - } - - public List getStatisticsInYearDelayTimes(Airport airport, Carrier carrier, int year) throws SQLException { - return getStatisticsDelayTimes(airport, carrier, year, null); - } - - public List getStatisticsInMonthDelayTimes(Airport airport, Carrier carrier, int month) throws SQLException { - return getStatisticsDelayTimes(airport, carrier, null, month); } - public List getStatisticsDelayTimes(Airport airport, Carrier carrier) throws SQLException { - return getStatisticsDelayTimes(airport, carrier, null, null); - } - - public List getExtraStatistics(Airport airport1, Airport airport2, Carrier carrier) throws SQLException { + public List getExtraStatistics(Airport airport1, Airport airport2, Carrier carrier) + throws SQLException { Connection conn = null; PreparedStatement stmt = null; - ResultSet rs = null; + ResultSet rs; List extraStatistics = new ArrayList<>(); - String query; + if (airport1 == null || airport2 == null) { + throw new SQLException(); + } + String query; if (carrier != null) { - query = "SELECT *" - + "FROM extraStats" - + "WHERE airport1 = ? AND airport2 = ? AND carrier = ?;"; + query = "SELECT * " + + "FROM extraStats " + + "WHERE airport1 = ? and airport2 = ? AND carrier = ?;"; } else { - query = "SELECT *" - + "FROM extraStats" - + "WHERE airport1 = ? AND airport2 = ?;"; + query = "SELECT * " + + "FROM extraStats " + + "WHERE airport1 = ? and airport2 = ?;"; } - try { // Get connection from pool. conn = cpds.getConnection(); @@ -1039,29 +1050,32 @@ public List getExtraStatistics(Airport airport1, Airport airport stmt = conn.prepareStatement(query); stmt.setString(1, airport1.getCode()); stmt.setString(2, airport2.getCode()); - if (carrier != null) { - stmt.setString(2, carrier.getCode()); + stmt.setString(3, carrier.getCode()); } - rs = stmt.executeQuery(); + Carrier tempCarrier = null; + while (rs.next()) { - ExtraStatistic extraStatistic = new ExtraStatistic(airport1, airport2, carrier); + if (carrier == null) { + String code = rs.getString("carrier"); + tempCarrier = new Carrier(code, carriers.get(code)); + } - extraStatistic.setLateAircraftDelaysTimedMean(rs.getInt("lateAircraftDelaysTimedMean")); - extraStatistic.setLateAircraftDelaysTimedMed(rs.getInt("lateAircraftDelaysTimedMed")); - extraStatistic.setLateAircraftDelaysTimedSd(rs.getInt("lateAircraftDelaysTimedSd")); - extraStatistic.setCarrierAircraftDelaysTimedMean(rs.getInt("carrierAircraftDelaysTimedMean")); - extraStatistic.setCarrierAircraftDelaysTimedMed(rs.getInt("carrierAircraftDelaysTimedMed")); - extraStatistic.setCarrierAircraftDelaysTimedSd(rs.getInt("carrierAircraftDelaysTimedSd")); + ExtraStatistic extraStatistic = new ExtraStatistic(airport1, airport2, tempCarrier); + + extraStatistic.setLateAircraftTimeMean(rs.getFloat("lateAircraftTimeMean")); + extraStatistic.setLateAircraftTimeMedian(rs.getFloat("lateAircraftTimeMedian")); + extraStatistic.setLateAircraftTimeSd(rs.getFloat("lateAircraftTimeSd")); + + extraStatistic.setCarrierTimeMean(rs.getFloat("carrierTimeMean")); + extraStatistic.setCarrierTimeMedian(rs.getFloat("carrierTimeMedian")); + extraStatistic.setCarrierTimeSd(rs.getFloat("carrierTimeSd")); extraStatistics.add(extraStatistic); } - } catch (SQLException e) { - // Handle errors for JDBC. - throw e; } finally { // finally block used to close resources. try { diff --git a/back-end/src/main/java/database/Test.java b/back-end/src/main/java/database/Test.java deleted file mode 100755 index ca1ef06..0000000 --- a/back-end/src/main/java/database/Test.java +++ /dev/null @@ -1,101 +0,0 @@ -package database; - -import java.beans.PropertyVetoException; -import java.sql.SQLException; -import java.time.YearMonth; -import java.util.ArrayList; -import java.util.List; - -import com.google.gson.Gson; - -import models.Airport; -import models.Carrier; -import models.Statistic; - -public class Test { - public static void main(String[] args) { - Airport airport1 = new Airport("ATL", "Atlanta, GA: Hartsfield-Jackson Atlanta International"); - Airport airport2 = new Airport("LAS", "Las Vegas, NV: McCarran International"); - - Carrier carrier1 = new Carrier("AA", "American Airlines Inc."); - Carrier carrier2 = new Carrier("B6", "JetBlue Airways"); - - YearMonth yearMonth1 = YearMonth.of(2003, 6); - - - /*Statistic stat1 = new Statistic(airport2, newCarrier, yearMonth); - stat1.setCancelledFlightCount(0); - stat1.setOnTimeFlightCount(1); - stat1.setDelayedFlightCount(2); - stat1.setDivertedFlightCount(3); - stat1.setTotalFlightCount(4); - - stat1.setLateAircraftDelayCount(5); - stat1.setCarrierDelayCount(6); - stat1.setWeatherDelayCount(7); - stat1.setSecurityDelayCount(8); - stat1.setNationalAviationSystemDelayCount(10); - - stat1.setLateAircraftDelayTime(11); - stat1.setCarrierDelayTime(12); - stat1.setWeatherDelayTime(13); - stat1.setSecurityDelayTime(14); - stat1.setNationalAviationSystemDelayTime(15); - stat1.setTotalDelayTime(16); - - Statistic stat = new Statistic(airport2, carrier, yearMonth); - stat.setCancelledFlightCount(0); - stat.setOnTimeFlightCount(1); - stat.setDelayedFlightCount(2); - stat.setDivertedFlightCount(3); - stat.setTotalFlightCount(4); - - stat.setLateAircraftDelayCount(5); - stat.setCarrierDelayCount(6); - stat.setWeatherDelayCount(7); - stat.setSecurityDelayCount(8); - stat.setNationalAviationSystemDelayCount(10); - - stat.setLateAircraftDelayTime(11); - stat.setCarrierDelayTime(12); - stat.setWeatherDelayTime(13); - stat.setSecurityDelayTime(14); - stat.setNationalAviationSystemDelayTime(15); - stat.setTotalDelayTime(16); - - List stats = new ArrayList<>(); - stats.add(stat1); - stats.add(stat);*/ - - List carriers = null; - List stats = null; - Statistic stat = null; - - try { - DatabaseConnector dbconn = new DatabaseConnector(); - - long startTime = System.nanoTime(); - stats = dbconn.getStatistics(airport1, carrier1); - long endTime = System.nanoTime(); - - long duration = (endTime - startTime); - System.out.print("Query duration: " + duration); - - dbconn.close(); - } catch (PropertyVetoException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Gson gson = new Gson(); - - for (Statistic statistic : stats) { - System.out.println(gson.toJson(statistic)); - } - - - } -} diff --git a/back-end/src/main/java/models/DelayData.java b/back-end/src/main/java/models/DelayData.java new file mode 100644 index 0000000..c3cc474 --- /dev/null +++ b/back-end/src/main/java/models/DelayData.java @@ -0,0 +1,38 @@ +package models; + +public class DelayData { + // Each field represents the number of delays for a specific reason. + private int lateAircraftCount; + private int carrierCount; + private int weatherCount; + private int securityCount; + private int nationalAviationSystemCount; + + public DelayData(int lateAircraftCount, int carrierCount, int weatherCount, int securityCount, int nationalAviationSystemCount) { + this.lateAircraftCount = lateAircraftCount; + this.carrierCount = carrierCount; + this.weatherCount = weatherCount; + this.securityCount = securityCount; + this.nationalAviationSystemCount = nationalAviationSystemCount; + } + + public int getLateAircraftCount() { + return lateAircraftCount; + } + + public int getCarrierCount() { + return carrierCount; + } + + public int getWeatherCount() { + return weatherCount; + } + + public int getSecurityCount() { + return securityCount; + } + + public int getNationalAviationSystemCount() { + return nationalAviationSystemCount; + } +} diff --git a/back-end/src/main/java/models/DelayTimeData.java b/back-end/src/main/java/models/DelayTimeData.java new file mode 100644 index 0000000..f290238 --- /dev/null +++ b/back-end/src/main/java/models/DelayTimeData.java @@ -0,0 +1,45 @@ +package models; + +public class DelayTimeData { + // Each field represents the total delay in minutes for a specific reason. + private int lateAircraftTime; + private int carrierTime; + private int weatherTime; + private int securityTime; + private int nationalAviationSystemTime; + private int totalTime; + + public DelayTimeData(int lateAircraftTime, int carrierTime, int weatherTime, int securityTime, + int nationalAviationSystemTime, int totalTime) { + this.lateAircraftTime = lateAircraftTime; + this.carrierTime = carrierTime; + this.weatherTime = weatherTime; + this.securityTime = securityTime; + this.nationalAviationSystemTime = nationalAviationSystemTime; + this.totalTime = totalTime; + } + + public int getLateAircraftTime() { + return lateAircraftTime; + } + + public int getCarrierTime() { + return carrierTime; + } + + public int getWeatherTime() { + return weatherTime; + } + + public int getSecurityTime() { + return securityTime; + } + + public int getNationalAviationSystemTime() { + return nationalAviationSystemTime; + } + + public int getTotalTime() { + return totalTime; + } +} diff --git a/back-end/src/main/java/models/ExtraStatistic.java b/back-end/src/main/java/models/ExtraStatistic.java index 09c0f0d..caf6e92 100644 --- a/back-end/src/main/java/models/ExtraStatistic.java +++ b/back-end/src/main/java/models/ExtraStatistic.java @@ -1,19 +1,19 @@ package models; - public class ExtraStatistic { private Airport airport1; private Airport airport2; private Carrier carrier; - // Extra stats - private double lateAircraftDelaysTimedMean; - private double lateAircraftDelaysTimedMed; - private double lateAircraftDelaysTimedSd; - private double carrierAircraftDelaysTimedMean; - private double carrierAircraftDelaysTimedMed; - private double carrierAircraftDelaysTimedSd; + // Late aircraft delay time extra stats. + private float lateAircraftTimeMean; + private float lateAircraftTimeMedian; + private float lateAircraftTimeSd; + // Carrier delay time extra stats. + private float carrierTimeMean; + private float carrierTimeMedian; + private float carrierTimeSd; public ExtraStatistic (Airport airport1, Airport airport2, Carrier carrier) { this.airport1 = airport1; @@ -33,51 +33,51 @@ public Carrier getCarrier() { return carrier; } - public int getLateAircraftDelaysTimedMean() { - return lateAircraftDelaysTimedMean; + public float getLateAircraftTimeMean() { + return lateAircraftTimeMean; } - public void setLateAircraftDelaysTimedMean(double lateAircraftDelaysTimedMean) { - this.lateAircraftDelaysTimedMean = lateAircraftDelaysTimedMean; + public float getLateAircraftTimeMedian() { + return lateAircraftTimeMedian; } - public int getLateAircraftDelaysTimedMed() { - return lateAircraftDelaysTimedMed; + public float getLateAircraftTimeSd() { + return lateAircraftTimeSd; } - public void setLateAircraftDelaysTimedMed(double lateAircraftDelaysTimedMed) { - this.lateAircraftDelaysTimedMed = lateAircraftDelaysTimedMed; + public float getCarrierTimeMean() { + return carrierTimeMean; } - public int getLateAircraftDelaysTimedSd() { - return lateAircraftDelaysTimedSd; + public float getCarrierTimeMedian() { + return carrierTimeMedian; } - public void setLateAircraftDelaysTimedSd(double lateAircraftDelaysTimedSd) { - this.lateAircraftDelaysTimedSd = lateAircraftDelaysTimedSd; + public float getCarrierTimeSd() { + return carrierTimeSd; } - public int getCarrierAircraftDelaysTimedMean() { - return carrierAircraftDelaysTimedMean; + public void setLateAircraftTimeMean(float lateAircraftTimeMean) { + this.lateAircraftTimeMean = lateAircraftTimeMean; } - public void setCarrierAircraftDelaysTimedMean(double carrierAircraftDelaysTimedMean) { - this.carrierAircraftDelaysTimedMean = carrierAircraftDelaysTimedMean; + public void setLateAircraftTimeMedian(float lateAircraftTimeMedian) { + this.lateAircraftTimeMedian = lateAircraftTimeMedian; } - public int getCarrierAircraftDelaysTimedMed() { - return carrierAircraftDelaysTimedMed; + public void setLateAircraftTimeSd(float lateAircraftTimeSd) { + this.lateAircraftTimeSd = lateAircraftTimeSd; } - public void setCarrierAircraftDelaysTimedMed(double carrierAircraftDelaysTimedMed) { - this.carrierAircraftDelaysTimedMed = carrierAircraftDelaysTimedMed; + public void setCarrierTimeMean(float carrierTimeMean) { + this.carrierTimeMean = carrierTimeMean; } - public int getCarrierAircraftDelaysTimedSd() { - return carrierAircraftDelaysTimedSd; + public void setCarrierTimeMedian(float carrierTimeMedian) { + this.carrierTimeMedian = carrierTimeMedian; } - public void setCarrierAircraftDelaysTimedSd(double carrierAircraftDelaysTimedSd) { - this.carrierAircraftDelaysTimedSd = carrierAircraftDelaysTimedSd; + public void setCarrierTimeSd(float carrierTimeSd) { + this.carrierTimeSd = carrierTimeSd; } } \ No newline at end of file diff --git a/back-end/src/main/java/models/FlightData.java b/back-end/src/main/java/models/FlightData.java new file mode 100644 index 0000000..6253517 --- /dev/null +++ b/back-end/src/main/java/models/FlightData.java @@ -0,0 +1,37 @@ +package models; + +public class FlightData { + private int cancelledCount; + private int onTimeCount; + private int delayedCount; + private int divertedCount; + private int totalCount; + + public FlightData(int cancelledCount, int onTimeCount, int delayedCount, int divertedCount, int totalCount) { + this.cancelledCount = cancelledCount; + this.onTimeCount = onTimeCount; + this.delayedCount = delayedCount; + this.divertedCount = divertedCount; + this.totalCount = totalCount; + } + + public int getCancelledCount() { + return cancelledCount; + } + + public int getOnTimeCount() { + return onTimeCount; + } + + public int getDelayedCount() { + return delayedCount; + } + + public int getDivertedCount() { + return divertedCount; + } + + public int getTotalCount() { + return totalCount; + } +} diff --git a/back-end/src/main/java/models/Link.java b/back-end/src/main/java/models/Link.java new file mode 100644 index 0000000..0c90688 --- /dev/null +++ b/back-end/src/main/java/models/Link.java @@ -0,0 +1,25 @@ +package models; + +public class Link { + private String href; + private String rel; + private String type; + + public Link(String href, String rel, String type) { + this.href = href; + this.rel = rel; + this.type = type; + } + + public String getHref() { + return href; + } + + public String getRel() { + return rel; + } + + public String getType() { + return type; + } +} diff --git a/back-end/src/main/java/models/Statistic.java b/back-end/src/main/java/models/Statistic.java index 05468e8..8807d9a 100755 --- a/back-end/src/main/java/models/Statistic.java +++ b/back-end/src/main/java/models/Statistic.java @@ -1,41 +1,25 @@ package models; -import java.time.YearMonth; - public class Statistic { private Airport airport; - private Airport airport1; - private Airport airport2; private Carrier carrier; - private YearMonth yearMonth; - - // Statistics about flights. - private int cancelledFlightCount; - private int onTimeFlightCount; - private int delayedFlightCount; - private int divertedFlightCount; - private int totalFlightCount; - - // Number of delays for each delay reason. - private int lateAircraftDelayCount; - private int carrierDelayCount; - private int weatherDelayCount; - private int securityDelayCount; - private int nationalAviationSystemDelayCount; - - // Total delay time in minutes for each delay reason. - private int lateAircraftDelayTime; - private int carrierDelayTime; - private int weatherDelayTime; - private int securityDelayTime; - private int nationalAviationSystemDelayTime; - private int totalDelayTime; + private Integer year; + private Integer month; - - public Statistic (Airport airport, Carrier carrier, YearMonth yearMonth) { + private FlightData flightData; + private DelayData delayData; + private DelayTimeData delayTimeData; + + public Statistic (Airport airport, Carrier carrier, Integer year, Integer month, FlightData flightData, DelayData delayData, + DelayTimeData delayTimeData) { this.airport = airport; this.carrier = carrier; - this.yearMonth = yearMonth; + this.year = year; + this.month = month; + + this.flightData = flightData; + this.delayData = delayData; + this.delayTimeData = delayTimeData; } public Airport getAirport() { @@ -46,136 +30,23 @@ public Carrier getCarrier() { return carrier; } - public YearMonth getYearMonth() { - return yearMonth; - } - - public int getCancelledFlightCount() { - return cancelledFlightCount; - } - - public void setCancelledFlightCount(int cancelledFlightCount) { - this.cancelledFlightCount = cancelledFlightCount; - } - - public int getOnTimeFlightCount() { - return onTimeFlightCount; - } - - public void setOnTimeFlightCount(int onTimeFlightCount) { - this.onTimeFlightCount = onTimeFlightCount; - } - - public int getDelayedFlightCount() { - return delayedFlightCount; - } - - public void setDelayedFlightCount(int delayedFlightCount) { - this.delayedFlightCount = delayedFlightCount; - } - - public int getDivertedFlightCount() { - return divertedFlightCount; - } - - public void setDivertedFlightCount(int divertedFlightCount) { - this.divertedFlightCount = divertedFlightCount; - } - - public int getTotalFlightCount() { - return totalFlightCount; - } - - public void setTotalFlightCount(int totalFlightCount) { - this.totalFlightCount = totalFlightCount; - } - - public int getLateAircraftDelayCount() { - return lateAircraftDelayCount; - } - - public void setLateAircraftDelayCount(int lateAircraftDelayCount) { - this.lateAircraftDelayCount = lateAircraftDelayCount; - } - - public int getCarrierDelayCount() { - return carrierDelayCount; + public Integer getYear() { + return year; } - public void setCarrierDelayCount(int carrierDelayCount) { - this.carrierDelayCount = carrierDelayCount; + public Integer getMonth() { + return month; } - public int getWeatherDelayCount() { - return weatherDelayCount; + public FlightData getFlightData() { + return flightData; } - public void setWeatherDelayCount(int weatherDelayCount) { - this.weatherDelayCount = weatherDelayCount; + public DelayData getDelayData() { + return delayData; } - public int getSecurityDelayCount() { - return securityDelayCount; + public DelayTimeData getDelayTimeData() { + return delayTimeData; } - - public void setSecurityDelayCount(int securityDelayCount) { - this.securityDelayCount = securityDelayCount; - } - - public int getNationalAviationSystemDelayCount() { - return nationalAviationSystemDelayCount; - } - - public void setNationalAviationSystemDelayCount(int nationalAviationSystemDelayCount) { - this.nationalAviationSystemDelayCount = nationalAviationSystemDelayCount; - } - - public int getLateAircraftDelayTime() { - return lateAircraftDelayTime; - } - - public void setLateAircraftDelayTime(int lateAircraftDelayTime) { - this.lateAircraftDelayTime = lateAircraftDelayTime; - } - - public int getCarrierDelayTime() { - return carrierDelayTime; - } - - public void setCarrierDelayTime(int carrierDelayTime) { - this.carrierDelayTime = carrierDelayTime; - } - - public int getWeatherDelayTime() { - return weatherDelayTime; - } - - public void setWeatherDelayTime(int weatherDelayTime) { - this.weatherDelayTime = weatherDelayTime; - } - - public int getSecurityDelayTime() { - return securityDelayTime; - } - - public void setSecurityDelayTime(int securityDelayTime) { - this.securityDelayTime = securityDelayTime; - } - - public int getNationalAviationSystemDelayTime() { - return nationalAviationSystemDelayTime; - } - - public void setNationalAviationSystemDelayTime(int nationalAviationSystemDelayTime) { - this.nationalAviationSystemDelayTime = nationalAviationSystemDelayTime; - } - - public int getTotalDelayTime() { - return totalDelayTime; - } - - public void setTotalDelayTime(int totalDelayTime) { - this.totalDelayTime = totalDelayTime; - } - } \ No newline at end of file diff --git a/back-end/src/main/java/rest/Application.java b/back-end/src/main/java/rest/Application.java index 9fe03bf..7a35390 100755 --- a/back-end/src/main/java/rest/Application.java +++ b/back-end/src/main/java/rest/Application.java @@ -1,6 +1,10 @@ package rest; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @SpringBootApplication public class Application { diff --git a/back-end/src/main/java/rest/MainRestController.java b/back-end/src/main/java/rest/MainRestController.java index 0d42337..fe17b68 100755 --- a/back-end/src/main/java/rest/MainRestController.java +++ b/back-end/src/main/java/rest/MainRestController.java @@ -1,41 +1,34 @@ package rest; -import java.beans.PropertyVetoException; +import java.io.IOException; import java.sql.SQLException; -import java.time.YearMonth; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; +import converters.StatisticDataSelectorHelper; +import models.*; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import converters.CsvConverter; import converters.JsonConverter; -import models.Airport; -import models.Carrier; -import models.Statistic; -import models.ExtraStatistic; import database.DatabaseConnector; +@CrossOrigin(origins = "http://localhost:4200") @RestController public class MainRestController { private DatabaseConnector databaseConnector; private JsonConverter jsonConverter; private CsvConverter csvConverter; + private final String URI = "http://localhost:8080/"; public MainRestController() { try { databaseConnector = new DatabaseConnector(); - } catch (PropertyVetoException | SQLException e) { + } catch (SQLException e) { e.printStackTrace(); System.exit(1); } @@ -44,359 +37,739 @@ public MainRestController() { csvConverter = new CsvConverter(); } - @GetMapping("/airports") - public ResponseEntity getAirports(@RequestHeader("Accept") String mediaType) { - List airports = null; + private StatisticDataSelectorHelper initializeDataSelector(boolean withAirport, boolean withCarrier, Integer year, + Integer month, List delayTimeTypes) { + StatisticDataSelectorHelper dataSelector; + + if (month != null && year != null) { + dataSelector = new StatisticDataSelectorHelper(withAirport, withCarrier, false, false); + } else if (year != null) { + dataSelector = new StatisticDataSelectorHelper(withAirport, withCarrier, false, true); + } else if (month != null) { + dataSelector = new StatisticDataSelectorHelper(withAirport, withCarrier, true, false); + } else { + dataSelector = new StatisticDataSelectorHelper(withAirport, withCarrier, true, true); + } + + if (delayTimeTypes != null && delayTimeTypes.isEmpty()) { + // No reasons given, select all reasons. + dataSelector.setDelayDataTimeTrue(); + } else if (delayTimeTypes != null) { + boolean lateAircraftTime = false; + boolean carrierTime = false; + boolean weatherTime = false; + boolean securityTime = false; + boolean nationalAviationSystemTime = false; + boolean totalTime = false; + + for (String delayReason : delayTimeTypes) { + switch (delayReason) { + case "late-aircraft": + lateAircraftTime = true; + break; + case "carrier": + carrierTime = true; + break; + case "weather": + weatherTime = true; + break; + case "security": + securityTime = true; + break; + case "national-aviation-system": + nationalAviationSystemTime = true; + break; + case "total": + totalTime = true; + break; + } + } + + if (!lateAircraftTime && !carrierTime && !weatherTime && !securityTime && !nationalAviationSystemTime && + !totalTime) { + // No delay types found, use all. + dataSelector.setDelayDataTimeTrue(); + } else { + dataSelector.setDelayTimeData(lateAircraftTime, carrierTime, weatherTime, securityTime, + nationalAviationSystemTime, totalTime); + } + } + + return dataSelector; + } + + private ResponseEntity createGetStatisticsResponse(String airportCode, String carrierCode, Integer year, + Integer month, String acceptHeader, + StatisticDataSelectorHelper dataSelector, + List links) { + String responseBody; + + Airport airport = null; + Carrier carrier = null; + + if (airportCode != null) { + airport = new Airport(airportCode, null); + + if (!databaseConnector.hasAirport(airport)) { + responseBody = "Airport with code " + airportCode + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + } + + if (carrierCode != null) { + carrier = new Carrier(carrierCode, null); + + if (!databaseConnector.hasCarrier(carrier)) { + responseBody = "Carrier with code " + carrierCode + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + } + + if (year != null) { + if (year < 1901) { + responseBody = "Year can not be smaller than 1901."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); + } + + if (year > Calendar.getInstance().get(Calendar.YEAR)) { + responseBody = "Year can not be greater than the current year."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); + } + } + + if (month != null) { + if (month < 1) { + responseBody = "Month can not be smaller than 1."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); + } + + if (month > 12) { + responseBody = "Month can not be greater than 12."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); + } + + if (year != null && year == Calendar.getInstance().get(Calendar.YEAR)) { + if (month > Calendar.getInstance().get(Calendar.MONTH)) { + + responseBody = "Month must be smaller than the current month."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); + } + } + } + + List statistics; try { - airports = databaseConnector.getAirports(); + statistics = databaseConnector.getStatistics(airport, carrier, year, month, dataSelector); } catch (SQLException e) { e.printStackTrace(); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); } HttpHeaders responseHeaders = new HttpHeaders(); - String responseBody; - - if (mediaType.equals("text/csv")) { + if (acceptHeader.equals("text/csv")) { responseHeaders.set("Content-Type", "text/csv"); - responseBody = csvConverter.AirportsToString(airports); + try { + responseBody = csvConverter.statisticsToString(statistics, dataSelector); + } catch (IOException e) { + e.printStackTrace(); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); + } } else { responseHeaders.set("Content-Type", "application/json"); - responseBody = jsonConverter.AirportsToString(airports); + String json = jsonConverter.statisticsToString(statistics, dataSelector); + responseBody = jsonConverter.mergeLinksAndJson(links, json); } - return new ResponseEntity(responseBody, responseHeaders, HttpStatus.OK); + return new ResponseEntity<>(responseBody, responseHeaders, HttpStatus.OK); } - @GetMapping("/carriers") - public ResponseEntity getCarriers(@RequestHeader("Accept") String mediaType) { - List carriers = null; + private ResponseEntity createGetExtraStatisticsResponse(String airportCode1, String airportCode2, + String carrierCode, String acceptHeader) { + HttpHeaders responseHeaders = new HttpHeaders(); + String responseBody; + + Airport airport1 = new Airport(airportCode1, null); + Airport airport2 = new Airport(airportCode2, null); + Carrier carrier = (carrierCode == null) ? null : new Carrier(carrierCode, null); + + if (!databaseConnector.hasAirport(airport1)) { + responseBody = "Airport with code " + airportCode1 + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + + if (!databaseConnector.hasAirport(airport2)) { + responseBody = "Airport with code " + airportCode2 + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + + if (carrier != null && !databaseConnector.hasCarrier(carrier)) { + responseBody = "Carrier with code " + carrierCode + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + + List extraStatistics; + try { - carriers = databaseConnector.getCarriers(); + extraStatistics = databaseConnector.getExtraStatistics(airport1, airport2, carrier); } catch (SQLException e) { e.printStackTrace(); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); } - HttpHeaders responseHeaders = new HttpHeaders(); - String responseBody; - - if (mediaType.equals("text/csv")) { + if (acceptHeader.equals("text/csv")) { responseHeaders.set("Content-Type", "text/csv"); - responseBody = csvConverter.CarriersToString(carriers); + try { + responseBody = csvConverter.extraStatisticsToString(extraStatistics, carrierCode == null); + } catch (IOException e) { + e.printStackTrace(); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); + } } else { - responseBody = jsonConverter.CarriersToString(carriers); responseHeaders.set("Content-Type", "application/json"); + String extraStatsJson = jsonConverter.extraStatisticsToString(extraStatistics, carrierCode == null); + responseBody = jsonConverter.mergeLinksAndJson(null, extraStatsJson); } - return new ResponseEntity(responseBody, responseHeaders, HttpStatus.OK); + return new ResponseEntity<>(responseBody, responseHeaders, HttpStatus.OK); } - @GetMapping("/airports/{airportCode}/carriers") - public ResponseEntity getCarriersAtAirport(@RequestHeader("Accept") String mediaType, @PathVariable String airportCode) { - List carriers = null; + @GetMapping("/") + public ResponseEntity getRoot() { + ArrayList links = new ArrayList<>(); + + links.add(new Link(URI + "airports/", "airports", "GET")); + links.add(new Link(URI + "carriers/", "carriers", "GET")); + + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.set("Content-Type", "application/json"); + String responseBody = jsonConverter.mergeLinksAndJson(links, null); + + return new ResponseEntity<>(responseBody, responseHeaders, HttpStatus.OK); + } + + @CrossOrigin + @GetMapping("/airports") + public ResponseEntity getAirports(@RequestHeader("Accept") String mediaType) { + HttpHeaders responseHeaders = new HttpHeaders(); + String responseBody; + List airports; + try { - carriers = databaseConnector.getCarriersAtAirport(new Airport(airportCode, null)); + airports = databaseConnector.getAirports(); } catch (SQLException e) { e.printStackTrace(); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); } - HttpHeaders responseHeaders = new HttpHeaders(); - String responseBody; - if (mediaType.equals("text/csv")) { - responseBody = csvConverter.CarriersToString(carriers); responseHeaders.set("Content-Type", "text/csv"); + try { + responseBody = csvConverter.airportsToString(airports); + } catch (IOException e) { + e.printStackTrace(); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); + } } else { - responseBody = jsonConverter.CarriersToString(carriers); responseHeaders.set("Content-Type", "application/json"); - } + String jsonAirports = jsonConverter.airportsToStringWithLinks(airports, URI + "airports/"); - return new ResponseEntity(responseBody, responseHeaders, HttpStatus.OK); - } + List links = new ArrayList<>(); + links.add(new Link(URI + "airports/carriers", "stats", "POST")); - // API POINT 4 - @GetMapping("/airports/{airportCode}/carriers/{carrierCode}/stats") - public ResponseEntity getStats(@RequestHeader("Accept") String mediaType, @PathVariable String airportCode, @PathVariable String carrierCode, - @RequestParam(value = "year", required = false) Integer year, @RequestParam(value = "month", required = false) Integer month) { - Airport airport = new Airport(airportCode, null); - Carrier carrier = new Carrier(carrierCode, null); + responseBody = jsonConverter.mergeLinksAndJson(links, jsonAirports); + } - List statistics = null; - Statistic statistic = null; + return new ResponseEntity<>(responseBody, responseHeaders, HttpStatus.OK); + } - if ((year != null && year < 2013) || (month != null && month < 1)) { - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); - } + @GetMapping("/carriers") + public ResponseEntity getCarriers(@RequestHeader("Accept") String mediaType) { + HttpHeaders responseHeaders = new HttpHeaders(); + String responseBody; + List carriers; try { - if (year != null && month != null) { - YearMonth yearMonth = YearMonth.of(year, month); - statistic = databaseConnector.getStatistic(airport, carrier, yearMonth); - } else if (year != null) { - statistics = databaseConnector.getStatisticsInYear(airport, carrier, year); - } else if (month != null) { - statistics = databaseConnector.getStatisticsInMonth(airport, carrier, month); - } else { - statistics = databaseConnector.getStatistics(airport, carrier); - } + carriers = databaseConnector.getCarriers(); } catch (SQLException e) { e.printStackTrace(); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); } - HttpHeaders responseHeaders = new HttpHeaders(); - String responseBody; - if (mediaType.equals("text/csv")) { - if (statistics != null) { - responseBody = csvConverter.StatisticsToString(statistics, false, false, true); - } else { - responseBody = csvConverter.StatisticToString(statistic, false, false, false); - } responseHeaders.set("Content-Type", "text/csv"); - } else { - if (statistics != null) { - responseBody = jsonConverter.StatisticsToString(statistics, false, false, true); - } else { - responseBody = jsonConverter.StatisticToString(statistic, false, false, false); + try { + responseBody = csvConverter.carriersToString(carriers); + } catch (IOException e) { + e.printStackTrace(); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); } + } else { responseHeaders.set("Content-Type", "application/json"); + String baseHref = URI + "carriers/"; + String jsonCarriers = jsonConverter.carriersToStringWithLinks(carriers, baseHref); + responseBody = jsonConverter.mergeLinksAndJson(null, jsonCarriers); } - return new ResponseEntity(responseBody, responseHeaders, HttpStatus.OK); + return new ResponseEntity<>(responseBody, responseHeaders, HttpStatus.OK); } + @GetMapping("/airports/{airportCode}") + public ResponseEntity getAirport(@PathVariable String airportCode) { + String responseBody; + HttpHeaders responseHeaders = new HttpHeaders(); - @PostMapping("/airports/{airportCode}/carriers/{carrierCode}/stats") - public ResponseEntity postStats(@RequestHeader("Content-Type") String mediaType, @RequestBody String data, @PathVariable String airportCode, @PathVariable String carrierCode, - @RequestParam(value = "year", required = false) Integer year, @RequestParam(value = "month", required = false) Integer month) { - Airport airport = new Airport(airportCode, null); - Carrier carrier = new Carrier(carrierCode, null); + if (!databaseConnector.hasAirport(new Airport(airportCode, null))) { + responseBody = "Airport with code " + airportCode + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } - List statistics = null; - Statistic statistic = null; + ArrayList links = new ArrayList<>(); - if ((year != null && year < 0) || (month != null && month < 1)) { - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + String baseHref = URI + "airports/" + airportCode + "/"; + links.add(new Link(baseHref + "carriers/", "carriers", "GET")); + + List airports; + try { + airports = databaseConnector.getAirports(); + } catch (SQLException e) { + e.printStackTrace(); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); } - if (mediaType.equals("text/csv")) { + for (Airport airport : airports) { + if (!airport.getCode().equals(airportCode)) { + links.add(new Link(baseHref + airport.getCode() + "/", "airport", "GET")); + } + } - } else { + responseHeaders.set("Content-Type", "application/json"); + responseBody = jsonConverter.mergeLinksAndJson(links, null); - } + return new ResponseEntity<>(responseBody, responseHeaders, HttpStatus.OK); + } - if (year != null && month != null) { - YearMonth yearMonth = YearMonth.of(year, month); - statistic = databaseConnector.getStatistic(airport, carrier, yearMonth); - } else if (year != null) { - statistics = databaseConnector.getStatisticsInYear(airport, carrier, year); - } else if (month != null) { - statistics = databaseConnector.getStatisticsInMonth(airport, carrier, month); - } else { - statistics = databaseConnector.getStatistics(airport, carrier); - } + @GetMapping("/airports/{airportCode}/carriers") + public ResponseEntity getCarriersAtAirport(@PathVariable String airportCode, + @RequestHeader("Accept") String mediaType) { + HttpHeaders responseHeaders = new HttpHeaders(); + String responseBody; + Airport airport = new Airport(airportCode, null); + if (!databaseConnector.hasAirport(airport)) { + responseBody = "Airport with code " + airportCode + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + List carriers; try { - if (year != null && month != null) { - YearMonth yearMonth = YearMonth.of(year, month); - statistic = databaseConnector.getStatistic(airport, carrier, yearMonth); - } else if (year != null) { - statistics = databaseConnector.getStatisticsInYear(airport, carrier, year); - } else if (month != null) { - statistics = databaseConnector.getStatisticsInMonth(airport, carrier, month); - } else { - statistics = databaseConnector.getStatistics(airport, carrier); - } + carriers = databaseConnector.getCarriersAtAirport(airport); } catch (SQLException e) { e.printStackTrace(); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); + } + + if (mediaType.equals("text/csv")) { + responseHeaders.set("Content-Type", "text/csv"); + try { + responseBody = csvConverter.carriersToString(carriers); + } catch (IOException e) { + e.printStackTrace(); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); + } + } else { + responseHeaders.set("Content-Type", "application/json"); + String baseHref = URI + "airports/" + airportCode + "/carriers/"; + String jsonCarriers = jsonConverter.carriersToStringWithLinks(carriers, baseHref); + responseBody = jsonConverter.mergeLinksAndJson(null, jsonCarriers); } + return new ResponseEntity<>(responseBody, responseHeaders, HttpStatus.OK); + } + + @GetMapping("/airports/{airportCode}/carriers/{carrierCode}") + public ResponseEntity getAirportCarrier(@PathVariable String airportCode, @PathVariable String carrierCode) { + ArrayList links = new ArrayList<>(); + + String baseHref = URI + "airports/" + airportCode + "/carriers/" + carrierCode + "/"; + links.add(new Link(baseHref + "stats/", "stats", "GET")); + links.add(new Link(baseHref + "stats/", "stats", "PUT")); + links.add(new Link(baseHref + "stats/", "stats", "DELETE")); + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.set("Content-Type", "application/json"); + String responseBody = jsonConverter.mergeLinksAndJson(links, null); + + return new ResponseEntity<>(responseBody, responseHeaders, HttpStatus.OK); + } + + @GetMapping("/airports/{airportCode}/carriers/{carrierCode}/stats") + public ResponseEntity getStats(@PathVariable String airportCode, @PathVariable String carrierCode, + @RequestParam(value = "year", required = false) Integer year, + @RequestParam(value = "month", required = false) Integer month, + @RequestHeader("Accept") String acceptHeader) { + StatisticDataSelectorHelper dataSelector = initializeDataSelector(false, false, year, month, null); + dataSelector.setFlightDataTrue(); + dataSelector.setDelayDataTrue(); + dataSelector.setDelayDataTimeTrue(); + + List links = new ArrayList<>(); + String baseHref = URI + "airports/" + airportCode + "/carriers/" + carrierCode + "/stats/"; + links.add(new Link(baseHref + "flight/", "flight", "GET")); + links.add(new Link(baseHref + "delay-time/", "delay-time", "GET")); + + return createGetStatisticsResponse(airportCode, carrierCode, year, month, acceptHeader, dataSelector, links); + } + + + @PostMapping("/airports/carriers/stats") + public ResponseEntity postStats(@RequestHeader("Content-Type") String mediaType, @RequestBody String data) { String responseBody; + List statistics; + if (mediaType.equals("text/csv")) { - responseHeaders.set("Content-Type", "text/csv"); - if (statistics != null) { - responseBody = csvConverter.StatisticsToString(statistics, false, false, true); - } else { - responseBody = csvConverter.StatisticToString(statistic, false, false, false); + try { + statistics = csvConverter.stringToStatistics(data, null, null, null, null); + } catch (Exception e) { + e.printStackTrace(); + responseBody = "Syntax error in CSV string."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); } } else { - if (statistics != null) { - responseBody = jsonConverter.StatisticsToString(statistics, false, false, true); - } else { - responseBody = jsonConverter.StatisticToString(statistic, false, false, false); + try { + statistics = jsonConverter.stringToStatistics(data, null, null, null, null); + } catch (Exception e) { + e.printStackTrace(); + responseBody = "Syntax error in JSON string."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); } } - return new ResponseEntity(responseBody, responseHeaders, HttpStatus.OK); + try { + databaseConnector.addStatistics(statistics); + } catch (SQLException e) { + e.printStackTrace(); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); + } + + return new ResponseEntity<>(HttpStatus.OK); } + @PutMapping("/airports/{airportCode}/carriers/{carrierCode}/stats") + public ResponseEntity putStats(@PathVariable String airportCode, @PathVariable String carrierCode, + @RequestParam(value = "year", required = false) Integer year, + @RequestParam(value = "month", required = false) Integer month, + @RequestHeader("Content-Type") String mediaType, @RequestBody String data) { + String responseBody; - //API POINT 5 - @GetMapping("/airports/{airportCode}/carriers/{carrierCode}/stats/flights") - public ResponseEntity getStatsFlights(@RequestHeader("Accept") String mediaType, @PathVariable String airportCode, @PathVariable String carrierCode, - @RequestParam(value = "year", required = false) Integer year, @RequestParam(value = "month", required = false) Integer month) { Airport airport = new Airport(airportCode, null); Carrier carrier = new Carrier(carrierCode, null); - List statistics = null; - Statistic statistic = null; + List statistics; - if ((year != null && year < 2013) || (month != null && month < 1)) { - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + if (!databaseConnector.hasAirport(airport)) { + responseBody = "Airport with code " + airportCode + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); } - try { - if (year != null && month != null) { - YearMonth yearMonth = YearMonth.of(year, month); - statistic = databaseConnector.getStatisticFlights(airport, carrier, yearMonth); - } else if (year != null) { - statistics = databaseConnector.getStatisticsInYearFlights(airport, carrier, year); - } else if (month != null) { - statistics = databaseConnector.getStatisticsInMonthFlights(airport, carrier, month); - } else { - statistics = databaseConnector.getStatisticsFlights(airport, carrier); + if (!databaseConnector.hasCarrier(carrier)) { + responseBody = "Carrier with code " + carrierCode + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + + if (year != null) { + if (year < 1901) { + responseBody = "Year can not be smaller than 1901."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); + } + + if (year > Calendar.getInstance().get(Calendar.YEAR)) { + responseBody = "Year can not be greater than the current year."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); } - } catch (SQLException e) { - e.printStackTrace(); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - HttpHeaders responseHeaders = new HttpHeaders(); - String responseBody; + if (month != null) { + if (month < 1) { + responseBody = "Month can not be smaller than 1."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); + } + + if (month > 12) { + responseBody = "Month can not be greater than 12."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); + } + + if (year != null && year == Calendar.getInstance().get(Calendar.YEAR)) { + if (month > Calendar.getInstance().get(Calendar.MONTH)) { + + responseBody = "Month must be smaller than the current month."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); + } + } + } if (mediaType.equals("text/csv")) { - if (statistics != null) { - responseBody = csvConverter.StatisticsToFlightString(statistics, false, false, true, false, false, false, true, true); - } else { - responseBody = csvConverter.StatisticToFlightString(statistic, false, false, false, false, false, false, true, true); + try { + statistics = csvConverter.stringToStatistics(data, airport, carrier, year, month); + } catch (Exception e) { + e.printStackTrace(); + responseBody = "Syntax error in CSV string."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); } - responseHeaders.set("Content-Type", "text/csv"); } else { - if (statistics != null) { - responseBody = jsonConverter.StatisticsToFlightString(statistics, false, false, true, false, false, false, true, true); - } else { - responseBody = jsonConverter.StatisticToFlightString(statistic, false, false, false, false, false, false, true, true); + try { + statistics = jsonConverter.stringToStatistics(data, airport, carrier, year, month); + } catch (Exception e) { + e.printStackTrace(); + responseBody = "Syntax error in JSON string."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); } - responseHeaders.set("Content-Type", "application/json"); } - return new ResponseEntity(responseBody, responseHeaders, HttpStatus.OK); + try { + databaseConnector.updateStatistics(statistics); + } catch (SQLException e) { + e.printStackTrace(); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); + } + + return new ResponseEntity<>(HttpStatus.OK); } + @DeleteMapping("/airports/{airportCode}/carriers/{carrierCode}/stats") + public ResponseEntity deleteStats(@PathVariable String airportCode, @PathVariable String carrierCode, + @RequestParam(value = "year", required = false) Integer year, + @RequestParam(value = "month", required = false) Integer month) { + String responseBody; - //API POINT 6 - @GetMapping("/airports/{airportCode}/carriers/{carrierCode}/stats/delay-times") - public ResponseEntity getStatsDelayTimes(@RequestHeader("Accept") String mediaType, @PathVariable String airportCode, @PathVariable String carrierCode, @RequestParam(value = "reason", required = false) String reason, - @RequestParam(value = "year", required = false) Integer year, @RequestParam(value = "month", required = false) Integer month) { Airport airport = new Airport(airportCode, null); Carrier carrier = new Carrier(carrierCode, null); - List statistics = null; - Statistic statistic = null; + if (!databaseConnector.hasAirport(airport)) { + responseBody = "Airport with code " + airportCode + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } - if ((year != null && year < 2013) || (month != null && month < 1)) { - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + if (!databaseConnector.hasCarrier(carrier)) { + responseBody = "Carrier with code " + carrierCode + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); } - try { - if (year != null && month != null) { - YearMonth yearMonth = YearMonth.of(year, month); - statistic = databaseConnector.getStatisticDelayTimes(airport, carrier, yearMonth); - } else if (year != null) { - statistics = databaseConnector.getStatisticsInYearDelayTimes(airport, carrier, year); - } else if (month != null) { - statistics = databaseConnector.getStatisticsInMonthDelayTimes(airport, carrier, month); - } else { - statistics = databaseConnector.getStatisticsDelayTimes(airport, carrier); + if (year != null) { + if (year < 1901) { + responseBody = "Year can not be smaller than 1901."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); + } + + if (year > Calendar.getInstance().get(Calendar.YEAR)) { + responseBody = "Year can not be greater than the current year."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); } - } catch (SQLException e) { - e.printStackTrace(); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - HttpHeaders responseHeaders = new HttpHeaders(); - String responseBody; + if (month != null) { + if (month < 1) { + responseBody = "Month can not be smaller than 1."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); + } - if (mediaType.equals("text/csv")) { - if (statistics != null) { - if (reason != null) { - responseBody = csvConverter.StatisticsToDelayTimeString(statistics, false, false, true, true, true, false, false, false, false); - } else { - responseBody = csvConverter.StatisticsToDelayTimeString(statistics, false, false, true, true, true, true, true, true, true); - } - } else { - if (reason != null) { - responseBody = csvConverter.StatisticsToDelayTimeString(statistics, false, false, false, true, true, false, false, false, false); - } else { - responseBody = csvConverter.StatisticsToDelayTimeString(statistics, false, false, false, true, true, true, true, true, true); - } + if (month > 12) { + responseBody = "Month can not be greater than 12."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); } - responseHeaders.set("Content-Type", "text/csv"); - } else { - if (statistics != null) { - if (reason != null) { - responseBody = jsonConverter.StatisticsToDelayTimeString(statistics, false, false, true, true, true, false, false, false, false); - } else { - responseBody = jsonConverter.StatisticsToDelayTimeString(statistics, false, false, true, true, true, true, true, true, true); - } - } else { - if (reason != null) { - responseBody = jsonConverter.StatisticsToDelayTimeString(statistics, false, false, false, true, true, false, false, false, false); - } else { - responseBody = jsonConverter.StatisticsToDelayTimeString(statistics, false, false, false, true, true, true, true, true, true); + + if (year != null && year == Calendar.getInstance().get(Calendar.YEAR)) { + if (month > Calendar.getInstance().get(Calendar.MONTH)) { + + responseBody = "Month must be smaller than the current month."; + return new ResponseEntity<>(responseBody, HttpStatus.BAD_REQUEST); } } - responseHeaders.set("Content-Type", "application/json"); } - return new ResponseEntity(responseBody, responseHeaders, HttpStatus.OK); + + try { + databaseConnector.deleteStatistics(airport, carrier, year, month); + } catch (SQLException e) { + e.printStackTrace(); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); + } + + return new ResponseEntity<>(HttpStatus.OK); + } + + @GetMapping("/airports/{airportCode}/carriers/{carrierCode}/stats/flight") + public ResponseEntity getFlightData(@PathVariable String airportCode, @PathVariable String carrierCode, + @RequestParam(value = "year", required = false) Integer year, + @RequestParam(value = "month", required = false) Integer month, + @RequestHeader("Accept") String acceptHeader) { + StatisticDataSelectorHelper dataSelector = initializeDataSelector(false, false, year, month, null); + dataSelector.setFlightData(true, true, true, false, false); + + return createGetStatisticsResponse(airportCode, carrierCode, year, month, acceptHeader, dataSelector, null); + } + + @GetMapping("/airports/carriers/stats/delay-time") + public ResponseEntity getDelayTime(@RequestParam(value = "type", required = false) List delayTypes, + @RequestParam(value = "year", required = false) Integer year, + @RequestParam(value = "month", required = false) Integer month, + @RequestHeader("Accept") String acceptHeader) { + if (delayTypes == null) { + delayTypes = new ArrayList<>(); + } + + StatisticDataSelectorHelper dataSelector = initializeDataSelector(true, true, year, month, + delayTypes); + + + return createGetStatisticsResponse(null, null, year, month, acceptHeader, dataSelector, null); } - //API POINT 7 - @GetMapping("/airports/{airportCode1}/{airportCode2}/carriers/{carrierCode}/extra-stats/delay-times") - public ResponseEntity getStatsDelayTimes(@RequestHeader("Accept") String mediaType, @PathVariable String airportCode1, @PathVariable String airportCode2, @PathVariable(required = false) String carrierCode) { + @GetMapping("/airports/{airportCode}/carriers/stats/delay-time") + public ResponseEntity getDelayTime(@PathVariable String airportCode, + @RequestParam(value = "type", required = false) List delayTypes, + @RequestParam(value = "year", required = false) Integer year, + @RequestParam(value = "month", required = false) Integer month, + @RequestHeader("Accept") String acceptHeader) { + if (delayTypes == null) { + delayTypes = new ArrayList<>(); + } + + StatisticDataSelectorHelper dataSelector = initializeDataSelector(false, true, year, month, + delayTypes); + + return createGetStatisticsResponse(airportCode, null, year, month, acceptHeader, dataSelector, null); + } + + @GetMapping("/airports/{airportCode1}/{airportCode2}") + public ResponseEntity get2Airports(@PathVariable String airportCode1, @PathVariable String airportCode2) { + String responseBody; + HttpHeaders responseHeaders = new HttpHeaders(); + Airport airport1 = new Airport(airportCode1, null); + if (!databaseConnector.hasAirport(airport1)) { + responseBody = "Airport with code " + airportCode1 + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + Airport airport2 = new Airport(airportCode2, null); - Carrier carrier = new Carrier(carrierCode, null); + if (!databaseConnector.hasAirport(airport2)) { + responseBody = "Airport with code " + airportCode2 + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + + ArrayList links = new ArrayList<>(); + + String baseHref = URI + "airports/" + airportCode1 + "/" + airportCode2 + "/"; + links.add(new Link(baseHref + "carriers/", "carriers", "GET")); + + responseHeaders.set("Content-Type", "application/json"); + responseBody = jsonConverter.mergeLinksAndJson(links, null); + + return new ResponseEntity<>(responseBody, responseHeaders, HttpStatus.OK); + } + + @GetMapping("/airports/{airportCode1}/{airportCode2}/carriers") + public ResponseEntity get2AirportsCarriers(@PathVariable String airportCode1, + @PathVariable String airportCode2) { + String responseBody; + HttpHeaders responseHeaders = new HttpHeaders(); - List extraStatistics = null; - ExtraStatistic extraStatistic = null; + Airport airport1 = new Airport(airportCode1, null); + if (!databaseConnector.hasAirport(airport1)) { + responseBody = "Airport with code " + airportCode1 + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + Airport airport2 = new Airport(airportCode2, null); + if (!databaseConnector.hasAirport(airport2)) { + responseBody = "Airport with code " + airportCode2 + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + + ArrayList links = new ArrayList<>(); + String baseHref = URI + "airports/" + airportCode1 + "/" + airportCode2 + "/carriers/"; + links.add(new Link(baseHref + "extra-stats/", "extra-stats", "GET")); + List carriers; try { - extraStatistics = databaseConnector.getExtraStatistics(airport1, airport2, carrier); + carriers = databaseConnector.getCarriers(); } catch (SQLException e) { e.printStackTrace(); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + responseBody = "Something went wrong!"; + return new ResponseEntity<>(responseBody, HttpStatus.INTERNAL_SERVER_ERROR); } - HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.set("Content-Type", "application/json"); + String jsonCarriers = jsonConverter.carriersToStringWithLinks(carriers, baseHref); + responseBody = jsonConverter.mergeLinksAndJson(links, jsonCarriers); + + return new ResponseEntity<>(responseBody, responseHeaders, HttpStatus.OK); + } + + @GetMapping("/airports/{airportCode1}/{airportCode2}/carriers/{carrierCode}") + public ResponseEntity get2AirportsCarrier(@PathVariable String airportCode1, + @PathVariable String airportCode2, + @PathVariable String carrierCode) { String responseBody; + HttpHeaders responseHeaders = new HttpHeaders(); - if (mediaType.equals("text/csv")) { - if (carrierCode != null) { - responseBody = csvConverter.ExtraStatisticsToString(extraStatistics, false, false, true); - } else { - responseBody = csvConverter.ExtraStatisticsToString(extraStatistics, false, false, false); - } - responseHeaders.set("Content-Type", "text/csv"); - } else { - if (carrierCode != null) { - responseBody = jsonConverter.ExtraStatisticsToString(extraStatistics, false, false, true); - } else { - responseBody = jsonConverter.ExtraStatisticsToString(extraStatistics, false, false, false); - } - responseHeaders.set("Content-Type", "application/json"); + Airport airport1 = new Airport(airportCode1, null); + if (!databaseConnector.hasAirport(airport1)) { + responseBody = "Airport with code " + airportCode1 + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); } + Airport airport2 = new Airport(airportCode2, null); + if (!databaseConnector.hasAirport(airport2)) { + responseBody = "Airport with code " + airportCode2 + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + + Carrier carrier = new Carrier(carrierCode, null); + if (!databaseConnector.hasCarrier(carrier)) { + responseBody = "Carrier with code " + carrierCode + " does not exist!"; + return new ResponseEntity<>(responseBody, HttpStatus.NOT_FOUND); + } + + ArrayList links = new ArrayList<>(); + + String baseHref = URI + "airports/" + airportCode1 + "/" + airportCode2 + "/carriers/" + carrierCode + "/"; + links.add(new Link(baseHref + "extra-stats/", "extra-stats", "GET")); + + responseHeaders.set("Content-Type", "application/json"); + responseBody = jsonConverter.mergeLinksAndJson(links, null); + + return new ResponseEntity<>(responseBody, responseHeaders, HttpStatus.OK); + } + + @GetMapping("/airports/{airportCode1}/{airportCode2}/carriers/extra-stats") + public ResponseEntity getExtraStats(@PathVariable String airportCode1, + @PathVariable String airportCode2, + @RequestHeader("Accept") String acceptHeader) { + return createGetExtraStatisticsResponse(airportCode1, airportCode2, null, acceptHeader); + } - return new ResponseEntity(responseBody,responseHeaders,HttpStatus.OK); + @GetMapping("/airports/{airportCode1}/{airportCode2}/carriers/{carrierCode}/extra-stats") + public ResponseEntity getExtraStats(@PathVariable String airportCode1, + @PathVariable String airportCode2, + @PathVariable(required = false) String carrierCode, + @RequestHeader("Accept") String acceptHeader) { + return createGetExtraStatisticsResponse(airportCode1, airportCode2, carrierCode, acceptHeader); } } diff --git a/back-end/src/main/java/tools/ExtraStatisticsGenerator.java b/back-end/src/main/java/tools/ExtraStatisticsGenerator.java new file mode 100644 index 0000000..6831863 --- /dev/null +++ b/back-end/src/main/java/tools/ExtraStatisticsGenerator.java @@ -0,0 +1,138 @@ +package tools; + +import java.sql.SQLException; +import java.util.*; + +import converters.StatisticDataSelectorHelper; +import database.DatabaseConnector; +import models.*; + +public class ExtraStatisticsGenerator { + + private static float computeMean(List values) { + int sum = 0; + + for (int value : values) { + sum += value; + } + + return sum / (float) values.size(); + } + + private static float computeMedian(List values) { + Collections.sort(values); + + float median; + + // get count of values + int totalElements = values.size(); + + // check if total number of scores is even + if (totalElements % 2 == 0) { + int sumOfMiddleElements = values.get(totalElements / 2) + values.get(totalElements / 2 - 1); + // calculate average of middle elements + median = sumOfMiddleElements / 2.f; + } else { + // get the middle element + median = values.get(totalElements / 2); + } + + return median; + } + + private static float computeStandardDeviation(List values, float mean) { + float sum = 0; + + for (int value : values) { + sum += (value - mean) * (value - mean); + } + + float variance = sum / values.size(); + return (float) Math.sqrt(variance); + } + + public static void main(String[] args) { + DatabaseConnector databaseConnector = null; + + List airports = null; + List carriers = null; + + try { + databaseConnector = new DatabaseConnector(); + + airports = databaseConnector.getAirports(); + carriers = databaseConnector.getCarriers(); + } catch (SQLException e) { + e.printStackTrace(); + System.exit(1); + } + + List extraStatistics = new ArrayList<>(); + + StatisticDataSelectorHelper dataSelector = new StatisticDataSelectorHelper(false, false, true, true); + dataSelector.setDelayTimeData(true, true, false, false, false, false); + + for (Carrier carrier : carriers) { + try { + for (int i=0; i < airports.size(); i++) { + List statistics1 = databaseConnector.getStatistics(airports.get(i), carrier, null, null, dataSelector); + if (statistics1.isEmpty()) { + if (airports.get(i).getCode().equals("ATL")) System.out.println(carrier.getCode()+ "JOOOS"); + continue; + } + + for (int j=i+1; j statistics2 = databaseConnector.getStatistics(airports.get(j), carrier, null, null, dataSelector); + if (statistics2.isEmpty()) { + continue; + } + + List lateAircraftTimes = new ArrayList<>(); + List carrierTimes = new ArrayList<>(); + + for (Statistic statistic : statistics1) { + lateAircraftTimes.add(statistic.getDelayTimeData().getLateAircraftTime()); + carrierTimes.add(statistic.getDelayTimeData().getCarrierTime()); + } + + for (Statistic statistic : statistics2) { + lateAircraftTimes.add(statistic.getDelayTimeData().getLateAircraftTime()); + carrierTimes.add(statistic.getDelayTimeData().getCarrierTime()); + } + + float lateAircraftTimeMean = computeMean(lateAircraftTimes); + float lateAircraftTimeMedian = computeMedian(lateAircraftTimes); + float lateAircraftTimeSd = computeStandardDeviation(lateAircraftTimes, lateAircraftTimeMean); + + float carrierTimeMean = computeMean(carrierTimes); + float carrierTimeMedian = computeMedian(carrierTimes); + float carrierTimeSd = computeStandardDeviation(carrierTimes, carrierTimeMean); + + ExtraStatistic extraStatistic = new ExtraStatistic(airports.get(i), airports.get(j), carrier); + + extraStatistic.setLateAircraftTimeMean(lateAircraftTimeMean); + extraStatistic.setLateAircraftTimeMedian(lateAircraftTimeMedian); + extraStatistic.setLateAircraftTimeSd(lateAircraftTimeSd); + + extraStatistic.setCarrierTimeMean(carrierTimeMean); + extraStatistic.setCarrierTimeMedian(carrierTimeMedian); + extraStatistic.setCarrierTimeSd(carrierTimeSd); + + extraStatistics.add(extraStatistic); + } + } + } catch (SQLException e) { + e.printStackTrace(); + System.exit(1); + } + } + + System.out.println("Computed " + extraStatistics.size() + " extra statistics."); + + try { + databaseConnector.addExtraStatistics(extraStatistics); + } catch (SQLException e) { + e.printStackTrace(); + } + } +} diff --git a/back-end/src/main/java/tools/JsonDataImporter.java b/back-end/src/main/java/tools/JsonDataImporter.java index 4c2df53..8a87422 100755 --- a/back-end/src/main/java/tools/JsonDataImporter.java +++ b/back-end/src/main/java/tools/JsonDataImporter.java @@ -1,12 +1,10 @@ package tools; -import java.beans.PropertyVetoException; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.sql.SQLException; -import java.time.YearMonth; import java.util.*; import com.google.gson.Gson; @@ -16,10 +14,7 @@ import com.google.gson.JsonObject; import database.DatabaseConnector; -import models.Airport; -import models.Carrier; -import models.ExtraStatistic; -import models.Statistic; +import models.*; public class JsonDataImporter { public static void main(String[] args) { @@ -28,8 +23,6 @@ public static void main(String[] args) { List airports = new ArrayList<>(); List carriers = new ArrayList<>(); List stats = new ArrayList<>(); - List lateAircraftDelayTimesArray = new ArrayList(); - List carrierDelayTimesArray = new ArrayList(); final String filePath = "C:\\\\Users\\Daan\\Downloads\\airlines.json"; BufferedReader bufferedReader = null; @@ -63,70 +56,48 @@ public static void main(String[] args) { JsonObject jsonTime = jsonObject.get("time").getAsJsonObject(); int year = jsonTime.get("year").getAsInt(); int month = jsonTime.get("month").getAsInt(); - YearMonth yearMonth = YearMonth.of(year, month); JsonObject jsonStatistics = jsonObject.get("statistics").getAsJsonObject(); JsonObject jsonFlightCount = jsonStatistics.get("flights").getAsJsonObject(); - int cancelledFlightCount = jsonFlightCount.get("cancelled").getAsInt(); - int onTimeFlightCount = jsonFlightCount.get("on time").getAsInt(); - int delayedFlightCount = jsonFlightCount.get("delayed").getAsInt(); - int divertedFlightCount = jsonFlightCount.get("diverted").getAsInt(); - int totalFlightCount = jsonFlightCount.get("total").getAsInt(); - - JsonObject jsonDelayCount = jsonStatistics.get("# of delays").getAsJsonObject(); - int lateAircraftDelayCount = jsonDelayCount.get("late aircraft").getAsInt(); - int weatherDelayCount = jsonDelayCount.get("weather").getAsInt(); - int securityDelayCount = jsonDelayCount.get("security").getAsInt(); - int nationalAviationSystemDelayCount = jsonDelayCount.get("national aviation system").getAsInt(); - int carrierDelayCount = jsonDelayCount.get("carrier").getAsInt(); + int cancelledCount = jsonFlightCount.get("cancelled").getAsInt(); + int onTimeCount = jsonFlightCount.get("on time").getAsInt(); + int delayedCount = jsonFlightCount.get("delayed").getAsInt(); + int divertedCount = jsonFlightCount.get("diverted").getAsInt(); + int totalCount = jsonFlightCount.get("total").getAsInt(); + FlightData flightData = new FlightData((cancelledCount > 0) ? cancelledCount:0, + (onTimeCount > 0) ? onTimeCount:0, (delayedCount > 0) ? delayedCount:0, + (divertedCount > 0) ? divertedCount:0, (totalCount > 0) ? totalCount:0); + + JsonObject jsonDelay = jsonStatistics.get("# of delays").getAsJsonObject(); + int lateAircraftCount = jsonDelay.get("late aircraft").getAsInt(); + int carrierCount = jsonDelay.get("carrier").getAsInt(); + int weatherCount = jsonDelay.get("weather").getAsInt(); + int securityCount = jsonDelay.get("security").getAsInt(); + int nationalAviationSystemCount = jsonDelay.get("national aviation system").getAsInt(); + DelayData delayData = new DelayData((lateAircraftCount > 0) ? lateAircraftCount:0, + (carrierCount > 0) ? carrierCount:0, (weatherCount > 0) ? weatherCount:0, + (securityCount > 0) ? securityCount:0, + (nationalAviationSystemCount > 0) ? nationalAviationSystemCount:0); JsonObject jsonDelayTime = jsonStatistics.get("minutes delayed").getAsJsonObject(); - int lateAircraftDelayTime = jsonDelayTime.get("late aircraft").getAsInt(); - int weatherDelayTime = jsonDelayTime.get("weather").getAsInt(); - int securityDelayTime = jsonDelayTime.get("security").getAsInt(); - int nationalAviationSystemDelayTime = jsonDelayTime.get("national aviation system").getAsInt(); - int carrierDelayTime = jsonDelayTime.get("carrier").getAsInt(); - int totalDelayTime = jsonDelayTime.get("total").getAsInt(); - - Statistic stat = new Statistic(airport, carrier, yearMonth); - stat.setCancelledFlightCount((cancelledFlightCount > 0) ? cancelledFlightCount: 0); - stat.setOnTimeFlightCount((onTimeFlightCount > 0) ? onTimeFlightCount: 0); - stat.setDelayedFlightCount((delayedFlightCount > 0) ? delayedFlightCount: 0); - stat.setDivertedFlightCount((divertedFlightCount > 0) ? divertedFlightCount: 0); - stat.setTotalFlightCount((totalFlightCount > 0) ? totalFlightCount: 0); - - stat.setLateAircraftDelayCount((lateAircraftDelayCount > 0) ? lateAircraftDelayCount: 0); - stat.setWeatherDelayCount((weatherDelayCount > 0) ? weatherDelayCount: 0); - stat.setSecurityDelayCount((securityDelayCount > 0) ? securityDelayCount: 0); - stat.setNationalAviationSystemDelayCount((nationalAviationSystemDelayCount > 0) ? nationalAviationSystemDelayCount: 0); - stat.setCarrierDelayCount((carrierDelayCount > 0) ? carrierDelayCount: 0); - - stat.setLateAircraftDelayTime((lateAircraftDelayTime > 0) ? lateAircraftDelayTime: 0); - stat.setWeatherDelayTime((weatherDelayTime > 0) ? weatherDelayTime: 0); - stat.setSecurityDelayTime((securityDelayTime > 0) ? securityDelayTime: 0); - stat.setNationalAviationSystemDelayTime((nationalAviationSystemDelayTime > 0) ? nationalAviationSystemDelayTime: 0); - stat.setCarrierDelayTime((carrierDelayTime > 0) ? carrierDelayTime: 0); - stat.setTotalDelayTime((totalDelayTime > 0) ? totalDelayTime: 0); - - stats.add(stat); - - lateAircraftDelayTimesArray.add(lateAircraftDelayTime); - carrierDelayTimesArray.add(carrierDelayTime); - - ExtraStatistic extraStatistic = new ExtraStatistic(airport, airport, carrier); - extraStatistic.setLateAircraftDelaysTimedMean(mean((ArrayList) lateAircraftDelayTimesArray)); - extraStatistic.setLateAircraftDelaysTimedMed(median((ArrayList) lateAircraftDelayTimesArray)); - extraStatistic.setLateAircraftDelaysTimedSd(standardDeviation((ArrayList) lateAircraftDelayTimesArray)); - extraStatistic.setCarrierAircraftDelaysTimedMean(mean((ArrayList) carrierDelayTimesArray)); - extraStatistic.setCarrierAircraftDelaysTimedMed(median((ArrayList) carrierDelayTimesArray)); - extraStatistic.setCarrierAircraftDelaysTimedMed(standardDeviation((ArrayList) carrierDelayTimesArray)); + int lateAircraftTime = jsonDelayTime.get("late aircraft").getAsInt(); + int carrierTime = jsonDelayTime.get("carrier").getAsInt(); + int weatherTime = jsonDelayTime.get("weather").getAsInt(); + int securityTime = jsonDelayTime.get("security").getAsInt(); + int nationalAviationSystemTime = jsonDelayTime.get("national aviation system").getAsInt(); + int totalTime = jsonDelayTime.get("total").getAsInt(); + DelayTimeData delayTimeData = new DelayTimeData((lateAircraftTime > 0) ? lateAircraftTime:0, + (carrierTime > 0) ? carrierTime:0, (weatherTime > 0) ? weatherTime:0, + (securityTime > 0) ? securityTime:0, + (nationalAviationSystemTime > 0) ? nationalAviationSystemTime:0, + (totalTime > 0) ? totalTime:0); + + Statistic statistic = new Statistic(airport, carrier, year, month, flightData, delayData, delayTimeData); + + stats.add(statistic); } - - - - for (Map.Entry item : airportsMap.entrySet()) { Airport airport = new Airport(item.getKey(), item.getValue()); airports.add(airport); @@ -138,59 +109,12 @@ public static void main(String[] args) { } try { - DatabaseConnector dbconn = new DatabaseConnector(); - dbconn.addAirports(airports); - dbconn.addCarriers(carriers); - dbconn.addStatistics(stats); - } catch (PropertyVetoException e) { - e.printStackTrace(); + DatabaseConnector databaseConnector = new DatabaseConnector(); + databaseConnector.addAirports(airports); + databaseConnector.addCarriers(carriers); + databaseConnector.addStatistics(stats); } catch (SQLException e) { e.printStackTrace(); } } - - public static double median(ArrayList values){ - Arrays.sort(new ArrayList[]{values}); - double median; - // get count of scores - int totalElements = values.size(); - // check if total number of scores is even - if (totalElements % 2 == 0) { - int sumOfMiddleElements = values.get(totalElements / 2) + values.get(totalElements / 2 - 1); - // calculate average of middle elements - median = ((double) sumOfMiddleElements) / 2; - } else { - // get the middle element - median = (double) values.get(values.size() / 2); - } - return median; - } - - public static double mean(ArrayList values){ - double mean; - int sum = 0, i; - for(double num : values) { - sum+= num; - } - mean = sum/values.size(); - return mean; - } - - public static double standardDeviation(ArrayList values) - { - double sum = 0.0, standardDeviation = 0.0; - int length = values.size(); - - for(double num : values) { - sum += num; - } - - double mean = sum/length; - - for(double num: values) { - standardDeviation += Math.pow(num - mean, 2); - } - - return Math.sqrt(standardDeviation/length); - } } diff --git a/back-end/src/main/main.iml b/back-end/src/main/main.iml deleted file mode 100644 index e8c15a0..0000000 --- a/back-end/src/main/main.iml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/back-end/src/main/web/WEB-INF/applicationContext.xml b/back-end/src/main/web/WEB-INF/applicationContext.xml deleted file mode 100644 index 142def2..0000000 --- a/back-end/src/main/web/WEB-INF/applicationContext.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/back-end/src/main/web/WEB-INF/dispatcher-servlet.xml b/back-end/src/main/web/WEB-INF/dispatcher-servlet.xml deleted file mode 100644 index 142def2..0000000 --- a/back-end/src/main/web/WEB-INF/dispatcher-servlet.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/back-end/src/main/web/WEB-INF/web.xml b/back-end/src/main/web/WEB-INF/web.xml deleted file mode 100644 index 7483b1f..0000000 --- a/back-end/src/main/web/WEB-INF/web.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - contextConfigLocation - /WEB-INF/applicationContext.xml - - - org.springframework.web.context.ContextLoaderListener - - - dispatcher - org.springframework.web.servlet.DispatcherServlet - 1 - - - dispatcher - *.form - - \ No newline at end of file diff --git a/back-end/src/main/web/index.jsp b/back-end/src/main/web/index.jsp deleted file mode 100644 index 1562c13..0000000 --- a/back-end/src/main/web/index.jsp +++ /dev/null @@ -1,16 +0,0 @@ -<%-- - Created by IntelliJ IDEA. - User: emanuelnae - Date: 2019-03-21 - Time: 12:22 - To change this template use File | Settings | File Templates. ---%> -<%@ page contentType="text/html;charset=UTF-8" language="java" %> - - - $Title$ - - - $END$ - - diff --git a/docs/Final_Report.pdf b/docs/Final_Report.pdf new file mode 100644 index 0000000..8dcc6ab Binary files /dev/null and b/docs/Final_Report.pdf differ diff --git a/front-end/.idea/encodings.xml b/front-end/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/front-end/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/front-end/.idea/front-end.iml b/front-end/.idea/front-end.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/front-end/.idea/front-end.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/front-end/.idea/modules.xml b/front-end/.idea/modules.xml new file mode 100644 index 0000000..87428d4 --- /dev/null +++ b/front-end/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/front-end/.idea/vcs.xml b/front-end/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/front-end/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/front-end/.idea/workspace.xml b/front-end/.idea/workspace.xml new file mode 100644 index 0000000..6812fc4 --- /dev/null +++ b/front-end/.idea/workspace.xml @@ -0,0 +1,208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ +
+ {{error}} +
+ +
    +
  • + Code: {{c.carrier.code}} +
    + Name: {{c.carrier.name}} +
  • +
diff --git a/front-end/angular6-httpclient/src/app/carriers/carriers.component.spec.ts b/front-end/angular6-httpclient/src/app/carriers/carriers.component.spec.ts new file mode 100644 index 0000000..542f6c9 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/carriers/carriers.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CarriersComponent } from './carriers.component'; + +describe('CarriersComponent', () => { + let component: CarriersComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CarriersComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CarriersComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/front-end/angular6-httpclient/src/app/carriers/carriers.component.ts b/front-end/angular6-httpclient/src/app/carriers/carriers.component.ts new file mode 100644 index 0000000..2a4c9c4 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/carriers/carriers.component.ts @@ -0,0 +1,52 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { RestService } from '../rest.service'; + +@Component({ + selector: 'app-carriers', + templateUrl: './carriers.component.html', + styleUrls: ['./carriers.component.css'] +}) +export class CarriersComponent implements OnInit { + + carriersWithLinks:any = []; + isError:boolean = false; + error:string; + + @Input() carrierCode:string; + + constructor(public rest:RestService) { } + + ngOnInit() { + this.getCarriers(); + } + + getCarriers() { + this.rest.getCarriers().subscribe((data) => { + console.log(data); + this.carriersWithLinks = data.content; + this.isError = false; + }, err => { + console.error(err); + this.carriersWithLinks = []; + this.error = 'Error ' + err.status + ': ' + err.error; + this.isError = true; + }); + } + + getCarriersAtAirport() { + if (!this.carrierCode) { + this.getCarriers(); + } else { + this.rest.getCarriersAtAirport(this.carrierCode).subscribe((data) => { + console.log(data); + this.carriersWithLinks = data.content; + this.isError = false; + }, err => { + console.error(err); + this.carriersWithLinks = []; + this.error = 'Error ' + err.status + ': ' + err.error; + this.isError = true; + }); + } + } +} diff --git a/front-end/angular6-httpclient/src/app/delay-time-statistics/delay-time-statistics.component.css b/front-end/angular6-httpclient/src/app/delay-time-statistics/delay-time-statistics.component.css new file mode 100644 index 0000000..e69de29 diff --git a/front-end/angular6-httpclient/src/app/delay-time-statistics/delay-time-statistics.component.html b/front-end/angular6-httpclient/src/app/delay-time-statistics/delay-time-statistics.component.html new file mode 100644 index 0000000..ebeac37 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/delay-time-statistics/delay-time-statistics.component.html @@ -0,0 +1,90 @@ +Back +

Delay Time Statistics

+ +
+ +

+ +

+ +Late aircraft delay time: +
+Carrier delay time: +
+Weather delay time: +
+Security delay time: +
+National aviation system delay Time: +
+Total delay time: +
+ +

+ +
    +
  • +
    + Year: {{c.year}} +
    + +
    + Month: {{c.month}} +
    + +
    + Airport code: {{c.airport.code}}
    + Airport name: {{c.airport.name}} +
    + +
    + Carrier code: {{c.carrier.code}}
    + Carrier name: {{c.carrier.name}} +
    + + Delay time data
    +
    + Late aircraft delay time {{c.delayTimeData.lateAircraftTime}} +
    + +
    + Carrier delay time {{c.delayTimeData.carrierTime}} +
    + +
    + Weather delay time {{c.delayTimeData.weatherTime}} +
    + +
    + Security delay time {{c.delayTimeData.securityTime}} +
    + +
    + National aviation system delay time {{c.delayTimeData.nationalAviationSystemTime}} +
    + +
    + Total delay time {{c.delayTimeData.totalTime}} +
    +
  • +
diff --git a/front-end/angular6-httpclient/src/app/delay-time-statistics/delay-time-statistics.component.spec.ts b/front-end/angular6-httpclient/src/app/delay-time-statistics/delay-time-statistics.component.spec.ts new file mode 100644 index 0000000..458804b --- /dev/null +++ b/front-end/angular6-httpclient/src/app/delay-time-statistics/delay-time-statistics.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { DelayTimeStatisticsComponent } from './delay-time-statistics.component'; + +describe('DelayTimeStatisticsComponent', () => { + let component: DelayTimeStatisticsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ DelayTimeStatisticsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(DelayTimeStatisticsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/front-end/angular6-httpclient/src/app/delay-time-statistics/delay-time-statistics.component.ts b/front-end/angular6-httpclient/src/app/delay-time-statistics/delay-time-statistics.component.ts new file mode 100644 index 0000000..9bb1b81 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/delay-time-statistics/delay-time-statistics.component.ts @@ -0,0 +1,60 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { RestService } from '../rest.service'; + +@Component({ + selector: 'app-delay-time-statistics', + templateUrl: './delay-time-statistics.component.html', + styleUrls: ['./delay-time-statistics.component.css'] +}) +export class DelayTimeStatisticsComponent implements OnInit { + @Input() airportCode:string; + @Input() year:number; + @Input() month:number; + + lateAircraftTime:boolean = false; + carrierTime:boolean = false; + weatherTime:boolean = false; + securityTime:boolean = false; + nationalAviationSystemTime:boolean = false; + totalTime:boolean = false; + + content:any = []; + + constructor(public rest:RestService) { } + + ngOnInit() { + } + + updateLateAircraftTime(event) { + this.lateAircraftTime = event.target.checked; + } + + updateCarrierTime(event) { + this.carrierTime = event.target.checked; + } + + updateWeatherTime(event) { + this.weatherTime = event.target.checked; + } + + updateSecurityTime(event) { + this.securityTime = event.target.checked; + } + + updateNationalAviationSystemTime(event) { + this.nationalAviationSystemTime = event.target.checked; + } + + updateTotalTime(event) { + this.totalTime = event.target.checked; + } + + getDelayTimeData() { + this.rest.getDelayTimeData(this.airportCode, this.year, this.month, this.lateAircraftTime, this.carrierTime, + this.weatherTime, this.securityTime, this.nationalAviationSystemTime, this.totalTime).subscribe(data => { + console.log(data); + this.content = data.content; + }); + } + +} diff --git a/front-end/angular6-httpclient/src/app/extra-statistics/extra-statistics.component.css b/front-end/angular6-httpclient/src/app/extra-statistics/extra-statistics.component.css new file mode 100644 index 0000000..e69de29 diff --git a/front-end/angular6-httpclient/src/app/extra-statistics/extra-statistics.component.html b/front-end/angular6-httpclient/src/app/extra-statistics/extra-statistics.component.html new file mode 100644 index 0000000..ebeb952 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/extra-statistics/extra-statistics.component.html @@ -0,0 +1,31 @@ +Back +

Extra Statistics

+ +
+
+
+ +

+ +
    +
  • +
    + Carrier code: {{c.carrier.code}} +
    + Carrier name: {{c.carrier.name}} +
    + Extra statistics
    + Late aircraft delay time mean: {{c.lateAircraftTimeMean}}
    + Late aircraft delay time median: {{c.lateAircraftTimeMedian}}
    + Late aircraft delay time standard deviation: {{c.lateAircraftTimeSd}}
    + Carrier delay time mean: {{c.carrierTimeMean}}
    + Carrier delay time median: {{c.carrierTimeMedian}}
    + Carrier delay time standard deviation: {{c.carrierTimeSd}} +
  • +
diff --git a/front-end/angular6-httpclient/src/app/extra-statistics/extra-statistics.component.spec.ts b/front-end/angular6-httpclient/src/app/extra-statistics/extra-statistics.component.spec.ts new file mode 100644 index 0000000..4589b66 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/extra-statistics/extra-statistics.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ExtraStatisticsComponent } from './extra-statistics.component'; + +describe('ExtraStatisticsComponent', () => { + let component: ExtraStatisticsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ExtraStatisticsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ExtraStatisticsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/front-end/angular6-httpclient/src/app/extra-statistics/extra-statistics.component.ts b/front-end/angular6-httpclient/src/app/extra-statistics/extra-statistics.component.ts new file mode 100644 index 0000000..81a804c --- /dev/null +++ b/front-end/angular6-httpclient/src/app/extra-statistics/extra-statistics.component.ts @@ -0,0 +1,28 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { RestService } from '../rest.service'; + +@Component({ + selector: 'app-extra-statistics', + templateUrl: './extra-statistics.component.html', + styleUrls: ['./extra-statistics.component.css'] +}) +export class ExtraStatisticsComponent implements OnInit { + content:any = []; + + @Input() airportCode1:string; + @Input() airportCode2:string; + @Input() carrierCode:string; + + constructor(public rest:RestService) { } + + ngOnInit() { + } + + getExtraStats() { + this.rest.getExtraStats(this.airportCode1, this.airportCode2, this.carrierCode).subscribe(data => { + console.log(data); + this.content = data.content; + }); + } + +} diff --git a/front-end/angular6-httpclient/src/app/flight-statistics/flight-statistics.component.css b/front-end/angular6-httpclient/src/app/flight-statistics/flight-statistics.component.css new file mode 100644 index 0000000..e69de29 diff --git a/front-end/angular6-httpclient/src/app/flight-statistics/flight-statistics.component.html b/front-end/angular6-httpclient/src/app/flight-statistics/flight-statistics.component.html new file mode 100644 index 0000000..95278c2 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/flight-statistics/flight-statistics.component.html @@ -0,0 +1,50 @@ +Back +

Flight Statistics

+ +
+ +

+ +
+
+ +

+ +
    +
  • +
    + Year: {{f.year}} +
    + +
    + Month: {{f.month}} +
    + + Flight statistics
    + Cancelled flights: {{f.flightData.cancelledCount}}
    + On time flights: {{f.flightData.onTimeCount}}
    + Delayed flights: {{f.flightData.delayedCount}}
    +
  • +
diff --git a/front-end/angular6-httpclient/src/app/flight-statistics/flight-statistics.component.spec.ts b/front-end/angular6-httpclient/src/app/flight-statistics/flight-statistics.component.spec.ts new file mode 100644 index 0000000..452a704 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/flight-statistics/flight-statistics.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { FlightStatisticsComponent } from './flight-statistics.component'; + +describe('FlightStatisticsComponent', () => { + let component: FlightStatisticsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ FlightStatisticsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(FlightStatisticsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/front-end/angular6-httpclient/src/app/flight-statistics/flight-statistics.component.ts b/front-end/angular6-httpclient/src/app/flight-statistics/flight-statistics.component.ts new file mode 100644 index 0000000..792b3c8 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/flight-statistics/flight-statistics.component.ts @@ -0,0 +1,32 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { RestService } from '../rest.service'; + +@Component({ + selector: 'app-flight-statistics', + templateUrl: './flight-statistics.component.html', + styleUrls: ['./flight-statistics.component.css'] +}) +export class FlightStatisticsComponent implements OnInit { + + @Input() airportCode:string; + @Input() carrierCode:string; + @Input() year:number; + @Input() month:number; + + flightData:any = []; + + constructor(public rest:RestService) { } + + ngOnInit() { + } + + getFlightData() { + if (this.airportCode && this.carrierCode) { + this.rest.getStats(this.airportCode, this.carrierCode, this.year, this.month).subscribe(data => { + console.log(data); + this.flightData = data.content; + }); + } + } + +} diff --git a/front-end/angular6-httpclient/src/app/main/main.component.css b/front-end/angular6-httpclient/src/app/main/main.component.css new file mode 100644 index 0000000..e69de29 diff --git a/front-end/angular6-httpclient/src/app/main/main.component.html b/front-end/angular6-httpclient/src/app/main/main.component.html new file mode 100644 index 0000000..21c49ea --- /dev/null +++ b/front-end/angular6-httpclient/src/app/main/main.component.html @@ -0,0 +1,16 @@ +

US Airlines Statistics

+ + diff --git a/front-end/angular6-httpclient/src/app/main/main.component.spec.ts b/front-end/angular6-httpclient/src/app/main/main.component.spec.ts new file mode 100644 index 0000000..0878044 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/main/main.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { MainComponent } from './main.component'; + +describe('MainComponent', () => { + let component: MainComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ MainComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(MainComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/front-end/angular6-httpclient/src/app/main/main.component.ts b/front-end/angular6-httpclient/src/app/main/main.component.ts new file mode 100644 index 0000000..355d203 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/main/main.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-main', + templateUrl: './main.component.html', + styleUrls: ['./main.component.css'] +}) +export class MainComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/front-end/angular6-httpclient/src/app/rest.service.spec.ts b/front-end/angular6-httpclient/src/app/rest.service.spec.ts new file mode 100644 index 0000000..5d2ff3c --- /dev/null +++ b/front-end/angular6-httpclient/src/app/rest.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { RestService } from './rest.service'; + +describe('RestService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: RestService = TestBed.get(RestService); + expect(service).toBeTruthy(); + }); +}); diff --git a/front-end/angular6-httpclient/src/app/rest.service.ts b/front-end/angular6-httpclient/src/app/rest.service.ts new file mode 100644 index 0000000..a19744b --- /dev/null +++ b/front-end/angular6-httpclient/src/app/rest.service.ts @@ -0,0 +1,235 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Observable, of } from 'rxjs'; +import { map, catchError, tap, } from 'rxjs/operators'; + +@Injectable({ + providedIn: 'root' +}) +export class RestService { + + constructor(private http: HttpClient) { } + + endpoint = 'http://localhost:8080/'; + httpOptions = { + headers: new HttpHeaders({ + 'Content-Type': 'application/json' + }) + }; + + private extractData(res: Response) { + let body = res; + return body || { }; + } + + getAirports(): Observable { + return this.http.get(this.endpoint + 'airports').pipe( + map(this.extractData)); + } + + getCarriers(): Observable { + return this.http.get(this.endpoint + 'carriers').pipe( + map(this.extractData)); + } + + getCarriersAtAirport(airportCode): Observable { + return this.http.get(this.endpoint + 'airports/' + airportCode + '/carriers/').pipe( + map(this.extractData)); + } + + getStats(airportCode:string, carrierCode:string, year:number, month:number): Observable { + if (!year && !month) { + return this.http.get(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats').pipe( + map(this.extractData)); + } else if (!month) { + return this.http.get(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats?year=' + year).pipe( + map(this.extractData)); + } else if (!year) { + return this.http.get(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats?month=' + month).pipe( + map(this.extractData)); + } else { + return this.http.get(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats?year=' + year + '&month=' + month).pipe( + map(this.extractData)); + } + } + + addStats(data): Observable { + return this.http.post(this.endpoint + 'airports/' + 'carriers/' + 'stats/', data, this.httpOptions).pipe( + tap(() => console.log(`added stats`)), + catchError(this.handleError('addStats')) + ); + } + + updateStats(airportCode:string, carrierCode:string, year:number, month:number, data): Observable { + if (!year && !month) { + return this.http.put(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats', data, this.httpOptions).pipe( + tap(_ => console.log(`updated stats for airport code=${airportCode} and carrier code=${carrierCode}`)), + catchError(this.handleError('updateStats')) + ); + } else if (!month) { + return this.http.put(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats?year=' + year, data, this.httpOptions).pipe( + tap(_ => console.log(`updated stats for airport code=${airportCode} and carrier code=${carrierCode}`)), + catchError(this.handleError('updateStats')) + ); + } else if (!year) { + return this.http.put(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats?month=' + month, data, this.httpOptions).pipe( + tap(_ => console.log(`updated stats for airport code=${airportCode} and carrier code=${carrierCode}`)), + catchError(this.handleError('updateStats')) + ); + } else { + return this.http.put(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats?year=' + year + '&month=' + month, data, this.httpOptions).pipe( + tap(_ => console.log(`updated stats for airport code=${airportCode} and carrier code=${carrierCode}`)), + catchError(this.handleError('updateStats')) + ); + } + } + + deleteStats(airportCode:string, carrierCode:string, year:number, month:number): Observable { + if (!year && !month) { + return this.http.delete(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats').pipe( + tap(_ => console.log(`deleted stats for airport code=${airportCode} and carrier code=${carrierCode}`)), + catchError(this.handleError('deleteStats')) + ); + } else if (!month) { + return this.http.delete(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats?year=' + year).pipe( + tap(_ => console.log(`deleted stats for airport code=${airportCode} and carrier code=${carrierCode}`)), + catchError(this.handleError('deleteStats')) + ); + } else if (!year) { + return this.http.delete(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats?month=' + month).pipe( + tap(_ => console.log(`deleted stats for airport code=${airportCode} and carrier code=${carrierCode}`)), + catchError(this.handleError('deleteStats')) + ); + } else { + return this.http.delete(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats?year=' + year + '&month=' + month).pipe( + tap(_ => console.log(`deleted stats for airport code=${airportCode} and carrier code=${carrierCode}`)), + catchError(this.handleError('deleteProduct')) + ); + } + } + + getFlightData(airportCode:string, carrierCode:string, year:number, month:number): Observable { + if (!year && !month) { + return this.http.get(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats/flight').pipe( + map(this.extractData)); + } else if (!month) { + return this.http.get(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats/flight?year=' + year).pipe( + map(this.extractData)); + } else if (!year) { + return this.http.get(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats/flight?month=' + month).pipe( + map(this.extractData)); + } else { + return this.http.get(this.endpoint + 'airports/' + airportCode + '/carriers/' + carrierCode + '/stats/flight?year=' + year + '&month=' + month).pipe( + map(this.extractData)); + } + } + + getDelayTimeData(airportCode:string, year:number, month:number, lateAircraft:boolean, carrier:boolean, weather:boolean, + security:boolean, nationalAviationSystem:boolean,total:boolean): Observable { + let url = this.endpoint + 'airports/carriers/stats/delay-time?'; + if (airportCode) { + url = this.endpoint + 'airports/' + airportCode + '/carriers/stats/delay-time?'; + } + + let prefix = false; + + if (year && month) { + url += 'year=' + year + '&month=' + month; + prefix = true; + } else if (year && !month) { + url += 'year=' + year; + prefix = true; + } else if (!year && month) { + url += 'month=' + month; + prefix = true; + } + + if (prefix && (lateAircraft || carrier || weather || security || nationalAviationSystem || total)) { + url += '&type='; + } + + let previousType = false; + + if (lateAircraft) { + url += 'late-aircraft'; + previousType = true; + } + + if (carrier) { + if (previousType) { + url += ',carrier'; + } else { + url += 'carrier'; + previousType = true; + } + } + + if (weather) { + if (previousType) { + url += ',weather'; + } else { + url += 'weather'; + previousType = true; + } + } + + if (security) { + if (previousType) { + url += ',security'; + } else { + url += 'security'; + previousType = true; + } + } + + if (nationalAviationSystem) { + if (previousType) { + url += ',national-aviation-system'; + } else { + url += 'national-aviation-system'; + previousType = true; + } + } + + if (total) { + if (previousType) { + url += ',total'; + } else { + url += 'total'; + previousType = true; + } + } + + return this.http.get(url).pipe( + map(this.extractData)); + } + + getExtraStats(airportCode1:string, airportCode2:string, carrierCode:string): Observable { + let url = this.endpoint + 'airports/' + airportCode1 + '/' + airportCode2 + '/carriers/extra-stats'; + if (carrierCode) { + url = this.endpoint + 'airports/' + airportCode1 + '/' + airportCode2 + '/carriers/' + carrierCode + '/extra-stats'; + } + + return this.http.get(url).pipe( + map(this.extractData)); + } + + getExtraStatsCarrier(airportCode1, airportCode2, carrierCode): Observable { + return this.http.get(this.endpoint + 'airports/' + airportCode1 + '/' + airportCode2 + '/carriers/' + carrierCode +'/extra-stats/').pipe( + map(this.extractData)); + } + + private handleError (operation = 'operation', result?: T) { + return (error: any): Observable => { + + // TODO: send the error to remote logging infrastructure + console.error(error); // log to console instead + + // TODO: better job of transforming error for user consumption + console.log(`${operation} failed: ${error.message}`); + + // Let the app keep running by returning an empty result. + return of(result as T); + }; + } +} diff --git a/front-end/angular6-httpclient/src/app/stats/stats.component.css b/front-end/angular6-httpclient/src/app/stats/stats.component.css new file mode 100644 index 0000000..e69de29 diff --git a/front-end/angular6-httpclient/src/app/stats/stats.component.html b/front-end/angular6-httpclient/src/app/stats/stats.component.html new file mode 100644 index 0000000..8e65c31 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/stats/stats.component.html @@ -0,0 +1,157 @@ +Back + +

Statistics

+ +Add/update statistics: +

+ +
+ +

+ +
+ + +
+
+ Flight statistics
+
+ +
+ +
+ +
+ +

+ + Delay statistics
+
+ +
+ +
+ +
+ +

+ + Delay time statistics
+
+ +
+ +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
    +
  • +
    + Year: {{s.year}} +
    + +
    + Month: {{s.month}} +

    + + Flight statistics
    + Cancelled flights: {{s.flightData.cancelledCount}}
    + On time flights: {{s.flightData.onTimeCount}}
    + Delayed flights: {{s.flightData.delayedCount}}
    + Diverted flights: {{s.flightData.divertedCount}}
    + Total flights: {{s.flightData.totalCount}}

    + + Delay statistics
    + Late aircraf delays: {{s.delayData.lateAircraftCount}}
    + Carrier delays: {{s.delayData.carrierCount}}
    + Weather delays: {{s.delayData.weatherCount}}
    + Security delays: {{s.delayData.securityCount}}
    + National aviation system delays: {{s.delayData.nationalAviationSystemCount}}

    + + Delay time statistics
    + Late aircraf delay time: {{s.delayTimeData.lateAircraftTime}}
    + Carrier delay time: {{s.delayTimeData.carrierTime}}
    + Weather delay time: {{s.delayTimeData.weatherTime}}
    + Security delay time: {{s.delayTimeData.securityTime}}
    + National aviation system delay time: {{s.delayTimeData.nationalAviationSystemTime}}
    + Total delay time: {{s.delayTimeData.totalTime}}

    +
  • +
diff --git a/front-end/angular6-httpclient/src/app/stats/stats.component.spec.ts b/front-end/angular6-httpclient/src/app/stats/stats.component.spec.ts new file mode 100644 index 0000000..9b880a4 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/stats/stats.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { StatsComponent } from './stats.component'; + +describe('StatsComponent', () => { + let component: StatsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ StatsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(StatsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/front-end/angular6-httpclient/src/app/stats/stats.component.ts b/front-end/angular6-httpclient/src/app/stats/stats.component.ts new file mode 100644 index 0000000..8291397 --- /dev/null +++ b/front-end/angular6-httpclient/src/app/stats/stats.component.ts @@ -0,0 +1,108 @@ +import { Component, Input } from '@angular/core'; +import { RestService } from '../rest.service'; +import { ActivatedRoute, Router } from '@angular/router'; + +@Component({ + selector: 'app-stats', + templateUrl: './stats.component.html', + styleUrls: ['./stats.component.css'] +}) +export class StatsComponent { + + addUpdate:boolean = false; + + statistics:any = []; + + cancelledCount:number = 0; + onTimeCount:number = 0; + delayedCount:number = 0; + divertedCount:number = 0; + totalCount:number = 0; + + lateAircraftCount:number = 0; + carrierCount: number = 0; + weatherCount: number = 0; + securityCount: number = 0; + nationalAviationSystemCount: number = 0; + + lateAircraftTime:number = 0; + carrierTime: number = 0; + weatherTime: number = 0; + securityTime: number = 0; + nationalAviationSystemTime: number = 0; + totalTime: number = 0; + + @Input() airportCode:string; + @Input() carrierCode:string; + @Input() year:number; + @Input() month:number; + + constructor(public rest:RestService) { } + + private toJson() { + let json = [ + { + year: this.year, + month: this.month, + airport: { + code: this.airportCode + }, + carrier: { + code: this.carrierCode + }, + flightData: { + cancelledCount: this.cancelledCount, + onTimeCount: this.onTimeCount, + delayedCount: this.delayedCount, + divertedCount: this.divertedCount, + totalCount: this.totalCount + }, + delayData: { + lateAircraftCount: this.lateAircraftCount, + carrierCount: this.carrierCount, + weatherCount: this.weatherCount, + securityCount: this.securityCount, + nationalAviationSystemCount: this.nationalAviationSystemCount + }, + delayTimeData: { + lateAircraftTime: this.lateAircraftTime, + carrierTime: this.carrierTime, + weatherTime: this.weatherTime, + securityTime: this.securityTime, + nationalAviationSystemTime: this.nationalAviationSystemTime, + totalTime: this.totalTime + } + } + ]; + return json; + } + + addUpdateStats(event) { + this.addUpdate = event.target.checked; + } + + getStatistics() { + if (this.airportCode && this.carrierCode) { + this.rest.getStats(this.airportCode, this.carrierCode, this.year, this.month).subscribe(data => { + console.log(data); + this.statistics = data.content; + }); + } + } + + addStatistics() { + this.rest.addStats(this.toJson()).subscribe(); + } + + updateStatistics() { + if (this.airportCode && this.carrierCode) { + this.rest.updateStats(this.airportCode, this. carrierCode, this.year, this.month, this.toJson()).subscribe(); + } + } + + deleteStatistics() { + if (this.airportCode && this.carrierCode) { + this.rest.deleteStats(this.airportCode, this.carrierCode, this.year, this.month).subscribe(); + } + } +} diff --git a/front-end/angular6-httpclient/src/assets/.gitkeep b/front-end/angular6-httpclient/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/front-end/angular6-httpclient/src/browserslist b/front-end/angular6-httpclient/src/browserslist new file mode 100644 index 0000000..37371cb --- /dev/null +++ b/front-end/angular6-httpclient/src/browserslist @@ -0,0 +1,11 @@ +# This file is currently used by autoprefixer to adjust CSS to support the below specified browsers +# For additional information regarding the format and rule options, please see: +# https://github.com/browserslist/browserslist#queries +# +# For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed + +> 0.5% +last 2 versions +Firefox ESR +not dead +not IE 9-11 \ No newline at end of file diff --git a/front-end/angular6-httpclient/src/environments/environment.prod.ts b/front-end/angular6-httpclient/src/environments/environment.prod.ts new file mode 100644 index 0000000..3612073 --- /dev/null +++ b/front-end/angular6-httpclient/src/environments/environment.prod.ts @@ -0,0 +1,3 @@ +export const environment = { + production: true +}; diff --git a/front-end/angular6-httpclient/src/environments/environment.ts b/front-end/angular6-httpclient/src/environments/environment.ts new file mode 100644 index 0000000..7b4f817 --- /dev/null +++ b/front-end/angular6-httpclient/src/environments/environment.ts @@ -0,0 +1,16 @@ +// This file can be replaced during build by using the `fileReplacements` array. +// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. +// The list of file replacements can be found in `angular.json`. + +export const environment = { + production: false +}; + +/* + * For easier debugging in development mode, you can import the following file + * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. + * + * This import should be commented out in production mode because it will have a negative impact + * on performance if an error is thrown. + */ +// import 'zone.js/dist/zone-error'; // Included with Angular CLI. diff --git a/front-end/angular6-httpclient/src/favicon.ico b/front-end/angular6-httpclient/src/favicon.ico new file mode 100644 index 0000000..8081c7c Binary files /dev/null and b/front-end/angular6-httpclient/src/favicon.ico differ diff --git a/front-end/angular6-httpclient/src/index.html b/front-end/angular6-httpclient/src/index.html new file mode 100644 index 0000000..961dead --- /dev/null +++ b/front-end/angular6-httpclient/src/index.html @@ -0,0 +1,14 @@ + + + + + Angular6Httpclient + + + + + + + + + diff --git a/front-end/angular6-httpclient/src/karma.conf.js b/front-end/angular6-httpclient/src/karma.conf.js new file mode 100644 index 0000000..2ef0379 --- /dev/null +++ b/front-end/angular6-httpclient/src/karma.conf.js @@ -0,0 +1,32 @@ +// Karma configuration file, see link for more information +// https://karma-runner.github.io/1.0/config/configuration-file.html + +module.exports = function (config) { + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular-devkit/build-angular'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage-istanbul-reporter'), + require('@angular-devkit/build-angular/plugins/karma') + ], + client: { + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + coverageIstanbulReporter: { + dir: require('path').join(__dirname, '../coverage/angular6-httpclient'), + reports: ['html', 'lcovonly', 'text-summary'], + fixWebpackSourcePaths: true + }, + reporters: ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false, + restartOnFileChange: true + }); +}; diff --git a/front-end/angular6-httpclient/src/main.ts b/front-end/angular6-httpclient/src/main.ts new file mode 100644 index 0000000..c7b673c --- /dev/null +++ b/front-end/angular6-httpclient/src/main.ts @@ -0,0 +1,12 @@ +import { enableProdMode } from '@angular/core'; +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; + +import { AppModule } from './app/app.module'; +import { environment } from './environments/environment'; + +if (environment.production) { + enableProdMode(); +} + +platformBrowserDynamic().bootstrapModule(AppModule) + .catch(err => console.error(err)); diff --git a/front-end/angular6-httpclient/src/polyfills.ts b/front-end/angular6-httpclient/src/polyfills.ts new file mode 100644 index 0000000..75d6393 --- /dev/null +++ b/front-end/angular6-httpclient/src/polyfills.ts @@ -0,0 +1,63 @@ +/** + * This file includes polyfills needed by Angular and is loaded before the app. + * You can add your own extra polyfills to this file. + * + * This file is divided into 2 sections: + * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. + * 2. Application imports. Files imported after ZoneJS that should be loaded before your main + * file. + * + * The current setup is for so-called "evergreen" browsers; the last versions of browsers that + * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), + * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. + * + * Learn more in https://angular.io/guide/browser-support + */ + +/*************************************************************************************************** + * BROWSER POLYFILLS + */ + +/** IE10 and IE11 requires the following for NgClass support on SVG elements */ +// import 'classlist.js'; // Run `npm install --save classlist.js`. + +/** + * Web Animations `@angular/platform-browser/animations` + * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. + * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). + */ +// import 'web-animations-js'; // Run `npm install --save web-animations-js`. + +/** + * By default, zone.js will patch all possible macroTask and DomEvents + * user can disable parts of macroTask/DomEvents patch by setting following flags + * because those flags need to be set before `zone.js` being loaded, and webpack + * will put import in the top of bundle, so user need to create a separate file + * in this directory (for example: zone-flags.ts), and put the following flags + * into that file, and then add the following code before importing zone.js. + * import './zone-flags.ts'; + * + * The flags allowed in zone-flags.ts are listed here. + * + * The following flags will work for all browsers. + * + * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame + * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick + * (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames + * + * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js + * with the following flag, it will bypass `zone.js` patch for IE/Edge + * + * (window as any).__Zone_enable_cross_context_check = true; + * + */ + +/*************************************************************************************************** + * Zone JS is required by default for Angular itself. + */ +import 'zone.js/dist/zone'; // Included with Angular CLI. + + +/*************************************************************************************************** + * APPLICATION IMPORTS + */ diff --git a/front-end/angular6-httpclient/src/styles.css b/front-end/angular6-httpclient/src/styles.css new file mode 100644 index 0000000..766a3f5 --- /dev/null +++ b/front-end/angular6-httpclient/src/styles.css @@ -0,0 +1,2 @@ +@import "~bootstrap/dist/css/bootstrap.min.css"; +@import "~font-awesome/css/font-awesome.css"; diff --git a/front-end/angular6-httpclient/src/test.ts b/front-end/angular6-httpclient/src/test.ts new file mode 100644 index 0000000..1631789 --- /dev/null +++ b/front-end/angular6-httpclient/src/test.ts @@ -0,0 +1,20 @@ +// This file is required by karma.conf.js and loads recursively all the .spec and framework files + +import 'zone.js/dist/zone-testing'; +import { getTestBed } from '@angular/core/testing'; +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting +} from '@angular/platform-browser-dynamic/testing'; + +declare const require: any; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting() +); +// Then we find all the tests. +const context = require.context('./', true, /\.spec\.ts$/); +// And load the modules. +context.keys().map(context); diff --git a/front-end/angular6-httpclient/src/tsconfig.app.json b/front-end/angular6-httpclient/src/tsconfig.app.json new file mode 100644 index 0000000..190fd30 --- /dev/null +++ b/front-end/angular6-httpclient/src/tsconfig.app.json @@ -0,0 +1,11 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "../out-tsc/app", + "types": [] + }, + "exclude": [ + "test.ts", + "**/*.spec.ts" + ] +} diff --git a/front-end/angular6-httpclient/src/tsconfig.spec.json b/front-end/angular6-httpclient/src/tsconfig.spec.json new file mode 100644 index 0000000..de77336 --- /dev/null +++ b/front-end/angular6-httpclient/src/tsconfig.spec.json @@ -0,0 +1,18 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "../out-tsc/spec", + "types": [ + "jasmine", + "node" + ] + }, + "files": [ + "test.ts", + "polyfills.ts" + ], + "include": [ + "**/*.spec.ts", + "**/*.d.ts" + ] +} diff --git a/front-end/angular6-httpclient/src/tslint.json b/front-end/angular6-httpclient/src/tslint.json new file mode 100644 index 0000000..aa7c3ee --- /dev/null +++ b/front-end/angular6-httpclient/src/tslint.json @@ -0,0 +1,17 @@ +{ + "extends": "../tslint.json", + "rules": { + "directive-selector": [ + true, + "attribute", + "app", + "camelCase" + ], + "component-selector": [ + true, + "element", + "app", + "kebab-case" + ] + } +} diff --git a/front-end/angular6-httpclient/tsconfig.json b/front-end/angular6-httpclient/tsconfig.json new file mode 100644 index 0000000..b271fd9 --- /dev/null +++ b/front-end/angular6-httpclient/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "baseUrl": "./", + "outDir": "./dist/out-tsc", + "sourceMap": true, + "declaration": false, + "module": "es2015", + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "importHelpers": true, + "target": "es5", + "typeRoots": [ + "node_modules/@types" + ], + "lib": [ + "es2018", + "dom" + ] + } +} diff --git a/front-end/angular6-httpclient/tslint.json b/front-end/angular6-httpclient/tslint.json new file mode 100644 index 0000000..868ecba --- /dev/null +++ b/front-end/angular6-httpclient/tslint.json @@ -0,0 +1,75 @@ +{ + "extends": "tslint:recommended", + "rulesDirectory": [ + "codelyzer" + ], + "rules": { + "array-type": false, + "arrow-parens": false, + "deprecation": { + "severity": "warn" + }, + "import-blacklist": [ + true, + "rxjs/Rx" + ], + "interface-name": false, + "max-classes-per-file": false, + "max-line-length": [ + true, + 140 + ], + "member-access": false, + "member-ordering": [ + true, + { + "order": [ + "static-field", + "instance-field", + "static-method", + "instance-method" + ] + } + ], + "no-consecutive-blank-lines": false, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-empty": false, + "no-inferrable-types": [ + true, + "ignore-params" + ], + "no-non-null-assertion": true, + "no-redundant-jsdoc": true, + "no-switch-case-fall-through": true, + "no-use-before-declare": true, + "no-var-requires": false, + "object-literal-key-quotes": [ + true, + "as-needed" + ], + "object-literal-sort-keys": false, + "ordered-imports": false, + "quotemark": [ + true, + "single" + ], + "trailing-comma": false, + "no-output-on-prefix": true, + "use-input-property-decorator": true, + "use-output-property-decorator": true, + "use-host-property-decorator": true, + "no-input-rename": true, + "no-output-rename": true, + "use-life-cycle-interface": true, + "use-pipe-transform-interface": true, + "component-class-suffix": true, + "directive-class-suffix": true + } +} diff --git a/lib/amqp-client-3.1.3.jar b/lib/amqp-client-3.1.3.jar deleted file mode 100644 index d658526..0000000 Binary files a/lib/amqp-client-3.1.3.jar and /dev/null differ diff --git a/lib/animal-sniffer-annotations-1.14.jar b/lib/animal-sniffer-annotations-1.14.jar deleted file mode 100644 index fb76acf..0000000 Binary files a/lib/animal-sniffer-annotations-1.14.jar and /dev/null differ diff --git a/lib/aopalliance-1.0.jar b/lib/aopalliance-1.0.jar deleted file mode 100644 index 578b1a0..0000000 Binary files a/lib/aopalliance-1.0.jar and /dev/null differ diff --git a/lib/c3p0-0.9.1.2.jar b/lib/c3p0-0.9.1.2.jar deleted file mode 100644 index 0f42d60..0000000 Binary files a/lib/c3p0-0.9.1.2.jar and /dev/null differ diff --git a/lib/checker-compat-qual-2.5.2.jar b/lib/checker-compat-qual-2.5.2.jar deleted file mode 100644 index 633d2c2..0000000 Binary files a/lib/checker-compat-qual-2.5.2.jar and /dev/null differ diff --git a/lib/commons-codec-1.10.jar b/lib/commons-codec-1.10.jar deleted file mode 100644 index 1d7417c..0000000 Binary files a/lib/commons-codec-1.10.jar and /dev/null differ diff --git a/lib/commons-logging-1.1.3.jar b/lib/commons-logging-1.1.3.jar deleted file mode 100644 index ab51254..0000000 Binary files a/lib/commons-logging-1.1.3.jar and /dev/null differ diff --git a/lib/commons-logging-1.2.jar b/lib/commons-logging-1.2.jar deleted file mode 100644 index 93a3b9f..0000000 Binary files a/lib/commons-logging-1.2.jar and /dev/null differ diff --git a/lib/error_prone_annotations-2.1.3.jar b/lib/error_prone_annotations-2.1.3.jar deleted file mode 100644 index ec3b185..0000000 Binary files a/lib/error_prone_annotations-2.1.3.jar and /dev/null differ diff --git a/lib/google-api-client-1.28.0.jar b/lib/google-api-client-1.28.0.jar deleted file mode 100644 index 450fea8..0000000 Binary files a/lib/google-api-client-1.28.0.jar and /dev/null differ diff --git a/lib/google-api-client-gson-1.28.0.jar b/lib/google-api-client-gson-1.28.0.jar deleted file mode 100644 index d52c883..0000000 Binary files a/lib/google-api-client-gson-1.28.0.jar and /dev/null differ diff --git a/lib/google-http-client-1.28.0.jar b/lib/google-http-client-1.28.0.jar deleted file mode 100644 index b6286aa..0000000 Binary files a/lib/google-http-client-1.28.0.jar and /dev/null differ diff --git a/lib/google-http-client-apache-2.0.0.jar b/lib/google-http-client-apache-2.0.0.jar deleted file mode 100644 index 83043dd..0000000 Binary files a/lib/google-http-client-apache-2.0.0.jar and /dev/null differ diff --git a/lib/google-http-client-gson-1.28.0.jar b/lib/google-http-client-gson-1.28.0.jar deleted file mode 100644 index 7b1598f..0000000 Binary files a/lib/google-http-client-gson-1.28.0.jar and /dev/null differ diff --git a/lib/google-http-client-jackson2-1.28.0.jar b/lib/google-http-client-jackson2-1.28.0.jar deleted file mode 100644 index 608e228..0000000 Binary files a/lib/google-http-client-jackson2-1.28.0.jar and /dev/null differ diff --git a/lib/google-oauth-client-1.28.0.jar b/lib/google-oauth-client-1.28.0.jar deleted file mode 100644 index b7a40f9..0000000 Binary files a/lib/google-oauth-client-1.28.0.jar and /dev/null differ diff --git a/lib/grpc-context-1.14.0.jar b/lib/grpc-context-1.14.0.jar deleted file mode 100644 index 498353a..0000000 Binary files a/lib/grpc-context-1.14.0.jar and /dev/null differ diff --git a/lib/gson-2.1.jar b/lib/gson-2.1.jar deleted file mode 100644 index 83c5c99..0000000 Binary files a/lib/gson-2.1.jar and /dev/null differ diff --git a/lib/guava-26.0-android.jar b/lib/guava-26.0-android.jar deleted file mode 100644 index 3db9b6c..0000000 Binary files a/lib/guava-26.0-android.jar and /dev/null differ diff --git a/lib/httpclient-4.5.5.jar b/lib/httpclient-4.5.5.jar deleted file mode 100644 index 7796b0e..0000000 Binary files a/lib/httpclient-4.5.5.jar and /dev/null differ diff --git a/lib/httpcore-4.4.9.jar b/lib/httpcore-4.4.9.jar deleted file mode 100644 index cddba28..0000000 Binary files a/lib/httpcore-4.4.9.jar and /dev/null differ diff --git a/lib/j2objc-annotations-1.1.jar b/lib/j2objc-annotations-1.1.jar deleted file mode 100644 index 4b6f127..0000000 Binary files a/lib/j2objc-annotations-1.1.jar and /dev/null differ diff --git a/lib/jackson-core-2.9.6.jar b/lib/jackson-core-2.9.6.jar deleted file mode 100644 index 09e7dd2..0000000 Binary files a/lib/jackson-core-2.9.6.jar and /dev/null differ diff --git a/lib/jcl-over-slf4j-1.7.6.jar b/lib/jcl-over-slf4j-1.7.6.jar deleted file mode 100644 index 1a1ceee..0000000 Binary files a/lib/jcl-over-slf4j-1.7.6.jar and /dev/null differ diff --git a/lib/jsr305-3.0.2.jar b/lib/jsr305-3.0.2.jar deleted file mode 100644 index 59222d9..0000000 Binary files a/lib/jsr305-3.0.2.jar and /dev/null differ diff --git a/lib/jul-to-slf4j-1.7.6.jar b/lib/jul-to-slf4j-1.7.6.jar deleted file mode 100644 index 433c898..0000000 Binary files a/lib/jul-to-slf4j-1.7.6.jar and /dev/null differ diff --git a/lib/log4j-over-slf4j-1.7.6.jar b/lib/log4j-over-slf4j-1.7.6.jar deleted file mode 100644 index 070a76f..0000000 Binary files a/lib/log4j-over-slf4j-1.7.6.jar and /dev/null differ diff --git a/lib/logback-classic-1.1.1.jar b/lib/logback-classic-1.1.1.jar deleted file mode 100644 index 39f68c4..0000000 Binary files a/lib/logback-classic-1.1.1.jar and /dev/null differ diff --git a/lib/logback-core-1.1.1.jar b/lib/logback-core-1.1.1.jar deleted file mode 100644 index 893962d..0000000 Binary files a/lib/logback-core-1.1.1.jar and /dev/null differ diff --git a/lib/opencensus-api-0.18.0.jar b/lib/opencensus-api-0.18.0.jar deleted file mode 100644 index 5c9afd3..0000000 Binary files a/lib/opencensus-api-0.18.0.jar and /dev/null differ diff --git a/lib/opencensus-contrib-http-util-0.18.0.jar b/lib/opencensus-contrib-http-util-0.18.0.jar deleted file mode 100644 index 48aa45c..0000000 Binary files a/lib/opencensus-contrib-http-util-0.18.0.jar and /dev/null differ diff --git a/lib/slf4j-api-1.7.6.jar b/lib/slf4j-api-1.7.6.jar deleted file mode 100644 index 19aaf37..0000000 Binary files a/lib/slf4j-api-1.7.6.jar and /dev/null differ diff --git a/lib/snakeyaml-1.13.jar b/lib/snakeyaml-1.13.jar deleted file mode 100644 index 453f99f..0000000 Binary files a/lib/snakeyaml-1.13.jar and /dev/null differ diff --git a/lib/snakeyaml-1.14.jar b/lib/snakeyaml-1.14.jar deleted file mode 100644 index 6356244..0000000 Binary files a/lib/snakeyaml-1.14.jar and /dev/null differ diff --git a/lib/spring-amqp-1.2.1.RELEASE.jar b/lib/spring-amqp-1.2.1.RELEASE.jar deleted file mode 100644 index 2b3391d..0000000 Binary files a/lib/spring-amqp-1.2.1.RELEASE.jar and /dev/null differ diff --git a/lib/spring-aop-3.1.4.RELEASE.jar b/lib/spring-aop-3.1.4.RELEASE.jar deleted file mode 100644 index ca7c314..0000000 Binary files a/lib/spring-aop-3.1.4.RELEASE.jar and /dev/null differ diff --git a/lib/spring-aop-4.1.6.RELEASE.jar b/lib/spring-aop-4.1.6.RELEASE.jar deleted file mode 100644 index ca4aa29..0000000 Binary files a/lib/spring-aop-4.1.6.RELEASE.jar and /dev/null differ diff --git a/lib/spring-asm-3.1.4.RELEASE.jar b/lib/spring-asm-3.1.4.RELEASE.jar deleted file mode 100644 index b5ae813..0000000 Binary files a/lib/spring-asm-3.1.4.RELEASE.jar and /dev/null differ diff --git a/lib/spring-beans-3.1.4.RELEASE.jar b/lib/spring-beans-3.1.4.RELEASE.jar deleted file mode 100644 index ce48668..0000000 Binary files a/lib/spring-beans-3.1.4.RELEASE.jar and /dev/null differ diff --git a/lib/spring-beans-4.1.6.RELEASE.jar b/lib/spring-beans-4.1.6.RELEASE.jar deleted file mode 100644 index 7206d00..0000000 Binary files a/lib/spring-beans-4.1.6.RELEASE.jar and /dev/null differ diff --git a/lib/spring-boot-1.0.0.RC5.jar b/lib/spring-boot-1.0.0.RC5.jar deleted file mode 100644 index 66f0d87..0000000 Binary files a/lib/spring-boot-1.0.0.RC5.jar and /dev/null differ diff --git a/lib/spring-boot-1.2.3.RELEASE.jar b/lib/spring-boot-1.2.3.RELEASE.jar deleted file mode 100644 index eed5612..0000000 Binary files a/lib/spring-boot-1.2.3.RELEASE.jar and /dev/null differ diff --git a/lib/spring-boot-autoconfigure-1.0.0.RC5.jar b/lib/spring-boot-autoconfigure-1.0.0.RC5.jar deleted file mode 100644 index c7fecf9..0000000 Binary files a/lib/spring-boot-autoconfigure-1.0.0.RC5.jar and /dev/null differ diff --git a/lib/spring-boot-autoconfigure-1.2.3.RELEASE.jar b/lib/spring-boot-autoconfigure-1.2.3.RELEASE.jar deleted file mode 100644 index 20b600a..0000000 Binary files a/lib/spring-boot-autoconfigure-1.2.3.RELEASE.jar and /dev/null differ diff --git a/lib/spring-boot-sample-amqp-1.0.0.RC5.jar b/lib/spring-boot-sample-amqp-1.0.0.RC5.jar deleted file mode 100644 index d5789fa..0000000 Binary files a/lib/spring-boot-sample-amqp-1.0.0.RC5.jar and /dev/null differ diff --git a/lib/spring-boot-starter-1.0.0.RC5.jar b/lib/spring-boot-starter-1.0.0.RC5.jar deleted file mode 100644 index b69cd04..0000000 Binary files a/lib/spring-boot-starter-1.0.0.RC5.jar and /dev/null differ diff --git a/lib/spring-boot-starter-amqp-1.0.0.RC5.jar b/lib/spring-boot-starter-amqp-1.0.0.RC5.jar deleted file mode 100644 index 7137316..0000000 Binary files a/lib/spring-boot-starter-amqp-1.0.0.RC5.jar and /dev/null differ diff --git a/lib/spring-boot-starter-logging-1.0.0.RC5.jar b/lib/spring-boot-starter-logging-1.0.0.RC5.jar deleted file mode 100644 index 25431a7..0000000 Binary files a/lib/spring-boot-starter-logging-1.0.0.RC5.jar and /dev/null differ diff --git a/lib/spring-context-4.0.2.RELEASE.jar b/lib/spring-context-4.0.2.RELEASE.jar deleted file mode 100644 index 871d535..0000000 Binary files a/lib/spring-context-4.0.2.RELEASE.jar and /dev/null differ diff --git a/lib/spring-context-4.1.6.RELEASE.jar b/lib/spring-context-4.1.6.RELEASE.jar deleted file mode 100644 index 6c48963..0000000 Binary files a/lib/spring-context-4.1.6.RELEASE.jar and /dev/null differ diff --git a/lib/spring-core-4.0.2.RELEASE.jar b/lib/spring-core-4.0.2.RELEASE.jar deleted file mode 100644 index c32918c..0000000 Binary files a/lib/spring-core-4.0.2.RELEASE.jar and /dev/null differ diff --git a/lib/spring-core-4.1.6.RELEASE.jar b/lib/spring-core-4.1.6.RELEASE.jar deleted file mode 100644 index fe5f612..0000000 Binary files a/lib/spring-core-4.1.6.RELEASE.jar and /dev/null differ diff --git a/lib/spring-expression-4.0.2.RELEASE.jar b/lib/spring-expression-4.0.2.RELEASE.jar deleted file mode 100644 index 7ae2961..0000000 Binary files a/lib/spring-expression-4.0.2.RELEASE.jar and /dev/null differ diff --git a/lib/spring-expression-4.1.6.RELEASE.jar b/lib/spring-expression-4.1.6.RELEASE.jar deleted file mode 100644 index a1ceae1..0000000 Binary files a/lib/spring-expression-4.1.6.RELEASE.jar and /dev/null differ diff --git a/lib/spring-rabbit-1.2.1.RELEASE.jar b/lib/spring-rabbit-1.2.1.RELEASE.jar deleted file mode 100644 index a06b71f..0000000 Binary files a/lib/spring-rabbit-1.2.1.RELEASE.jar and /dev/null differ diff --git a/lib/spring-tx-3.1.4.RELEASE.jar b/lib/spring-tx-3.1.4.RELEASE.jar deleted file mode 100644 index fe6a01b..0000000 Binary files a/lib/spring-tx-3.1.4.RELEASE.jar and /dev/null differ