From 5c406c34cbdf0df44049ecd1c4e3a5ee1351ea39 Mon Sep 17 00:00:00 2001 From: Adrien Maret Date: Mon, 26 Jul 2021 13:14:57 +0300 Subject: [PATCH] Rename tenantGroup to group (#89) --- .../register-metadata/index.md | 4 +-- .../register-measure/index.md | 6 ++-- .../register-metadata/index.md | 4 +-- .../register-qos/index.md | 4 +-- doc/1/guides/mappings/index.md | 6 ++-- features/fixtures/application/app.ts | 18 +++++------ lib/DeviceManagerPlugin.ts | 22 ++++++------- lib/controllers/EngineController.ts | 8 ++--- lib/models/CustomProperties.ts | 32 +++++++++---------- lib/services/EngineService.ts | 12 +++---- 10 files changed, 58 insertions(+), 58 deletions(-) diff --git a/doc/1/classes/assets-custom-properties/register-metadata/index.md b/doc/1/classes/assets-custom-properties/register-metadata/index.md index ae7a27a7..3ff74c6c 100644 --- a/doc/1/classes/assets-custom-properties/register-metadata/index.md +++ b/doc/1/classes/assets-custom-properties/register-metadata/index.md @@ -25,7 +25,7 @@ registerMetadata (mappings: JSONObject, options: JSONObject); | Properties | Type | Description | |-----------|-----------------------|---------------------------------------------| -| `tenantGroup` |
string
| Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition. | +| `group` |
string
| Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition. | ## Usage @@ -40,5 +40,5 @@ deviceManagerPlugin.assets.registerMetadata({ fields: { text: { type: 'text' } } } -}, { tenantGroup: 'water_management' }); +}, { group: 'water_management' }); ``` \ No newline at end of file diff --git a/doc/1/classes/devices-custom-properties/register-measure/index.md b/doc/1/classes/devices-custom-properties/register-measure/index.md index 7ca2d614..87efb656 100644 --- a/doc/1/classes/devices-custom-properties/register-measure/index.md +++ b/doc/1/classes/devices-custom-properties/register-measure/index.md @@ -26,7 +26,7 @@ registerMeasure (measureName: string, mappings: JSONObject, options: JSONObject) | Properties | Type | Description | |-----------|-----------------------|---------------------------------------------| -| `tenantGroup` |
string
| Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition | +| `group` |
string
| Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition | ## Usage @@ -44,7 +44,7 @@ deviceManagerPlugin.devices.registerMeasure( celsius: { type: 'float' } } }, - { tenantGroup: 'water_management' }); + { group: 'water_management' }); deviceManagerPlugin.devices.registerMeasure( 'humidity', @@ -58,5 +58,5 @@ deviceManagerPlugin.devices.registerMeasure( } } }, - { tenantGroup: 'air_quality' }); + { group: 'air_quality' }); ``` \ No newline at end of file diff --git a/doc/1/classes/devices-custom-properties/register-metadata/index.md b/doc/1/classes/devices-custom-properties/register-metadata/index.md index 2e24f89a..73080be5 100644 --- a/doc/1/classes/devices-custom-properties/register-metadata/index.md +++ b/doc/1/classes/devices-custom-properties/register-metadata/index.md @@ -25,7 +25,7 @@ registerMetadata (mappings: JSONObject, options: JSONObject); | Properties | Type | Description | |-----------|-----------------------|---------------------------------------------| -| `tenantGroup` |
string
| Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition. | +| `group` |
string
| Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition. | ## Usage @@ -40,5 +40,5 @@ deviceManagerPlugin.devices.registerMetadata({ fields: { text: { type: 'text' } } } -}, { tenantGroup: 'water_management' }); +}, { group: 'water_management' }); ``` \ No newline at end of file diff --git a/doc/1/classes/devices-custom-properties/register-qos/index.md b/doc/1/classes/devices-custom-properties/register-qos/index.md index 1e138228..58cc5d3b 100644 --- a/doc/1/classes/devices-custom-properties/register-qos/index.md +++ b/doc/1/classes/devices-custom-properties/register-qos/index.md @@ -25,7 +25,7 @@ registerQos (mappings: JSONObject, options: JSONObject); | Properties | Type | Description | |-----------|-----------------------|---------------------------------------------| -| `tenantGroup` |
string
| Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition. | +| `group` |
string
| Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition. | ## Usage @@ -36,5 +36,5 @@ const deviceManagerPlugin = new DeviceManagerPlugin(); deviceManagerPlugin.devices.registerQos({ battery: { type: 'integer' } -}, { tenantGroup: 'water_management' }); +}, { group: 'water_management' }); ``` \ No newline at end of file diff --git a/doc/1/guides/mappings/index.md b/doc/1/guides/mappings/index.md index 063fcdf1..2a351486 100644 --- a/doc/1/guides/mappings/index.md +++ b/doc/1/guides/mappings/index.md @@ -73,7 +73,7 @@ deviceManager.assets.registerMetadata({ deviceManager.assets.registerMetadata({ stillAlive: { type: 'boolean' } -}, { tenantGroup: 'astronaut' }); // A tenant group is specified : 'astronaut'. +}, { group: 'astronaut' }); // A tenant group is specified : 'astronaut'. // These are the mappings definition for the `metadata` field // of the `assets` collection will only be applied for // the 'astronaut' tenant. @@ -206,7 +206,7 @@ deviceManager.devices.registerMeasure('gravity', { }, value: { type: 'float' }, } -}, { tenantGroup: 'astronaut' }); +}, { group: 'astronaut' }); deviceManager.devices.registerQos({ // By default, every 'devices' tenant collection battery: { type: 'integer' } // will have the 'battery' property with the provided @@ -215,7 +215,7 @@ deviceManager.devices.registerQos({ // By default, every 'devices' ten deviceManager.devices.registerQos({ // The 'devices' collection of the 'astronaut' tenant durability: { type: 'float' } // will have the 'durability' property with the provided -}, { tenantGroup: 'astronaut' }); // mappings inside the 'qos' field. +}, { group: 'astronaut' }); // mappings inside the 'qos' field. deviceManager.devices.registerMetadata({ // By default, every 'devices' tenant collection group: { // will have the 'group' property with the provided diff --git a/features/fixtures/application/app.ts b/features/fixtures/application/app.ts index 5eb3281d..397a188e 100644 --- a/features/fixtures/application/app.ts +++ b/features/fixtures/application/app.ts @@ -58,7 +58,7 @@ deviceManager.devices.registerMeasure('gravity', { }, value: { type: 'float' }, } -}, { tenantGroup: 'astronaut' }); +}, { group: 'astronaut' }); deviceManager.devices.registerMeasure('acceleration', { properties: { @@ -71,34 +71,34 @@ deviceManager.devices.registerMeasure('acceleration', { }, acceleration: { type: 'float' }, } -}, { tenantGroup: 'astronaut' }); +}, { group: 'astronaut' }); deviceManager.devices.registerQos({ durability: { type: 'float' } -}, { tenantGroup: 'astronaut' }); +}, { group: 'astronaut' }); deviceManager.devices.registerQos({ signalStrenght: { type: 'float' } -}, { tenantGroup: 'astronaut' }); +}, { group: 'astronaut' }); deviceManager.devices.registerMetadata({ awake: { type: 'boolean' } -}, { tenantGroup: 'astronaut' }); +}, { group: 'astronaut' }); deviceManager.devices.registerMetadata({ sleeping: { type: 'boolean' } -}, { tenantGroup: 'astronaut' }); +}, { group: 'astronaut' }); deviceManager.assets.registerMetadata({ stillAlive: { type: 'boolean' } -}, { tenantGroup: 'astronaut' }); +}, { group: 'astronaut' }); deviceManager.assets.registerMetadata({ freezing: { type: 'boolean' } -}, { tenantGroup: 'astronaut' }); +}, { group: 'astronaut' }); app.plugin.use(deviceManager); @@ -113,7 +113,7 @@ app.config.set('plugins.kuzzle-plugin-logger.services.stdout.level', 'debug'); * Register pipe for scenario used to test the tenant specific event propagation */ app.pipe.register('tenant:tenant-ayse:device:new-payload', async eventParam => { - await app.sdk.realtime.publish('tests', 'messages', eventParam); + await app.sdk.realtime.publish('tests', 'messages', eventParam.result); return eventParam; }); diff --git a/lib/DeviceManagerPlugin.ts b/lib/DeviceManagerPlugin.ts index e711c432..09db33b4 100644 --- a/lib/DeviceManagerPlugin.ts +++ b/lib/DeviceManagerPlugin.ts @@ -192,12 +192,12 @@ export class DeviceManagerPlugin extends Plugin { const devicesProperties = this.devices.definitions.get('commons'); // Retrieve each group name which has custom properties definition - const tenantGroups = [...new Set(Array.from(this.devices.definitions.keys()) + const groups = [...new Set(Array.from(this.devices.definitions.keys()) .concat(Array.from(this.assets.definitions.keys())))]; // Init each group with 'devices' and 'assets' commons properties definition - for (const tenantGroup of tenantGroups) { - this.config.mappings.set(tenantGroup, { + for (const group of groups) { + this.config.mappings.set(group, { assets: { dynamic: 'false', properties: assetsProperties @@ -210,9 +210,9 @@ export class DeviceManagerPlugin extends Plugin { } // Merge custom 'devices' properties with commons properties - for (const [tenantGroup, customProperties] of this.devices.definitions) { - this.config.mappings.set(tenantGroup, { - assets: this.config.mappings.get(tenantGroup).assets, + for (const [group, customProperties] of this.devices.definitions) { + this.config.mappings.set(group, { + assets: this.config.mappings.get(group).assets, devices: { dynamic: 'false', properties: { @@ -224,8 +224,8 @@ export class DeviceManagerPlugin extends Plugin { } // Merge custom 'assets' properties with commons properties - for (const [tenantGroup, customProperties] of this.assets.definitions) { - this.config.mappings.set(tenantGroup, { + for (const [group, customProperties] of this.assets.definitions) { + this.config.mappings.set(group, { assets: { dynamic: 'false', properties: { @@ -233,7 +233,7 @@ export class DeviceManagerPlugin extends Plugin { ...customProperties } }, - devices: this.config.mappings.get(tenantGroup).devices, + devices: this.config.mappings.get(group).devices, }); // Use "devices" mappings to generate "assets" collection mappings @@ -244,7 +244,7 @@ export class DeviceManagerPlugin extends Plugin { model: { type: 'keyword' }, }; - const tenantMappings = this.config.mappings.get(tenantGroup); + const tenantMappings = this.config.mappings.get(group); for (const [measureType, definition] of Object.entries(tenantMappings.devices.properties.measures.properties) as any) { tenantMappings.assets.properties.measures.properties[measureType] = { @@ -258,7 +258,7 @@ export class DeviceManagerPlugin extends Plugin { } }; } - this.config.mappings.set(tenantGroup, tenantMappings); + this.config.mappings.set(group, tenantMappings); } // Merge custom mappings from decoders for payloads collection diff --git a/lib/controllers/EngineController.ts b/lib/controllers/EngineController.ts index 50c82441..856f940b 100644 --- a/lib/controllers/EngineController.ts +++ b/lib/controllers/EngineController.ts @@ -52,18 +52,18 @@ export class EngineController { async create (request: KuzzleRequest) { const index = request.getIndex(); - const tenantGroup = request.getString('group', 'commons'); + const group = request.getString('group', 'commons'); - const { collections } = await this.engineService.create(index, tenantGroup); + const { collections } = await this.engineService.create(index, group); return { index, collections }; } async update (request: KuzzleRequest) { const index = request.getIndex(); - const tenantGroup = request.getString('group', 'commons'); + const group = request.getString('group', 'commons'); - const { collections } = await this.engineService.update(index, tenantGroup); + const { collections } = await this.engineService.update(index, group); return { index, collections }; } diff --git a/lib/models/CustomProperties.ts b/lib/models/CustomProperties.ts index 146662ed..da411422 100644 --- a/lib/models/CustomProperties.ts +++ b/lib/models/CustomProperties.ts @@ -13,14 +13,14 @@ export class CustomProperties { this.definitions.set('commons', defaultMappings.properties); } - mergeMappings (propertyName: string, mappings: JSONObject, tenantGroup: string) { - const property = this.definitions.has(tenantGroup) - ? this.definitions.get(tenantGroup)[propertyName] || {} + mergeMappings (propertyName: string, mappings: JSONObject, group: string) { + const property = this.definitions.has(group) + ? this.definitions.get(group)[propertyName] || {} : {}; property.properties = { ...property.properties, ...mappings } - this.definitions.set(tenantGroup, { ...this.definitions.get(tenantGroup), [propertyName]: property }); + this.definitions.set(group, { ...this.definitions.get(group), [propertyName]: property }); } } @@ -30,10 +30,10 @@ export class AssetsCustomProperties extends CustomProperties { * * @param mappings Mappings definition of the "metadata" property * @param options Additional options - * - `tenantGroup` Name of the group for which the mappings should apply + * - `group` Name of the group for which the mappings should apply */ - registerMetadata (mappings: JSONObject, { tenantGroup='commons' }: { tenantGroup?: string } = {}) { - this.mergeMappings('metadata', mappings, tenantGroup); + registerMetadata (mappings: JSONObject, { group='commons' }: { group?: string } = {}) { + this.mergeMappings('metadata', mappings, group); } } @@ -43,10 +43,10 @@ export class DevicesCustomProperties extends CustomProperties { * * @param mappings Mappings definition of the "qos" property * @param options Additional options - * - `tenantGroup` Name of the group for which the mappings should apply + * - `group` Name of the group for which the mappings should apply */ - registerQos (mappings: JSONObject, { tenantGroup='commons' }: { tenantGroup?: string } = {}) { - this.mergeMappings('qos', mappings, tenantGroup); + registerQos (mappings: JSONObject, { group='commons' }: { group?: string } = {}) { + this.mergeMappings('qos', mappings, group); } /** @@ -54,10 +54,10 @@ export class DevicesCustomProperties extends CustomProperties { * * @param mappings Mappings definition of the "metadata" property * @param options Additional options - * - `tenantGroup` Name of the group for which the mappings should apply + * - `group` Name of the group for which the mappings should apply */ - registerMetadata (mappings: JSONObject, { tenantGroup='commons' }: { tenantGroup?: string } = {}) { - this.mergeMappings('metadata', mappings, tenantGroup); + registerMetadata (mappings: JSONObject, { group='commons' }: { group?: string } = {}) { + this.mergeMappings('metadata', mappings, group); } /** @@ -66,9 +66,9 @@ export class DevicesCustomProperties extends CustomProperties { * @param measureName Name of the measure property you mean to add (eg. 'temperature') * @param mappings Mappings definition of the added measure property * @param options Additional options - * - `tenantGroup` Name of the group for which the mappings should apply + * - `group` Name of the group for which the mappings should apply */ - registerMeasure (measureName: string, mappings: JSONObject, { tenantGroup='commons' }: { tenantGroup?: string } = {}) { - this.mergeMappings('measures', { [measureName]: { ...mappings } }, tenantGroup); + registerMeasure (measureName: string, mappings: JSONObject, { group='commons' }: { group?: string } = {}) { + this.mergeMappings('measures', { [measureName]: { ...mappings } }, group); } } diff --git a/lib/services/EngineService.ts b/lib/services/EngineService.ts index 4ecc9b4a..9a9a1113 100644 --- a/lib/services/EngineService.ts +++ b/lib/services/EngineService.ts @@ -19,15 +19,15 @@ export class EngineService { this.context = context; } - async create (index: string, tenantGroup = 'commons') { + async create (index: string, group = 'commons') { if (await this.exists(index)) { throw new BadRequestError(`Tenant "${index}" already have a device-manager engine`); } const collections = []; const promises = []; - const templates = this.config.mappings.get(tenantGroup) - ? this.config.mappings.get(tenantGroup) + const templates = this.config.mappings.get(group) + ? this.config.mappings.get(group) : this.config.mappings.get('commons'); for (const [collection, mappings] of Object.entries(templates)) { @@ -49,15 +49,15 @@ export class EngineService { return { collections }; } - async update (index: string, tenantGroup = 'commons') { + async update (index: string, group = 'commons') { if (! await this.exists(index)) { throw new NotFoundError(`Tenant "${index}" does not have a device-manager engine`); } const collections = []; const promises = []; - const templates = this.config.mappings.get(tenantGroup) - ? this.config.mappings.get(tenantGroup) + const templates = this.config.mappings.get(group) + ? this.config.mappings.get(group) : this.config.mappings.get('commons'); for (const [collection, mappings] of Object.entries(templates)) {