diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a9f4a7..3354f6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added equivalent untis to `RexsStandardUnitIds` (`deg`, `degree`) +### Fixed + +- RexsSchemaRegistry does now find REXS Versions also based on the additional model version strings + ## [0.14.0] - 2025-07-18 diff --git a/api/src/main/java/info/rexs/schema/RexsSchemaRegistry.java b/api/src/main/java/info/rexs/schema/RexsSchemaRegistry.java index dd9ed2e..661032a 100644 --- a/api/src/main/java/info/rexs/schema/RexsSchemaRegistry.java +++ b/api/src/main/java/info/rexs/schema/RexsSchemaRegistry.java @@ -50,14 +50,14 @@ public class RexsSchemaRegistry implements IRexsSchemaRegistry { private static RexsSchemaRegistry instance = null; - private Map versions = new HashMap<>(); - private Map> componentMap = new HashMap<>(); - private Map> attributeUnits = new HashMap<>(); - private Map> attributeTypes = new HashMap<>(); - private Map> attributeMap = new HashMap<>(); - private Map>> attributeToComponentMap = new HashMap<>(); - private Map>> componentToAttributesMap = new HashMap<>(); - private Map>>> relationsToAllowedCombinationsMap = new HashMap<>(); + private final Map versions = new HashMap<>(); + private final Map> componentMap = new HashMap<>(); + private final Map> attributeUnits = new HashMap<>(); + private final Map> attributeTypes = new HashMap<>(); + private final Map> attributeMap = new HashMap<>(); + private final Map>> attributeToComponentMap = new HashMap<>(); + private final Map>> componentToAttributesMap = new HashMap<>(); + private final Map>>> relationsToAllowedCombinationsMap = new HashMap<>(); private RexsSchemaRegistry() { try { @@ -92,7 +92,10 @@ public void registerRexsVersion(RexsVersion version) { if (rexsSchema == null) throw new IllegalStateException(String.format("rexs db model for version %s not found", version.getModelVersion())); registerRexsSchema(version, rexsSchema); + // register primary version versions.put(version.getModelVersion(), version); + // register additional versions + version.getAdditionalModelVersions().forEach(additionalVersion -> versions.put(additionalVersion, version)); } private void registerRexsSchema(RexsVersion version, RexsSchema rexsSchema) { @@ -323,7 +326,7 @@ public List getAttributeIdsOfComponentType(RexsComponentType rexsCompone @Override public RexsVersion getVersion(String version) { - return versions.get(version); + return versions.getOrDefault(version, RexsVersion.UNKNOWN); } @Override diff --git a/api/src/main/java/info/rexs/schema/RexsSchemaResolver.java b/api/src/main/java/info/rexs/schema/RexsSchemaResolver.java index 488f195..d4abbd7 100644 --- a/api/src/main/java/info/rexs/schema/RexsSchemaResolver.java +++ b/api/src/main/java/info/rexs/schema/RexsSchemaResolver.java @@ -19,11 +19,10 @@ import java.util.HashMap; import java.util.Map; -import jakarta.xml.bind.JAXBContext; -import jakarta.xml.bind.Unmarshaller; - import info.rexs.schema.constants.RexsVersion; import info.rexs.schema.jaxb.RexsSchema; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.Unmarshaller; /** * This class provides the REXS schemas of all available REXS versions (REXS standard and own). @@ -36,7 +35,7 @@ public class RexsSchemaResolver { private static RexsSchemaResolver instance = null; /** An internal index with all created REXS schemas (REXS standard and own) for quick access. */ - private Map rexsSchemaFileCache = new HashMap<>(); + private final Map rexsSchemaFileCache = new HashMap<>(); private RexsSchemaResolver() {} diff --git a/api/src/main/java/info/rexs/schema/constants/RexsVersion.java b/api/src/main/java/info/rexs/schema/constants/RexsVersion.java index d4e452f..4337a75 100644 --- a/api/src/main/java/info/rexs/schema/constants/RexsVersion.java +++ b/api/src/main/java/info/rexs/schema/constants/RexsVersion.java @@ -49,6 +49,35 @@ public class RexsVersion { */ private final String modelVersion; + /** + * Additional (case-insensitive) identifiers of the versions in the REXS model. + */ + private final List additionalModelVersions = new ArrayList<>(); + + /** + * Gets the additional model versions. + * + * @return A list of additional model versions. + */ + public List getAdditionalModelVersions() { + return new ArrayList<>(additionalModelVersions); + } + + /** + * Creates a new REXS version with additional model versions. + * + * @param schemaVersion The (case-insensitive) identifier of the version in the REXS schema. + * @param schemaProvider The (case-insensitive) identifier of the provider in the REXS schema. + * @param modelVersion The (case-insensitive) identifier of the version in the REXS model. + * @param additionalModelVersions Additional (case-insensitive) identifiers of the versions inthe REXS model. + */ + private RexsVersion(String schemaVersion, String schemaProvider, String modelVersion, List additionalModelVersions) { + this.schemaVersion = schemaVersion; + this.schemaProvider = schemaProvider; + this.modelVersion = modelVersion; + this.additionalModelVersions.addAll(additionalModelVersions); + } + /** * Creates a new REXS version. * @@ -89,7 +118,7 @@ public static RexsVersion create(String schemaVersion, String schemaProvider, St throw new IllegalArgumentException("schemaVersion must follow the pattern X.X"); // create the primary version - RexsVersion primaryVersion = new RexsVersion(schemaVersion, schemaProvider, primaryModelVersion); + RexsVersion primaryVersion = new RexsVersion(schemaVersion, schemaProvider, primaryModelVersion, List.of(additionalModelVersions)); allModelVersions.put(primaryVersion.getModelVersion(), primaryVersion); // register additional versions diff --git a/api/src/test/java/info/rexs/schema/RexsSchemaRegistryTest.java b/api/src/test/java/info/rexs/schema/RexsSchemaRegistryTest.java new file mode 100644 index 0000000..523faf9 --- /dev/null +++ b/api/src/test/java/info/rexs/schema/RexsSchemaRegistryTest.java @@ -0,0 +1,19 @@ +package info.rexs.schema; + +import info.rexs.schema.constants.RexsVersion; +import info.rexs.schema.constants.standard.RexsStandardVersions; +import junit.framework.TestCase; + +public class RexsSchemaRegistryTest extends TestCase { + + public void testGetVersion() { + // find version by primary model version + assertEquals(RexsStandardVersions.V1_0, RexsSchemaRegistry.getInstance().getVersion("1.0")); + + // find version by additional model version + assertEquals(RexsStandardVersions.V1_0, RexsSchemaRegistry.getInstance().getVersion("0.90")); + + // invalid version returns UNKNOWN + assertEquals(RexsVersion.UNKNOWN, RexsSchemaRegistry.getInstance().getVersion("9.9")); + } +}