mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
Ref T118, allow to just provide an id (from backend) and set the entity on swift side
* added getDistributorForDbKey * added fillInMissingAircraftAndLiveryEntities * fromDbJson function adjusted
This commit is contained in:
@@ -118,6 +118,45 @@ namespace BlackCore
|
||||
return CDatabaseUtils::consolidateModelsWithDbDataAllowsGuiRefresh(models, force, false);
|
||||
}
|
||||
|
||||
int CDatabaseUtils::fillInMissingAircraftAndLiveryEntities(CAircraftModelList &models)
|
||||
{
|
||||
// fill in those entities which have only an id (key), but no data yet
|
||||
int c = 0;
|
||||
for (CAircraftModel &model : models)
|
||||
{
|
||||
bool changed = false;
|
||||
if (model.getLivery().hasValidDbKey() && !model.getLivery().hasCompleteData())
|
||||
{
|
||||
const CLivery livery = sApp->getWebDataServices()->getLiveryForDbKey(model.getLivery().getDbKey());
|
||||
if (livery.isLoadedFromDb())
|
||||
{
|
||||
model.setLivery(livery);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (model.getAircraftIcaoCode().hasValidDbKey() && !model.getAircraftIcaoCode().hasCompleteData())
|
||||
{
|
||||
const CAircraftIcaoCode icao = sApp->getWebDataServices()->getAircraftIcaoCodeForDbKey(model.getAircraftIcaoCode().getDbKey());
|
||||
if (icao.isLoadedFromDb())
|
||||
{
|
||||
model.setAircraftIcaoCode(icao);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (model.getDistributor().hasValidDbKey() && !model.getDistributor().hasCompleteData())
|
||||
{
|
||||
const CDistributor distributor = sApp->getWebDataServices()->getDistributorForDbKey(model.getDistributor().getDbKey());
|
||||
if (distributor.isLoadedFromDb())
|
||||
{
|
||||
model.setDistributor(distributor);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed) { c++; }
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
CAircraftModelList CDatabaseUtils::consolidateModelsWithSimulatorModelsAllowsGuiRefresh(const CAircraftModelList &models, const CAircraftModelList &simulatorModels, bool processEvents)
|
||||
{
|
||||
if (models.isEmpty() || simulatorModels.isEmpty()) { return models; }
|
||||
|
||||
@@ -47,6 +47,9 @@ namespace BlackCore
|
||||
//! Consolidate models with DB data
|
||||
static int consolidateModelsWithDbData(BlackMisc::Simulation::CAircraftModelList &models, bool force);
|
||||
|
||||
//! Fill in missing data if only the id is provided, but no data
|
||||
static int fillInMissingAircraftAndLiveryEntities(BlackMisc::Simulation::CAircraftModelList &models);
|
||||
|
||||
//! Consolidate models with simulator model data (aka "models on disk")
|
||||
//! \remark kept here with the other consolidate functions, but actually DB independent
|
||||
static BlackMisc::Simulation::CAircraftModelList consolidateModelsWithSimulatorModelsAllowsGuiRefresh(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CAircraftModelList &simulatorModels, bool processEvents);
|
||||
|
||||
@@ -134,11 +134,13 @@ namespace BlackCore
|
||||
CStatusMessageList msgs;
|
||||
bool directWrite;
|
||||
const bool sendingSuccessful = CDatastoreUtility::parseSwiftPublishResponse(dataFileData, modelsPublished, modelsSkipped, msgs, directWrite);
|
||||
const int c = CDatabaseUtils::fillInMissingAircraftAndLiveryEntities(modelsPublished);
|
||||
emit this->publishedModels(modelsPublished, modelsSkipped, msgs, sendingSuccessful, directWrite);
|
||||
if (!modelsPublished.isEmpty())
|
||||
{
|
||||
emit this->publishedModelsSimplified(modelsPublished);
|
||||
}
|
||||
Q_UNUSED(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -85,6 +85,13 @@ namespace BlackCore
|
||||
return m_distributorCache.get();
|
||||
}
|
||||
|
||||
CDistributor CModelDataReader::getDistributorForDbKey(const QString &dbKey) const
|
||||
{
|
||||
if (dbKey.isEmpty()) { return CDistributor(); }
|
||||
const CDistributorList distributors(getDistributors());
|
||||
return distributors.findByKeyOrAlias(dbKey);
|
||||
}
|
||||
|
||||
CAircraftModelList CModelDataReader::getModels() const
|
||||
{
|
||||
return m_modelCache.get();
|
||||
|
||||
@@ -71,6 +71,10 @@ namespace BlackCore
|
||||
//! \threadsafe
|
||||
BlackMisc::Simulation::CDistributorList getDistributors() const;
|
||||
|
||||
//! Get distributor for id
|
||||
//! \threadsafe
|
||||
BlackMisc::Simulation::CDistributor getDistributorForDbKey(const QString &dbKey) const;
|
||||
|
||||
//! Get models
|
||||
//! \threadsafe
|
||||
BlackMisc::Simulation::CAircraftModelList getModels() const;
|
||||
|
||||
@@ -456,6 +456,12 @@ namespace BlackCore
|
||||
return 0;
|
||||
}
|
||||
|
||||
CDistributor CWebDataServices::getDistributorForDbKey(const QString &key) const
|
||||
{
|
||||
if (m_modelDataReader) { return m_modelDataReader->getDistributorForDbKey(key); }
|
||||
return CDistributor();
|
||||
}
|
||||
|
||||
CDistributor CWebDataServices::smartDistributorSelector(const CDistributor &distributor) const
|
||||
{
|
||||
if (m_modelDataReader) { return m_modelDataReader->smartDistributorSelector(distributor); }
|
||||
|
||||
@@ -162,6 +162,10 @@ namespace BlackCore
|
||||
//! \threadsafe
|
||||
int getDistributorsCount() const;
|
||||
|
||||
//! Distributor for key
|
||||
//! \threadsafe
|
||||
BlackMisc::Simulation::CDistributor getDistributorForDbKey(const QString &key) const;
|
||||
|
||||
//! Use distributor object to select the best complete distributor from DB
|
||||
//! \threadsafe
|
||||
BlackMisc::Simulation::CDistributor smartDistributorSelector(const BlackMisc::Simulation::CDistributor &distributor) const;
|
||||
|
||||
@@ -712,9 +712,36 @@ namespace BlackMisc
|
||||
const QString modelMode(json.value(prefix + "mode").toString());
|
||||
|
||||
const CSimulatorInfo simInfo = CSimulatorInfo::fromDatabaseJson(json, prefix);
|
||||
const CAircraftIcaoCode aircraftIcao(CAircraftIcaoCode::fromDatabaseJson(json, "ac_"));
|
||||
const CLivery livery(CLivery::fromDatabaseJson(json, "liv_"));
|
||||
const CDistributor distributor(CDistributor::fromDatabaseJson(json, "dist_"));
|
||||
CDistributor distributor(CDistributor::fromDatabaseJson(json, "dist_"));
|
||||
CAircraftIcaoCode aircraftIcao(CAircraftIcaoCode::fromDatabaseJson(json, "ac_"));
|
||||
CLivery livery(CLivery::fromDatabaseJson(json, "liv_"));
|
||||
|
||||
if (!aircraftIcao.isLoadedFromDb())
|
||||
{
|
||||
const int idAircraftIcao = json.value(prefix + "idaircrafticao").toInt(-1);
|
||||
if (idAircraftIcao >= 0)
|
||||
{
|
||||
aircraftIcao.setDbKey(idAircraftIcao);
|
||||
}
|
||||
}
|
||||
|
||||
if (!livery.isLoadedFromDb())
|
||||
{
|
||||
const int idLivery = json.value(prefix + "idlivery").toInt(-1);
|
||||
if (idLivery >= 0)
|
||||
{
|
||||
livery.setDbKey(idLivery);
|
||||
}
|
||||
}
|
||||
|
||||
if (!distributor.isLoadedFromDb())
|
||||
{
|
||||
const QString idDistributor = json.value(prefix + "iddistributor").toString();
|
||||
if (!idDistributor.isEmpty())
|
||||
{
|
||||
distributor.setDbKey(idDistributor);
|
||||
}
|
||||
}
|
||||
|
||||
CAircraftModel model(
|
||||
modelString, CAircraftModel::TypeDatabaseEntry, simInfo, modelName, modelDescription, aircraftIcao, livery
|
||||
|
||||
Reference in New Issue
Block a user