mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +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;
|
||||
CStatusMessageList msgs;
|
||||
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);
|
||||
|
||||
emit this->publishedModels(modelsPublished, modelsSkipped, msgs, sendingSuccessful, directWrite);
|
||||
@@ -276,5 +276,84 @@ namespace BlackCore
|
||||
}
|
||||
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
|
||||
|
||||
@@ -104,6 +104,12 @@ namespace BlackCore
|
||||
|
||||
//! Split data array
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user