Class PeppolSBDHDataReader

java.lang.Object
com.helger.peppol.sbdh.PeppolSBDHDataReader

@NotThreadSafe public class PeppolSBDHDataReader extends Object
Main class to read standard business documents and extract the Peppol required data out of it.
Author:
Philip Helger
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    static final String
     
    static final boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    PeppolSBDHDataReader(@NonNull com.helger.peppolid.factory.IIdentifierFactory aIdentifierFactory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected @NonNull com.helger.sbdh.SBDMarshaller
    Create a new SBD marshaller used for reading SBD documents.
    extractData(@NonNull com.helger.io.resource.IReadableResource aStandardBusinessDocument)
    Extract the document data from the Standard Business Document represents by the passed parameter.
    extractData(@NonNull InputStream aStandardBusinessDocument)
    Extract the document data from the Standard Business Document represents by the passed parameter.
    extractData(@NonNull org.unece.cefact.namespaces.sbdh.StandardBusinessDocument aStandardBusinessDocument)
    Extract the document data from the Standard Business Document represents by the passed parameter.
    extractData(@NonNull org.unece.cefact.namespaces.sbdh.StandardBusinessDocumentHeader aSBDH, @NonNull Element aBusinessMessage)
    Extract the document data from the Standard Business Document represents by the passed parameter.
    extractData(@NonNull Node aStandardBusinessDocument)
    Extract the document data from the Standard Business Document represents by the passed parameter.
    extractDataUnchecked(@NonNull org.unece.cefact.namespaces.sbdh.StandardBusinessDocumentHeader aSBDH, @NonNull Element aBusinessMessage)
    Extract the document data from the Standard Business Document represents by the passed parameter without any value checks.
    final @NonNull com.helger.peppolid.factory.IIdentifierFactory
     
    final boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    The SBDH C1 country requirement is contained for long enough.
    final boolean
     
    protected boolean
    isValidBusinessMessage(@NonNull Element aBusinessMessage)
    Check if the passed business message is valid or not.
    protected boolean
    isValidCountryC1(@Nullable String sCountryC1)
    Check if the passed C1 country code is valid or not.
    protected boolean
    isValidCreationDateTime(@NonNull com.helger.datetime.xml.XMLOffsetDateTime aCreationDateTime)
    Check if the passed document identification creation date time is valid or not.
    protected boolean
    isValidDocumentTypeIdentifier(@Nullable String sDocumentTypeIdentifier)
    Check if the passed document type identifier value is valid or not.
    protected boolean
    isValidHeaderVersion(@Nullable String sHeaderVersion)
    Check if the passed header version is valid or not.
    protected boolean
    isValidInstanceIdentifier(@Nullable String sInstanceIdentifier)
    Check if the passed document identification instance identifier is valid or not.
    protected boolean
    isValidMLSTo(@Nullable String sScheme, @Nullable String sValue)
    Check if the provided MLS addressee (from MLS_TO field) is valid or not.
    protected boolean
    isValidMLSType(@Nullable String sType)
    Check if the provided MLS type (from MLS_TYPE field) is valid or not.
    protected boolean
    isValidProcessIdentifier(@Nullable String sProcessIdentifier)
    Check if the passed process identifier value is valid or not.
    protected boolean
    isValidReceiverAuthority(@Nullable String sReceiverAuthority)
    Check if the passed receiver authority is valid or not.
    protected boolean
    isValidReceiverIdentifier(@Nullable String sReceiverAuthority, @Nullable String sReceiverIdentifier)
    Check if the passed receiver identifier is valid or not.
    protected boolean
    isValidSenderAuthority(@Nullable String sSenderAuthority)
    Check if the passed sender authority is valid or not.
    protected boolean
    isValidSenderIdentifier(@Nullable String sSenderAuthority, @Nullable String sSenderIdentifier)
    Check if the passed sender identifier is valid or not.
    protected boolean
    isValidStandard(@Nullable String sStandard, @NonNull Element aBusinessMessage, @NonNull String sDocumentTypeIdentifierValue)
    Check if the passed document identification standard is valid or not.
    protected boolean
    isValidType(@Nullable String sType, @NonNull Element aBusinessMessage)
    Check if the passed document identification type is valid or not.
    protected boolean
    isValidTypeVersion(@Nullable String sTypeVersion, @NonNull Element aBusinessMessage, @NonNull String sDocumentTypeIdentifierValue)
    Check if the passed document identification type version is valid or not.
    final @NonNull PeppolSBDHDataReader
    Deprecated, for removal: This API element is subject to removal in a future version.
    The SBDH C1 country requirement is contained for long enough.
    final @NonNull PeppolSBDHDataReader
    Enable or disable the performing of value checks on data extraction.
    void
    validateData(@NonNull org.unece.cefact.namespaces.sbdh.StandardBusinessDocumentHeader aSBDH, @NonNull Element aBusinessMessage, @NonNull com.helger.diagnostics.error.list.ErrorList aErrorList)
    Validate the provided SBDH and the Business Message according to the Peppol rules and store the results in an Error List.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_PERFORM_VALUE_CHECKS

      public static final boolean DEFAULT_PERFORM_VALUE_CHECKS
      See Also:
    • DEFAULT_CHECK_FOR_COUNTRY_C1

      @Deprecated(forRemoval=true, since="12.3.6") public static final boolean DEFAULT_CHECK_FOR_COUNTRY_C1
      Deprecated, for removal: This API element is subject to removal in a future version.
      See Also:
    • DEFAULT_COUNTRY_CODE_REGEX

      public static final String DEFAULT_COUNTRY_CODE_REGEX
      See Also:
  • Constructor Details

    • PeppolSBDHDataReader

      public PeppolSBDHDataReader(@NonNull com.helger.peppolid.factory.IIdentifierFactory aIdentifierFactory)
  • Method Details

    • getIdentifierFactory

      public final @NonNull com.helger.peppolid.factory.IIdentifierFactory getIdentifierFactory()
      Returns:
      The identifier provided in the constructor. Never null.
      Since:
      8.2.3
    • isPerformValueChecks

      public final boolean isPerformValueChecks()
      Returns:
      true if value checks on data extraction are enabled, false if not. By default checks are enabled - see DEFAULT_PERFORM_VALUE_CHECKS.
      Since:
      8.2.3
    • setPerformValueChecks

      public final @NonNull PeppolSBDHDataReader setPerformValueChecks(boolean b)
      Enable or disable the performing of value checks on data extraction.
      Parameters:
      b - true to enable checks, false to disable them.
      Returns:
      this for chaining
      Since:
      8.2.3
    • isCheckForCountryC1

      @Deprecated(forRemoval=true, since="12.3.6") public final boolean isCheckForCountryC1()
      Deprecated, for removal: This API element is subject to removal in a future version.
      The SBDH C1 country requirement is contained for long enough. No need anymore to disable this check.
      In case of value checks, should the Country C1 also be checked?
      Returns:
      true to check for mandatory country C1, false to not do it.
      Since:
      9.2.2
    • setCheckForCountryC1

      @Deprecated(forRemoval=true, since="12.3.6") public final @NonNull PeppolSBDHDataReader setCheckForCountryC1(boolean b)
      Deprecated, for removal: This API element is subject to removal in a future version.
      The SBDH C1 country requirement is contained for long enough. No need anymore to disable this check.
      Enable or disable the checking for C1 country code. This needs to be called upon message reception, is messages without a C1 country code should be accepted.
      Parameters:
      b - true to enable the check, false to disable it.
      Returns:
      this for chaining
      Since:
      9.2.2
    • isValidHeaderVersion

      @OverrideOnDemand protected boolean isValidHeaderVersion(@Nullable String sHeaderVersion)
      Check if the passed header version is valid or not. By default is must match CPeppolSBDH.HEADER_VERSION. Override this method to allow for other schemes as well.
      Parameters:
      sHeaderVersion - The value to be checked. This is the content of the XML element HeaderVersion. May be null.
      Returns:
      true if the value is valid, false otherwise.
    • isValidSenderAuthority

      @OverrideOnDemand protected boolean isValidSenderAuthority(@Nullable String sSenderAuthority)
      Check if the passed sender authority is valid or not. By default is must match PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME. Override this method to allow for other schemes as well.
      Parameters:
      sSenderAuthority - The value to be checked. This is the content of the XML attribute Sender/Identifier/@Authority. May be null.
      Returns:
      true if the value is valid, false otherwise.
    • isValidSenderIdentifier

      @OverrideOnDemand protected boolean isValidSenderIdentifier(@Nullable String sSenderAuthority, @Nullable String sSenderIdentifier)
      Check if the passed sender identifier is valid or not. By default is must not be empty. Override this method to perform further checks.
      Parameters:
      sSenderAuthority - The authority of the sender that was already validated with isValidSenderAuthority(String). This parameter is present to allow for different identifier checks for different authorities. May be null.
      sSenderIdentifier - The value to be checked. This conforms to the XML element value of Sender/Identifier. May be null.
      Returns:
      true if the value is valid for the given authority, false otherwise.
    • isValidReceiverAuthority

      @OverrideOnDemand protected boolean isValidReceiverAuthority(@Nullable String sReceiverAuthority)
      Check if the passed receiver authority is valid or not. By default is must match PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME. Override this method to allow for other schemes as well.
      Parameters:
      sReceiverAuthority - The value to be checked. This is the content of the XML attribute Receiver/Identifier/@Authority. May be null.
      Returns:
      true if the value is valid, false otherwise.
    • isValidReceiverIdentifier

      @OverrideOnDemand protected boolean isValidReceiverIdentifier(@Nullable String sReceiverAuthority, @Nullable String sReceiverIdentifier)
      Check if the passed receiver identifier is valid or not. By default is must not be empty. Override this method to perform further checks.
      Parameters:
      sReceiverAuthority - The authority of the receiver that was already validated with isValidReceiverAuthority(String). This parameter is present to allow for different identifier checks for different authorities. May be null.
      sReceiverIdentifier - The value to be checked. This conforms to the XML element value of Receiver/Identifier. May be null.
      Returns:
      true if the value is valid for the given authority, false otherwise.
    • isValidDocumentTypeIdentifier

      @OverrideOnDemand protected boolean isValidDocumentTypeIdentifier(@Nullable String sDocumentTypeIdentifier)
      Check if the passed document type identifier value is valid or not. By default it must not be empty. Override this method to perform further checks.
      Parameters:
      sDocumentTypeIdentifier - The value to be checked excluding the Peppol identifier scheme. This conforms to the XML element value of BusinessScope/Scope[Type/text()="DOCUMENTID"]/InstanceIdentifier . May be null.
      Returns:
      true if the value is valid, false otherwise.
    • isValidProcessIdentifier

      @OverrideOnDemand protected boolean isValidProcessIdentifier(@Nullable String sProcessIdentifier)
      Check if the passed process identifier value is valid or not. By default it must not be empty. Override this method to perform further checks.
      Parameters:
      sProcessIdentifier - The value to be checked excluding the Peppol identifier scheme. This conforms to the XML element value of BusinessScope/Scope[Type/text()="PROCESSID"]/InstanceIdentifier . May be null.
      Returns:
      true if the value is valid, false otherwise.
    • isValidCountryC1

      @OverrideOnDemand protected boolean isValidCountryC1(@Nullable String sCountryC1)
      Check if the passed C1 country code is valid or not. By default is must follow the regular expression provided in the Peppol specification. Override this method to perform further checks.
      Parameters:
      sCountryC1 - The value to be checked excluding the Peppol identifier scheme. This conforms to the XML element value of BusinessScope/Scope[Type/text()="COUNTRY_C1"]/InstanceIdentifier . May be null.
      Returns:
      true if the value is valid, false otherwise.
    • isValidMLSTo

      @OverrideOnDemand protected boolean isValidMLSTo(@Nullable String sScheme, @Nullable String sValue)
      Check if the provided MLS addressee (from MLS_TO field) is valid or not.
      Parameters:
      sScheme - The participant identifier scheme. May be null.
      sValue - The participant identifier value. May be null.
      Returns:
      true if the MLS addressee is considered valid, false if not.
      Since:
      10.3.3
    • isValidMLSType

      @OverrideOnDemand protected boolean isValidMLSType(@Nullable String sType)
      Check if the provided MLS type (from MLS_TYPE field) is valid or not.
      Parameters:
      sType - The type to check. May be null.
      Returns:
      true if the MLS type is considered valid, false if not.
      Since:
      10.3.3
    • isValidBusinessMessage

      @OverrideOnDemand protected boolean isValidBusinessMessage(@NonNull Element aBusinessMessage)
      Check if the passed business message is valid or not. By default this method always returns true since the element is never null and no UBL specific checks are performed. Override this method to perform further or other checks.
      Parameters:
      aBusinessMessage - The business message element to check against. Never null.
      Returns:
      true if the value is valid, false otherwise.
    • isValidStandard

      @OverrideOnDemand protected boolean isValidStandard(@Nullable String sStandard, @NonNull Element aBusinessMessage, @NonNull String sDocumentTypeIdentifierValue)
      Check if the passed document identification standard is valid or not. By default this checks if the standard is the same as the namespace URI of the business message root element. Override this method to perform further or other checks.
      Parameters:
      sStandard - The value to be checked. This corresponds to the field "DocumentIdentification/Standard". May be null.
      aBusinessMessage - The business message element to check against. Never null.
      sDocumentTypeIdentifierValue - The document type identifier value provided. Never null.
      Returns:
      true if the value is valid, false otherwise.
    • isValidTypeVersion

      @OverrideOnDemand protected boolean isValidTypeVersion(@Nullable String sTypeVersion, @NonNull Element aBusinessMessage, @NonNull String sDocumentTypeIdentifierValue)
      Check if the passed document identification type version is valid or not. By default this refers to the UBL version and must either be "2.0" or "2.1". Override this method to perform further or other checks.
      Parameters:
      sTypeVersion - The value to be checked. This corresponds to the field "DocumentIdentification/TypeVersion". May be null.
      aBusinessMessage - The business message element to check against. Never null.
      sDocumentTypeIdentifierValue - The document type identifier value provided. Never null.
      Returns:
      true if the value is valid, false otherwise.
    • isValidType

      @OverrideOnDemand protected boolean isValidType(@Nullable String sType, @NonNull Element aBusinessMessage)
      Check if the passed document identification type is valid or not. By default this checks if the type is the same as the local name of the business message root element. Override this method to perform further or other checks.
      Parameters:
      sType - The value to be checked. This corresponds to the field "DocumentIdentification/Type". May be null.
      aBusinessMessage - The business message element to check against. Never null.
      Returns:
      true if the value is valid, false otherwise.
    • isValidInstanceIdentifier

      @OverrideOnDemand protected boolean isValidInstanceIdentifier(@Nullable String sInstanceIdentifier)
      Check if the passed document identification instance identifier is valid or not. By default all non-empty values are valid. Override this method to perform further or other checks.
      Parameters:
      sInstanceIdentifier - The value to be checked. This corresponds to the field "DocumentIdentification/InstanceIdentifier". May be null .
      Returns:
      true if the value is valid, false otherwise.
    • isValidCreationDateTime

      @OverrideOnDemand protected boolean isValidCreationDateTime(@NonNull com.helger.datetime.xml.XMLOffsetDateTime aCreationDateTime)
      Check if the passed document identification creation date time is valid or not. By default all values are valid as they cannot be null. Override this method to perform further or other checks.
      Parameters:
      aCreationDateTime - The value to be checked. This corresponds to the field "DocumentIdentification/CreationDateAndTime". Is never null .
      Returns:
      true if the value is valid, false otherwise.
    • createSBDMarshaller

      @OverrideOnDemand protected @NonNull com.helger.sbdh.SBDMarshaller createSBDMarshaller()
      Create a new SBD marshaller used for reading SBD documents. Override this method to customize reading.
      Returns:
      An instance of the SBDMarshaller and never null.
    • extractData

      public @NonNull PeppolSBDHData extractData(@WillClose @NonNull InputStream aStandardBusinessDocument) throws PeppolSBDHDataReadException
      Extract the document data from the Standard Business Document represents by the passed parameter.
      Parameters:
      aStandardBusinessDocument - The input stream to read from. Will be closed by this method. May not be null.
      Returns:
      The document data and never null.
      Throws:
      PeppolSBDHDataReadException - In case the passed Standard Business Document does not conform to the Peppol rules.
    • extractData

      public @NonNull PeppolSBDHData extractData(@NonNull com.helger.io.resource.IReadableResource aStandardBusinessDocument) throws PeppolSBDHDataReadException
      Extract the document data from the Standard Business Document represents by the passed parameter.
      Parameters:
      aStandardBusinessDocument - The resource to read from. May not be null.
      Returns:
      The document data and never null.
      Throws:
      PeppolSBDHDataReadException - In case the passed Standard Business Document does not conform to the Peppol rules.
    • extractData

      public @NonNull PeppolSBDHData extractData(@NonNull Node aStandardBusinessDocument) throws PeppolSBDHDataReadException
      Extract the document data from the Standard Business Document represents by the passed parameter.
      Parameters:
      aStandardBusinessDocument - The DOM node to read from. May not be null.
      Returns:
      The document data and never null.
      Throws:
      PeppolSBDHDataReadException - In case the passed Standard Business Document does not conform to the Peppol rules.
    • extractData

      public @NonNull PeppolSBDHData extractData(@NonNull org.unece.cefact.namespaces.sbdh.StandardBusinessDocument aStandardBusinessDocument) throws PeppolSBDHDataReadException
      Extract the document data from the Standard Business Document represents by the passed parameter.
      Parameters:
      aStandardBusinessDocument - The domain object to read from. May not be null.
      Returns:
      The document data and never null.
      Throws:
      PeppolSBDHDataReadException - In case the passed Standard Business Document does not conform to the Peppol rules.
    • validateData

      public void validateData(@NonNull org.unece.cefact.namespaces.sbdh.StandardBusinessDocumentHeader aSBDH, @NonNull Element aBusinessMessage, @NonNull com.helger.diagnostics.error.list.ErrorList aErrorList)
      Validate the provided SBDH and the Business Message according to the Peppol rules and store the results in an Error List.
      Parameters:
      aSBDH - The SBDH to be validated. Must not be null.
      aBusinessMessage - The Business Message to be validated (this does NOT mean Schematron validation). Must not be null.
      aErrorList - The error list to be filled. Must not be null.
    • extractData

      public @NonNull PeppolSBDHData extractData(@NonNull org.unece.cefact.namespaces.sbdh.StandardBusinessDocumentHeader aSBDH, @NonNull Element aBusinessMessage) throws PeppolSBDHDataReadException
      Extract the document data from the Standard Business Document represents by the passed parameter. Eventually value checks are performed if isPerformValueChecks() is true.
      Parameters:
      aSBDH - The header object to read from. May not be null.
      aBusinessMessage - The main business message (XML payload) to extract data from. May not be null.
      Returns:
      The document data and never null.
      Throws:
      PeppolSBDHDataReadException - In case the passed Standard Business Document does not conform to the Peppol rules.
    • extractDataUnchecked

      public @NonNull PeppolSBDHData extractDataUnchecked(@NonNull org.unece.cefact.namespaces.sbdh.StandardBusinessDocumentHeader aSBDH, @NonNull Element aBusinessMessage)
      Extract the document data from the Standard Business Document represents by the passed parameter without any value checks. This might be handy, if value checks were executed separately.
      Parameters:
      aSBDH - The header object to read from. May not be null.
      aBusinessMessage - The main business message (XML payload) to extract data from. May not be null.
      Returns:
      The document data and never null.
      Since:
      9.2.2