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

TRAVELCCM_Service.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 // Boost
00007 #include <boost/make_shared.hpp>
00008 // StdAir
00009 #include <stdair/basic/BasChronometer.hpp>
00010 #include <stdair/basic/BasFileMgr.hpp>
00011 #include <stdair/bom/BomManager.hpp> 
00012 #include <stdair/bom/BookingRequestStruct.hpp> 
00013 #include <stdair/factory/FacBomManager.hpp>
00014 #include <stdair/service/Logger.hpp>
00015 #include <stdair/STDAIR_Service.hpp>
00016 // TravelCCM
00017 #include <travelccm/factory/FacTRAVELCCMServiceContext.hpp>
00018 #include <travelccm/command/ChoiceManager.hpp>
00019 #include <travelccm/service/TRAVELCCM_ServiceContext.hpp>
00020 #include <travelccm/TRAVELCCM_Service.hpp>
00021 
00022 namespace TRAVELCCM {
00023 
00024   // ////////////////////////////////////////////////////////////////////
00025   TRAVELCCM_Service::TRAVELCCM_Service() : _travelccmServiceContext (NULL) {
00026     assert (false);
00027   }
00028 
00029   // ////////////////////////////////////////////////////////////////////
00030   TRAVELCCM_Service::TRAVELCCM_Service (const TRAVELCCM_Service& iService)
00031   : _travelccmServiceContext (NULL) {
00032     assert (false);
00033   }
00034 
00035   // ////////////////////////////////////////////////////////////////////
00036   TRAVELCCM_Service::TRAVELCCM_Service (const stdair::BasLogParams& iLogParams,
00037                                         const stdair::BasDBParams& iDBParams)
00038     : _travelccmServiceContext (NULL) {
00039     
00040     // Initialise the STDAIR service handler
00041     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00042       initStdAirService (iLogParams, iDBParams);
00043     
00044     // Initialise the service context
00045     initServiceContext();
00046 
00047     // Add the StdAir service context to the AIRINV service context
00048     // \note AIRINV owns the STDAIR service resources here.
00049     const bool ownStdairService = true;
00050     addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
00051     
00052     // Initialise the (remaining of the) context
00053     initTravelCCMService();
00054   }
00055 
00056   // ////////////////////////////////////////////////////////////////////
00057   TRAVELCCM_Service::TRAVELCCM_Service (const stdair::BasLogParams& iLogParams)
00058     : _travelccmServiceContext (NULL) {
00059     
00060     // Initialise the STDAIR service handler
00061     stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00062       initStdAirService (iLogParams);
00063     
00064     // Initialise the service context
00065     initServiceContext();
00066 
00067     // Add the StdAir service context to the AIRINV service context
00068     // \note AIRINV owns the STDAIR service resources here.
00069     const bool ownStdairService = true;
00070     addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
00071     
00072     // Initialise the (remaining of the) context
00073     initTravelCCMService();
00074   }
00075 
00076   // ////////////////////////////////////////////////////////////////////
00077   TRAVELCCM_Service::
00078   TRAVELCCM_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
00079     : _travelccmServiceContext (NULL) {
00080         
00081     // Initialise the service context
00082     initServiceContext();
00083 
00084     // Store the STDAIR service object within the (AIRINV) service context
00085     // \note AirInv does not own the STDAIR service resources here.
00086     const bool doesNotOwnStdairService = false;
00087     addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
00088 
00089     // Initialise the (remaining of the) context
00090     initTravelCCMService();
00091   }
00092 
00093   // ////////////////////////////////////////////////////////////////////
00094   TRAVELCCM_Service::~TRAVELCCM_Service() {
00095     // Delete/Clean all the objects from memory
00096     finalise();
00097   }
00098   
00099   // ////////////////////////////////////////////////////////////////////
00100   void TRAVELCCM_Service::finalise() {
00101     assert (_travelccmServiceContext != NULL);
00102     // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
00103     _travelccmServiceContext->reset();
00104   }
00105 
00106   // ////////////////////////////////////////////////////////////////////
00107   void TRAVELCCM_Service::initServiceContext() {
00108     // Initialise the context
00109     TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext = 
00110       FacTRAVELCCMServiceContext::instance().create();
00111     _travelccmServiceContext = &lTRAVELCCM_ServiceContext;
00112   }
00113   
00114   // ////////////////////////////////////////////////////////////////////
00115   void TRAVELCCM_Service::
00116   addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
00117                     const bool iOwnStdairService) {
00118     // Retrieve the Travelccm service context
00119     assert (_travelccmServiceContext != NULL);
00120     TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
00121       *_travelccmServiceContext;
00122 
00123     // Store the STDAIR service object within the (TRAVELCCM) service context
00124     lTRAVELCCM_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
00125                                                  iOwnStdairService);
00126   }
00127 
00128   // ////////////////////////////////////////////////////////////////////
00129   stdair::STDAIR_ServicePtr_T TRAVELCCM_Service::
00130   initStdAirService (const stdair::BasLogParams& iLogParams,
00131                      const stdair::BasDBParams& iDBParams) {
00132 
00139     stdair::STDAIR_ServicePtr_T oSTDAIR_Service_ptr = 
00140       boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
00141     assert (oSTDAIR_Service_ptr != NULL);
00142 
00143     return oSTDAIR_Service_ptr;
00144   }
00145   
00146   // ////////////////////////////////////////////////////////////////////
00147   stdair::STDAIR_ServicePtr_T TRAVELCCM_Service::
00148   initStdAirService (const stdair::BasLogParams& iLogParams) {
00149 
00156     stdair::STDAIR_ServicePtr_T oSTDAIR_Service_ptr = 
00157       boost::make_shared<stdair::STDAIR_Service> (iLogParams);
00158     assert (oSTDAIR_Service_ptr != NULL);
00159 
00160     return oSTDAIR_Service_ptr;
00161   }
00162   
00163   // ////////////////////////////////////////////////////////////////////
00164   void TRAVELCCM_Service::initTravelCCMService() {
00165     // Do nothing at this stage. A sample BOM tree may be built by
00166     // calling the buildSampleBom() method
00167   }
00168   
00169   // //////////////////////////////////////////////////////////////////////
00170   void TRAVELCCM_Service::buildSampleBom() {
00171 
00172     // Retrieve the TravelCCM service context
00173     if (_travelccmServiceContext == NULL) {
00174       throw stdair::NonInitialisedServiceException ("The TravelCCM service has "
00175                                                     "not been initialised");
00176     }
00177     assert (_travelccmServiceContext != NULL);
00178 
00179     // Retrieve the TravelCCM service context and whether it owns the Stdair
00180     // service
00181     TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
00182       *_travelccmServiceContext;
00183     const bool doesOwnStdairService =
00184       lTRAVELCCM_ServiceContext.getOwnStdairServiceFlag();
00185 
00186     // Retrieve the StdAir service object from the (TravelCCM) service context
00187     stdair::STDAIR_Service& lSTDAIR_Service =
00188       lTRAVELCCM_ServiceContext.getSTDAIR_Service();
00189 
00190     // Retrieve the persistent BOM root object.
00191     stdair::BomRoot& lPersistentBomRoot = 
00192       lSTDAIR_Service.getPersistentBomRoot();
00193 
00198     if (doesOwnStdairService == true) {
00199       //
00200       lSTDAIR_Service.buildSampleBom();
00201     }
00202 
00215     buildComplementaryLinks (lPersistentBomRoot);
00216 
00221     if (doesOwnStdairService == true) {
00222       //
00223       clonePersistentBom ();
00224     }
00225   } 
00226 
00227   // ////////////////////////////////////////////////////////////////////
00228   void TRAVELCCM_Service::clonePersistentBom () {  
00229 
00230     // Retrieve the TravelCCM service context
00231     if (_travelccmServiceContext == NULL) {
00232       throw stdair::NonInitialisedServiceException ("The TravelCCM service has "
00233                                                     "not been initialised");
00234     }
00235     assert (_travelccmServiceContext != NULL);
00236 
00237     // Retrieve the TravelCCM service context and whether it owns the Stdair
00238     // service
00239     TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
00240       *_travelccmServiceContext;
00241     const bool doesOwnStdairService =
00242       lTRAVELCCM_ServiceContext.getOwnStdairServiceFlag();
00243 
00244     // Retrieve the StdAir service object from the (TravelCCM) service context
00245     stdair::STDAIR_Service& lSTDAIR_Service =
00246       lTRAVELCCM_ServiceContext.getSTDAIR_Service();
00247 
00252     if (doesOwnStdairService == true) {
00253       lSTDAIR_Service.clonePersistentBom ();
00254     }  
00255 
00268     stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();   
00269     buildComplementaryLinks (lBomRoot);
00270   }
00271 
00272   // ////////////////////////////////////////////////////////////////////
00273   void TRAVELCCM_Service::buildComplementaryLinks (stdair::BomRoot& ioBomRoot) {
00274     // Currently, no more things to do by TravelCCM at that stage.
00275   }
00276 
00277   // //////////////////////////////////////////////////////////////////////
00278   void TRAVELCCM_Service::
00279   buildSampleTravelSolutions (stdair::TravelSolutionList_T& ioTSList) {
00280 
00281     // Retrieve the TRAVELCCM service context
00282     if (_travelccmServiceContext == NULL) {
00283       throw stdair::NonInitialisedServiceException ("The Travelccm service has "
00284                                                     "not been initialised");
00285     }
00286     assert (_travelccmServiceContext != NULL);
00287 
00288     TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
00289       *_travelccmServiceContext;
00290   
00291     // Retrieve the STDAIR service object from the (TRAVELCCM) service context
00292     stdair::STDAIR_Service& lSTDAIR_Service =
00293       lTRAVELCCM_ServiceContext.getSTDAIR_Service();
00294 
00295     // Delegate the BOM building to the dedicated service
00296     lSTDAIR_Service.buildSampleTravelSolutions (ioTSList);
00297   }
00298 
00299   // //////////////////////////////////////////////////////////////////////
00300   stdair::BookingRequestStruct TRAVELCCM_Service::
00301   buildSampleBookingRequest (const bool isForCRS) {
00302 
00303     // Retrieve the TRAVELCCM service context
00304     if (_travelccmServiceContext == NULL) {
00305       throw stdair::NonInitialisedServiceException ("The Travelccm service has "
00306                                                     "not been initialised");
00307     }
00308     assert (_travelccmServiceContext != NULL);
00309 
00310     TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
00311       *_travelccmServiceContext;
00312   
00313     // Retrieve the STDAIR service object from the (TRAVELCCM) service context
00314     stdair::STDAIR_Service& lSTDAIR_Service =
00315       lTRAVELCCM_ServiceContext.getSTDAIR_Service();
00316 
00317     // Delegate the BOM building to the dedicated service
00318     return lSTDAIR_Service.buildSampleBookingRequest (isForCRS);
00319   }
00320 
00321   // //////////////////////////////////////////////////////////////////////
00322   std::string TRAVELCCM_Service::csvDisplay() const {
00323 
00324     // Retrieve the TRAVELCCM service context
00325     if (_travelccmServiceContext == NULL) {
00326       throw stdair::NonInitialisedServiceException ("The TravelccmMaster service"
00327                                                     " has not been initialised");
00328     }
00329     assert (_travelccmServiceContext != NULL);
00330 
00331     TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
00332       *_travelccmServiceContext;
00333   
00334     // Retrieve the STDAIR service object from the (TRAVELCCM) service context
00335     stdair::STDAIR_Service& lSTDAIR_Service =
00336       lTRAVELCCM_ServiceContext.getSTDAIR_Service(); 
00337     const stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00338 
00339     // Delegate the BOM building to the dedicated service
00340     return lSTDAIR_Service.csvDisplay(lBomRoot);
00341   }
00342   
00343   // //////////////////////////////////////////////////////////////////////
00344   std::string TRAVELCCM_Service::
00345   csvDisplay (const stdair::TravelSolutionList_T& iTravelSolutionList) const {
00346     // Retrieve the TRAVELCCM service context
00347     if (_travelccmServiceContext == NULL) {
00348       throw stdair::NonInitialisedServiceException ("The TravelccmMaster service"
00349                                                     " has not been initialised");
00350     }
00351     assert (_travelccmServiceContext != NULL);
00352 
00353     TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
00354       *_travelccmServiceContext;
00355   
00356     // Retrieve the STDAIR service object from the (TRAVELCCM) service context
00357     stdair::STDAIR_Service& lSTDAIR_Service =
00358       lTRAVELCCM_ServiceContext.getSTDAIR_Service();
00359 
00360     // Delegate the BOM building to the dedicated service
00361     return lSTDAIR_Service.csvDisplay (iTravelSolutionList);
00362   }
00363 
00364   // ////////////////////////////////////////////////////////////////////
00365   const stdair::TravelSolutionStruct* TRAVELCCM_Service::
00366   chooseTravelSolution (stdair::TravelSolutionList_T& ioTravelSolutionList,
00367                         const stdair::BookingRequestStruct& iBookingRequest,
00368                         const stdair::PassengerChoiceModel::EN_PassengerChoiceModel& iPassengerChoiceModel) {
00369 
00370     const stdair::TravelSolutionStruct* oTravelSolution_ptr = 
00371       ChoiceManager::chooseTravelSolution (ioTravelSolutionList,
00372                                            iBookingRequest,
00373                                            iPassengerChoiceModel);
00374     return oTravelSolution_ptr;
00375   }
00376   
00377 }