Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions dynadjust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,28 @@ if (BUILD_TESTING)
add_test (NAME reftran-source-test COMMAND $<TARGET_FILE:${DNAREFTRAN_TARGET}> srctest -r itrf2014 -e 01.01.2020 --export-xml)
add_test (NAME check-source-reftran COMMAND bash check_source_tags.sh srctest.ITRF2014.01.01.2020msr.xml CAMPAIGN_2023A CAMPAIGN_2023B EMPTY)

# 8a. XML import with and without xsi:noNamespaceSchemaLocation (issue #346)
# Verify dnaimport handles XML files regardless of whether the schema location
# attribute is present. Strip the attribute and import each sample data pair.

# gnss-network: with schema location (original files)
add_test (NAME import-xml-gnss-with-xsd COMMAND $<TARGET_FILE:${DNAIMPORT_TARGET}> -n xsd_gnss gnss-networkstn.xml gnss-networkmsr.xml -r GDA2020)
# gnss-network: without schema location
add_test (NAME import-xml-gnss-strip COMMAND bash strip_schema_location.sh gnss-networkstn.xml gnss-networkstn-noxsd.xml)
add_test (NAME import-xml-gnss-strip-msr COMMAND bash strip_schema_location.sh gnss-networkmsr.xml gnss-networkmsr-noxsd.xml)
add_test (NAME import-xml-gnss-without-xsd COMMAND $<TARGET_FILE:${DNAIMPORT_TARGET}> -n xsd_gnss gnss-networkstn-noxsd.xml gnss-networkmsr-noxsd.xml -r GDA2020)
set_tests_properties(import-xml-gnss-strip import-xml-gnss-strip-msr PROPERTIES FIXTURES_SETUP gnss_strip)
set_tests_properties(import-xml-gnss-without-xsd PROPERTIES FIXTURES_REQUIRED gnss_strip)

# urban-network: with schema location
add_test (NAME import-xml-urban-with-xsd COMMAND $<TARGET_FILE:${DNAIMPORT_TARGET}> -n xsd_urban urban-networkstn.xml urban-networkmsr.xml -r GDA2020)
# urban-network: without schema location
add_test (NAME import-xml-urban-strip COMMAND bash strip_schema_location.sh urban-networkstn.xml urban-networkstn-noxsd.xml)
add_test (NAME import-xml-urban-strip-msr COMMAND bash strip_schema_location.sh urban-networkmsr.xml urban-networkmsr-noxsd.xml)
add_test (NAME import-xml-urban-without-xsd COMMAND $<TARGET_FILE:${DNAIMPORT_TARGET}> -n xsd_urban urban-networkstn-noxsd.xml urban-networkmsr-noxsd.xml -r GDA2020)
set_tests_properties(import-xml-urban-strip import-xml-urban-strip-msr PROPERTIES FIXTURES_SETUP urban_strip)
set_tests_properties(import-xml-urban-without-xsd PROPERTIES FIXTURES_REQUIRED urban_strip)

# 9. gnss reference frame transformations
add_test (NAME ref-gnss01-network COMMAND $<TARGET_FILE:${DNAREFTRAN_TARGET}> gnss -r itrf2014 -e 01.01.2020)
add_test (NAME ref-gnss02-network COMMAND $<TARGET_FILE:${DNAREFTRAN_TARGET}> gnss -r itrf1988 -e 03.12.1995)
Expand Down Expand Up @@ -1744,16 +1766,8 @@ if (BUILD_TESTING)
add_test (NAME import-no-frame COMMAND $<TARGET_FILE:${DNAIMPORT_TARGET}> -n sample -r itrf1975 dsg.stn dsg.msr)
# no stations and measurements (generated above)
add_test (NAME import-no-data COMMAND $<TARGET_FILE:${DNAIMPORT_TARGET}> -n null ./null.stn ./null.msr)
# no DynaML.xsd - remove file in platform-independent manner (using CMake command) by setting up a test dependency
add_test (NAME import-no-xsd-file-remove COMMAND ${CMAKE_COMMAND} -E remove DynaML.xsd)
add_test (NAME import-no-xsd-file COMMAND $<TARGET_FILE:${DNAIMPORT_TARGET}> -n gnss gnss-networkstn.xml gnss-networkmsr.xml)
set_tests_properties(import-no-xsd-file PROPERTIES DEPENDS import-no-xsd-file-remove TIMEOUT 5)
# Restore DynaML.xsd after testing its absence
add_test (NAME import-no-xsd-file-restore COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/../sampleData/DynaML.xsd DynaML.xsd)
set_tests_properties(import-no-xsd-file-restore PROPERTIES DEPENDS import-no-xsd-file)
# no geoid file
add_test (NAME import-no-geoid COMMAND $<TARGET_FILE:${DNAIMPORT_TARGET}> -n geoid --geo-file ./nofile.geo)
set_tests_properties(import-no-geoid PROPERTIES DEPENDS import-no-xsd-file-restore)
# no project file
add_test (NAME import-no-project COMMAND $<TARGET_FILE:${DNAIMPORT_TARGET}> -p ./nofile.dnaproj)
# measurement stns not in station file
Expand All @@ -1765,7 +1779,7 @@ if (BUILD_TESTING)
add_test (NAME import-misc-network-size COMMAND $<TARGET_FILE:${DNAIMPORT_TARGET}> -n contig --import-contiguous-stn-msr 5000 --export-dna)

