6#include <QElapsedTimer>
8#include <QNetworkReply>
10#include <QStringBuilder>
18using namespace swift::misc::aviation;
19using namespace swift::misc::network;
20using namespace swift::misc::db;
45 bool overrideNewerOnly)
68 bool overrideNewerOnly)
70 const QDir directory(dir);
105 const int c = airports.
size();
115 ex,
this, QStringLiteral(
"Reading airports from '%1'").arg(fileName));
158 if (m_syncedAirportCache)
162 m_syncedAirportCache =
true;
163 m_airportCache.synchronize();
171 m_airportCache.admit();
186 oldUrlInfo = m_readerUrlCache.get();
198 void CAirportDataReader::parseAirportData(
QNetworkReply *nwReplyPtr)
208 const CDatabaseReader::JsonDatastoreResponse res =
210 const QUrl url = nwReply->
url();
212 if (res.hasErrorMessage())
223 if (res.isRestricted())
226 if (incrementalAirports.isEmpty())
252 const int size = airports.
size();
254 if (size > 0 && latestTimestamp < 0)
256 CLogMessage(
this).error(u
"No timestamp in airport list, setting to last modified value");
260 m_airportCache.set(airports, latestTimestamp);
267 const QDateTime &newerThan)
278 CUrl url = this->getAirportsUrl(mode);
294 void CAirportDataReader::baseUrlCacheChanged()
299 void CAirportDataReader::updateReaderUrl(
const CUrl &url)
301 const CUrl current = m_readerUrlCache.get();
306 const CStatusMessage m = m_readerUrlCache.set(url);
static void logInconsistentData(const swift::misc::CStatusMessage &msg, const char *funcInfo=nullptr)
Use this to log inconsistent data.
void threadAssertCheck() const
Make sure everything runs correctly in own thread.
QNetworkReply * getFromNetworkAndLog(const swift::misc::network::CUrl &url, const swift::misc::CSlot< void(QNetworkReply *)> &callback)
Get request from network, and log with m_urlReadLog.
bool doWorkCheck() const
Still enabled etc.?
qint64 lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const
When was reply last modified, -1 if N/A.
bool readFromJsonFilesInBackground(const QString &dir, swift::misc::network::CEntityFlags::Entity whatToRead, bool overrideNewerOnly)
Data read from local data.
swift::misc::network::CEntityFlags::Entity getSupportedEntities() const
Supported entities by this reader.
swift::misc::aviation::CAirport getAirportForIcaoDesignator(const QString &designator) const
Returns airport for designator (or default).
CAirportDataReader(QObject *parent, const CDatabaseReaderConfigList &config)
Constructor.
swift::misc::network::CUrl getDbServiceBaseUrl() const
Get the service URL, individual for each reader.
swift::misc::network::CEntityFlags::Entity getEntitiesWithCacheTimestampNewerThan(const QDateTime &threshold) const
Entities already having data in cache (based on timestamp assumption).
void invalidateCaches(swift::misc::network::CEntityFlags::Entity entities)
Invalidate the caches for given entities.
int getAirportsCount() const
Returns a list of all airports in the database.
swift::misc::aviation::CAirport getAirportForNameOrLocation(const QString &location) const
Get airports for location.
void synchronizeCaches(swift::misc::network::CEntityFlags::Entity entities)
Admit caches for given entities.
bool hasChangedUrl(swift::misc::network::CEntityFlags::Entity entity, swift::misc::network::CUrl &oldUrlInfo, swift::misc::network::CUrl &newUrlInfo) const
Changed URL, means the cache values have been read from elsewhere.
swift::misc::aviation::CAirportList getAirports() const
Returns a list of all airports in the database.
int getCacheCount(swift::misc::network::CEntityFlags::Entity entity) const
Cache`s number of entities.
swift::misc::CStatusMessageList readFromJsonFiles(const QString &dir, swift::misc::network::CEntityFlags::Entity whatToRead, bool overrideNewerOnly)
Data read from local data.
void admitCaches(swift::misc::network::CEntityFlags::Entity entities)
Admit caches for given entities.
QDateTime getCacheTimestamp(swift::misc::network::CEntityFlags::Entity entities) const
Get cache timestamp.
swift::misc::network::CEntityFlags::Entity getEntitiesWithCacheCount() const
Entities already having data in cache.
Value object encapsulating a list of reader configs.
void emitAndLogDataRead(swift::misc::network::CEntityFlags::Entity entity, int number, const JsonDatastoreResponse &res)
Emit signal and log when data have been read.
static QString queryLatestTimestamp(const QDateTime &ts)
Latest timestamp query for DB.
virtual void cacheHasChanged(swift::misc::network::CEntityFlags::Entity entities)
Cache for given entity has changed.
void logNoWorkingUrl(swift::misc::network::CEntityFlags::Entity entity)
Log if no working URL exists, using m_noWorkingUrlSeverity.
CDatabaseReader(QObject *owner, const CDatabaseReaderConfigList &config, const QString &name)
Constructor.
bool overrideCacheFromFile(bool overrideNewerOnly, const QFileInfo &fileInfo, swift::misc::network::CEntityFlags::Entity entity, swift::misc::CStatusMessageList &msgs) const
Override cache from file.
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.
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.
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.
CDatabaseReader::JsonDatastoreResponse setStatusAndTransformReplyIntoDatastoreResponse(QNetworkReply *nwReply)
Check if terminated or error, otherwise split into array of objects.
void logParseMessage(const QString &entity, int size, int msElapsed, const JsonDatastoreResponse &response) const
Parsing info message.
bool hasCacheTimestampNewerThan(swift::misc::network::CEntityFlags::Entity entity, const QDateTime &threshold) const
Has entity a valid and newer timestamp.
static QJsonObject readQJsonObjectFromDatabaseFile(const QString &filename)
QJsonObject from database JSON file (normally shared file).
static CDataCache * instance()
Return the singleton instance.
static QString appendFilePaths(const QString &path1, const QString &path2)
Append file paths.
Thrown when a convertFromJson method encounters an unrecoverable error in JSON data.
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
size_type size() const
Returns number of elements in the sequence.
void push_back(const T &value)
Appends an element at the end of the sequence.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
static CStatusMessage fromJsonException(const CJsonException &ex, const CLogCategoryList &categories, const QString &prefix)
Object from JSON exception message.
static constexpr auto SeverityInfo
Status severities.
bool isFailure() const
Operation considered unsuccessful.
Status messages, e.g. from Core -> GUI.
bool isFailure() const
Any message is marked as failure.
void clearAllValues(const QString &keyPrefix={})
Clear all values from the cache.
qint64 latestTimestampMsecsSinceEpoch() const
Latest timestamp.
Value object encapsulating information about an airpot.
Value object encapsulating information of airport ICAO data.
Value object for a list of airports.
static CAirportList fromDatabaseJson(const QJsonArray &array, CAirportList *inconsistent=nullptr)
From our DB JSON.
CAirport findFirstByIcao(const CAirportIcaoCode &icao) const
Find first station by callsign, if not return default.
CAirport findFirstByNameOrLocation(const QString &nameOrLocation) const
Find first by name or location, if not return default.
DataRetrievalModeFlag
Which data to read, requires corresponding readers.
@ DbReading
directly from DB
int replaceOrAddObjectsByKey(const CONTAINER &container)
Update or insert data (based on DB key).
QString dbKeysAsString(const QString &separator) const
The DB keys as string.
static CAirportList fromMultipleJsonFormats(const QJsonObject &jsonObject)
@ ReadStarted
reading has been started
@ ReadFinished
reading done
@ ReadParsing
parsing data
@ ReadFailed
reading failed
static QString entitiesToString(CEntityFlags::Entity entities, const QString &separator=", ")
Entities to string list.
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
bool isEmpty() const
Empty.
CUrl withAppendedPath(const QString &path) const
Append path.
void appendQuery(const QString &queryToAppend)
Append query.
Classes interacting with the swift database (aka "datastore").
Free functions in swift::misc.
qint64 toMSecsSinceEpoch() const const
QDateTime toUTC() const const
bool exists() const const
qint64 elapsed() const const
QString absoluteFilePath() const const
QDateTime birthTime() const const
bool exists(const QString &path)
bool isEmpty() const const
QObject * parent() const const
bool isEmpty() const const
QUrl fromLocalFile(const QString &localFile)
QString url(QUrl::FormattingOptions options) const const