Materials: External Modules Part 1
Refactored code to support local and external material sources This is the first PR in a series to support external modules. External modules allow materials to be stored in external data sources such as databases or web services. No new functionality is introduced in this PR, rather it is a refactoring of code that will allow for changes to be introduced in future PRs. Minor performance improvements have also been made in the model and material managers. The Python API has been enhanced for many data types to allow for modification within Python.
This commit is contained in:
committed by
Chris Hennes
parent
382720b82e
commit
592406a328
@@ -101,11 +101,49 @@ bool ModelProperty::operator==(const ModelProperty& other) const
|
||||
return true;
|
||||
}
|
||||
|
||||
return (_name == other._name) && (_displayName == other._displayName) && (_propertyType == other._propertyType)
|
||||
&& (_units == other._units) && (_url == other._url) && (_description == other._description)
|
||||
return (_name == other._name) && (_displayName == other._displayName)
|
||||
&& (_propertyType == other._propertyType) && (_units == other._units)
|
||||
&& (_url == other._url) && (_description == other._description)
|
||||
&& (_inheritance == other._inheritance);
|
||||
}
|
||||
|
||||
void ModelProperty::validate(const ModelProperty& other) const
|
||||
{
|
||||
if (_name != other._name) {
|
||||
throw InvalidProperty("Model names don't match");
|
||||
}
|
||||
if (getDisplayName() != other.getDisplayName()) {
|
||||
Base::Console().Log("Local display name '%s'\n", getDisplayName().toStdString().c_str());
|
||||
Base::Console().Log("Remote display name '%s'\n",
|
||||
other.getDisplayName().toStdString().c_str());
|
||||
throw InvalidProperty("Model display names don't match");
|
||||
}
|
||||
if (_propertyType != other._propertyType) {
|
||||
throw InvalidProperty("Model property types don't match");
|
||||
}
|
||||
if (_units != other._units) {
|
||||
throw InvalidProperty("Model units don't match");
|
||||
}
|
||||
if (_url != other._url) {
|
||||
throw InvalidProperty("Model URLs don't match");
|
||||
}
|
||||
if (_description != other._description) {
|
||||
throw InvalidProperty("Model descriptions don't match");
|
||||
}
|
||||
if (_inheritance != other._inheritance) {
|
||||
throw InvalidProperty("Model inheritance don't match");
|
||||
}
|
||||
|
||||
if (_columns.size() != other._columns.size()) {
|
||||
Base::Console().Log("Local property column count %d\n", _columns.size());
|
||||
Base::Console().Log("Remote property column count %d\n", other._columns.size());
|
||||
throw InvalidProperty("Model property column counts don't match");
|
||||
}
|
||||
for (int i = 0; i < _columns.size(); i++) {
|
||||
_columns[i].validate(other._columns[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TYPESYSTEM_SOURCE(Materials::Model, Base::BaseClass)
|
||||
|
||||
Model::Model()
|
||||
@@ -129,6 +167,31 @@ Model::Model(std::shared_ptr<ModelLibrary> library,
|
||||
, _doi(doi)
|
||||
{}
|
||||
|
||||
QString Model::getDirectory() const
|
||||
{
|
||||
return _directory;
|
||||
}
|
||||
|
||||
void Model::setDirectory(const QString& directory)
|
||||
{
|
||||
_directory = directory;
|
||||
}
|
||||
|
||||
QString Model::getFilename() const
|
||||
{
|
||||
return _filename;
|
||||
}
|
||||
|
||||
void Model::setFilename(const QString& filename)
|
||||
{
|
||||
_filename = filename;
|
||||
}
|
||||
|
||||
QString Model::getFilePath() const
|
||||
{
|
||||
return QDir(_directory + QStringLiteral("/") + _filename).absolutePath();
|
||||
}
|
||||
|
||||
ModelProperty& Model::operator[](const QString& key)
|
||||
{
|
||||
try {
|
||||
@@ -138,3 +201,54 @@ ModelProperty& Model::operator[](const QString& key)
|
||||
throw PropertyNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
void Model::validate(const std::shared_ptr<Model>& other) const
|
||||
{
|
||||
try {
|
||||
_library->validate(*(other->_library));
|
||||
}
|
||||
catch (const InvalidLibrary& e)
|
||||
{
|
||||
throw InvalidModel(e.what());
|
||||
}
|
||||
|
||||
// std::map<QString, ModelProperty> _properties;
|
||||
if (_type != other->_type) {
|
||||
throw InvalidModel("Model types don't match");
|
||||
}
|
||||
if (_name != other->_name) {
|
||||
throw InvalidModel("Model names don't match");
|
||||
}
|
||||
if (_directory != other->_directory) {
|
||||
throw InvalidModel("Model directories don't match");
|
||||
}
|
||||
if (!other->_filename.isEmpty()) {
|
||||
throw InvalidModel("Remote filename is not empty");
|
||||
}
|
||||
if (_uuid != other->_uuid) {
|
||||
throw InvalidModel("Model UUIDs don't match");
|
||||
}
|
||||
if (_description != other->_description) {
|
||||
throw InvalidModel("Model descriptions don't match");
|
||||
}
|
||||
if (_url != other->_url) {
|
||||
throw InvalidModel("Model URLs don't match");
|
||||
}
|
||||
if (_doi != other->_doi) {
|
||||
throw InvalidModel("Model DOIs don't match");
|
||||
}
|
||||
if (_inheritedUuids != other->_inheritedUuids) {
|
||||
throw InvalidModel("Model inherited UUIDs don't match");
|
||||
}
|
||||
|
||||
// Need to compare properties
|
||||
if (_properties.size() != other->_properties.size()) {
|
||||
// Base::Console().Log("Local property count %d\n", _properties.size());
|
||||
// Base::Console().Log("Remote property count %d\n", other->_properties.size());
|
||||
throw InvalidModel("Model property counts don't match");
|
||||
}
|
||||
for (auto& property : _properties) {
|
||||
auto& remote = other->_properties[property.first];
|
||||
property.second.validate(remote);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user