mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
refs #755, validation also for "distributors from DB"
* validation now in webdataservices (so it can check against DB data) * utility functions
This commit is contained in:
committed by
Roland Winklmeier
parent
610dba2028
commit
0846a8773a
@@ -340,7 +340,7 @@ namespace BlackMisc
|
||||
if (distributors.isEmpty()) { return false; }
|
||||
bool found = false;
|
||||
const int noDistributorOrder = distributors.size();
|
||||
if (this->hasDistributor())
|
||||
if (this->hasDbDistributor())
|
||||
{
|
||||
const CDistributor d = distributors.findByKeyOrAlias(this->m_distributor.getDbKey());
|
||||
if (d.hasValidDbKey())
|
||||
@@ -360,22 +360,27 @@ namespace BlackMisc
|
||||
return found;
|
||||
}
|
||||
|
||||
bool CAircraftModel::hasDistributor() const
|
||||
bool CAircraftModel::hasDbDistributor() const
|
||||
{
|
||||
return this->m_distributor.hasValidDbKey();
|
||||
return this->m_distributor.isLoadedFromDb();
|
||||
}
|
||||
|
||||
bool CAircraftModel::matchesDistributor(const CDistributor &distributor) const
|
||||
bool CAircraftModel::hasDistributor() const
|
||||
{
|
||||
if (!distributor.hasValidDbKey()) { return false; }
|
||||
if (!this->hasDistributor()) { return false; }
|
||||
return this->m_distributor.hasValidDbKey(); // key is valid, but not guaranteed from DB
|
||||
}
|
||||
|
||||
bool CAircraftModel::matchesDbDistributor(const CDistributor &distributor) const
|
||||
{
|
||||
if (!distributor.isLoadedFromDb()) { return false; }
|
||||
if (!this->hasDbDistributor()) { return false; }
|
||||
return this->m_distributor.getDbKey() == distributor.getDbKey();
|
||||
}
|
||||
|
||||
bool CAircraftModel::matchesAnyDistributor(const CDistributorList &distributors) const
|
||||
bool CAircraftModel::matchesAnyDbDistributor(const CDistributorList &distributors) const
|
||||
{
|
||||
if (distributors.isEmpty()) { return false; }
|
||||
if (!this->hasDistributor()) { return false; }
|
||||
if (!this->hasDbDistributor()) { return false; }
|
||||
return distributors.matchesAnyKeyOrAlias(this->m_distributor.getDbKey());
|
||||
}
|
||||
|
||||
|
||||
@@ -222,14 +222,17 @@ namespace BlackMisc
|
||||
//! Update distributor`s order attribute
|
||||
bool setDistributorOrder(const CDistributorList &distributors);
|
||||
|
||||
//! Distributor
|
||||
//! Distributor loaded from DB
|
||||
bool hasDbDistributor() const;
|
||||
|
||||
//! Distributor, but not necessarily loaded from DB
|
||||
bool hasDistributor() const;
|
||||
|
||||
//! By distributor
|
||||
bool matchesDistributor(const CDistributor &distributor) const;
|
||||
bool matchesDbDistributor(const CDistributor &distributor) const;
|
||||
|
||||
//! By distributor
|
||||
bool matchesAnyDistributor(const CDistributorList &distributors) const;
|
||||
bool matchesAnyDbDistributor(const CDistributorList &distributors) const;
|
||||
|
||||
//! Name
|
||||
const QString &getName() const { return this->m_name; }
|
||||
|
||||
@@ -243,7 +243,7 @@ namespace BlackMisc
|
||||
if (distributors.isEmpty()) { return CAircraftModelList(); }
|
||||
return this->findBy([ = ](const CAircraftModel & model)
|
||||
{
|
||||
return model.matchesAnyDistributor(distributors);
|
||||
return model.matchesAnyDbDistributor(distributors);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -565,6 +565,37 @@ namespace BlackMisc
|
||||
return msgs;
|
||||
}
|
||||
|
||||
CStatusMessageList CAircraftModelList::validateDistributors(const CDistributorList &distributors, CAircraftModelList &validModels, CAircraftModelList &invalidModels) const
|
||||
{
|
||||
CStatusMessageList msgs;
|
||||
CDistributorList distributorsFromDb(distributors);
|
||||
distributorsFromDb.removeIfNotLoadedFromDb();
|
||||
|
||||
// Any DB distributors?
|
||||
if (distributorsFromDb.isEmpty())
|
||||
{
|
||||
const CStatusMessage msg = CStatusMessage(this).validationError("No DB distributors for validation");
|
||||
msgs.push_back(msg);
|
||||
invalidModels.push_back(*this);
|
||||
return msgs;
|
||||
}
|
||||
|
||||
for (const CAircraftModel &model : *this)
|
||||
{
|
||||
if (model.hasDbDistributor() || model.matchesAnyDbDistributor(distributorsFromDb))
|
||||
{
|
||||
validModels.push_back(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
const CStatusMessage msg = CStatusMessage(this).validationError("No valid distributor for '%1', was '%2'") << model.getModelString() << model.getDistributor().getDbKey();
|
||||
msgs.push_back(msg);
|
||||
invalidModels.push_back(model);
|
||||
}
|
||||
}
|
||||
return msgs;
|
||||
}
|
||||
|
||||
QJsonArray CAircraftModelList::toDatabaseJson() const
|
||||
{
|
||||
QJsonArray array;
|
||||
|
||||
@@ -204,6 +204,9 @@ namespace BlackMisc
|
||||
//! Validate for publishing
|
||||
CStatusMessageList validateForPublishing(CAircraftModelList &validModels, CAircraftModelList &invalidModels) const;
|
||||
|
||||
//! Validate distributors
|
||||
CStatusMessageList validateDistributors(const BlackMisc::Simulation::CDistributorList &distributors, CAircraftModelList &validModels, CAircraftModelList &invalidModels) const;
|
||||
|
||||
//! To database JSON
|
||||
QJsonArray toDatabaseJson() const;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace BlackMisc
|
||||
|
||||
CDistributor CDistributorList::findByModelData(const CAircraftModel &model) const
|
||||
{
|
||||
// some stuipd hardcoded resolutions
|
||||
// some stuipd hardcoded resolutions for distributors
|
||||
if (model.getDistributor().hasValidDbKey()) { return model.getDistributor(); }
|
||||
if (model.getModelString().startsWith("WOA", Qt::CaseInsensitive)) { return this->findByKeyOrAlias("WOAI"); }
|
||||
if (model.getDescription().contains("WOA", Qt::CaseInsensitive)) { return this->findByKeyOrAlias("WOAI"); }
|
||||
@@ -114,5 +114,15 @@ namespace BlackMisc
|
||||
}
|
||||
return distributors;
|
||||
}
|
||||
|
||||
bool CDistributorList::isCompletelyFromDb() const
|
||||
{
|
||||
return !this->contains(&CDistributor::isLoadedFromDb, false);
|
||||
}
|
||||
|
||||
int CDistributorList::removeIfNotLoadedFromDb()
|
||||
{
|
||||
return this->removeIf(&CDistributor::isLoadedFromDb, false);
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -67,6 +67,12 @@ namespace BlackMisc
|
||||
|
||||
//! Find for given simulator
|
||||
CDistributorList matchesSimulator(const CSimulatorInfo &simulator) const;
|
||||
|
||||
//! All data from DB?
|
||||
bool isCompletelyFromDb() const;
|
||||
|
||||
//! Remove distributors not from DB
|
||||
int removeIfNotLoadedFromDb();
|
||||
};
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user