Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

Expand Down Expand Up @@ -75,6 +76,8 @@ class OceanFreightController {
/* Ocean Freight Repository */
private final OceanFreightRepository oceanFreightRepository;

private static final Logger LOGGER = LoggerFactory.getLogger(OceanFreightController.class);

/* One argument constructor */
OceanFreightController(OceanFreightRepository oceanFreightRepository) {
this.oceanFreightRepository = oceanFreightRepository;
Expand All @@ -94,6 +97,8 @@ ResponseEntity<?> getFreight(@PathVariable String paintainer) throws Exception {

OceanFreight record = oceanFreightRepository.findByPaintainerHBL(paintainer);

LOGGER.info("stored record---=>"+record);

// If there is an existing entry in database, then make marine traffic API calls
if (record != null) {
// Simultaneous execution of multiple GET requests
Expand All @@ -105,6 +110,7 @@ ResponseEntity<?> getFreight(@PathVariable String paintainer) throws Exception {
long numOfDays = calculateDays(record.getEtd());
// Prepare marine traffic API urls
urisToGet = prepareURIs(mmsi, numOfDays);
LOGGER.info("numbers of URI to be called--->"+urisToGet.size());
// Fetch the urls
execution.fetch(urisToGet);

Expand All @@ -115,6 +121,9 @@ ResponseEntity<?> getFreight(@PathVariable String paintainer) throws Exception {
if (isErrorMessageInReturnedJson(json)) {
return prepareErrorMessage(json);
}

LOGGER.info("Response received -->",logResponseAsJson(json));

VesselCurrentPosition currentPosition = parseJsonForCurrentPosition(json);

// Get the result for vessel voyage and check for an error
Expand Down Expand Up @@ -143,6 +152,14 @@ ResponseEntity<?> getFreight(@PathVariable String paintainer) throws Exception {
HttpStatus.NOT_FOUND);
}

private String logResponseAsJson(String jsonString) throws IOException {
ObjectMapper mapper = new ObjectMapper();
Object jsonObject = mapper.readValue(jsonString, Object.class);
String prettyJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject);
return prettyJson;

}

/**
* Method that updates freight record for paintainer.
*
Expand Down Expand Up @@ -334,8 +351,11 @@ private List<GeoCoordinates> convertRouteFromWkt(String wktRoute) {
for (String entry : positions) {
String[] coordinates = entry.trim().split(" ");
GeoCoordinates geoEntry = new GeoCoordinates();
geoEntry.setLat(coordinates[1]);
geoEntry.setLon(coordinates[0]);
LOGGER.info("coordinates values received-->",entry);
if(coordinates !=null && coordinates.length ==2) {
geoEntry.setLat(coordinates[1]);
geoEntry.setLon(coordinates[0]);
}
geoRoute.add(geoEntry);
}
return geoRoute;
Expand Down