-
Notifications
You must be signed in to change notification settings - Fork 222
#5319 - gbXML Reverse Translator - Scan for the gbxml Schema version: skip schema validation with a warning when not 7.03 #5320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/gbxml/ReverseTranslator.cpp
Outdated
| LOG(Warn, "gbXML has no `version` attribute for the schema version, assuming 7.03."); | ||
| version = "7.03"; | ||
| } | ||
| if (version == "7.03") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only suggestion I would have is to put "7.03" in XMLValidator since that is the thing that knows which version of the schema it has. Then if version != 7.03, a call to gbxmlValidator.validate would log something like Cannot validate #{version}.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or keep the code as is but return "7.03" from a XMLValidator::gbxmlValidatorExpectedVersion() method or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Thanks @jmarrec looks good to me! |
5059797 to
ccffa37
Compare
|
CI Results for ecb6a53:
|
| XMLValidator& operator=(XMLValidator&& other) noexcept = default; | ||
|
|
||
| static XMLValidator gbxmlValidator(); | ||
| static XMLValidator gbxmlValidator(const VersionString& schemaVersion = VersionString(7, 3)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it clearer that this is 7.03 schema, and reserve use for supporting more schemas.
| if (schemaVersion != VersionString(7, 3)) { | ||
| LOG_AND_THROW("Unexpected gbXML Schema Version: accepted = [7.03]"); | ||
| } | ||
| const bool quiet = true; | ||
| ::openstudio::embedded_files::extractFile(":/xml/resources/GreenBuildingXML_Ver7.03.xsd", openstudio::toString(tmpDir), quiet); | ||
| auto validator = XMLValidator(tmpDir / "GreenBuildingXML_Ver7.03.xsd"); | ||
| std::string schemaName = fmt::format("GreenBuildingXML_Ver{}.{:02}.xsd", schemaVersion.major(), schemaVersion.minor()); | ||
| ::openstudio::embedded_files::extractFile(fmt::format(":/xml/resources/{}", schemaName), openstudio::toString(tmpDir), quiet); | ||
| auto validator = XMLValidator(tmpDir / schemaName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearly throw if anything else that schema version 7.03 is passed for now
| auto root = doc.document_element(); | ||
| if (std::string_view{root.name()} != "gbXML") { | ||
| LOG(Error, "Expected the root element to be <gbXML>"); | ||
| return boost::none; | ||
| } | ||
| // Scan version of gbxml schema | ||
| std::string version = root.attribute("version").value(); | ||
| VersionString schemaVersion(7, 3); | ||
| if (version.empty()) { | ||
| LOG(Warn, "gbXML has no `version` attribute for the schema version, assuming 7.03."); | ||
| } else { | ||
| try { | ||
| schemaVersion = VersionString(version); | ||
| } catch (...) { | ||
| LOG(Warn, "gbXML has `version` '" << version << "' which was not understood, assuming 7.03."); | ||
| } | ||
| } | ||
| if (schemaVersion == VersionString(7, 3)) { | ||
| // validate the gbxml prior to reverse translation | ||
| auto gbxmlValidator = XMLValidator::gbxmlValidator(schemaVersion); | ||
| gbxmlValidator.validate(path); | ||
| } else { | ||
| LOG(Error, | ||
| "Version of schema specified: " << version | ||
| << ", expected 7.03. gbXML Schema Validation skipped. Note that ReverseTranslator rules are built " | ||
| "for 7.03 and older versions are not officially supported, check resulting model with care."); | ||
| }; | ||
|
|
||
| result = this->convert(root); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip gbXMLValidation with a clear message when the version is not 7.03.
Warn if the gbXML attribute "version" is missing (it's required) and still assume 7.03
Pull request overview
Pull Request Author
src/model/test)src/energyplus/Test)src/osversion/VersionTranslator.cpp)Labels:
IDDChangeAPIChangePull Request - Ready for CIso that CI builds your PRReview Checklist
This will not be exhaustively relevant to every PR.