Skip to content

Conversation

@jmarrec
Copy link
Collaborator

@jmarrec jmarrec commented Dec 18, 2024

Pull request overview

Pull Request Author

  • Model API Changes / Additions
  • Any new or modified fields have been implemented in the EnergyPlus ForwardTranslator (and ReverseTranslator as appropriate)
  • Model API methods are tested (in src/model/test)
  • EnergyPlus ForwardTranslator Tests (in src/energyplus/Test)
  • If a new object or method, added a test in NREL/OpenStudio-resources: Add Link
  • If needed, added VersionTranslation rules for the objects (src/osversion/VersionTranslator.cpp)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes
  • If methods have been deprecated, update rest of code to use the new methods

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

@jmarrec jmarrec added component - gbXML Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. labels Dec 18, 2024
@jmarrec jmarrec self-assigned this Dec 18, 2024
LOG(Warn, "gbXML has no `version` attribute for the schema version, assuming 7.03.");
version = "7.03";
}
if (version == "7.03") {
Copy link
Contributor

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}.

Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would ccffa37 work? @macumber

@macumber
Copy link
Contributor

Thanks @jmarrec looks good to me!

@jmarrec jmarrec force-pushed the 5319_gbxmlRT_Validation branch from 5059797 to ccffa37 Compare December 18, 2024 17:30
XMLValidator& operator=(XMLValidator&& other) noexcept = default;

static XMLValidator gbxmlValidator();
static XMLValidator gbxmlValidator(const VersionString& schemaVersion = VersionString(7, 3));
Copy link
Collaborator Author

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.

Comment on lines +480 to +486
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);
Copy link
Collaborator Author

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

Comment on lines +94 to +122
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);
Copy link
Collaborator Author

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

@jmarrec jmarrec merged commit 2d4cbea into develop Dec 19, 2024
4 of 6 checks passed
@jmarrec jmarrec deleted the 5319_gbxmlRT_Validation branch December 19, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component - gbXML Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GbXMLReverseTranslator schema validation using wrong schema version

4 participants