8 #include <boost/make_shared.hpp>
10 #include <stdair/stdair_exceptions.hpp>
11 #include <stdair/stdair_basic_types.hpp>
12 #include <stdair/stdair_json.hpp>
13 #include <stdair/basic/BasChronometer.hpp>
14 #include <stdair/basic/BasFileMgr.hpp>
15 #include <stdair/bom/BomManager.hpp>
16 #include <stdair/bom/BookingRequestStruct.hpp>
17 #include <stdair/bom/TravelSolutionStruct.hpp>
18 #include <stdair/bom/CancellationStruct.hpp>
19 #include <stdair/bom/BomRoot.hpp>
20 #include <stdair/bom/Inventory.hpp>
21 #include <stdair/service/Logger.hpp>
22 #include <stdair/STDAIR_Service.hpp>
24 #include <sevmgr/SEVMGR_Service.hpp>
26 #include <airinv/AIRINV_Master_Service.hpp>
28 #include <airsched/AIRSCHED_Service.hpp>
30 #include <simfqt/SIMFQT_Service.hpp>
41 SIMCRS_Service::SIMCRS_Service() : _simcrsServiceContext (NULL) {
46 SIMCRS_Service::SIMCRS_Service (
const SIMCRS_Service& iService) {
51 SIMCRS_Service::SIMCRS_Service (
const stdair::BasLogParams& iLogParams,
53 : _simcrsServiceContext (NULL) {
56 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
57 initStdAirService (iLogParams);
60 initServiceContext (iCRSCode);
64 const bool ownStdairService =
true;
65 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
71 initAIRSCHEDService();
81 SIMCRS_Service::SIMCRS_Service (
const stdair::BasLogParams& iLogParams,
82 const stdair::BasDBParams& iDBParams,
84 : _simcrsServiceContext (NULL) {
87 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
88 initStdAirService (iLogParams, iDBParams);
91 initServiceContext (iCRSCode);
95 const bool ownStdairService =
true;
96 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
102 initAIRSCHEDService();
113 SIMCRS_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
114 SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr,
116 : _simcrsServiceContext (NULL) {
119 initServiceContext (iCRSCode);
123 const bool doesNotOwnStdairService =
false;
124 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
127 const bool doesNotOwnSEVMGRService =
false;
128 addSEVMGRService (ioSEVMGR_Service_ptr, doesNotOwnSEVMGRService);
134 initAIRSCHEDService();
150 void SIMCRS_Service::finalise() {
151 assert (_simcrsServiceContext != NULL);
153 _simcrsServiceContext->reset();
157 void SIMCRS_Service::initServiceContext (
const CRSCode_T& iCRSCode) {
159 SIMCRS_ServiceContext& lSIMCRS_ServiceContext =
161 _simcrsServiceContext = &lSIMCRS_ServiceContext;
165 void SIMCRS_Service::
166 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
167 const bool iOwnStdairService) {
170 assert (_simcrsServiceContext != NULL);
171 SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
174 lSIMCRS_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
179 void SIMCRS_Service::
180 addSEVMGRService (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr,
181 const bool iOwnSEVMGRService) {
184 assert (_simcrsServiceContext != NULL);
185 SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
188 lSIMCRS_ServiceContext.setSEVMGR_Service (ioSEVMGR_Service_ptr,
193 stdair::STDAIR_ServicePtr_T SIMCRS_Service::
194 initStdAirService (
const stdair::BasLogParams& iLogParams) {
203 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
204 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
206 return lSTDAIR_Service_ptr;
210 stdair::STDAIR_ServicePtr_T SIMCRS_Service::
211 initStdAirService (
const stdair::BasLogParams& iLogParams,
212 const stdair::BasDBParams& iDBParams) {
221 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
222 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
224 return lSTDAIR_Service_ptr;
228 void SIMCRS_Service::initAIRSCHEDService() {
231 assert (_simcrsServiceContext != NULL);
232 SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
235 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
236 lSIMCRS_ServiceContext.getSTDAIR_ServicePtr();
245 AIRSCHED::AIRSCHED_ServicePtr_T lAIRSCHED_Service_ptr =
246 boost::make_shared<AIRSCHED::AIRSCHED_Service> (lSTDAIR_Service_ptr);
249 lSIMCRS_ServiceContext.setAIRSCHED_Service (lAIRSCHED_Service_ptr);
253 void SIMCRS_Service::initSIMFQTService() {
256 assert (_simcrsServiceContext != NULL);
257 SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
260 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
261 lSIMCRS_ServiceContext.getSTDAIR_ServicePtr();
270 SIMFQT::SIMFQT_ServicePtr_T lSIMFQT_Service_ptr =
271 boost::make_shared<SIMFQT::SIMFQT_Service> (lSTDAIR_Service_ptr);
274 lSIMCRS_ServiceContext.setSIMFQT_Service (lSIMFQT_Service_ptr);
278 void SIMCRS_Service::initAIRINVService() {
281 assert (_simcrsServiceContext != NULL);
282 SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
285 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
286 lSIMCRS_ServiceContext.getSTDAIR_ServicePtr();
295 AIRINV::AIRINV_Master_ServicePtr_T lAIRINV_Master_Service_ptr;
296 const bool ownSEVMGRService =
297 lSIMCRS_ServiceContext.getOwnSEVMGRServiceFlag();
298 if (ownSEVMGRService ==
false) {
300 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
301 lSIMCRS_ServiceContext.getSEVMGR_ServicePtr();
302 assert (lSEVMGR_Service_ptr != NULL);
303 lAIRINV_Master_Service_ptr =
304 boost::make_shared<AIRINV::AIRINV_Master_Service> (lSTDAIR_Service_ptr,
305 lSEVMGR_Service_ptr);
307 lAIRINV_Master_Service_ptr =
308 boost::make_shared<AIRINV::AIRINV_Master_Service> (lSTDAIR_Service_ptr);
310 assert (lAIRINV_Master_Service_ptr != NULL);
313 lSIMCRS_ServiceContext.setAIRINV_Service (lAIRINV_Master_Service_ptr);
317 void SIMCRS_Service::initSimcrsService() {
325 const stdair::ODFilePath& iODInputFilepath,
326 const stdair::FRAT5FilePath& iFRAT5InputFilepath,
327 const stdair::FFDisutilityFilePath& iFFDisutilityInputFilepath,
328 const AIRRAC::YieldFilePath& iYieldInputFilepath,
329 const SIMFQT::FareFilePath& iFareInputFilepath) {
332 if (_simcrsServiceContext == NULL) {
333 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
334 "has not been initialised");
336 assert (_simcrsServiceContext != NULL);
341 const bool doesOwnStdairService =
342 lSIMCRS_ServiceContext.getOwnStdairServiceFlag();
345 stdair::STDAIR_Service& lSTDAIR_Service =
346 lSIMCRS_ServiceContext.getSTDAIR_Service();
349 stdair::BomRoot& lPersistentBomRoot =
350 lSTDAIR_Service.getPersistentBomRoot();
361 AIRSCHED::AIRSCHED_Service& lAIRSCHED_Service =
362 lSIMCRS_ServiceContext.getAIRSCHED_Service();
363 lAIRSCHED_Service.parseAndLoad (iScheduleInputFilepath);
371 AIRINV::AIRINV_Master_Service& lAIRINV_Service =
372 lSIMCRS_ServiceContext.getAIRINV_Service();
373 lAIRINV_Service.parseAndLoad (iScheduleInputFilepath, iODInputFilepath,
375 iFFDisutilityInputFilepath,
376 iYieldInputFilepath);
381 SIMFQT::SIMFQT_Service& lSIMFQT_Service =
382 lSIMCRS_ServiceContext.getSIMFQT_Service();
383 lSIMFQT_Service.parseAndLoad (iFareInputFilepath);
395 if (doesOwnStdairService ==
true) {
405 if (_simcrsServiceContext == NULL) {
406 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
407 "has not been initialised");
409 assert (_simcrsServiceContext != NULL);
414 const bool doesOwnStdairService =
415 lSIMCRS_ServiceContext.getOwnStdairServiceFlag();
418 stdair::STDAIR_Service& lSTDAIR_Service =
419 lSIMCRS_ServiceContext.getSTDAIR_Service();
422 stdair::BomRoot& lPersistentBomRoot =
423 lSTDAIR_Service.getPersistentBomRoot();
429 if (doesOwnStdairService ==
true) {
431 lSTDAIR_Service.buildSampleBom();
443 AIRSCHED::AIRSCHED_Service& lAIRSCHED_Service =
444 lSIMCRS_ServiceContext.getAIRSCHED_Service();
445 lAIRSCHED_Service.buildSampleBom();
453 AIRINV::AIRINV_Master_Service& lAIRINV_Service =
454 lSIMCRS_ServiceContext.getAIRINV_Service();
455 lAIRINV_Service.buildSampleBom();
460 SIMFQT::SIMFQT_Service& lSIMFQT_Service =
461 lSIMCRS_ServiceContext.getSIMFQT_Service();
462 lSIMFQT_Service.buildSampleBom();
474 if (doesOwnStdairService ==
true) {
484 if (_simcrsServiceContext == NULL) {
485 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
486 "has not been initialised");
488 assert (_simcrsServiceContext != NULL);
493 const bool doesOwnStdairService =
494 lSIMCRS_ServiceContext.getOwnStdairServiceFlag();
497 stdair::STDAIR_Service& lSTDAIR_Service =
498 lSIMCRS_ServiceContext.getSTDAIR_Service();
504 if (doesOwnStdairService ==
true) {
506 lSTDAIR_Service.clonePersistentBom ();
518 AIRSCHED::AIRSCHED_Service& lAIRSCHED_Service =
519 lSIMCRS_ServiceContext.getAIRSCHED_Service();
520 lAIRSCHED_Service.clonePersistentBom ();
528 AIRINV::AIRINV_Master_Service& lAIRINV_Service =
529 lSIMCRS_ServiceContext.getAIRINV_Service();
530 lAIRINV_Service.clonePersistentBom ();
535 SIMFQT::SIMFQT_Service& lSIMFQT_Service =
536 lSIMCRS_ServiceContext.getSIMFQT_Service();
537 lSIMFQT_Service.clonePersistentBom ();
543 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
557 if (_simcrsServiceContext == NULL) {
558 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
559 "has not been initialised");
561 assert (_simcrsServiceContext != NULL);
565 stdair::STDAIR_Service& lSTDAIR_Service =
566 lSIMCRS_ServiceContext.getSTDAIR_Service();
569 lSTDAIR_Service.buildSampleTravelSolutions (ioTravelSolutionList);
577 if (_simcrsServiceContext == NULL) {
578 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
579 "has not been initialised");
581 assert (_simcrsServiceContext != NULL);
585 stdair::STDAIR_Service& lSTDAIR_Service =
586 lSIMCRS_ServiceContext.getSTDAIR_Service();
589 return lSTDAIR_Service.buildSampleBookingRequest (isForCRS);
594 const stdair::ClassCode_T& iClassCode,
595 const stdair::PartySize_T& iPartySize) {
598 if (_simcrsServiceContext == NULL) {
599 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
600 "has not been initialised");
602 assert (_simcrsServiceContext != NULL);
606 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
607 lSIMCRS_ServiceContext.getAIRINV_Service();
609 return lAIRINV_Master_Service.sell (iSegmentDateKey, iClassCode,
618 if (_simcrsServiceContext == NULL) {
619 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
620 "has not been initialised");
622 assert (_simcrsServiceContext != NULL);
626 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
627 lSIMCRS_ServiceContext.getAIRINV_Service();
629 return lAIRINV_Master_Service.jsonHandler (iJSONString);
636 const stdair::Date_T& iEndDate) {
639 if (_simcrsServiceContext == NULL) {
640 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
641 "not been initialised");
643 assert (_simcrsServiceContext != NULL);
647 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
648 lSIMCRS_ServiceContext.getAIRINV_Service();
650 lAIRINV_Master_Service.initSnapshotAndRMEvents (iStartDate, iEndDate);
657 if (_simcrsServiceContext == NULL) {
658 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
659 "has not been initialised");
661 assert (_simcrsServiceContext != NULL);
665 stdair::STDAIR_Service& lSTDAIR_Service =
666 lSIMCRS_ServiceContext.getSTDAIR_Service();
667 const stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
670 return lSTDAIR_Service.csvDisplay(lBomRoot);
675 csvDisplay (
const stdair::TravelSolutionList_T& ioTravelSolutionList)
const {
678 if (_simcrsServiceContext == NULL) {
679 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
680 "has not been initialised");
682 assert (_simcrsServiceContext != NULL);
686 stdair::STDAIR_Service& lSTDAIR_Service =
687 lSIMCRS_ServiceContext.getSTDAIR_Service();
690 return lSTDAIR_Service.csvDisplay (ioTravelSolutionList);
695 list (
const stdair::AirlineCode_T& iAirlineCode,
696 const stdair::FlightNumber_T& iFlightNumber)
const {
699 if (_simcrsServiceContext == NULL) {
700 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
701 "not been initialised");
703 assert (_simcrsServiceContext != NULL);
707 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
708 lSIMCRS_ServiceContext.getAIRINV_Service();
711 return lAIRINV_Master_Service.list (iAirlineCode, iFlightNumber);
717 const stdair::FlightNumber_T& iFlightNumber,
718 const stdair::Date_T& iDepartureDate)
const {
721 if (_simcrsServiceContext == NULL) {
722 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
723 "not been initialised");
725 assert (_simcrsServiceContext != NULL);
729 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
730 lSIMCRS_ServiceContext.getAIRINV_Service();
733 return lAIRINV_Master_Service.csvDisplay (iAirlineCode, iFlightNumber,
742 if (_simcrsServiceContext == NULL) {
743 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
744 "has not been initialised");
746 assert (_simcrsServiceContext != NULL);
750 stdair::TravelSolutionList_T oTravelSolutionList;
753 AIRSCHED::AIRSCHED_Service& lAIRSCHED_Service =
754 lSIMCRS_ServiceContext.getAIRSCHED_Service();
757 stdair::BasChronometer lTravelSolutionRetrievingChronometer;
758 lTravelSolutionRetrievingChronometer.start();
760 lAIRSCHED_Service.buildSegmentPathList (oTravelSolutionList,
764 const double lSegmentPathRetrievingMeasure =
765 lTravelSolutionRetrievingChronometer.elapsed();
766 STDAIR_LOG_DEBUG (
"Travel solution retrieving: "
767 << lSegmentPathRetrievingMeasure <<
" - "
768 << lSIMCRS_ServiceContext.display());
770 return oTravelSolutionList;
775 fareQuote (
const stdair::BookingRequestStruct& iBookingRequest,
776 stdair::TravelSolutionList_T& ioTravelSolutionList) {
779 if (_simcrsServiceContext == NULL) {
780 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
781 "not been initialised");
783 assert (_simcrsServiceContext != NULL);
788 SIMFQT::SIMFQT_Service& lSIMFQT_Service =
789 lSIMCRS_ServiceContext.getSIMFQT_Service();
792 stdair::BasChronometer lFareQuoteRetrievalChronometer;
793 lFareQuoteRetrievalChronometer.start();
795 lSIMFQT_Service.quotePrices (iBookingRequest, ioTravelSolutionList);
798 const double lFareQuoteRetrievalMeasure =
799 lFareQuoteRetrievalChronometer.elapsed();
800 STDAIR_LOG_DEBUG (
"Fare Quote retrieving: " << lFareQuoteRetrievalMeasure
801 <<
" - " << lSIMCRS_ServiceContext.display());
809 if (_simcrsServiceContext == NULL) {
810 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
811 "not been initialised");
813 assert (_simcrsServiceContext != NULL);
821 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
822 lSIMCRS_ServiceContext.getAIRINV_Service();
825 stdair::BasChronometer lAvlChronometer;
826 lAvlChronometer.start();
829 ioTravelSolutionList);
832 const double lAvlMeasure = lAvlChronometer.elapsed();
833 STDAIR_LOG_DEBUG (
"Availability retrieval: " << lAvlMeasure <<
" - "
834 << lSIMCRS_ServiceContext.display());
839 sell (
const stdair::TravelSolutionStruct& iTravelSolution,
840 const stdair::PartySize_T& iPartySize) {
841 bool hasSaleBeenSuccessful =
false;
844 if (_simcrsServiceContext == NULL) {
845 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
846 "not been initialised");
848 assert (_simcrsServiceContext != NULL);
856 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
857 lSIMCRS_ServiceContext.getAIRINV_Service();
860 stdair::BasChronometer lSellChronometer;
861 lSellChronometer.start();
868 STDAIR_LOG_DEBUG (
"Made a sell of " << iPartySize
869 <<
" persons on the following travel solution: "
870 << iTravelSolution.describe()
871 <<
" with the chosen fare option: "
872 << iTravelSolution.getChosenFareOption().describe()
873 <<
". Successful? " << hasSaleBeenSuccessful);
876 const double lSellMeasure = lSellChronometer.elapsed();
877 STDAIR_LOG_DEBUG (
"Booking sell: " << lSellMeasure <<
" - "
878 << lSIMCRS_ServiceContext.display());
880 return hasSaleBeenSuccessful;
887 bool hasCancellationBeenSuccessful =
false;
890 if (_simcrsServiceContext == NULL) {
891 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
892 "not been initialised");
894 assert (_simcrsServiceContext != NULL);
902 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
903 lSIMCRS_ServiceContext.getAIRINV_Service();
906 stdair::BasChronometer lCancellationChronometer;
907 lCancellationChronometer.start();
909 hasCancellationBeenSuccessful =
914 STDAIR_LOG_DEBUG (
"Made a cancellation of " << iCancellation.describe());
917 const double lCancellationMeasure = lCancellationChronometer.elapsed();
918 STDAIR_LOG_DEBUG (
"Booking cancellation: " << lCancellationMeasure <<
" - "
919 << lSIMCRS_ServiceContext.display());
921 return hasCancellationBeenSuccessful;
928 if (_simcrsServiceContext == NULL) {
929 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
930 "not been initialised");
932 assert (_simcrsServiceContext != NULL);
936 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
937 lSIMCRS_ServiceContext.getAIRINV_Service();
939 lAIRINV_Master_Service.takeSnapshots (iSnapshot);
947 if (_simcrsServiceContext == NULL) {
948 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
949 "not been initialised");
951 assert (_simcrsServiceContext != NULL);
955 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
956 lSIMCRS_ServiceContext.getAIRINV_Service();
958 lAIRINV_Master_Service.optimise (iRMEvent);