From 56fbbf190498dda8f6a09fff28c695901bbb6265 Mon Sep 17 00:00:00 2001 From: depryf Date: Fri, 9 Feb 2024 12:45:08 -0500 Subject: [PATCH] Changed handling of bad data level (#252) --- CHANGELOG.md | 4 ++++ .../java/com/imsweb/naaccrxml/NaaccrErrorUtils.java | 2 ++ .../naaccrxml/runtime/NaaccrPatientConverter.java | 4 ++-- .../java/com/imsweb/naaccrxml/XsdSchemaTest.java | 1 + .../invalid_bad-data-item-1.xml | 13 ------------- 5 files changed, 9 insertions(+), 15 deletions(-) delete mode 100644 src/test/resources/data/validity/invalid_library_only/invalid_bad-data-item-1.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index b1e7c33..f1806c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## NAACCR XML Version History +**Version 10.2** + +- Changed data level errors from an exception to a validation error reported on the item. + **Version 10.1** - Optimized read SAS macro. diff --git a/src/main/java/com/imsweb/naaccrxml/NaaccrErrorUtils.java b/src/main/java/com/imsweb/naaccrxml/NaaccrErrorUtils.java index 9d55beb..847eacd 100644 --- a/src/main/java/com/imsweb/naaccrxml/NaaccrErrorUtils.java +++ b/src/main/java/com/imsweb/naaccrxml/NaaccrErrorUtils.java @@ -20,6 +20,7 @@ private NaaccrErrorUtils() { public static final String CODE_BAD_LINE_LENGTH = "Invalid line length"; public static final String CODE_BAD_NAACCR_ID = "Unknown NAACCR ID"; public static final String CODE_BAD_NAACCR_NUM = "Wrong NAACCR Number"; + public static final String CODE_BAD_DATA_LEVEL = "Invalid data level"; public static final String CODE_VAL_TOO_LONG = "Value too long"; public static final String CODE_VAL_TOO_SHORT = "Value too short"; public static final String CODE_VAL_DATA_TYPE = "Value invalid for data type"; @@ -36,6 +37,7 @@ private NaaccrErrorUtils() { _MESSAGES.put(CODE_BAD_LINE_LENGTH, "invalid line length, expected ${0} but got ${1}"); _MESSAGES.put(CODE_BAD_NAACCR_ID, "unknown NAACCR ID: ${0}"); _MESSAGES.put(CODE_BAD_NAACCR_NUM, "NAACCR Number '${0}' does not correspond to NAACCR ID '${1}'"); + _MESSAGES.put(CODE_BAD_DATA_LEVEL, "invalid data level, expected ${0} but got ${1}"); _MESSAGES.put(CODE_VAL_TOO_LONG, "value too long, expected at most ${0} character(s) but got ${1}"); _MESSAGES.put(CODE_VAL_TOO_SHORT, "value too short, expected exactly ${0} character(s) but got ${1}"); _MESSAGES.put(CODE_VAL_DATA_TYPE, "invalid value according to data type '${0}'"); diff --git a/src/main/java/com/imsweb/naaccrxml/runtime/NaaccrPatientConverter.java b/src/main/java/com/imsweb/naaccrxml/runtime/NaaccrPatientConverter.java index 73c1591..304b84b 100644 --- a/src/main/java/com/imsweb/naaccrxml/runtime/NaaccrPatientConverter.java +++ b/src/main/java/com/imsweb/naaccrxml/runtime/NaaccrPatientConverter.java @@ -244,7 +244,7 @@ else if (NaaccrXmlDictionaryUtils.NAACCR_PADDING_RIGHT_ZERO.equals(itemDef.getPa value = StringUtils.rightPad(value, itemDef.getLength(), '0'); } else if (!NaaccrXmlDictionaryUtils.NAACCR_PADDING_LEFT_BLANK.equals(itemDef.getPadding()) && !NaaccrXmlDictionaryUtils.NAACCR_PADDING_RIGHT_BLANK.equals(itemDef.getPadding()) - && !NaaccrXmlDictionaryUtils.NAACCR_PADDING_NONE.equals(itemDef.getPadding())) + && !NaaccrXmlDictionaryUtils.NAACCR_PADDING_NONE.equals(itemDef.getPadding())) throw new IllegalStateException("Unknown padding option: " + itemDef.getPadding()); } @@ -356,7 +356,7 @@ else if (def.getDataType() != null) { if (NaaccrXmlUtils.NAACCR_XML_TAG_PATIENT.equals(parentTag) && NaaccrXmlDictionaryUtils.getPatToTumorChangedNaaccr18And21Ids().contains(rawId)) return item; - reportSyntaxError("invalid parent XML tag for '" + def.getNaaccrId() + "'; was expecting '" + def.getParentXmlElement() + "' but got '" + parentTag + "'"); + reportError(item, lineNumber, currentPath, def, item.getValue(), NaaccrErrorUtils.CODE_BAD_DATA_LEVEL, def.getParentXmlElement(), parentTag); } } diff --git a/src/test/java/com/imsweb/naaccrxml/XsdSchemaTest.java b/src/test/java/com/imsweb/naaccrxml/XsdSchemaTest.java index 70a1db8..83379f3 100644 --- a/src/test/java/com/imsweb/naaccrxml/XsdSchemaTest.java +++ b/src/test/java/com/imsweb/naaccrxml/XsdSchemaTest.java @@ -38,6 +38,7 @@ public class XsdSchemaTest { private static final String _XSD_FILE = "xsd/naaccr_data_1.7.xsd"; @Test + @SuppressWarnings("resource") public void testXsdAgainstLibrary() throws IOException { Path dir = Paths.get(TestingUtils.getWorkingDirectory() + "/src/test/resources/data/validity"); diff --git a/src/test/resources/data/validity/invalid_library_only/invalid_bad-data-item-1.xml b/src/test/resources/data/validity/invalid_library_only/invalid_bad-data-item-1.xml deleted file mode 100644 index a84b769..0000000 --- a/src/test/resources/data/validity/invalid_library_only/invalid_bad-data-item-1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - 00000000 - - 00000001 - - C123 - - - \ No newline at end of file