Search in sources :

Example 1 with ValidationExecutorSet

use of com.helger.phive.api.executorset.ValidationExecutorSet 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 ValidationExecutorSet

use of com.helger.phive.api.executorset.ValidationExecutorSet in project phive by phax.

the class PhiveJsonHelperTest method testValidationResultsBackAndForth.

@Test
public void testValidationResultsBackAndForth() {
    // Register
    final ValidationExecutorSetRegistry<IValidationSourceXML> aRegistry = new ValidationExecutorSetRegistry<>();
    final VESID aVESID = new VESID("group", "art", "1.0");
    final ValidationExecutorSet<IValidationSourceXML> aVES = new ValidationExecutorSet<>(aVESID, "name", false);
    aVES.addExecutor(ValidationExecutorXSD.create(new ClassPathResource("test/schema1.xsd")));
    aRegistry.registerValidationExecutorSet(aVES);
    // Validate
    final ValidationResultList aVRL = ValidationExecutionManager.executeValidation(aVES, ValidationSourceXML.create(new ClassPathResource("test/schema1.xml")));
    assertTrue(aVRL.containsAtLeastOneError());
    // To JSON
    final Locale aDisplayLocale = Locale.US;
    final IJsonObject aObj = new JsonObject();
    PhiveJsonHelper.applyValidationResultList(aObj, aVES, aVRL, aDisplayLocale, 123, null, null);
    // And back
    final IValidationExecutorSet<IValidationSourceXML> aVES2 = PhiveJsonHelper.getAsVES(aRegistry, aObj);
    assertNotNull(aVES2);
    assertSame(aVES, aVES2);
    final ValidationResultList aVRL2 = PhiveJsonHelper.getAsValidationResultList(aObj);
    assertNotNull(aVRL2);
    // direct equals doesn't work, because of the restored exception
    assertEquals(aVRL.size(), aVRL2.size());
    assertEquals(1, aVRL.size());
    assertEquals(aVRL.get(0).getErrorList().size(), aVRL2.get(0).getErrorList().size());
    // and forth
    final IJsonObject aObj2 = new JsonObject();
    PhiveJsonHelper.applyValidationResultList(aObj2, aVES2, aVRL2, aDisplayLocale, 123, null, null);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aObj, aObj2);
}
Also used : ValidationExecutorSet(com.helger.phive.api.executorset.ValidationExecutorSet) IValidationExecutorSet(com.helger.phive.api.executorset.IValidationExecutorSet) Locale(java.util.Locale) VESID(com.helger.phive.api.executorset.VESID) IJsonObject(com.helger.json.IJsonObject) ValidationResultList(com.helger.phive.api.result.ValidationResultList) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) ValidationExecutorSetRegistry(com.helger.phive.api.executorset.ValidationExecutorSetRegistry) Test(org.junit.Test)

Example 3 with ValidationExecutorSet

use of com.helger.phive.api.executorset.ValidationExecutorSet in project phive by phax.

the class VOM1ConverterTest method testReadGoodExamples.

