Data Personalization Scope Example

This guide walks you through the process of creating an application that demonstrates to the concept of auto scope and manual scope used for data personalization.

What you’ll build

An oeCloud based app with a model autoscoped on organization and will post data with manual scopes to that model.

What you’ll need

  • You should have Node and NPM installed.
  • mod headers extension installed on google chrome.You can get it here

How to start with this guide

You can start from scratch and complete each step, or you can bypass basic setup steps that are already familiar to you.

To start from the scratch go to Getting Started

Basic terms and their definition.

Term Description
autoscope Setting in model.json where developer can force model to be automatically scoped at certain parameter. Specified as an array of strings in model definition.
scope While POSTing the data user can specify a scope manually by adding a json attribute named scope : {}
_scope Final calculated scope which will be stored in the database. The final _scope will be a combination of autoscope and Manual Scope. _scope will be stored as an array of Integer bit positions reserved on first come first serve basis.
Weightages Weightages specified on request may be as an additional header. These weightages will be used while calculating the score while retrieving the records.
score Final value calculated based on weightages of the matched records. The record with highest score will be given priority over the next highest score and so on.

Getting started

  1. First we will create a model with autoscope organization.
```javascript
{
    "name": "Customer",
    "base": "BaseEntity",
    "strict": false,
    "idInjection": false,
    "options": {
        "validateUpsert": true
    },
    "properties": {
        "name": {
            "type": "string",
            "required": true
        }
    },
    "hidden": [],
    "validations": [],
    "relations": {},
    "acls": [],
    "methods": {},
    "autoscope": [
        "organization"
    ]
}
```
- Refresh the screen so that you can see your newly created model.

**Observation:** The model definition contains a property `autoscope` which is used to autoscope a model on some contributor.
  1. We will post data with manual scopes in it and no autoscope set.

    • Use api POST/Customers and post the following data.
    [
       {
            "name": "1manualScopes-device",
            "scope": {
                "device": "mobile"
            }
        },
        {
            "name": "2manualScopes-device-location",
            "scope": {
                "device": "desktop",
                "location": "in"
            }
        },
        {
            "name": "1manualScopes-lang",
            "scope": {
                "lang": "en-in"
            }
        },
        {
            "name": "2manualScopes-location-roles",
            "scope": {
                "location": "us",
                "roles": ["admin", "designer"]
            }
        }
    ]
    
    • You should get an error saying “Insufficient data, autoscope value not found for model customer”

    Observations: Whenever a model is autoscoped on some value then that value should be available for application to post the data.

  2. Will post data with manual scopes in it and autoscope values set.

    • In mod headers plugin set request headers with name= organization and value= ev and repeat the same process in step 2.
    • Your data should be successfully posted to customer model.

    Observations: The scope property in each record corresponds to manual scope for that record.

  3. We will try to post a record with scope value same as autoscope.

    • Use api POST/Customers and post the following data.
        {
            "name": "scopeValueEqual2Autoscope",
            "scope": {
                "organization": "ev"
            }
        }
    
    • It should throw an Error saying Invalid data.

    Observations: You cannot pass the contributors in scope if model is autoscoped on the same contributors.

summary

Congratulations!! You have successfully completed the guide on various concepts of manual and auto scope.