9.4.3 Defining entities
9.4.3.1 General structure
The JSON entities are defined by creating one subdirectory per kind of entity in the src/main/kauri/mockdata directory.
The listing below shows the directory structure of a module containing three types of entities: contacts, tasks and projects.
Within these directories, you create one JSON file per entity instance. The name of the file (without .json extension) is the ID of the entity.
. |-- contact-module | `-- src | `-- main | `-- kauri | |-- mockdata | `-- contacts | `-- 1.json | `-- 2.json | `-- 3.json | `-- tasks | `-- 1.json | `-- 12.json | `-- 13.json | `-- projects | `-- 1.json | `-- 2.json | `-- 3.json
9.4.3.2 JSON entities
Here is an example of a project entity that contains a label, description, start, finish, type, status, importance and a set of subtasks:
{
label: "Defining prototype module requirements",
description: "Investigating which requirements we have towards prototyping a Kauri project",
start: "2008-09-01",
finish: "2008-09-30",
type: "research",
status: "busy",
importance: "+++",
subtasks: [
{label: "Explore", description: "run the kauri samples, make it work!"},
{label: "Try a prototype", description: "hands on, try to make a prototype"}
]
}
9.4.3.3 Linking between entities
In the example above, we could imagine that the subtasks are also entities itself, which we want to CRUD by themselves. Then we would like to create a reference to these entities instead of repeating them. This can be accomplished by linking entities using objects with a $ref property. If the name of the name-value pair in a JSON object is '$ref' then the value is a reference to another entity.
9.4.3.3.1 Example
{
"label": "Defining prototype module requirements",
"description": "Investigating which requirements we have towards prototyping a Kauri project",
"start": "2008-09-01",
"finish": "2008-09-30",
"type": "research",
"status": "busy",
"importance": "+++",
"subtasks": [
{$ref: "/tasks/3"},
{$ref: "/tasks/3"}
]
}
Of course in this case we have to have a file /entities/tasks/3.json:
{
"label": "Explore",
"description": "run the kauri samples, make it work!"
}
When GETting the project entity, the entities linked via $ref will be merged within the project JSON.
Previous