8 #include <boost/make_shared.hpp>
10 #include <stdair/stdair_exceptions.hpp>
11 #include <stdair/stdair_basic_types.hpp>
12 #include <stdair/basic/BasChronometer.hpp>
13 #include <stdair/basic/BasFileMgr.hpp>
14 #include <stdair/bom/BomManager.hpp>
15 #include <stdair/bom/BookingRequestStruct.hpp>
16 #include <stdair/bom/TravelSolutionStruct.hpp>
17 #include <stdair/bom/CancellationStruct.hpp>
18 #include <stdair/bom/BomRoot.hpp>
19 #include <stdair/bom/Inventory.hpp>
20 #include <stdair/service/Logger.hpp>
21 #include <stdair/STDAIR_Service.hpp>
23 #include <airinv/AIRINV_Master_Service.hpp>
25 #include <airsched/AIRSCHED_Service.hpp>
27 #include <simfqt/SIMFQT_Service.hpp>
38 SIMCRS_Service::SIMCRS_Service() : _simcrsServiceContext (NULL) {
43 SIMCRS_Service::SIMCRS_Service (
const SIMCRS_Service& iService) {
48 SIMCRS_Service::SIMCRS_Service (
const stdair::BasLogParams& iLogParams,
50 : _simcrsServiceContext (NULL) {
53 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
54 initStdAirService (iLogParams);
57 initServiceContext (iCRSCode);
61 const bool ownStdairService =
true;
62 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
68 initAIRSCHEDService();
78 SIMCRS_Service::SIMCRS_Service (
const stdair::BasLogParams& iLogParams,
79 const stdair::BasDBParams& iDBParams,
81 : _simcrsServiceContext (NULL) {
84 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
85 initStdAirService (iLogParams, iDBParams);
88 initServiceContext (iCRSCode);
92 const bool ownStdairService =
true;
93 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
99 initAIRSCHEDService();
110 SIMCRS_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
112 : _simcrsServiceContext (NULL) {
115 initServiceContext (iCRSCode);
119 const bool doesNotOwnStdairService =
false;
120 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
126 initAIRSCHEDService();
142 void SIMCRS_Service::finalise() {
143 assert (_simcrsServiceContext != NULL);
145 _simcrsServiceContext->reset();
149 void SIMCRS_Service::initServiceContext (
const CRSCode_T& iCRSCode) {
151 SIMCRS_ServiceContext& lSIMCRS_ServiceContext =
153 _simcrsServiceContext = &lSIMCRS_ServiceContext;
157 void SIMCRS_Service::
158 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
159 const bool iOwnStdairService) {
162 assert (_simcrsServiceContext != NULL);
163 SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
166 lSIMCRS_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
171 stdair::STDAIR_ServicePtr_T SIMCRS_Service::
172 initStdAirService (
const stdair::BasLogParams& iLogParams) {
181 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
182 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
184 return lSTDAIR_Service_ptr;
188 stdair::STDAIR_ServicePtr_T SIMCRS_Service::
189 initStdAirService (
const stdair::BasLogParams& iLogParams,
190 const stdair::BasDBParams& iDBParams) {
199 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
200 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
202 return lSTDAIR_Service_ptr;
206 void SIMCRS_Service::initAIRSCHEDService() {
209 assert (_simcrsServiceContext != NULL);
210 SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
213 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
214 lSIMCRS_ServiceContext.getSTDAIR_ServicePtr();
223 AIRSCHED::AIRSCHED_ServicePtr_T lAIRSCHED_Service_ptr =
224 boost::make_shared<AIRSCHED::AIRSCHED_Service> (lSTDAIR_Service_ptr);
227 lSIMCRS_ServiceContext.setAIRSCHED_Service (lAIRSCHED_Service_ptr);
231 void SIMCRS_Service::initSIMFQTService() {
234 assert (_simcrsServiceContext != NULL);
235 SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
238 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
239 lSIMCRS_ServiceContext.getSTDAIR_ServicePtr();
248 SIMFQT::SIMFQT_ServicePtr_T lSIMFQT_Service_ptr =
249 boost::make_shared<SIMFQT::SIMFQT_Service> (lSTDAIR_Service_ptr);
252 lSIMCRS_ServiceContext.setSIMFQT_Service (lSIMFQT_Service_ptr);
256 void SIMCRS_Service::initAIRINVService() {
259 assert (_simcrsServiceContext != NULL);
260 SIMCRS_ServiceContext& lSIMCRS_ServiceContext = *_simcrsServiceContext;
263 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
264 lSIMCRS_ServiceContext.getSTDAIR_ServicePtr();
273 AIRINV::AIRINV_Master_ServicePtr_T lAIRINV_Service_ptr =
274 boost::make_shared<AIRINV::AIRINV_Master_Service> (lSTDAIR_Service_ptr);
277 lSIMCRS_ServiceContext.setAIRINV_Service (lAIRINV_Service_ptr);
281 void SIMCRS_Service::initSimcrsService() {
289 const stdair::Filename_T& iODInputFilename,
290 const AIRRAC::YieldFilePath& iYieldInputFilepath,
291 const SIMFQT::FareFilePath& iFareInputFilepath) {
294 assert (_simcrsServiceContext != NULL);
302 AIRSCHED::AIRSCHED_Service& lAIRSCHED_Service =
303 lSIMCRS_ServiceContext.getAIRSCHED_Service();
304 lAIRSCHED_Service.parseAndLoad (iScheduleInputFilename);
312 AIRINV::AIRINV_Master_Service& lAIRINV_Service =
313 lSIMCRS_ServiceContext.getAIRINV_Service();
314 lAIRINV_Service.parseAndLoad (iScheduleInputFilename, iODInputFilename,
315 iYieldInputFilepath);
320 SIMFQT::SIMFQT_Service& lSIMFQT_Service =
321 lSIMCRS_ServiceContext.getSIMFQT_Service();
322 lSIMFQT_Service.parseAndLoad (iFareInputFilepath);
329 if (_simcrsServiceContext == NULL) {
330 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
331 "has not been initialised");
333 assert (_simcrsServiceContext != NULL);
338 const bool doesOwnStdairService =
339 lSIMCRS_ServiceContext.getOwnStdairServiceFlag();
342 stdair::STDAIR_Service& lSTDAIR_Service =
343 lSIMCRS_ServiceContext.getSTDAIR_Service();
349 if (doesOwnStdairService ==
true) {
351 lSTDAIR_Service.buildSampleBom();
363 AIRSCHED::AIRSCHED_Service& lAIRSCHED_Service =
364 lSIMCRS_ServiceContext.getAIRSCHED_Service();
365 lAIRSCHED_Service.buildSampleBom();
373 AIRINV::AIRINV_Master_Service& lAIRINV_Service =
374 lSIMCRS_ServiceContext.getAIRINV_Service();
375 lAIRINV_Service.buildSampleBom();
380 SIMFQT::SIMFQT_Service& lSIMFQT_Service =
381 lSIMCRS_ServiceContext.getSIMFQT_Service();
382 lSIMFQT_Service.buildSampleBom();
397 if (_simcrsServiceContext == NULL) {
398 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
399 "has not been initialised");
401 assert (_simcrsServiceContext != NULL);
405 stdair::STDAIR_Service& lSTDAIR_Service =
406 lSIMCRS_ServiceContext.getSTDAIR_Service();
409 lSTDAIR_Service.buildSampleTravelSolutions (ioTravelSolutionList);
417 if (_simcrsServiceContext == NULL) {
418 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
419 "has not been initialised");
421 assert (_simcrsServiceContext != NULL);
425 stdair::STDAIR_Service& lSTDAIR_Service =
426 lSIMCRS_ServiceContext.getSTDAIR_Service();
429 return lSTDAIR_Service.buildSampleBookingRequest (isForCRS);
435 const stdair::FlightNumber_T& iFlightNumber,
436 const stdair::Date_T& iDepartureDate)
const {
439 if (_simcrsServiceContext == NULL) {
440 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
441 "has not been initialised");
443 assert (_simcrsServiceContext != NULL);
447 stdair::STDAIR_Service& lSTDAIR_Service =
448 lSIMCRS_ServiceContext.getSTDAIR_Service();
451 return lSTDAIR_Service.jsonExport (iAirlineCode, iFlightNumber,
458 const stdair::Date_T& iEndDate) {
461 if (_simcrsServiceContext == NULL) {
462 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
463 "not been initialised");
465 assert (_simcrsServiceContext != NULL);
469 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
470 lSIMCRS_ServiceContext.getAIRINV_Service();
472 lAIRINV_Master_Service.initSnapshotAndRMEvents (iStartDate, iEndDate);
479 if (_simcrsServiceContext == NULL) {
480 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
481 "has not been initialised");
483 assert (_simcrsServiceContext != NULL);
487 stdair::STDAIR_Service& lSTDAIR_Service =
488 lSIMCRS_ServiceContext.getSTDAIR_Service();
491 return lSTDAIR_Service.csvDisplay();
496 csvDisplay (
const stdair::TravelSolutionList_T& ioTravelSolutionList)
const {
499 if (_simcrsServiceContext == NULL) {
500 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
501 "has not been initialised");
503 assert (_simcrsServiceContext != NULL);
507 stdair::STDAIR_Service& lSTDAIR_Service =
508 lSIMCRS_ServiceContext.getSTDAIR_Service();
511 return lSTDAIR_Service.csvDisplay (ioTravelSolutionList);
519 if (_simcrsServiceContext == NULL) {
520 throw stdair::NonInitialisedServiceException (
"The SimCRS service "
521 "has not been initialised");
523 assert (_simcrsServiceContext != NULL);
527 stdair::TravelSolutionList_T oTravelSolutionList;
530 AIRSCHED::AIRSCHED_Service& lAIRSCHED_Service =
531 lSIMCRS_ServiceContext.getAIRSCHED_Service();
534 stdair::BasChronometer lTravelSolutionRetrievingChronometer;
535 lTravelSolutionRetrievingChronometer.start();
537 lAIRSCHED_Service.buildSegmentPathList (oTravelSolutionList,
541 const double lSegmentPathRetrievingMeasure =
542 lTravelSolutionRetrievingChronometer.elapsed();
543 STDAIR_LOG_DEBUG (
"Travel solution retrieving: "
544 << lSegmentPathRetrievingMeasure <<
" - "
545 << lSIMCRS_ServiceContext.display());
547 return oTravelSolutionList;
552 fareQuote (
const stdair::BookingRequestStruct& iBookingRequest,
553 stdair::TravelSolutionList_T& ioTravelSolutionList) {
556 if (_simcrsServiceContext == NULL) {
557 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
558 "not been initialised");
560 assert (_simcrsServiceContext != NULL);
565 SIMFQT::SIMFQT_Service& lSIMFQT_Service =
566 lSIMCRS_ServiceContext.getSIMFQT_Service();
569 stdair::BasChronometer lFareQuoteRetrievalChronometer;
570 lFareQuoteRetrievalChronometer.start();
572 lSIMFQT_Service.quotePrices (iBookingRequest, ioTravelSolutionList);
575 const double lFareQuoteRetrievalMeasure =
576 lFareQuoteRetrievalChronometer.elapsed();
577 STDAIR_LOG_DEBUG (
"Fare Quote retrieving: " << lFareQuoteRetrievalMeasure
578 <<
" - " << lSIMCRS_ServiceContext.display());
584 const stdair::PartnershipTechnique& iPartnershipTechnique) {
587 if (_simcrsServiceContext == NULL) {
588 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
589 "not been initialised");
591 assert (_simcrsServiceContext != NULL);
599 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
600 lSIMCRS_ServiceContext.getAIRINV_Service();
603 stdair::BasChronometer lAvlChronometer;
604 lAvlChronometer.start();
607 ioTravelSolutionList,
608 iPartnershipTechnique);
611 const double lAvlMeasure = lAvlChronometer.elapsed();
612 STDAIR_LOG_DEBUG (
"Availability retrieval: " << lAvlMeasure <<
" - "
613 << lSIMCRS_ServiceContext.display());
618 sell (
const stdair::TravelSolutionStruct& iTravelSolution,
619 const stdair::PartySize_T& iPartySize) {
620 bool hasSaleBeenSuccessful =
false;
623 if (_simcrsServiceContext == NULL) {
624 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
625 "not been initialised");
627 assert (_simcrsServiceContext != NULL);
635 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
636 lSIMCRS_ServiceContext.getAIRINV_Service();
639 stdair::BasChronometer lSellChronometer;
640 lSellChronometer.start();
647 STDAIR_LOG_DEBUG (
"Made a sell of " << iPartySize
648 <<
" persons on the following travel solution: "
649 << iTravelSolution.describe()
650 <<
" with the chosen fare option: "
651 << iTravelSolution.getChosenFareOption().describe()
652 <<
". Successful? " << hasSaleBeenSuccessful);
655 const double lSellMeasure = lSellChronometer.elapsed();
656 STDAIR_LOG_DEBUG (
"Booking sell: " << lSellMeasure <<
" - "
657 << lSIMCRS_ServiceContext.display());
659 return hasSaleBeenSuccessful;
666 bool hasCancellationBeenSuccessful =
false;
669 if (_simcrsServiceContext == NULL) {
670 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
671 "not been initialised");
673 assert (_simcrsServiceContext != NULL);
681 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
682 lSIMCRS_ServiceContext.getAIRINV_Service();
685 stdair::BasChronometer lCancellationChronometer;
686 lCancellationChronometer.start();
688 hasCancellationBeenSuccessful =
693 STDAIR_LOG_DEBUG (
"Made a cancellation of " << iCancellation.describe());
696 const double lCancellationMeasure = lCancellationChronometer.elapsed();
697 STDAIR_LOG_DEBUG (
"Booking cancellation: " << lCancellationMeasure <<
" - "
698 << lSIMCRS_ServiceContext.display());
700 return hasCancellationBeenSuccessful;
707 if (_simcrsServiceContext == NULL) {
708 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
709 "not been initialised");
711 assert (_simcrsServiceContext != NULL);
715 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
716 lSIMCRS_ServiceContext.getAIRINV_Service();
718 lAIRINV_Master_Service.takeSnapshots (iSnapshot);
724 const stdair::ForecastingMethod& iForecastingMethod,
725 const stdair::PartnershipTechnique& iPartnershipTechnique) {
728 if (_simcrsServiceContext == NULL) {
729 throw stdair::NonInitialisedServiceException (
"The SimCRS service has "
730 "not been initialised");
732 assert (_simcrsServiceContext != NULL);
736 AIRINV::AIRINV_Master_Service& lAIRINV_Master_Service =
737 lSIMCRS_ServiceContext.getAIRINV_Service();
739 lAIRINV_Master_Service.optimise (iRMEvent, iForecastingMethod, iPartnershipTechnique);