GetOrCreateRtEntitiesByType@1
Node GetOrCreateRtEntitiesByType@1 is used to find an existing entity based on specified field filters or create a new entity RtId if none is found. This node helps manage entities within OctoMesh's Entity Repository by ensuring each entity has a unique runtime ID (RtId).
- See CreateUpdateInfo@1 for creating update info objects using the
RtIdobtained. - See ApplyChanges@1 for applying changes to the repository.
Adapter Prerequisites
Node Configuration
transformations:
- type: GetOrCreateRtEntitiesByType@1
ckTypeId: Industry.Energy/Photovoltaic.Module # The CK type ID of the entity to find or create
fieldFilters: # Field filters used to find the entity
- path: $.serialNumber # The JSON path to the value in the payload
attributeName: SerialNumber # The attribute name in the entity
operator: Equal # The operator to use for filtering (e.g., Equal, NotEqual)
- path: $.manufacturer
attributeName: Manufacturer
operator: Equal
rtIdTargetPath: $.entity.rtId # Path where the RtId should be stored in the payload
ckTypeIdTargetPath: $.entity.ckTypeId # Path where the CK type ID should be stored in the payload
modOperationPath: $.entity.modOperation # Path where the modification operation (Insert/Update) should be stored
Configuration Properties
-
ckTypeId(CkId<CkTypeId>?) (required): The CK type ID of the entity to find or create. -
fieldFilters(ICollection<PathFieldFilter>?) (required): A collection of field filters used to find the entity. Each filter includes:path(string): The JSON path to the value in the payload.attributeName(string): The attribute name in the entity to filter on.operator(FieldFilterOperator): The operator to use for filtering (e.g.,Equal,NotEqual,Contains).
-
rtIdTargetPath(string): The JSON path where theRtIdshould be stored in the payload. Default is$.rtId. -
ckTypeIdTargetPath(string): The JSON path where the CK type ID should be stored in the payload. Default is$.ckTypeId. -
modOperationPath(string): The JSON path where the modification operation (InsertorUpdate) should be stored in the payload. Default is$.modOperation.
Usage Example
Here's an example of how you might use the GetOrCreateRtEntitiesByType@1 node in a transformation pipeline:
transformations:
- type: GetOrCreateRtEntitiesByType@1
ckTypeId: Industry.Energy/Photovoltaic.Module
fieldFilters:
- path: $.data.serialNumber
attributeName: SerialNumber
operator: Equal
- path: $.data.model
attributeName: Model
operator: Equal
rtIdTargetPath: $.entity.rtId
ckTypeIdTargetPath: $.entity.ckTypeId
modOperationPath: $.entity.modOperation
In this example:
-
Objective: Find an existing Photovoltaic Module entity based on its serial number and model. If it doesn't exist, create a new
RtIdfor it. -
Field Filters:
- Filter by
SerialNumberwhere the value is obtained from$.data.serialNumberin the payload. - Filter by
Modelwhere the value is obtained from$.data.modelin the payload.
- Filter by
-
Output Paths:
- The found or newly created
RtIdis stored at$.entity.rtId. - The
ckTypeIdis stored at$.entity.ckTypeId. - The modification operation (
InsertorUpdate) is stored at$.entity.modOperation.
- The found or newly created
Configuration Properties Details
ckTypeId (required)
- Type:
CkId<CkTypeId>? - Description: The CK type ID of the entity to find or create. This specifies the type of entity in the repository.
fieldFilters (required)
- Type:
ICollection<PathFieldFilter>? - Description: A list of field filters used to search for the entity. Each
PathFieldFilterincludes:path: The JSON path to the value in the payload.attributeName: The name of the attribute in the entity to filter on.operator: The comparison operator (Equal,NotEqual,Contains, etc.).
rtIdTargetPath
- Type:
string - Default:
$.rtId - Description: The JSON path where the resulting
RtIdshould be stored in the payload.
ckTypeIdTargetPath
- Type:
string - Default:
$.ckTypeId - Description: The JSON path where the CK type ID should be stored in the payload.
modOperationPath
- Type:
string - Default:
$.modOperation - Description: The JSON path where the modification operation (
InsertorUpdate) should be stored in the payload. This indicates whether a new entity was created or an existing one was found.
Notes
-
Mandatory Properties: Both
ckTypeIdandfieldFiltersare required. The node will log an error and terminate processing for the item if they are not provided. -
Field Filters: Ensure that the
attributeNamecorresponds to a valid attribute in the CK type specified byckTypeId. -
Operators: The
operatorin field filters can be one of the following:EqualNotEqualContainsStartsWithEndsWith
-
Processing Logic:
- The node attempts to find an existing entity that matches the specified field filters.
- If an entity is found:
- The existing
RtIdis stored atrtIdTargetPath. - The
ckTypeIdis stored atckTypeIdTargetPath. - The
modOperationis set toUpdateand stored atmodOperationPath.
- The existing
- If no entity is found:
- A new
RtIdis generated and stored atrtIdTargetPath. - The
ckTypeIdis stored atckTypeIdTargetPath. - The
modOperationis set toInsertand stored atmodOperationPath.
- A new
-
Subsequent Processing:
- The
RtId,ckTypeId, andmodOperationcan be used in subsequent nodes, such asCreateUpdateInfo@1, to create or update the entity in the repository.
- The
Related Nodes
-
CreateUpdateInfo@1: Create update info objects for entities, which can then be applied to the repository.
-
ApplyChanges@1: Apply accumulated update info objects to the Mesh Adapter.
-
FilterLatestUpdateInfo@1: Filter and retrieve the latest update info objects from the payload.
By configuring and using the GetOrCreateRtEntitiesByType@1 node, you can effectively manage entities in your data pipeline by ensuring that each entity has a unique runtime ID and determining whether to perform an insert or update operation based on the existence of the entity.