phax / ph-schematron

Java Schematron library that supports XSLT and native application
Apache License 2.0
116 stars 36 forks source link

Schematron assert ID in AbstractSVRLMessage #103

Closed mangeg closed 3 years ago

mangeg commented 4 years ago

Would it be possible to add the assert id from schematron/XSLT files in the AbstractSVRLMessage(SVRLFailedAssert, SVRLSuccessfulReport)?

The ID I have in mind is "PEPPOL-EN16931-R041" from the sample below. When using ph-bdve-peppol to validate files, the returned ValidationResults and the containing errors getErrorID() returns null. I am not sure if the intent of the errorId is to contains this type of information. But I did a test in a fork where I added fetching of error ID from FailedAssert in SVRLFailedAssert and SVRLSuccessfulReport via AbstractSVRLMessage, https://github.com/mangeg/ph-schematron/commit/f5d4fb6fe827d5a808c9f9cf996668c3515c289f. With these changes I am able to get the assert id from IError.getErrorID().

The use for this would be to be able to programmatically act on results without depending on the readable validation message, ie. (Allowance/charge base amount MUST be provided when Allowance/charge percentage is provided.) in the sample.

From PEPPOL-EN16931-UBL.sch

SCH:

<rule context="ubl-invoice:Invoice/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)] | ubl-invoice:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)] | ubl-creditnote:CreditNote/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)] | ubl-creditnote:CreditNote/cac:CreditNoteLine/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)]">
    <assert id="PEPPOL-EN16931-R041" test="false()" flag="fatal">Allowance/charge base amount MUST
        be provided when allowance/charge percentage is provided.</assert>
</rule>

XSLT:

<svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" test="false()">
    <xsl:attribute name="id">PEPPOL-EN16931-R041</xsl:attribute>
    <xsl:attribute name="flag">fatal</xsl:attribute>
    <xsl:attribute name="location">
        <xsl:apply-templates select="." mode="schematron-select-full-path" />
    </xsl:attribute>
    <svrl:text>Allowance/charge base amount MUST be provided when allowance/charge percentage is provided.</svrl:text>
</svrl:failed-assert>
phax commented 4 years ago

Hi, Can you please check if a preceeding element fired-rule contains the respective test ID? Than I might take it from there...

mangeg commented 4 years ago

No, the fired-rule elements only have template and context + the generated mode and priority attributes.

Should it have been generated on the svrl:fired-rule as well?

The full section from XSLT

<!--RULE -->
<xsl:template match="ubl-invoice:Invoice/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)] | ubl-invoice:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)] | ubl-creditnote:CreditNote/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)] | ubl-creditnote:CreditNote/cac:CreditNoteLine/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)]" mode="M12" priority="1010">
    <svrl:fired-rule context="ubl-invoice:Invoice/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)] | ubl-invoice:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)] | ubl-creditnote:CreditNote/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)] | ubl-creditnote:CreditNote/cac:CreditNoteLine/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)]" />

    <!--ASSERT -->
    <xsl:choose>
        <xsl:when test="false()" />
        <xsl:otherwise>
            <svrl:failed-assert test="false()">
                <xsl:attribute name="id">PEPPOL-EN16931-R041</xsl:attribute>
                <xsl:attribute name="flag">fatal</xsl:attribute>
                <xsl:attribute name="location">
                    <xsl:apply-templates mode="schematron-select-full-path" select="." />
                </xsl:attribute>
                <svrl:text>Allowance/charge base amount MUST
be provided when allowance/charge percentage is provided.</svrl:text>
            </svrl:failed-assert>
        </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates mode="M12" select="*" />
</xsl:template>

from Schematron

<!-- Allowance/Charge (document level/line level) -->
<rule context="ubl-invoice:Invoice/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)] | ubl-invoice:Invoice/cac:InvoiceLine/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)] | ubl-creditnote:CreditNote/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)] | ubl-creditnote:CreditNote/cac:CreditNoteLine/cac:AllowanceCharge[cbc:MultiplierFactorNumeric and not(cbc:BaseAmount)]">
    <assert id="PEPPOL-EN16931-R041" test="false()" flag="fatal">Allowance/charge base amount MUST
  be provided when allowance/charge percentage is provided.</assert>
</rule>
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

phax commented 3 years ago

Finally - that was done in ph-schematron 6.0.1