StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BomJSONExport.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <ostream>
7 #if BOOST_VERSION >= 103400
8 // Boost ForEach
9 #include <boost/foreach.hpp>
10 #endif // BOOST_VERSION >= 103400
11 // StdAir
14 #include <stdair/bom/BomRoot.hpp>
15 #include <stdair/bom/Inventory.hpp>
17 #include <stdair/bom/LegDate.hpp>
19 #include <stdair/bom/LegCabin.hpp>
23 #include <stdair/bom/Bucket.hpp>
25 
26 namespace stdair {
27 
28  // ////////////////////////////////////////////////////////////////////
29  void BomJSONExport::jsonExport (std::ostream& oStream,
30  const FlightDate& iFlightDate) {
31 
32  // Create an empty property tree object
33  bpt::ptree pt;
34 
35 #if BOOST_VERSION >= 104100
36 
39  const AirlineCode_T& lAirlineCode = iFlightDate.getAirlineCode();
40  const FlightNumber_T& lFlightNumber = iFlightDate.getFlightNumber();
41  const Date_T& lFlightDateDate = iFlightDate.getDepartureDate();
42 
43  // Put airline code in property tree
44  pt.put ("flight_date.airline_code", lAirlineCode);
45 
46  // Put flight number level in property tree
47  pt.put ("flight_date.flight_number", lFlightNumber);
48 
49  // Put the flight departure date in property tree
50  const std::string& lDepartureDateStr =
51  boost::gregorian::to_simple_string (lFlightDateDate);
52  pt.put ("flight_date.departure_date", lDepartureDateStr);
53 #endif // BOOST_VERSION >= 104100
54 
55  //
56  jsonLegDateExport (pt, iFlightDate);
57 
58  //
59  jsonLegCabinExport (pt, iFlightDate);
60 
61  //
62  jsonBucketExport (pt, iFlightDate);
63 
64  //
65  jsonSegmentDateExport (pt, iFlightDate);
66 
67  //
68  jsonSegmentCabinExport (pt, iFlightDate);
69 
70  //
71  jsonFareFamilyExport (pt, iFlightDate);
72 
73  //
74  jsonBookingClassExport (pt, iFlightDate);
75 
76 #if BOOST_VERSION >= 104100
77  // Write the property tree into the JSON stream.
78  write_json (oStream, pt);
79 #endif // BOOST_VERSION >= 104100
80  }
81 
82  // ////////////////////////////////////////////////////////////////////
83  void BomJSONExport::jsonLegDateExport (bpt::ptree& ioPropertyTree,
84  const FlightDate& iFlightDate) {
89  // Check whether there are LegDate objects
90  if (BomManager::hasList<LegDate> (iFlightDate) == false) {
91  return;
92  }
93 
94  // Browse the leg-dates
95  const LegDateList_T& lLegDateList =
96  BomManager::getList<LegDate> (iFlightDate);
97  for (LegDateList_T::const_iterator itLD = lLegDateList.begin();
98  itLD != lLegDateList.end(); ++itLD) {
99  const LegDate* lLD_ptr = *itLD;
100  assert (lLD_ptr != NULL);
101 
102 #if BOOST_VERSION >= 104100
103 
104  //
105  bpt::ptree lLegDateArray;
106 
107  // Put boarding point in property tree
108  lLegDateArray.put ("BoardPoint", lLD_ptr->getBoardingPoint());
109  // Put off point in property tree
110  lLegDateArray.put ("OffPoint", lLD_ptr->getOffPoint());
111  // Put boarding date in property tree
112  lLegDateArray.put ("BoardDate", lLD_ptr->getBoardingDate());
113  // Put off date in property tree
114  lLegDateArray.put ("OffDate", lLD_ptr->getOffDate());
115  // Put boarding time in property tree
116  lLegDateArray.put ("BoardTime", lLD_ptr->getBoardingTime());
117  // Put off time in property tree
118  lLegDateArray.put ("OffTime", lLD_ptr->getOffTime());
119  // Put elapsed time in property tree
120  lLegDateArray.put ("Elapsed", lLD_ptr->getElapsedTime());
121  // Put date offset in property tree
122  lLegDateArray.put ("Date_Offset", lLD_ptr->getDateOffset());
123  // Put time offset in property tree
124  lLegDateArray.put ("Time_Offset", lLD_ptr->getTimeOffset());
125  // Put distance in property tree
126  lLegDateArray.put ("Distance", lLD_ptr->getDistance());
127  // Put capacity in property tree
128  lLegDateArray.put ("Capacity", lLD_ptr->getCapacity());
129 
130  // Put leg date array in property tree
131  std::ostringstream oStream;
132  oStream << "flight_date.leg_" << lLD_ptr->getBoardingPoint();
133  ioPropertyTree.put_child(oStream.str(),lLegDateArray);
134 
135 #endif // BOOST_VERSION >= 104100
136  }
137  }
138 
139  // ////////////////////////////////////////////////////////////////////
140  void BomJSONExport::jsonLegCabinExport (bpt::ptree& ioPropertyTree,
141  const FlightDate& iFlightDate) {
146  // Check whether there are LegDate objects
147  if (BomManager::hasList<LegDate> (iFlightDate) == false) {
148  return;
149  }
150 
151  const LegDateList_T& lLegDateList =
152  BomManager::getList<LegDate> (iFlightDate);
153  for (LegDateList_T::const_iterator itLD = lLegDateList.begin();
154  itLD != lLegDateList.end(); ++itLD) {
155  const LegDate* lLD_ptr = *itLD;
156  assert (lLD_ptr != NULL);
157 
158  // Browse the leg-cabins
159  const LegCabinList_T& lLegCabinList =
160  BomManager::getList<LegCabin> (*lLD_ptr);
161  for (LegCabinList_T::const_iterator itLC = lLegCabinList.begin();
162  itLC != lLegCabinList.end(); ++itLC) {
163  const LegCabin* lLC_ptr = *itLC;
164  assert (lLC_ptr != NULL);
165 
166 #if BOOST_VERSION >= 104100
167 
168  //
169  bpt::ptree lLegCabinArray;
170 
171  // Put the offered capacity in property tree
172  lLegCabinArray.put ("OffedCAP", lLC_ptr->getOfferedCapacity());
173  // Put the physical capacity in property tree
174  lLegCabinArray.put ("PhyCAP", lLC_ptr->getPhysicalCapacity());
175  // Put regrade adjustment in property tree
176  lLegCabinArray.put ("RgdADJ", lLC_ptr->getRegradeAdjustment());
177  // Put authorization level in property tree
178  lLegCabinArray.put ("AU", lLC_ptr->getAuthorizationLevel());
179  // Put UPR in property tree
180  lLegCabinArray.put ("UPR", lLC_ptr->getUPR());
181  // Put sold seats in property tree
182  lLegCabinArray.put ("SS", lLC_ptr->getSoldSeat());
183  // Put staff nb of seats in property tree
184  lLegCabinArray.put ("Staff", lLC_ptr->getStaffNbOfSeats());
185  // Put waiting list nb of seats in property tree
186  lLegCabinArray.put ("WL", lLC_ptr->getWLNbOfSeats());
187  // Put group nb of seats in property tree
188  lLegCabinArray.put ("Group", lLC_ptr->getGroupNbOfSeats());
189  // Put committed space in property tree
190  lLegCabinArray.put ("CommSpace", lLC_ptr->getCommittedSpace());
191  // Put availability pool in property tree
192  lLegCabinArray.put ("AvPool", lLC_ptr->getAvailabilityPool());
193  // Put availability in property tree
194  lLegCabinArray.put ("Avl", lLC_ptr->getAvailability());
195  // Put net availability in property tree
196  lLegCabinArray.put ("NAV", lLC_ptr->getNetAvailability());
197  // Put gross availability in property tree
198  lLegCabinArray.put ("GAV", lLC_ptr->getGrossAvailability());
199  // Put avg cancellation percentage in property tree
200  lLegCabinArray.put ("ACP", lLC_ptr->getAvgCancellationPercentage());
201  // Put ETB in property tree
202  lLegCabinArray.put ("ETB", lLC_ptr->getETB());
203  // Put current bid price in property tree
204  lLegCabinArray.put ("BidPrice", lLC_ptr->getCurrentBidPrice());
205 
206  // Put leg cabin array in property tree
207  std::ostringstream oStream;
208  oStream << "flight_date"
209  << ".leg_" << lLD_ptr->getBoardingPoint()
210  << ".cabin_" << lLC_ptr->toString();
211  ioPropertyTree.put_child (oStream.str(), lLegCabinArray);
212 
213 #endif // BOOST_VERSION >= 104100
214  }
215  }
216  }
217 
218  // ////////////////////////////////////////////////////////////////////
219  void BomJSONExport::jsonBucketExport (bpt::ptree& ioPropertyTree,
220  const FlightDate& iFlightDate) {
225  // Check whether there are LegDate objects
226  if (BomManager::hasList<LegDate> (iFlightDate) == false) {
227  return;
228  }
229 
230  // Browse the leg-dates
231  const LegDateList_T& lLegDateList =
232  BomManager::getList<LegDate> (iFlightDate);
233  for (LegDateList_T::const_iterator itLD = lLegDateList.begin();
234  itLD != lLegDateList.end(); ++itLD) {
235  const LegDate* lLD_ptr = *itLD;
236  assert (lLD_ptr != NULL);
237 
238  // Browse the leg-cabins
239  const LegCabinList_T& lLegCabinList =
240  BomManager::getList<LegCabin> (*lLD_ptr);
241  for (LegCabinList_T::const_iterator itLC = lLegCabinList.begin();
242  itLC != lLegCabinList.end(); ++itLC) {
243  const LegCabin* lLC_ptr = *itLC;
244  assert (lLC_ptr != NULL);
245 
246  // Check whether there are bucket objects
247  if (BomManager::hasList<Bucket> (*lLC_ptr) == false) {
248  return;
249  }
250 
251  // Browse the buckets
252  const BucketList_T& lBucketList = BomManager::getList<Bucket> (*lLC_ptr);
253  for (BucketList_T::const_iterator itBuck = lBucketList.begin();
254  itBuck != lBucketList.end(); ++itBuck) {
255  const Bucket* lBucket_ptr = *itBuck;
256  assert (lBucket_ptr != NULL);
257 
258 #if BOOST_VERSION >= 104100
259 
260  //
261  bpt::ptree lLegBucketArray;
262 
263  // Put yield in property tree
264  lLegBucketArray.put ("Yield", lBucket_ptr->getYieldRangeUpperValue());
265  // Put seat_index in property tree
266  lLegBucketArray.put ("SI", lBucket_ptr->getSeatIndex());
267  // Put sold_seats in property tree
268  lLegBucketArray.put ("SS", lBucket_ptr->getSoldSeats());
269  // Put avaibility in property tree
270  lLegBucketArray.put ("AV", lBucket_ptr->getAvailability());
271 
272  // Put bucket array in property tree
273  std::ostringstream oStream;
274  oStream << "flight_date"
275  << ".leg_" << lLD_ptr->getBoardingPoint()
276  << ".cabin_" << lLC_ptr->toString()
277  << ".bucket_" << lBucket_ptr->toString();
278  ioPropertyTree.put_child (oStream.str(),lLegBucketArray);
279 
280 #endif // BOOST_VERSION >= 104100
281  }
282  }
283  }
284  }
285 
286  // ////////////////////////////////////////////////////////////////////
287  void BomJSONExport::jsonSegmentDateExport (bpt::ptree& ioPropertyTree,
288  const FlightDate& iFlightDate) {
289 
294  // Check whether there are SegmentDate objects
295  if (BomManager::hasList<SegmentDate> (iFlightDate) == false) {
296  return;
297  }
298 
299  // Browse the segment-dates
300  unsigned short idx = 0;
301  const SegmentDateList_T& lSegmentDateList =
302  BomManager::getList<SegmentDate> (iFlightDate);
303  for (SegmentDateList_T::const_iterator itSD = lSegmentDateList.begin();
304  itSD != lSegmentDateList.end(); ++itSD, ++idx) {
305  const SegmentDate* lSD_ptr = *itSD;
306  assert (lSD_ptr != NULL);
307 
308 #if BOOST_VERSION >= 104100
309 
310  //
311  bpt::ptree lSegmentDateArray;
312 
313  // Put boarding point in property tree
314  lSegmentDateArray.put ("BoardPoint", lSD_ptr->getBoardingPoint());
315  // Put off point in property tree
316  lSegmentDateArray.put ("OffPoint", lSD_ptr->getOffPoint());
317  // Put boarding date in property tree
318  lSegmentDateArray.put ("BoardDate", lSD_ptr->getBoardingDate());
319  // Put off date in property tree
320  lSegmentDateArray.put ("OffDate", lSD_ptr->getOffDate());
321  // Put boarding time in property tree
322  lSegmentDateArray.put ("BoardTime", lSD_ptr->getBoardingTime());
323  // Put off time in property tree
324  lSegmentDateArray.put ("OffTime", lSD_ptr->getOffTime());
325  // Put elapsed time in property tree
326  lSegmentDateArray.put ("Elapsed", lSD_ptr->getElapsedTime());
327  // Put date offset in property tree
328  lSegmentDateArray.put ("Date_Offset", lSD_ptr->getDateOffset());
329  // Put time offset in property tree
330  lSegmentDateArray.put ("Time_Offset", lSD_ptr->getTimeOffset());
331  // Put distance in property tree
332  lSegmentDateArray.put ("Distance", lSD_ptr->getDistance());
333 
334  // Put segment date array in property tree
335  std::ostringstream oStream;
336  oStream << "flight_date.segment_" << lSD_ptr->getBoardingPoint()
337  << "_" << lSD_ptr->getOffPoint();
338  ioPropertyTree.put_child(oStream.str(),lSegmentDateArray);
339 
340 #endif // BOOST_VERSION >= 104100
341  }
342  }
343 
344  // ////////////////////////////////////////////////////////////////////
345  void BomJSONExport::jsonSegmentCabinExport (bpt::ptree& ioPropertyTree,
346  const FlightDate& iFlightDate) {
350  }
351 
352  // ////////////////////////////////////////////////////////////////////
353  void BomJSONExport::jsonFareFamilyExport (bpt::ptree& ioPropertyTree,
354  const FlightDate& iFlightDate) {
359  // Check whether there are SegmentDate objects
360  if (BomManager::hasList<SegmentDate> (iFlightDate) == false) {
361  return;
362  }
363 
364  // Browse the segment-dates
365  unsigned short idx = 0;
366  const SegmentDateList_T& lSegmentDateList =
367  BomManager::getList<SegmentDate> (iFlightDate);
368  for (SegmentDateList_T::const_iterator itSD = lSegmentDateList.begin();
369  itSD != lSegmentDateList.end(); ++itSD, ++idx) {
370  const SegmentDate* lSD_ptr = *itSD;
371  assert (lSD_ptr != NULL);
372 
373  // Browse the segment-cabins
374  const SegmentCabinList_T& lSegmentCabinList =
375  BomManager::getList<SegmentCabin> (*lSD_ptr);
376  for (SegmentCabinList_T::const_iterator itSC = lSegmentCabinList.begin();
377  itSC != lSegmentCabinList.end(); ++itSC) {
378  const SegmentCabin* lSC_ptr = *itSC;
379  assert (lSC_ptr != NULL);
380 
381  // Check whether there are fare family objects
382  if (BomManager::hasList<FareFamily> (*lSC_ptr) == false) {
383  continue;
384  }
385 
386  // Browse the fare families
387  unsigned short ffIdx = 0;
388  const FareFamilyList_T& lFareFamilyList =
389  BomManager::getList<FareFamily> (*lSC_ptr);
390  for (FareFamilyList_T::const_iterator itFF = lFareFamilyList.begin();
391  itFF != lFareFamilyList.end(); ++itFF, ++ffIdx) {
392  const FareFamily* lFF_ptr = *itFF;
393  assert (lFF_ptr != NULL);
394 
395 #if BOOST_VERSION >= 104100
396  //
397  bpt::ptree lFFArray;
398 
399  // Put cabin in property tree
400  lFFArray.put ("cabin",lSC_ptr->toString());
401  // Put fare family in property tree
402  lFFArray.put ("code", lFF_ptr->getFamilyCode());
403  // Put MIN in property tree
404  lFFArray.put ("MIN", lSC_ptr->getMIN());
405  // Put UPR in property tree
406  lFFArray.put ("UPR", lSC_ptr->getUPR());
407  // Put committed Ssace in property tree
408  lFFArray.put ("CommSpace", lSC_ptr->getCommittedSpace());
409  // Put availability pool in property tree
410  lFFArray.put ("AvPool", lSC_ptr->getAvailabilityPool());
411  // Put current bid price in property tree
412  lFFArray.put ("BP", lSC_ptr->getCurrentBidPrice());
413 
414  std::ostringstream oStream;
415  oStream << "flight_date.segment_" << lSD_ptr->getBoardingPoint()
416  << "_" << lSD_ptr->getOffPoint()
417  << ".fare_family_" << lFF_ptr->toString();
418  ioPropertyTree.put_child (oStream.str(), lFFArray);
419 #endif // BOOST_VERSION >= 104100
420  }
421  }
422  }
423  }
424 
425  // ////////////////////////////////////////////////////////////////////
426  void BomJSONExport::jsonBookingClassExport (bpt::ptree& ioPropertyTree,
427  const BookingClass& iBookingClass,
428  const std::string& iLeadingString) {
435  std::ostringstream oStream;
436  oStream << iLeadingString;
437  oStream << ".class_" << iBookingClass.toString();
438 
439 #if BOOST_VERSION >= 104100
440 
441  bpt::ptree lBookingClassArray;
442 
443  // Put sub class in property tree
444  lBookingClassArray.put ("Subclass", iBookingClass.getSubclassCode());
445  // Put authorization level in property tree
446  std::ostringstream oAUProtStr;
447  oAUProtStr << iBookingClass.getAuthorizationLevel()
448  << " (" << iBookingClass.getProtection()
449  << ") ";
450  lBookingClassArray.put ("MIN/AU (Prot)", oAUProtStr.str());
451  // Put negotiated space in property tree
452  lBookingClassArray.put ("Nego", iBookingClass.getNegotiatedSpace());
453  // Put no show percentage in property tree
454  lBookingClassArray.put ("NS%", iBookingClass.getNoShowPercentage());
455  // Put cancellation percentage in property tree
456  lBookingClassArray.put ("OB%", iBookingClass.getCancellationPercentage());
457  // Put sub nb of bookings in property tree
458  lBookingClassArray.put ("Bkgs", iBookingClass.getNbOfBookings());
459  // Put nb of group bookings in property tree
460  lBookingClassArray.put ("GrpBks (pdg)", iBookingClass.getNbOfGroupBookings());
461  // Put nb of staff bookings in property tree
462  lBookingClassArray.put ("StfBkgs", iBookingClass.getNbOfStaffBookings());
463  // Put nb of WL bookings in property tree
464  lBookingClassArray.put ("WLBkgs", iBookingClass.getNbOfWLBookings());
465  // Put ETB in property tree
466  lBookingClassArray.put ("ETB", iBookingClass.getETB());
467  // Put net class availability in property tree
468  lBookingClassArray.put ("ClassAvl", iBookingClass.getNetClassAvailability());
469  // Put segment availability in property tree
470  lBookingClassArray.put ("SegAvl", iBookingClass.getSegmentAvailability());
471  // Put net revenue availability in property tree
472  lBookingClassArray.put ("RevAvl", iBookingClass.getNetRevenueAvailability());
473 
474  //
475  ioPropertyTree.put_child (oStream.str(), lBookingClassArray);
476 
477 #endif // BOOST_VERSION >= 104100
478  }
479 
480  // ////////////////////////////////////////////////////////////////////
481  void BomJSONExport::jsonBookingClassExport (bpt::ptree& ioPropertyTree,
482  const FlightDate& iFlightDate) {
483  // Check whether there are SegmentDate objects
484  if (BomManager::hasList<SegmentDate> (iFlightDate) == false) {
485  return;
486  }
487 
488  // Browse the segment-dates
489  const SegmentDateList_T& lSegmentDateList =
490  BomManager::getList<SegmentDate> (iFlightDate);
491  for (SegmentDateList_T::const_iterator itSD = lSegmentDateList.begin();
492  itSD != lSegmentDateList.end(); ++itSD) {
493  const SegmentDate* lSD_ptr = *itSD;
494  assert (lSD_ptr != NULL);
495 
496  // Build the leading string to be displayed
497  std::ostringstream oLeadingStr;
498  // Begin completed the leading string to be displayed
499  oLeadingStr << "flight_date.segment_" << lSD_ptr->getBoardingPoint()
500  << "_" << lSD_ptr->getOffPoint();
501 
502  // Browse the segment-cabins
503  const SegmentCabinList_T& lSegmentCabinList =
504  BomManager::getList<SegmentCabin> (*lSD_ptr);
505  for (SegmentCabinList_T::const_iterator itSC = lSegmentCabinList.begin();
506  itSC != lSegmentCabinList.end(); ++itSC) {
507  const SegmentCabin* lSC_ptr = *itSC;
508  assert (lSC_ptr != NULL);
509 
510  // Check whether there are FareFamily objects
511  if (BomManager::hasList<FareFamily> (*lSC_ptr) == true) {
512 
513  // Browse the fare families
514  const FareFamilyList_T& lFareFamilyList =
515  BomManager::getList<FareFamily> (*lSC_ptr);
516  for (FareFamilyList_T::const_iterator itFF = lFareFamilyList.begin();
517  itFF != lFareFamilyList.end(); ++itFF) {
518  const FareFamily* lFF_ptr = *itFF;
519  assert (lFF_ptr != NULL);
520 
521  oLeadingStr << ".fare_family_" << lFF_ptr->toString();
522 
523  // Browse the booking-classes
524  const BookingClassList_T& lBookingClassList =
525  BomManager::getList<BookingClass> (*lFF_ptr);
526  for (BookingClassList_T::const_iterator itBC =
527  lBookingClassList.begin();
528  itBC != lBookingClassList.end(); ++itBC) {
529  const BookingClass* lBC_ptr = *itBC;
530  assert (lBC_ptr != NULL);
531 
532  //
533  jsonBookingClassExport (ioPropertyTree, *lBC_ptr,
534  oLeadingStr.str());
535  }
536  }
537  } else {
538 
539  // The fare family code is a fake one ('NoFF'), and therefore
540  // does not vary
541  FamilyCode_T lDefaultFamilyCode ("NoFF");
542  oLeadingStr << ".fare_family_" << lDefaultFamilyCode ;
543 
544  // Browse the booking-classes, directly from the segment-cabin object
545  const BookingClassList_T& lBookingClassList =
546  BomManager::getList<BookingClass> (*lSC_ptr);
547  for (BookingClassList_T::const_iterator itBC =
548  lBookingClassList.begin();
549  itBC != lBookingClassList.end(); ++itBC) {
550  const BookingClass* lBC_ptr = *itBC;
551  assert (lBC_ptr != NULL);
552 
553  //
554  jsonBookingClassExport (ioPropertyTree, *lBC_ptr, oLeadingStr.str());
555  }
556  }
557  }
558  }
559  }
560 }