Autogenerated IDs for simple and nested attributes
Learn about configuring reference attributes for auto-generated IDs.
To make attributes from a relation auto-generated, attributes from the appropriate relation type must be defined as auto-generated in the same way, as for simple and nested attributes of the entity. To make attributes from referenced entity auto-generated, attributes must be marked as auto-generated directly in the referenced type configuration.
Auto-generated IDs
Unique IDs for attributes can be generated automatically. The feature is available for simple and nested attributes. This section describes auto-generated IDs for simple and nested attributes.
The following table describes how the Universal Unique Identifier (UUID) and sequential IDs are generated using the following properties:
Option | Applies To | Description | Default Value |
---|---|---|---|
autoGenerated | Attribute/Source | If true , the value of the attribute/crosswalk is
auto-generated. Use this to enable the feature. | False |
generateIfEmpty | Attribute | If true , the value is generated only if a value is not
sent in the request. Note: You must send an empty string to generate a value. A null value is not considered an empty string and will not generate a value. | False |
generateIfNotEmpty | Attribute | If true , the value is generated even if a value is sent
in the request. | true |
generatedValueUniqueForCrosswalk | Attribute | If true and the object is already stored, the
existing value by same crosswalk in the request is reused instead of
generating a new one. | False |
generator | Attribute/source | The generator name. | None |
autoGenerationPattern | Simple attribute/source | Template for generating. The {value} is
substituted by the generated value from the generator. | None |
autoGenerationNestedPattern | Nested attribute | Used to specify auto-generated patterns for simple sub-attributes. | None |
uniqueGeneratedValuePerEntityPerRequest | Entity | If in the entity more than one auto-generated attribute/crosswalk
are defined with the same generator and this property is set to
true , only one value is generated for all those
attributes per request. | False |
If you specify the value for any auto generated field in the above table as null
, it is treated as not-empty. If you have specified the null value, but also want to auto-generate the value, ensure the generateIfNotEmpty field is true
.
Simplified Algorithm of Generating Attributes
- Analyze
generateIfEmpty
andgenerateIfNotEmpty
flags for a particular attribute. - Compare the attribute state (exists or not) in the current request with the provided flags.
- Trigger the generation based on the flags and attribute state. If the generation
is triggered, analyze the
generatedValueUniqueForCrosswalk
flag. If it is false, generate regardless of the stored object. When it'strue
, try to find the attribute in the saved object.- If the found attribute belongs to the current crosswalk, the stored value of an attribute is reused.
- If attribute is not found or does not belong to the current crosswalk, a new value is generated.
Simple Attribute
For generating a simple attribute, the autoGenerationPattern
property is required. If this property does not contain a {value}
,
it's considered as auto-generated with a fixed pattern (no generator is used for
generating the value). The data type of a simple attribute must be consistent with
the autoGenerationPattern
property. For example, if the data type
is Int
, then autoGenerationPattern=idx_{value}
is
invalid because it produces a value that cannot be converted to
Int
.
Nested Attribute
autoGenerationNestedPattern
property is
required."autoGenerationNestedPattern":{
"Type":"AUTO",
"ID":"{value}"
}
It generates the entire nested attribute with the sub-attributes,
Type
and ID
.
Deepnested Attribute Structure Generation
{
"attributes": [
{
"uri": "configuration/entityTypes/Object/attributes/Nested1",
"name": "Nested1",
"type": "Nested",
"autoGenerated": true,
"generateIfEmpty": true,
"generateIfNotEmpty": true,
"generator": "Seq_generator",
"autoGenerationNestedPattern": {
"ID1": "id1_{value}"
},
"attributes": [
{
"uri": "configuration/entityTypes/Object/attributes/Nested1/attributes/ID1",
"name": "ID1",
"type": "String"
},
{
"uri": "configuration/entityTypes/Object/attributes/Nested1/attributes/Nested2",
"name": "Nested2",
"type": "Nested",
"autoGenerated": true,
"generateIfEmpty": true,
"generateIfNotEmpty": true,
"generator": "Seq_generator",
"autoGenerationNestedPattern": {
"ID2": "id2_{value}"
},
"attributes": [
{
"uri": "configuration/entityTypes/Object/attributes/Nested1/attributes/Nested2/attributes/ID2",
"name": "ID2",
"type": "String"
}
]
}
]
}
]
}
Attribute at a Deeper Level of a Nest
- All immediate parents of the auto-generated attribute are found in current request.
- The auto-generated attribute is generated in each parent.
- If the
generatedValueUniqueForCrosswalk
istrue
, it tries to find the parent in the stored object and reuse the value of its sub attribute only if the parent is at the current level.
true
, only one value is generated for the auto-generated attribute. This value belongs to all the dataProvider crosswalks.ID Generation Behavior for Attributes and Crosswalks
For Attributes
dataProvider=true
, only one value is generated for the
auto-generated attribute and this value belongs to all dataProvider
crosswalks.The behavior of the ID generation for attributes is as follows:
generatedValueUniqueForCrosswalk= True:,generateIfEmpty = True, and generateIfNotEmpty= True
Value was Sent | Value by Crosswalk Exists | Reaction |
---|---|---|
Yes | Yes | Reuse existing value. |
No | Generate new value and save it instead of the value that was sent. | |
No | Yes | Reuse existing value. |
No | Generate new value. |
generatedValueUniqueForCrosswalk= True:,generateIfEmpty = True, and generateIfNotEmpty= False
Value was Sent | Value by Crosswalk Exists | Reaction |
---|---|---|
Yes | Doesn't matter | Nothing is generated - the value from the request is saved in the object. |
No | Yes | Reuse existing value. |
No | Generate new value |
generatedValueUniqueForCrosswalk= True:,generateIfEmpty = False, and generateIfNotEmpty= True
Value was Sent | Value by Crosswalk Exists | Reaction |
---|---|---|
Yes | Yes | Reuse existing value. |
No | Generate new value and save it instead of the value that was sent. | |
No | Doesn't matter | Nothing is generated. |
generatedValueUniqueForCrosswalk= True:,generateIfEmpty = False, and generateIfNotEmpty= False
Value was Sent | Value by Crosswalk Exists | Reaction |
---|---|---|
Does not matter | Does not matter | Nothing is generated. |
generatedValueUniqueForCrosswalk= False:,generateIfEmpty = True, and generateIfNotEmpty= True
Value was Sent | Value by Crosswalk Exists | Reaction |
---|---|---|
Yes | Does not matter | Generate new value and save it instead of the value that was sent. |
No | Generate a new value |
generatedValueUniqueForCrosswalk= False:,generateIfEmpty = True, and generateIfNotEmpty= False
Value was Sent | Value by Crosswalk Exists | Reaction |
---|---|---|
Yes | Does not matter | Nothing is generated. |
No | Generate a new value |
generatedValueUniqueForCrosswalk= False:,generateIfEmpty = False, and generateIfNotEmpty= True
Value was Sent | Value by Crosswalk Exists | Reaction |
---|---|---|
Yes | Does not matter | Generate new value and save it instead of the value that was sent. |
No | Nothing is generated. |
generatedValueUniqueForCrosswalk= False:,generateIfEmpty = False, and generateIfNotEmpty= False
Value was Sent | Value by Crosswalk Exists | Reaction |
---|---|---|
Does not matter | Does not matter | Nothing is generated. |
For Crosswalks
For crosswalks, the behavior depends on whether the value was sent or not.
Value was Sent | Reaction |
---|---|
No | Generate a new crosswalk value. |
Yes | Reuse the crosswalk value that was saved. |
send
object does not exist, the value of the
auto-generated crosswalk is generated. If the send
object already
exists, the value of the auto-generated crosswalk with the same source type is
reused.Creation of Auto-generated Simple Attributes
"attributes":[
{
"uri":"configuration/entityTypes/Object/attributes/AutoGeneratedSimple",
"name":"AutoGeneratedSimple",
"label":"Auto-generated Simple",
"type":"String",
"autoGenerated":true,
"generateIfEmpty":true,
"generatedValueUniqueForCrosswalk":true,
"generator":"UUID4_generator",
"autoGenerationPattern":"Simple_{value}"
},
...
]
Creation of Auto-generated Nested Attributes
"attributes":[
{
"uri":"configuration/entityTypes/Object/attributes/AutoGeneratedNested",
"name":"AutoGeneratedNested",
"label":"Auto-generated Nested",
"type":"Nested",
"autoGenerated":true,
"generateIfEmpty":true,
"generatedValueUniqueForCrosswalk":true,
"generator":"UUID4_generator",
"autoGenerationNestedPattern":{
"Type":"AUTO",
"ID":"{value}"
},
"attributes":[
{
"uri":"configuration/entityTypes/Object/attributes/AutoGeneratedForcedNested/attributes/Type",
"name":"Type",
"label":"Type",
"type":"String",
"description":""
},
{
"uri":"configuration/entityTypes/Object/attributes/AutoGeneratedForcedNested/attributes/ID",
"name":"ID",
"label":"ID",
"type":"String",
"description":""
}
]
},
...
]