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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPeppolSBDHDataReader(com.helger.peppolid.factory.IIdentifierFactory aIdentifierFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.helger.sbdh.SBDMarshallerCreate a new SBD marshaller used for reading SBD documents.extractData(com.helger.commons.io.resource.IReadableResource aStandardBusinessDocument) Extract the document data from the Standard Business Document represents by the passed parameter.extractData(InputStream aStandardBusinessDocument) Extract the document data from the Standard Business Document represents by the passed parameter.extractData(org.unece.cefact.namespaces.sbdh.StandardBusinessDocument aStandardBusinessDocument) Extract the document data from the Standard Business Document represents by the passed parameter.extractData(org.unece.cefact.namespaces.sbdh.StandardBusinessDocumentHeader aSBDH, Element aBusinessMessage) Extract the document data from the Standard Business Document represents by the passed parameter.extractData(Node aStandardBusinessDocument) Extract the document data from the Standard Business Document represents by the passed parameter.extractDataUnchecked(org.unece.cefact.namespaces.sbdh.StandardBusinessDocumentHeader aSBDH, Element aBusinessMessage) Extract the document data from the Standard Business Document represents by the passed parameter without any value checks.final com.helger.peppolid.factory.IIdentifierFactoryfinal booleanIn case of value checks, should the Country C1 also be checked?final booleanprotected booleanisValidBusinessMessage(Element aBusinessMessage) Check if the passed business message is valid or not.protected booleanisValidCountryC1(String sCountryC1) Check if the passed C1 country code is valid or not.protected booleanisValidCreationDateTime(com.helger.commons.datetime.XMLOffsetDateTime aCreationDateTime) Check if the passed document identification creation date time is valid or not.protected booleanisValidDocumentTypeIdentifier(String sDocumentTypeIdentifier) Check if the passed document type identifier value is valid or not.protected booleanisValidHeaderVersion(String sHeaderVersion) Check if the passed header version is valid or not.protected booleanisValidInstanceIdentifier(String sInstanceIdentifier) Check if the passed document identification instance identifier is valid or not.protected booleanisValidProcessIdentifier(String sProcessIdentifier) Check if the passed process identifier value is valid or not.protected booleanisValidReceiverAuthority(String sReceiverAuthority) Check if the passed receiver authority is valid or not.protected booleanisValidReceiverIdentifier(String sReceiverAuthority, String sReceiverIdentifier) Check if the passed receiver identifier is valid or not.protected booleanisValidSenderAuthority(String sSenderAuthority) Check if the passed sender authority is valid or not.protected booleanisValidSenderIdentifier(String sSenderAuthority, String sSenderIdentifier) Check if the passed sender identifier is valid or not.protected booleanisValidStandard(String sStandard, Element aBusinessMessage, String sDocumentTypeIdentifierValue) Check if the passed document identification standard is valid or not.protected booleanisValidType(String sType, Element aBusinessMessage) Check if the passed document identification type is valid or not.protected booleanisValidTypeVersion(String sTypeVersion, Element aBusinessMessage, String sDocumentTypeIdentifierValue) Check if the passed document identification type version is valid or not.final PeppolSBDHDataReadersetCheckForCountryC1(boolean b) Enable or disable the checking for C1 country code.final PeppolSBDHDataReadersetPerformValueChecks(boolean b) Enable or disable the performing of value checks on data extraction.voidvalidateData(org.unece.cefact.namespaces.sbdh.StandardBusinessDocumentHeader aSBDH, Element aBusinessMessage, 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.
-
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
- See Also:
-
-
Constructor Details
-
PeppolSBDHDataReader
public PeppolSBDHDataReader(@Nonnull com.helger.peppolid.factory.IIdentifierFactory aIdentifierFactory)
-
-
Method Details
-
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
public final boolean isCheckForCountryC1()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
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.
-
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.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 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
Create a new SBD marshaller used for reading SBD documents. Override this method to customize reading.- Returns:
- An instance of the
SBDMarshallerand nevernull.
-
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 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
@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 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
@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 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
@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 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.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 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
@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 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
@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 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
-