From 088edd2b79aaa22d2cea57605d819c2098b64a0d Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Mon, 11 May 2020 08:22:44 -0400 Subject: [PATCH 1/2] Add getControlSchema to SchemaFactory, add Multi-Release to MANIFEST --- pom.xml | 9 ++++++++- .../edi/internal/schema/StaEDISchemaFactory.java | 5 +++++ .../java/io/xlate/edi/schema/SchemaFactory.java | 13 +++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 202279c5..473dfdc0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ io.xlate staedi - 1.4.2-SNAPSHOT + 1.5.0-SNAPSHOT StAEDI : Streaming API for EDI for Java Streaming API for EDI for Java @@ -106,6 +106,13 @@ org.apache.maven.plugins maven-jar-plugin 3.2.0 + + + + true + + + org.apache.maven.plugins diff --git a/src/main/java/io/xlate/edi/internal/schema/StaEDISchemaFactory.java b/src/main/java/io/xlate/edi/internal/schema/StaEDISchemaFactory.java index 0fbf3a5b..40f56d65 100644 --- a/src/main/java/io/xlate/edi/internal/schema/StaEDISchemaFactory.java +++ b/src/main/java/io/xlate/edi/internal/schema/StaEDISchemaFactory.java @@ -107,6 +107,11 @@ public Schema createSchema(URL location) throws EDISchemaException { } } + @Override + public Schema getControlSchema(String standard, String[] version) throws EDISchemaException { + return SchemaUtils.getControlSchema(standard, version); + } + @Override public boolean isPropertySupported(String name) { return supportedProperties.contains(name); diff --git a/src/main/java/io/xlate/edi/schema/SchemaFactory.java b/src/main/java/io/xlate/edi/schema/SchemaFactory.java index e4eba18b..c0f54f30 100644 --- a/src/main/java/io/xlate/edi/schema/SchemaFactory.java +++ b/src/main/java/io/xlate/edi/schema/SchemaFactory.java @@ -37,6 +37,19 @@ public static SchemaFactory newFactory() { public abstract Schema createSchema(InputStream stream) throws EDISchemaException; + /** + * Retrieve the control schema for the provided standard and version. This method + * loads an internal, immutable schema provided by StAEDI. + * + * @param standard the standard, e.g. X12 or EDIFACT + * @param version the version of the standard + * @return the control schema corresponding to the standard and version + * @throws EDISchemaException when the schema can not be loaded. + * + * @since 1.5 + */ + public Schema getControlSchema(String standard, String[] version) throws EDISchemaException; + /** * Query the set of properties that this factory supports. * From ea09b66b23de92ebfb4bb2299876124463f5aeb0 Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Mon, 11 May 2020 08:41:52 -0400 Subject: [PATCH 2/2] Add test for getControlSchema --- .../edi/internal/schema/StaEDISchemaFactoryTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/io/xlate/edi/internal/schema/StaEDISchemaFactoryTest.java b/src/test/java/io/xlate/edi/internal/schema/StaEDISchemaFactoryTest.java index a3c4bbbb..9402bed4 100644 --- a/src/test/java/io/xlate/edi/internal/schema/StaEDISchemaFactoryTest.java +++ b/src/test/java/io/xlate/edi/internal/schema/StaEDISchemaFactoryTest.java @@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test; import io.xlate.edi.schema.EDISchemaException; +import io.xlate.edi.schema.EDIType; import io.xlate.edi.schema.Schema; import io.xlate.edi.schema.SchemaFactory; import io.xlate.edi.stream.EDIStreamConstants.Standards; @@ -253,4 +254,14 @@ public void testDuplicateElementTypeNames() { assertNotNull(cause); assertEquals("duplicate name: DE0004", cause.getMessage()); } + + @Test + public void testGetControlSchema() throws EDISchemaException { + SchemaFactory factory = SchemaFactory.newFactory(); + Schema schema = factory.getControlSchema(Standards.X12, new String[] { "00501" }); + assertNotNull(schema); + assertEquals(EDIType.Type.SEGMENT, schema.getType("ISA").getType()); + assertEquals(EDIType.Type.SEGMENT, schema.getType("GS").getType()); + assertEquals(EDIType.Type.SEGMENT, schema.getType("ST").getType()); + } }