Skip to content

GH-3: Allow any cim namespace URIs#5

Open
bern-soptim wants to merge 3 commits intoSOPTIM:mainfrom
bern-soptim:GT-3-Allow-any-cim-namespace-URIs
Open

GH-3: Allow any cim namespace URIs#5
bern-soptim wants to merge 3 commits intoSOPTIM:mainfrom
bern-soptim:GT-3-Allow-any-cim-namespace-URIs

Conversation

@bern-soptim
Copy link
Copy Markdown
Collaborator

Solves: Allow any cim namespace URIs #3

The CIMXML library now supports any cim namespace and a configurable mapping of cim namespace URIs to custom CimProfile implementations besides the existing CimProfile16, CimProfile17 and CimProfile18.

For this mapping, the CimNamespaceMapper has been introduced.

The static enum CimVersion has be removed and all usages have been replaced by the namespace URIs.

Before, there was a fixed set of cim namespaces supported by the CIMXML library:

"http://iec.ch/TC57/2013/CIM-schema-cim16#" -> CimVersion.CIM_16; "http://iec.ch/TC57/CIM100#" -> CimVersion.CIM_17; "https://cim.ucaiug.io/ns#" -> CimVersion.CIM_18;
anything else: CimVersion.NO_CIM;

Objects.requireNonNull(cimNamespace, "cimNamespace");
final var profile = headerProfilesByCimNamespace.get(cimNamespace);
if (profile == null)
return null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note on this code path: This method is public and returns a Map, so it should not return null. Please return an empty map instead (e.g., Map.of()), so callers don’t need additional null checks and we avoid potential NullPointerExceptions.

Suggested change
return null;
return Map.of();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I use Collections.emptyMap() now.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a HashMap via ctor with known capacity, the requested capacity is not fully allocated by default.

Suggested change
final var map = HashMap.newHashMap(1_024);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was not the intention here, it should simply not start too small, as there are typically a few hundred properties in CIM/CGMES.

import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

public class CimNamespaceMapper {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like a naming smell. The class has members to register factories. It also has members to unregister factories.
Pls rename it.

Suggested change
public class CimNamespaceMapper {
public class CimNamespaceFactoryCatalog {
Suggested change
public class CimNamespaceMapper {
public class CimNamespaceFactoryRegistry {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great name, using CimNamespaceFactoryRegistry now.

Comment on lines +85 to +92
if(!isHeaderProfile) {
if (!CimProfile17.hasOntology(graph)) {
throw new IllegalArgumentException("Graph does not contain the required ontology subject for a CIM profile.");
}
if (!CimProfile17.hasVersionIRIAndKeyword(graph)) {
throw new IllegalArgumentException("Graphs ontology does not contain the required versionIRI and keyword for a CIM profile.");
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce nesting

Suggested change
if(!isHeaderProfile) {
if (!CimProfile17.hasOntology(graph)) {
throw new IllegalArgumentException("Graph does not contain the required ontology subject for a CIM profile.");
}
if (!CimProfile17.hasVersionIRIAndKeyword(graph)) {
throw new IllegalArgumentException("Graphs ontology does not contain the required versionIRI and keyword for a CIM profile.");
}
}
if (isHeaderProfile) {
return;
}
if (!CimProfile17.hasOntology(graph)) {
throw new IllegalArgumentException("Graph does not contain the required ontology subject for a CIM profile.");
}
if (!CimProfile17.hasVersionIRIAndKeyword(graph)) {
throw new IllegalArgumentException("Graphs ontology does not contain the required versionIRI and keyword for a CIM profile.");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I applied this as suggested

@bern-soptim bern-soptim force-pushed the GT-3-Allow-any-cim-namespace-URIs branch from d99c4c2 to 1a5e544 Compare February 13, 2026 13:25
Copy link
Copy Markdown

@shinji-san shinji-san left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry. During a second review, I found a few more points.

}

public static void registerProfileFactory(String namespace, Function<Graph, CimProfile> factory) {
Objects.requireNonNull(namespace, "namespace");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls define a constant instead of duplicating this literal value (namespace) four times.

public final static Node GRAPH_PRECONDITIONS = NodeFactory.createURI(GRAPH_PRECONDITIONS_URI);
public static final Node GRAPH_FORWARD_DIFFERENCES = NodeFactory.createURI(GRAPH_FORWARD_DIFFERENCES_URI);
public static final Node GRAPH_REVERSE_DIFFERENCES = NodeFactory.createURI(GRAPH_REVERSE_DIFFERENCES_URI);
public static final Node GRAPH_PRECONDITIONS = NodeFactory.createURI(GRAPH_PRECONDITIONS_URI);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, to prevent the class from being instantiated, you can define a private constructor. This will prevent the compiler from implicitly generating a public parameterless constructor.

import de.soptim.opencgmes.cimxml.graph.CimProfile;
import de.soptim.opencgmes.cimxml.graph.CimProfile17;
import de.soptim.opencgmes.cimxml.graph.CimProfile18;
import de.soptim.opencgmes.cimxml.parser.CimXmlParser;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused. Can be removed

@spah-soptim spah-soptim linked an issue Mar 2, 2026 that may be closed by this pull request
@bern-soptim bern-soptim force-pushed the GT-3-Allow-any-cim-namespace-URIs branch from 72a39f0 to 7856af0 Compare March 7, 2026 20:07
@wilu-soptim
Copy link
Copy Markdown
Collaborator

Please resolve the merge conflicts in the gitignore and pom.xml

The CIMXML library now supports any cim namespace and a configurable mapping of cim namespace URIs to custom `CimProfile` implementations besides the existing `CimProfile16`, `CimProfile17` and `CimProfile18`.

For this mapping, the `CimNamespaceFactoryRegistry` has been introduced.

The static enum `CimVersion` has be removed and all usages have been replaced by the namespace URIs.

Before, there was a fixed set of cim namespaces supported by the CIMXML library:

"http://iec.ch/TC57/2013/CIM-schema-cim16#" -> `CimVersion.`;
"http://iec.ch/TC57/CIM100#" -> `CimVersion.CIM_17`;
"https://cim.ucaiug.io/ns#" -> `CimVersion.CIM_18`;
anything else: `CimVersion.NO_CIM`;

New public method CimProfileRegistry#getMatchingProfiles to find matching profile for a given set of `owlVerionIRIs`.
--> this enables for generich JSON-LD export demonstrated in `TestConvertCimXmlToJsonLd`

Upgraded to Jena 5.6.0
Using Apache Jena `GraphFactory.createGraphMem()` instead of specific graph implementations. This makes migration easier. Especially with the renamed graph implementation in Jena 6.0 .

- added several code quality plugins
 - spotbugs-maven-plugin
 - maven-checkstyle-plugin
 - maven-pmd-plugin
 - jacoco-maven-plugin
 - license-maven-plugin
 - cyclonedx-maven-plugin (for SBOM)
- using the Google coding conventions for Java (checkstyle)
- configured IntelliJ for Google coding conventions for Java

Refactored CIMXML handling: rename classes and methods for consistency, add code style configuration, and update .gitignore.
Updated keyword for FileHeaderProfiles for compatibility with CGMES 3.0 and refactor URI handling in conversion.
@bern-soptim bern-soptim force-pushed the GT-3-Allow-any-cim-namespace-URIs branch from 7856af0 to 3af063e Compare March 17, 2026 20:31
Copy link
Copy Markdown
Collaborator

@wilu-soptim wilu-soptim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of my feedback has been adressed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow any cim namespace URIs

4 participants