$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <cassert> 00006 #include <ostream> 00007 #if BOOST_VERSION >= 103400 00008 // Boost ForEach 00009 #include <boost/foreach.hpp> 00010 #endif // BOOST_VERSION >= 103400 00011 // StdAir 00012 #include <stdair/stdair_date_time_types.hpp> 00013 #include <stdair/basic/BasConst_BomDisplay.hpp> 00014 #include <stdair/bom/BomManager.hpp> 00015 #include <stdair/bom/BomRoot.hpp> 00016 #include <stdair/bom/Inventory.hpp> 00017 #include <stdair/bom/FlightDate.hpp> 00018 #include <stdair/bom/LegDate.hpp> 00019 #include <stdair/bom/SegmentDate.hpp> 00020 #include <stdair/bom/LegCabin.hpp> 00021 #include <stdair/bom/SegmentCabin.hpp> 00022 #include <stdair/bom/FareFamily.hpp> 00023 #include <stdair/bom/BookingClass.hpp> 00024 #include <stdair/bom/Bucket.hpp> 00025 #include <stdair/bom/EventStruct.hpp> 00026 #include <stdair/bom/EventTypes.hpp> 00027 #include <stdair/bom/BookingRequestStruct.hpp> 00028 #include <stdair/bom/BreakPointStruct.hpp> 00029 #include <stdair/bom/BomJSONExport.hpp> 00030 00031 namespace stdair { 00032 00033 // //////////////////////////////////////////////////////////////////// 00034 void BomJSONExport:: 00035 jsonExportFlightDateList (std::ostream& oStream, 00036 const BomRoot& iBomRoot, 00037 const AirlineCode_T& iAirlineCode, 00038 const FlightNumber_T& iFlightNumber) { 00039 00040 // Check whether there are Inventory objects 00041 if (BomManager::hasList<Inventory> (iBomRoot) == false) { 00042 return; 00043 } 00044 00045 #if BOOST_VERSION >= 104100 00046 00047 // Create empty property tree objects 00048 bpt::ptree pt; 00049 bpt::ptree ptInventoryList; 00050 00051 // Browse the inventories 00052 const InventoryList_T& lInventoryList = 00053 BomManager::getList<Inventory> (iBomRoot); 00054 for (InventoryList_T::const_iterator itInv = lInventoryList.begin(); 00055 itInv != lInventoryList.end(); ++itInv) { 00056 const Inventory* lInv_ptr = *itInv; 00057 assert (lInv_ptr != NULL); 00058 00059 // Retrieve the inventory key (airline code) 00060 const AirlineCode_T& lAirlineCode = lInv_ptr->getAirlineCode(); 00061 00062 // Display only the requested inventories 00063 if (iAirlineCode == "all" || iAirlineCode == lAirlineCode) { 00064 00065 // Flight date tree 00066 bpt::ptree ptFD; 00067 // Create an empty flight-dates array 00068 bpt::ptree lFDDatePropertyTree; 00069 00070 // Check whether there are FlightDate objects 00071 if (BomManager::hasMap<FlightDate> (*lInv_ptr) == false) { 00072 return; 00073 } 00074 00075 // Browse the flight-dates 00076 const FlightDateMap_T& lFlightDateList = 00077 BomManager::getMap<FlightDate> (*lInv_ptr); 00078 for (FlightDateMap_T::const_iterator itFD = lFlightDateList.begin(); 00079 itFD != lFlightDateList.end(); ++itFD) { 00080 const FlightDate* lFD_ptr = itFD->second; 00081 assert (lFD_ptr != NULL); 00082 00083 // Retrieve the key of the flight-date 00084 const FlightNumber_T& lFlightNumber = lFD_ptr->getFlightNumber(); 00085 const Date_T& lFlightDateDate = lFD_ptr->getDepartureDate(); 00086 00087 // Display only the requested flight number 00088 if (iFlightNumber == 0 || iFlightNumber == lFlightNumber) { 00089 00090 // Add the airline code to the inventory tree 00091 ptFD.put ("airline_code", lAirlineCode); 00092 // Put flight number in property tree 00093 ptFD.put ("number", lFlightNumber); 00094 // Put flight date date in property tree 00095 ptFD.put ("date", lFlightDateDate); 00096 00097 // Put the current flight date tree in the array 00098 ptInventoryList.push_back(std::make_pair("", ptFD)); 00099 00100 } 00101 } 00102 00103 } 00104 } 00105 00106 // Store the inventory(ies) array tree into the global tree 00107 pt.add_child ("inventories", ptInventoryList); 00108 00109 // Write the property tree into the JSON stream. 00110 write_json (oStream, pt); 00111 #endif // BOOST_VERSION >= 104100 00112 } 00113 00114 // //////////////////////////////////////////////////////////////////// 00115 void BomJSONExport::jsonExportFlightDate (bpt::ptree& ioFDPropertyTree, 00116 const Inventory& iInventory, 00117 const FlightNumber_T& iFlightNumber) { 00118 00119 // Check whether there are FlightDate objects 00120 if (BomManager::hasMap<FlightDate> (iInventory) == false) { 00121 return; 00122 } 00123 00124 #if BOOST_VERSION >= 104100 00125 00126 // Create an empty flight-dates array 00127 bpt::ptree lFDDatePropertyTree; 00128 00129 // Browse the flight-dates 00130 const FlightDateMap_T& lFlightDateList = 00131 BomManager::getMap<FlightDate> (iInventory); 00132 for (FlightDateMap_T::const_iterator itFD = lFlightDateList.begin(); 00133 itFD != lFlightDateList.end(); ++itFD) { 00134 const FlightDate* lFD_ptr = itFD->second; 00135 assert (lFD_ptr != NULL); 00136 00137 // Retrieve the key of the flight-date 00138 const FlightNumber_T& lFlightNumber = lFD_ptr->getFlightNumber(); 00139 const Date_T& lFlightDateDate = lFD_ptr->getDepartureDate(); 00140 00141 // Display only the requested flight number 00142 if (iFlightNumber == 0 || iFlightNumber == lFlightNumber) { 00143 00144 // Create an empty property tree object for the current flight date 00145 bpt::ptree lCurrFDTree; 00146 00147 // Put flight number in property tree 00148 lCurrFDTree.put ("number", lFlightNumber); 00149 // Put flight date date in property tree 00150 lCurrFDTree.put ("date", lFlightDateDate); 00151 00152 // Put the current flight date tree in the flight date array 00153 ioFDPropertyTree.push_back(std::make_pair("", lCurrFDTree)); 00154 00155 } 00156 } 00157 #endif // BOOST_VERSION >= 104100 00158 00159 } 00160 00161 // //////////////////////////////////////////////////////////////////// 00162 void BomJSONExport:: 00163 jsonExportFlightDateObjects (std::ostream& oStream, 00164 const FlightDate& iFlightDate) { 00165 00166 #if BOOST_VERSION >= 104100 00167 00171 // Create an empty property tree object 00172 bpt::ptree pt; 00173 00174 // Put the airline code in property tree 00175 const AirlineCode_T& lAirlineCode = iFlightDate.getAirlineCode(); 00176 pt.put ("flight_date.airline_code", lAirlineCode); 00177 00178 // Put the flight number in property tree 00179 const FlightNumber_T& lFlightNumber = iFlightDate.getFlightNumber(); 00180 pt.put ("flight_date.flight_number", lFlightNumber); 00181 00182 // Put the flight departure date in property tree 00183 const Date_T& lFlightDateDate = iFlightDate.getDepartureDate(); 00184 const std::string& lDepartureDateStr = 00185 boost::gregorian::to_simple_string (lFlightDateDate); 00186 pt.put ("flight_date.departure_date", lDepartureDateStr); 00187 00191 // Create an empty legs array 00192 bpt::ptree ptLegs; 00193 00194 // Recursively construct the legs array 00195 jsonExportLegDate (ptLegs, iFlightDate); 00196 00197 // Add legs tree to the global property tree 00198 pt.add_child ("flight_date.legs", ptLegs); 00199 00203 // Create an empty segments array 00204 bpt::ptree ptSegments; 00205 00206 // Recursively construct the segments array 00207 jsonExportSegmentDate (ptSegments, iFlightDate); 00208 00209 // Add segments tree to the global property tree 00210 pt.add_child ("flight_date.segments", ptSegments); 00211 00212 // Write the property tree into the JSON stream. 00213 write_json (oStream, pt); 00214 00215 #endif // BOOST_VERSION >= 104100 00216 } 00217 00218 // //////////////////////////////////////////////////////////////////// 00219 void BomJSONExport::jsonExportLegDate (bpt::ptree& ioLegDateListTree, 00220 const FlightDate& iFlightDate) { 00221 00222 // Check whether there are LegDate objects 00223 if (BomManager::hasList<LegDate> (iFlightDate) == false) { 00224 return; 00225 } 00226 00227 // Browse the leg-dates 00228 const LegDateList_T& lLegDateList = 00229 BomManager::getList<LegDate> (iFlightDate); 00230 for (LegDateList_T::const_iterator itLD = lLegDateList.begin(); 00231 itLD != lLegDateList.end(); ++itLD) { 00232 const LegDate* lLD_ptr = *itLD; 00233 assert (lLD_ptr != NULL); 00234 00235 #if BOOST_VERSION >= 104100 00236 00237 // Create an empty property tree object for the current leg date 00238 bpt::ptree lCurrLDTree; 00239 00240 // Put boarding point in property tree 00241 const AirportCode_T& lBoardingPoint = lLD_ptr->getBoardingPoint(); 00242 lCurrLDTree.put ("board_point", lBoardingPoint); 00243 // Put off point in property tree 00244 const AirportCode_T& lOffPoint = lLD_ptr->getOffPoint(); 00245 lCurrLDTree.put ("off_point", lOffPoint); 00246 // Put boarding date in property tree 00247 const Date_T& lBoardingDate = lLD_ptr->getBoardingDate(); 00248 lCurrLDTree.put ("board_date", lBoardingDate); 00249 // Put off date in property tree 00250 const Date_T& lOffDate = lLD_ptr->getOffDate(); 00251 lCurrLDTree.put ("off_dDate", lOffDate); 00252 // Put boarding time in property tree 00253 const Duration_T& lBoardingTime = lLD_ptr->getBoardingTime(); 00254 lCurrLDTree.put ("board_time", lBoardingTime); 00255 // Put off time in property tree 00256 const Duration_T& lOffTime = lLD_ptr->getOffTime(); 00257 lCurrLDTree.put ("off_time", lOffTime); 00258 // Put elapsed time in property tree 00259 const Duration_T& lElapsedTime = lLD_ptr->getElapsedTime(); 00260 lCurrLDTree.put ("elapsed_time", lElapsedTime); 00261 // Put date offset in property tree 00262 const DateOffset_T& lDateOffset = lLD_ptr->getDateOffset(); 00263 lCurrLDTree.put ("date_offset", lDateOffset); 00264 // Put time offset in property tree 00265 const Duration_T& lTimeOffset = lLD_ptr->getTimeOffset(); 00266 lCurrLDTree.put ("time_offset", lTimeOffset); 00267 // Put distance in property tree 00268 const Distance_T& lDistance = lLD_ptr->getDistance(); 00269 lCurrLDTree.put ("distance", lDistance); 00270 // Put capacity in property tree 00271 const CabinCapacity_T& lCapacity = lLD_ptr->getCapacity(); 00272 lCurrLDTree.put ("capacity", lCapacity); 00273 00274 // Create an empty property tree object for the leg cabins array 00275 // corresponding to the current leg date. 00276 bpt::ptree lLegCabinArray; 00277 00278 // Recursively construct the leg cabins array 00279 jsonExportLegCabin (lLegCabinArray, *lLD_ptr); 00280 00281 // Add the leg cabins array to the leg date tree 00282 lCurrLDTree.add_child ("cabins", lLegCabinArray); 00283 00284 // Put the current leg date tree in the leg date list tree 00285 ioLegDateListTree.push_back(std::make_pair("", lCurrLDTree)); 00286 00287 #endif // BOOST_VERSION >= 104100 00288 } 00289 } 00290 00291 // //////////////////////////////////////////////////////////////////// 00292 void BomJSONExport::jsonExportLegCabin (bpt::ptree& ioLegCabinListTree, 00293 const LegDate& iLegDate) { 00294 00295 // Check whether there are LegCabin objects 00296 if (BomManager::hasList<LegCabin> (iLegDate) == false) { 00297 return; 00298 } 00299 00300 // Browse the leg-cabins 00301 const LegCabinList_T& lLegCabinList = 00302 BomManager::getList<LegCabin> (iLegDate); 00303 for (LegCabinList_T::const_iterator itLC = lLegCabinList.begin(); 00304 itLC != lLegCabinList.end(); ++itLC) { 00305 const LegCabin* lLC_ptr = *itLC; 00306 assert (lLC_ptr != NULL); 00307 00308 #if BOOST_VERSION >= 104100 00309 00310 // Create an empty property tree object for the current leg cabin 00311 bpt::ptree lCurrLCTree; 00312 bpt::ptree lCurrLCBPV; 00313 00314 // Put the cabin code in property tree 00315 const CabinCode_T& lCabinCode = lLC_ptr->getCabinCode(); 00316 lCurrLCTree.put ("code", lCabinCode); 00317 // Put the offered capacity in property tree 00318 const CabinCapacity_T& lOfferedCapacity = lLC_ptr->getOfferedCapacity(); 00319 lCurrLCTree.put ("offed_cap", lOfferedCapacity); 00320 // Put the physical capacity in property tree 00321 const CabinCapacity_T& lPhysicalCapacity = lLC_ptr->getPhysicalCapacity(); 00322 lCurrLCTree.put ("phy_cap", lPhysicalCapacity); 00323 // Put regrade adjustment in property tree 00324 const CapacityAdjustment_T& lRegradeAdjustment = lLC_ptr->getRegradeAdjustment(); 00325 lCurrLCTree.put ("rgd_adj", lRegradeAdjustment); 00326 // Put authorization level in property tree 00327 const AuthorizationLevel_T& lAuthorizationLevel = lLC_ptr->getAuthorizationLevel(); 00328 lCurrLCTree.put ("au", lAuthorizationLevel); 00329 // Put UPR in property tree 00330 const UPR_T& lUPR = lLC_ptr->getUPR(); 00331 lCurrLCTree.put ("upr", lUPR); 00332 // Put sold seats in property tree 00333 const NbOfSeats_T& lNbOfSoldSeats = lLC_ptr->getSoldSeat(); 00334 lCurrLCTree.put ("ss", lNbOfSoldSeats); 00335 // Put staff nb of seats in property tree 00336 const NbOfSeats_T& lStaffNbOfSeats = lLC_ptr->getStaffNbOfSeats(); 00337 lCurrLCTree.put ("staff", lStaffNbOfSeats); 00338 // Put waiting list nb of seats in property tree 00339 const NbOfSeats_T& lWLNbOfSeats = lLC_ptr->getWLNbOfSeats(); 00340 lCurrLCTree.put ("wl", lWLNbOfSeats); 00341 // Put group nb of seats in property tree 00342 const NbOfSeats_T& lGroupNbOfSeats = lLC_ptr->getGroupNbOfSeats(); 00343 lCurrLCTree.put ("group", lGroupNbOfSeats); 00344 // Put committed space in property tree 00345 const CommittedSpace_T& lCommittedSpace = lLC_ptr->getCommittedSpace(); 00346 lCurrLCTree.put ("comm_space", lCommittedSpace); 00347 // Put availability pool in property tree 00348 const Availability_T& lAvailabilityPool = lLC_ptr->getAvailabilityPool(); 00349 lCurrLCTree.put ("av_pool", lAvailabilityPool); 00350 // Put availability in property tree 00351 const Availability_T& lAvailability = lLC_ptr->getAvailability(); 00352 lCurrLCTree.put ("avl", lAvailability); 00353 // Put net availability in property tree 00354 const Availability_T& lNetAvailability = lLC_ptr->getNetAvailability(); 00355 lCurrLCTree.put ("nav", lNetAvailability); 00356 // Put gross availability in property tree 00357 const Availability_T& lGrossAvailability = lLC_ptr->getGrossAvailability(); 00358 lCurrLCTree.put ("gav", lGrossAvailability); 00359 // Put avg cancellation percentage in property tree 00360 const OverbookingRate_T& lAvgCancellationPercentage = 00361 lLC_ptr->getAvgCancellationPercentage(); 00362 lCurrLCTree.put ("acp", lAvgCancellationPercentage); 00363 // Put ETB in property tree 00364 const NbOfSeats_T& lExpectedToBoard = lLC_ptr->getETB(); 00365 lCurrLCTree.put ("etb", lExpectedToBoard ); 00366 // Put current bid price in property tree 00367 const BidPrice_T& lCurrentBidPrice = lLC_ptr->getCurrentBidPrice(); 00368 lCurrLCTree.put ("bid_price", lCurrentBidPrice); 00369 // Put current bid price vector in property tree 00370 const BidPriceVector_T& lCurrentBidPriceVector = 00371 lLC_ptr->getBidPriceVector(); 00372 std::ostringstream ostr; 00373 BidPriceVector_T::const_iterator itBP = lCurrentBidPriceVector.begin(); 00374 while (itBP != lCurrentBidPriceVector.end()) { 00375 ostr << *itBP; 00376 ++itBP; 00377 if (itBP != lCurrentBidPriceVector.end()) { 00378 ostr << ","; 00379 } 00380 } 00381 lCurrLCTree.put ("BPV", ostr.str()); 00382 00383 // Create an empty property tree object for the buckets array 00384 // corresponding to the current leg cabin. 00385 bpt::ptree lBucketTree; 00386 00387 // Recursively construct the buckets array 00388 jsonExportBucket (lBucketTree, *lLC_ptr); 00389 00390 // Add the buckets array to the leg cabin tree 00391 lCurrLCTree.add_child ("buckets", lBucketTree); 00392 00393 // Put the current leg cabin tree in the leg cabin list tree 00394 ioLegCabinListTree.push_back(std::make_pair("", lCurrLCTree)); 00395 00396 #endif // BOOST_VERSION >= 104100 00397 } 00398 } 00399 00400 // //////////////////////////////////////////////////////////////////// 00401 void BomJSONExport::jsonExportBucket (bpt::ptree& ioBucketListTree, 00402 const LegCabin& iLegCabin) { 00403 00408 // Check whether there are Bucket objects 00409 if (BomManager::hasList<Bucket> (iLegCabin) == false) { 00410 return; 00411 } 00412 00413 // Browse the buckets 00414 const BucketList_T& lBucketList = BomManager::getList<Bucket> (iLegCabin); 00415 for (BucketList_T::const_iterator itBuck = lBucketList.begin(); 00416 itBuck != lBucketList.end(); ++itBuck) { 00417 const Bucket* lBucket_ptr = *itBuck; 00418 assert (lBucket_ptr != NULL); 00419 00420 #if BOOST_VERSION >= 104100 00421 00422 // Create an empty property tree object for the current bucket 00423 bpt::ptree lCurrBucketTree; 00424 00425 // Put yield in property tree 00426 const Yield_T& lYieldRangeUpperValue = 00427 lBucket_ptr->getYieldRangeUpperValue(); 00428 lCurrBucketTree.put ("yield", lYieldRangeUpperValue); 00429 // Put seat_index in property tree 00430 const SeatIndex_T& lSeatIndex = lBucket_ptr->getSeatIndex(); 00431 lCurrBucketTree.put ("si", lSeatIndex); 00432 // Put sold_seats in property tree 00433 const NbOfSeats_T& lSoldSeats = lBucket_ptr->getSoldSeats(); 00434 lCurrBucketTree.put ("ss", lSoldSeats); 00435 // Put avaibility in property tree 00436 const CabinCapacity_T& lAvailability = lBucket_ptr->getAvailability(); 00437 lCurrBucketTree.put ("av", lAvailability); 00438 00439 // Put the current bucket tree in the bucket list tree 00440 ioBucketListTree.push_back(std::make_pair("", lCurrBucketTree)); 00441 00442 #endif // BOOST_VERSION >= 104100 00443 } 00444 } 00445 00446 // //////////////////////////////////////////////////////////////////// 00447 void BomJSONExport::jsonExportSegmentDate (bpt::ptree& ioSegmentDateTree, 00448 const FlightDate& iFlightDate) { 00449 00450 // Check whether there are SegmentDate objects 00451 if (BomManager::hasList<SegmentDate> (iFlightDate) == false) { 00452 return; 00453 } 00454 00455 // Browse the segment-dates 00456 const SegmentDateList_T& lSegmentDateList = 00457 BomManager::getList<SegmentDate> (iFlightDate); 00458 for (SegmentDateList_T::const_iterator itSD = lSegmentDateList.begin(); 00459 itSD != lSegmentDateList.end(); ++itSD) { 00460 const SegmentDate* lSD_ptr = *itSD; 00461 assert (lSD_ptr != NULL); 00462 00463 #if BOOST_VERSION >= 104100 00464 00465 // Create an empty property tree object for the current segment date 00466 bpt::ptree lCurrSDTree; 00467 00468 // Put segment key in property tree 00469 lCurrSDTree.put ("segment", lSD_ptr->toString()); 00470 00471 // Create an empty property tree object for the segment cabin array 00472 // corresponding to the current segment date 00473 bpt::ptree lSegmentCabinTree; 00474 00475 // Recursively construct the segment cabin array 00476 jsonExportSegmentCabin (lSegmentCabinTree, *lSD_ptr); 00477 00478 // Add the segment cabin array to the tree of the current segment date 00479 lCurrSDTree.add_child ("sub_classes", lSegmentCabinTree); 00480 00481 // Put segment date array in property tree 00482 ioSegmentDateTree.push_back(std::make_pair("", lCurrSDTree)); 00483 00484 #endif // BOOST_VERSION >= 104100 00485 } 00486 } 00487 00488 // //////////////////////////////////////////////////////////////////// 00489 void BomJSONExport::jsonExportSegmentCabin (bpt::ptree& ioPropertyTree, 00490 const SegmentDate& iSegmentDate) { 00491 00492 // Check whether there are SegmentCabin objects 00493 if (BomManager::hasList<SegmentCabin> (iSegmentDate) == false) { 00494 return; 00495 } 00496 00497 // Browse the segment-cabins 00498 const SegmentCabinList_T& lSegmentCabinList = 00499 BomManager::getList<SegmentCabin> (iSegmentDate); 00500 for (SegmentCabinList_T::const_iterator itSC = lSegmentCabinList.begin(); 00501 itSC != lSegmentCabinList.end(); ++itSC) { 00502 const SegmentCabin* lSC_ptr = *itSC; 00503 assert (lSC_ptr != NULL); 00504 00505 #if BOOST_VERSION >= 104100 00506 // Create an empty property tree object for the current segment cabin 00507 bpt::ptree lSCArray; 00508 00509 // Put cabin in property tree 00510 00511 lSCArray.put ("cabin_code",lSC_ptr->toString()); 00512 00513 // Export the cabin tree to add fare-families and sub-classes details 00514 jsonExportFareFamily (ioPropertyTree, lSCArray, *lSC_ptr); 00515 00516 #endif // BOOST_VERSION >= 104100 00517 00518 } 00519 } 00520 00521 // //////////////////////////////////////////////////////////////////// 00522 void BomJSONExport::jsonExportFareFamily (bpt::ptree& ioPropertyTree, 00523 bpt::ptree& ioSCTree, 00524 const SegmentCabin& iSegmentCabin) { 00525 00526 // Check whether there are FareFamily objects 00527 if (BomManager::hasList<FareFamily> (iSegmentCabin) == true) { 00528 00529 // Browse the fare-families 00530 const FareFamilyList_T& lFareFamilyList = 00531 BomManager::getList<FareFamily> (iSegmentCabin); 00532 for (FareFamilyList_T::const_iterator itFF = lFareFamilyList.begin(); 00533 itFF != lFareFamilyList.end(); ++itFF) { 00534 const FareFamily* lFF_ptr = *itFF; 00535 assert (lFF_ptr != NULL); 00536 00537 // Browse the booking-classes 00538 const BookingClassList_T& lBookingClassList = 00539 BomManager::getList<BookingClass> (*lFF_ptr); 00540 for (BookingClassList_T::const_iterator itBC = 00541 lBookingClassList.begin(); 00542 itBC != lBookingClassList.end(); ++itBC) { 00543 const BookingClass* lBC_ptr = *itBC; 00544 assert (lBC_ptr != NULL); 00545 00546 #if BOOST_VERSION >= 104100 00547 00548 // Put family code in property tree 00549 const FamilyCode_T& lFamilyCode = lFF_ptr->getFamilyCode(); 00550 ioSCTree.put ("family_code", lFamilyCode); 00551 00552 // Export the cabin tree to add sub-classes details 00553 jsonExportBookingClass (ioPropertyTree, ioSCTree, *lBC_ptr); 00554 00555 #endif // BOOST_VERSION >= 104100 00556 00557 } 00558 } 00559 } else { 00560 00561 // The fare family code is a fake one ('NoFF'), and therefore 00562 // does not vary 00563 const FamilyCode_T lDefaultFamilyCode ("NoFF"); 00564 00565 // Browse the booking-classes, directly from the segment-cabin object 00566 const BookingClassList_T& lBookingClassList = 00567 BomManager::getList<BookingClass> (iSegmentCabin); 00568 for (BookingClassList_T::const_iterator itBC = 00569 lBookingClassList.begin(); 00570 itBC != lBookingClassList.end(); ++itBC) { 00571 const BookingClass* lBC_ptr = *itBC; 00572 assert (lBC_ptr != NULL); 00573 00574 #if BOOST_VERSION >= 104100 00575 00576 // Put family code in property tree 00577 ioSCTree.put ("family_code", lDefaultFamilyCode); 00578 00579 // Export the cabin tree to add sub-classes details 00580 jsonExportBookingClass (ioPropertyTree, ioSCTree, *lBC_ptr); 00581 00582 #endif // BOOST_VERSION >= 104100 00583 } 00584 } 00585 } 00586 00587 // //////////////////////////////////////////////////////////////////// 00588 void BomJSONExport::jsonExportBookingClass (bpt::ptree& ioPropertyTree, 00589 bpt::ptree& ioSCTree, 00590 const BookingClass& iBookingClass) { 00591 00597 #if BOOST_VERSION >= 104100 00598 00599 // Put sub class in property tree 00600 ioSCTree.put ("class_code", iBookingClass.toString()); 00601 // Put authorization level in property tree 00602 std::ostringstream oAUBlStr; 00603 oAUBlStr << iBookingClass.getAuthorizationLevel(); 00604 //<< " (" << iBookingClass.getCumulatedBookingLimit() 00605 //<< ") "; 00606 ioSCTree.put ("au", oAUBlStr.str()); 00607 // Put negotiated space in property tree 00608 const NbOfSeats_T& lNegotiatedSpace = 00609 iBookingClass.getNegotiatedSpace(); 00610 ioSCTree.put ("nego", lNegotiatedSpace); 00611 // Put no show percentage in property tree 00612 const OverbookingRate_T& lNoShowPercentage = 00613 iBookingClass.getNoShowPercentage(); 00614 ioSCTree.put ("ns%", lNoShowPercentage); 00615 // Put cancellation percentage in property tree 00616 const OverbookingRate_T& lCancellationPercentage = 00617 iBookingClass.getCancellationPercentage(); 00618 ioSCTree.put ("ob%", lCancellationPercentage); 00619 // Put sub nb of bookings in property tree 00620 const NbOfBookings_T lNbOfBookings = 00621 iBookingClass.getNbOfBookings(); 00622 ioSCTree.put ("bkgs", lNbOfBookings); 00623 // Put nb of group bookings in property tree 00624 const NbOfBookings_T& lNbOfGroupBookings = 00625 iBookingClass.getNbOfGroupBookings(); 00626 ioSCTree.put ("grp_bks (pdg)", lNbOfGroupBookings); 00627 // Put nb of staff bookings in property tree 00628 const NbOfBookings_T& lNbOfStaffBookings = 00629 iBookingClass.getNbOfStaffBookings(); 00630 ioSCTree.put ("stf_bkgs", lNbOfStaffBookings); 00631 // Put nb of WL bookings in property tree 00632 const NbOfBookings_T& lNbOfWLBookings = 00633 iBookingClass.getNbOfWLBookings(); 00634 ioSCTree.put ("wl_bkgs", lNbOfWLBookings); 00635 // Put ETB in property tree 00636 const NbOfBookings_T& lETB = iBookingClass.getETB(); 00637 ioSCTree.put ("etb", lETB); 00638 // Put net class availability in property tree 00639 const Availability_T& lNetClassAvailability = 00640 iBookingClass.getNetClassAvailability(); 00641 ioSCTree.put ("class_avl", lNetClassAvailability); 00642 // Put segment availability in property tree 00643 const Availability_T& lSegmentAvailability = 00644 iBookingClass.getSegmentAvailability(); 00645 ioSCTree.put ("seg_avl", lSegmentAvailability); 00646 // Put net revenue availability in property tree 00647 const Availability_T& lNetRevenueAvailability = 00648 iBookingClass.getNetRevenueAvailability(); 00649 ioSCTree.put ("rev_avl", lNetRevenueAvailability); 00650 00651 // Add the sub-classe (containing cabin and fare-families information) 00652 // to the global tree 00653 ioPropertyTree.push_back(std::make_pair("", ioSCTree)); 00654 00655 #endif // BOOST_VERSION >= 104100 00656 } 00657 00658 // //////////////////////////////////////////////////////////////////// 00659 void BomJSONExport:: 00660 jsonExportBookingRequestObject (std::ostream& oStream, 00661 const EventStruct& iEventStruct) { 00662 00663 // Get the current event type: it should be booking request 00664 const EventType::EN_EventType& lEventType = 00665 iEventStruct.getEventType(); 00666 assert (lEventType == EventType::BKG_REQ); 00667 00668 // Get the booking request (the current event type is booking request) 00669 const BookingRequestStruct& lBookingRequest = 00670 iEventStruct.getBookingRequest(); 00671 00672 #if BOOST_VERSION >= 104100 00673 00674 // Create an empty property tree object for the current booking request 00675 bpt::ptree ptBookingRequest; 00676 00677 // Put request date time in property tree 00678 const DateTime_T& lRequestDateTime = 00679 lBookingRequest.getRequestDateTime(); 00680 ptBookingRequest.put ("time_stamp", lRequestDateTime); 00681 // Put event type in property tree 00682 ptBookingRequest.put ("event_type", EventType::getLabel(lEventType)); 00683 // Put origin in property tree 00684 const AirportCode_T& lOrigin = lBookingRequest.getOrigin(); 00685 ptBookingRequest.put ("org", lOrigin); 00686 // Put destination in property tree 00687 const AirportCode_T& lDestination = lBookingRequest.getDestination(); 00688 ptBookingRequest.put ("des", lDestination); 00689 // Put preferred cabin in property tree 00690 const CabinCode_T& lCabinCode = lBookingRequest.getPreferredCabin(); 00691 ptBookingRequest.put ("cab", lCabinCode); 00692 // Put party size in property tree 00693 const NbOfSeats_T& lNbOfSeats = lBookingRequest.getPartySize(); 00694 ptBookingRequest.put ("pax", lNbOfSeats); 00695 // Put point-of-sale in property tree 00696 const AirportCode_T& lPOS = lBookingRequest.getPOS(); 00697 ptBookingRequest.put ("pos", lPOS); 00698 // Put channel in property tree 00699 const ChannelLabel_T& lChannelLabel = 00700 lBookingRequest.getBookingChannel(); 00701 ptBookingRequest.put ("cha", lChannelLabel); 00702 // Put WTP in property tree 00703 const WTP_T& lWTP = lBookingRequest.getWTP(); 00704 ptBookingRequest.put ("wtp", lWTP); 00705 // Put request date in property tree 00706 const Date_T& lRequestDate = 00707 lRequestDateTime.boost::posix_time::ptime::date(); 00708 ptBookingRequest.put ("bkg_date", lRequestDate); 00709 // Put departure date in property tree 00710 const Date_T& lPreferedDepartureDate = 00711 lBookingRequest.getPreferedDepartureDate(); 00712 ptBookingRequest.put ("dep_date", lPreferedDepartureDate); 00713 // Put advance purchase in property tree 00714 assert (lPreferedDepartureDate >= lRequestDate); 00715 const DateOffset_T& lAdvancePurchase = 00716 lPreferedDepartureDate - lRequestDate; 00717 ptBookingRequest.put ("adv_purchase", lAdvancePurchase); 00718 // Put stay duration in property tree 00719 const DayDuration_T& lStayDuration = 00720 lBookingRequest.getStayDuration(); 00721 ptBookingRequest.put ("stay_duration", lStayDuration); 00722 // Put return date in property tree 00723 const DateOffset_T lDayDuration (lStayDuration); 00724 const Date_T& lReturnDate = 00725 lPreferedDepartureDate + lDayDuration; 00726 ptBookingRequest.put ("return_date", lReturnDate); 00727 // Put cancellation date in property tree 00728 // TODO: cancellation date 00729 ptBookingRequest.put ("cancel_date", "xxxx-xx-xx"); 00730 // Put preferred departure time in property tree 00731 const Duration_T& lPreferredDepartureTime = 00732 lBookingRequest.getPreferredDepartureTime(); 00733 ptBookingRequest.put ("dep_time", lPreferredDepartureTime); 00734 // Put preferred return time in property tree 00735 // TODO: preferred return time 00736 ptBookingRequest.put ("return_time", "xxPM"); 00737 // Put preferred carriers in property tree 00738 // TODO: preferred carriers 00739 ptBookingRequest.put ("pref_carriers", "XX"); 00740 00741 // Write the property tree into the JSON stream. 00742 write_json (oStream, ptBookingRequest); 00743 00744 #endif // BOOST_VERSION >= 104100 00745 } 00746 00747 // //////////////////////////////////////////////////////////////////// 00748 void BomJSONExport:: 00749 jsonExportBreakPointObject (std::ostream& oStream, 00750 const EventStruct& iEventStruct) { 00751 00752 // Get the current event type: it should be break point 00753 const EventType::EN_EventType& lEventType = 00754 iEventStruct.getEventType(); 00755 assert (lEventType == EventType::BRK_PT); 00756 00757 // Get the break point (the current event type is break point) 00758 const BreakPointStruct& lBreakPoint = 00759 iEventStruct.getBreakPoint(); 00760 00761 #if BOOST_VERSION >= 104100 00762 00763 // Create an empty property tree object for the current break point 00764 bpt::ptree ptBreakPoint; 00765 00766 // Put break point date time in property tree 00767 const DateTime_T& lRequestDateTime = 00768 lBreakPoint.getBreakPointTime(); 00769 ptBreakPoint.put ("time_stamp", lRequestDateTime); 00770 // Put event type in property tree 00771 ptBreakPoint.put ("event_type", EventType::getLabel(lEventType)); 00772 00773 // Write the property tree into the JSON stream. 00774 write_json (oStream, ptBreakPoint); 00775 00776 00777 #endif // BOOST_VERSION >= 104100 00778 } 00779 00780 }