diff --git a/API/code/restapi/src/main/java/org/panalpina/api/rest/controller/AirFreightController.java b/API/code/restapi/src/main/java/org/panalpina/api/rest/controller/AirFreightController.java index d94cac97a..4a8480b33 100644 --- a/API/code/restapi/src/main/java/org/panalpina/api/rest/controller/AirFreightController.java +++ b/API/code/restapi/src/main/java/org/panalpina/api/rest/controller/AirFreightController.java @@ -23,6 +23,8 @@ import org.panalpina.api.rest.model.FlightTrack; import org.panalpina.api.rest.model.GenericMessage; import org.panalpina.api.rest.repository.AirFreightRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -35,8 +37,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; - /** * Air Freight Controller. * @@ -45,6 +45,12 @@ */ @RestController class AirFreightController { + + /** + * Logger + */ + private static final Logger LOGGER = LoggerFactory.getLogger(AirFreightController.class); + /* FlightAware API v3 user name */ @Value("${fxml3.username}") private String username; @@ -223,23 +229,32 @@ private String formatDate(String ETD) { * @return faFlightID * @throws IOException IOException */ - private JsonNode parseFaFlightIDFromJson(String json, String date) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode rootNode = objectMapper.readTree(json); - JsonNode flights = rootNode.get("FlightInfoStatusResult").get("flights"); - - if (flights.isArray()) { - for (final JsonNode objNode : flights) { - JsonNode faFlightID = objNode.get("faFlightID"); - JsonNode filedDepartureTimeNode = objNode.get("filed_departure_time"); - String filedDepartureDate = filedDepartureTimeNode.get("date").asText(); - if (date.equals(filedDepartureDate)) { - return objNode; - } - } - } - return null; - } + private JsonNode parseFaFlightIDFromJson(String json, String date) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode rootNode = objectMapper.readTree(json); + JsonNode flightInfoStatus = rootNode.get("FlightInfoStatusResult"); + if (flightInfoStatus == null) { + LOGGER.debug("flight Info status is null"); + return null; + } + JsonNode flights = flightInfoStatus.get("flights"); + + if (flights == null) { + LOGGER.debug("flights is null or empty"); + } + + if (flights != null && flights.isArray()) { + for (final JsonNode objNode : flights) { + JsonNode faFlightID = objNode.get("faFlightID"); + JsonNode filedDepartureTimeNode = objNode.get("filed_departure_time"); + String filedDepartureDate = filedDepartureTimeNode.get("date").asText(); + if (date.equals(filedDepartureDate)) { + return objNode; + } + } + } + return null; + } /** * Method that retrieves flight tracks for a flight diff --git a/API/code/restapi/src/main/resources/application.properties b/API/code/restapi/src/main/resources/application.properties index 20faf5c55..8096fc43d 100644 --- a/API/code/restapi/src/main/resources/application.properties +++ b/API/code/restapi/src/main/resources/application.properties @@ -33,4 +33,4 @@ marinetraffic.api.param.protocol.value=jsono marinetraffic.api.param.timespan.value=240 # MMSI value for test purposes marinetraffic.api.test.mmsi.value=310627000 - +logging.level.root=DEBUG diff --git a/API/docs/images/debug_logs.PNG b/API/docs/images/debug_logs.PNG new file mode 100644 index 000000000..b79c7a4b2 Binary files /dev/null and b/API/docs/images/debug_logs.PNG differ diff --git a/API/docs/images/no_flight_data.PNG b/API/docs/images/no_flight_data.PNG new file mode 100644 index 000000000..3e1d9819b Binary files /dev/null and b/API/docs/images/no_flight_data.PNG differ diff --git a/API/docs/images/npe_fix.PNG b/API/docs/images/npe_fix.PNG new file mode 100644 index 000000000..9e4015d66 Binary files /dev/null and b/API/docs/images/npe_fix.PNG differ diff --git a/API/docs/postman/F2F-BugFix of get flight status latest data.postman_collection.json b/API/docs/postman/F2F-BugFix of get flight status latest data.postman_collection.json new file mode 100644 index 000000000..fba89d99d --- /dev/null +++ b/API/docs/postman/F2F-BugFix of get flight status latest data.postman_collection.json @@ -0,0 +1,34 @@ +{ + "info": { + "_postman_id": "83b6c426-6768-4287-ba5b-d7f7fe020d4f", + "name": "F2F-BugFix of get flight status latest data", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Get flight details by shipment number (200)", + "request": { + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "http://localhost:8080/v1/flight/PNH015420", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "v1", + "flight", + "PNH015420" + ] + } + }, + "response": [] + } + ] +} \ No newline at end of file diff --git a/API/docs/validation.md b/API/docs/validation.md new file mode 100644 index 000000000..9d9ff8651 --- /dev/null +++ b/API/docs/validation.md @@ -0,0 +1,61 @@ +# Panalpina Bugfix#1 verfiication + +The fix is only for backend the verification document explains only aboout how to verify the backend service. + + +#Apply patch + +Skip this test if already done. + +git am < 0001-commit-for-BugFix-1-challenge.patch +git am < 0002-fixed-review-comments.patch + +#Setup backend: + +update the below properties in application.properties. + +fxml3.username=UCtURaPR +fxml3.password=9d1f7723d5165ac5d9151c8b966176982aea8eca +fxml3.url.prefix=https://flightxml.flightaware.com/json/FlightXML3/ + +setup the backend document by following the steps in $cd API/docs/README.md file. + + +#Bug 1: + +By looking at the stacktrace, there is a mismatch in the response json. I fixed by checking for the not null condition. + +Import the $cd API/docs/postman/F2F-BugFix of get flight status latest data.postman_collection into postman. + +Execute the Get flight details by shipment number (200) with any value parameter by replacing the value with `PNH015420`. You will get the result. + +Please refer the screenshots. + + +![npe+fix](./images/npe_fix.png) + + +![no_flight_data_in_api](./images/no_flight_data.png) + + + +#Bug 2: + +The debug log is enabled. Refer the screenshot. + + +![degug_logs](./images/debug_logs.png) + +#Bug 3: + +By looking at the console of browser, the error is because of max request limit reached. There is no code fix required. It has to do with business deciding on the maximum request can be buy from google maps. + +You have exceeded your request quota for this API. See https://developers.google.com/maps/documentation/javascript/error-messages?utm_source=maps_js&utm_medium=degraded&utm_campaign=billing#api-key-and-billing-errors + + + + + + + +