{"info":{"_postman_id":"c1f2ca70-0f08-4466-bb27-117eadbb7efa","name":"NGSI-LD Entity Relationships","description":"<html><head></head><body><p>This tutorial teaches <strong>NGSI-LD</strong> users about batch commands and entity relationships. The tutorial builds on the data\ncreated in the previous <a href=\"https://github.com/FIWARE/tutorials.Getting-Started/tree/NGSI-LD\">Smart Farm example</a> and\ncreates and associates a series of related data entities to create add sensors and farm workers to the farm.</p>\n<p>The <code>docker-compose</code> file for this tutorial can be found on GitHub: </p>\n<p><img src=\"https://fiware.github.io/tutorials.Entity-Relationships/icon/GitHub-Mark-32px.png\" alt=\"GitHub\"> <a href=\"https://github.com/Fiware/tutorials.Entity-Relationships\">FIWARE 102: Batch Commands and Entity Relationships</a></p>\n<p>This tutorial teaches <strong>NGSI-LD</strong> users about batch commands and entity relationships. The tutorial builds on the data\ncreated in the previous <a href=\"https://github.com/FIWARE/tutorials.Getting-Started/tree/NGSI-LD\">Smart Farm example</a> and\ncreates and associates a series of related data entities to create add sensors and farm workers to the farm.</p>\n<h1 id=\"understanding-entities-and-relationships\">Understanding Entities and Relationships</h1>\n<p>Within the FIWARE platform, the context of an entity represents the state of a physical or conceptual object which\nexists in the real world.</p>\n<h2 id=\"entities-within-a-farm-management-information-system-fmis\">Entities within a Farm Management Information System (FMIS)</h2>\n<p>To illustrate entity relationships within an FMIS system based on NGSI-LD, we will need to create a series of entities.\nFor this simplified FMIS, we will only need a small number entities. The relationship between our entities is defined as\nshown:</p>\n<p><img src=\"https://fiware.github.io/tutorials.Entity-Relationships/img/ngsi-ld-entities.png\" alt=\"\"></p>\n<ul>\n<li>A building, such as a barn, is a real world bricks and mortar construct. <strong>Building</strong> entities would have properties\nsuch as:<ul>\n<li>A name of the building e.g. \"The Big Red Barn\"</li>\n<li>The category of the building (e.g. \"barn\")</li>\n<li>An address \"Friedrichstraße 44, 10969 Kreuzberg, Berlin\"</li>\n<li>A physical location e.g. <em>52.5075 N, 13.3903 E</em></li>\n<li>A filling level - the degree to which the building is full.</li>\n<li>A temperature - e.g. <em>21 °C</em></li>\n<li>An association to the owner of the building (a real person)</li>\n</ul>\n</li>\n<li>Smart devices such as <strong>TemperatureSensors</strong> or <strong>FillingLevelSensors</strong> would extend a common <strong>Device</strong> data model.\nEach <strong>Device</strong> entity would have properties such as:<ul>\n<li>A description of the device</li>\n<li>The category of device (e.g. <em>sensor</em>, <em>actuator</em>, <em>both</em>)</li>\n<li>The name of the property they are measuring (e.g. <em>temperature</em>)</li>\n<li>An association to the asset (e.g. building) they are measuring</li>\n</ul>\n</li>\n<li>A <strong>person</strong> is an entity representing a farmer or farm labourer. Each <strong>Person</strong> entity would have properties such\nas:<ul>\n<li>A name of the person e.g. \"Mr. Jones\"</li>\n<li>A job title</li>\n<li>An association to the farm buildings they own.</li>\n</ul>\n</li>\n<li>A task something we do down on the farm. It is a conceptual entity, used to associate workers, agricultural products\nand locations <strong>Task</strong> entities would have properties such as:<ul>\n<li>The name of the task (e.g. <em>Spray Herbicide XXX on field Y</em>)</li>\n<li>The status of the task (e.g. <em>scheduled</em>, <em>in progress</em>, <em>completed</em>)</li>\n<li>An association to the worker (i.e. a <strong>Person</strong> entity) who performs the task</li>\n<li>An association to the product (e.g. <strong>Herbicide</strong> entity) to be used.</li>\n<li>An association to the location (e.g. <strong>PartField</strong> entity) to be used.</li>\n</ul>\n</li>\n</ul>\n<p>As you can see, each of the entities defined above contain a mixture of static and dynamic data. Some properties are\nliable to change. A <strong>Herbicide</strong> could change its <code>formula</code>, hay could be sold and the <code>fillingLevel</code> of the barn could\nbe reduced and so on.</p>\n<blockquote>\n<p><strong>Note</strong> this tutorial uses the following typographic styling :</p>\n<ul>\n<li>Entity types have been made <strong>bold text</strong></li>\n<li>Data attributes are written in <code>monospace text</code></li>\n<li>Items in the real world use plain text</li>\n</ul>\n<p>Therefore a person in the real world is represented in the context data by a <strong>Person</strong> entity, and a real world barn\nowned by a person is represented in the context data by a <strong>Building</strong> entity which has a <code>owner</code> attribute.</p>\n</blockquote>\n<h1 id=\"architecture\">Architecture</h1>\n<p>The demo FMIS application will send and receive NGSI-LD calls to a compliant context broker. Since the standardized\nNGSI-LD interface is available across multiple context brokers, so we only need to pick one - for example the\n<a href=\"https://fiware-orion.readthedocs.io/en/latest/\">Orion Context Broker</a>. The application will therefore only make use of\none FIWARE component.</p>\n<p>Currently, the Orion Context Broker relies on open source <a href=\"https://www.mongodb.com/\">MongoDB</a> technology to keep\npersistence of the context data it holds.</p>\n<p>To promote interoperability of data exchange, NGSI-LD context brokers explicitly expose a\n<a href=\"https://json-ld.org/spec/latest/json-ld/#the-context\">JSON-LD <code>@context</code> file</a> to define the data held within the\ncontext entities. This defines a unique URI for every entity type and every attribute so that other services outside of\nthe NGSI domain are able to pick and choose the names of their data structures. Every <code>@context</code> file must be available\non the network. In our case the tutorial application will be used to host a series of static files.</p>\n<p>Therefore, the architecture will consist of three elements:</p>\n<ul>\n<li>The <a href=\"https://fiware-orion.readthedocs.io/en/latest/\">Orion Context Broker</a> which will receive requests using\n<a href=\"https://forge.etsi.org/swagger/ui/?url=https://forge.etsi.org/gitlab/NGSI-LD/NGSI-LD/raw/master/spec/updated/full_api.json\">NGSI-LD</a></li>\n<li>The underlying <a href=\"https://www.mongodb.com/\">MongoDB</a> database :<ul>\n<li>Used by the Orion Context Broker to hold context data information such as data entities, subscriptions and\nregistrations</li>\n</ul>\n</li>\n<li>The <strong>Tutorial Application</strong> does the following:<ul>\n<li>Offers static <code>@context</code> files defining the context entities within the system.</li>\n</ul>\n</li>\n</ul>\n<p>Since all interactions between the two elements are initiated by HTTP requests, the entities can be containerized and\nrun from exposed ports.</p>\n<p><img src=\"https://fiware.github.io/tutorials.Entity-Relationships/img/architecture-ld.png\" alt=\"\"></p>\n<p>The necessary configuration information can be seen in the services section of the associated <code>docker-compose.yml</code> file.\nIt has been described in a <a href=\"https://github.com/FIWARE/tutorials.Getting-Started/tree/NGSI-LD\">previous tutorial</a></p>\n<h1 id=\"prerequisites\">Prerequisites</h1>\n<h2 id=\"docker-and-docker-compose\">Docker and Docker Compose</h2>\n<p>To keep things simple both components will be run using <a href=\"https://www.docker.com\">Docker</a>. <strong>Docker</strong> is a container\ntechnology which allows to different components isolated into their respective environments.</p>\n<ul>\n<li>To install Docker on Windows follow the instructions <a href=\"https://docs.docker.com/docker-for-windows/\">here</a></li>\n<li>To install Docker on Mac follow the instructions <a href=\"https://docs.docker.com/docker-for-mac/\">here</a></li>\n<li>To install Docker on Linux follow the instructions <a href=\"https://docs.docker.com/install/\">here</a></li>\n</ul>\n<p><strong>Docker Compose</strong> is a tool for defining and running multi-container Docker applications. A\n<a href=\"https://raw.githubusercontent.com/Fiware/tutorials.Entity-Relationships/master/docker-compose.yml\">YAML file</a> is used\nconfigure the required services for the application. This means all container services can be brought up in a single\ncommand. Docker Compose is installed by default as part of Docker for Windows and Docker for Mac, however Linux users\nwill need to follow the instructions found <a href=\"https://docs.docker.com/compose/install/\">here</a></p>\n<p>You can check your current <strong>Docker</strong> and <strong>Docker Compose</strong> versions using the following commands:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-console\">docker-compose -v\ndocker version\n</code></pre>\n<p>Please ensure that you are using Docker version 18.03 or higher and Docker Compose 1.21 or higher and upgrade if\nnecessary.</p>\n<h2 id=\"cygwin-for-windows\">Cygwin for Windows</h2>\n<p>We will start up our services using a simple Bash script. Windows users should download <a href=\"http://www.cygwin.com/\">cygwin</a>\nto provide a command-line functionality similar to a Linux distribution on Windows.</p>\n<h1 id=\"start-up\">Start Up</h1>\n<p>All services can be initialised from the command-line by running the\n<a href=\"https://github.com/FIWARE/tutorials.Entity-Relationships/blob/NGSI-LD/services\">services</a> Bash script provided within\nthe repository. Please clone the repository and create the necessary images by running the commands as shown:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-console\">git clone https://github.com/FIWARE/tutorials.Entity-Relationships.git\ncd tutorials.Entity-Relationships\ngit checkout NGSI-LD\n\n./services start\n</code></pre>\n<p>This command will also import seed data (<strong>Building</strong>, <strong>Person</strong>, <strong>TemperatureSensor</strong>, <strong>FillingLevelSensor</strong>,\n<strong>Herbicide</strong> and <strong>PartField</strong>) on startup.</p>\n</body></html>","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","toc":[{"content":"Understanding Entities and Relationships","slug":"understanding-entities-and-relationships"},{"content":"Architecture","slug":"architecture"},{"content":"Prerequisites","slug":"prerequisites"},{"content":"Start Up","slug":"start-up"}],"owner":"513743","collectionId":"c1f2ca70-0f08-4466-bb27-117eadbb7efa","publishedId":"TVepAoFN","public":true,"customColor":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"233C68"},"publishDate":"2020-11-16T14:50:35.000Z"},"item":[{"name":"Create Three Temperature Sensors","id":"96d317ad-849a-4dea-afed-c07600669122","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"},{"key":"Link","value":"<http://context/ngsi-context.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\"","type":"text"}],"body":{"mode":"raw","raw":"[\n    {\n      \"id\": \"urn:ngsi-ld:TemperatureSensor:001\",\n      \"type\": \"TemperatureSensor\",\n      \"description\" : {\"type\": \"Property\", \"value\": \"Temperature Gauge 1\"},\n      \"category\": {\"type\": \"VocabProperty\", \"vocab\": \"sensor\"},\n      \"controlledProperty\" : {\"type\": \"Property\", \"value\": \"temperature\"},\n      \"temperature\": {\"type\": \"Property\", \"value\": 20, \"unitCode\": \"CEL\"}\n    },\n    {\n      \"id\": \"urn:ngsi-ld:TemperatureSensor:002\",\n      \"type\": \"TemperatureSensor\",\n      \"description\" : {\"type\": \"Property\", \"value\": \"Temperature Gauge 2\"},\n      \"category\": {\"type\": \"VocabProperty\", \"vocab\": \"sensor\"},\n      \"controlledProperty\" : {\"type\": \"Property\", \"value\": \"temperature\"},\n      \"temperature\": {\"type\": \"Property\", \"value\": 21, \"unitCode\": \"CEL\"}\n    },\n    {\n      \"id\": \"urn:ngsi-ld:TemperatureSensor:003\",\n      \"type\": \"TemperatureSensor\",\n      \"description\" : {\"type\": \"Property\", \"value\": \"Temperature Gauge 3\"},\n      \"category\": {\"type\": \"VocabProperty\", \"vocab\": \"sensor\"},\n      \"controlledProperty\" : {\"type\": \"Property\", \"value\": \"temperature\"},\n      \"temperature\": {\"type\": \"Property\", \"value\": 27, \"unitCode\": \"CEL\"}\n    }\n]"},"url":"http://localhost:1026/ngsi-ld/v1/entityOperations/upsert","description":"<p>In the previous tutorial, we created each entity individually,</p>\n<p>Lets create several sensors at the same time. This request uses the convenience batch processing endpoint to create five\nentities. Batch processing uses the <code>/ngsi-ld/v1/entityOperations/</code>endpoints and the <code>upsert</code> endpoints means we will\ncreate new entities if they are not present and overwrite existing entities if they exist.</p>\n<p>To differentiate different <strong>Device</strong>, each temperature sensor has been assigned <code>type=TemperatureSensor</code>. Real-world\nproperties such as <code>category</code> have been added as properties to each device.</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","entityOperations","upsert"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"96d317ad-849a-4dea-afed-c07600669122"},{"name":"Create Three Filling Sensors","id":"a732851a-47fc-4a1e-bce7-c6873e3a0a33","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"},{"key":"Link","value":"<http://context/ngsi-context.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\"","type":"text"}],"body":{"mode":"raw","raw":"[\n    {\n      \"id\": \"urn:ngsi-ld:FillingLevelSensor:001\",\n      \"type\": \"FillingLevelSensor\",\n      \"description\" : {\"type\": \"Property\", \"value\": \"Filling Level Sensor 1\"},\n      \"category\": {\"type\": \"VocabProperty\", \"vocab\": \"sensor\"},\n      \"controlledProperty\" : {\"type\": \"Property\", \"value\": \"fillingLevel\"},\n      \"fillingLevel\": {\"type\": \"Property\", \"value\": 1, \"unitCode\": \"C62\"}\n    },\n    {\n      \"id\": \"urn:ngsi-ld:FillingLevelSensor:002\",\n      \"type\": \"FillingLevelSensor\",\n      \"description\" : {\"type\": \"Property\", \"value\": \"Filling Level Sensor 2\"},\n      \"category\": {\"type\": \"VocabProperty\", \"vocab\": \"sensor\"},\n      \"controlledProperty\" : {\"type\": \"Property\", \"value\": \"fillingLevel\"},\n      \"fillingLevel\": {\"type\": \"Property\", \"value\": 0.9, \"unitCode\": \"C62\"}\n    },\n    {\n      \"id\": \"urn:ngsi-ld:FillingLevelSensor:003\",\n      \"type\": \"FillingLevelSensor\",\n      \"description\" : {\"type\": \"Property\", \"value\": \"Filling Gauge 3\"},\n      \"category\": {\"type\": \"VocabProperty\", \"vocab\": \"sensor\"},\n      \"controlledProperty\" : {\"type\": \"Property\", \"value\": \"fillingLevel\"},\n      \"fillingLevel\": {\"type\": \"Property\", \"value\": 0.8, \"unitCode\": \"C62\"}\n    }\n]"},"url":"http://localhost:1026/ngsi-ld/v1/entityOperations/upsert","description":"<p>Similarly, we can create a series of <strong>FillingLevelSensors</strong> entities by using the <code>type=FillingLevelSensor</code>.</p>\n<p>In both cases we have encoded each entity <code>id</code> according to the NGSI-LD\n<a href=\"https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.03.01_60/gs_cim009v010301p.pdf\">specification</a> - the proposal\nis that each <code>id</code> is a URN follows a standard format: <code>urn:ngsi-ld:&lt;entity-type&gt;:&lt;entity-id&gt;</code>. This will mean that every\n<code>id</code> in the system will be unique.</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","entityOperations","upsert"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"a732851a-47fc-4a1e-bce7-c6873e3a0a33"},{"name":"Obtain Device Information","id":"9fbfb2a1-b69c-4e66-93ee-c9b44d9cea5b","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"Link","value":"<http://context/ngsi-context.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\"","type":"text"}],"url":"http://localhost:1026/ngsi-ld/v1/entities/?type=TemperatureSensor,FillingLevelSensor&options=keyValues","description":"<p>Device information can be requested by making a GET request on the <code>/ngsi-ld/v1/entities</code> endpoint. For example to\nreturn the context data of the devices.</p>\n<p>As you can see there are currently three additional property attributes present <code>description</code>, <code>category</code> and\n<code>controlledProperty</code></p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","entities",""],"host":["localhost:1026"],"query":[{"key":"type","value":"TemperatureSensor,FillingLevelSensor"},{"key":"options","value":"keyValues"}],"variable":[]}},"response":[],"_postman_id":"9fbfb2a1-b69c-4e66-93ee-c9b44d9cea5b"},{"name":"Adding a Foreign Key Relationship","id":"2f3fb74a-0554-4a0f-b96d-765922466ff1","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"},{"key":"Link","value":"<http://context/ngsi-context.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\"","type":"text"}],"body":{"mode":"raw","raw":"[\n    {\n        \"id\": \"urn:ngsi-ld:TemperatureSensor:001\",\n        \"type\": \"TemperatureSensor\",\n        \"controllingAsset\": {\n            \"type\": \"Relationship\",\n            \"object\": \"urn:ngsi-ld:Building:farm001\"\n        }\n    },\n    {\n        \"id\": \"urn:ngsi-ld:TemperatureSensor:002\",\n        \"type\": \"TemperatureSensor\",\n        \"controllingAsset\": {\n            \"type\": \"Relationship\",\n            \"object\": \"urn:ngsi-ld:Building:barn002\"\n        }\n    },\n    {\n        \"id\": \"urn:ngsi-ld:FillingLevelSensor:003\",\n        \"type\": \"FillingLevelSensor\",\n        \"controllingAsset\": {\n            \"type\": \"Relationship\",\n            \"object\": \"urn:ngsi-ld:Building:farm002\"\n        }\n    },\n    {\n        \"id\": \"urn:ngsi-ld:FillingLevelSensor:001\",\n        \"type\": \"FillingLevelSensor\",\n        \"controllingAsset\": {\n            \"type\": \"Relationship\",\n            \"object\": \"urn:ngsi-ld:Building:farm001\"\n        }\n    },\n    {\n        \"id\": \"urn:ngsi-ld:FillingLevelSensor:002\",\n        \"type\": \"FillingLevelSensor\",\n        \"controllingAsset\": {\n            \"type\": \"Relationship\",\n            \"object\": \"urn:ngsi-ld:Building:barn002\"\n        }\n    },\n    {\n        \"id\": \"urn:ngsi-ld:TemperatureSensor:003\",\n        \"type\": \"TemperatureSensor\",\n        \"controllingAsset\": {\n            \"type\": \"Relationship\",\n            \"object\": \"urn:ngsi-ld:Building:farm002\"\n        }\n    }\n]"},"url":"http://localhost:1026/ngsi-ld/v1/entityOperations/update?options=update","description":"<p>In databases, foreign keys are often used to designate a one-to-many relationship - for example a building can hold many\ndevices. In order to remember this information we need to add an association relationship similar to a foreign key.\nBatch processing can again be used to amend the existing the <strong>TemperatureSensor</strong> and <strong>FillingLevelSensor</strong> entities\nto add a <code>controllingAsset</code> attribute holding the relationship to each building controlled by the device. According to\nthe Smart Data Model <a href=\"https://swagger.lab.fiware.org/?url=https://smart-data-models.github.io/dataModel.Device/Device/swagger.yaml\">Device</a>\ndefinition <code>https://uri.fiware.org/ns/data-models#controllingAsset</code> is the URI long name to be used for this\nrelationship, and the value of the <code>controllingAsset</code> attribute corresponds to a URN associated to a <strong>Building</strong> entity\nitself.</p>\n<p>The URN follows a standard format: <code>urn:ngsi-ld:&lt;entity-type&gt;:&lt;entity-id&gt;</code>.</p>\n<p>The following request associates six devices to <code>urn:ngsi-ld:Building:farm001</code>, <code>urn:ngsi-ld:Building:barn002</code> and\n<code>urn:ngsi-ld:Building:farm002</code>.</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","entityOperations","update"],"host":["localhost:1026"],"query":[{"key":"options","value":"update"}],"variable":[]}},"response":[],"_postman_id":"2f3fb74a-0554-4a0f-b96d-765922466ff1"},{"name":"Obtain Updated Device Information","id":"fea82e93-6022-4884-ae53-1970e83db681","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"Link","value":"<http://context/ngsi-context.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\"","type":"text"}],"url":"http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:TemperatureSensor:001?options=keyValues","description":"<p>Now when the devcie information is requested again, the response has changed and includes a new property\n<code>controllingAsset</code>, which has been added in the previous step.</p>\n","urlObject":{"protocol":"http","port":"1026","path":["ngsi-ld","v1","entities","urn:ngsi-ld:TemperatureSensor:001"],"host":["localhost"],"query":[{"key":"options","value":"keyValues"},{"disabled":true,"description":{"content":"<p>Entity type</p>\n","type":"text/plain"},"key":"type","value":"Shelf"}],"variable":[]}},"response":[],"_postman_id":"fea82e93-6022-4884-ae53-1970e83db681"},{"name":"Obtain a Foreign Key URN","id":"deee7416-9521-45ae-b718-71dc931211ca","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"Link","value":"<http://context/ngsi-context.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\"","type":"text"},{"key":"Accept","value":"application/json","type":"text","name":"Accept"}],"url":"http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:TemperatureSensor:001?options=keyValues&attrs=controllingAsset","description":"<p>We can also make a request to retrieve the <code>controllingAsset</code> attribute relationship information from a known <strong>Device</strong>\nentity by using the <code>options=keyValues</code> setting.</p>\n<p>This can be interpreted as <em>\"I am making sensor readings inside the <strong>Building</strong> entity with the\n<code>id=urn:ngsi-ld:Building:farm001</code>\"</em></p>\n","urlObject":{"protocol":"http","port":"1026","path":["ngsi-ld","v1","entities","urn:ngsi-ld:TemperatureSensor:001"],"host":["localhost"],"query":[{"key":"options","value":"keyValues"},{"disabled":true,"description":{"content":"<p>Entity type</p>\n","type":"text/plain"},"key":"type","value":"Shelf"},{"key":"attrs","value":"controllingAsset"}],"variable":[]}},"response":[],"_postman_id":"deee7416-9521-45ae-b718-71dc931211ca"},{"name":"Reading from Parent Entity to Child Entity","id":"a6953855-c9e1-4b81-a209-3ae1e70dc318","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"Link","value":"<http://context/ngsi-context.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\"","type":"text"}],"url":"http://localhost:1026/ngsi-ld/v1/entities?q=controllingAsset==\"urn:ngsi-ld:Building:farm001\"&options=keyValues&attrs=controllingAsset","description":"<p>Reading from a parent to a child can be done using the following query.</p>\n<p>This request is asking for the <code>id</code> of all <strong>Device</strong> entities associated to the URN <code>urn:ngsi-ld:Building:farm001</code>, the\nresponse is a JSON array as shown.</p>\n<p>In plain English, this can be interpreted as <em>\"There are two devices in <code>urn:ngsi-ld:Building:farm001</code>\"</em>. The request can\nbe altered use the <code>count=true</code> to return the number of entities which fulfill the criteria.</p>\n<p>This returns an HTTP Header as part of the response which indicates the number of affected entities.</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","entities"],"host":["localhost:1026"],"query":[{"key":"q","value":"controllingAsset==\"urn:ngsi-ld:Building:farm001\""},{"key":"options","value":"keyValues"},{"key":"attrs","value":"controllingAsset"}],"variable":[]}},"response":[],"_postman_id":"a6953855-c9e1-4b81-a209-3ae1e70dc318"},{"name":"Creating many-to-many Relationships","id":"40f3c039-6491-4342-9d4e-54da11585a5b","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"},{"key":"Link","value":"<http://context/ngsi-context.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\"","type":"text"}],"body":{"mode":"raw","raw":"{\n    \"id\": \"urn:ngsi-ld:Task:001\",\n    \"type\": \"Task\",\n    \"worker\": {\n        \"type\": \"Relationship\",\n        \"object\": \"urn:ngsi-ld:Person:001\"\n    },\n    \"field\": {\n        \"type\": \"Relationship\",\n        \"object\": \"urn:ngsi-ld:PartField:002\"\n    },\n    \"product\": {\n        \"type\": \"Relationship\",\n        \"object\": \"urn:ngsi-ld:Herbicide:001\"\n    },\n    \"description\": {\n        \"type\": \"Property\",\n        \"value\": \"Spray the North Field with Agent Orange\"\n    },\n    \"status\": {\n        \"type\": \"Property\",\n        \"value\": \"scheduled\"\n    },\n    \"dueDate\": {\n        \"type\": \"Property\",\n        \"value\": \"2021-07-16\"\n    }\n}"},"url":"http://localhost:1026/ngsi-ld/v1/entities/","description":"<p>Bridge Tables are often used to relate many-to-many relationships. For example, every spraying activity within the FMIS\nwill need to associate a farm worker, a product to apply, and a location to apply the treatment (known as a\n<strong>PartField</strong>)</p>\n<p>In order to hold the context information to \"direct a worker to spray a herbicide onto a field\" we will need to create a\nnew data entity <strong>Task</strong> which exists to associate data from other entities. It has a foreign key relationship to the\n<strong>Person</strong>, <strong>Herbicide</strong> and <strong>PartField</strong> entities and therefore requires relationship attributes called <code>field</code>,\n<code>herbicide</code> and <code>worker</code>.</p>\n<p>Assigning a task is simply done by creating an entity holding the relationship information and any other additional\nproperties (such as <code>description</code> and <code>status</code>)</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","entities",""],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"40f3c039-6491-4342-9d4e-54da11585a5b"},{"name":"Reading from a bridge table (1)","id":"dc1cdab9-de24-4161-80ac-43aaa1fa943a","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"Link","value":"<http://context/ngsi-context.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\"","type":"text"},{"key":"Accept","value":"application/json","type":"text","name":"Accept"}],"url":"http://localhost:1026/ngsi-ld/v1/entities/?q=field==\"urn:ngsi-ld:PartField:002\"&options=keyValues&attrs=worker&type=Task","description":"<p>When reading from a bridge table entity, the <code>type</code> of the entity must be known.</p>\n<p>After creating at least one <strong>Task</strong> entity we can query <em>Which workers are assigned activities in field\n<code>urn:ngsi-ld:PartField:002</code>?</em> by making the following request:</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","entities",""],"host":["localhost:1026"],"query":[{"key":"q","value":"field==\"urn:ngsi-ld:PartField:002\""},{"key":"options","value":"keyValues"},{"key":"attrs","value":"worker"},{"key":"type","value":"Task"}],"variable":[]}},"response":[],"_postman_id":"dc1cdab9-de24-4161-80ac-43aaa1fa943a"},{"name":"Reading from a bridge table (2)","id":"b02f43b4-c696-479d-b2fb-e31ccc12c60f","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"Link","value":"<http://context/ngsi-context.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\"","type":"text"},{"key":"Accept","value":"application/json","type":"text","name":"Accept"}],"url":"http://localhost:1026/ngsi-ld/v1/entities/?q=product==\"urn:ngsi-ld:Herbicide:001\"&options=keyValues&attrs=field&type=Task","description":"<p>Similarly we can request <em>Which fields are treated using <code>urn:ngsi-ld:Herbicide:001</code>?</em> by altering the request as shown:</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","entities",""],"host":["localhost:1026"],"query":[{"key":"q","value":"product==\"urn:ngsi-ld:Herbicide:001\""},{"key":"options","value":"keyValues"},{"key":"attrs","value":"field"},{"key":"type","value":"Task"}],"variable":[]}},"response":[],"_postman_id":"b02f43b4-c696-479d-b2fb-e31ccc12c60f"},{"name":"Relationships of Properties","id":"193167a5-1d2a-4352-8d5c-65081056e174","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"Link","value":"<http://context/ngsi-context.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\"","type":"text"},{"key":"Accept","value":"application/json","type":"text","name":"Accept"}],"url":"http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:Building:farm001?attrs=temperature","description":"<p><em>Properties-of-Properties</em> and <em>Relationships of Properties</em> are metadata. The addition of metadata entities such as\nthese into the context data allows users to navigate the graph of entities relationships and gain further insights about\nthe state of the system.</p>\n<h3 id=\"retrieving-the-temperature-of-a-barn\">Retrieving the Temperature of a Barn</h3>\n<p>The temperature readings from a temperature sensor have already been discussed. It may also be necessary to duplicate\nthis data into another entity. For example, the temperature reading of a sensor in the barn is also the temperature\nreading of the barn itself. A dummy reading has already been added into the <code>urn:ngsi-ld:Building:farm001</code> Entity and\ncan be retrieved with a GET request.</p>\n<p>As you can see the <code>temperature</code> Property holds additional information regarding the provider of the measurement, this\nwill allow additional inferences to be made.</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","entities","urn:ngsi-ld:Building:farm001"],"host":["localhost:1026"],"query":[{"key":"attrs","value":"temperature"}],"variable":[]}},"response":[],"_postman_id":"193167a5-1d2a-4352-8d5c-65081056e174"}],"event":[{"listen":"prerequest","script":{"id":"3d79eb80-4f1b-49d0-be1b-c165d0586d37","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"c64b5091-5afd-482c-b3c6-8a17360e1378","type":"text/javascript","exec":[""]}}],"variable":[{"key":"orion","value":"localhost:1026"},{"key":"ngsi-context.jsonld","value":"http://context/ngsi-context.jsonld"}]}