$treeview $search $mathjax
StdAir Logo  1.00.1
$projectbrief
$projectbrief
$searchbox

stdair/service/STDAIR_Service.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 #if BOOST_VERSION >= 104100
00008 // Boost Property Tree
00009 #include <boost/property_tree/ptree.hpp>
00010 #include <boost/property_tree/json_parser.hpp>
00011 #endif // BOOST_VERSION >= 104100
00012 // StdAir
00013 #include <stdair/stdair_types.hpp>
00014 #include <stdair/stdair_json.hpp>
00015 #include <stdair/basic/BasChronometer.hpp>
00016 #include <stdair/bom/BomManager.hpp>
00017 #include <stdair/bom/BomRetriever.hpp>
00018 #include <stdair/bom/BomJSONExport.hpp>
00019 #include <stdair/bom/BomJSONImport.hpp>
00020 #include <stdair/bom/BomINIImport.hpp>
00021 #include <stdair/bom/BomDisplay.hpp>
00022 #include <stdair/bom/BomRoot.hpp>
00023 #include <stdair/bom/EventStruct.hpp>
00024 #include <stdair/bom/BookingRequestStruct.hpp>
00025 #include <stdair/bom/DatePeriod.hpp>
00026 #include <stdair/command/CmdBomManager.hpp>
00027 #include <stdair/command/CmdCloneBomManager.hpp>
00028 #include <stdair/service/FacSupervisor.hpp>
00029 #include <stdair/service/FacSTDAIRServiceContext.hpp>
00030 #include <stdair/service/Logger.hpp>
00031 #include <stdair/service/DBSessionManager.hpp>
00032 #include <stdair/STDAIR_Service.hpp>
00033 
00034 #if BOOST_VERSION >= 104100
00035 namespace bpt = boost::property_tree;
00036 #else // BOOST_VERSION >= 104100
00037 namespace bpt {
00038   typedef char ptree;
00039 }
00040 #endif // BOOST_VERSION >= 104100
00041 
00042 namespace stdair {
00043 
00044   // //////////////////////////////////////////////////////////////////////
00045   STDAIR_Service::STDAIR_Service() : _stdairServiceContext (NULL) {
00046 
00047     // Initialise the service context
00048     initServiceContext();
00049     
00050     // Initialise the (remaining of the) context
00051     init();
00052   }
00053 
00054   // //////////////////////////////////////////////////////////////////////
00055   STDAIR_Service::STDAIR_Service (const STDAIR_Service& iService) 
00056     : _stdairServiceContext (NULL) {
00057     assert (false);
00058   }
00059 
00060   // //////////////////////////////////////////////////////////////////////
00061   STDAIR_Service::STDAIR_Service (const BasLogParams& iLogParams)  
00062     : _stdairServiceContext (NULL) {
00063 
00064     // Initialise the service context
00065     initServiceContext();
00066     
00067     // Set the log file
00068     logInit (iLogParams);
00069 
00070     // Initialise the (remaining of the) context
00071     init();
00072   }
00073 
00074   // //////////////////////////////////////////////////////////////////////
00075   STDAIR_Service::STDAIR_Service (const BasLogParams& iLogParams,
00076                                   const BasDBParams& iDBParams) 
00077     : _stdairServiceContext (NULL) { 
00078 
00079     // Initialise the service context
00080     initServiceContext();
00081 
00082     // Set the log file
00083     logInit (iLogParams);
00084 
00085     // Create a database session
00086     dbInit (iDBParams);
00087 
00088     // Initialise the (remaining of the) context
00089     init();
00090   }
00091 
00092   // //////////////////////////////////////////////////////////////////////
00093   STDAIR_Service::~STDAIR_Service() {
00094     // Delete/Clean all the objects from memory
00095     finalise();
00096   }
00097 
00098   // //////////////////////////////////////////////////////////////////////
00099   void STDAIR_Service::initServiceContext() {
00100     // Initialise the service context
00101     STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00102       FacSTDAIRServiceContext::instance().create();
00103 
00104     // Store the stdair service context
00105     _stdairServiceContext = &lSTDAIR_ServiceContext;
00106   }
00107 
00108   // //////////////////////////////////////////////////////////////////////
00109   void STDAIR_Service::logInit (const BasLogParams& iLogParams) {
00110     Logger::init (iLogParams);
00111   }
00112 
00113   // //////////////////////////////////////////////////////////////////////
00114   void STDAIR_Service::dbInit (const BasDBParams& iDBParams) {
00115     DBSessionManager::init (iDBParams);
00116 
00117     // Store the database parameters into the StdAir service context
00118     assert (_stdairServiceContext != NULL);
00119     STDAIR_ServiceContext& lSTDAIR_ServiceContext = *_stdairServiceContext;
00120     lSTDAIR_ServiceContext.setDBParams (iDBParams);
00121   }
00122 
00123   // //////////////////////////////////////////////////////////////////////
00124   void STDAIR_Service::init() {
00125   }
00126   
00127   // //////////////////////////////////////////////////////////////////////
00128   BomRoot& STDAIR_Service::getBomRoot() const {
00129     // Retrieve the StdAir service context
00130     assert (_stdairServiceContext != NULL);
00131     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00132       *_stdairServiceContext;
00133     // Return the clone built-in Bom root
00134     return lSTDAIR_ServiceContext.getCloneBomRoot();
00135   }  
00136 
00137   // //////////////////////////////////////////////////////////////////////
00138   BomRoot& STDAIR_Service::getPersistentBomRoot() const {
00139     // Retrieve the StdAir service context
00140     assert (_stdairServiceContext != NULL);
00141     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00142       *_stdairServiceContext;
00143     // Return the persistent built-in Bom root
00144     return lSTDAIR_ServiceContext.getPersistentBomRoot();
00145   }
00146 
00147   // //////////////////////////////////////////////////////////////////////
00148   BasLogParams STDAIR_Service::getLogParams() const {
00149     return Logger::getLogParams();
00150   }
00151 
00152   // //////////////////////////////////////////////////////////////////////
00153   const BasDBParams& STDAIR_Service::getDBParams() const {
00154     // Retrieve the StdAir service context
00155     assert (_stdairServiceContext != NULL);
00156     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00157       *_stdairServiceContext;
00158     return lSTDAIR_ServiceContext.getDBParams();
00159   }
00160   
00161   // //////////////////////////////////////////////////////////////////////
00162   const ServiceInitialisationType& STDAIR_Service::
00163   getServiceInitialisationType() const {
00164     // Retrieve the StdAir service context
00165     assert (_stdairServiceContext != NULL);
00166     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00167       *_stdairServiceContext;
00168     return lSTDAIR_ServiceContext.getServiceInitialisationType();
00169   }
00170 
00171   // //////////////////////////////////////////////////////////////////////
00172   void STDAIR_Service::buildSampleBom() {
00173     // Retrieve the StdAir service context
00174     assert (_stdairServiceContext != NULL);
00175     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00176       *_stdairServiceContext;
00177 
00178     // Retrieve the BOM tree root
00179     BomRoot& lPersistentBomRoot = lSTDAIR_ServiceContext.getPersistentBomRoot();
00180     
00181     // Delegate the building process to the dedicated command
00182     CmdBomManager::buildSampleBom (lPersistentBomRoot);
00183   }
00184 
00185   // //////////////////////////////////////////////////////////////////////
00186   void STDAIR_Service::
00187   buildDummyInventory (const CabinCapacity_T& iCabinCapacity) {
00188     // Retrieve the StdAir service context
00189     assert (_stdairServiceContext != NULL);
00190     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00191       *_stdairServiceContext;
00192 
00193     // Retrieve the BOM tree root
00194     BomRoot& lPersistentBomRoot = lSTDAIR_ServiceContext.getPersistentBomRoot();
00195     
00196     // Delegate the building process to the dedicated command
00197     CmdBomManager::buildDummyInventory (lPersistentBomRoot, iCabinCapacity);
00198     CmdBomManager::buildCompleteDummyInventoryForFareFamilies (lPersistentBomRoot);
00199 
00200   } 
00201 
00202   // //////////////////////////////////////////////////////////////////////
00203   void STDAIR_Service::
00204   buildDummyLegSegmentAccesses (BomRoot& iBomRoot) {
00205     // Retrieve the StdAir service context
00206     assert (_stdairServiceContext != NULL);
00207 
00208     // Delegate the building process to the dedicated command
00209     CmdBomManager::buildDummyLegSegmentAccesses (iBomRoot);
00210 
00211   }
00212 
00213   // //////////////////////////////////////////////////////////////////////
00214   void STDAIR_Service::
00215   buildSampleTravelSolutionForPricing (TravelSolutionList_T& ioTravelSolutionList) {
00216     // Build a sample list of travel solution structures
00217     CmdBomManager::buildSampleTravelSolutionForPricing (ioTravelSolutionList);
00218   }
00219 
00220   // //////////////////////////////////////////////////////////////////////
00221   void STDAIR_Service::
00222   buildSampleTravelSolutions (TravelSolutionList_T& ioTravelSolutionList) {
00223     // Build a sample list of travel solution structures
00224     CmdBomManager::buildSampleTravelSolutions (ioTravelSolutionList);
00225   }
00226 
00227   // //////////////////////////////////////////////////////////////////////
00228   BookingRequestStruct STDAIR_Service::
00229   buildSampleBookingRequest (const bool isForCRS) {
00230 
00231     // Build a sample booking request structure
00232     if (isForCRS == true) {
00233       return CmdBomManager::buildSampleBookingRequestForCRS();
00234     }
00235 
00236     return CmdBomManager::buildSampleBookingRequest();
00237   } 
00238 
00239 
00240   // //////////////////////////////////////////////////////////////////////
00241   std::string STDAIR_Service::
00242   jsonExportFlightDateList (const AirlineCode_T& iAirlineCode,
00243                             const FlightNumber_T& iFlightNumber) const {
00244     std::ostringstream oStr;
00245 
00246     // Retrieve the StdAir service context
00247     assert (_stdairServiceContext != NULL);
00248     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00249       *_stdairServiceContext;
00250 
00251     // Retrieve the BOM tree root
00252     const BomRoot& lCloneBomRoot = lSTDAIR_ServiceContext.getCloneBomRoot();
00253 
00254     BomJSONExport::jsonExportFlightDateList (oStr, lCloneBomRoot, 
00255                                              iAirlineCode, iFlightNumber);
00256     
00257     return oStr.str();
00258   }
00259 
00260   // //////////////////////////////////////////////////////////////////////
00261   std::string STDAIR_Service::
00262   jsonExportFlightDateObjects (const stdair::AirlineCode_T& iAirlineCode,
00263                                const stdair::FlightNumber_T& iFlightNumber,
00264                                const stdair::Date_T& iDepartureDate) const {
00265     std::ostringstream oStr;
00266 
00267     // Retrieve the StdAir service context
00268     assert (_stdairServiceContext != NULL);
00269     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00270       *_stdairServiceContext;
00271 
00272     // Retrieve the BOM tree root
00273     const BomRoot& lCloneBomRoot = lSTDAIR_ServiceContext.getCloneBomRoot();
00274 
00275     // Retrieve the flight-date object corresponding to the key
00276     FlightDate* lFlightDate_ptr = 
00277       BomRetriever::retrieveFlightDateFromKeySet (lCloneBomRoot, iAirlineCode,
00278                                                   iFlightNumber, 
00279                                                   iDepartureDate);
00280 
00281     // Dump the content of the whole BOM tree into the string
00282     if (lFlightDate_ptr != NULL) {
00283       BomJSONExport::jsonExportFlightDateObjects (oStr, *lFlightDate_ptr);
00284       
00285     } else {
00286 #if BOOST_VERSION >= 104100
00287       //
00288       bpt::ptree lPropertyTree;
00289       
00290       // Build the appropriate message, so that the client may know that
00291       // no flight-date can be found for that given key.
00292       std::ostringstream oNoFlightDateStream;
00293       oNoFlightDateStream << "No flight-date found for the given key: '"
00294                           << iAirlineCode << iFlightNumber
00295                           << " - " << iDepartureDate << "'";
00296       const std::string oNoFlightDateString (oNoFlightDateStream.str());
00297 
00298       // Put in the property tree the fact that no flight-date has been found.
00299       // \note That is not (necessary) an error.
00300       lPropertyTree.put ("error", oNoFlightDateString.c_str());
00301 
00302       // Write the property tree into the JSON stream.
00303       write_json (oStr, lPropertyTree);
00304 #endif // BOOST_VERSION >= 104100
00305     }
00306     
00307     return oStr.str();
00308   } 
00309 
00310   // //////////////////////////////////////////////////////////////////////
00311   std::string STDAIR_Service::
00312   jsonExportEventObject (const EventStruct& iEventStruct) const {
00313     
00314     std::ostringstream oStr; 
00315 
00316     const EventType::EN_EventType& lEventType = 
00317       iEventStruct.getEventType();
00318 
00319     switch (lEventType) {
00320     case EventType::BKG_REQ:{
00321       BomJSONExport::jsonExportBookingRequestObject (oStr, iEventStruct);
00322       break;
00323     }
00324     case EventType::CX:
00325     case EventType::OPT_NOT_4_FD:
00326     case EventType::OPT_NOT_4_NET:
00327     case EventType::SKD_CHG:
00328     case EventType::SNAPSHOT:
00329     case EventType::RM: 
00330       break;
00331     case EventType::BRK_PT:
00332       BomJSONExport::jsonExportBreakPointObject (oStr, iEventStruct);
00333       break;
00334     default:
00335       break;
00336     }
00337     return oStr.str();
00338   }
00339 
00340   // //////////////////////////////////////////////////////////////////////
00341   bool STDAIR_Service::
00342   jsonImportConfiguration (const JSONString& iJSONString) const {  
00343 
00344     // Retrieve the StdAir service context
00345     assert (_stdairServiceContext != NULL);
00346     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00347       *_stdairServiceContext;
00348 
00349     // Retrieve the config holder
00350     ConfigHolderStruct& lConfigHolder = 
00351       lSTDAIR_ServiceContext.getConfigHolder();
00352 
00353     // Import the JSON string in the configuration holder
00354     return BomJSONImport::jsonImportConfig (iJSONString, lConfigHolder);
00355   }
00356 
00357   // //////////////////////////////////////////////////////////////////////
00358   std::string STDAIR_Service::
00359   jsonExportConfiguration () const {  
00360 
00361     // Retrieve the StdAir service context
00362     assert (_stdairServiceContext != NULL);
00363     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00364       *_stdairServiceContext;
00365 
00366     // Retrieve the config holder
00367     ConfigHolderStruct& lConfigHolder = 
00368       lSTDAIR_ServiceContext.getConfigHolder();
00369 
00370     // Export the configuration tree in a JSon format
00371     return lConfigHolder.jsonExport();
00372   }
00373 
00374   // //////////////////////////////////////////////////////////////////////  
00375   void STDAIR_Service::importINIConfig (const ConfigINIFile& iConfigINIFile) {  
00376 
00377     // Retrieve the StdAir service context
00378     assert (_stdairServiceContext != NULL);
00379     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00380       *_stdairServiceContext;
00381 
00382     // Retrieve the config holder
00383     ConfigHolderStruct& lConfigHolder = 
00384       lSTDAIR_ServiceContext.getConfigHolder();
00385 
00386     // Try to import the configuration
00387     stdair::BomINIImport::importINIConfig (lConfigHolder, iConfigINIFile);
00388   } 
00389 
00390   // //////////////////////////////////////////////////////////////////////  
00391   void STDAIR_Service::importConfigValue (const std::string& iValue,
00392                                           const std::string& iPath) {  
00393 
00394     // Retrieve the StdAir service context
00395     assert (_stdairServiceContext != NULL);
00396     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00397       *_stdairServiceContext;
00398 
00399     // Retrieve the config holder
00400     ConfigHolderStruct& lConfigHolder = 
00401       lSTDAIR_ServiceContext.getConfigHolder();
00402 
00403     // Add the given value to the configuration
00404     lConfigHolder.addValue (iValue, iPath);
00405   }
00406 
00407   // //////////////////////////////////////////////////////////////////////  
00408   void STDAIR_Service::updateAirlineFeatures () { 
00409 
00410     // Retrieve the StdAir service context
00411     assert (_stdairServiceContext != NULL);
00412     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00413       *_stdairServiceContext;
00414 
00415     // Retrieve the config holder
00416     ConfigHolderStruct& lConfigHolder = 
00417       lSTDAIR_ServiceContext.getConfigHolder();
00418 
00419     // Retrieve the persistent BOM tree root
00420     BomRoot& lPersistentBomRoot = 
00421       lSTDAIR_ServiceContext.getPersistentBomRoot(); 
00422 
00423     // Add the given value to the configuration
00424     lConfigHolder.updateAirlineFeatures (lPersistentBomRoot);
00425   }
00426 
00427   // //////////////////////////////////////////////////////////////////////
00428   std::string STDAIR_Service::list (const AirlineCode_T& iAirlineCode,
00429                                     const FlightNumber_T& iFlightNumber) const {
00430     std::ostringstream oStr;
00431 
00432     // Retrieve the StdAir service context
00433     assert (_stdairServiceContext != NULL);
00434     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = *_stdairServiceContext;
00435 
00436     // Retrieve the BOM tree root
00437     const BomRoot& lCloneBomRoot = lSTDAIR_ServiceContext.getCloneBomRoot();
00438     
00439     // Dump the content of the whole BOM tree into the string
00440     BomDisplay::list (oStr, lCloneBomRoot, iAirlineCode, iFlightNumber);
00441     
00442     return oStr.str();
00443   }
00444 
00445   // //////////////////////////////////////////////////////////////////////
00446   std::string STDAIR_Service::listAirportPairDateRange () const {
00447     std::ostringstream oStr;
00448 
00449     // Retrieve the StdAir service context
00450     assert (_stdairServiceContext != NULL);
00451     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = *_stdairServiceContext;
00452 
00453     // Retrieve the BOM tree root
00454     const BomRoot& lCloneBomRoot = lSTDAIR_ServiceContext.getCloneBomRoot();
00455     
00456     // Dump the content of the whole BOM tree into the string
00457     BomDisplay::listAirportPairDateRange (oStr, lCloneBomRoot);
00458     
00459     return oStr.str();
00460   }
00461 
00462   // //////////////////////////////////////////////////////////////////////
00463   bool STDAIR_Service::check (const AirlineCode_T& iAirlineCode,
00464                               const FlightNumber_T& iFlightNumber,
00465                               const stdair::Date_T& iDepartureDate) const {
00466     std::ostringstream oStr;
00467 
00468     // Retrieve the StdAir service context
00469     assert (_stdairServiceContext != NULL);
00470     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = *_stdairServiceContext;
00471 
00472     // Retrieve the BOM tree root
00473     const BomRoot& lCloneBomRoot = lSTDAIR_ServiceContext.getCloneBomRoot();
00474     
00475     // Dump the content of the whole BOM tree into the string
00476     const FlightDate* lFlightDate_ptr =
00477       BomRetriever::retrieveFlightDateFromKeySet (lCloneBomRoot, iAirlineCode,
00478                                                   iFlightNumber,
00479                                                   iDepartureDate);    
00480     
00481     return (lFlightDate_ptr != NULL);
00482   }
00483 
00484   // //////////////////////////////////////////////////////////////////////
00485   bool STDAIR_Service::check (const stdair::AirportCode_T& ioOrigin,
00486                               const stdair::AirportCode_T& ioDestination,
00487                               const stdair::Date_T& ioDepartureDate) const {
00488     std::ostringstream oStr;
00489 
00490     // Retrieve the StdAir service context
00491     assert (_stdairServiceContext != NULL);
00492     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = *_stdairServiceContext;
00493 
00494     // Retrieve the BOM tree root
00495     const BomRoot& lCloneBomRoot = lSTDAIR_ServiceContext.getCloneBomRoot();
00496     
00497     // Dump the content of the whole BOM tree into the string
00498     stdair::DatePeriodList_T lDatePeriodList;
00499     BomRetriever::retrieveDatePeriodListFromKeySet  (lCloneBomRoot, ioOrigin,
00500                                                      ioDestination,
00501                                                      ioDepartureDate,
00502                                                      lDatePeriodList);    
00503     
00504     return (lDatePeriodList.size() != 0);
00505   }
00506 
00507   // //////////////////////////////////////////////////////////////////////
00508   std::string STDAIR_Service::configDisplay () const {
00509 
00510     // Retrieve the StdAir service context
00511     assert (_stdairServiceContext != NULL);    
00512     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00513       *_stdairServiceContext;
00514 
00515     // Retrieve the config holder
00516     ConfigHolderStruct& lConfigHolder = 
00517       lSTDAIR_ServiceContext.getConfigHolder();
00518 
00519     // Display (dump in the returned string) the configuration.
00520     return lConfigHolder.describe();
00521 
00522   }
00523 
00524   // //////////////////////////////////////////////////////////////////////
00525   std::string STDAIR_Service::csvDisplay () const {
00526 
00527     // Retrieve the StdAir service context
00528     assert (_stdairServiceContext != NULL);    
00529     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = 
00530       *_stdairServiceContext;
00531 
00532     // Retrieve the persistent BOM tree root
00533     const BomRoot& lPersistentBomRoot = 
00534       lSTDAIR_ServiceContext.getPersistentBomRoot();
00535     
00536     // Call the dedicated service
00537     return csvDisplay (lPersistentBomRoot);
00538   }
00539 
00540   // //////////////////////////////////////////////////////////////////////
00541   std::string STDAIR_Service::csvDisplay (const BomRoot& iBomRoot) const {
00542     std::ostringstream oStr;
00543 
00544     // Retrieve the StdAir service context
00545     assert (_stdairServiceContext != NULL);
00546     
00547     // Dump the content of the whole BOM tree into the string
00548     BomDisplay::csvDisplay (oStr, iBomRoot);
00549     
00550     return oStr.str();
00551   }
00552 
00553   // //////////////////////////////////////////////////////////////////////
00554   std::string STDAIR_Service::
00555   csvDisplay (const stdair::AirlineCode_T& iAirlineCode,
00556               const stdair::FlightNumber_T& iFlightNumber,
00557               const stdair::Date_T& iDepartureDate) const {
00558     std::ostringstream oStr;
00559 
00560     // Retrieve the StdAir service context
00561     assert (_stdairServiceContext != NULL);
00562     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = *_stdairServiceContext;
00563 
00564     // Retrieve the BOM tree root
00565     const BomRoot& lCloneBomRoot = lSTDAIR_ServiceContext.getCloneBomRoot();
00566 
00567     // Retrieve the flight-date object corresponding to the key
00568     FlightDate* lFlightDate_ptr = 
00569       BomRetriever::retrieveFlightDateFromKeySet (lCloneBomRoot, iAirlineCode,
00570                                                   iFlightNumber, 
00571                                                   iDepartureDate);
00572 
00573     // Dump the content of the whole BOM tree into the string
00574     if (lFlightDate_ptr != NULL) {
00575       BomDisplay::csvDisplay (oStr, *lFlightDate_ptr);
00576       
00577     } else {
00578       oStr << "   No flight-date found for the given key: '"
00579            << iAirlineCode << iFlightNumber << " - " << iDepartureDate << "'";
00580     }
00581     
00582     return oStr.str();
00583   }
00584 
00585   // //////////////////////////////////////////////////////////////////////
00586   std::string STDAIR_Service::
00587   csvDisplay (const TravelSolutionList_T& iTravelSolutionList) const {
00588 
00589     // Dump the content of the whole list of travel solutions into the string
00590     std::ostringstream oStr;
00591     BomDisplay::csvDisplay (oStr, iTravelSolutionList);
00592     
00593     return oStr.str();
00594   }
00595 
00596   // //////////////////////////////////////////////////////////////////////
00597   std::string STDAIR_Service::
00598   csvDisplay (const stdair::AirportCode_T& iOrigin,
00599               const stdair::AirportCode_T& iDestination,
00600               const stdair::Date_T& iDepartureDate) const {
00601     std::ostringstream oStr;
00602 
00603     // Retrieve the StdAir service context
00604     assert (_stdairServiceContext != NULL);
00605     const STDAIR_ServiceContext& lSTDAIR_ServiceContext = *_stdairServiceContext;
00606 
00607     // Retrieve the BOM tree root
00608     const BomRoot& lCloneBomRoot = lSTDAIR_ServiceContext.getCloneBomRoot();
00609 
00610     // Retrieve the flight-date object corresponding to the key
00611     DatePeriodList_T lDatePeriodList;
00612     BomRetriever::retrieveDatePeriodListFromKeySet (lCloneBomRoot, iOrigin,
00613                                                     iDestination, 
00614                                                     iDepartureDate,
00615                                                     lDatePeriodList);
00616 
00617     // Dump the content of the whole BOM tree into the string
00618     if (lDatePeriodList.empty()) {
00619       oStr << "   No fare-rule found for the given key: '"
00620             << iOrigin << "-" << iDestination << " - " << iDepartureDate << "'";
00621     } else {
00622       BomDisplay::csvDisplay (oStr, lDatePeriodList);
00623     }
00624     
00625     return oStr.str();
00626   }
00627 
00628   // //////////////////////////////////////////////////////////////////////
00629   void STDAIR_Service::finalise() {
00630     // Clean all the objects
00631     FacSupervisor::cleanAll();
00632   } 
00633 
00634   // //////////////////////////////////////////////////////////////////////
00635   void STDAIR_Service::clonePersistentBom () {  
00636 
00637     // Retrieve the StdAir service context
00638     assert (_stdairServiceContext != NULL);
00639     STDAIR_ServiceContext& lSTDAIR_ServiceContext = *_stdairServiceContext; 
00640 
00641     // Clean all the cloned objects
00642     FacSupervisor::instance().cleanCloneBomLayer();
00643 
00644     // Init the root of the clone BOM tree
00645     lSTDAIR_ServiceContext.initCloneBomRoot();
00646 
00647     // Retrieve the persistent BOM tree root and the clone BOM tree root
00648     const BomRoot& lPersistentBomRoot = 
00649       lSTDAIR_ServiceContext.getPersistentBomRoot(); 
00650     BomRoot& lCloneBomRoot = lSTDAIR_ServiceContext.getCloneBomRoot(); 
00651    
00652     // Call the dedicated service to clone the whole BOM
00653     CmdCloneBomManager::cloneBomRoot (lPersistentBomRoot, lCloneBomRoot);
00654     
00655   }
00656 
00657 }