OpenTREP Logo  0.07.7
C++ Open Travel Request Parsing Library
OPENTREP_ServiceContext.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <string>
7 #include <istream>
8 #include <ostream>
9 #include <sstream>
10 // OpenTrep
13 #include <opentrep/bom/World.hpp>
15 
16 namespace OPENTREP {
17 
37  // //////////////////////////////////////////////////////////////////////
38  void OPENTREP_ServiceContext::
39  updateXapianAndSQLDBConnectionWithDeploymentNumber() {
43  if (_sqlDBType == DBType::NODB) {
44  // Nothing more to be done here
45 
46  } else if (_sqlDBType == DBType::SQLITE3) {
47  std::ostringstream oStr;
48  oStr << _sqlDBConnectionStringWPfxDBName;
49  oStr << _deploymentNumber;
50  _sqlDBConnectionString = SQLDBConnectionString_T (oStr.str());
51 
52  } else if (_sqlDBType == DBType::MYSQL) {
61  const StringMap_T& lStrMap =
62  parseMySQLConnectionString (_sqlDBConnectionStringWPfxDBName);
63 
68  const SQLDBConnectionString_T& lSQLDBConnStr =
69  buildMySQLConnectionString (lStrMap, _deploymentNumber);
70 
71  // Store the newly formed SQL connection string
72  _sqlDBConnectionString = lSQLDBConnStr;
73  }
74 
78  std::ostringstream oStr;
79  oStr << _travelDBFilePathPrefix;
80  oStr << _deploymentNumber;
81  _travelDBFilePath = TravelDBFilePath_T (oStr.str());
82  }
83 
84  // //////////////////////////////////////////////////////////////////////
85  OPENTREP_ServiceContext::OPENTREP_ServiceContext()
86  : _world (NULL),
87  _porFilePath (DEFAULT_OPENTREP_POR_FILEPATH),
88  _deploymentNumber (DEFAULT_OPENTREP_DEPLOYMENT_NUMBER),
89  _travelDBFilePathPrefix (DEFAULT_OPENTREP_XAPIAN_DB_FILEPATH),
90  _travelDBFilePath (DEFAULT_OPENTREP_XAPIAN_DB_FILEPATH),
91  _sqlDBType (DEFAULT_OPENTREP_SQL_DB_TYPE),
92  _sqlDBConnectionStringWPfxDBName (DEFAULT_OPENTREP_SQLITE_DB_FILEPATH),
93  _sqlDBConnectionString (DEFAULT_OPENTREP_SQLITE_DB_FILEPATH),
94  _shouldIndexNonIATAPOR (DEFAULT_OPENTREP_INCLUDE_NONIATA_POR),
95  _shouldIndexPORInXapian (DEFAULT_OPENTREP_INDEX_IN_XAPIAN),
96  _shouldAddPORInSQLDB (DEFAULT_OPENTREP_ADD_IN_DB) {
97  assert (false);
98  }
99 
100  // //////////////////////////////////////////////////////////////////////
101  OPENTREP_ServiceContext::
102  OPENTREP_ServiceContext (const TravelDBFilePath_T& iTravelDBFilePath,
103  const DBType& iSQLDBType,
104  const SQLDBConnectionString_T& iSQLDBConnStr,
105  const DeploymentNumber_T& iDeploymentNumber)
106  : _world (NULL),
107  _porFilePath (DEFAULT_OPENTREP_POR_FILEPATH),
108  _deploymentNumber (iDeploymentNumber),
109  _travelDBFilePathPrefix (iTravelDBFilePath),
110  _travelDBFilePath (iTravelDBFilePath), _sqlDBType (iSQLDBType),
111  _sqlDBConnectionStringWPfxDBName (iSQLDBConnStr),
112  _sqlDBConnectionString (iSQLDBConnStr),
113  _shouldIndexNonIATAPOR (DEFAULT_OPENTREP_INCLUDE_NONIATA_POR),
114  _shouldIndexPORInXapian (DEFAULT_OPENTREP_INDEX_IN_XAPIAN),
115  _shouldAddPORInSQLDB (DEFAULT_OPENTREP_ADD_IN_DB) {
116  updateXapianAndSQLDBConnectionWithDeploymentNumber();
117  }
118 
119  // //////////////////////////////////////////////////////////////////////
120  OPENTREP_ServiceContext::
121  OPENTREP_ServiceContext (const PORFilePath_T& iPORFilePath,
122  const TravelDBFilePath_T& iTravelDBFilePath,
123  const DBType& iSQLDBType,
124  const SQLDBConnectionString_T& iSQLDBConnStr,
125  const DeploymentNumber_T& iDeploymentNumber,
126  const shouldIndexNonIATAPOR_T& iShouldIndexNonIATAPOR,
127  const shouldIndexPORInXapian_T& iShouldIdxPORInXapian,
128  const shouldAddPORInSQLDB_T& iShouldAddPORInSQLDB)
129  : _world (NULL), _porFilePath (iPORFilePath),
130  _deploymentNumber (iDeploymentNumber),
131  _travelDBFilePathPrefix (iTravelDBFilePath),
132  _travelDBFilePath (iTravelDBFilePath), _sqlDBType (iSQLDBType),
133  _sqlDBConnectionStringWPfxDBName (iSQLDBConnStr),
134  _sqlDBConnectionString (iSQLDBConnStr),
135  _shouldIndexNonIATAPOR (iShouldIndexNonIATAPOR),
136  _shouldIndexPORInXapian (iShouldIdxPORInXapian),
137  _shouldAddPORInSQLDB (iShouldAddPORInSQLDB) {
138  updateXapianAndSQLDBConnectionWithDeploymentNumber();
139  }
140 
141  // //////////////////////////////////////////////////////////////////////
142  OPENTREP_ServiceContext::~OPENTREP_ServiceContext() {
143  }
144 
145  // //////////////////////////////////////////////////////////////////////
147  assert (_world != NULL);
148  return *_world;
149  }
150 
151  // //////////////////////////////////////////////////////////////////////
152  const std::string OPENTREP_ServiceContext::shortDisplay() const {
153  std::ostringstream oStr;
154  oStr << "OPENTREP_ServiceContext: "
155  << "file-path of the POR file: " << _porFilePath
156  << "; deployment number/version: " << _deploymentNumber
157  << "; Directory prefix of Xapian index/database: "
158  << _travelDBFilePathPrefix
159  << "; Actual directory of Xapian index/database: " << _travelDBFilePath
160  << "; SQL database (" << _sqlDBType.describe()
161  << ") connection string with DB name prefix: "
162  << _sqlDBConnectionStringWPfxDBName
163  << "); Connection string with actual DB name: "
164  << _sqlDBConnectionString
165  << "; should include non-IATA POR: " << _shouldIndexNonIATAPOR
166  << "; should index POR in Xapian: " << _shouldIndexPORInXapian
167  << "; should insert POR into the SQL DB: " << _shouldAddPORInSQLDB
168  << std::endl;
169  return oStr.str();
170  }
171 
172  // //////////////////////////////////////////////////////////////////////
173  const std::string OPENTREP_ServiceContext::display() const {
174  std::ostringstream oStr;
175  oStr << shortDisplay();
176  if (_world != NULL) {
177  oStr << _world->display();
178  }
179  return oStr.str();
180  }
181 
182 }
OPENTREP::shouldIndexNonIATAPOR_T
bool shouldIndexNonIATAPOR_T
Definition: OPENTREP_Types.hpp:136
OPENTREP::DBType::MYSQL
@ MYSQL
Definition: DBType.hpp:22
OPENTREP::DBType::SQLITE3
@ SQLITE3
Definition: DBType.hpp:21
OPENTREP::buildMySQLConnectionString
SQLDBConnectionString_T buildMySQLConnectionString(const StringMap_T &iStringMap, const DeploymentNumber_T &iDeploymentNumber)
Definition: Utilities.cpp:215
OPENTREP::DBType::describe
const std::string describe() const
Definition: DBType.cpp:131
OPENTREP::StringMap_T
std::map< const std::string, std::string > StringMap_T
Definition: Utilities.hpp:43
OPENTREP::DBType::NODB
@ NODB
Definition: DBType.hpp:20
OPENTREP::OPENTREP_ServiceContext::display
const std::string display() const
Definition: OPENTREP_ServiceContext.cpp:173
OPENTREP::DEFAULT_OPENTREP_INDEX_IN_XAPIAN
const bool DEFAULT_OPENTREP_INDEX_IN_XAPIAN
OPENTREP::OPENTREP_ServiceContext::shortDisplay
const std::string shortDisplay() const
Definition: OPENTREP_ServiceContext.cpp:152
OPENTREP::DEFAULT_OPENTREP_INCLUDE_NONIATA_POR
const bool DEFAULT_OPENTREP_INCLUDE_NONIATA_POR
BasConst_OPENTREP_Service.hpp
OPENTREP::shouldAddPORInSQLDB_T
bool shouldAddPORInSQLDB_T
Definition: OPENTREP_Types.hpp:146
OPENTREP::DEFAULT_OPENTREP_SQLITE_DB_FILEPATH
const std::string DEFAULT_OPENTREP_SQLITE_DB_FILEPATH
OPENTREP
Definition: BasChronometer.cpp:10
OPENTREP::DEFAULT_OPENTREP_ADD_IN_DB
const bool DEFAULT_OPENTREP_ADD_IN_DB
OPENTREP_ServiceContext.hpp
OPENTREP::World
Definition: World.hpp:20
OPENTREP::World::display
std::string display() const
Definition: World.cpp:60
OPENTREP::DEFAULT_OPENTREP_POR_FILEPATH
const std::string DEFAULT_OPENTREP_POR_FILEPATH
OPENTREP::OPENTREP_ServiceContext::getWorldHandler
World & getWorldHandler() const
Definition: OPENTREP_ServiceContext.cpp:146
OPENTREP::DEFAULT_OPENTREP_SQL_DB_TYPE
const std::string DEFAULT_OPENTREP_SQL_DB_TYPE
OPENTREP::parseMySQLConnectionString
StringMap_T parseMySQLConnectionString(const SQLDBConnectionString_T &iSQLDBConnStr)
Definition: Utilities.cpp:107
World.hpp
OPENTREP::DeploymentNumber_T
unsigned short DeploymentNumber_T
Definition: OPENTREP_Types.hpp:108
OPENTREP::DEFAULT_OPENTREP_DEPLOYMENT_NUMBER
const unsigned short DEFAULT_OPENTREP_DEPLOYMENT_NUMBER
OPENTREP::shouldIndexPORInXapian_T
bool shouldIndexPORInXapian_T
Definition: OPENTREP_Types.hpp:141
OPENTREP::DEFAULT_OPENTREP_XAPIAN_DB_FILEPATH
const std::string DEFAULT_OPENTREP_XAPIAN_DB_FILEPATH
Utilities.hpp