StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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
11 #include <stdair/bom/BomRoot.hpp>
12 #include <stdair/bom/Inventory.hpp>
14 #include <stdair/bom/LegDate.hpp>
16 #include <stdair/bom/LegCabin.hpp>
21 #include <stdair/bom/ParsedKey.hpp>
24 
25 namespace stdair {
26 
27  // ////////////////////////////////////////////////////////////////////
28  Inventory* BomRetriever::
30  const std::string& iFullKeyStr) {
31  Inventory* oInventory_ptr = NULL;
32 
33  // Extract the inventory key (i.e., airline code)
34  const InventoryKey& lInventoryKey =
36 
37  oInventory_ptr = iBomRoot.getInventory (lInventoryKey);
38 
39  return oInventory_ptr;
40  }
41 
42  // ////////////////////////////////////////////////////////////////////
44  const InventoryKey& iKey) {
45  Inventory* oInventory_ptr = NULL;
46 
47  //
48  oInventory_ptr = iBomRoot.getInventory (iKey);
49 
50  return oInventory_ptr;
51  }
52 
53  // ////////////////////////////////////////////////////////////////////
56  const AirlineCode_T& iAirlineCode) {
57  Inventory* oInventory_ptr = NULL;
58 
59  //
60  const InventoryKey lKey (iAirlineCode);
61  oInventory_ptr = iBomRoot.getInventory (lKey);
62 
63  return oInventory_ptr;
64  }
65 
66  // ////////////////////////////////////////////////////////////////////
69  const std::string& iFullKeyStr) {
70  FlightDate* oFlightDate_ptr = NULL;
71 
72  // Retrieve the inventory
73  Inventory* oInventory_ptr =
74  BomRetriever::retrieveInventoryFromLongKey (iBomRoot, iFullKeyStr);
75  if (oInventory_ptr == NULL) {
76  return oFlightDate_ptr;
77  }
78  assert (oInventory_ptr != NULL);
79 
80  // Extract the flight-date key (i.e., flight number and date)
81  const FlightDateKey& lFlightDateKey =
83 
84  oFlightDate_ptr = oInventory_ptr->getFlightDate (lFlightDateKey);
85 
86  return oFlightDate_ptr;
87  }
88 
89  // ////////////////////////////////////////////////////////////////////
92  const AirlineCode_T& iAirlineCode,
93  const FlightNumber_T& iFlightNumber,
94  const Date_T& iFlightDateDate) {
95  FlightDate* oFlightDate_ptr = NULL;
96 
97  // Retrieve the inventory
98  Inventory* oInventory_ptr =
99  BomRetriever::retrieveInventoryFromKey (iBomRoot, iAirlineCode);
100  if (oInventory_ptr == NULL) {
101  return oFlightDate_ptr;
102  }
103  assert (oInventory_ptr != NULL);
104 
105  //
106  oFlightDate_ptr = retrieveFlightDateFromKey (*oInventory_ptr,
107  iFlightNumber, iFlightDateDate);
108 
109  return oFlightDate_ptr;
110  }
111 
112  // ////////////////////////////////////////////////////////////////////
115  const std::string& iFullKeyStr) {
116  FlightDate* oFlightDate_ptr = NULL;
117 
118  // Extract the flight-date key (i.e., flight number and date)
119  const FlightDateKey& lFlightDateKey =
121 
122  oFlightDate_ptr = iInventory.getFlightDate (lFlightDateKey);
123 
124  return oFlightDate_ptr;
125  }
126 
127  // ////////////////////////////////////////////////////////////////////
130  const FlightDateKey& iKey) {
131  FlightDate* oFlightDate_ptr = NULL;
132 
133  //
134  oFlightDate_ptr = iInventory.getFlightDate (iKey);
135 
136  return oFlightDate_ptr;
137  }
138 
139  // ////////////////////////////////////////////////////////////////////
142  const FlightNumber_T& iFlightNumber,
143  const Date_T& iFlightDateDate) {
144  FlightDate* oFlightDate_ptr = NULL;
145 
146  //
147  const FlightDateKey lKey (iFlightNumber, iFlightDateDate);
148  oFlightDate_ptr = iInventory.getFlightDate (lKey);
149 
150  return oFlightDate_ptr;
151  }
152 
153  // ////////////////////////////////////////////////////////////////////
156  const std::string& iFullKeyStr) {
157  SegmentDate* oSegmentDate_ptr = NULL;
158 
159  // Retrieve the flight-date
160  FlightDate* oFlightDate_ptr =
161  BomRetriever::retrieveFlightDateFromLongKey (iBomRoot, iFullKeyStr);
162  if (oFlightDate_ptr == NULL) {
163  return oSegmentDate_ptr;
164  }
165  assert (oFlightDate_ptr != NULL);
166 
167  // Extract the segment-date key (i.e., origin and destination)
168  const SegmentDateKey& lSegmentDateKey =
170 
171  oSegmentDate_ptr = oFlightDate_ptr->getSegmentDate (lSegmentDateKey);
172 
173  return oSegmentDate_ptr;
174  }
175 
176  // ////////////////////////////////////////////////////////////////////
179  const std::string& iFullKeyStr) {
180  SegmentDate* oSegmentDate_ptr = NULL;
181 
182  ParsedKey lParsedKey = BomKeyManager::extractKeys (iFullKeyStr);
183 
184  if (iInventory.getAirlineCode() != lParsedKey._airlineCode) {
185  STDAIR_LOG_DEBUG ("Airline code: " << lParsedKey._airlineCode);
186  return oSegmentDate_ptr;
187  }
188 
189  FlightDate* lFlightDate_ptr =
190  retrieveFlightDateFromKey (iInventory, lParsedKey.getFlightDateKey());
191  if (lFlightDate_ptr == NULL) {
192  STDAIR_LOG_DEBUG ("Flight-date key: "
193  << lParsedKey.getFlightDateKey().toString());
194  return oSegmentDate_ptr;
195  }
196 
197  oSegmentDate_ptr =
198  retrieveSegmentDateFromKey (*lFlightDate_ptr, lParsedKey.getSegmentKey());
199  if (oSegmentDate_ptr == NULL) {
200  STDAIR_LOG_DEBUG ("Segment-date key: "
201  << lParsedKey.getSegmentKey().toString());
202  return oSegmentDate_ptr;
203  }
204 
205  return oSegmentDate_ptr;
206  }
207 
208  // ////////////////////////////////////////////////////////////////////
211  const std::string& iFullKeyStr) {
212  SegmentDate* oSegmentDate_ptr = NULL;
213 
214  // Extract the segment-date key (i.e., origin and destination)
215  const SegmentDateKey& lSegmentDateKey =
217 
218  oSegmentDate_ptr = iFlightDate.getSegmentDate (lSegmentDateKey);
219 
220  return oSegmentDate_ptr;
221  }
222 
223  // ////////////////////////////////////////////////////////////////////
226  const SegmentDateKey& iKey) {
227  SegmentDate* oSegmentDate_ptr = NULL;
228 
229  //
230  oSegmentDate_ptr = iFlightDate.getSegmentDate (iKey);
231 
232  return oSegmentDate_ptr;
233  }
234 
235  // ////////////////////////////////////////////////////////////////////
238  const AirportCode_T& iOrigin,
239  const AirportCode_T& iDestination) {
240  SegmentDate* oSegmentDate_ptr = NULL;
241 
242  //
243  const SegmentDateKey lKey (iOrigin, iDestination);
244  oSegmentDate_ptr = iFlightDate.getSegmentDate (lKey);
245 
246  return oSegmentDate_ptr;
247  }
248 
249  // ////////////////////////////////////////////////////////////////////
252  const std::string& iFullKeyStr,
253  const ClassCode_T& iClassCode) {
254  BookingClass* oBookingClass_ptr = NULL;
255 
256  SegmentDate* lSegmentDate_ptr = retrieveSegmentDateFromLongKey (iInventory,
257  iFullKeyStr);
258 
259  if (lSegmentDate_ptr == NULL) {
260  return oBookingClass_ptr;
261  }
262  assert (lSegmentDate_ptr != NULL);
263 
264  //
265  oBookingClass_ptr =
266  BomManager::getObjectPtr<BookingClass> (*lSegmentDate_ptr, iClassCode);
267 
268  return oBookingClass_ptr;
269  }
270 
271  // ////////////////////////////////////////////////////////////////////
274  const stdair::AirportCode_T& iOrigin,
275  const stdair::AirportCode_T& iDestination) {
276 
277  // Get the Airport pair stream of the segment path.
278  const AirportPairKey lAirportPairKey (iOrigin, iDestination);
279 
280  // Search for the fare rules having the same origin and
281  // destination airport as the travel solution
282  AirportPair* oAirportPair_ptr = BomManager::
283  getObjectPtr<AirportPair> (iBomRoot, lAirportPairKey.toString());
284 
285  return oAirportPair_ptr;
286 
287  }
288 
289  // ////////////////////////////////////////////////////////////////////
290  void BomRetriever::
292  const stdair::Date_T& iDepartureDate,
293  stdair::DatePeriodList_T& ioDatePeriodList) {
294 
295  // Get the list of date-period
296  const DatePeriodList_T& lFareDatePeriodList =
297  BomManager::getList<DatePeriod> (iAirportPair);
298 
299  // Browse the date-period list
300  for (DatePeriodList_T::const_iterator itDateRange =
301  lFareDatePeriodList.begin();
302  itDateRange != lFareDatePeriodList.end(); ++itDateRange) {
303 
304  DatePeriod* lCurrentFareDatePeriod_ptr = *itDateRange ;
305  assert (lCurrentFareDatePeriod_ptr != NULL);
306 
307  // Select the date-period objects having a corresponding date range
308  const bool isDepartureDateValid =
309  lCurrentFareDatePeriod_ptr->isDepartureDateValid (iDepartureDate);
310 
311  // Add the date-period objects having a corresponding date range
312  // to the list to display
313  if (isDepartureDateValid == true) {
314  ioDatePeriodList.push_back(lCurrentFareDatePeriod_ptr);
315  }
316  }
317 
318  }
319 
320  // ////////////////////////////////////////////////////////////////////
321  void BomRetriever::
323  const stdair::AirportCode_T& iOrigin,
324  const stdair::AirportCode_T& iDestination,
325  const stdair::Date_T& iDepartureDate,
326  stdair::DatePeriodList_T& ioDatePeriodList) {
327 
328  // Retrieve the airport-pair
329  AirportPair* oAirportPair_ptr =
331  iDestination);
332  if (oAirportPair_ptr == NULL) {
333  return;
334  }
335  assert (oAirportPair_ptr != NULL);
336 
337  // Retrieve the flight date
338  BomRetriever::retrieveDatePeriodListFromKey (*oAirportPair_ptr, iDepartureDate,
339  ioDatePeriodList);
340 
341  }
342 
343  // ////////////////////////////////////////////////////////////////////
346 
347  LegCabin* oLegCabin_ptr = NULL;
348 
349  // Retrieve the Inventory
350  const Inventory* lInventory_ptr = BomRetriever::
352 
353  if (lInventory_ptr == NULL) {
354  std::ostringstream oStr;
355  oStr << "The inventory corresponding to the '"
356  << DEFAULT_AIRLINE_CODE << "' airline can not be found";
357  throw ObjectNotFoundException (oStr.str());
358  }
359 
360  // Retrieve the FlightDate
361  const FlightDate* lFlightDate_ptr = BomRetriever::
364 
365  if (lFlightDate_ptr == NULL) {
366  std::ostringstream oStr;
367  oStr << "The flight-date corresponding to ("
368  << DEFAULT_FLIGHT_NUMBER << ", "
369  << DEFAULT_DEPARTURE_DATE << ") can not be found";
370  throw ObjectNotFoundException (oStr.str());
371  }
372 
373  // Retrieve the LegDate
374  const LegDateKey lLegDateKey (DEFAULT_ORIGIN);
375  const LegDate* lLegDate_ptr =
376  lFlightDate_ptr->getLegDate (lLegDateKey);
377 
378  if (lLegDate_ptr == NULL) {
379  std::ostringstream oStr;
380  oStr << "The leg-date corresponding to the '"
381  << DEFAULT_ORIGIN << "' origin can not be found";
382  throw ObjectNotFoundException (oStr.str());
383  }
384 
385  // Retrieve the LegCabin
386  const LegCabinKey lLegCabinKey (DEFAULT_CABIN_CODE);
387  oLegCabin_ptr = lLegDate_ptr->getLegCabin (lLegCabinKey);
388 
389  if (oLegCabin_ptr == NULL) {
390  std::ostringstream oStr;
391  oStr << "The leg-cabin corresponding to the '"
392  << DEFAULT_CABIN_CODE << "' cabin code can not be found";
393  throw ObjectNotFoundException (oStr.str());
394  }
395 
396  assert (oLegCabin_ptr != NULL);
397  return *oLegCabin_ptr;
398 
399  }
400 
401  // ////////////////////////////////////////////////////////////////////
404 
405  SegmentCabin* oSegmentCabin_ptr = NULL;
406 
407  // Retrieve the Inventory
408  const Inventory* lInventory_ptr = BomRetriever::
410 
411  if (lInventory_ptr == NULL) {
412  std::ostringstream oStr;
413  oStr << "The inventory corresponding to the '"
414  << DEFAULT_AIRLINE_CODE << "' airline can not be found";
415  throw ObjectNotFoundException (oStr.str());
416  }
417 
418  // Retrieve the FlightDate
419  const FlightDate* lFlightDate_ptr = BomRetriever::
422 
423  if (lFlightDate_ptr == NULL) {
424  std::ostringstream oStr;
425  oStr << "The flight-date corresponding to ("
426  << DEFAULT_FLIGHT_NUMBER << ", "
427  << DEFAULT_DEPARTURE_DATE << ") can not be found";
428  throw ObjectNotFoundException (oStr.str());
429  }
430 
431  // Retrieve the SegmentDate
432  const SegmentDateKey lSegmentDateKey (DEFAULT_ORIGIN, DEFAULT_DESTINATION);
433  const SegmentDate* lSegmentDate_ptr =
434  lFlightDate_ptr->getSegmentDate (lSegmentDateKey);
435 
436  if (lSegmentDate_ptr == NULL) {
437  std::ostringstream oStr;
438  oStr << "The segment-date corresponding to the '"
439  << DEFAULT_ORIGIN << "' origin and '"
440  << DEFAULT_DESTINATION << "' destination can not be found";
441  throw ObjectNotFoundException (oStr.str());
442  }
443 
444  // Retrieve the SegmentCabin
445  const SegmentCabinKey lSegmentCabinKey (DEFAULT_CABIN_CODE);
446  oSegmentCabin_ptr =
447  BomManager::getObjectPtr<SegmentCabin> (*lSegmentDate_ptr, lSegmentCabinKey.toString());
448 
449  if (oSegmentCabin_ptr == NULL) {
450  std::ostringstream oStr;
451  oStr << "The segment-cabin corresponding to the '"
452  << DEFAULT_CABIN_CODE << "' cabin code can not be found";
453  throw ObjectNotFoundException (oStr.str());
454  }
455 
456  assert (oSegmentCabin_ptr != NULL);
457  return *oSegmentCabin_ptr;
458  }
459 
460 }