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 Details

    • DEFAULT_PERFORM_VALUE_CHECKS

      public static final boolean DEFAULT_PERFORM_VALUE_CHECKS
      See Also:
    • DEFAULT_CHECK_FOR_COUNTRY_C1

      public static final boolean DEFAULT_CHECK_FOR_COUNTRY_C1
      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

      @Nonnull public final 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

      @Nonnull public final 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

      public final boolean isCheckForCountryC1()
      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

      @Nonnull public final PeppolSBDHDataReader setCheckForCountryC1(boolean b)
      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.
    • 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.commons.datetime.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

      @Nonnull @OverrideOnDemand protected 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

      @Nonnull public PeppolSBDHData extractData(@Nonnull @WillClose 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

      @Nonnull public PeppolSBDHData extractData(@Nonnull com.helger.commons.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

      @Nonnull public 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

      @Nonnull public 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.commons.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

      @Nonnull public 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

      @Nonnull public 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