set_tests_properties(import-no-option import-invalid-option import-invalid-file import-nearby import-no-files import-no-frame
import-no-data import-no-xsd-file import-no-geoid import-no-project import-no-stns import-no-help
import-no-data import-no-geoid import-no-project import-no-stns import-no-help
import-misc-block-size import-misc-network-size import-misc-07
PROPERTIES WILL_FAIL TRUE)

Expand Down
36 changes: 18 additions & 18 deletions dynadjust/dynadjust/dnaimport/dnainterop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

#include <dynadjust/dnaimport/dnainterop.hpp>

//#include <include/io/DynaML-schema.hxx>

using namespace dynadjust::epsg;

MsrTally g_map_tally;
Expand Down Expand Up @@ -400,18 +398,6 @@ void dna_import::ParseXML(const std::string& fileName, vdnaStnPtr* vStations, PU
_filespecifiedreferenceframe = false;
_filespecifiedepoch = false;

// Check if DynaML.xsd exists in the current directory
// This prevents the XML parser from hanging when the schema file is missing
if (!std::filesystem::exists("DynaML.xsd"))
{
import_file_mutex.unlock();
std::stringstream ss;
ss << "ParseXML(): DynaML.xsd schema file not found in the current directory." << std::endl;
ss << " The XML parser requires this file to validate XML input files." << std::endl;
ss << " Please ensure DynaML.xsd is present in the working directory.";
SignalExceptionParse(ss.str(), 0);
}

try
{
// Instantiate individual parsers.
Expand Down Expand Up @@ -473,7 +459,7 @@ void dna_import::ParseXML(const std::string& fileName, vdnaStnPtr* vStations, PU
::xml_schema::document doc_p (DnaXmlFormat_p, "DnaXmlFormat");

DnaXmlFormat_p.pre();
doc_p.parse (*ifsInputFILE_);
doc_p.parse (*ifsInputFILE_, ::xml_schema::flags::dont_validate);
DnaXmlFormat_p.post_DnaXmlFormat (vStations, vMeasurements);

// unlock after parsing
Expand Down Expand Up @@ -553,6 +539,7 @@ void dna_import::ParseXML(const std::string& fileName, vdnaStnPtr* vStations, PU
{
std::stringstream ss;
ss << "The default input file reference frame \"" << referenceframe_p.str() << "\" is not recognised.";
import_file_mutex.unlock();
SignalExceptionParse(static_cast<std::string>(ss.str()), 0);
}

Expand Down Expand Up @@ -580,6 +567,7 @@ void dna_import::ParseXML(const std::string& fileName, vdnaStnPtr* vStations, PU
}
std::stringstream ss;
ss << "ParseXML(): An std::ios_base failure was encountered while parsing " << fileName << "." << std::endl << " " << f.what();
import_file_mutex.unlock();
SignalExceptionParse(static_cast<std::string>(ss.str()), 0);
}
catch (const std::system_error& e)
Expand All @@ -598,20 +586,22 @@ void dna_import::ParseXML(const std::string& fileName, vdnaStnPtr* vStations, PU
}
std::stringstream ss;
ss << "ParseXML(): An std::ios_base failure was encountered while parsing " << fileName << "." << std::endl << " " << e.what();
import_file_mutex.unlock();
SignalExceptionParse(static_cast<std::string>(ss.str()), 0);
}
catch (const XMLInteropException& e)
catch (const XMLInteropException& e)
{
std::stringstream ss;
ss << "ParseXML(): An exception was encountered while parsing " << fileName << "." << std::endl << " " << e.what();
import_file_mutex.unlock();
SignalExceptionParse(static_cast<std::string>(ss.str()), 0);
}
catch (const ::xml_schema::parsing& e)
{
std::stringstream ss("");
ss << e.what();

::xsd::cxx::parser::diagnostics<char>::const_iterator _it;
::xsd::cxx::parser::diagnostics<char>::const_iterator _it;
for (_it=e.diagnostics().begin(); _it!=e.diagnostics().end(); _it++)
{
ss << std::endl;
Expand All @@ -620,19 +610,29 @@ void dna_import::ParseXML(const std::string& fileName, vdnaStnPtr* vStations, PU
ss << ", severity " << _it->severity() << std::endl;
ss << " - " << _it->message();
}
import_file_mutex.unlock();
SignalExceptionParse(ss.str(), 0);
}
catch (const ::xml_schema::exception& e)
{
std::stringstream ss;
ss << "ParseXML(): An xml_schema exception was encountered while parsing " << fileName << "." << std::endl << " " << e.what();
import_file_mutex.unlock();
SignalExceptionParse(static_cast<std::string>(ss.str()), 0);
}
catch (const std::exception& e)
{
std::stringstream ss;
ss << "ParseXML(): An error was encountered while parsing " << fileName << "." << std::endl << " " << e.what();
import_file_mutex.unlock();
SignalExceptionParse(ss.str(), 0);
}
catch (...)
{
std::stringstream ss;
ss << "ParseXML(): An unknown error was encountered while parsing " << fileName << "." << std::endl;
SignalExceptionParse(ss.str(), 0);
import_file_mutex.unlock();
SignalExceptionParse(ss.str(), 0);
}

if (parseStatus_ != PARSE_SUCCESS)
Expand Down
15 changes: 13 additions & 2 deletions dynadjust/dynadjust/dnaimport/dnaparser_pimpl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <dynadjust/dnaimport/dnaparser_pimpl.hxx>
#include <include/measurement_types/dnastntally.hpp>

#include <include/io/DynaML-schema.hxx>

using namespace dynadjust::measurements;
using namespace dynadjust::epsg;
using namespace dynadjust::exception;
Expand Down Expand Up @@ -942,6 +940,19 @@ DnaXmlFormat_pimpl::DnaXmlFormat_pimpl(std::ifstream* is, PUINT32 clusterID, con
_referenceframe = referenceframe;
_epoch = epoch;

// Initialise file EPSG and epoch from the default reference frame.
// Previously these were set by the XSD attribute defaults during
// validation. With dont_validate, the attribute parsers are only
// called when the attributes are present in the XML, so we need
// sensible fallbacks.
try {
_fileEpsg = epsgStringFromName<std::string>(_referenceframe);
}
catch (...) {
_fileEpsg.clear();
}
_fileEpoch = epoch;

// capture first file flag
_firstFile = firstFile;

Expand Down
2 changes: 0 additions & 2 deletions dynadjust/dynadjust/dnaimport/dnaparser_pskel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

#include <dynadjust/dnaimport/dnaparser_pskel.hxx>

#include <include/io/DynaML-schema.hxx>

using namespace dynadjust::measurements;

// Clusterpoint_pskel
Expand Down
9 changes: 0 additions & 9 deletions dynadjust/dynadjust/dnaimportwrapper/dnaimportwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1739,20 +1739,11 @@ int main(int argc, char* argv[]) {
}
// Import data as normal
else {
// Change current directory to the import folder
// A hack to circumvent the problem caused by importing DynaML files in
// different directories to where import is run from, causing errors
// because DynaML.xsd cannot be found.
std::filesystem::path currentPath(std::filesystem::current_path());
std::filesystem::current_path(std::filesystem::path(p.g.input_folder));

// Import all data as-is.
// All filtering is performed later below
if (ImportDataFiles(parserDynaML, &vStations, &vMeasurements, &vstationsTotal, &vmeasurementsTotal, &imp_file,
&vinput_file_meta, &parsestnTally, &parsemsrTally, errorCount, p) != EXIT_SUCCESS)
return EXIT_FAILURE;

current_path(currentPath);
}

epsgCode = epsgCodeFromName<UINT32>(p.i.reference_frame);
Expand Down
Loading
Loading