use of com.helger.phive.api.result.ValidationResultList in project phase4 by phax.
the class Phase4PeppolValidation method validateOutgoingBusinessDocument.
/**
* Validate the passed DOM element using the provided VESID using the provided
* registry.
*
* @param aXML
* The XML element to be validated. May not be <code>null</code>.
* @param aVESRegistry
* The VES registry the VESID is looked up in.
* @param aVESID
* The {@link VESID} to be used. Must be contained in the provided
* registry. May not be <code>null</code>.
* @param aValidationResultHandler
* The validation result handler to be used. May not be
* <code>null</code>.
* @throws Phase4PeppolException
* In case e.g. the validation failed. This usually implies, that the
* document will NOT be send out.
* @since 0.10.1
*/
public static void validateOutgoingBusinessDocument(@Nonnull final Element aXML, @Nonnull final IValidationExecutorSetRegistry<IValidationSourceXML> aVESRegistry, @Nonnull final VESID aVESID, @Nonnull final IPhase4PeppolValidationResultHandler aValidationResultHandler) throws Phase4PeppolException {
ValueEnforcer.notNull(aXML, "XMLElement");
ValueEnforcer.notNull(aVESRegistry, "VESRegistry");
ValueEnforcer.notNull(aVESID, "VESID");
ValueEnforcer.notNull(aValidationResultHandler, "ValidationResultHandler");
final IValidationExecutorSet<IValidationSourceXML> aVES = aVESRegistry.getOfID(aVESID);
if (aVES == null)
throw new Phase4PeppolException("The validation executor set ID " + aVESID.getAsSingleID() + " is unknown!");
final ValidationResultList aValidationResult = ValidationExecutionManager.executeValidation(aVES, ValidationSourceXML.create(null, aXML));
if (aValidationResult.containsAtLeastOneError()) {
aValidationResultHandler.onValidationErrors(aValidationResult);
LOGGER.warn("Continue to send AS4 message, although validation errors are contained!");
} else
aValidationResultHandler.onValidationSuccess(aValidationResult);
}
use of com.helger.phive.api.result.ValidationResultList in project phase4 by phax.
the class MainPhase4PeppolSender method main.
public static void main(final String[] args) {
// Provide context
WebScopeManager.onGlobalBegin(MockServletContext.create());
final File aSCPath = AS4Configuration.getDumpBasePathFile();
WebFileIO.initPaths(aSCPath, aSCPath.getAbsolutePath(), false);
// Dump (for debugging purpose only)
AS4DumpManager.setIncomingDumper(new AS4IncomingDumperFileBased());
AS4DumpManager.setOutgoingDumper(new AS4OutgoingDumperFileBased());
try {
final Element aPayloadElement = DOMReader.readXMLDOM(new File("src/test/resources/examples/base-example.xml")).getDocumentElement();
if (aPayloadElement == null)
throw new IllegalStateException("Failed to read XML file to be send");
// Start configuring here
IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9958:peppol-development-governikus-01");
if (false)
aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("0088:5050689000018as4");
final ESimpleUserMessageSendResult eResult;
eResult = Phase4PeppolSender.builder().documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:2017:poacc:billing:01:1.0")).senderParticipantID(Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9915:phase4-test-sender")).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aPayloadElement).smpClient(new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST)).rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).validationConfiguration(PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3, new Phase4PeppolValidatonResultHandler() {
@Override
public void onValidationSuccess(final ValidationResultList aValidationResult) {
LOGGER.info("Successfully validated XML payload");
}
}).sendMessageAndCheckForReceipt();
LOGGER.info("Peppol send result: " + eResult);
} catch (final Exception ex) {
LOGGER.error("Error sending Peppol message via AS4", ex);
} finally {
WebScopeManager.onGlobalEnd();
}
}
use of com.helger.phive.api.result.ValidationResultList in project en16931-cii2ubl by phax.
the class CIIToUBL22ConverterTest method testConvertAndValidateAll.
@Test
public void testConvertAndValidateAll() {
final String sBasePath = MockSettings.getBaseDir().getAbsolutePath();
for (final File aFile : MockSettings.getAllTestFiles()) {
LOGGER.info("Converting " + aFile.toString() + " to UBL 2.2");
// Main conversion
final ErrorList aErrorList = new ErrorList();
final Serializable aInvoice = new CIIToUBL22Converter().convertCIItoUBL(aFile, aErrorList);
assertTrue("Errors: " + aErrorList.toString(), aErrorList.isEmpty());
assertNotNull(aInvoice);
final File aDestFile = new File("toubl22/" + aFile.getParentFile().getAbsolutePath().substring(sBasePath.length()), FilenameHelper.getBaseName(aFile.getName()) + "-ubl.xml");
final ValidationResultList aResultList;
if (aInvoice instanceof InvoiceType) {
final InvoiceType aUBLInvoice = (InvoiceType) aInvoice;
// Check UBL XSD scheme
final UBL22WriterBuilder<InvoiceType> aWriter = UBL22Writer.invoice().setFormattedOutput(true);
aWriter.write(aUBLInvoice, aDestFile);
// Validate against EN16931 validation rules
aResultList = ValidationExecutionManager.executeValidation(MockSettings.VES_REGISTRY.getOfID(EN16931Validation.VID_UBL_INVOICE_137), ValidationSourceXML.create(new FileSystemResource(aDestFile)));
} else {
final CreditNoteType aUBLInvoice = (CreditNoteType) aInvoice;
// Check UBL XSD scheme
final UBL22WriterBuilder<CreditNoteType> aWriter = UBL22Writer.creditNote().setFormattedOutput(true);
aWriter.write(aUBLInvoice, aDestFile);
// Validate against EN16931 validation rules
aResultList = ValidationExecutionManager.executeValidation(MockSettings.VES_REGISTRY.getOfID(EN16931Validation.VID_UBL_CREDIT_NOTE_137), ValidationSourceXML.create(new FileSystemResource(aDestFile)));
}
assertNotNull(aResultList);
// Check that no errors (but maybe warnings) are contained
for (final ValidationResult aResult : aResultList) {
assertTrue("Errors: " + aResult.getErrorList().toString(), aResult.getErrorList().isEmpty());
}
}
}
Aggregations