diff --git a/kontroller/src/main/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/DefaultXmlStreamHandler.kt b/kontroller/src/main/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/DefaultXmlStreamHandler.kt index 367575f31..5c573d089 100644 --- a/kontroller/src/main/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/DefaultXmlStreamHandler.kt +++ b/kontroller/src/main/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/DefaultXmlStreamHandler.kt @@ -62,7 +62,7 @@ class DefaultXmlStreamHandler( validationErrors } } catch (thrown: Throwable) { - listOf(avgiverFileError) + listOf(avgiverFileError(thrown.message)) } private fun processIndividElement( @@ -78,7 +78,7 @@ class DefaultXmlStreamHandler( validationErrors } } catch (thrown: Throwable) { - listOf(individFileError) + listOf(individFileError(thrown.message)) } companion object { diff --git a/kontroller/src/main/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/FixedValidationErrors.kt b/kontroller/src/main/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/FixedValidationErrors.kt index ba7005fbc..c567b1a2d 100644 --- a/kontroller/src/main/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/FixedValidationErrors.kt +++ b/kontroller/src/main/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/FixedValidationErrors.kt @@ -12,10 +12,10 @@ object FixedValidationErrors { messageText = "Klarer ikke å lese fil. Får feilmeldingen: $exceptionMessage" ) - val individFileError = ValidationReportEntry( + fun individFileError(exceptionMessage: String?) = ValidationReportEntry( severity = Severity.ERROR, ruleName = IndividRuleId.INDIVID_01.title, - messageText = "Definisjon av Individ er feil i forhold til filspesifikasjonen" + messageText = "Definisjon av Individ er feil i forhold til filspesifikasjonen. $exceptionMessage" ) val individMissingError = ValidationReportEntry( @@ -24,10 +24,10 @@ object FixedValidationErrors { messageText = "Filen mangler individer" ) - val avgiverFileError = ValidationReportEntry( + fun avgiverFileError(exceptionMessage: String?) = ValidationReportEntry( severity = Severity.ERROR, ruleName = AvgiverRuleId.AVGIVER_01.title, - messageText = "Klarer ikke å validere Avgiver mot filspesifikasjon" + messageText = "Klarer ikke å validere Avgiver mot filspesifikasjon. $exceptionMessage" ) fun singleAvgiverError(found: Int) = ValidationReportEntry( diff --git a/kontroller/src/main/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/XmlElementHandlers.kt b/kontroller/src/main/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/XmlElementHandlers.kt index 54a9d46c5..8446c4d6a 100644 --- a/kontroller/src/main/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/XmlElementHandlers.kt +++ b/kontroller/src/main/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/XmlElementHandlers.kt @@ -18,19 +18,24 @@ object XmlElementHandlers { xmlStreamReader, KostraIndividType::class.java ).let { individType -> - if (KostraValidationUtils.validate( - xmlReader = StringReader(KostraBarnevernConverter.marshallInstance(individType)), - xsdResource = KostraValidationUtils.INDIVID_XSD_RESOURCE - ) - ) IndividRules.individRules.mapNotNull { it.validate(individType, arguments) }.flatten() - .map { reportEntry -> - reportEntry.copy( - caseworker = individType.saksbehandler, - journalId = individType.journalnummer, - individId = individType.id - ) - } to individType - else listOf(individFileError) to null + val (valid, errorMessage) = KostraValidationUtils.validate( + xmlReader = StringReader(KostraBarnevernConverter.marshallInstance(individType)), + xsdResource = KostraValidationUtils.INDIVID_XSD_RESOURCE + ) + if (valid) + IndividRules.individRules + .mapNotNull { it.validate(individType, arguments) } + .flatten() + .map { reportEntry -> + reportEntry.copy( + caseworker = individType.saksbehandler, + journalId = individType.journalnummer, + individId = individType.id + ) + } to individType + else { + listOf(individFileError(errorMessage)) to null + } } } @@ -39,12 +44,15 @@ object XmlElementHandlers { xmlStreamReader, KostraAvgiverType::class.java ).let { avgiverType -> - if (KostraValidationUtils.validate( - xmlReader = StringReader(KostraBarnevernConverter.marshallInstance(avgiverType)), - xsdResource = KostraValidationUtils.AVGIVER_XSD_RESOURCE - ) - ) AvgiverRules.avgiverRules.mapNotNull { it.validate(avgiverType, arguments) }.flatten() to avgiverType - else listOf(avgiverFileError) to null + val (valid, errorMessage) = KostraValidationUtils.validate( + xmlReader = StringReader(KostraBarnevernConverter.marshallInstance(avgiverType)), + xsdResource = KostraValidationUtils.AVGIVER_XSD_RESOURCE + ) + if (valid) + AvgiverRules.avgiverRules + .mapNotNull { it.validate(avgiverType, arguments) } + .flatten() to avgiverType + else listOf(avgiverFileError(errorMessage)) to null } } } \ No newline at end of file diff --git a/kontroller/src/test/kotlin/no/ssb/kostra/validation/rule/barnevern/BarnevernValidatorTest.kt b/kontroller/src/test/kotlin/no/ssb/kostra/validation/rule/barnevern/BarnevernValidatorTest.kt index 036e543e0..9c313bf3d 100644 --- a/kontroller/src/test/kotlin/no/ssb/kostra/validation/rule/barnevern/BarnevernValidatorTest.kt +++ b/kontroller/src/test/kotlin/no/ssb/kostra/validation/rule/barnevern/BarnevernValidatorTest.kt @@ -18,7 +18,10 @@ import no.ssb.kostra.validation.report.Severity import no.ssb.kostra.validation.report.ValidationReportEntry import no.ssb.kostra.validation.rule.RuleTestData.argumentsInTest import no.ssb.kostra.validation.rule.barnevern.xmlhandling.BarnevernXmlStreamHandler +import no.ssb.kostra.validation.rule.barnevern.xmlhandling.DefaultXmlStreamHandler import no.ssb.kostra.validation.rule.barnevern.xmlhandling.FixedValidationErrors +import no.ssb.kostra.validation.rule.barnevern.xmlhandling.XmlElementHandlers +import java.io.File import java.time.Year class BarnevernValidatorTest : BehaviorSpec({ @@ -59,7 +62,8 @@ class BarnevernValidatorTest : BehaviorSpec({ ValidationReportEntry( severity = Severity.ERROR, ruleName = AvgiverRuleId.AVGIVER_01.title, - messageText = "Klarer ikke å validere Avgiver mot filspesifikasjon" + messageText = "Klarer ikke å validere Avgiver mot filspesifikasjon. " + + "cvc-datatype-valid.1.2.1: '42' is not a valid value for 'gYear'." ), 51 ), row( @@ -70,7 +74,9 @@ class BarnevernValidatorTest : BehaviorSpec({ ValidationReportEntry( severity = Severity.ERROR, ruleName = IndividRuleId.INDIVID_01.title, - messageText = "Definisjon av Individ er feil i forhold til filspesifikasjonen" + messageText = """Definisjon av Individ er feil i forhold til filspesifikasjonen. """ + + """cvc-pattern-valid: Value 'abc' is not facet-valid with respect to pattern '\d{11}' """ + + """for type '#AnonType_FodselsnummerIndividType'.""" ), 4 ), row( diff --git a/kontroller/src/test/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/DefaultXmlStreamHandlerTest.kt b/kontroller/src/test/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/DefaultXmlStreamHandlerTest.kt index e2eedf265..d2c52a5c5 100644 --- a/kontroller/src/test/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/DefaultXmlStreamHandlerTest.kt +++ b/kontroller/src/test/kotlin/no/ssb/kostra/validation/rule/barnevern/xmlhandling/DefaultXmlStreamHandlerTest.kt @@ -74,7 +74,7 @@ class DefaultXmlStreamHandlerTest : BehaviorSpec({ Then("result should be as expected") { result.shouldNotBeNull() - result.shouldContain(avgiverFileError) + result.shouldContain(avgiverFileError("null")) } } @@ -94,7 +94,7 @@ class DefaultXmlStreamHandlerTest : BehaviorSpec({ Then("result should be as expected") { result.shouldNotBeNull() - result.shouldContain(individFileError) + result.shouldContain(individFileError("null")) } } } diff --git a/kostra-barnevern/src/main/kotlin/no/ssb/kostra/barnevern/KostraValidationUtils.kt b/kostra-barnevern/src/main/kotlin/no/ssb/kostra/barnevern/KostraValidationUtils.kt index 358a827f6..e33f44532 100644 --- a/kostra-barnevern/src/main/kotlin/no/ssb/kostra/barnevern/KostraValidationUtils.kt +++ b/kostra-barnevern/src/main/kotlin/no/ssb/kostra/barnevern/KostraValidationUtils.kt @@ -17,14 +17,14 @@ object KostraValidationUtils { private const val DISALLOW_DOCTYPE_DECL = "http://apache.org/xml/features/disallow-doctype-decl" @JvmStatic - fun validate(xml: String): Boolean = validate(StringReader(xml)) + fun validate(xml: String): Boolean = validate(StringReader(xml)).first @JvmStatic - fun validate(xmlReader: Reader, xsdResource: String = KOSTRA_BARNEVERN_XSD_RESOURCE): Boolean = try { + fun validate(xmlReader: Reader, xsdResource: String = KOSTRA_BARNEVERN_XSD_RESOURCE): Pair = try { getSchemaValidator(xsdResource).validate(StreamSource(xmlReader)) - true + true to "" } catch (thrown: SAXParseException) { - false + false to "${thrown.message}" } @JvmStatic diff --git a/kostra-barnevern/src/main/kotlin/no/ssb/kostra/barnevern/xsd/KostraTiltakType.kt b/kostra-barnevern/src/main/kotlin/no/ssb/kostra/barnevern/xsd/KostraTiltakType.kt index 959dae64e..c1881681d 100644 --- a/kostra-barnevern/src/main/kotlin/no/ssb/kostra/barnevern/xsd/KostraTiltakType.kt +++ b/kostra-barnevern/src/main/kotlin/no/ssb/kostra/barnevern/xsd/KostraTiltakType.kt @@ -7,7 +7,7 @@ import java.time.LocalDate @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "TiltakType", propOrder = ["lovhjemmel", "jmfrLovhjemmel", "kategori", "opphevelse"]) +@XmlType(name = "TiltakType", propOrder = ["lovhjemmel", "jmfrLovhjemmel", "kategori", "tiltaksgrunnlag", "opphevelse"]) data class KostraTiltakType( @field:XmlAttribute(name = "Id", required = true)