Skip to content
Snippets Groups Projects
Commit 1319ceb0 authored by Ján Macháček's avatar Ján Macháček
Browse files

fix - report facade

parent 9eae55fd
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -5,14 +5,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cz.muni.fi.pa165.core.client.AirplaneApi;
import cz.muni.fi.pa165.core.client.FlightApi;
import cz.muni.fi.pa165.core.client.AirportApi;
import cz.muni.fi.pa165.core.client.*;
import cz.muni.fi.pa165.core.client.invoker.ApiException;
import cz.muni.fi.pa165.core.client.model.AirplaneDto;
import cz.muni.fi.pa165.core.client.model.AirplaneTypeDto;
import cz.muni.fi.pa165.core.client.model.AirportDto;
import cz.muni.fi.pa165.core.client.model.FlightDto;
import cz.muni.fi.pa165.core.client.model.*;
import cz.muni.fi.pa165.report.server.ReportType;
import cz.muni.fi.pa165.report.server.exceptions.ResourceNotFoundException;
import cz.muni.fi.pa165.report.server.service.ReportDocumentService;
......@@ -35,6 +30,10 @@ public class ReportFacadeImpl implements ReportFacade{
public Resource getReportAirportById(Long id){
AirportDto airport;
CityDto cityDto;
CountryDto countryDto;
CountryApi countryApi = new CountryApi();
CityApi cityApi = new CityApi();
AirportApi airportApi = new AirportApi();
List<String> airportData = new ArrayList<>();
List<String> cityData = new ArrayList<>();
......@@ -49,11 +48,13 @@ public class ReportFacadeImpl implements ReportFacade{
+ airport.getLocation());
documentData.put("airport", airportData);
if(airport.getCity() != null) {
cityData.add("Airport is located in the city " + airport.getCity().getName());
if(airport.getCityId() != null && airport.getCityId() != 0) {
cityDto = cityApi.getCityById(airport.getCityId());
cityData.add("Airport is located in the city " + cityDto.getName());
if (airport.getCity().getCountry() != null){
cityData.add("Country of this city is " + airport.getCity().getCountry());
if (cityDto.getCountryId() != null && cityDto.getCountryId() != 0){
countryDto = countryApi.getCountryById(cityDto.getCountryId());
cityData.add("Country of this city is " + countryDto.getName());
}
}
documentData.put("airportCity", cityData);
......@@ -69,9 +70,15 @@ public class ReportFacadeImpl implements ReportFacade{
public Resource getReportFlightById(Long id){
FlightApi flightApi = new FlightApi();
StewardApi stewardApi = new StewardApi();
AirplaneApi airplaneApi = new AirplaneApi();
AirportApi airportApi = new AirportApi();
AirplaneDto airplaneDto;
AirportDto arrivalAirportDto;
AirportDto departureAirportDto;
FlightDto flight;
List<String> flightData = new ArrayList<>();
List<String> stewardsData;
List<String> stewardsData = new ArrayList<>();
List<String> airplaneData = new ArrayList<>();
List<String> airportsData = new ArrayList<>();
......@@ -83,21 +90,34 @@ public class ReportFacadeImpl implements ReportFacade{
flightData.add("Departure time of flight is " + flight.getDepartureTime());
documentData.put("flight", flightData);
stewardsData = flight.getStewards().stream().map(stewardDto ->
stewardDto.getFirstName() + " " + stewardDto.getLastName()).toList();
if( flight.getAssignedStewardIds() != null){
flight.getAssignedStewardIds().forEach(stewardId ->
{
StewardDto stewardDto;
try {
stewardDto = stewardApi.getSteward(stewardId);
} catch (ApiException e) {
throw new ResourceNotFoundException(e);
}
stewardsData.add(stewardDto.getFirstName() + " " + stewardDto.getLastName());
});
}
documentData.put("stewards", stewardsData);
if(flight.getAirplane() != null) {
airplaneData.add("Airplane name is " + flight.getAirplane().getName());
airplaneData.add("Airplane capacity is " + flight.getAirplane().getCapacity());
if(flight.getAirplaneId() != null && flight.getAirplaneId() != 0) {
airplaneDto = airplaneApi.getAirplaneById(flight.getAirplaneId());
airplaneData.add("Airplane name is " + airplaneDto.getName());
airplaneData.add("Airplane capacity is " + airplaneDto.getCapacity());
}
documentData.put("airplane", airplaneData);
if (flight.getArrivalAirport() != null) {
airportsData.add("Arrival airport is " + flight.getArrivalAirport().getName());
if (flight.getArrivalAirportId() != null && flight.getArrivalAirportId() != 0) {
arrivalAirportDto = airportApi.getAirportById(flight.getArrivalAirportId());
airportsData.add("Arrival airport is " + arrivalAirportDto.getName());
}
if (flight.getDepartureAirport() != null) {
airportsData.add("Departure airport is " + flight.getDepartureAirport().getName());
if (flight.getDepartureAirportId() != null && flight.getDepartureAirportId() != 0) {
departureAirportDto = airportApi.getAirportById(flight.getDepartureAirportId());
airportsData.add("Departure airport is " + departureAirportDto.getName());
}
documentData.put("airports", airportsData);
......@@ -111,6 +131,8 @@ public class ReportFacadeImpl implements ReportFacade{
public Resource getReportAirplaneById(Long id){
AirplaneApi airplaneApi = new AirplaneApi();
AirplaneTypeApi airplaneTypeApi = new AirplaneTypeApi();
AirplaneTypeDto airplaneTypeDto;
AirplaneDto airplane;
List<String> airplaneData = new ArrayList<>();
List<String> airplaneTypeData = new ArrayList<>();
......@@ -123,7 +145,7 @@ public class ReportFacadeImpl implements ReportFacade{
airplaneData.add("Airplane capacity: " + airplane.getCapacity());
documentData.put("airplane", airplaneData);
AirplaneTypeDto airplaneTypeDto = airplane.getType();
airplaneTypeDto = airplaneTypeApi.getAirplaneTypeById(airplane.getTypeId());
airplaneTypeData.add("Airplane type name: " + airplaneTypeDto.getName());
documentData.put("airplaneType", airplaneTypeData);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment