mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
Issue #77 Break cyclic dependency between CDatastoreUtility CAircraftModelList by factoring out dependent functionality
This commit is contained in:
@@ -185,7 +185,7 @@ namespace BlackCore
|
|||||||
CAircraftModelList modelsSkipped;
|
CAircraftModelList modelsSkipped;
|
||||||
CStatusMessageList msgs;
|
CStatusMessageList msgs;
|
||||||
bool directWrite;
|
bool directWrite;
|
||||||
const bool sendingSuccessful = CDatastoreUtility::parseSwiftPublishResponse(responseData, modelsPublished, modelsSkipped, msgs, directWrite);
|
const bool sendingSuccessful = parseSwiftPublishResponse(responseData, modelsPublished, modelsSkipped, msgs, directWrite);
|
||||||
const int c = CDatabaseUtils::fillInMissingAircraftAndLiveryEntities(modelsPublished);
|
const int c = CDatabaseUtils::fillInMissingAircraftAndLiveryEntities(modelsPublished);
|
||||||
|
|
||||||
emit this->publishedModels(modelsPublished, modelsSkipped, msgs, sendingSuccessful, directWrite);
|
emit this->publishedModels(modelsPublished, modelsSkipped, msgs, sendingSuccessful, directWrite);
|
||||||
@@ -276,5 +276,84 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
return arrays;
|
return arrays;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CDatabaseWriter::parseSwiftPublishResponse(const QString &jsonResponse, CAircraftModelList &publishedModels, CAircraftModelList &skippedModels, CStatusMessageList &messages, bool &directWrite)
|
||||||
|
{
|
||||||
|
directWrite = false;
|
||||||
|
|
||||||
|
if (jsonResponse.isEmpty())
|
||||||
|
{
|
||||||
|
messages.push_back(CStatusMessage(static_cast<CDatabaseWriter *>(nullptr), CStatusMessage::SeverityError, u"Empty JSON data for published models"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonDocument jsonDoc(QJsonDocument::fromJson(jsonResponse.toUtf8()));
|
||||||
|
|
||||||
|
// array of messages only
|
||||||
|
if (jsonDoc.isArray())
|
||||||
|
{
|
||||||
|
const CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(jsonDoc.array()));
|
||||||
|
messages.push_back(msgs);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// no object -> most likely some fucked up HTML string with the PHP error
|
||||||
|
if (!jsonDoc.isObject())
|
||||||
|
{
|
||||||
|
const QString phpError(CNetworkUtils::removeHtmlPartsFromPhpErrorMessage(jsonResponse));
|
||||||
|
messages.push_back(CStatusMessage(static_cast<CDatabaseWriter *>(nullptr), CStatusMessage::SeverityError, phpError));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fully blown object
|
||||||
|
QJsonObject json(jsonDoc.object());
|
||||||
|
bool hasData = false;
|
||||||
|
if (json.contains("msgs"))
|
||||||
|
{
|
||||||
|
const QJsonValue msgJson(json.take("msgs"));
|
||||||
|
const CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(msgJson.toArray()));
|
||||||
|
if (!msgs.isEmpty())
|
||||||
|
{
|
||||||
|
messages.push_back(msgs);
|
||||||
|
hasData = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// direct write means models written, otherwise CRs
|
||||||
|
if (json.contains("directWrite"))
|
||||||
|
{
|
||||||
|
const QJsonValue dw(json.take("directWrite"));
|
||||||
|
directWrite = dw.toBool(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json.contains("publishedModels"))
|
||||||
|
{
|
||||||
|
const QJsonValue publishedJson(json.take("publishedModels"));
|
||||||
|
const CAircraftModelList published = CAircraftModelList::fromDatabaseJson(publishedJson.toArray(), "");
|
||||||
|
if (!published.isEmpty())
|
||||||
|
{
|
||||||
|
publishedModels.push_back(published);
|
||||||
|
hasData = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json.contains("skippedModels"))
|
||||||
|
{
|
||||||
|
const QJsonValue skippedJson(json.take("skippedModels"));
|
||||||
|
const CAircraftModelList skipped = CAircraftModelList::fromDatabaseJson(skippedJson.toArray(), "");
|
||||||
|
if (!skipped.isEmpty())
|
||||||
|
{
|
||||||
|
skippedModels.push_back(skipped);
|
||||||
|
hasData = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasData)
|
||||||
|
{
|
||||||
|
messages.push_back(CStatusMessage(static_cast<CDatabaseWriter *>(nullptr), CStatusMessage::SeverityError, u"Received response, but no JSON data"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasData;
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -104,6 +104,12 @@ namespace BlackCore
|
|||||||
|
|
||||||
//! Split data array
|
//! Split data array
|
||||||
static QList<QByteArray> splitData(const QByteArray &data, int size);
|
static QList<QByteArray> splitData(const QByteArray &data, int size);
|
||||||
|
|
||||||
|
//! Get data from a DB response
|
||||||
|
static bool parseSwiftPublishResponse(const QString &jsonResponse,
|
||||||
|
BlackMisc::Simulation::CAircraftModelList &publishedModels,
|
||||||
|
BlackMisc::Simulation::CAircraftModelList &skippedModels,
|
||||||
|
BlackMisc::CStatusMessageList &messages, bool &directWrite);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Db;
|
using namespace BlackMisc::Db;
|
||||||
using namespace BlackMisc::Simulation;
|
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Db;
|
using namespace BlackMisc::Db;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
using namespace BlackMisc::Simulation;
|
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Db;
|
using namespace BlackMisc::Db;
|
||||||
using namespace BlackMisc::Simulation;
|
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Db;
|
using namespace BlackMisc::Db;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
using namespace BlackMisc::Simulation;
|
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include "blackmisc/db/datastoreutility.h"
|
#include "blackmisc/db/datastoreutility.h"
|
||||||
#include "blackmisc/logcategories.h"
|
#include "blackmisc/logcategories.h"
|
||||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
|
||||||
#include "blackmisc/network/networkutils.h"
|
#include "blackmisc/network/networkutils.h"
|
||||||
#include "blackmisc/statusmessage.h"
|
#include "blackmisc/statusmessage.h"
|
||||||
#include "blackmisc/statusmessagelist.h"
|
#include "blackmisc/statusmessagelist.h"
|
||||||
@@ -21,7 +20,6 @@
|
|||||||
#include <QTimeZone>
|
#include <QTimeZone>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Simulation;
|
|
||||||
using namespace BlackMisc::Network;
|
using namespace BlackMisc::Network;
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
@@ -79,85 +77,6 @@ namespace BlackMisc
|
|||||||
return parseDateTimeStringOptimized(removeDateTimeSeparators(timestamp));
|
return parseDateTimeStringOptimized(removeDateTimeSeparators(timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDatastoreUtility::parseSwiftPublishResponse(const QString &jsonResponse, CAircraftModelList &publishedModels, CAircraftModelList &skippedModels, CStatusMessageList &messages, bool &directWrite)
|
|
||||||
{
|
|
||||||
directWrite = false;
|
|
||||||
|
|
||||||
if (jsonResponse.isEmpty())
|
|
||||||
{
|
|
||||||
messages.push_back(CStatusMessage(static_cast<CDatastoreUtility *>(nullptr), CStatusMessage::SeverityError, u"Empty JSON data for published models"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QJsonDocument jsonDoc(QJsonDocument::fromJson(jsonResponse.toUtf8()));
|
|
||||||
|
|
||||||
// array of messages only
|
|
||||||
if (jsonDoc.isArray())
|
|
||||||
{
|
|
||||||
const CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(jsonDoc.array()));
|
|
||||||
messages.push_back(msgs);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no object -> most likely some fucked up HTML string with the PHP error
|
|
||||||
if (!jsonDoc.isObject())
|
|
||||||
{
|
|
||||||
const QString phpError(CNetworkUtils::removeHtmlPartsFromPhpErrorMessage(jsonResponse));
|
|
||||||
messages.push_back(CStatusMessage(static_cast<CDatastoreUtility *>(nullptr), CStatusMessage::SeverityError, phpError));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// fully blown object
|
|
||||||
QJsonObject json(jsonDoc.object());
|
|
||||||
bool hasData = false;
|
|
||||||
if (json.contains("msgs"))
|
|
||||||
{
|
|
||||||
const QJsonValue msgJson(json.take("msgs"));
|
|
||||||
const CStatusMessageList msgs(CStatusMessageList::fromDatabaseJson(msgJson.toArray()));
|
|
||||||
if (!msgs.isEmpty())
|
|
||||||
{
|
|
||||||
messages.push_back(msgs);
|
|
||||||
hasData = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// direct write means models written, otherwise CRs
|
|
||||||
if (json.contains("directWrite"))
|
|
||||||
{
|
|
||||||
const QJsonValue dw(json.take("directWrite"));
|
|
||||||
directWrite = dw.toBool(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json.contains("publishedModels"))
|
|
||||||
{
|
|
||||||
const QJsonValue publishedJson(json.take("publishedModels"));
|
|
||||||
const CAircraftModelList published = CAircraftModelList::fromDatabaseJson(publishedJson.toArray(), "");
|
|
||||||
if (!published.isEmpty())
|
|
||||||
{
|
|
||||||
publishedModels.push_back(published);
|
|
||||||
hasData = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json.contains("skippedModels"))
|
|
||||||
{
|
|
||||||
const QJsonValue skippedJson(json.take("skippedModels"));
|
|
||||||
const CAircraftModelList skipped = CAircraftModelList::fromDatabaseJson(skippedJson.toArray(), "");
|
|
||||||
if (!skipped.isEmpty())
|
|
||||||
{
|
|
||||||
skippedModels.push_back(skipped);
|
|
||||||
hasData = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasData)
|
|
||||||
{
|
|
||||||
messages.push_back(CStatusMessage(static_cast<CDatastoreUtility *>(nullptr), CStatusMessage::SeverityError, u"Received response, but no JSON data"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasData;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CDatastoreUtility::parseAutoPublishResponse(const QString &jsonResponse, CStatusMessageList &messages)
|
bool CDatastoreUtility::parseAutoPublishResponse(const QString &jsonResponse, CStatusMessageList &messages)
|
||||||
{
|
{
|
||||||
if (jsonResponse.isEmpty())
|
if (jsonResponse.isEmpty())
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
class CStatusMessageList;
|
class CStatusMessageList;
|
||||||
|
|
||||||
namespace Simulation { class CAircraftModelList; }
|
|
||||||
namespace Db
|
namespace Db
|
||||||
{
|
{
|
||||||
/*!
|
/*!
|
||||||
@@ -51,12 +50,6 @@ namespace BlackMisc
|
|||||||
//! Parse a timestamp object
|
//! Parse a timestamp object
|
||||||
static QDateTime parseTimestamp(const QString ×tamp);
|
static QDateTime parseTimestamp(const QString ×tamp);
|
||||||
|
|
||||||
//! Get data from a DB response
|
|
||||||
static bool parseSwiftPublishResponse(const QString &jsonResponse,
|
|
||||||
Simulation::CAircraftModelList &publishedModels,
|
|
||||||
Simulation::CAircraftModelList &skippedModels,
|
|
||||||
CStatusMessageList &messages, bool &directWrite);
|
|
||||||
|
|
||||||
//! Auto publish response
|
//! Auto publish response
|
||||||
static bool parseAutoPublishResponse(const QString &jsonResponse, CStatusMessageList &messages);
|
static bool parseAutoPublishResponse(const QString &jsonResponse, CStatusMessageList &messages);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user