TravelCCM Logo  1.00.1
C++ Travel Customer Choice Model Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
TRAVELCCM_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/basic/BasFileMgr.hpp>
11 #include <stdair/bom/BomManager.hpp>
12 #include <stdair/bom/BookingRequestStruct.hpp>
13 #include <stdair/factory/FacBomManager.hpp>
14 #include <stdair/service/Logger.hpp>
15 #include <stdair/STDAIR_Service.hpp>
16 // TravelCCM
21 
22 namespace TRAVELCCM {
23 
24  // ////////////////////////////////////////////////////////////////////
25  TRAVELCCM_Service::TRAVELCCM_Service() : _travelccmServiceContext (NULL) {
26  assert (false);
27  }
28 
29  // ////////////////////////////////////////////////////////////////////
30  TRAVELCCM_Service::TRAVELCCM_Service (const TRAVELCCM_Service& iService)
31  : _travelccmServiceContext (NULL) {
32  assert (false);
33  }
34 
35  // ////////////////////////////////////////////////////////////////////
36  TRAVELCCM_Service::TRAVELCCM_Service (const stdair::BasLogParams& iLogParams,
37  const stdair::BasDBParams& iDBParams)
38  : _travelccmServiceContext (NULL) {
39 
40  // Initialise the STDAIR service handler
41  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
42  initStdAirService (iLogParams, iDBParams);
43 
44  // Initialise the service context
45  initServiceContext();
46 
47  // Add the StdAir service context to the AIRINV service context
48  // \note AIRINV owns the STDAIR service resources here.
49  const bool ownStdairService = true;
50  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
51 
52  // Initialise the (remaining of the) context
53  initTravelCCMService();
54  }
55 
56  // ////////////////////////////////////////////////////////////////////
57  TRAVELCCM_Service::TRAVELCCM_Service (const stdair::BasLogParams& iLogParams)
58  : _travelccmServiceContext (NULL) {
59 
60  // Initialise the STDAIR service handler
61  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
62  initStdAirService (iLogParams);
63 
64  // Initialise the service context
65  initServiceContext();
66 
67  // Add the StdAir service context to the AIRINV service context
68  // \note AIRINV 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  initTravelCCMService();
74  }
75 
76  // ////////////////////////////////////////////////////////////////////
77  TRAVELCCM_Service::
78  TRAVELCCM_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
79  : _travelccmServiceContext (NULL) {
80 
81  // Initialise the service context
82  initServiceContext();
83 
84  // Store the STDAIR service object within the (AIRINV) service context
85  // \note AirInv does not own the STDAIR service resources here.
86  const bool doesNotOwnStdairService = false;
87  addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
88 
89  // Initialise the (remaining of the) context
90  initTravelCCMService();
91  }
92 
93  // ////////////////////////////////////////////////////////////////////
95  // Delete/Clean all the objects from memory
96  finalise();
97  }
98 
99  // ////////////////////////////////////////////////////////////////////
100  void TRAVELCCM_Service::finalise() {
101  assert (_travelccmServiceContext != NULL);
102  // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
103  _travelccmServiceContext->reset();
104  }
105 
106  // ////////////////////////////////////////////////////////////////////
107  void TRAVELCCM_Service::initServiceContext() {
108  // Initialise the context
109  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
111  _travelccmServiceContext = &lTRAVELCCM_ServiceContext;
112  }
113 
114  // ////////////////////////////////////////////////////////////////////
115  void TRAVELCCM_Service::
116  addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
117  const bool iOwnStdairService) {
118  // Retrieve the Travelccm service context
119  assert (_travelccmServiceContext != NULL);
120  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
121  *_travelccmServiceContext;
122 
123  // Store the STDAIR service object within the (TRAVELCCM) service context
124  lTRAVELCCM_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
125  iOwnStdairService);
126  }
127 
128  // ////////////////////////////////////////////////////////////////////
129  stdair::STDAIR_ServicePtr_T TRAVELCCM_Service::
130  initStdAirService (const stdair::BasLogParams& iLogParams,
131  const stdair::BasDBParams& iDBParams) {
132 
139  stdair::STDAIR_ServicePtr_T oSTDAIR_Service_ptr =
140  boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
141  assert (oSTDAIR_Service_ptr != NULL);
142 
143  return oSTDAIR_Service_ptr;
144  }
145 
146  // ////////////////////////////////////////////////////////////////////
147  stdair::STDAIR_ServicePtr_T TRAVELCCM_Service::
148  initStdAirService (const stdair::BasLogParams& iLogParams) {
149 
156  stdair::STDAIR_ServicePtr_T oSTDAIR_Service_ptr =
157  boost::make_shared<stdair::STDAIR_Service> (iLogParams);
158  assert (oSTDAIR_Service_ptr != NULL);
159 
160  return oSTDAIR_Service_ptr;
161  }
162 
163  // ////////////////////////////////////////////////////////////////////
164  void TRAVELCCM_Service::initTravelCCMService() {
165  // Do nothing at this stage. A sample BOM tree may be built by
166  // calling the buildSampleBom() method
167  }
168 
169  // //////////////////////////////////////////////////////////////////////
171 
172  // Retrieve the TravelCCM service context
173  if (_travelccmServiceContext == NULL) {
174  throw stdair::NonInitialisedServiceException ("The TravelCCM service has "
175  "not been initialised");
176  }
177  assert (_travelccmServiceContext != NULL);
178 
179  // Retrieve the TravelCCM service context and whether it owns the Stdair
180  // service
181  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
182  *_travelccmServiceContext;
183  const bool doesOwnStdairService =
184  lTRAVELCCM_ServiceContext.getOwnStdairServiceFlag();
185 
186  // Retrieve the StdAir service object from the (TravelCCM) service context
187  stdair::STDAIR_Service& lSTDAIR_Service =
188  lTRAVELCCM_ServiceContext.getSTDAIR_Service();
189 
190  // Retrieve the persistent BOM root object.
191  stdair::BomRoot& lPersistentBomRoot =
192  lSTDAIR_Service.getPersistentBomRoot();
193 
198  if (doesOwnStdairService == true) {
199  //
200  lSTDAIR_Service.buildSampleBom();
201  }
202 
215  buildComplementaryLinks (lPersistentBomRoot);
216 
221  if (doesOwnStdairService == true) {
222  //
224  }
225  }
226 
227  // ////////////////////////////////////////////////////////////////////
229 
230  // Retrieve the TravelCCM service context
231  if (_travelccmServiceContext == NULL) {
232  throw stdair::NonInitialisedServiceException ("The TravelCCM service has "
233  "not been initialised");
234  }
235  assert (_travelccmServiceContext != NULL);
236 
237  // Retrieve the TravelCCM service context and whether it owns the Stdair
238  // service
239  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
240  *_travelccmServiceContext;
241  const bool doesOwnStdairService =
242  lTRAVELCCM_ServiceContext.getOwnStdairServiceFlag();
243 
244  // Retrieve the StdAir service object from the (TravelCCM) service context
245  stdair::STDAIR_Service& lSTDAIR_Service =
246  lTRAVELCCM_ServiceContext.getSTDAIR_Service();
247 
252  if (doesOwnStdairService == true) {
253  lSTDAIR_Service.clonePersistentBom ();
254  }
255 
268  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
269  buildComplementaryLinks (lBomRoot);
270  }
271 
272  // ////////////////////////////////////////////////////////////////////
273  void TRAVELCCM_Service::buildComplementaryLinks (stdair::BomRoot& ioBomRoot) {
274  // Currently, no more things to do by TravelCCM at that stage.
275  }
276 
277  // //////////////////////////////////////////////////////////////////////
279  buildSampleTravelSolutions (stdair::TravelSolutionList_T& ioTSList) {
280 
281  // Retrieve the TRAVELCCM service context
282  if (_travelccmServiceContext == NULL) {
283  throw stdair::NonInitialisedServiceException ("The Travelccm service has "
284  "not been initialised");
285  }
286  assert (_travelccmServiceContext != NULL);
287 
288  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
289  *_travelccmServiceContext;
290 
291  // Retrieve the STDAIR service object from the (TRAVELCCM) service context
292  stdair::STDAIR_Service& lSTDAIR_Service =
293  lTRAVELCCM_ServiceContext.getSTDAIR_Service();
294 
295  // Delegate the BOM building to the dedicated service
296  lSTDAIR_Service.buildSampleTravelSolutions (ioTSList);
297  }
298 
299  // //////////////////////////////////////////////////////////////////////
300  stdair::BookingRequestStruct TRAVELCCM_Service::
301  buildSampleBookingRequest (const bool isForCRS) {
302 
303  // Retrieve the TRAVELCCM service context
304  if (_travelccmServiceContext == NULL) {
305  throw stdair::NonInitialisedServiceException ("The Travelccm service has "
306  "not been initialised");
307  }
308  assert (_travelccmServiceContext != NULL);
309 
310  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
311  *_travelccmServiceContext;
312 
313  // Retrieve the STDAIR service object from the (TRAVELCCM) service context
314  stdair::STDAIR_Service& lSTDAIR_Service =
315  lTRAVELCCM_ServiceContext.getSTDAIR_Service();
316 
317  // Delegate the BOM building to the dedicated service
318  return lSTDAIR_Service.buildSampleBookingRequest (isForCRS);
319  }
320 
321  // //////////////////////////////////////////////////////////////////////
322  std::string TRAVELCCM_Service::csvDisplay() const {
323 
324  // Retrieve the TRAVELCCM service context
325  if (_travelccmServiceContext == NULL) {
326  throw stdair::NonInitialisedServiceException ("The TravelccmMaster service"
327  " has not been initialised");
328  }
329  assert (_travelccmServiceContext != NULL);
330 
331  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
332  *_travelccmServiceContext;
333 
334  // Retrieve the STDAIR service object from the (TRAVELCCM) service context
335  stdair::STDAIR_Service& lSTDAIR_Service =
336  lTRAVELCCM_ServiceContext.getSTDAIR_Service();
337  const stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
338 
339  // Delegate the BOM building to the dedicated service
340  return lSTDAIR_Service.csvDisplay(lBomRoot);
341  }
342 
343  // //////////////////////////////////////////////////////////////////////
344  std::string TRAVELCCM_Service::
345  csvDisplay (const stdair::TravelSolutionList_T& iTravelSolutionList) const {
346  // Retrieve the TRAVELCCM service context
347  if (_travelccmServiceContext == NULL) {
348  throw stdair::NonInitialisedServiceException ("The TravelccmMaster service"
349  " has not been initialised");
350  }
351  assert (_travelccmServiceContext != NULL);
352 
353  TRAVELCCM_ServiceContext& lTRAVELCCM_ServiceContext =
354  *_travelccmServiceContext;
355 
356  // Retrieve the STDAIR service object from the (TRAVELCCM) service context
357  stdair::STDAIR_Service& lSTDAIR_Service =
358  lTRAVELCCM_ServiceContext.getSTDAIR_Service();
359 
360  // Delegate the BOM building to the dedicated service
361  return lSTDAIR_Service.csvDisplay (iTravelSolutionList);
362  }
363 
364  // ////////////////////////////////////////////////////////////////////
365  const stdair::TravelSolutionStruct* TRAVELCCM_Service::
366  chooseTravelSolution (stdair::TravelSolutionList_T& ioTravelSolutionList,
367  const stdair::BookingRequestStruct& iBookingRequest,
368  const stdair::PassengerChoiceModel::EN_PassengerChoiceModel& iPassengerChoiceModel) {
369 
370  const stdair::TravelSolutionStruct* oTravelSolution_ptr =
371  ChoiceManager::chooseTravelSolution (ioTravelSolutionList,
372  iBookingRequest,
373  iPassengerChoiceModel);
374  return oTravelSolution_ptr;
375  }
376 
377 }