Search in sources :

Example 1 with VOMEdifactType

use of com.helger.phive.engine.vom.v10.VOMEdifactType in project phive by phax.

the class VOM1Converter method convertToVES_XML.

@Nullable
public ValidationExecutorSet<IValidationSourceXML> convertToVES_XML(@Nonnull final VOMType aVOM, @Nonnull final ErrorList aErrorList) {
    ValueEnforcer.notNull(aVOM, "VOM");
    ValueEnforcer.notNull(aErrorList, "ErrorList");
    if (m_bPerformValidation) {
        VOM1Validator.validate(aVOM, m_aXmlSchemaResolver, m_aNamespaceContextResolver, m_aResourceResolver, m_aComplianceSettings, aErrorList);
        if (aErrorList.containsAtLeastOneError())
            return null;
    }
    // Create stub
    final ValidationExecutorSet<IValidationSourceXML> ret = new ValidationExecutorSet<>(_createVESID(aVOM.getId()), aVOM.getName(), false);
    if (m_aComplianceSettings.isAllowEdifact() && aVOM.getValidation().hasEdifactEntries()) {
        if (aVOM.getValidation().hasXsdEntries())
            throw new IllegalStateException("If Edifact is enabled and present, than no XSD can be present!");
        // Add all Edifacts
        for (final VOMEdifactType aEdifact : aVOM.getValidation().getEdifact()) ret.addExecutor(_createExecutorEdifact(aEdifact));
    } else {
        // Add all XSDs
        for (final VOMXSDType aXsd : aVOM.getValidation().getXsd()) ret.addExecutor(_createExecutorXSD(aXsd));
    }
    // Add all XSDs
    for (final VOMSchematronType aSchematron : aVOM.getValidation().getSchematron()) ret.addExecutor(_createExecutorSchematron(aSchematron));
    return ret;
}
Also used : ValidationExecutorSet(com.helger.phive.api.executorset.ValidationExecutorSet) VOMSchematronType(com.helger.phive.engine.vom.v10.VOMSchematronType) VOMEdifactType(com.helger.phive.engine.vom.v10.VOMEdifactType) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) VOMXSDType(com.helger.phive.engine.vom.v10.VOMXSDType) Nullable(javax.annotation.Nullable)

Example 2 with VOMEdifactType

use of com.helger.phive.engine.vom.v10.VOMEdifactType in project phive by phax.

the class VOM1Converter method _createExecutorEdifact.

@Nonnull
private IValidationExecutor<IValidationSourceXML> _createExecutorEdifact(@Nonnull final VOMEdifactType aEdifact) {
    final IEdifactValidationExecutorProviderXML aProvider = m_aComplianceSettings.getEdifactValidationExecutorProviderXML();
    final StringMap aOptions = new StringMap();
    for (final VOMOptionType aOption : aEdifact.getOption()) aOptions.put(aOption.getName(), aOption.getValue());
    LOGGER.info("Trying to resolve Edifact artifact '" + aEdifact.getDirectory() + '/' + aEdifact.getMessage() + "'");
    final IValidationExecutor<IValidationSourceXML> aVES = aProvider.createValidationExecutor(aEdifact.getDirectory(), aEdifact.getMessage(), aOptions);
    if (aVES == null)
        throw new IllegalStateException("Failed to resolve Edifact artifact '" + aEdifact.getDirectory() + '/' + aEdifact.getMessage() + "'");
    return aVES;
}
Also used : StringMap(com.helger.commons.collection.attr.StringMap) VOMOptionType(com.helger.phive.engine.vom.v10.VOMOptionType) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) IEdifactValidationExecutorProviderXML(com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML) Nonnull(javax.annotation.Nonnull)

Example 3 with VOMEdifactType

use of com.helger.phive.engine.vom.v10.VOMEdifactType in project phive by phax.

the class VOM1Validator method validateValidation.

public static void validateValidation(@Nonnull final String sXPath, @Nullable final VOMValidationType aValidation, @Nonnull final IVOMXmlSchemaResolver aXmlSchemaResolver, @Nonnull final IVOMNamespaceContextResolver aNamespaceContextResolver, @Nonnull final IVOMResourceResolver aResourceResolver, @Nonnull final VOM1ComplianceSettings aSettings, @Nonnull final ErrorList aErrorList) {
    if (aValidation == null) {
        aErrorList.add(_createError(EVOMErrorCode.REQUIRED, sXPath));
    } else {
        // validation element is present
        if (aValidation.getXsdCount() + aValidation.getEdifactCount() + aValidation.getSchematronCount() == 0)
            aErrorList.add(_createError(EVOMErrorCode.NO_VALIDATION_RULES, sXPath));
        else {
            // XSD
            // XML uses 1-based indices
            int nIndex = 1;
            for (final VOMXSDType aXSD : aValidation.getXsd()) {
                validateXSD(sXPath + "/xsd[" + nIndex + "]", aXSD, aXmlSchemaResolver, aErrorList);
                ++nIndex;
            }
            // Edifact
            if (aSettings.isAllowEdifact()) {
                nIndex = 1;
                for (final VOMEdifactType aEdifact : aValidation.getEdifact()) {
                    validateEdifact(sXPath + "/edifact[" + nIndex + "]", aEdifact, aErrorList);
                    ++nIndex;
                }
            } else {
                if (!aValidation.getEdifact().isEmpty())
                    aErrorList.add(_createError(EVOMErrorCode.EDIFACT_NOT_ALLOWED, sXPath));
            }
            // Schematron
            nIndex = 1;
            for (final VOMSchematronType aSchematron : aValidation.getSchematron()) {
                validateSchematron(sXPath + "/schematron[" + nIndex + "]", aSchematron, aNamespaceContextResolver, aResourceResolver, aErrorList);
                ++nIndex;
            }
        }
    }
}
Also used : VOMSchematronType(com.helger.phive.engine.vom.v10.VOMSchematronType) VOMEdifactType(com.helger.phive.engine.vom.v10.VOMEdifactType) VOMXSDType(com.helger.phive.engine.vom.v10.VOMXSDType)

Aggregations

IValidationSourceXML (com.helger.phive.engine.source.IValidationSourceXML)2 VOMEdifactType (com.helger.phive.engine.vom.v10.VOMEdifactType)2 VOMSchematronType (com.helger.phive.engine.vom.v10.VOMSchematronType)2 VOMXSDType (com.helger.phive.engine.vom.v10.VOMXSDType)2 StringMap (com.helger.commons.collection.attr.StringMap)1 ValidationExecutorSet (com.helger.phive.api.executorset.ValidationExecutorSet)1 IEdifactValidationExecutorProviderXML (com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML)1 VOMOptionType (com.helger.phive.engine.vom.v10.VOMOptionType)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1