Untitled
public ResponseEntity<?> getPackingDetails(String shipmentId, String osdId) { RestTemplate restTemplate = new RestTemplate(); StringBuilder stringBuilder = new StringBuilder(); String decisionsUrl = tonkeanService.getAcceptClaim(); HttpHeaders headers = new HttpHeaders(); headers.add("content-type", "application/json"); stringBuilder.append(adjustmentProperties.getBaseUrl()).append(adjustmentProperties.getPackingListUrl()) .append("?shipmentId=").append(shipmentId); String url = stringBuilder.toString(); try { long startTime = System.currentTimeMillis(); PackingDetails[] response = restTemplate.getForObject(url, PackingDetails[].class); long endTime = System.currentTimeMillis(); long responseTime = endTime - startTime; LOGGER.info("Elapsed time for the WMS API fetching packing list based on shipment id {} is {} milliseconds.", shipmentId, responseTime); ApiFuture<DocumentSnapshot> future = fireStoreDatabase.collection(COL_NAME).document(osdId).get(); DocumentSnapshot document = future.get(); if (response != null && response.length > 0) { if (document.exists()) { IncidentDto incidentDto = document.toObject(IncidentDto.class); String fileName = response[0].getFileName().substring(0, response[0].getFileName().length() - 3) + "pdf"; boolean isFileNameFound = incidentDto.getFileName().stream().anyMatch(x -> x.contains(fileName)); if (isFileNameFound) { LOGGER.info("Packing Slip already exists for osdId: {}", osdId); return new ResponseEntity<>(mapResponse("PackingSlip is already exists with name:" + fileName, HttpStatus.OK.value(), false, null), HttpStatus.OK); } else { LOGGER.info("Packing Slip succesfully found for shipment Id: {}", shipmentId); // Decisions Response Will be populated ResponseEntity<String> respons = restTemplate.postForEntity(url, new HttpEntity<>(response[0].getFileName(), headers), String.class); if (respons.getStatusCodeValue() == 200) { return new ResponseEntity<>(mapResponse("packing found for shipment id : " + shipmentId, HttpStatus.OK.value(), false, response[0].getFileName()), HttpStatus.OK); } else { return new ResponseEntity<>(mapResponse("Failed to fetch data.", HttpStatus.INTERNAL_SERVER_ERROR.value(), true, null), HttpStatus.INTERNAL_SERVER_ERROR); } } } } else { return new ResponseEntity<>(mapResponse("No packing slip found for shipment id : " + shipmentId, HttpStatus.NOT_FOUND.value(), false, null), HttpStatus.NOT_FOUND); } } catch (Exception e) { LOGGER.error("Error found while calling shipment details : {} ", e.getMessage(), e); } return new ResponseEntity<>( mapResponse("Failed to fetch data.", HttpStatus.INTERNAL_SERVER_ERROR.value(), true, null), HttpStatus.INTERNAL_SERVER_ERROR); }
Leave a Comment