Cargo inputUWSInfo = (Cargo) _um.unmarshal(new StreamSource(new StringReader(convertToXml)));
Meta meta = inputUWSInfo.getMeta();
UWSInfo uwsInfo = inputUWSInfo.getUWSInfo();
if(existsMandatory(meta, uwsInfo)) {
LOG.warn("Compulsory uws info are empty. Message will be dropped.");
addExptInfo(EMAND.name(), "");
return false;
}
if(!meta.getType().equalsIgnoreCase(UWS)) {
LOG.warn("Processing performs only for UWS. Message will be dropped.");
addExptInfo(EWVAL.name(), meta.getType());
return false;
}
if(!OP_TYPE.UPD.name().equalsIgnoreCase(meta.getSubtype().trim())) {
LOG.warn("Processing performs only for UPD sub type. Message will be dropped.");
addExptInfo(EENUM.name(), meta.getSubtype());
return false;
}
if(!meta.getSource().equalsIgnoreCase(SKY_CHAIN)) {
LOG.error("Processing performs only for SkyChain. Message will be dropped.");
addExptInfo(EWVAL.name(), meta.getSource());
return false;
}
FlightInfo inputFlightID = uwsInfo.getFlightInfo();
String flightNumber = formatFlightNo(inputFlightID.getFlightNumber());
LOG.debug("Airport Code - {}, Departure Date of Month - {}, Final Msg Indicator - {}, Original Flight No - {}, Flight No formatted - {}", inputFlightID.getAirportCode(), inputFlightID.getDateOfMonth(), inputFlightID.getFinalMessageIndicator(), inputFlightID.getFlightNumber(), flightNumber);
String flightDate = createFlightDateFrom(inputFlightID.getDateOfMonth());
if(isNullOrEmptyStr(flightDate)) {
LOG.error("Departure date cannot be constructed. Message will be dropped.");
addExptInfo(EWVAL.name(), inputFlightID.getDateOfMonth());
return false;
}
LOG.debug("Flight Number, Departure Date - {}, {}", flightNumber, flightDate);
EntDbAfttab entDbAfttab = afttabBean.findFlightForUws(flightNumber, flightDate);
if(entDbAfttab == null) {
LOG.error("Flight provided cannot be found. Message will be dropped.");
addExptInfo(EnumExceptionCodes.ENOFL.name(), String.format("%s (%s)", flightNumber, flightDate));
return false;
}
LOG.debug("URNO from DB - {}", entDbAfttab.getUrno());
LOG.debug("FLUT : {}, {}", entDbAfttab.getFlut(), flightDate.equals(entDbAfttab.getFlut()));
EntDbMsgTelex msgTelex = createMessageTelex(message, uwsInfo, entDbAfttab.getUrno());
if(msgTelex == null) {
LOG.error("Message Telex persisting encounter error. It won't be persisted.");
}
List<EntDbLoadUld> existingLoadUlds = dLLoadUldBean.findUldsByFlight(entDbAfttab.getUrno());
List<EntDbLoadUld> newLoadUlds = new ArrayList<>();
Map<EntDbLoadUld, EntDbLoadUld> updatedLoadUlds = new HashMap<>();
//TODO: to confirm mei => if no value eg weight status in xml but there is in db, shall update with blank???
for (UWSULDDetails uwsUld : uwsInfo.getUWSULDDetails()) {
//TODO: to refactor ummmm
EntDbLoadUld loadUld = existedLoadUlds(existingLoadUlds, uwsUld.getULDNumber());
EntDbLoadUld originalUld = null;
boolean isExisted = true;
if(loadUld == null) {
loadUld = new EntDbLoadUld();
isExisted = false;
initialize(loadUld, entDbAfttab);
} else {
originalUld = new EntDbLoadUld(loadUld);
}
loadUld.setIdFlight(entDbAfttab.getUrno());
loadUld.setUldCurrFltno(flightNumber);
loadUld.setUldNumber(uwsUld.getULDNumber());
loadUld.setUldDest3(uwsUld.getDest3());
loadUld.setUldWeight(uwsUld.getWeight()+"");
loadUld.setUldWeightStatus(uwsUld.getWeightStatus());
loadUld.setUldLoadCat1(uwsUld.getLoadCat1());
loadUld.setUldLoadCat2(uwsUld.getLoadCat2());
loadUld.setUldContourCode(uwsUld.getLoadContourCode());
loadUld.setUldContourNum(uwsUld.getLoadContourNumber());
loadUld.setShcList(uwsUld.getShcList());
loadUld.setShcRemarks(uwsUld.getShcRemarks());
loadUld.setDataSource(HpEKConstants.ULD_SOURCE_SKYCHAIN);
loadUld.setRecFlag(" ");
if(isExisted) {
loadUld.setUpdatedUser(HpEKConstants.ULD_SOURCE_SKYCHAIN);
loadUld.setUpdatedDate(HpUfisCalendar.getCurrentUTCTime());
updatedLoadUlds.put(loadUld, originalUld);
} else {
loadUld.setCreatedUser(HpEKConstants.ULD_SOURCE_SKYCHAIN);
loadUld.setCreatedDate(HpUfisCalendar.getCurrentUTCTime());
newLoadUlds.add(loadUld);
}
}
if(!uwsInfo.getBULKULDDetails().isEmpty()) {
//Delete existing bulk records regarding the provided flight
dLLoadUldBean.deleteBulkUldsByFlight(entDbAfttab.getUrno());
}
for (BULKULDDetails bulkUld : uwsInfo.getBULKULDDetails()) {
//TODO: to refactor ummmm
EntDbLoadUld loadUld = new EntDbLoadUld();
initialize(loadUld, entDbAfttab);
loadUld.setUldNumber(bulkUld.getULDNumber());
loadUld.setIdFlight(entDbAfttab.getUrno());
loadUld.setUldCurrFltno(flightNumber);
loadUld.setUldDest3(bulkUld.getDest3());
loadUld.setUldWeight(bulkUld.getWeight()+"");
loadUld.setUldWeightStatus(bulkUld.getWeightStatus());
loadUld.setUldLoadCat1(bulkUld.getLoadCat1());
loadUld.setUldLoadCat2(bulkUld.getLoadCat2());
loadUld.setUldContourCode(bulkUld.getLoadContourCode());
loadUld.setUldContourNum(bulkUld.getLoadContourNumber());
loadUld.setShcList(bulkUld.getShcList());
loadUld.setShcRemarks(bulkUld.getShcRemarks());
loadUld.setDataSource(HpEKConstants.ULD_SOURCE_SKYCHAIN);
loadUld.setRecFlag(" ");
loadUld.setCreatedUser(HpEKConstants.ULD_SOURCE_SKYCHAIN);
loadUld.setCreatedDate(HpUfisCalendar.getCurrentUTCTime());
newLoadUlds.add(loadUld);
}
for (SIULDDetails siUld : uwsInfo.getSIULDDetails()) {
EntDbLoadUld loadUld = existedLoadUlds(updatedLoadUlds.keySet(), siUld.getULDNumber());
if(loadUld == null) {
loadUld = existedLoadUlds(newLoadUlds, siUld.getULDNumber());
}
if(loadUld != null) {