7 #include <boost/make_shared.hpp>
9 #include <stdair/basic/BasChronometer.hpp>
10 #include <stdair/bom/BomKeyManager.hpp>
11 #include <stdair/bom/BomManager.hpp>
12 #include <stdair/bom/BomKeyManager.hpp>
13 #include <stdair/bom/BomRoot.hpp>
14 #include <stdair/bom/Inventory.hpp>
15 #include <stdair/bom/FlightDate.hpp>
16 #include <stdair/bom/AirlineFeature.hpp>
17 #include <stdair/bom/RMEventStruct.hpp>
18 #include <stdair/factory/FacBomManager.hpp>
19 #include <stdair/service/Logger.hpp>
20 #include <stdair/STDAIR_Service.hpp>
22 #include <rmol/RMOL_Service.hpp>
24 #include <airrac/AIRRAC_Service.hpp>
37 AIRINV_Service::AIRINV_Service () : _airinvServiceContext (NULL) {
42 AIRINV_Service::AIRINV_Service (
const AIRINV_Service& iService)
43 : _airinvServiceContext (NULL) {
48 AIRINV_Service::AIRINV_Service (
const stdair::BasLogParams& iLogParams)
49 : _airinvServiceContext (NULL) {
52 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
53 initStdAirService (iLogParams);
60 const bool ownStdairService =
true;
61 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
74 AIRINV_Service::AIRINV_Service (
const stdair::BasLogParams& iLogParams,
75 const stdair::BasDBParams& iDBParams)
76 : _airinvServiceContext (NULL) {
79 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
80 initStdAirService (iLogParams, iDBParams);
87 const bool ownStdairService =
true;
88 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
101 AIRINV_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
102 : _airinvServiceContext (NULL) {
105 initServiceContext();
109 const bool doesNotOwnStdairService =
false;
110 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
130 void AIRINV_Service::finalise() {
131 assert (_airinvServiceContext != NULL);
133 _airinvServiceContext->reset();
137 void AIRINV_Service::initServiceContext() {
139 AIRINV_ServiceContext& lAIRINV_ServiceContext =
141 _airinvServiceContext = &lAIRINV_ServiceContext;
145 void AIRINV_Service::
146 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
147 const bool iOwnStdairService) {
150 assert (_airinvServiceContext != NULL);
151 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
154 lAIRINV_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
159 stdair::STDAIR_ServicePtr_T AIRINV_Service::
160 initStdAirService (
const stdair::BasLogParams& iLogParams,
161 const stdair::BasDBParams& iDBParams) {
170 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
171 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
173 return lSTDAIR_Service_ptr;
177 stdair::STDAIR_ServicePtr_T AIRINV_Service::
178 initStdAirService (
const stdair::BasLogParams& iLogParams) {
187 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
188 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
190 return lSTDAIR_Service_ptr;
194 void AIRINV_Service::initRMOLService() {
197 assert (_airinvServiceContext != NULL);
198 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
201 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
202 lAIRINV_ServiceContext.getSTDAIR_ServicePtr();
211 RMOL::RMOL_ServicePtr_T lRMOL_Service_ptr =
212 boost::make_shared<RMOL::RMOL_Service> (lSTDAIR_Service_ptr);
215 lAIRINV_ServiceContext.setRMOL_Service (lRMOL_Service_ptr);
219 void AIRINV_Service::initAIRRACService() {
222 assert (_airinvServiceContext != NULL);
223 AIRINV_ServiceContext& lAIRINV_ServiceContext = *_airinvServiceContext;
226 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
227 lAIRINV_ServiceContext.getSTDAIR_ServicePtr();
236 AIRRAC::AIRRAC_ServicePtr_T lAIRRAC_Service_ptr =
237 boost::make_shared<AIRRAC::AIRRAC_Service> (lSTDAIR_Service_ptr);
240 lAIRINV_ServiceContext.setAIRRAC_Service (lAIRRAC_Service_ptr);
244 void AIRINV_Service::initAirinvService() {
254 assert (_airinvServiceContext != NULL);
256 stdair::STDAIR_Service& lSTDAIR_Service =
257 lAIRINV_ServiceContext.getSTDAIR_Service();
258 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
267 const stdair::Filename_T& iODInputFilename,
268 const AIRRAC::YieldFilePath& iYieldFilename) {
271 assert (_airinvServiceContext != NULL);
273 stdair::STDAIR_Service& lSTDAIR_Service =
274 lAIRINV_ServiceContext.getSTDAIR_Service();
275 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
281 AIRRAC::AIRRAC_Service& lAIRRAC_Service =
282 lAIRINV_ServiceContext.getAIRRAC_Service();
283 lAIRRAC_Service.parseAndLoad (iYieldFilename);
286 lAIRRAC_Service.updateYields();
293 if (_airinvServiceContext == NULL) {
294 throw stdair::NonInitialisedServiceException(
"The AirInv service has not "
297 assert (_airinvServiceContext != NULL);
302 const bool doesOwnStdairService =
303 lAIRINV_ServiceContext.getOwnStdairServiceFlag();
306 stdair::STDAIR_Service& lSTDAIR_Service =
307 lAIRINV_ServiceContext.getSTDAIR_Service();
313 if (doesOwnStdairService ==
true) {
315 lSTDAIR_Service.buildSampleBom();
328 AIRRAC::AIRRAC_Service& lAIRRAC_Service =
329 lAIRINV_ServiceContext.getAIRRAC_Service();
330 lAIRRAC_Service.buildSampleBom();
337 RMOL::RMOL_Service& lRMOL_Service= lAIRINV_ServiceContext.getRMOL_Service();
338 lRMOL_Service.buildSampleBom();
365 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
377 const stdair::FlightNumber_T& iFlightNumber,
378 const stdair::Date_T& iDepartureDate)
const {
381 if (_airinvServiceContext == NULL) {
382 throw stdair::NonInitialisedServiceException (
"The AirInv service "
383 "has not been initialised");
385 assert (_airinvServiceContext != NULL);
390 stdair::STDAIR_Service& lSTDAIR_Service =
391 lAIRINV_ServiceContext.getSTDAIR_Service();
394 return lSTDAIR_Service.jsonExport (iAirlineCode, iFlightNumber,
400 list (
const stdair::AirlineCode_T& iAirlineCode,
401 const stdair::FlightNumber_T& iFlightNumber)
const {
402 std::ostringstream oFlightListStr;
404 if (_airinvServiceContext == NULL) {
405 throw stdair::NonInitialisedServiceException (
"The AirInv service "
406 "has not been initialised");
408 assert (_airinvServiceContext != NULL);
415 stdair::STDAIR_Service& lSTDAIR_Service =
416 lAIRINV_ServiceContext.getSTDAIR_Service();
419 return lSTDAIR_Service.list (iAirlineCode, iFlightNumber);
424 check (
const stdair::AirlineCode_T& iAirlineCode,
425 const stdair::FlightNumber_T& iFlightNumber,
426 const stdair::Date_T& iDepartureDate)
const {
427 std::ostringstream oFlightListStr;
429 if (_airinvServiceContext == NULL) {
430 throw stdair::NonInitialisedServiceException (
"The AirInv service "
431 "has not been initialised");
433 assert (_airinvServiceContext != NULL);
440 stdair::STDAIR_Service& lSTDAIR_Service =
441 lAIRINV_ServiceContext.getSTDAIR_Service();
444 return lSTDAIR_Service.check (iAirlineCode, iFlightNumber, iDepartureDate);
451 if (_airinvServiceContext == NULL) {
452 throw stdair::NonInitialisedServiceException (
"The AirInv service "
453 "has not been initialised");
455 assert (_airinvServiceContext != NULL);
460 stdair::STDAIR_Service& lSTDAIR_Service =
461 lAIRINV_ServiceContext.getSTDAIR_Service();
464 return lSTDAIR_Service.csvDisplay();
470 const stdair::FlightNumber_T& iFlightNumber,
471 const stdair::Date_T& iDepartureDate)
const {
474 if (_airinvServiceContext == NULL) {
475 throw stdair::NonInitialisedServiceException (
"The AirInv service "
476 "has not been initialised");
478 assert (_airinvServiceContext != NULL);
483 stdair::STDAIR_Service& lSTDAIR_Service =
484 lAIRINV_ServiceContext.getSTDAIR_Service();
487 return lSTDAIR_Service.csvDisplay (iAirlineCode, iFlightNumber,
494 const stdair::Date_T& iEndDate) {
496 if (_airinvServiceContext == NULL) {
497 throw stdair::NonInitialisedServiceException (
"The AirInv service "
498 "has not been initialised");
500 assert (_airinvServiceContext != NULL);
504 stdair::STDAIR_Service& lSTDAIR_Service =
505 lAIRINV_ServiceContext.getSTDAIR_Service();
506 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
508 stdair::RMEventList_T oRMEventList;
509 const stdair::InventoryList_T& lInventoryList =
510 stdair::BomManager::getList<stdair::Inventory> (lBomRoot);
511 for (stdair::InventoryList_T::const_iterator itInv = lInventoryList.begin();
512 itInv != lInventoryList.end(); ++itInv) {
513 const stdair::Inventory* lInv_ptr = *itInv;
514 assert (lInv_ptr != NULL);
517 iStartDate, iEndDate);
526 const stdair::PartnershipTechnique& iPartnershipTechnique) {
528 if (_airinvServiceContext == NULL) {
529 throw stdair::NonInitialisedServiceException (
"The AirInv service "
530 "has not been initialised");
532 assert (_airinvServiceContext != NULL);
536 stdair::STDAIR_Service& lSTDAIR_Service =
537 lAIRINV_ServiceContext.getSTDAIR_Service();
538 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
541 stdair::BasChronometer lAvlChronometer;
542 lAvlChronometer.start();
553 const stdair::ClassCode_T& iClassCode,
554 const stdair::PartySize_T& iPartySize) {
555 bool isSellSuccessful =
false;
557 if (_airinvServiceContext == NULL) {
558 throw stdair::NonInitialisedServiceException (
"The AirInv service "
559 "has not been initialised");
561 assert (_airinvServiceContext != NULL);
567 const stdair::InventoryKey& lInventoryKey =
568 stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey);
571 stdair::STDAIR_Service& lSTDAIR_Service =
572 lAIRINV_ServiceContext.getSTDAIR_Service();
573 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
576 stdair::Inventory& lInventory = stdair::BomManager::
577 getObject<stdair::Inventory> (lBomRoot, lInventoryKey.toString());
580 stdair::BasChronometer lSellChronometer; lSellChronometer.start();
582 iClassCode, iPartySize);
589 return isSellSuccessful;
594 const stdair::ClassCode_T& iClassCode,
595 const stdair::PartySize_T& iPartySize) {
596 bool isCancellationSuccessful =
false;
598 if (_airinvServiceContext == NULL) {
599 throw stdair::NonInitialisedServiceException (
"The AirInv service "
600 "has not been initialised");
602 assert (_airinvServiceContext != NULL);
608 const stdair::InventoryKey& lInventoryKey =
609 stdair::BomKeyManager::extractInventoryKey (iSegmentDateKey);
612 stdair::STDAIR_Service& lSTDAIR_Service =
613 lAIRINV_ServiceContext.getSTDAIR_Service();
614 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
617 stdair::Inventory& lInventory = stdair::BomManager::
618 getObject<stdair::Inventory> (lBomRoot, lInventoryKey.toString());
621 stdair::BasChronometer lCancellationChronometer;
622 lCancellationChronometer.start();
625 iClassCode,iPartySize);
633 return isCancellationSuccessful;
638 const stdair::DateTime_T& iSnapshotTime) {
640 if (_airinvServiceContext == NULL) {
641 throw stdair::NonInitialisedServiceException (
"The AirInv service "
642 "has not been initialised");
644 assert (_airinvServiceContext != NULL);
648 stdair::STDAIR_Service& lSTDAIR_Service =
649 lAIRINV_ServiceContext.getSTDAIR_Service();
650 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
652 const stdair::InventoryList_T lInventoryList =
653 stdair::BomManager::getList<stdair::Inventory> (lBomRoot);
654 for (stdair::InventoryList_T::const_iterator itInv = lInventoryList.begin();
655 itInv != lInventoryList.end(); ++itInv) {
656 const stdair::Inventory* lInv_ptr = *itInv;
657 assert (lInv_ptr != NULL);
665 const stdair::KeyDescription_T& iFDDescription,
666 const stdair::DateTime_T& iRMEventTime,
667 const stdair::ForecastingMethod& iForecastingMethod,
668 const stdair::PartnershipTechnique& iPartnershipTechnique) {
669 if (_airinvServiceContext == NULL) {
670 throw stdair::NonInitialisedServiceException (
"The AirInv service "
671 "has not been initialised");
673 assert (_airinvServiceContext != NULL);
677 stdair::STDAIR_Service& lSTDAIR_Service =
678 lAIRINV_ServiceContext.getSTDAIR_Service();
679 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
680 stdair::Inventory& lInventory =
681 stdair::BomManager::getObject<stdair::Inventory> (lBomRoot, iAirlineCode);
682 stdair::FlightDate& lFlightDate =
683 stdair::BomManager::getObject<stdair::FlightDate> (lInventory,
687 RMOL::RMOL_Service& lRMOL_Service =lAIRINV_ServiceContext.getRMOL_Service();
690 bool isOptimised = lRMOL_Service.optimise (lFlightDate, iRMEventTime,
691 iForecastingMethod, iPartnershipTechnique);
694 if (isOptimised ==
true) {
695 InventoryManager::updateBookingControls (lFlightDate);