Package com.helger.peppol.sbdh
Class PeppolSBDHDataReader
java.lang.Object
com.helger.peppol.sbdh.PeppolSBDHDataReader
Main class to read standard business documents and extract the Peppol required data out of it.
- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanDeprecated, for removal: This API element is subject to removal in a future version.static final Stringstatic final boolean -
Constructor Summary
ConstructorsConstructorDescriptionPeppolSBDHDataReader(@NonNull com.helger.peppolid.factory.IIdentifierFactory aIdentifierFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected @NonNull com.helger.sbdh.SBDMarshallerCreate a new SBD marshaller used for reading SBD documents.@NonNull PeppolSBDHDataextractData(@NonNull com.helger.io.resource.IReadableResource aStandardBusinessDocument) Extract the document data from the Standard Business Document represents by the passed parameter.@NonNull PeppolSBDHDataextractData(@NonNull InputStream aStandardBusinessDocument) Extract the document data from the Standard Business Document represents by the passed parameter.@NonNull PeppolSBDHDataextractData(@NonNull org.unece.cefact.namespaces.sbdh.StandardBusinessDocument aStandardBusinessDocument) Extract the document data from the Standard Business Document represents by the passed parameter.@NonNull PeppolSBDHDataextractData(@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.@NonNull PeppolSBDHDataextractData(@NonNull Node aStandardBusinessDocument) Extract the document data from the Standard Business Document represents by the passed parameter.@NonNull PeppolSBDHDataextractDataUnchecked(@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.IIdentifierFactoryfinal booleanDeprecated, for removal: This API element is subject to removal in a future version.The SBDH C1 country requirement is contained for long enough.final booleanprotected booleanisValidBusinessMessage(@NonNull Element aBusinessMessage) Check if the passed business message is valid or not.protected booleanisValidCountryC1(@Nullable String sCountryC1) Check if the passed C1 country code is valid or not.protected booleanisValidCreationDateTime(@NonNull com.helger.datetime.xml.XMLOffsetDateTime aCreationDateTime) Check if the passed document identification creation date time is valid or not.protected booleanisValidDocumentTypeIdentifier(@Nullable String sDocumentTypeIdentifier) Check if the passed document type identifier value is valid or not.protected booleanisValidHeaderVersion(@Nullable String sHeaderVersion) Check if the passed header version is valid or not.protected booleanisValidInstanceIdentifier(@Nullable String sInstanceIdentifier) Check if the passed document identification instance identifier is valid or not.protected booleanisValidMLSTo(@Nullable String sScheme, @Nullable String sValue) Check if the provided MLS addressee (from MLS_TO field) is valid or not.protected booleanisValidMLSType(@Nullable String sType) Check if the provided MLS type (from MLS_TYPE field) is valid or not.protected booleanisValidProcessIdentifier(@Nullable String sProcessIdentifier) Check if the passed process identifier value is valid or not.protected booleanisValidReceiverAuthority(@Nullable String sReceiverAuthority) Check if the passed receiver authority is valid or not.protected booleanisValidReceiverIdentifier(@Nullable String sReceiverAuthority, @Nullable String sReceiverIdentifier) Check if the passed receiver identifier is valid or not.protected booleanisValidSenderAuthority(@Nullable String sSenderAuthority) Check if the passed sender authority is valid or not.protected booleanisValidSenderIdentifier(@Nullable String sSenderAuthority, @Nullable String sSenderIdentifier) Check if the passed sender identifier is valid or not.protected booleanisValidStandard(@Nullable String sStandard, @NonNull Element aBusinessMessage, @NonNull String sDocumentTypeIdentifierValue) Check if the passed document identification standard is valid or not.protected booleanisValidType(@Nullable String sType, @NonNull Element aBusinessMessage) Check if the passed document identification type is valid or not.protected booleanisValidTypeVersion(@Nullable String sTypeVersion, @NonNull Element aBusinessMessage, @NonNull String sDocumentTypeIdentifierValue) Check if the passed document identification type version is valid or not.final @NonNull PeppolSBDHDataReadersetCheckForCountryC1(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.final @NonNull PeppolSBDHDataReadersetPerformValueChecks(boolean b) Enable or disable the performing of value checks on data extraction.voidvalidateData(@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.
-
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_C1Deprecated, for removal: This API element is subject to removal in a future version.- See Also:
-
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:
trueif value checks on data extraction are enabled,falseif not. By default checks are enabled - seeDEFAULT_PERFORM_VALUE_CHECKS.- Since:
- 8.2.3
-
setPerformValueChecks
Enable or disable the performing of value checks on data extraction.- Parameters:
b-trueto enable checks,falseto disable them.- Returns:
- this for chaining
- Since:
- 8.2.3
-
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:
trueto check for mandatory country C1,falseto 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-trueto enable the check,falseto disable it.- Returns:
- this for chaining
- Since:
- 9.2.2
-
isValidHeaderVersion
Check if the passed header version is valid or not. By default is must matchCPeppolSBDH.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 elementHeaderVersion. May benull.- Returns:
trueif the value is valid,falseotherwise.
-
isValidSenderAuthority
Check if the passed sender authority is valid or not. By default is must matchPeppolIdentifierHelper.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 attributeSender/Identifier/@Authority. May benull.- Returns:
trueif the value is valid,falseotherwise.
-
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 withisValidSenderAuthority(String). This parameter is present to allow for different identifier checks for different authorities. May benull.sSenderIdentifier- The value to be checked. This conforms to the XML element value ofSender/Identifier. May benull.- Returns:
trueif the value is valid for the given authority,falseotherwise.
-
isValidReceiverAuthority
Check if the passed receiver authority is valid or not. By default is must matchPeppolIdentifierHelper.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 attributeReceiver/Identifier/@Authority. May benull.- Returns:
trueif the value is valid,falseotherwise.
-
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 withisValidReceiverAuthority(String). This parameter is present to allow for different identifier checks for different authorities. May benull.sReceiverIdentifier- The value to be checked. This conforms to the XML element value ofReceiver/Identifier. May benull.- Returns:
trueif the value is valid for the given authority,falseotherwise.
-
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 ofBusinessScope/Scope[Type/text()="DOCUMENTID"]/InstanceIdentifier. May benull.- Returns:
trueif the value is valid,falseotherwise.
-
isValidProcessIdentifier
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 ofBusinessScope/Scope[Type/text()="PROCESSID"]/InstanceIdentifier. May benull.- Returns:
trueif the value is valid,falseotherwise.
-
isValidCountryC1
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 ofBusinessScope/Scope[Type/text()="COUNTRY_C1"]/InstanceIdentifier. May benull.- Returns:
trueif the value is valid,falseotherwise.
-
isValidMLSTo
Check if the provided MLS addressee (from MLS_TO field) is valid or not.- Parameters:
sScheme- The participant identifier scheme. May benull.sValue- The participant identifier value. May benull.- Returns:
trueif the MLS addressee is considered valid,falseif not.- Since:
- 10.3.3
-
isValidMLSType
Check if the provided MLS type (from MLS_TYPE field) is valid or not.- Parameters:
sType- The type to check. May benull.- Returns:
trueif the MLS type is considered valid,falseif not.- Since:
- 10.3.3
-
isValidBusinessMessage
Check if the passed business message is valid or not. By default this method always returnstruesince the element is nevernulland no UBL specific checks are performed. Override this method to perform further or other checks.- Parameters:
aBusinessMessage- The business message element to check against. Nevernull.- Returns:
trueif the value is valid,falseotherwise.
-
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 benull.aBusinessMessage- The business message element to check against. Nevernull.sDocumentTypeIdentifierValue- The document type identifier value provided. Nevernull.- Returns:
trueif the value is valid,falseotherwise.
-
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 benull.aBusinessMessage- The business message element to check against. Nevernull.sDocumentTypeIdentifierValue- The document type identifier value provided. Nevernull.- Returns:
trueif the value is valid,falseotherwise.
-
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 benull.aBusinessMessage- The business message element to check against. Nevernull.- Returns:
trueif the value is valid,falseotherwise.
-
isValidInstanceIdentifier
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 benull.- Returns:
trueif the value is valid,falseotherwise.
-
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 benull. Override this method to perform further or other checks.- Parameters:
aCreationDateTime- The value to be checked. This corresponds to the field "DocumentIdentification/CreationDateAndTime". Is nevernull.- Returns:
trueif the value is valid,falseotherwise.
-
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
SBDMarshallerand nevernull.
-
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 benull.- 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 benull.- 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 benull.- 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 benull.- 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 benull.aBusinessMessage- The Business Message to be validated (this does NOT mean Schematron validation). Must not benull.aErrorList- The error list to be filled. Must not benull.
-
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 ifisPerformValueChecks()istrue.- Parameters:
aSBDH- The header object to read from. May not benull.aBusinessMessage- The main business message (XML payload) to extract data from. May not benull.- 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 benull.aBusinessMessage- The main business message (XML payload) to extract data from. May not benull.- Returns:
- The document data and never
null. - Since:
- 9.2.2
-