How to define unique keys for ElementClasses?
On Identity
In a model, elements often need to be referenced, either in other parts of the model or as way to find the element within the model during tests or other logic. In order to do so, they need to be uniquely addressable.
Some Examples:
- A person needs to be uniquely identified, which is possible by the id number.
- A car is uniquely identified by its license plate.
- A DataElement is uniquely identified by its name, which cannot be used for another element in that model.
- A
ScriptParameterTypeneeds to be uniquely identified by its name within a script.
Here, we define identifiers at the attribute level.
Configuring identifiers in the tooling
ElementClasses can annotate attributes as identifiers. The values of these attributes will be combined to create a unique key.
Modelling steps:
- Set attribute identifiers: mark one or more attributes with
<isIdentifier>true</isIdentifier>. Their values will be combined to form the element's unique key. - Choose key scope:
- Parent-scoped (default): for elements that are part of a Composition or Extension, the key automatically includes the parent's key.
- Globally unique: set
<isGloballyUnique>true</isGloballyUnique>if the element should be addressable independently of its parent. SeeisGloballyUniquefor the exact requirements each option places on the parent and the Composition/Extension reference.
- Mark Identifier
- Mark Globally Unique
ScriptParameterType.xml
<elementClass name="ScriptParameterType">
<group name="org.normalizedsystems.scripts" ontology="scriptElements"/>
<role name="node"/>
<attributes>
<attribute name="name">
<isIdentifier>true</isIdentifier>
<dataType name="Name" ontology="scriptElements"/>
</attribute>
</attributes>
</elementClass>
ValueType.xml
<elementClass name="ValueType">
<isGloballyUnique>true</isGloballyUnique>
<group name="valueTypes" ontology="elements"/>
<role name="data"/>
<attributes>
<attribute name="name">
<isIdentifier>true</isIdentifier>
<dataType name="Name" ontology="elements"/>
</attribute>
</attributes>
</elementClass>