jobAssign.setRecStatus(rec_status);
jobAssign.setUpdatedDate(HpUfisCalendar.getCurrentUTCTime());
jobAssign.setUpdatedUser(HpEKConstants.RMS_RTC_SOURCE);
jobAssign.setMsgSendDate(msgSendDate);
EntDbStaffShift dbStaffShift = null;
if(!isNullOrEmptyStr(jobAssign.getIdStaffShift())){
//one job per one shift
dbStaffShift = clsDlStaffShiftLocal.findById(jobAssign.getIdStaffShift());
if(dbStaffShift != null){
//update "X" only when Shift exist
dbStaffShift.setRecStatus(rec_status);
dbStaffShift.setUpdatedDate(HpUfisCalendar.getCurrentUTCTime());
dbStaffShift.setUpdatedUser(HpEKConstants.RMS_RTC_SOURCE);
dbStaffShift.setMsgSendDate(msgSendDate);
}
}
//merge to DB
EntDbFltJobAssign resultJob = clsDlFltJobAssignLocal.merge(jobAssign);
if(resultJob != null)
LOG.debug("Removed assigned job for Staff <{}>.", resultJob.getStaffNumber());
EntDbStaffShift resultShift = clsDlStaffShiftLocal.merge(dbStaffShift);
if(resultShift != null)
LOG.debug("Removed assign shift for Staff <{}>.", resultShift.getStaffNumber());
}else if(" ".equals(rec_status)){
/** UPDATE JOB_ASSIGN **/
if(_inputStaffDetail.getID() != null)//Conditional case
jobAssign.setStaffNumber(_inputStaffDetail.getID());
if(_inputStaffDetail.getName() != null)
jobAssign.setStaffName(_inputStaffDetail.getName());
//Service Detail
ServiceDetailsType _inputServiceDetailsType = _inputStaffDetail.getServiceDetails();
if(_inputServiceDetailsType == null){
LOG.debug("No Service Detail in input Staff <{}>.", _inputStaffDetail.getID());
return;
}
String serCode = null;
if (_inputServiceDetailsType.getServiceCode() != null) {// check in MD table
for (EntDbMdRmsServCode servicCode : clsEntStartUpInitSingleton.getMdRmsServCodesList()) {
if (_inputServiceDetailsType.getServiceCode().equalsIgnoreCase(servicCode.getStaffTypeCode())) {
if(servicCode.getStaffTypeCode().equalsIgnoreCase(HpEKConstants.RMS_STAFF_TYPE_SPHL))
serCode = _inputStaffDetail.getServiceDetails().getServiceCode(); break;
}
}
if(serCode == null)
LOG.debug("Service Code <{}> is not found in MdRmsServiceCode table.", _inputServiceDetailsType.getServiceCode());
jobAssign.setSpecialService(_inputServiceDetailsType.getServiceCode());
}
String paxSeq = String.valueOf(_inputServiceDetailsType.getPaxSequence());
// 2013-11-22 updated by JGO - remove pax_ref_num and add pax_name for sphl
//jobAssign.setPaxRefNum(paxSeq);
String paxName = _inputServiceDetailsType.getPaxName();
if (_input.getMeta().getSource().contains("SPHL") && HpUfisUtils.isNotEmptyStr(paxName)) {
paxName = paxName.replaceAll("/", " ");
// find the pax from macs
// check from load pax table by id_flight, paxname and status <> 'x'
List<EntDbLoadPax> paxes = loadPaxBean.findPaxByFlightAndName(jobAssign.getIdFlight(), paxName);
String idLoadPax = "0";
String idServiceReq = "0";
if (paxes.size() == 0) {
LOG.warn("No Pax found in Lod_Pax table by id_flight: {} and pax_name: {}",
jobAssign.getIdFlight(),
paxName);
} else if (paxes.size() > 1) {
LOG.warn("More than 1 Pax found in Load_Pax table by id_flight: {} and pax_name: {}",
jobAssign.getIdFlight(),
paxName);
} else {
idLoadPax = paxes.get(0).getUuid();
// look for service request for the pax
// fisrt round: search by id_load_pax and service_code
LOG.debug("Find service request from service_request table");
List<EntDbServiceRequest> requests = serviceRequestBean
.findPaxRequest(null, idLoadPax, _inputServiceDetailsType.getServiceCode(), null);
if (requests == null || requests.size() == 0) {
LOG.warn("No service request found by id_load_pax: {} and service_code: {}",
idLoadPax,
_inputServiceDetailsType.getServiceCode());
LOG.debug("Change Criteria to find service request");
// if not found, second round: search by id_flight, inter_ref_number and service_code
requests = serviceRequestBean.findPaxRequest(jobAssign.getIdFlight(), null,
_inputServiceDetailsType.getServiceCode(), paxes.get(0)
.getPKId().getIntrefnumber());
}
if (requests == null || requests.size() == 0) {
LOG.warn("No service request found by id_flight: {}, interRefNumber: {} and service_code: {}",
jobAssign.getIdFlight(),
paxes.get(0).getPKId().getIntrefnumber(),
_inputServiceDetailsType.getServiceCode());
} else {
idServiceReq = requests.get(0).getUuid();
}
}
jobAssign.setIdLoadPax(idLoadPax);
jobAssign.setIdServiceReq(idServiceReq);
jobAssign.setPaxName(paxName);
}
jobAssign.setChargeNote(String.valueOf(_inputServiceDetailsType.getDocNumber()));
//Equipment
EquipmentType equipType = _input.getTaskDetails().getResources().getEquipment();
EquipmentDetailsType equip = new EquipmentDetailsType();
if(equipType != null && !equipType.getEquipmentDetails().isEmpty()){//Conditional case
equip = equipType.getEquipmentDetails().get(0);//get the first equip ONLY
if(equip.getID() != null)//Conditional case
jobAssign.setEquipId(equip.getID());
if(equip.getDescription() != null)
jobAssign.setEquipDesc(equip.getDescription());
}else{
jobAssign.setEquipId(null);
jobAssign.setEquipDesc(null);
}
jobAssign.setTransactUser(_input.getAudit().getChangeUser());
jobAssign.setTransactDate(convertDateToUTC(_input.getAudit().getChangeTime()));
jobAssign.setMsgSendDate(msgSendDate);
jobAssign.setRecStatus(rec_status);
jobAssign.setStaffType(HpEKConstants.RMS_STAFF_TYPE_SPHL);
jobAssign.setDataSource(HpEKConstants.RMS_RTC_SOURCE);
jobAssign.setUpdatedDate(HpUfisCalendar.getCurrentUTCTime());
jobAssign.setUpdatedUser(HpEKConstants.RMS_RTC_SOURCE);
//merge JOB_ASSIGN to db
EntDbFltJobAssign resultJobAssign = clsDlFltJobAssignLocal.merge(jobAssign);
if(resultJobAssign != null)
LOG.debug("Assigned job has been updated for Staff <{}>", resultJobAssign.getStaffNumber());
/** UPDATE shift **/
if(isNullOrEmptyStr(jobAssign.getIdStaffShift())){
LOG.debug("No input shift to update for staff <{}>", jobAssign.getStaffNumber());
}else{
EntDbStaffShift dbStaffShift = clsDlStaffShiftLocal.findById(jobAssign.getIdStaffShift());
if(dbStaffShift != null){//is existing..
dbStaffShift.setUpdatedDate(HpUfisCalendar.getCurrentUTCTime());
dbStaffShift.setUpdatedUser(HpEKConstants.RMS_RTC_SOURCE);
}
else{
dbStaffShift = new EntDbStaffShift();
dbStaffShift.setCreatedDate(HpUfisCalendar.getCurrentUTCTime());
dbStaffShift.setCreatedUser(HpEKConstants.RMS_RTC_SOURCE);
}
if(_inputStaffDetail.getID() != null)//Conditional case
dbStaffShift.setStaffNumber(_inputStaffDetail.getID());
if(_inputStaffDetail.getName() != null)
dbStaffShift.setStaffName(_inputStaffDetail.getName());
if(_inputStaffDetail.getWalkie() != null)
dbStaffShift.setStaffWalkieNo(_inputStaffDetail.getWalkie());
if(_inputStaffDetail.getQualification() != null)
dbStaffShift.setStaffQualification(_inputStaffDetail.getQualification());
dbStaffShift.setRecStatus(rec_status);
dbStaffShift.setMsgSendDate(msgSendDate);
dbStaffShift.setStaffType(HpEKConstants.RMS_STAFF_TYPE_SPHL);
dbStaffShift.setDataSource(HpEKConstants.RMS_RTC_SOURCE);
dbStaffShift.setStaffType(HpEKConstants.RMS_STAFF_TYPE_SPHL);
EntDbStaffShift resultShift = clsDlStaffShiftLocal.merge(dbStaffShift);
if(resultShift != null)
LOG.debug("Assigned shift has been updated for Staff <{}>.", resultShift.getStaffNumber());
}
}
}