6#ifndef SWIFT_CORE_DB_DATABASEREADER_H
7#define SWIFT_CORE_DB_DATABASEREADER_H
12#include <QNetworkReply>
14#include <QReadWriteLock>
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;
66 bool isNewer(qint64 mSecsSinceEpoch)
const {
return m_lastModified.toMSecsSinceEpoch() > mSecsSinceEpoch; }
105 bool isSharedFile()
const;
117 QString getLoadTimeString()
const;
120 QString getLoadTimeStringWithStartedHint()
const;
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;
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;
205 swift::misc::network::CEntityFlags::Entity
220 virtual int getCacheCount(swift::misc::network::CEntityFlags::Entity entity)
const = 0;
228 virtual swift::misc::network::CEntityFlags::Entity
264 swift::misc::network::CEntityFlags::Entity
268 swift::misc::network::CEntityFlags::Entity
288 swift::misc::network::CEntityFlags::Entity whatToRead,
289 bool overrideNewer) = 0;
293 swift::misc::network::CEntityFlags::Entity whatToRead,
294 bool overrideNewer) = 0;
301 static void stringToDatastoreResponse(
const QString &jsonContent,
310 void dataRead(swift::misc::network::CEntityFlags::Entity entities,
323 qint64 current, qint64 max,
const QUrl &url);
354 swift::misc::network::CEntityFlags::Entity
359 void emitAndLogDataRead(swift::misc::network::CEntityFlags::Entity entity,
int number,
366 void logNoWorkingUrl(swift::misc::network::CEntityFlags::Entity entity);
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);
445 swift::misc::network::CEntityFlags::Entity entity,
457 virtual void read(swift::misc::network::CEntityFlags::Entity entities,
CThreadedReader(const CThreadedReader &)=delete
Copy constructor.
Details how to read a certain entity.
Value object encapsulating a list of reader configs.
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.
QDateTime getLatestSharedFileHeaderTimestamp(swift::misc::network::CEntityFlags::Entity entity) const
Header timestamp (last-modified) for shared file.
void emitAndLogDataRead(swift::misc::network::CEntityFlags::Entity entity, int number, const JsonDatastoreResponse &res)
Emit signal and log when data have been read.
swift::misc::network::CEntityFlags::Entity emitReadSignalPerSingleCachedEntity(swift::misc::network::CEntityFlags::Entity cachedEntities, bool onlyIfHasData)
Split into single entity and send dataRead signal.
HeaderResponse transformReplyIntoHeaderResponse(QNetworkReply *nwReply) const
Check if terminated or error, otherwise set header information.
static QString queryLatestTimestamp(const QDateTime &ts)
Latest timestamp query for DB.
QNetworkReply::NetworkError m_1stReplyStatus
Successful connection?
bool isSharedHeaderNewerThanCacheTimestamp(swift::misc::network::CEntityFlags::Entity entity) const
Is the file timestamp newer than cache timestamp?
swift::misc::db::CDbInfoList getSharedInfoObjects() const
Shared info list (latest data timestamps from DB web service).
virtual void cacheHasChanged(swift::misc::network::CEntityFlags::Entity entities)
Cache for given entity has changed.
void networkReplyProgress(int logId, qint64 current, qint64 max, const QUrl &url)
Network request progress.
bool hasSharedInfoObjects() const
Shared info objects available?
swift::misc::CStatusMessage::StatusSeverity m_severityNoWorkingUrl
severity of message if there is no working URL
void sharedFileHeaderRead(swift::misc::network::CEntityFlags::Entity entity, const QString &fileName, bool success)
Header of shared file read.
static QString dateTimeToDbLatestTs(const QDateTime &ts)
A newer than value understood by swift DB.
void setReplyStatus(QNetworkReply::NetworkError status, const QString &message="")
Feedback about connection status.
virtual swift::misc::network::CEntityFlags::Entity getEntitiesWithCacheCount() const =0
Entities already having data in cache.
static const QStringList & getLogCategories()
Log categories.
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.
QDateTime getLatestEntityTimestampFromSharedInfoObjects(swift::misc::network::CEntityFlags::Entity entity) const
Obtain latest object timestamp from shared info objects.
QReadWriteLock m_statusLock
Lock.
JsonDatastoreResponse transformReplyIntoDatastoreResponse(QNetworkReply *nwReply) const
Check if terminated or error, otherwise split into array of objects.
bool hasSharedFileHeader(const swift::misc::network::CEntityFlags::Entity entity) const
Header of shared file read (for single entity)?
QDateTime getLatestEntityTimestampFromDbInfoObjects(swift::misc::network::CEntityFlags::Entity entity) const
Obtain latest object timestamp from DB info objects.
void logNoWorkingUrl(swift::misc::network::CEntityFlags::Entity entity)
Log if no working URL exists, using m_noWorkingUrlSeverity.
bool supportsAnyOfEntities(swift::misc::network::CEntityFlags::Entity entities) const
Is any of the given entities supported here by this reader.
QString getSupportedEntitiesAsString() const
Supported entities as string.
void swiftDbDataRead(bool success)
DB have been read.
bool hasDbInfoObjects() const
DB info objects available?
swift::misc::network::CEntityFlags::Entity getEntitesWithNewerHeaderTimestamp(swift::misc::network::CEntityFlags::Entity entities) const
Those entities where the timestamp of the header is newer than the cache timestamp.
swift::misc::network::CEntityFlags::Entity getEntitesWithNewerSharedInfoObject(swift::misc::network::CEntityFlags::Entity entities) const
Those entities where the timestamp of a shared info object is newer than the cache timestamp.
CDatabaseReaderConfig getConfigForEntity(swift::misc::network::CEntityFlags::Entity entity) const
Config for given entity.
QMap< swift::misc::network::CEntityFlags::Entity, HeaderResponse > m_sharedFileResponses
file responses of the shared files
void receivedSharedFileHeader(QNetworkReply *nwReplyPtr)
Received a reply of a header for a shared file.
CDatabaseReader(QObject *owner, const CDatabaseReaderConfigList &config, const QString &name)
Constructor.
swift::misc::network::CEntityFlags::Entity maskBySupportedEntities(swift::misc::network::CEntityFlags::Entity entities) const
Mask by supported entities.
bool hasSharedFileHeaders(const swift::misc::network::CEntityFlags::Entity entities) const
Headers of shared file read (for single entity)?
bool overrideCacheFromFile(bool overrideNewerOnly, const QFileInfo &fileInfo, swift::misc::network::CEntityFlags::Entity entity, swift::misc::CStatusMessageList &msgs) const
Override cache from file.
virtual swift::misc::network::CUrl getDbServiceBaseUrl() const =0
Get the service URL, individual for each reader.
static const QString & parameterLatestTimestamp()
Name of latest timestamp.
static const swift::misc::network::CUrl & getDbUrl()
DB base URL.
swift::misc::db::CDbInfoList getDbInfoObjects() const
DB Info list (latest data timestamps from DB web service).
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.
void startReadFromBackendInBackgroundThread(swift::misc::network::CEntityFlags::Entity entities, swift::misc::db::CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan=QDateTime())
Start reading in own thread (without config/caching).
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.
swift::misc::network::CUrl getBaseUrl(swift::misc::db::CDbFlags::DataRetrievalModeFlag mode) const
Base URL for mode (either a shared or DB URL).
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.
bool setHeaderInfoPart(HeaderResponse &headerResponse, QNetworkReply *nwReply) const
Set the header part.
static bool isChangedUrl(const swift::misc::network::CUrl &oldUrl, const swift::misc::network::CUrl ¤tUrl)
Has URL been changed? Means we load from a different server.
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.
static QString fileNameForMode(swift::misc::network::CEntityFlags::Entity entity, swift::misc::db::CDbFlags::DataRetrievalModeFlag mode)
File name for given mode, either php service or shared file name.
virtual void synchronizeCaches(swift::misc::network::CEntityFlags::Entity entities)=0
Admit caches for given entities.
CDatabaseReader::JsonDatastoreResponse setStatusAndTransformReplyIntoDatastoreResponse(QNetworkReply *nwReply)
Check if terminated or error, otherwise split into array of objects.
bool m_1stReplyReceived
Successful connection?
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.
const QString & getStatusMessage() const
Status message (error message).
void logParseMessage(const QString &entity, int size, int msElapsed, const JsonDatastoreResponse &response) const
Parsing info message.
bool isSharedInfoObjectNewerThanCacheTimestamp(swift::misc::network::CEntityFlags::Entity entity) const
Is the shared info timestamp newer than cache timestamp?
bool hasCacheTimestampNewerThan(swift::misc::network::CEntityFlags::Entity entity, const QDateTime &threshold) const
Has entity a valid and newer timestamp.
void receivedSharedFileHeaderNonClosing(QNetworkReply *nwReplyPtr)
Received a reply of a header for a shared file.
const QObject * owner() const
Owner of the worker.
A sequence of log categories.
Streamable status message, e.g.
static constexpr auto SeverityError
Status severities.
swift::misc::StatusSeverity StatusSeverity
Status severities.
static constexpr 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.
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.
qint64 toMSecsSinceEpoch() const const
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.