8 #include <boost/make_shared.hpp>
10 #include <stdair/stdair_json.hpp>
11 #include <stdair/basic/BasChronometer.hpp>
12 #include <stdair/basic/EventType.hpp>
13 #include <stdair/bom/BomKeyManager.hpp>
14 #include <stdair/bom/SnapshotStruct.hpp>
15 #include <stdair/bom/RMEventStruct.hpp>
16 #include <stdair/service/Logger.hpp>
17 #include <stdair/STDAIR_Service.hpp>
19 #include <sevmgr/SEVMGR_Service.hpp>
32 AIRINV_Master_Service::AIRINV_Master_Service()
33 : _airinvMasterServiceContext (NULL) {
38 AIRINV_Master_Service::
39 AIRINV_Master_Service (
const AIRINV_Master_Service& iService)
40 : _airinvMasterServiceContext (NULL) {
45 AIRINV_Master_Service::
46 AIRINV_Master_Service (
const stdair::BasLogParams& iLogParams,
47 const stdair::BasDBParams& iDBParams)
48 : _airinvMasterServiceContext (NULL) {
51 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
52 initStdAirService (iLogParams, iDBParams);
59 const bool ownStdairService =
true;
60 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
63 initSlaveAirinvService();
67 AIRINV_Master_Service::
68 AIRINV_Master_Service (
const stdair::BasLogParams& iLogParams)
69 : _airinvMasterServiceContext (NULL) {
72 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
73 initStdAirService (iLogParams);
80 const bool ownStdairService =
true;
81 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
84 initSlaveAirinvService();
88 AIRINV_Master_Service::
89 AIRINV_Master_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
90 : _airinvMasterServiceContext (NULL) {
97 const bool doesNotOwnStdairService =
false;
98 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
101 initSlaveAirinvService();
105 AIRINV_Master_Service::
106 AIRINV_Master_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
107 SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr)
108 : _airinvMasterServiceContext (NULL) {
111 initServiceContext();
115 const bool doesNotOwnStdairService =
false;
116 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
119 const bool doesNotOwnSEVMGRService =
false;
120 addSEVMGRService (ioSEVMGR_Service_ptr, doesNotOwnSEVMGRService);
123 initSlaveAirinvService();
133 void AIRINV_Master_Service::finalise() {
134 assert (_airinvMasterServiceContext != NULL);
136 _airinvMasterServiceContext->reset();
140 void AIRINV_Master_Service::initServiceContext() {
142 AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
144 _airinvMasterServiceContext = &lAIRINV_Master_ServiceContext;
148 void AIRINV_Master_Service::
149 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
150 const bool iOwnStdairService) {
153 assert (_airinvMasterServiceContext != NULL);
154 AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
155 *_airinvMasterServiceContext;
158 lAIRINV_Master_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
163 void AIRINV_Master_Service::
164 addSEVMGRService (SEVMGR::SEVMGR_ServicePtr_T ioSEVMGR_Service_ptr,
165 const bool iOwnSEVMGRService) {
168 assert (_airinvMasterServiceContext != NULL);
169 AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
170 *_airinvMasterServiceContext;
173 lAIRINV_Master_ServiceContext.setSEVMGR_Service (ioSEVMGR_Service_ptr,
178 stdair::STDAIR_ServicePtr_T AIRINV_Master_Service::
179 initStdAirService (
const stdair::BasLogParams& iLogParams,
180 const stdair::BasDBParams& iDBParams) {
189 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
190 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
192 return lSTDAIR_Service_ptr;
196 stdair::STDAIR_ServicePtr_T AIRINV_Master_Service::
197 initStdAirService (
const stdair::BasLogParams& iLogParams) {
206 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
207 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
209 return lSTDAIR_Service_ptr;
213 void AIRINV_Master_Service::initSlaveAirinvService() {
216 assert (_airinvMasterServiceContext != NULL);
217 AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
218 *_airinvMasterServiceContext;
221 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
222 lAIRINV_Master_ServiceContext.getSTDAIR_ServicePtr();
223 assert (lSTDAIR_Service_ptr != NULL);
235 const bool ownSEVMGRService =
236 lAIRINV_Master_ServiceContext.getOwnSEVMGRServiceFlag();
237 if (ownSEVMGRService ==
false) {
239 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
240 lAIRINV_Master_ServiceContext.getSEVMGR_ServicePtr();
241 assert (lSEVMGR_Service_ptr != NULL);
242 lAIRINV_Service_ptr = boost::make_shared<AIRINV_Service> (lSTDAIR_Service_ptr,
243 lSEVMGR_Service_ptr);
245 lAIRINV_Service_ptr = boost::make_shared<AIRINV_Service> (lSTDAIR_Service_ptr);
247 assert (lAIRINV_Service_ptr != NULL);
250 lAIRINV_Master_ServiceContext.setAIRINV_Service (lAIRINV_Service_ptr);
258 if (_airinvMasterServiceContext == NULL) {
259 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
260 "has not been initialised");
262 assert (_airinvMasterServiceContext != NULL);
267 *_airinvMasterServiceContext;
268 const bool doesOwnStdairService =
269 lAIRINV_Master_ServiceContext.getOwnStdairServiceFlag();
274 lAIRINV_Master_ServiceContext.getAIRINV_Service();
283 if (doesOwnStdairService ==
true) {
294 if (_airinvMasterServiceContext == NULL) {
295 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
296 "has not been initialised");
298 assert (_airinvMasterServiceContext != NULL);
303 *_airinvMasterServiceContext;
304 const bool doesOwnStdairService =
305 lAIRINV_Master_ServiceContext.getOwnStdairServiceFlag();
308 stdair::STDAIR_Service& lSTDAIR_Service =
309 lAIRINV_Master_ServiceContext.getSTDAIR_Service();
310 stdair::BomRoot& lPersistentBomRoot =
311 lSTDAIR_Service.getPersistentBomRoot();
317 if (doesOwnStdairService ==
true) {
319 lSTDAIR_Service.buildSampleBom();
331 lAIRINV_Master_ServiceContext.getAIRINV_Service();
344 if (doesOwnStdairService ==
true) {
354 const stdair::ODFilePath& iODInputFilename,
355 const stdair::FRAT5FilePath& iFRAT5InputFilename,
356 const stdair::FFDisutilityFilePath& iFFDisutilityInputFilename,
357 const AIRRAC::YieldFilePath& iYieldFilename) {
360 if (_airinvMasterServiceContext == NULL) {
361 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
362 "has not been initialised");
364 assert (_airinvMasterServiceContext != NULL);
369 *_airinvMasterServiceContext;
370 const bool doesOwnStdairService =
371 lAIRINV_Master_ServiceContext.getOwnStdairServiceFlag();
376 lAIRINV_Master_ServiceContext.getAIRINV_Service();
379 stdair::STDAIR_Service& lSTDAIR_Service =
380 lAIRINV_Master_ServiceContext.getSTDAIR_Service();
381 stdair::BomRoot& lPersistentBomRoot =
382 lSTDAIR_Service.getPersistentBomRoot();
387 lAIRINV_Service.
parseAndLoad (iScheduleInputFilename, iODInputFilename,
389 iFFDisutilityInputFilename, iYieldFilename);
407 if (doesOwnStdairService ==
true) {
418 if (_airinvMasterServiceContext == NULL) {
419 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
420 "has not been initialised");
422 assert (_airinvMasterServiceContext != NULL);
427 *_airinvMasterServiceContext;
428 const bool doesOwnStdairService =
429 lAIRINV_Master_ServiceContext.getOwnStdairServiceFlag();
434 lAIRINV_Master_ServiceContext.getAIRINV_Service();
437 stdair::STDAIR_Service& lSTDAIR_Service =
438 lAIRINV_Master_ServiceContext.getSTDAIR_Service();
444 if (doesOwnStdairService ==
true) {
447 lSTDAIR_Service.clonePersistentBom ();
460 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
475 if (_airinvMasterServiceContext == NULL) {
476 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
477 "has not been initialised");
479 assert (_airinvMasterServiceContext != NULL);
482 *_airinvMasterServiceContext;
487 lAIRINV_Master_ServiceContext.getAIRINV_Service();
497 const stdair::FlightNumber_T& iFlightNumber)
const {
500 if (_airinvMasterServiceContext == NULL) {
501 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
502 "has not been initialised");
504 assert (_airinvMasterServiceContext != NULL);
507 *_airinvMasterServiceContext;
512 lAIRINV_Master_ServiceContext.getAIRINV_Service();
522 const stdair::FlightNumber_T& iFlightNumber,
523 const stdair::Date_T& iDepartureDate)
const {
526 if (_airinvMasterServiceContext == NULL) {
527 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
528 "has not been initialised");
530 assert (_airinvMasterServiceContext != NULL);
533 *_airinvMasterServiceContext;
538 lAIRINV_Master_ServiceContext.getAIRINV_Service();
548 list (
const stdair::AirlineCode_T& iAirlineCode,
549 const stdair::FlightNumber_T& iFlightNumber)
const {
550 std::ostringstream oFlightListStr;
553 if (_airinvMasterServiceContext == NULL) {
554 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
555 "has not been initialised");
557 assert (_airinvMasterServiceContext != NULL);
560 *_airinvMasterServiceContext;
565 lAIRINV_Master_ServiceContext.getAIRINV_Service();
568 return lAIRINV_Service.
list (iAirlineCode, iFlightNumber);
573 check (
const stdair::AirlineCode_T& iAirlineCode,
574 const stdair::FlightNumber_T& iFlightNumber,
575 const stdair::Date_T& iDepartureDate)
const {
576 std::ostringstream oFlightListStr;
579 if (_airinvMasterServiceContext == NULL) {
580 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
581 "has not been initialised");
583 assert (_airinvMasterServiceContext != NULL);
586 *_airinvMasterServiceContext;
591 lAIRINV_Master_ServiceContext.getAIRINV_Service();
594 return lAIRINV_Service.
check (iAirlineCode, iFlightNumber, iDepartureDate);
601 if (_airinvMasterServiceContext == NULL) {
602 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
603 "has not been initialised");
605 assert (_airinvMasterServiceContext != NULL);
608 *_airinvMasterServiceContext;
613 lAIRINV_Master_ServiceContext.getAIRINV_Service();
622 const stdair::FlightNumber_T& iFlightNumber,
623 const stdair::Date_T& iDepartureDate)
const {
626 if (_airinvMasterServiceContext == NULL) {
627 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
628 "has not been initialised");
630 assert (_airinvMasterServiceContext != NULL);
633 *_airinvMasterServiceContext;
638 lAIRINV_Master_ServiceContext.getAIRINV_Service();
641 return lAIRINV_Service.
csvDisplay (iAirlineCode, iFlightNumber,
648 const stdair::Date_T& iEndDate) {
651 if (_airinvMasterServiceContext == NULL) {
652 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
653 "has not been initialised");
655 assert (_airinvMasterServiceContext != NULL);
658 *_airinvMasterServiceContext;
661 SEVMGR::SEVMGR_ServicePtr_T lSEVMGR_Service_ptr =
662 lAIRINV_Master_ServiceContext.getSEVMGR_ServicePtr();
663 assert (lSEVMGR_Service_ptr != NULL);
666 InventoryManager::initSnapshotEvents (lSEVMGR_Service_ptr, iStartDate, iEndDate);
674 lAIRINV_Master_ServiceContext.getAIRINV_Service();
675 lSEVMGR_Service_ptr->addStatus (stdair::EventType::RM, 0);
676 stdair::RMEventList_T lRMEventList =
678 assert (lRMEventList.empty() ==
false);
679 InventoryManager::addRMEventsToEventQueue (lSEVMGR_Service_ptr, lRMEventList);
687 if (_airinvMasterServiceContext == NULL) {
688 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
689 "has not been initialised");
691 assert (_airinvMasterServiceContext != NULL);
694 *_airinvMasterServiceContext;
699 lAIRINV_Master_ServiceContext.getAIRINV_Service();
702 stdair::BasChronometer lAvlChronometer;
703 lAvlChronometer.start();
715 const stdair::ClassCode_T& iClassCode,
716 const stdair::PartySize_T& iPartySize) {
719 if (_airinvMasterServiceContext == NULL) {
720 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
721 "has not been initialised");
723 assert (_airinvMasterServiceContext != NULL);
726 *_airinvMasterServiceContext;
735 lAIRINV_Master_ServiceContext.getAIRINV_Service();
738 stdair::BasChronometer lSellChronometer;
739 lSellChronometer.start();
742 const bool hasBeenSaleSuccessful =
743 lAIRINV_Service.
sell (iSegmentDateKey, iClassCode, iPartySize);
752 return hasBeenSaleSuccessful;
757 const stdair::PartySize_T& iPartySize) {
760 if (_airinvMasterServiceContext == NULL) {
761 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
762 "has not been initialised");
764 assert (_airinvMasterServiceContext != NULL);
767 *_airinvMasterServiceContext;
776 lAIRINV_Master_ServiceContext.getAIRINV_Service();
779 stdair::BasChronometer lSellChronometer;
780 lSellChronometer.start();
783 const bool hasBeenSaleSuccessful =
784 lAIRINV_Service.
sell (iClassID, iPartySize);
793 return hasBeenSaleSuccessful;
798 const stdair::ClassCode_T& iClassCode,
799 const stdair::PartySize_T& iPartySize) {
802 if (_airinvMasterServiceContext == NULL) {
803 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
804 "has not been initialised");
806 assert (_airinvMasterServiceContext != NULL);
809 *_airinvMasterServiceContext;
818 lAIRINV_Master_ServiceContext.getAIRINV_Service();
821 stdair::BasChronometer lCancelChronometer;
822 lCancelChronometer.start();
825 const bool hasBeenSaleSuccessful =
826 lAIRINV_Service.
cancel (iSegmentDateKey, iClassCode, iPartySize);
835 return hasBeenSaleSuccessful;
840 const stdair::PartySize_T& iPartySize) {
843 if (_airinvMasterServiceContext == NULL) {
844 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
845 "has not been initialised");
847 assert (_airinvMasterServiceContext != NULL);
850 *_airinvMasterServiceContext;
859 lAIRINV_Master_ServiceContext.getAIRINV_Service();
862 stdair::BasChronometer lCancelChronometer;
863 lCancelChronometer.start();
866 const bool hasBeenSaleSuccessful =
867 lAIRINV_Service.
cancel (iClassID, iPartySize);
876 return hasBeenSaleSuccessful;
884 if (_airinvMasterServiceContext == NULL) {
885 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
886 "has not been initialised");
888 assert (_airinvMasterServiceContext != NULL);
891 *_airinvMasterServiceContext;
896 lAIRINV_Master_ServiceContext.getAIRINV_Service();
899 const stdair::DateTime_T& lSnapshotTime = iSnapshot.getSnapshotTime();
900 const stdair::AirlineCode_T& lAirlineCode = iSnapshot.getAirlineCode();
910 if (_airinvMasterServiceContext == NULL) {
911 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
912 "has not been initialised");
914 assert (_airinvMasterServiceContext != NULL);
917 *_airinvMasterServiceContext;
922 lAIRINV_Master_ServiceContext.getAIRINV_Service();
925 const stdair::DateTime_T& lRMEventTime = iRMEvent.getRMEventTime();
926 const stdair::AirlineCode_T& lAirlineCode = iRMEvent.getAirlineCode();
927 const stdair::KeyDescription_T& lFDDescription =
928 iRMEvent.getFlightDateDescription();
930 lAIRINV_Service.
optimise (lAirlineCode, lFDDescription, lRMEventTime);