From 1b448c52b65c6e2e6741b792637b9bd0a6e3a8fe Mon Sep 17 00:00:00 2001 From: Martin Skopp Date: Tue, 23 Nov 2021 17:16:24 +0100 Subject: [PATCH] Backporting fix for issue #3 Fixing NPE when XFWB comes without SpecifiedLogisticsTransportMovement.StageCode.ModeCode value --- .../converter/XFWB3toOneRecordConverter.java | 4 +- .../XFWB3toOneRecordConverterTest.java | 44 +++ .../888-11111111_XFWB_noModeCode.xml | 270 ++++++++++++++++++ 3 files changed, 317 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/888-11111111_XFWB_noModeCode.xml diff --git a/src/main/java/com/riege/onerecord/converter/XFWB3toOneRecordConverter.java b/src/main/java/com/riege/onerecord/converter/XFWB3toOneRecordConverter.java index c958cca..9bb3c94 100644 --- a/src/main/java/com/riege/onerecord/converter/XFWB3toOneRecordConverter.java +++ b/src/main/java/com/riege/onerecord/converter/XFWB3toOneRecordConverter.java @@ -383,7 +383,9 @@ private void convertCIMPSegment03to04Flights() { // ModeCode is the same in 1R+XFWB, so we apply 1:1 // In XFWB, ModeCode="4" means "Air transport" // In XFWB, there is also a ltm.getMode() with value "Air transport" - tm.setModeCode(ltm.getModeCode().getValue()); + if (ltm.getModeCode() != null) { + tm.setModeCode(ltm.getModeCode().getValue()); + } tm.setModeQualifier(value(ltm.getStageCode())); if (ltm.getDepartureEvent() != null) { tm.setDepartureLocation( diff --git a/src/test/java/com/riege/onerecord/converter/XFWB3toOneRecordConverterTest.java b/src/test/java/com/riege/onerecord/converter/XFWB3toOneRecordConverterTest.java index e0f0437..752887b 100644 --- a/src/test/java/com/riege/onerecord/converter/XFWB3toOneRecordConverterTest.java +++ b/src/test/java/com/riege/onerecord/converter/XFWB3toOneRecordConverterTest.java @@ -61,4 +61,48 @@ public void test88811111111() throws JAXBException, JsonProcessingException { Assertions.assertTrue(json.contains("Piece#goodsDescription\" : \"CONSOLIDATION\\nAS PER ATTACHED\\nMANIFEST\\nSECURE CARGO\\nNOT RESTRICTED\\nAIRLINE PHARMA\\nSERVICE\"")); } + @Test + public void test88811111111noModeCode() throws JAXBException, JsonProcessingException { + String filename = "888-11111111_XFWB_noModeCode.xml"; + + InputStream is; + WaybillType xfwb; + XFWB3toOneRecordConverter converter; + String awb; + + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + // mapper.disable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")); + + is = ClassLoader.getSystemResourceAsStream(filename); + xfwb = new ConverterUtil().unmarshalXFWB3(is); + awb = xfwb.getBusinessHeaderDocument().getID().getValue(); + converter = new XFWB3toOneRecordConverter(xfwb); + + Assertions.assertNotNull(converter.getValidationHints()); + Assertions.assertFalse(converter.getValidationHints().isEmpty()); + for (ValidationMessage msg : converter.getValidationHints()) { + System.out.println(awb + " HINT: " + msg.getMessage()); + } + + Assertions.assertNotNull(converter.getValidationWarnings()); + Assertions.assertFalse(converter.getValidationWarnings().isEmpty()); + for (ValidationMessage msg : converter.getValidationWarnings()) { + System.out.println(awb + " WARNING: " + msg.getMessage()); + } + + Assertions.assertNotNull(converter.getValidationErrors()); + Assertions.assertTrue(converter.getValidationErrors().isEmpty()); + for (ValidationMessage msg : converter.getValidationErrors()) { + System.out.println(awb + " ERROR: " + msg.getMessage()); + } + + String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(converter.getOneRecordResult()); + System.out.println(awb + " JSON=\n" + json); + Assertions.assertTrue(json.contains("customsInfoNote\" : \"USCI1234567812345678X7\"")); + Assertions.assertTrue(json.contains("Piece#goodsDescription\" : \"CONSOLIDATION\\nAS PER ATTACHED\\nMANIFEST\\nSECURE CARGO\\nNOT RESTRICTED\\nAIRLINE PHARMA\\nSERVICE\"")); + } + } diff --git a/src/test/resources/888-11111111_XFWB_noModeCode.xml b/src/test/resources/888-11111111_XFWB_noModeCode.xml new file mode 100644 index 0000000..4443768 --- /dev/null +++ b/src/test/resources/888-11111111_XFWB_noModeCode.xml @@ -0,0 +1,270 @@ + + + + 888-11111111_6c763819-1067-43fe-acf7-db4daf4f77cf + Master Air Waybill + 741 + 2021-03-10T11:00:00+01:00 + Creation + 3.00 + + RIEGESOFTWARE + + + REUAGT88FORWARDER/FRA01 + + + CCSPROVIDERNAME + + + + 888-11111111 + FRA8117142550 + + C + Consolidation Shipment + + + 2021-03-10T00:00:00 + MARK USER + + ORK + + + + + 8112345678 + true + true + true + true + true + 1042.0 + 2.602 + 3 + + FORWARDER COMPANY IRELAND LTD + SHP_ACCOUNT_NO_1234 + + ABCD + HARBOUR POINT BUSINESS PARK + LITTLE CITY + IE + + + + 353123456789 + + + + + FORWARDER COMPANY SHANGHAI LTD +ROOM 123 SPECIAL BUILDING. NR 987 + + SUHANG RD. PUDONG AIRPORT +AIRPORT ROAD + SHANGHAI + CN + People's Republic of China + + + + 861234567890 + + + + + FORWARDER COMPANY IRELAND LIMITED + 87654321 + 3456789 + + ABCD + Harbour Point Business Part + Little City + IE + + + 0123 + + + + 353987654321 + + + + + ORK + + + PVG + + + Main-Carriage + Air transport + XX8012 + 1 + + XX + + + + DUB + Airport + + + + 2021-03-10T00:00:00 + + ORK + Airport + + + + + Main-Carriage + Air transport + XX345 + 2 + + XX + + + + AUH + Airport + + + + 2021-03-12T00:00:00 + + DUB + Airport + + + + + NSC + + + 4 PALLETS + + + TEMPERATURE CONTROL 15 TO 25 DEGREES CELSIUS + + + HANDLE WITH CARE + + + T + IE1234567N + SHP + IE + + + CP + HILDA HILARIOUS + SHP + IE + + + CT + 353123454321 + SHP + IE + + + T + USCI1234567812345678X7 + CNE + CN + + + CP + PAUL PERSON + CNE + CN + + + CT + 862123454321 + CNE + CN + + + RA + 01234-01 + ISS + IE + + + ED + 1299 + + + X + + + EUR + + + + MC + true + C + 1234.56 + + + F + 1 + + 1 + 000111 + 1042.0 + 2602000 + 333 + 3 + + CONSOLIDATION +AS PER ATTACHED +MANIFEST +SECURE CARGO +NOT RESTRICTED +AIRLINE PHARMA +SERVICE + + + 2 + + 80 + 120 + 96 + + + + 1 + + 80 + 120 + 79 + + + + Q + 1042.0 + 4.44 + 4626.48 + + + + + F + + true + 4626.48 + 11.22 + 222.33 + 4860.03 + + + +