6 #ifndef SWIFT_CORE_DB_DATABASEREADER_H
7 #define SWIFT_CORE_DB_DATABASEREADER_H
12 #include <QNetworkReply>
14 #include <QReadWriteLock>
32 class CLogCategoryList;
46 QDateTime m_lastModified;
47 int m_httpStatusCode = -1;
48 qulonglong m_contentLengthHeader = 0;
49 qint64 m_requestStarted = -1;
50 qint64 m_responseReceived = -1;
51 qint64 m_loadTimeMs = -1;
62 return m_lastModified.toMSecsSinceEpoch() > ts.toMSecsSinceEpoch();
66 bool isNewer(qint64 mSecsSinceEpoch)
const {
return m_lastModified.toMSecsSinceEpoch() > mSecsSinceEpoch; }
105 bool isSharedFile()
const;
117 QString getLoadTimeString()
const;
120 QString getLoadTimeStringWithStartedHint()
const;
126 void setValues(
const QNetworkReply *nwReply);
133 QJsonArray m_jsonArray;
134 int m_arraySize = -1;
135 int m_stringSize = 0;
136 bool m_restricted =
false;
140 bool isEmpty()
const {
return m_jsonArray.isEmpty(); }
143 bool isLoadedFromDb()
const;
158 void setJsonArray(
const QJsonArray &value);
164 QString toQString()
const;
167 operator QJsonArray()
const {
return m_jsonArray; }
172 void readInBackgroundThread(swift::misc::network::CEntityFlags::Entity entities,
const QDateTime &newerThan);
176 swift::misc::network::CEntityFlags::Entity
177 triggerLoadingDirectlyFromDb(swift::misc::network::CEntityFlags::Entity entities,
const QDateTime &newerThan);
181 swift::misc::network::CEntityFlags::Entity
182 triggerLoadingDirectlyFromSharedFiles(swift::misc::network::CEntityFlags::Entity entities,
183 bool checkCacheTsUpfront);
187 bool hasReceivedOkReply()
const;
192 bool hasReceivedOkReply(QString &message)
const;
196 bool hasReceivedFirstReply()
const;
202 QString getSupportedEntitiesAsString()
const;
205 swift::misc::network::CEntityFlags::Entity
206 maskBySupportedEntities(swift::misc::network::CEntityFlags::Entity entities)
const;
209 bool supportsAnyOfEntities(swift::misc::network::CEntityFlags::Entity entities)
const;
212 virtual QDateTime
getCacheTimestamp(swift::misc::network::CEntityFlags::Entity entity)
const = 0;
215 bool hasCacheTimestampNewerThan(swift::misc::network::CEntityFlags::Entity entity,
216 const QDateTime &threshold)
const;
220 virtual int getCacheCount(swift::misc::network::CEntityFlags::Entity entity)
const = 0;
228 virtual swift::misc::network::CEntityFlags::Entity
232 bool hasDbInfoObjects()
const;
235 bool hasSharedInfoObjects()
const;
238 bool hasSharedFileHeader(
const swift::misc::network::CEntityFlags::Entity entity)
const;
241 bool hasSharedFileHeaders(
const swift::misc::network::CEntityFlags::Entity entities)
const;
245 QDateTime getLatestEntityTimestampFromDbInfoObjects(swift::misc::network::CEntityFlags::Entity entity)
const;
250 getLatestEntityTimestampFromSharedInfoObjects(swift::misc::network::CEntityFlags::Entity entity)
const;
254 QDateTime getLatestSharedFileHeaderTimestamp(swift::misc::network::CEntityFlags::Entity entity)
const;
258 bool isSharedHeaderNewerThanCacheTimestamp(swift::misc::network::CEntityFlags::Entity entity)
const;
261 bool isSharedInfoObjectNewerThanCacheTimestamp(swift::misc::network::CEntityFlags::Entity entity)
const;
264 swift::misc::network::CEntityFlags::Entity
265 getEntitesWithNewerHeaderTimestamp(swift::misc::network::CEntityFlags::Entity entities)
const;
268 swift::misc::network::CEntityFlags::Entity
269 getEntitesWithNewerSharedInfoObject(swift::misc::network::CEntityFlags::Entity entities)
const;
272 const QString &getStatusMessage()
const;
288 swift::misc::network::CEntityFlags::Entity whatToRead,
289 bool overrideNewer) = 0;
293 swift::misc::network::CEntityFlags::Entity whatToRead,
294 bool overrideNewer) = 0;
297 static const QStringList &getLogCategories();
301 static void stringToDatastoreResponse(
const QString &jsonContent,
310 void dataRead(swift::misc::network::CEntityFlags::Entity entities,
323 qint64 current, qint64 max,
const QUrl &url);
328 bool m_1stReplyReceived =
false;
330 QNetworkReply::NetworkError m_1stReplyStatus = QNetworkReply::UnknownServerError;
354 swift::misc::network::CEntityFlags::Entity
355 emitReadSignalPerSingleCachedEntity(swift::misc::network::CEntityFlags::Entity cachedEntities,
359 void emitAndLogDataRead(swift::misc::network::CEntityFlags::Entity entity,
int number,
366 void logNoWorkingUrl(swift::misc::network::CEntityFlags::Entity entity);
375 static QString fileNameForMode(swift::misc::network::CEntityFlags::Entity entity,
379 static const QString ¶meterLatestTimestamp();
383 static QString dateTimeToDbLatestTs(
const QDateTime &ts);
386 static QString queryLatestTimestamp(
const QDateTime &ts);
394 virtual void admitCaches(swift::misc::network::CEntityFlags::Entity entities) = 0;
401 virtual bool hasChangedUrl(swift::misc::network::CEntityFlags::Entity entity,
406 virtual void cacheHasChanged(swift::misc::network::CEntityFlags::Entity entities);
415 void startReadFromBackendInBackgroundThread(swift::misc::network::CEntityFlags::Entity entities,
417 const QDateTime &newerThan = QDateTime());
420 void receivedSharedFileHeader(QNetworkReply *nwReplyPtr);
423 void receivedSharedFileHeaderNonClosing(QNetworkReply *nwReplyPtr);
429 HeaderResponse transformReplyIntoHeaderResponse(QNetworkReply *nwReply)
const;
432 bool setHeaderInfoPart(
HeaderResponse &headerResponse, QNetworkReply *nwReply)
const;
436 void setReplyStatus(QNetworkReply::NetworkError status,
const QString &message =
"");
440 void setReplyStatus(QNetworkReply *nwReply);
444 bool overrideCacheFromFile(
bool overrideNewerOnly,
const QFileInfo &fileInfo,
445 swift::misc::network::CEntityFlags::Entity entity,
449 void logParseMessage(
const QString &entity,
int size,
int msElapsed,
453 virtual void networkReplyProgress(
int logId, qint64 current, qint64 max,
const QUrl &url)
override;
457 virtual void read(swift::misc::network::CEntityFlags::Entity entities,
Support for threaded based reading and parsing tasks such as data files via http, or file system and ...
Details how to read a certain entity.
Value object encapsulating a list of reader configs.
Specialized version of threaded reader for DB data.
virtual QDateTime getCacheTimestamp(swift::misc::network::CEntityFlags::Entity entity) const =0
Get cache timestamp.
virtual bool hasChangedUrl(swift::misc::network::CEntityFlags::Entity entity, swift::misc::network::CUrl &oldUrlInfo, swift::misc::network::CUrl &newUrlInfo) const =0
Changed URL, means the cache values have been read from elsewhere.
virtual void admitCaches(swift::misc::network::CEntityFlags::Entity entities)=0
Admit caches for given entities.
void sharedFileHeaderRead(swift::misc::network::CEntityFlags::Entity entity, const QString &fileName, bool success)
Header of shared file read.
virtual swift::misc::network::CEntityFlags::Entity getEntitiesWithCacheCount() const =0
Entities already having data in cache.
virtual int getCacheCount(swift::misc::network::CEntityFlags::Entity entity) const =0
Cache`s number of entities.
void entityDownloadProgress(swift::misc::network::CEntityFlags::Entity entity, int logId, int progress, qint64 current, qint64 max, const QUrl &url)
Download progress for an entity.
QReadWriteLock m_statusLock
Lock.
void swiftDbDataRead(bool success)
DB have been read.
QMap< swift::misc::network::CEntityFlags::Entity, HeaderResponse > m_sharedFileResponses
file responses of the shared files
virtual swift::misc::network::CUrl getDbServiceBaseUrl() const =0
Get the service URL, individual for each reader.
virtual void read(swift::misc::network::CEntityFlags::Entity entities, swift::misc::db::CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan)=0
Read / re-read data file.
QString m_statusMessage
Returned status message from watchdog.
virtual bool readFromJsonFilesInBackground(const QString &dir, swift::misc::network::CEntityFlags::Entity whatToRead, bool overrideNewer)=0
Data read from local data.
virtual swift::misc::network::CEntityFlags::Entity getSupportedEntities() const =0
Supported entities by this reader.
void dataRead(swift::misc::network::CEntityFlags::Entity entities, swift::misc::network::CEntityFlags::ReadState state, int number, const QUrl &url)
Combined read signal.
virtual swift::misc::CStatusMessageList readFromJsonFiles(const QString &dir, swift::misc::network::CEntityFlags::Entity whatToRead, bool overrideNewer)=0
Data read from local data.
virtual swift::misc::network::CEntityFlags::Entity getEntitiesWithCacheTimestampNewerThan(const QDateTime &threshold) const =0
Entities already having data in cache (based on timestamp assumption)
CDatabaseReaderConfigList m_config
DB reder configuration.
swift::misc::CStatusMessageList initFromLocalResourceFiles(swift::misc::network::CEntityFlags::Entity entities, bool inBackground)
Init from local resource file.
virtual void invalidateCaches(swift::misc::network::CEntityFlags::Entity entities)=0
Invalidate the caches for given entities.
virtual void synchronizeCaches(swift::misc::network::CEntityFlags::Entity entities)=0
Admit caches for given entities.
void databaseReaderMessages(const swift::misc::CStatusMessageList &messages)
Database reader messages.
void setSeverityNoWorkingUrl(swift::misc::CStatusMessage::StatusSeverity s)
Severity used for log messages in case of no URLs.
Streamable status message, e.g.
bool isWarningOrAbove() const
Warning or above.
constexpr static auto SeverityError
Status severities.
StatusSeverity getSeverity() const
Message severity.
constexpr static auto SeverityWarning
Status severities.
Status messages, e.g. from Core -> GUI.
DataRetrievalModeFlag
Which data to read, requires corresponding readers.
Value object encapsulating a list of info objects.
QString toQString(bool i18n=false) const
Cast as QString.
ReadState
State of operation.
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
Classes interacting with the swift database (aka "datastore").
Free functions in swift::misc.
StatusSeverity
Status severities.
Response from our database (depending on JSON DB backend generates)
int getArraySize() const
Number of elements.
QJsonArray getJsonArray() const
Get the JSON array.
bool isRestricted() const
Incremental data, restricted by query?
bool isEmpty() const
Any data?
void setRestricted(bool restricted)
Mark as restricted.
void setStringSize(int size)
Set string size.
#define SWIFT_CORE_EXPORT
Export a class or function from the library.