StdAir Logo  1.00.0
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BomRetriever.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // StdAir
12 #include <stdair/bom/BomRoot.hpp>
13 #include <stdair/bom/Inventory.hpp>
16 #include <stdair/bom/LegDate.hpp>
18 #include <stdair/bom/LegCabin.hpp>
23 #include <stdair/bom/ParsedKey.hpp>
26 
27 namespace stdair {
28 
29  // ////////////////////////////////////////////////////////////////////
30  Inventory* BomRetriever::
32  const std::string& iFullKeyStr) {
33  Inventory* oInventory_ptr = NULL;
34 
35  // Extract the inventory key (i.e., airline code)
36  const InventoryKey& lInventoryKey =
38 
39  oInventory_ptr = iBomRoot.getInventory (lInventoryKey);
40 
41  return oInventory_ptr;
42  }
43 
44  // ////////////////////////////////////////////////////////////////////
47  const std::string& iFullKeyStr) {
48  Inventory* oInventory_ptr = NULL;
49 
50  // Extract the inventory key (i.e., airline code)
51  const InventoryKey& lInventoryKey =
53  const stdair::AirlineCode_T lAirlineCode =
54  lInventoryKey.getAirlineCode();
55 
56  oInventory_ptr =
57  BomManager::getObjectPtr<Inventory> (iInventory,
58  lAirlineCode);
59  return oInventory_ptr;
60  }
61 
62  // ////////////////////////////////////////////////////////////////////
64  const InventoryKey& iKey) {
65  Inventory* oInventory_ptr = NULL;
66 
67  //
68  oInventory_ptr = iBomRoot.getInventory (iKey);
69 
70  return oInventory_ptr;
71  }
72 
73  // ////////////////////////////////////////////////////////////////////
76  const AirlineCode_T& iAirlineCode) {
77  Inventory* oInventory_ptr = NULL;
78 
79  //
80  const InventoryKey lKey (iAirlineCode);
81  oInventory_ptr = iBomRoot.getInventory (lKey);
82 
83  return oInventory_ptr;
84  }
85 
86  // ////////////////////////////////////////////////////////////////////
89  const AirlineCode_T& iAirlineCode) {
90  Inventory* oInventory_ptr = NULL;
91  AirlineFeature* oAirlineFeature_ptr = NULL;
92 
93  //
94  oInventory_ptr = retrieveInventoryFromKey (iBomRoot, iAirlineCode);
95  if (oInventory_ptr == NULL) {
96  return oAirlineFeature_ptr;
97  }
98  assert (oInventory_ptr != NULL);
99 
100  oAirlineFeature_ptr =
101  BomManager::getObjectPtr<AirlineFeature,Inventory> (*oInventory_ptr,
102  iAirlineCode);
103 
104  return oAirlineFeature_ptr;
105  }
106 
107  // ////////////////////////////////////////////////////////////////////
110  const std::string& iFullKeyStr) {
111  FlightDate* oFlightDate_ptr = NULL;
112 
113  // Retrieve the inventory
114  Inventory* oInventory_ptr =
115  BomRetriever::retrieveInventoryFromLongKey (iBomRoot, iFullKeyStr);
116  if (oInventory_ptr == NULL) {
117  return oFlightDate_ptr;
118  }
119  assert (oInventory_ptr != NULL);
120 
121  // Extract the flight-date key (i.e., flight number and date)
122  const FlightDateKey& lFlightDateKey =
124 
125  oFlightDate_ptr = oInventory_ptr->getFlightDate (lFlightDateKey);
126 
127  return oFlightDate_ptr;
128  }
129 
130  // ////////////////////////////////////////////////////////////////////
133  const AirlineCode_T& iAirlineCode,
134  const FlightNumber_T& iFlightNumber,
135  const Date_T& iFlightDateDate) {
136  FlightDate* oFlightDate_ptr = NULL;
137 
138  // Retrieve the inventory
139  Inventory* oInventory_ptr =
140  BomRetriever::retrieveInventoryFromKey (iBomRoot, iAirlineCode);
141  if (oInventory_ptr == NULL) {
142  return oFlightDate_ptr;
143  }
144  assert (oInventory_ptr != NULL);
145 
146  //
147  oFlightDate_ptr = retrieveFlightDateFromKey (*oInventory_ptr,
148  iFlightNumber, iFlightDateDate);
149 
150  return oFlightDate_ptr;
151  }
152 
153  // ////////////////////////////////////////////////////////////////////
156  const std::string& iFullKeyStr) {
157  FlightDate* oFlightDate_ptr = NULL;
158 
159  // Extract the flight-date key (i.e., flight number and date)
160  const FlightDateKey& lFlightDateKey =
162 
163  oFlightDate_ptr = iInventory.getFlightDate (lFlightDateKey);
164 
165  return oFlightDate_ptr;
166  }
167 
168  // ////////////////////////////////////////////////////////////////////
171  const FlightDateKey& iKey) {
172  FlightDate* oFlightDate_ptr = NULL;
173 
174  //
175  oFlightDate_ptr = iInventory.getFlightDate (iKey);
176 
177  return oFlightDate_ptr;
178  }
179 
180  // ////////////////////////////////////////////////////////////////////
183  const FlightNumber_T& iFlightNumber,
184  const Date_T& iFlightDateDate) {
185  FlightDate* oFlightDate_ptr = NULL;
186 
187  //
188  const FlightDateKey lKey (iFlightNumber, iFlightDateDate);
189  oFlightDate_ptr = iInventory.getFlightDate (lKey);
190 
191  return oFlightDate_ptr;
192  }
193 
194  // ////////////////////////////////////////////////////////////////////
197  const std::string& iFullKeyStr) {
198  SegmentDate* oSegmentDate_ptr = NULL;
199 
200  // Retrieve the flight-date
201  FlightDate* oFlightDate_ptr =
202  BomRetriever::retrieveFlightDateFromLongKey (iBomRoot, iFullKeyStr);
203  if (oFlightDate_ptr == NULL) {
204  return oSegmentDate_ptr;
205  }
206  assert (oFlightDate_ptr != NULL);
207 
208  // Extract the segment-date key (i.e., origin and destination)
209  const SegmentDateKey& lSegmentDateKey =
211 
212  oSegmentDate_ptr = oFlightDate_ptr->getSegmentDate (lSegmentDateKey);
213 
214  return oSegmentDate_ptr;
215  }
216 
217  // ////////////////////////////////////////////////////////////////////
220  const std::string& iFullKeyStr) {
221  SegmentDate* oSegmentDate_ptr = NULL;
222 
223  ParsedKey lParsedKey = BomKeyManager::extractKeys (iFullKeyStr);
224 
225  if (iInventory.getAirlineCode() != lParsedKey._airlineCode) {
226  STDAIR_LOG_DEBUG ("Airline code: " << lParsedKey._airlineCode);
227  return oSegmentDate_ptr;
228  }
229 
230  FlightDate* lFlightDate_ptr =
231  retrieveFlightDateFromKey (iInventory, lParsedKey.getFlightDateKey());
232  if (lFlightDate_ptr == NULL) {
233  STDAIR_LOG_DEBUG ("Flight-date key: "
234  << lParsedKey.getFlightDateKey().toString());
235  return oSegmentDate_ptr;
236  }
237 
238  oSegmentDate_ptr =
239  retrieveSegmentDateFromKey (*lFlightDate_ptr, lParsedKey.getSegmentKey());
240  if (oSegmentDate_ptr == NULL) {
241  STDAIR_LOG_DEBUG ("Segment-date key: "
242  << lParsedKey.getSegmentKey().toString());
243  return oSegmentDate_ptr;
244  }
245 
246  return oSegmentDate_ptr;
247  }
248 
249  // ////////////////////////////////////////////////////////////////////
252  const std::string& iFullKeyStr) {
253  SegmentDate* oSegmentDate_ptr = NULL;
254 
255  // Extract the segment-date key (i.e., origin and destination)
256  const SegmentDateKey& lSegmentDateKey =
258 
259  oSegmentDate_ptr = iFlightDate.getSegmentDate (lSegmentDateKey);
260 
261  return oSegmentDate_ptr;
262  }
263 
264  // ////////////////////////////////////////////////////////////////////
267  const std::string& iFullKeyStr) {
268  LegDate* oLegDate_ptr = NULL;
269 
270  // Extract the segment-date key (i.e., origin and destination)
271  const LegDateKey& lLegDateKey =
272  BomKeyManager::extractLegDateKey (iFullKeyStr);
273 
274  oLegDate_ptr = iFlightDate.getLegDate (lLegDateKey);
275 
276  return oLegDate_ptr;
277  }
278 
279  // ////////////////////////////////////////////////////////////////////
282  const std::string& iFullKeyStr) {
283  SegmentDate* oSegmentDate_ptr = NULL;
284  Inventory* oInventory_ptr = NULL;
285 
286  // Extract the inventory key (i.e., airline code)
287  const InventoryKey& lInventoryKey =
289  const stdair::AirlineCode_T lAirlineCode =
290  lInventoryKey.getAirlineCode();
291 
292  // Retrieve the inventory
293  oInventory_ptr =
294  retrieveInventoryFromLongKey (iInventory, lAirlineCode);
295 
296  if (oInventory_ptr != NULL) {
297  oSegmentDate_ptr =
298  retrieveSegmentDateFromLongKey (*oInventory_ptr, iFullKeyStr);
299  }
300 
301  return oSegmentDate_ptr;
302 
303  }
304 
305  // ////////////////////////////////////////////////////////////////////
308  const SegmentDateKey& iKey) {
309  SegmentDate* oSegmentDate_ptr = NULL;
310 
311  //
312  oSegmentDate_ptr = iFlightDate.getSegmentDate (iKey);
313 
314  return oSegmentDate_ptr;
315  }
316 
317  // ////////////////////////////////////////////////////////////////////
320  const AirportCode_T& iOrigin,
321  const AirportCode_T& iDestination) {
322  SegmentDate* oSegmentDate_ptr = NULL;
323 
324  //
325  const SegmentDateKey lKey (iOrigin, iDestination);
326  oSegmentDate_ptr = iFlightDate.getSegmentDate (lKey);
327 
328  return oSegmentDate_ptr;
329  }
330 
331  // ////////////////////////////////////////////////////////////////////
334  const std::string& iFullKeyStr,
335  const ClassCode_T& iClassCode) {
336  BookingClass* oBookingClass_ptr = NULL;
337 
338  SegmentDate* lSegmentDate_ptr = retrieveSegmentDateFromLongKey (iInventory,
339  iFullKeyStr);
340 
341  if (lSegmentDate_ptr == NULL) {
342  return oBookingClass_ptr;
343  }
344  assert (lSegmentDate_ptr != NULL);
345 
346  //
347  oBookingClass_ptr =
348  BomManager::getObjectPtr<BookingClass> (*lSegmentDate_ptr, iClassCode);
349 
350  return oBookingClass_ptr;
351  }
352 
353  // ////////////////////////////////////////////////////////////////////
356  const stdair::AirportCode_T& iOrigin,
357  const stdair::AirportCode_T& iDestination) {
358 
359  // Get the Airport pair stream of the segment path.
360  const AirportPairKey lAirportPairKey (iOrigin, iDestination);
361 
362  // Search for the fare rules having the same origin and
363  // destination airport as the travel solution
364  AirportPair* oAirportPair_ptr = BomManager::
365  getObjectPtr<AirportPair> (iBomRoot, lAirportPairKey.toString());
366 
367  return oAirportPair_ptr;
368 
369  }
370 
371  // ////////////////////////////////////////////////////////////////////
372  void BomRetriever::
374  const stdair::Date_T& iDepartureDate,
375  stdair::DatePeriodList_T& ioDatePeriodList) {
376 
377  // Get the list of date-period
378  const DatePeriodList_T& lFareDatePeriodList =
379  BomManager::getList<DatePeriod> (iAirportPair);
380 
381  // Browse the date-period list
382  for (DatePeriodList_T::const_iterator itDateRange =
383  lFareDatePeriodList.begin();
384  itDateRange != lFareDatePeriodList.end(); ++itDateRange) {
385 
386  DatePeriod* lCurrentFareDatePeriod_ptr = *itDateRange ;
387  assert (lCurrentFareDatePeriod_ptr != NULL);
388 
389  // Select the date-period objects having a corresponding date range
390  const bool isDepartureDateValid =
391  lCurrentFareDatePeriod_ptr->isDepartureDateValid (iDepartureDate);
392 
393  // Add the date-period objects having a corresponding date range
394  // to the list to display
395  if (isDepartureDateValid == true) {
396  ioDatePeriodList.push_back(lCurrentFareDatePeriod_ptr);
397  }
398  }
399 
400  }
401 
402  // ////////////////////////////////////////////////////////////////////
403  void BomRetriever::
405  const stdair::AirportCode_T& iOrigin,
406  const stdair::AirportCode_T& iDestination,
407  const stdair::Date_T& iDepartureDate,
408  stdair::DatePeriodList_T& ioDatePeriodList) {
409 
410  // Retrieve the airport-pair
411  AirportPair* oAirportPair_ptr =
413  iDestination);
414  if (oAirportPair_ptr == NULL) {
415  return;
416  }
417  assert (oAirportPair_ptr != NULL);
418 
419  // Retrieve the flight date
420  BomRetriever::retrieveDatePeriodListFromKey (*oAirportPair_ptr, iDepartureDate,
421  ioDatePeriodList);
422 
423  }
424 
425  // ////////////////////////////////////////////////////////////////////
428  const bool isForFareFamilies) {
429 
430  LegCabin* oLegCabin_ptr = NULL;
431 
432  // Retrieve the Inventory
433  const Inventory* lInventory_ptr = BomRetriever::
435 
436  if (lInventory_ptr == NULL) {
437  std::ostringstream oStr;
438  oStr << "The inventory corresponding to the '"
439  << DEFAULT_AIRLINE_CODE << "' airline can not be found";
440  throw ObjectNotFoundException (oStr.str());
441  }
442 
443  // Retrieve the FlightDate
444  FlightDate* lFlightDate_ptr = NULL;
445  if (isForFareFamilies == true) {
446  lFlightDate_ptr = BomRetriever::
449 
450  if (lFlightDate_ptr == NULL) {
451  std::ostringstream oStr;
452  oStr << "The flight-date corresponding to ("
453  << DEFAULT_FLIGHT_NUMBER_FF << ", "
454  << DEFAULT_DEPARTURE_DATE << ") can not be found";
455  throw ObjectNotFoundException (oStr.str());
456  }
457  } else {
458  lFlightDate_ptr = BomRetriever::
461 
462  if (lFlightDate_ptr == NULL) {
463  std::ostringstream oStr;
464  oStr << "The flight-date corresponding to ("
465  << DEFAULT_FLIGHT_NUMBER << ", "
466  << DEFAULT_DEPARTURE_DATE << ") can not be found";
467  throw ObjectNotFoundException (oStr.str());
468  }
469  }
470  assert(lFlightDate_ptr != NULL);
471 
472  // Retrieve the LegDate
473  const LegDateKey lLegDateKey (DEFAULT_ORIGIN);
474  const LegDate* lLegDate_ptr =
475  lFlightDate_ptr->getLegDate (lLegDateKey);
476 
477  if (lLegDate_ptr == NULL) {
478  std::ostringstream oStr;
479  oStr << "The leg-date corresponding to the '"
480  << DEFAULT_ORIGIN << "' origin can not be found";
481  throw ObjectNotFoundException (oStr.str());
482  }
483 
484  // Retrieve the LegCabin
485  const LegCabinKey lLegCabinKey (DEFAULT_CABIN_CODE);
486  oLegCabin_ptr = lLegDate_ptr->getLegCabin (lLegCabinKey);
487 
488  if (oLegCabin_ptr == NULL) {
489  std::ostringstream oStr;
490  oStr << "The leg-cabin corresponding to the '"
491  << DEFAULT_CABIN_CODE << "' cabin code can not be found";
492  throw ObjectNotFoundException (oStr.str());
493  }
494 
495  assert (oLegCabin_ptr != NULL);
496  return *oLegCabin_ptr;
497 
498  }
499 
500  // ////////////////////////////////////////////////////////////////////
503  const bool isForFareFamilies) {
504 
505  SegmentCabin* oSegmentCabin_ptr = NULL;
506 
507  // Retrieve the Inventory
508  const Inventory* lInventory_ptr = BomRetriever::
510 
511  if (lInventory_ptr == NULL) {
512  std::ostringstream oStr;
513  oStr << "The inventory corresponding to the '"
514  << DEFAULT_AIRLINE_CODE << "' airline can not be found";
515  throw ObjectNotFoundException (oStr.str());
516  }
517 
518  // Retrieve the FlightDate
519  FlightDate* lFlightDate_ptr = NULL;
520  if (isForFareFamilies == true) {
521  lFlightDate_ptr = BomRetriever::
524 
525  if (lFlightDate_ptr == NULL) {
526  std::ostringstream oStr;
527  oStr << "The flight-date corresponding to ("
528  << DEFAULT_FLIGHT_NUMBER_FF << ", "
529  << DEFAULT_DEPARTURE_DATE << ") can not be found";
530  throw ObjectNotFoundException (oStr.str());
531  }
532  } else {
533  lFlightDate_ptr = BomRetriever::
536 
537  if (lFlightDate_ptr == NULL) {
538  std::ostringstream oStr;
539  oStr << "The flight-date corresponding to ("
540  << DEFAULT_FLIGHT_NUMBER << ", "
541  << DEFAULT_DEPARTURE_DATE << ") can not be found";
542  throw ObjectNotFoundException (oStr.str());
543  }
544  }
545  assert(lFlightDate_ptr != NULL);
546 
547  // Retrieve the SegmentDate
548  const SegmentDateKey lSegmentDateKey (DEFAULT_ORIGIN, DEFAULT_DESTINATION);
549  const SegmentDate* lSegmentDate_ptr =
550  lFlightDate_ptr->getSegmentDate (lSegmentDateKey);
551 
552  if (lSegmentDate_ptr == NULL) {
553  std::ostringstream oStr;
554  oStr << "The segment-date corresponding to the '"
555  << DEFAULT_ORIGIN << "' origin and '"
556  << DEFAULT_DESTINATION << "' destination can not be found";
557  throw ObjectNotFoundException (oStr.str());
558  }
559 
560  // Retrieve the SegmentCabin
561  const SegmentCabinKey lSegmentCabinKey (DEFAULT_CABIN_CODE);
562  oSegmentCabin_ptr =
563  BomManager::getObjectPtr<SegmentCabin> (*lSegmentDate_ptr, lSegmentCabinKey.toString());
564 
565  if (oSegmentCabin_ptr == NULL) {
566  std::ostringstream oStr;
567  oStr << "The segment-cabin corresponding to the '"
568  << DEFAULT_CABIN_CODE << "' cabin code can not be found";
569  throw ObjectNotFoundException (oStr.str());
570  }
571 
572  assert (oSegmentCabin_ptr != NULL);
573  return *oSegmentCabin_ptr;
574  }
575 
576  // ////////////////////////////////////////////////////////////////////
577  std::string BomRetriever::
579 
580  std::ostringstream lFullKeyStr;
581 
582  // Get the parent flight date
583  FlightDate* lFlightDate_ptr =
584  BomManager::getParentPtr<FlightDate>(iSegmentdate);
585  if (lFlightDate_ptr == NULL) {
586  return lFullKeyStr.str();
587  }
588  assert (lFlightDate_ptr != NULL);
589 
590  // Get the parent inventory
591  Inventory* lInventory_ptr =
592  BomManager::getParentPtr<Inventory> (*lFlightDate_ptr);
593  if (lInventory_ptr == NULL) {
594  return lFullKeyStr.str();
595  }
596  assert (lInventory_ptr != NULL);
597 
598  lFullKeyStr << lInventory_ptr->describeKey()
600  lFullKeyStr << lFlightDate_ptr->describeKey()
602  lFullKeyStr << iSegmentdate.describeKey();
603 
604  return lFullKeyStr.str();
605 
606  }
607 
608 }