8 #include <boost/make_shared.hpp>
10 #include <stdair/basic/BasChronometer.hpp>
11 #include <stdair/basic/EventType.hpp>
12 #include <stdair/bom/BomKeyManager.hpp>
13 #include <stdair/bom/EventQueue.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>
30 AIRINV_Master_Service::AIRINV_Master_Service()
31 : _airinvMasterServiceContext (NULL) {
36 AIRINV_Master_Service::
37 AIRINV_Master_Service (
const AIRINV_Master_Service& iService)
38 : _airinvMasterServiceContext (NULL) {
43 AIRINV_Master_Service::
44 AIRINV_Master_Service (
const stdair::BasLogParams& iLogParams,
45 const stdair::BasDBParams& iDBParams)
46 : _airinvMasterServiceContext (NULL) {
49 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
50 initStdAirService (iLogParams, iDBParams);
57 const bool ownStdairService =
true;
58 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
61 initSlaveAirinvService();
65 AIRINV_Master_Service::
66 AIRINV_Master_Service (
const stdair::BasLogParams& iLogParams)
67 : _airinvMasterServiceContext (NULL) {
70 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
71 initStdAirService (iLogParams);
78 const bool ownStdairService =
true;
79 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
82 initSlaveAirinvService();
86 AIRINV_Master_Service::
87 AIRINV_Master_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
88 : _airinvMasterServiceContext (NULL) {
95 const bool doesNotOwnStdairService =
false;
96 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
99 initSlaveAirinvService();
109 void AIRINV_Master_Service::finalise() {
110 assert (_airinvMasterServiceContext != NULL);
112 _airinvMasterServiceContext->reset();
116 void AIRINV_Master_Service::initServiceContext() {
118 AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
120 _airinvMasterServiceContext = &lAIRINV_Master_ServiceContext;
124 void AIRINV_Master_Service::
125 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
126 const bool iOwnStdairService) {
129 assert (_airinvMasterServiceContext != NULL);
130 AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
131 *_airinvMasterServiceContext;
134 lAIRINV_Master_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
139 stdair::STDAIR_ServicePtr_T AIRINV_Master_Service::
140 initStdAirService (
const stdair::BasLogParams& iLogParams,
141 const stdair::BasDBParams& iDBParams) {
150 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
151 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
153 return lSTDAIR_Service_ptr;
157 stdair::STDAIR_ServicePtr_T AIRINV_Master_Service::
158 initStdAirService (
const stdair::BasLogParams& iLogParams) {
167 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
168 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
170 return lSTDAIR_Service_ptr;
174 void AIRINV_Master_Service::initSlaveAirinvService() {
177 assert (_airinvMasterServiceContext != NULL);
178 AIRINV_Master_ServiceContext& lAIRINV_Master_ServiceContext =
179 *_airinvMasterServiceContext;
182 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
183 lAIRINV_Master_ServiceContext.getSTDAIR_ServicePtr();
184 assert (lSTDAIR_Service_ptr != NULL);
196 boost::make_shared<AIRINV_Service> (lSTDAIR_Service_ptr);
199 lAIRINV_Master_ServiceContext.setAIRINV_Service (lAIRINV_Service_ptr);
207 if (_airinvMasterServiceContext == NULL) {
208 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
209 "has not been initialised");
211 assert (_airinvMasterServiceContext != NULL);
214 *_airinvMasterServiceContext;
219 lAIRINV_Master_ServiceContext.getAIRINV_Service();
228 const stdair::Filename_T& iODInputFilename,
229 const AIRRAC::YieldFilePath& iYieldFilename) {
232 if (_airinvMasterServiceContext == NULL) {
233 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
234 "has not been initialised");
236 assert (_airinvMasterServiceContext != NULL);
239 *_airinvMasterServiceContext;
244 lAIRINV_Master_ServiceContext.getAIRINV_Service();
247 lAIRINV_Service.
parseAndLoad (iScheduleInputFilename, iODInputFilename,
255 if (_airinvMasterServiceContext == NULL) {
256 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
257 "has not been initialised");
259 assert (_airinvMasterServiceContext != NULL);
264 *_airinvMasterServiceContext;
265 const bool doesOwnStdairService =
266 lAIRINV_Master_ServiceContext.getOwnStdairServiceFlag();
269 stdair::STDAIR_Service& lSTDAIR_Service =
270 lAIRINV_Master_ServiceContext.getSTDAIR_Service();
276 if (doesOwnStdairService ==
true) {
278 lSTDAIR_Service.buildSampleBom();
290 lAIRINV_Master_ServiceContext.getAIRINV_Service();
305 const stdair::FlightNumber_T& iFlightNumber,
306 const stdair::Date_T& iDepartureDate)
const {
309 if (_airinvMasterServiceContext == NULL) {
310 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
311 "has not been initialised");
313 assert (_airinvMasterServiceContext != NULL);
316 *_airinvMasterServiceContext;
321 lAIRINV_Master_ServiceContext.getAIRINV_Service();
324 return lAIRINV_Service.
jsonExport (iAirlineCode, iFlightNumber,
330 list (
const stdair::AirlineCode_T& iAirlineCode,
331 const stdair::FlightNumber_T& iFlightNumber)
const {
332 std::ostringstream oFlightListStr;
335 if (_airinvMasterServiceContext == NULL) {
336 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
337 "has not been initialised");
339 assert (_airinvMasterServiceContext != NULL);
342 *_airinvMasterServiceContext;
347 lAIRINV_Master_ServiceContext.getAIRINV_Service();
350 return lAIRINV_Service.
list (iAirlineCode, iFlightNumber);
355 check (
const stdair::AirlineCode_T& iAirlineCode,
356 const stdair::FlightNumber_T& iFlightNumber,
357 const stdair::Date_T& iDepartureDate)
const {
358 std::ostringstream oFlightListStr;
361 if (_airinvMasterServiceContext == NULL) {
362 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
363 "has not been initialised");
365 assert (_airinvMasterServiceContext != NULL);
368 *_airinvMasterServiceContext;
373 lAIRINV_Master_ServiceContext.getAIRINV_Service();
376 return lAIRINV_Service.
check (iAirlineCode, iFlightNumber, iDepartureDate);
383 if (_airinvMasterServiceContext == NULL) {
384 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
385 "has not been initialised");
387 assert (_airinvMasterServiceContext != NULL);
390 *_airinvMasterServiceContext;
395 lAIRINV_Master_ServiceContext.getAIRINV_Service();
404 const stdair::FlightNumber_T& iFlightNumber,
405 const stdair::Date_T& iDepartureDate)
const {
408 if (_airinvMasterServiceContext == NULL) {
409 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
410 "has not been initialised");
412 assert (_airinvMasterServiceContext != NULL);
415 *_airinvMasterServiceContext;
420 lAIRINV_Master_ServiceContext.getAIRINV_Service();
423 return lAIRINV_Service.
csvDisplay (iAirlineCode, iFlightNumber,
430 const stdair::Date_T& iEndDate) {
433 if (_airinvMasterServiceContext == NULL) {
434 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
435 "has not been initialised");
437 assert (_airinvMasterServiceContext != NULL);
440 *_airinvMasterServiceContext;
443 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
444 lAIRINV_Master_ServiceContext.getSTDAIR_ServicePtr();
445 assert (lSTDAIR_Service_ptr != NULL);
448 stdair::EventQueue& lQueue = lSTDAIR_Service_ptr->getEventQueue();
451 InventoryManager::initSnapshotEvents (iStartDate, iEndDate, lQueue);
459 lAIRINV_Master_ServiceContext.getAIRINV_Service();
460 lQueue.addStatus (stdair::EventType::RM, 0);
461 stdair::RMEventList_T lRMEventList =
463 InventoryManager::addRMEventsToEventQueue (lQueue, lRMEventList);
469 const stdair::PartnershipTechnique& iPartnershipTechnique) {
472 if (_airinvMasterServiceContext == NULL) {
473 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
474 "has not been initialised");
476 assert (_airinvMasterServiceContext != NULL);
479 *_airinvMasterServiceContext;
484 lAIRINV_Master_ServiceContext.getAIRINV_Service();
487 stdair::BasChronometer lAvlChronometer;
488 lAvlChronometer.start();
500 const stdair::ClassCode_T& iClassCode,
501 const stdair::PartySize_T& iPartySize) {
504 if (_airinvMasterServiceContext == NULL) {
505 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
506 "has not been initialised");
508 assert (_airinvMasterServiceContext != NULL);
511 *_airinvMasterServiceContext;
520 lAIRINV_Master_ServiceContext.getAIRINV_Service();
523 stdair::BasChronometer lSellChronometer;
524 lSellChronometer.start();
527 const bool hasBeenSaleSuccessful =
528 lAIRINV_Service.
sell (iSegmentDateKey, iClassCode, iPartySize);
537 return hasBeenSaleSuccessful;
542 const stdair::ClassCode_T& iClassCode,
543 const stdair::PartySize_T& iPartySize) {
546 if (_airinvMasterServiceContext == NULL) {
547 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
548 "has not been initialised");
550 assert (_airinvMasterServiceContext != NULL);
553 *_airinvMasterServiceContext;
562 lAIRINV_Master_ServiceContext.getAIRINV_Service();
565 stdair::BasChronometer lCancelChronometer;
566 lCancelChronometer.start();
569 const bool hasBeenSaleSuccessful =
570 lAIRINV_Service.
cancel (iSegmentDateKey, iClassCode, iPartySize);
579 return hasBeenSaleSuccessful;
587 if (_airinvMasterServiceContext == NULL) {
588 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
589 "has not been initialised");
591 assert (_airinvMasterServiceContext != NULL);
594 *_airinvMasterServiceContext;
599 lAIRINV_Master_ServiceContext.getAIRINV_Service();
602 const stdair::DateTime_T& lSnapshotTime = iSnapshot.getSnapshotTime();
603 const stdair::AirlineCode_T& lAirlineCode = iSnapshot.getAirlineCode();
611 const stdair::ForecastingMethod& iForecastingMethod,
612 const stdair::PartnershipTechnique& iPartnershipTechnique) {
615 if (_airinvMasterServiceContext == NULL) {
616 throw stdair::NonInitialisedServiceException (
"The AirInvMaster service "
617 "has not been initialised");
619 assert (_airinvMasterServiceContext != NULL);
622 *_airinvMasterServiceContext;
627 lAIRINV_Master_ServiceContext.getAIRINV_Service();
630 const stdair::DateTime_T& lRMEventTime = iRMEvent.getRMEventTime();
631 const stdair::AirlineCode_T& lAirlineCode = iRMEvent.getAirlineCode();
632 const stdair::KeyDescription_T& lFDDescription =
633 iRMEvent.getFlightDateDescription();
635 lAIRINV_Service.
optimise (lAirlineCode, lFDDescription, lRMEventTime,
636 iForecastingMethod, iPartnershipTechnique);