ULDInfo inputUldInfo = (ULDInfo) _um.unmarshal(new StreamSource(new StringReader(message)));
FlightID inputFlightID = inputUldInfo.getFlightID();
Meta inputMeta = inputUldInfo.getMeta();
ULDDetails inputUldDetails = inputUldInfo.getULDDetails();
if(existsMandatory(inputFlightID, inputMeta, inputUldDetails)){
LOG.error("Compulsory uld info are empty. Message dropped. ");
addExptInfo(EMAND.name(), "");
return false;
}
if(!inputFlightID.getCarrierCode().contains(EK)) {
LOG.error("Processing performs only for EK flight. Message will be dropped.");
addExptInfo(EWALC.name(), inputFlightID.getCarrierCode());
return false;
}
if(!inputMeta.getType().equalsIgnoreCase(ULD_INFO)) {
LOG.warn("Processing performs only for ULDInfo. Message will be dropped.");
addExptInfo(EWVAL.name(), inputMeta.getType());
return false;
}
if(!OP_TYPE.valueList().contains(inputMeta.getSubtype().trim().toUpperCase())) {
LOG.warn("Processing performs only for INS, UPD, DEL sub type. Message will be dropped.");
addExptInfo(EENUM.name(), inputMeta.getSubtype());
return false;
}
if(!inputMeta.getSource().equalsIgnoreCase(SKY_CHAIN)) {
LOG.error("Processing performs only for SkyChain. Message will be dropped.");
addExptInfo(EWVAL.name(), inputMeta.getSource());
return false;
}
String flightNumber = String
.format("%s %s%s", inputFlightID.getCarrierCode(),
formatCedaFltn(inputFlightID
.getFlightNumber()), isNullOrEmptyStr(inputFlightID
.getFlightSuffix()) ? "" : inputFlightID
.getFlightSuffix());
String flightDate = formatFlightDate(inputFlightID.getFlightDate());
if(isNullOrEmptyStr(flightDate)) {
LOG.error("Flight Date provided format parsing error is encountered. Message will be dropped.");
addExptInfo(EWVAL.name(), inputFlightID.getFlightDate());
return false;
}
LOG.debug("Formed UFIS Flight Number, Flight Date - {}, {}", flightNumber, flightDate);
EntDbAfttab entDbAfttab = afttabBean.findFlightForUldDept(flightNumber, flightDate);
LOG.debug("Flight Search by Departure is done.");
if(entDbAfttab == null) {
entDbAfttab = afttabBean.findFlightForUldOrg(flightNumber, flightDate);
}
LOG.debug("Flight Search by Non-Departure is done as the search by Departure is not found.");
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("DB - URNO : {}, FLDA : {}, Flight Date Match : {}", entDbAfttab.getUrno(), entDbAfttab.getFlda(), flightDate.equals(entDbAfttab.getFlda()));
boolean isDel = inputMeta.getSubtype().equalsIgnoreCase(OP_TYPE.DEL.name());
HpUfisAppConstants.UfisASCommands cmdForBroadcasting;
EntDbLoadUld oldLoadUld = null;
EntDbLoadUld loadUld = (EntDbLoadUld) dLLoadUldBean.getUldNum(entDbAfttab.getUrno(), inputUldDetails.getULDNumber());
//TODO: Log Telex message
if(loadUld == null) {
if(isDel){
LOG.error("ULD record does not exist to delete. Message dropped.");
addExptInfo(EnumExceptionCodes.ENOUD.name(), inputUldDetails.getULDNumber());
return false;
}
loadUld = new EntDbLoadUld();
initialize(loadUld, entDbAfttab);
loadUld.setUldCurrFltno(flightNumber);
loadUld.setUldNumber(inputUldDetails.getULDNumber().trim());
loadUld.setCreatedUser(HpEKConstants.ULD_SOURCE_SKYCHAIN);
loadUld.setCreatedDate(HpUfisCalendar.getCurrentUTCTime());
cmdForBroadcasting = HpUfisAppConstants.UfisASCommands.IRT;
} else {
oldLoadUld = new EntDbLoadUld(loadUld);
loadUld.setUpdatedUser(HpEKConstants.ULD_SOURCE_SKYCHAIN);
loadUld.setUpdatedDate(HpUfisCalendar.getCurrentUTCTime());
cmdForBroadcasting = HpUfisAppConstants.UfisASCommands.URT;
}
String uldCreatedDate = convertFlDateToUTC(TZ_DF_FORMATTER, inputUldDetails.getCreatedDate().trim());
loadUld.setUldCreateDate(new HpUfisCalendar(uldCreatedDate).getTime());
LOG.debug("ULD Created Date : {}, {}", uldCreatedDate, new HpUfisCalendar(uldCreatedDate).getTime());
loadUld.setUldCreateUser(inputUldDetails.getCreatedBy().trim());
if (!isNullOrEmptyStr(inputUldDetails.getModifiedDate())) {
String uldModifiedDate = convertFlDateToUTC(TZ_DF_FORMATTER, inputUldDetails.getModifiedDate());
loadUld.setUldUpdateDate(new HpUfisCalendar(uldModifiedDate).getTime());
LOG.debug("ULD Modified Date : {}, {}", uldModifiedDate, new HpUfisCalendar(uldModifiedDate).getTime());
}
if (!isNullOrEmptyStr(inputUldDetails.getModifiedBy())) {
loadUld.setUldUpdateUser(inputUldDetails.getModifiedBy().trim());
}
loadUld.setIdFlight(entDbAfttab.getUrno());
loadUld.setDataSource(HpEKConstants.ULD_SOURCE_SKYCHAIN);
String specialHandlingCodes = loadUld.getShcList();
List<String> specialHandlingCodeList = isNullOrEmptyStr(specialHandlingCodes) ? Collections.EMPTY_LIST : Arrays.asList(specialHandlingCodes.toUpperCase().split("\\.")) ;
String inputSHC = inputUldDetails.getSpecialHandlingCode().trim();
if(!specialHandlingCodeList.contains(inputSHC.toUpperCase())) {
loadUld.setShcList(isNullOrEmptyStr(specialHandlingCodes) ? inputSHC : specialHandlingCodes.concat(String.format(".%s", inputSHC)));
}
loadUld.setUldOwner(inputUldDetails.getOwnerCarrierCode());
loadUld.setUldDest3(inputUldDetails.getPointOfLading());
loadUld.setRecFlag(" ");
if(isDel) {
loadUld.setRecFlag("X");
cmdForBroadcasting = HpUfisAppConstants.UfisASCommands.DRT;