Search in sources :

Example 6 with ValidationResultList

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);
}
Also used : ValidationResultList(com.helger.phive.api.result.ValidationResultList) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML)

Example 7 with ValidationResultList

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();
    }
}
Also used : SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) ValidationResultList(com.helger.phive.api.result.ValidationResultList) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 8 with ValidationResultList

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());
        }
    }
}
Also used : Serializable(java.io.Serializable) ErrorList(com.helger.commons.error.list.ErrorList) ValidationResultList(com.helger.phive.api.result.ValidationResultList) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) ValidationResult(com.helger.phive.api.result.ValidationResult) File(java.io.File) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType) Test(org.junit.Test)

Aggregations

ValidationResultList (com.helger.phive.api.result.ValidationResultList)8 ErrorList (com.helger.commons.error.list.ErrorList)4 ValidationResult (com.helger.phive.api.result.ValidationResult)4 File (java.io.File)4 Test (org.junit.Test)4 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)3 Serializable (java.io.Serializable)3 CrossIndustryInvoiceType (un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType)3 IJsonObject (com.helger.json.IJsonObject)2 IValidationSourceXML (com.helger.phive.engine.source.IValidationSourceXML)2 IError (com.helger.commons.error.IError)1 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)1 IReadableResource (com.helger.commons.io.resource.IReadableResource)1 ETriState (com.helger.commons.state.ETriState)1 IJson (com.helger.json.IJson)1 IJsonArray (com.helger.json.IJsonArray)1 JsonObject (com.helger.json.JsonObject)1 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)1 AS4IncomingDumperFileBased (com.helger.phase4.dump.AS4IncomingDumperFileBased)1 AS4OutgoingDumperFileBased (com.helger.phase4.dump.AS4OutgoingDumperFileBased)1