Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Additionally, tokens can be used to hold complex arbitrary data structures as embedded JSON objects. The JSON objects have to be escaped when persisting.

Example: Mapping an entity relation to tokens

Mapping an entity relation to tokens may not be obvious at first. This section will walk through a simple example of mapping an entity relation model to tokens.

...

Consider the entity relations diagram above. There are projects, which has one or more products. The projects also have n employees assigned. Additionally, an employee can be assigned to m projects. The project has an id, a human readable name and a list of key words. A product has an id and a name. An employee has an id, name and an email address.

Creating the project entity

When starting with project creation, the first token to create could be

...

Code Block
languagejs
{
  "relatedId": "project1",
  "key": "key_words",
  "value": "[\"eggsfoo\", \"hambar\"]"
}

User Account Private Token Store

This Token Store is conceptually different. It may be accessed both with Management API Client permissions, or with signed-in user account permissions. These tokens are private to the user account. Unlike Management API Client private tokens, these tokens may be shared between applications and services. To do that, ACLs must be defined. Se here for more information.

...


Creating the product entity

We can start creating the product entity by giving it a name.

Code Block
languagejs
{
  "relatedId": "product1",
  "key": "name",
  "value": "apples"
}

After creating the product, we can create a token to represent the relation between the product and the project.

Code Block
languagejs
{
  "relatedId": "product1",
  "key": "project",
  "value": "project1"
}

Creating the employee entity

The employee is a simple entity with id, name and email address. We will start by creating a token with a name.

Code Block
languagejs
{
  "relatedId": "employee1",
  "key": "name",
  "value": "John"
}

After that we may create a token with an email address.

Code Block
languagejs
{
  "relatedId": "employee1",
  "key": "email",
  "value": "john@example.com"
}

After we have the basic object created, we can create the relation between the employee and the project:

Code Block
languagejs
{
  "relatedId": "employee1",
  "key": "project",
  "value": "[\"project1\"]"
}

If the employee is part of many projects, then we can append the project IDs to the list.

The above steps can be repeated after all project employee info has been saved.