@Test
public void testReadGoodExamples() {
    final VOM1Marshaller m = new VOM1Marshaller();
    for (final File f : new FileSystemIterator(new File("src/test/resources/vom/good")).withFilter(IFileFilter.filenameEndsWith(".xml"))) {
        LOGGER.info("Reading " + f.getName());
        final VOMType aVOM = m.read(f);
        assertNotNull(aVOM);
        final IReadableResource aFakeXSD = new ReadableResourceByteArray("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"urn:1\" targetNamespace=\"urn:a\" version=\"1.0\"><xs:element name=\"a\" type=\"xs:string\" /></xs:schema>".getBytes(StandardCharsets.ISO_8859_1));
        final Schema aFakeSchema = XMLSchemaCache.getInstance().getSchema(aFakeXSD);
        final IVOMXmlSchemaResolver aXmlSchemaResolver = new MapBasedVOMXmlSchemaResolver().addMapping("ubl21-invoice", aFakeSchema);
        final IVOMNamespaceContextResolver aNamespaceContextResolver = new MapBasedVOMNamespaceContextResolver().addMapping("ubl21", new MapBasedNamespaceContext().addMapping("a", "urn:a"));
        final IVOMResourceResolver aResourceResolver = new MapBasedVOMResourceResolver().addMapping("cius-pt-200", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("cius-pt-201", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("atnat-invoice-6", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("xrechnung-ublinv-200", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("en16931-ublinv-132", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY));
        final IVOMArtifactResolver aAR = aVESID -> {
            switch(aVESID.getAsSingleID()) {
                case "com.helger:test-special:1.5.678":
                    return new ReadableResourceByteArray("crap".getBytes(StandardCharsets.ISO_8859_1));
            }
            return null;
        };
        final IEdifactValidationExecutorProviderXML aEdifactProvider = (sDirectory, sMessage, aOptions) -> {
            if (sDirectory.equals("d01b") && sMessage.equals("DESADV"))
                return ValidationExecutorXSD.create(aFakeXSD);
            return null;
        };
        final VOM1ComplianceSettings aSettings = VOM1ComplianceSettings.builder().allowEdifact(true).edifactValidationExecutorProviderXML(aEdifactProvider).build();
        final ErrorList aErrorList = new ErrorList();
        final VOM1Converter aConverter1 = new VOM1Converter().xmlSchemaResolver(aXmlSchemaResolver).namespaceContextResolver(aNamespaceContextResolver).resourceResolver(aResourceResolver).complianceSettings(aSettings).artifactResolver(aAR).validationEnabled(true);
        final ValidationExecutorSet<IValidationSourceXML> aVES = aConverter1.convertToVES_XML(aVOM, aErrorList);
        assertNotNull(aErrorList.toString(), aVES);
    }
}
Also used : IEdifactValidationExecutorProviderXML(com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML) Logger(org.slf4j.Logger) ValidationExecutorSet(com.helger.phive.api.executorset.ValidationExecutorSet) Assert.assertNotNull(org.junit.Assert.assertNotNull) ErrorList(com.helger.commons.error.list.ErrorList) MapBasedNamespaceContext(com.helger.xml.namespace.MapBasedNamespaceContext) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) LoggerFactory(org.slf4j.LoggerFactory) IReadableResource(com.helger.commons.io.resource.IReadableResource) Test(org.junit.Test) FileSystemIterator(com.helger.commons.io.file.FileSystemIterator) ValidationExecutorXSD(com.helger.phive.engine.xsd.ValidationExecutorXSD) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Schema(javax.xml.validation.Schema) IFileFilter(com.helger.commons.io.file.IFileFilter) ReadableResourceByteArray(com.helger.commons.io.resource.inmemory.ReadableResourceByteArray) XMLSchemaCache(com.helger.xml.schema.XMLSchemaCache) VOMType(com.helger.phive.engine.vom.v10.VOMType) ArrayHelper(com.helger.commons.collection.ArrayHelper) VOMType(com.helger.phive.engine.vom.v10.VOMType) Schema(javax.xml.validation.Schema) IReadableResource(com.helger.commons.io.resource.IReadableResource) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) ReadableResourceByteArray(com.helger.commons.io.resource.inmemory.ReadableResourceByteArray) IEdifactValidationExecutorProviderXML(com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML) MapBasedNamespaceContext(com.helger.xml.namespace.MapBasedNamespaceContext) ErrorList(com.helger.commons.error.list.ErrorList) FileSystemIterator(com.helger.commons.io.file.FileSystemIterator) File(java.io.File) Test(org.junit.Test)

Example 4 with ValidationExecutorSet

use of com.helger.phive.api.executorset.ValidationExecutorSet in project phive by phax.

the class PhiveJsonHelperTest method testValidationResults.

@Test
public void testValidationResults() {
    final IJsonObject aObj = new JsonObject();
    final Locale aDisplayLocale = Locale.US;
    final VESID aVESID = new VESID("group", "art", "1.0");
    final IValidationExecutorSet<?> aVES = new ValidationExecutorSet<>(aVESID, "name", false);
    PhiveJsonHelper.applyValidationResultList(aObj, aVES, new CommonsArrayList<>(), aDisplayLocale, 123, null, null);
    final String sJson = aObj.getAsJsonString();
    assertEquals("{\"ves\":{\"vesid\":\"group:art:1.0\",\"name\":\"name\",\"deprecated\":false}," + "\"success\":true," + "\"interrupted\":false," + "\"mostSevereErrorLevel\":\"SUCCESS\"," + "\"results\":[]," + "\"durationMS\":123}", sJson);
}
Also used : Locale(java.util.Locale) ValidationExecutorSet(com.helger.phive.api.executorset.ValidationExecutorSet) IValidationExecutorSet(com.helger.phive.api.executorset.IValidationExecutorSet) VESID(com.helger.phive.api.executorset.VESID) IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Test(org.junit.Test)

Aggregations

ValidationExecutorSet (com.helger.phive.api.executorset.ValidationExecutorSet)4 IValidationSourceXML (com.helger.phive.engine.source.IValidationSourceXML)3 Test (org.junit.Test)3 IJsonObject (com.helger.json.IJsonObject)2 JsonObject (com.helger.json.JsonObject)2 IValidationExecutorSet (com.helger.phive.api.executorset.IValidationExecutorSet)2 VESID (com.helger.phive.api.executorset.VESID)2 Locale (java.util.Locale)2 ArrayHelper (com.helger.commons.collection.ArrayHelper)1 ErrorList (com.helger.commons.error.list.ErrorList)1 FileSystemIterator (com.helger.commons.io.file.FileSystemIterator)1 IFileFilter (com.helger.commons.io.file.IFileFilter)1 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)1 IReadableResource (com.helger.commons.io.resource.IReadableResource)1 ReadableResourceByteArray (com.helger.commons.io.resource.inmemory.ReadableResourceByteArray)1 ValidationExecutorSetRegistry (com.helger.phive.api.executorset.ValidationExecutorSetRegistry)1 ValidationResultList (com.helger.phive.api.result.ValidationResultList)1 IEdifactValidationExecutorProviderXML (com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML)1 VOMEdifactType (com.helger.phive.engine.vom.v10.VOMEdifactType)1 VOMSchematronType (com.helger.phive.engine.vom.v10.VOMSchematronType)1