SimFQT Logo  1.00.0
C++ Simulated Fare Quote System Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
SIMFQT_Service.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // Boost
7 #include <boost/make_shared.hpp>
8 // StdAir
9 #include <stdair/basic/BasChronometer.hpp>
10 #include <stdair/bom/BomDisplay.hpp>
11 #include <stdair/bom/TravelSolutionStruct.hpp>
12 #include <stdair/bom/BookingRequestStruct.hpp>
13 #include <stdair/service/Logger.hpp>
14 #include <stdair/STDAIR_Service.hpp>
15 // Simfqt
22 
23 namespace SIMFQT {
24 
25  // //////////////////////////////////////////////////////////////////////
26  SIMFQT_Service::SIMFQT_Service() : _simfqtServiceContext (NULL) {
27  assert (false);
28  }
29 
30  // //////////////////////////////////////////////////////////////////////
31  SIMFQT_Service::SIMFQT_Service (const SIMFQT_Service& iService) {
32  assert (false);
33  }
34 
35  // ////////////////////////////////////////////////////////////////////
36  SIMFQT_Service::SIMFQT_Service (const stdair::BasLogParams& iLogParams)
37  : _simfqtServiceContext (NULL) {
38 
39  // Initialise the STDAIR service handler
40  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
41  initStdAirService (iLogParams);
42 
43  // Initialise the service context
44  initServiceContext();
45 
46  // Add the StdAir service context to the SIMFQT service context
47  // \note SIMFQT owns the STDAIR service resources here.
48  const bool ownStdairService = true;
49  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
50 
51  // Initialise the (remaining of the) context
52  initSimfqtService();
53  }
54 
55  // ////////////////////////////////////////////////////////////////////
56  SIMFQT_Service::SIMFQT_Service (const stdair::BasLogParams& iLogParams,
57  const stdair::BasDBParams& iDBParams)
58  : _simfqtServiceContext (NULL) {
59 
60  // Initialise the STDAIR service handler
61  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
62  initStdAirService (iLogParams, iDBParams);
63 
64  // Initialise the service context
65  initServiceContext();
66 
67  // Add the StdAir service context to the SIMFQT service context
68  // \note SIMFQT owns the STDAIR service resources here.
69  const bool ownStdairService = true;
70  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
71 
72  // Initialise the (remaining of the) context
73  initSimfqtService();
74  }
75 
76  // ////////////////////////////////////////////////////////////////////
77  SIMFQT_Service::
78  SIMFQT_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
79  : _simfqtServiceContext (NULL) {
80 
81  // Initialise the service context
82  initServiceContext();
83 
84  // Store the STDAIR service object within the (SIMFQT) service context
85  // \note Simfqt does not own the STDAIR service resources here.
86  const bool doesNotOwnStdairService = false;
87  addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
88 
89  // Initialise the context
90  initSimfqtService();
91  }
92 
93  // //////////////////////////////////////////////////////////////////////
95  // Delete/Clean all the objects from memory
96  finalise();
97  }
98 
99  // //////////////////////////////////////////////////////////////////////
100  void SIMFQT_Service::finalise() {
101  assert (_simfqtServiceContext != NULL);
102  // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
103  _simfqtServiceContext->reset();
104  }
105 
106  // //////////////////////////////////////////////////////////////////////
107  void SIMFQT_Service::initServiceContext() {
108  // Initialise the service context
109  SIMFQT_ServiceContext& lSIMFQT_ServiceContext =
111  _simfqtServiceContext = &lSIMFQT_ServiceContext;
112  }
113 
114  // ////////////////////////////////////////////////////////////////////
115  void SIMFQT_Service::
116  addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
117  const bool iOwnStdairService) {
118 
119  // Retrieve the SimFQT service context
120  assert (_simfqtServiceContext != NULL);
121  SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
122 
123  // Store the STDAIR service object within the (SimFQT) service context
124  lSIMFQT_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
125  iOwnStdairService);
126  }
127 
128  // //////////////////////////////////////////////////////////////////////
129  stdair::STDAIR_ServicePtr_T SIMFQT_Service::
130  initStdAirService (const stdair::BasLogParams& iLogParams,
131  const stdair::BasDBParams& iDBParams) {
132 
139  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
140  boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
141  assert (lSTDAIR_Service_ptr != NULL);
142 
143  return lSTDAIR_Service_ptr;
144  }
145 
146  // //////////////////////////////////////////////////////////////////////
147  stdair::STDAIR_ServicePtr_T SIMFQT_Service::
148  initStdAirService (const stdair::BasLogParams& iLogParams) {
149 
156  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
157  boost::make_shared<stdair::STDAIR_Service> (iLogParams);
158  assert (lSTDAIR_Service_ptr != NULL);
159 
160  return lSTDAIR_Service_ptr;
161  }
162 
163  // ////////////////////////////////////////////////////////////////////
164  void SIMFQT_Service::initSimfqtService() {
165  // Do nothing at this stage. A sample BOM tree may be built by
166  // calling the buildSampleBom() method
167  }
168 
169  // ////////////////////////////////////////////////////////////////////
170  void SIMFQT_Service::
171  parseAndLoad (const FareFilePath& iFareFilename) {
172 
173  // Retrieve the SimFQT service context
174  if (_simfqtServiceContext == NULL) {
175  throw stdair::NonInitialisedServiceException ("The SimFQT service "
176  "has not been initialised");
177  }
178  assert (_simfqtServiceContext != NULL);
179 
180  // Retrieve the SimFQT service context and whether it owns the Stdair
181  // service
182  SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
183  const bool doesOwnStdairService =
184  lSIMFQT_ServiceContext.getOwnStdairServiceFlag();
185 
186  // Retrieve the StdAir service object from the (SimFQT) service context
187  stdair::STDAIR_Service& lSTDAIR_Service =
188  lSIMFQT_ServiceContext.getSTDAIR_Service();
189 
190  // Retrieve the persistent BOM root object.
191  stdair::BomRoot& lPersistentBomRoot =
192  lSTDAIR_Service.getPersistentBomRoot();
193 
197  FareParser::fareRuleGeneration (iFareFilename, lPersistentBomRoot);
198 
210  buildComplementaryLinks (lPersistentBomRoot);
211 
216  if (doesOwnStdairService == true) {
217  //
219  }
220  }
221 
222  // ////////////////////////////////////////////////////////////////////
224 
225  // Retrieve the SimFQT service context
226  if (_simfqtServiceContext == NULL) {
227  throw stdair::NonInitialisedServiceException ("The SimFQT service "
228  "has not been initialised");
229  }
230  assert (_simfqtServiceContext != NULL);
231 
232  // Retrieve the SimFQT service context and whether it owns the Stdair
233  // service
234  SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
235  const bool doesOwnStdairService =
236  lSIMFQT_ServiceContext.getOwnStdairServiceFlag();
237 
238  // Retrieve the StdAir service object from the (SimFQT) service context
239  stdair::STDAIR_Service& lSTDAIR_Service =
240  lSIMFQT_ServiceContext.getSTDAIR_Service();
241 
242  // Retrieve the persistent BOM root object.
243  stdair::BomRoot& lPersistentBomRoot =
244  lSTDAIR_Service.getPersistentBomRoot();
245 
250  if (doesOwnStdairService == true) {
251  //
252  lSTDAIR_Service.buildSampleBom();
253  }
254 
266  buildComplementaryLinks (lPersistentBomRoot);
267 
272  if (doesOwnStdairService == true) {
273  //
275  }
276  }
277 
278  // ////////////////////////////////////////////////////////////////////
280 
281  // Retrieve the SimFQT service context
282  if (_simfqtServiceContext == NULL) {
283  throw stdair::NonInitialisedServiceException ("The SimFQT service "
284  "has not been initialised");
285  }
286  assert (_simfqtServiceContext != NULL);
287 
288  // Retrieve the SimFQT service context and whether it owns the Stdair
289  // service
290  SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
291  const bool doesOwnStdairService =
292  lSIMFQT_ServiceContext.getOwnStdairServiceFlag();
293 
294  // Retrieve the StdAir service object from the (SimFQT) service context
295  stdair::STDAIR_Service& lSTDAIR_Service =
296  lSIMFQT_ServiceContext.getSTDAIR_Service();
297 
302  if (doesOwnStdairService == true) {
303  //
304  lSTDAIR_Service.clonePersistentBom ();
305  }
306 
310  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
311  buildComplementaryLinks (lBomRoot);
312  }
313 
314  // ////////////////////////////////////////////////////////////////////
315  void SIMFQT_Service::buildComplementaryLinks (stdair::BomRoot& ioBomRoot) {
316  // Currently, no more things to do by SimFQT at that stage.
317  }
318 
319  // //////////////////////////////////////////////////////////////////////
320  stdair::BookingRequestStruct SIMFQT_Service::buildBookingRequest(const bool isForCRS) {
321 
322  // Retrieve the SIMFQT service context
323  if (_simfqtServiceContext == NULL) {
324  throw stdair::NonInitialisedServiceException ("The Simfqt service has not "
325  "been initialised");
326  }
327  assert (_simfqtServiceContext != NULL);
328 
329  SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
330 
331  // Retrieve the STDAIR service object from the (Simfqt) service context
332  stdair::STDAIR_Service& lSTDAIR_Service =
333  lSIMFQT_ServiceContext.getSTDAIR_Service();
334 
335  // Delegate the BOM building to the dedicated service
336  stdair::BookingRequestStruct oBookingRequest =
337  lSTDAIR_Service.buildSampleBookingRequest (isForCRS);
338 
339  return oBookingRequest;
340  }
341 
342  // //////////////////////////////////////////////////////////////////////
343  void SIMFQT_Service::
344  buildSampleTravelSolutions(stdair::TravelSolutionList_T& ioTravelSolutionList){
345 
346  // Retrieve the SIMFQT service context
347  if (_simfqtServiceContext == NULL) {
348  throw stdair::NonInitialisedServiceException ("The Simfqt service has not "
349  "been initialised");
350  }
351  assert (_simfqtServiceContext != NULL);
352 
353  SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
354 
355  // Retrieve the STDAIR service object from the (Simfqt) service context
356  stdair::STDAIR_Service& lSTDAIR_Service =
357  lSIMFQT_ServiceContext.getSTDAIR_Service();
358 
359  // Delegate the BOM building to the dedicated service
360  lSTDAIR_Service.buildSampleTravelSolutionForPricing (ioTravelSolutionList);
361  }
362 
363 
364  // ////////////////////////////////////////////////////////////////////
365  std::string SIMFQT_Service::csvDisplay() const {
366 
367  // Retrieve the SIMFQT service context
368  if (_simfqtServiceContext == NULL) {
369  throw stdair::NonInitialisedServiceException ("The SimFQT service "
370  "has not been initialised");
371  }
372  assert (_simfqtServiceContext != NULL);
373 
374  SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
375 
376  // Retrieve the STDAIR service object from the (SimFQT) service context
377  stdair::STDAIR_Service& lSTDAIR_Service =
378  lSIMFQT_ServiceContext.getSTDAIR_Service();
379 
380  // Get the root of the BOM tree, on which all of the other BOM objects
381  // are attached
382  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
383 
384  // Delegate the BOM display to the dedicated service
385  std::ostringstream oCSVStr;
386  stdair::BomDisplay::csvSimFQTAirRACDisplay (oCSVStr, lBomRoot);
387  return oCSVStr.str();
388  }
389 
390  // //////////////////////////////////////////////////////////////////////
391  std::string SIMFQT_Service::
392  csvDisplay (const stdair::TravelSolutionList_T& ioTravelSolutionList) const {
393 
394  // Retrieve the Simfqt service context
395  if (_simfqtServiceContext == NULL) {
396  throw stdair::NonInitialisedServiceException ("The Simfqt service has not "
397  "been initialised");
398  }
399  assert (_simfqtServiceContext != NULL);
400 
401  // Retrieve the Simfqt service context
402  SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
403 
404  // Retrieve the STDAIR service object from the (Simfqt) service context
405  stdair::STDAIR_Service& lSTDAIR_Service =
406  lSIMFQT_ServiceContext.getSTDAIR_Service();
407 
408  // Delegate the BOM building to the dedicated service
409  return lSTDAIR_Service.csvDisplay (ioTravelSolutionList);
410  }
411 
412  // //////////////////////////////////////////////////////////////////////
413  std::string SIMFQT_Service::
414  csvDisplay (const stdair::AirportCode_T& iOrigin,
415  const stdair::AirportCode_T& iDestination,
416  const stdair::Date_T& iDepartureDate) const {
417 
418  // Retrieve the SIMFQT service context
419  if (_simfqtServiceContext == NULL) {
420  throw stdair::NonInitialisedServiceException ("The Simfqt service "
421  "has not been initialised");
422  }
423  assert (_simfqtServiceContext != NULL);
424 
425  SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
426 
427  // Retrieve the STDAIR service object from the (SIMFQT) service context
428  stdair::STDAIR_Service& lSTDAIR_Service =
429  lSIMFQT_ServiceContext.getSTDAIR_Service();
430 
431  // Delegate the BOM display to the dedicated service
432  return lSTDAIR_Service.csvDisplay (iOrigin, iDestination,
433  iDepartureDate);
434  }
435 
436  // //////////////////////////////////////////////////////////////////////
437  std::string SIMFQT_Service::list() const {
438 
439  // Retrieve the SIMFQT service context
440  if (_simfqtServiceContext == NULL) {
441  throw stdair::NonInitialisedServiceException ("The Simfqt service "
442  "has not been initialised");
443  }
444  assert (_simfqtServiceContext != NULL);
445 
446  SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
447 
448  // Retrieve the STDAIR service object from the (SIMFQT) service context
449  stdair::STDAIR_Service& lSTDAIR_Service =
450  lSIMFQT_ServiceContext.getSTDAIR_Service();
451 
452  // Delegate the BOM display to the dedicated service
453  return lSTDAIR_Service.listAirportPairDateRange ();
454  }
455 
456  // ////////////////////////////////////////////////////////////////////
457  bool SIMFQT_Service::
458  check (const stdair::AirportCode_T& iOrigin,
459  const stdair::AirportCode_T& iDestination,
460  const stdair::Date_T& iDepartureDate) const {
461  std::ostringstream oFlightListStr;
462 
463  if (_simfqtServiceContext == NULL) {
464  throw stdair::NonInitialisedServiceException ("The Simfqt service "
465  "has not been initialised");
466  }
467  assert (_simfqtServiceContext != NULL);
468  SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
469 
470  // Retrieve the STDAIR service object from the (SIMFQT) service context
471  stdair::STDAIR_Service& lSTDAIR_Service =
472  lSIMFQT_ServiceContext.getSTDAIR_Service();
473 
474  // Delegate the BOM display to the dedicated service
475  return lSTDAIR_Service.check (iOrigin, iDestination, iDepartureDate);
476  }
477 
478  // ////////////////////////////////////////////////////////////////////
479  void SIMFQT_Service::
480  quotePrices (const stdair::BookingRequestStruct& iBookingRequest,
481  stdair::TravelSolutionList_T& ioTravelSolutionList) {
482 
483  // Retrieve the Simfqt service context
484  if (_simfqtServiceContext == NULL) {
485  throw stdair::NonInitialisedServiceException ("The SimFQT service "
486  "has not been initialised");
487  }
488  assert (_simfqtServiceContext != NULL);
489 
490  SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
491 
492  // Retrieve the StdAir service context
493  stdair::STDAIR_Service& lSTDAIR_Service =
494  lSIMFQT_ServiceContext.getSTDAIR_Service();
495 
496  // Get the root of the BOM tree, on which all of the other BOM objects
497  // will be attached
498  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
499 
500  // Delegate the action to the dedicated command
501  stdair::BasChronometer lFareQuoteRetrievalChronometer;
502  lFareQuoteRetrievalChronometer.start();
503  FareQuoter::priceQuote (iBookingRequest, ioTravelSolutionList, lBomRoot);
504 
505  // DEBUG
506  const double lFareQuoteRetrievalMeasure =
507  lFareQuoteRetrievalChronometer.elapsed();
508  STDAIR_LOG_DEBUG ("Fare Quote retrieving: " << lFareQuoteRetrievalMeasure
509  << " - " << lSIMFQT_ServiceContext.display());
510  }
511 
512 }