Go to the documentation of this file.00001
00002
00003
00004
00005 #include <cassert>
00006
00007 #include <boost/make_shared.hpp>
00008
00009 #include <stdair/basic/BasChronometer.hpp>
00010 #include <stdair/bom/BomDisplay.hpp>
00011 #include <stdair/bom/TravelSolutionStruct.hpp>
00012 #include <stdair/bom/BookingRequestStruct.hpp>
00013 #include <stdair/service/Logger.hpp>
00014 #include <stdair/STDAIR_Service.hpp>
00015
00016 #include <simfqt/basic/BasConst_SIMFQT_Service.hpp>
00017 #include <simfqt/factory/FacSimfqtServiceContext.hpp>
00018 #include <simfqt/command/FareParser.hpp>
00019 #include <simfqt/command/FareQuoter.hpp>
00020 #include <simfqt/service/SIMFQT_ServiceContext.hpp>
00021 #include <simfqt/SIMFQT_Service.hpp>
00022
00023 namespace SIMFQT {
00024
00025
00026 SIMFQT_Service::SIMFQT_Service() : _simfqtServiceContext (NULL) {
00027 assert (false);
00028 }
00029
00030
00031 SIMFQT_Service::SIMFQT_Service (const SIMFQT_Service& iService) {
00032 assert (false);
00033 }
00034
00035
00036 SIMFQT_Service::SIMFQT_Service (const stdair::BasLogParams& iLogParams)
00037 : _simfqtServiceContext (NULL) {
00038
00039
00040 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00041 initStdAirService (iLogParams);
00042
00043
00044 initServiceContext();
00045
00046
00047
00048 const bool ownStdairService = true;
00049 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
00050
00051
00052 initSimfqtService();
00053 }
00054
00055
00056 SIMFQT_Service::SIMFQT_Service (const stdair::BasLogParams& iLogParams,
00057 const stdair::BasDBParams& iDBParams)
00058 : _simfqtServiceContext (NULL) {
00059
00060
00061 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00062 initStdAirService (iLogParams, iDBParams);
00063
00064
00065 initServiceContext();
00066
00067
00068
00069 const bool ownStdairService = true;
00070 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
00071
00072
00073 initSimfqtService();
00074 }
00075
00076
00077 SIMFQT_Service::
00078 SIMFQT_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
00079 : _simfqtServiceContext (NULL) {
00080
00081
00082 initServiceContext();
00083
00084
00085
00086 const bool doesNotOwnStdairService = false;
00087 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
00088
00089
00090 initSimfqtService();
00091 }
00092
00093
00094 SIMFQT_Service::~SIMFQT_Service() {
00095
00096 finalise();
00097 }
00098
00099
00100 void SIMFQT_Service::finalise() {
00101 assert (_simfqtServiceContext != NULL);
00102
00103 _simfqtServiceContext->reset();
00104 }
00105
00106
00107 void SIMFQT_Service::initServiceContext() {
00108
00109 SIMFQT_ServiceContext& lSIMFQT_ServiceContext =
00110 FacSimfqtServiceContext::instance().create();
00111 _simfqtServiceContext = &lSIMFQT_ServiceContext;
00112 }
00113
00114
00115 void SIMFQT_Service::
00116 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
00117 const bool iOwnStdairService) {
00118
00119
00120 assert (_simfqtServiceContext != NULL);
00121 SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
00122
00123
00124 lSIMFQT_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
00125 iOwnStdairService);
00126 }
00127
00128
00129 stdair::STDAIR_ServicePtr_T SIMFQT_Service::
00130 initStdAirService (const stdair::BasLogParams& iLogParams,
00131 const stdair::BasDBParams& iDBParams) {
00132
00139 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00140 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
00141 assert (lSTDAIR_Service_ptr != NULL);
00142
00143 return lSTDAIR_Service_ptr;
00144 }
00145
00146
00147 stdair::STDAIR_ServicePtr_T SIMFQT_Service::
00148 initStdAirService (const stdair::BasLogParams& iLogParams) {
00149
00156 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
00157 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
00158 assert (lSTDAIR_Service_ptr != NULL);
00159
00160 return lSTDAIR_Service_ptr;
00161 }
00162
00163
00164 void SIMFQT_Service::initSimfqtService() {
00165
00166
00167 }
00168
00169
00170 void SIMFQT_Service::
00171 parseAndLoad (const FareFilePath& iFareFilename) {
00172
00173
00174 assert (_simfqtServiceContext != NULL);
00175 SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
00176 stdair::STDAIR_Service& lSTDAIR_Service =
00177 lSIMFQT_ServiceContext.getSTDAIR_Service();
00178 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00179
00180
00181 FareParser::fareRuleGeneration (iFareFilename, lBomRoot);
00182 }
00183
00184
00185 void SIMFQT_Service::buildSampleBom() {
00186
00187
00188 if (_simfqtServiceContext == NULL) {
00189 throw stdair::NonInitialisedServiceException ("The SimFQT service "
00190 "has not been initialised");
00191 }
00192 assert (_simfqtServiceContext != NULL);
00193
00194
00195
00196 SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
00197 const bool doesOwnStdairService =
00198 lSIMFQT_ServiceContext.getOwnStdairServiceFlag();
00199
00200
00201 stdair::STDAIR_Service& lSTDAIR_Service =
00202 lSIMFQT_ServiceContext.getSTDAIR_Service();
00203
00208 if (doesOwnStdairService == true) {
00209
00210 lSTDAIR_Service.buildSampleBom();
00211 }
00212
00228 }
00229
00230
00231 stdair::BookingRequestStruct SIMFQT_Service::buildBookingRequest(const bool isForCRS) {
00232
00233
00234 if (_simfqtServiceContext == NULL) {
00235 throw stdair::NonInitialisedServiceException ("The Simfqt service has not "
00236 "been initialised");
00237 }
00238 assert (_simfqtServiceContext != NULL);
00239
00240 SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
00241
00242
00243 stdair::STDAIR_Service& lSTDAIR_Service =
00244 lSIMFQT_ServiceContext.getSTDAIR_Service();
00245
00246
00247 stdair::BookingRequestStruct oBookingRequest =
00248 lSTDAIR_Service.buildSampleBookingRequest (isForCRS);
00249
00250 return oBookingRequest;
00251 }
00252
00253
00254 void SIMFQT_Service::
00255 buildSampleTravelSolutions(stdair::TravelSolutionList_T& ioTravelSolutionList){
00256
00257
00258 if (_simfqtServiceContext == NULL) {
00259 throw stdair::NonInitialisedServiceException ("The Simfqt service has not "
00260 "been initialised");
00261 }
00262 assert (_simfqtServiceContext != NULL);
00263
00264 SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
00265
00266
00267 stdair::STDAIR_Service& lSTDAIR_Service =
00268 lSIMFQT_ServiceContext.getSTDAIR_Service();
00269
00270
00271 lSTDAIR_Service.buildSampleTravelSolutionForPricing (ioTravelSolutionList);
00272 }
00273
00274
00275
00276 std::string SIMFQT_Service::csvDisplay() const {
00277
00278
00279 if (_simfqtServiceContext == NULL) {
00280 throw stdair::NonInitialisedServiceException ("The SimFQT service "
00281 "has not been initialised");
00282 }
00283 assert (_simfqtServiceContext != NULL);
00284
00285 SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
00286
00287
00288 stdair::STDAIR_Service& lSTDAIR_Service =
00289 lSIMFQT_ServiceContext.getSTDAIR_Service();
00290
00291
00292
00293 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00294
00295
00296 std::ostringstream oCSVStr;
00297 stdair::BomDisplay::csvSimFQTAirRACDisplay (oCSVStr, lBomRoot);
00298 return oCSVStr.str();
00299 }
00300
00301
00302 std::string SIMFQT_Service::
00303 csvDisplay (const stdair::TravelSolutionList_T& ioTravelSolutionList) const {
00304
00305
00306 if (_simfqtServiceContext == NULL) {
00307 throw stdair::NonInitialisedServiceException ("The Simfqt service has not "
00308 "been initialised");
00309 }
00310 assert (_simfqtServiceContext != NULL);
00311
00312
00313 SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
00314
00315
00316 stdair::STDAIR_Service& lSTDAIR_Service =
00317 lSIMFQT_ServiceContext.getSTDAIR_Service();
00318
00319
00320 return lSTDAIR_Service.csvDisplay (ioTravelSolutionList);
00321 }
00322
00323
00324 std::string SIMFQT_Service::
00325 csvDisplay (const stdair::AirportCode_T& iOrigin,
00326 const stdair::AirportCode_T& iDestination,
00327 const stdair::Date_T& iDepartureDate) const {
00328
00329
00330 if (_simfqtServiceContext == NULL) {
00331 throw stdair::NonInitialisedServiceException ("The Simfqt service "
00332 "has not been initialised");
00333 }
00334 assert (_simfqtServiceContext != NULL);
00335
00336 SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
00337
00338
00339 stdair::STDAIR_Service& lSTDAIR_Service =
00340 lSIMFQT_ServiceContext.getSTDAIR_Service();
00341
00342
00343 return lSTDAIR_Service.csvDisplay (iOrigin, iDestination,
00344 iDepartureDate);
00345 }
00346
00347
00348 std::string SIMFQT_Service::list() const {
00349
00350
00351 if (_simfqtServiceContext == NULL) {
00352 throw stdair::NonInitialisedServiceException ("The Simfqt service "
00353 "has not been initialised");
00354 }
00355 assert (_simfqtServiceContext != NULL);
00356
00357 SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
00358
00359
00360 stdair::STDAIR_Service& lSTDAIR_Service =
00361 lSIMFQT_ServiceContext.getSTDAIR_Service();
00362
00363
00364 return lSTDAIR_Service.listAirportPairDateRange ();
00365 }
00366
00367
00368 bool SIMFQT_Service::
00369 check (const stdair::AirportCode_T& iOrigin,
00370 const stdair::AirportCode_T& iDestination,
00371 const stdair::Date_T& iDepartureDate) const {
00372 std::ostringstream oFlightListStr;
00373
00374 if (_simfqtServiceContext == NULL) {
00375 throw stdair::NonInitialisedServiceException ("The Simfqt service "
00376 "has not been initialised");
00377 }
00378 assert (_simfqtServiceContext != NULL);
00379 SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
00380
00381
00382 stdair::STDAIR_Service& lSTDAIR_Service =
00383 lSIMFQT_ServiceContext.getSTDAIR_Service();
00384
00385
00386 return lSTDAIR_Service.check (iOrigin, iDestination, iDepartureDate);
00387 }
00388
00389
00390 void SIMFQT_Service::
00391 quotePrices (const stdair::BookingRequestStruct& iBookingRequest,
00392 stdair::TravelSolutionList_T& ioTravelSolutionList) {
00393
00394
00395 if (_simfqtServiceContext == NULL) {
00396 throw stdair::NonInitialisedServiceException ("The SimFQT service "
00397 "has not been initialised");
00398 }
00399 assert (_simfqtServiceContext != NULL);
00400
00401 SIMFQT_ServiceContext& lSIMFQT_ServiceContext = *_simfqtServiceContext;
00402
00403
00404 stdair::STDAIR_Service& lSTDAIR_Service =
00405 lSIMFQT_ServiceContext.getSTDAIR_Service();
00406
00407
00408
00409 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
00410
00411
00412 stdair::BasChronometer lFareQuoteRetrievalChronometer;
00413 lFareQuoteRetrievalChronometer.start();
00414 FareQuoter::priceQuote (iBookingRequest, ioTravelSolutionList, lBomRoot);
00415
00416
00417 const double lFareQuoteRetrievalMeasure =
00418 lFareQuoteRetrievalChronometer.elapsed();
00419 STDAIR_LOG_DEBUG ("Fare Quote retrieving: " << lFareQuoteRetrievalMeasure
00420 << " - " << lSIMFQT_ServiceContext.display());
00421 }
00422
00423 }