Integration with Ontologies: How to invoke a Flow when you create an Ontology instance?
In this tutorial, we will see how to process the notifications generated by the system when an ontology receives insertion messages.
Let's start from the "noderedTest" ontology that has the following structure:
We will create a flow that allows us to insert a value and register a notifier to be able to process the information related to the Insertion event in said ontology.
Let's assume the following insertion flow:
Every time you click on the INJECT node "Data to insert", an ontology instance will be inserted in "noderedTest". To collect the value of the insert, you will use the "OnesaitPlatform Notification endpoint" node:
This node requires the following properties:
Name: (optional) The name you will give to the node within the flow.
Ontologies available: Drop-down menu where you will select the ontology on which you want to receive notifications.
Operation type: It is the type of operation that you will be waiting for to be notified about. There are three options:
INSERT: You will be notified of a message for each insert operation about the ontology.
REMOVE: You will be notified of a message for each remove operation on the ontology.
UPDATE: You will be notified of a message for each update operation on the ontology.
URL: Name that you will give to the endpoint that listens to the notification that the platform will return. As a limitation, a URL cannot be repeated within a domain.
Going on with the example, now you are going to configure the node to notify you with any insert message about the "noderedTest" ontology:
To test it, launch an insert by clicking on the INJECT node "Data to insert" and look at the "debug" tab:
The first data appearing in the "debug" log is the one about the response to the insertion, showing the ID of the element inserted in the ontology.
Just under that, you can see the message received by the notifier. In the "msg.payload" you will receive an object with the following structure:
The meaning of each field is as follows:
notificationModel: Object that encompasses all the information of both the notification and the operation. Within the "notificationModel", there is:
operationModel: Object that encompasses all information regarding the operation for which you have been notified. The operation information is broken down into:
ontologyName: Name of the ontology subject of the operation.
operationType: Type of operation performed on the ontology.
user: User who performed the operation.
source: Module from which the operation was launched.
body: Contains the data of the operation. In this case, this is the inserted record.
queryType: In the case of a query operation, the type of query.
objectId: If it is an operation by ID, the ID of the ontology object that was affected by the operation.
deviceTemplate: Type of device that launched the operation. You will only be informed if the operation was launched from a device defined on the platform.
device: Name of the device that launched the operation. You will only be informed if the operation was launched from a device defined on the platform.
clientSession: Client session.
clientConnection: Client connection.
cacheable: Only applies to queries, to indicate if they have been retrieved from cache.
notificationEntityId: Node-RED identifier of the node receiving the notification.
url: Endpoint through which the notification arrives to the node.
Should you want to see the data of the operation, you can access "msg.payload.notificationModel.operationModel.body":