8 #include <boost/date_time/gregorian/gregorian.hpp>
9 #include <boost/date_time/posix_time/ptime.hpp>
11 #include <soci/soci.h>
32 OPENTREP_Service (std::ostream& ioLogStream,
const PORFilePath_T& iPORFilepath,
40 : _opentrepServiceContext (NULL) {
41 init (ioLogStream, iPORFilepath, iTravelDBFilePath, iSQLDBType,
42 iSQLDBConnStr, iDeploymentNumber, iShouldIndexNonIATAPOR,
43 iShouldIndexPORInXapian, iShouldAddPORInSQLDB);
48 OPENTREP_Service (std::ostream& ioLogStream,
53 : _opentrepServiceContext (NULL) {
54 init (ioLogStream, iTravelDBFilePath, iSQLDBType, iSQLDBConnStr,
59 OPENTREP_Service::OPENTREP_Service() : _opentrepServiceContext (NULL) {
64 OPENTREP_Service::OPENTREP_Service (
const OPENTREP_Service& iService) {
76 std::ostream& ioLogOutputFile) {
81 SQLDBConnectionString_T
86 std::string oSQLDBConnStr =
87 static_cast<const std::string
> (iSQLDBConnStr);
96 void OPENTREP_Service::init (std::ostream& ioLogStream,
97 const TravelDBFilePath_T& iTravelDBFilePath,
98 const DBType& iSQLDBType,
99 const SQLDBConnectionString_T& iSQLDBConnStr,
105 const SQLDBConnectionString_T& lSQLDBConnStr =
109 OPENTREP_ServiceContext& lOPENTREP_ServiceContext =
111 iSQLDBType, lSQLDBConnStr,
113 _opentrepServiceContext = &lOPENTREP_ServiceContext;
117 lOPENTREP_ServiceContext.setWorld (lWorld);
121 void OPENTREP_Service::
122 init (std::ostream& ioLogStream,
123 const PORFilePath_T& iPORFilepath,
124 const TravelDBFilePath_T& iTravelDBFilePath,
125 const DBType& iSQLDBType,
126 const SQLDBConnectionString_T& iSQLDBConnStr,
135 const SQLDBConnectionString_T& lSQLDBConnStr =
139 OPENTREP_ServiceContext& lOPENTREP_ServiceContext =
142 iSQLDBType, lSQLDBConnStr,
144 iShouldIndexNonIATAPOR,
145 iShouldIndexPORInXapian,
146 iShouldAddPORInSQLDB);
147 _opentrepServiceContext = &lOPENTREP_ServiceContext;
151 lOPENTREP_ServiceContext.setWorld (lWorld);
155 void OPENTREP_Service::finalise() {
160 if (_opentrepServiceContext == NULL) {
164 assert (_opentrepServiceContext != NULL);
179 lSQLDBConnectionString);
188 if (_opentrepServiceContext == NULL) {
192 assert (_opentrepServiceContext != NULL);
201 oNbOfEntries = XapianIndexManager::getSize (lTravelDBFilePath);
202 const double lIndexSizeMeasure = lIndexSizeChronometer.
elapsed();
206 << lIndexSizeMeasure <<
" - "
207 << lOPENTREP_ServiceContext.
display());
218 if (_opentrepServiceContext == NULL) {
222 assert (_opentrepServiceContext != NULL);
231 oNbOfMatches = XapianIndexManager::drawRandomLocations (lTravelDBFilePath,
234 const double lRandomGetMeasure = lRandomGetChronometer.
elapsed();
238 << lRandomGetMeasure <<
" - "
239 << lOPENTREP_ServiceContext.
display());
246 bool oCreationSuccessful =
true;
248 if (_opentrepServiceContext == NULL) {
252 assert (_opentrepServiceContext != NULL);
263 <<
"Hence nothing is done at that stage. "
264 <<
" - " << lOPENTREP_ServiceContext.
display());
265 return oCreationSuccessful;
278 lDBCreationChronometer.
start();
282 oCreationSuccessful =
286 const double lDBCreationMeasure = lDBCreationChronometer.
elapsed();
290 <<
" - " << lOPENTREP_ServiceContext.
display());
292 return oCreationSuccessful;
298 if (_opentrepServiceContext == NULL) {
302 assert (_opentrepServiceContext != NULL);
310 << lOPENTREP_ServiceContext.
display());
315 if (_opentrepServiceContext == NULL) {
319 assert (_opentrepServiceContext != NULL);
330 <<
"Hence nothing is done at that stage. "
331 <<
" - " << lOPENTREP_ServiceContext.
display());
341 lDBCreationChronometer.
start();
344 soci::session* lSociSession_ptr =
346 assert (lSociSession_ptr != NULL);
347 soci::session& lSociSession = *lSociSession_ptr;
356 const double lDBCreationMeasure = lDBCreationChronometer.
elapsed();
360 <<
" - " << lOPENTREP_ServiceContext.
display());
365 if (_opentrepServiceContext == NULL) {
369 assert (_opentrepServiceContext != NULL);
380 <<
"Hence nothing is done at that stage. "
381 <<
" - " << lOPENTREP_ServiceContext.
display());
391 lDBCreationChronometer.
start();
394 soci::session* lSociSession_ptr =
396 assert (lSociSession_ptr != NULL);
397 soci::session& lSociSession = *lSociSession_ptr;
406 const double lDBCreationMeasure = lDBCreationChronometer.
elapsed();
410 << lDBCreationMeasure <<
" - "
411 << lOPENTREP_ServiceContext.
display());
418 if (_opentrepServiceContext == NULL) {
422 assert (_opentrepServiceContext != NULL);
439 << oDeploymentNumber <<
" - "
440 << lOPENTREP_ServiceContext.
display());
442 return oDeploymentNumber;
450 if (_opentrepServiceContext == NULL) {
454 assert (_opentrepServiceContext != NULL);
458 oShouldIndexNonIATAPOR =
462 oShouldIndexNonIATAPOR = !(oShouldIndexNonIATAPOR);
469 << oShouldIndexNonIATAPOR <<
" - "
470 << lOPENTREP_ServiceContext.
display());
472 return oShouldIndexNonIATAPOR;
480 if (_opentrepServiceContext == NULL) {
484 assert (_opentrepServiceContext != NULL);
488 oShouldIndexPORInXapian =
492 oShouldIndexPORInXapian = !(oShouldIndexPORInXapian);
495 lOPENTREP_ServiceContext.
496 setShouldIndexPORInXapianFlag (oShouldIndexPORInXapian);
500 << oShouldIndexPORInXapian <<
" - "
501 << lOPENTREP_ServiceContext.
display());
503 return oShouldIndexPORInXapian;
511 if (_opentrepServiceContext == NULL) {
515 assert (_opentrepServiceContext != NULL);
519 oShouldAddPORInSQLDB =
523 oShouldAddPORInSQLDB = !(oShouldAddPORInSQLDB);
530 << oShouldAddPORInSQLDB <<
" - "
531 << lOPENTREP_ServiceContext.
display());
533 return oShouldAddPORInSQLDB;
540 if (_opentrepServiceContext == NULL) {
544 assert (_opentrepServiceContext != NULL);
556 lDBListChronometer.
start();
559 soci::session* lSociSession_ptr =
561 assert (lSociSession_ptr != NULL);
562 soci::session& lSociSession = *lSociSession_ptr;
571 const double lDBListMeasure = lDBListChronometer.
elapsed();
575 <<
" - " << lOPENTREP_ServiceContext.
display());
587 if (_opentrepServiceContext == NULL) {
591 assert (_opentrepServiceContext != NULL);
603 lDBListChronometer.
start();
606 soci::session* lSociSession_ptr =
608 assert (lSociSession_ptr != NULL);
609 soci::session& lSociSession = *lSociSession_ptr;
612 const bool lSeveralEntries =
false;
614 ioLocationList, lSeveralEntries);
620 const double lDBListMeasure = lDBListChronometer.
elapsed();
624 <<
" - " << lOPENTREP_ServiceContext.
display());
636 if (_opentrepServiceContext == NULL) {
640 assert (_opentrepServiceContext != NULL);
652 lDBListChronometer.
start();
655 soci::session* lSociSession_ptr =
657 assert (lSociSession_ptr != NULL);
658 soci::session& lSociSession = *lSociSession_ptr;
668 const double lDBListMeasure = lDBListChronometer.
elapsed();
672 <<
" - " << lOPENTREP_ServiceContext.
display());
684 if (_opentrepServiceContext == NULL) {
688 assert (_opentrepServiceContext != NULL);
700 lDBListChronometer.
start();
703 soci::session* lSociSession_ptr =
705 assert (lSociSession_ptr != NULL);
706 soci::session& lSociSession = *lSociSession_ptr;
716 const double lDBListMeasure = lDBListChronometer.
elapsed();
720 <<
" - " << lOPENTREP_ServiceContext.
display());
732 if (_opentrepServiceContext == NULL) {
736 assert (_opentrepServiceContext != NULL);
748 lDBListChronometer.
start();
751 soci::session* lSociSession_ptr =
753 assert (lSociSession_ptr != NULL);
754 soci::session& lSociSession = *lSociSession_ptr;
764 const double lDBListMeasure = lDBListChronometer.
elapsed();
768 <<
" - " << lOPENTREP_ServiceContext.
display());
779 if (_opentrepServiceContext == NULL) {
783 assert (_opentrepServiceContext != NULL);
795 lDBListChronometer.
start();
798 soci::session* lSociSession_ptr =
800 assert (lSociSession_ptr != NULL);
801 soci::session& lSociSession = *lSociSession_ptr;
811 const double lDBListMeasure = lDBListChronometer.
elapsed();
815 <<
" - " << lOPENTREP_ServiceContext.
display());
827 if (_opentrepServiceContext == NULL) {
831 assert (_opentrepServiceContext != NULL);
843 lDBListChronometer.
start();
846 soci::session* lSociSession_ptr =
848 assert (lSociSession_ptr != NULL);
849 soci::session& lSociSession = *lSociSession_ptr;
859 const double lDBListMeasure = lDBListChronometer.
elapsed();
863 <<
" - " << lOPENTREP_ServiceContext.
display());
873 if (_opentrepServiceContext == NULL) {
877 assert (_opentrepServiceContext != NULL);
912 lInsertIntoXapianAndSQLDBChronometer.
start();
913 oNbOfEntries = IndexBuilder::buildSearchIndex (lPORFilePath,
916 lSQLDBConnectionString,
918 lShouldIndexPORInXapian,
919 lShouldAddPORInSQLDB,
921 const double lInsertIntoXapianAndSQLDBMeasure =
922 lInsertIntoXapianAndSQLDBChronometer.
elapsed();
926 << lInsertIntoXapianAndSQLDBMeasure <<
" - "
927 << lOPENTREP_ServiceContext.
display());
939 if (_opentrepServiceContext == NULL) {
943 assert (_opentrepServiceContext != NULL);
951 boost::posix_time::ptime lNowDateTime =
952 boost::posix_time::second_clock::local_time();
957 <<
"==================================================="
959 << lNowDateTime <<
" - Match query '" << iTravelQuery
960 <<
"' on Xapian database (index)");
963 if (iTravelQuery.empty() ==
true) {
964 std::ostringstream errorStr;
965 errorStr <<
"The travel query is empty.";
983 lRequestInterpreterChronometer.
start();
985 RequestInterpreter::interpretTravelRequest (lTravelDBFilePath,
986 lSQLDBType, lSQLDBConnString,
988 ioLocationList, ioWordList,
990 const double lRequestInterpreterMeasure =
991 lRequestInterpreterChronometer.
elapsed();
995 << lRequestInterpreterMeasure <<
" - "
996 << lOPENTREP_ServiceContext.
display());
NbOfDBEntries_T getIndexSize()
Structure allowing measuring the time elapsed between two events.
#define OPENTREP_LOG_ERROR(iToBeLogged)
const unsigned short DEFAULT_OPENTREP_DEPLOYMENT_NUMBER
#define OPENTREP_LOG_DEBUG(iToBeLogged)
const shouldIndexNonIATAPOR_T & getShouldIncludeAllPORFlag() const
void setSQLDBConnectionString(const std::string &iSQLDBConnStr)
void setSQLDBConnectString(const SQLDBConnectionString_T &)
unsigned int GeonamesID_T
unsigned short NbOfMatches_T
const TravelDBFilePath_T & getTravelDBFilePath() const
const PORFilePath_T & getPORFilePath() const
const std::string DEFAULT_OPENTREP_MYSQL_CONN_STRING
Class holding the context of the OpenTrep services.
void setShouldIncludeAllPORFlag(const shouldIndexNonIATAPOR_T &iShouldIndexNonIATAPOR)
bool shouldIndexNonIATAPOR_T
OPENTREP::shouldIndexPORInXapian_T toggleShouldIndexPORInXapianFlag()
const std::string DEFAULT_OPENTREP_SQLITE_DB_FILEPATH
const OTransliterator & getTransliterator() const
NbOfDBEntries_T insertIntoDBAndXapian()
static NbOfDBEntries_T getPORByFAACode(soci::session &, const FAACode_T &, LocationList_T &)
void createSQLDBIndexes()
static FacWorld & instance()
void setLogParameters(const LOG::EN_LogLevel iLogLevel, std::ostream &ioLogStream)
const shouldAddPORInSQLDB_T & getShouldAddPORInSQLDB() const
const SQLDBConnectionString_T & getSQLDBConnectionString() const
unsigned int NbOfDBEntries_T
NbOfMatches_T listByIataCode(const IATACode_T &, LocationList_T &)
static bool createSQLDBUser(const DBType &, const SQLDBConnectionString_T &, const DeploymentNumber_T &)
void setShouldAddPORInSQLDB(const shouldAddPORInSQLDB_T &iShouldAddPORInSQLDB)
std::list< Word_T > WordList_T
NbOfMatches_T listByFaaCode(const FAACode_T &, LocationList_T &)
NbOfDBEntries_T getNbOfPORFromDB()
static void createSQLDBTables(soci::session &)
NbOfMatches_T listByIcaoCode(const ICAOCode_T &, LocationList_T &)
static void terminateSQLDBSession(const DBType &, const SQLDBConnectionString_T &, soci::session &)
const std::string display() const
static FacOpenTrepServiceContext & instance()
static NbOfDBEntries_T getPORByUICCode(soci::session &, const UICCode_T &, LocationList_T &)
const shouldIndexPORInXapian_T & getShouldIndexPORInXapianFlag() const
NbOfMatches_T drawRandomLocations(const NbOfMatches_T &iNbOfDraws, LocationList_T &)
Enumeration of database types.
static NbOfDBEntries_T getPORByIATACode(soci::session &, const IATACode_T &, LocationList_T &, const bool iUniqueEntry)
static NbOfDBEntries_T displayCount(soci::session &)
const DBType & getSQLDBType() const
std::list< Location > LocationList_T
NbOfMatches_T listByUICCode(const UICCode_T &, LocationList_T &)
static NbOfDBEntries_T getPORByUNLOCode(soci::session &, const UNLOCode_T &, LocationList_T &)
NbOfMatches_T interpretTravelRequest(const std::string &iTravelQuery, LocationList_T &, WordList_T &)
OPENTREP::shouldAddPORInSQLDB_T toggleShouldAddPORInSQLDBFlag()
bool shouldAddPORInSQLDB_T
bool shouldIndexPORInXapian_T
std::pair< const PORFilePath_T, const DBFilePathPair_T > FilePathSet_T
static Logger & instance()
OPENTREP_ServiceContext & create(const TravelDBFilePath_T &, const DBType &, const SQLDBConnectionString_T &, const DeploymentNumber_T &)
static NbOfDBEntries_T getPORByGeonameID(soci::session &, const GeonamesID_T &, LocationList_T &)
NbOfMatches_T listByGeonameID(const GeonamesID_T &, LocationList_T &)
const DeploymentNumber_T & getDeploymentNumber() const
OPENTREP::DeploymentNumber_T toggleDeploymentNumber()
FilePathSet_T getFilePaths() const
SQLDBConnectionString_T getSQLConnStr(const DBType &iSQLDBType, const SQLDBConnectionString_T &iSQLDBConnStr)
OPENTREP::shouldIndexNonIATAPOR_T toggleShouldIncludeAllPORFlag()
static NbOfDBEntries_T getPORByICAOCode(soci::session &, const ICAOCode_T &, LocationList_T &)
void setDeploymentNumber(const DeploymentNumber_T &iDeploymentNumber)
static void createSQLDBIndexes(soci::session &)
static soci::session * initSQLDBSession(const DBType &, const SQLDBConnectionString_T &)
void logInit(const LOG::EN_LogLevel iLogLevel, std::ostream &ioLogOutputFile)
unsigned short DeploymentNumber_T
NbOfMatches_T listByUNLOCode(const UNLOCode_T &, LocationList_T &)
const unsigned short DEFAULT_OPENTREP_DEPLOYMENT_NUMBER_SIZE
std::pair< const TravelDBFilePath_T, const SQLDBConnectionString_T > DBFilePathPair_T