Skip to content

Commit

Permalink
2.0.0-rc28 - Revert new metadata format for device (#233)
Browse files Browse the repository at this point in the history
Co-authored-by: Aschen <amaret@kuzzle.io>
Co-authored-by: Sébastien <sebtiz13@gmail.com>
  • Loading branch information
3 people committed Oct 27, 2022
1 parent d43a99f commit c622290
Show file tree
Hide file tree
Showing 19 changed files with 3,015 additions and 1,136 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ doc/framework
frontmatter-errors.json

.vscode
.idea/
5 changes: 4 additions & 1 deletion features/AssetCategory.feature
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ Feature: AssetCategory
| body.model | "M" |
| body.reference | "asset_03" |
| body.category | "solarTruck" |
Then The formatted document "engine-ayse":"assets":"solarTruck-M-asset_03" content match:
When I successfully execute the action "device-manager/asset":"get" with args:
| engineId | "engine-ayse" |
| _id | "solarTruck-M-asset_03" |
Then I should receive a result matching:
| metadata.panelSurface | 101 |

Scenario: link, update and unlink a metadata on a parent category, and verify edition propagation on children category
Expand Down
12 changes: 2 additions & 10 deletions features/AssetController.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ Feature: DeviceManager asset controller
| body.model | "ALTMODEL" |
Then The document "engine-kuzzle":"assets":"outils-PERFO-asset_01" content match:
| model | "ALTMODEL" |
When I successfully execute the action "document":"update" with args:
| index | "engine-kuzzle" |
| collection | "assets" |
When I successfully execute the action "device-manager/asset":"update" with args:
| engineId | "engine-kuzzle" |
| _id | "outils-PERFO-asset_01" |
| options.prettify | true |
| body.metadata.foobar | 42 |
| body.metadata.index | "engine-kuzzle" |
| body.model | "PERFO" |
Expand All @@ -28,12 +26,6 @@ Feature: DeviceManager asset controller
| model | "PERFO" |
| metadata.foobar | 42 |
| metadata.index | "engine-kuzzle" |
And The document "engine-kuzzle":"assets":"outils-PERFO-asset_01" content match:
| model | "PERFO" |
| metadata[0].key | "foobar" |
| metadata[0].value.integer | 42 |
| metadata[1].key | "index" |
| metadata[1].value.keyword | "engine-kuzzle" |
Then I refresh the collection "engine-kuzzle":"assets"
When I successfully execute the action "device-manager/asset":"search" with args:
| engineId | "engine-kuzzle" |
Expand Down
34 changes: 0 additions & 34 deletions features/DeviceController/Update.feature

This file was deleted.

17 changes: 0 additions & 17 deletions features/Observer.feature

This file was deleted.

2 changes: 1 addition & 1 deletion features/PayloadController.feature
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Feature: Payloads Controller
| lvlBattery | 0.8 |
| metadata.color | "RED" |
And I refresh the collection "device-manager":"devices"
Then The formatted document "device-manager":"devices":"DummyTemp-12345" content match:
Then The document "device-manager":"devices":"DummyTemp-12345" content match:
| reference | "12345" |
| model | "DummyTemp" |
| metadata.color | "RED" |
2 changes: 1 addition & 1 deletion features/fixtures/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ for (let i = 0; i < 50; i++) {
reference: `detached-${i}`,
model: "DummyTemp",
measures: [],
metadata: [],
metadata: {},
engineId: null,
assetId: null,
});
Expand Down
8 changes: 0 additions & 8 deletions features/step_definitions/common/controllers-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ Then("I should receive a result matching:", function (dataTable) {
should(this.props.result).matchObject(expectedResult);
});

Then("I should have a realtime object matching:", function (dataTable) {
const expectedResult = this.parseObject(dataTable);

should(this.props.realtime).not.be.undefined();

should(this.props.result).matchObject(expectedResult);
});

Then(
"The property {string} of the result should match:",
function (path, dataTable) {
Expand Down
24 changes: 3 additions & 21 deletions features/step_definitions/common/documents-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,11 @@ Then(

Then(
"The document {string}:{string}:{string} content match:",
async function (index, collection, _id, dataTable) {
async function (index, collection, documentId, dataTable) {
const expectedContent = this.parseObject(dataTable);
const document = await this.sdk.document.get(index, collection, _id);
should(document._source).matchObject(expectedContent);
}
);

Then(
"The formatted document {string}:{string}:{string} content match:",
async function (index, collection, _id, dataTable) {
const expectedContent = this.parseObject(dataTable);
const response = await this.sdk.query({
controller: "document",
action: "get",
body: {},
index,
collection,
_id,
options: {
prettify: true,
},
});
const document = response.result;
const document = await this.sdk.document.get(index, collection, documentId);

should(document._source).matchObject(expectedContent);
}
);
Expand Down
14 changes: 0 additions & 14 deletions features/step_definitions/observer-step.js

This file was deleted.

45 changes: 2 additions & 43 deletions lib/DeviceManagerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
KuzzleRequest,
BadRequestError,
BatchController,
Request,
} from "kuzzle";
import { ConfigManager, EngineController } from "kuzzle-plugin-commons";

Expand Down Expand Up @@ -194,8 +193,6 @@ export class DeviceManagerPlugin extends Plugin {

this.context = context;

this.assetCategoryService = new AssetCategoryService(this);

/* eslint-disable sort-keys */
this.pipes = {
"device-manager/asset:before*": this.pipeCheckEngine.bind(this),
Expand All @@ -204,40 +201,6 @@ export class DeviceManagerPlugin extends Plugin {
"device-manager/device:beforeSearch": this.pipeCheckEngine.bind(this),
"device-manager/device:beforeUpdate": this.pipeCheckEngine.bind(this),
"generic:document:beforeWrite": [],
"generic:document:afterGet": async (documents, request: Request) => {
if (
(request.input.args.collection === "assets" ||
request.input.args.collection === "devices") &&
request.input.args.options?.prettify
) {
for (const document of documents) {
if (document._source?.metadata) {
document._source.metadata =
this.assetCategoryService.formatMetadataForGet(
document._source.metadata
);
}
}
}
return documents;
},
"generic:document:beforeUpdate": async (documents, request: Request) => {
if (
(request.input.args.collection === "assets" ||
request.input.args.collection === "devices") &&
request.input.args.options?.prettify
) {
for (const document of documents) {
if (document._source?.metadata) {
document._source.metadata =
this.assetCategoryService.formatMetadataForES(
document._source.metadata
);
}
}
}
return documents;
},
};
/* eslint-enable sort-keys */

Expand All @@ -264,6 +227,7 @@ export class DeviceManagerPlugin extends Plugin {
settings: this.config.engineCollections.config.settings,
});

this.assetCategoryService = new AssetCategoryService(this);
this.batchController = new BatchController(this.sdk as any, {
interval: this.config.batchInterval,
});
Expand All @@ -282,7 +246,6 @@ export class DeviceManagerPlugin extends Plugin {
this.measuresRegister,
this.assetCategoryService
);

this.payloadService = new PayloadService(
this,
this.batchController,
Expand All @@ -308,11 +271,7 @@ export class DeviceManagerPlugin extends Plugin {
this.measuresService
);

this.deviceController = new DeviceController(
this,
this.deviceService,
this.assetCategoryService
);
this.deviceController = new DeviceController(this, this.deviceService);
this.decodersController = new DecoderController(
this,
this.decodersRegister
Expand Down
5 changes: 2 additions & 3 deletions lib/modules/asset-category/AssetCategoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
FormattedMetadata,
FormattedValue,
} from "./types/AssetCategoryContent";
import { EsDeviceContent } from "../device";

export class AssetCategoryService {
private config: DeviceManagerConfiguration;
Expand Down Expand Up @@ -233,8 +232,8 @@ export class AssetCategoryService {
* @param document
*/
formatDocumentMetadata(
document: KDocument<BaseAssetContent | EsDeviceContent>
): KDocument<BaseAssetContent | EsDeviceContent> {
document: KDocument<BaseAssetContent>
): KDocument<BaseAssetContent> {
const metadata = document._source.metadata;
if (metadata) {
const asset = document._source as JSONObject;
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/device/Device.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { JSONObject } from "kuzzle-sdk";
import _ from "lodash";

import { MeasureContent } from "./../measure";
import { LinkRequest } from "./../asset";

import { DeviceContent } from "./types/DeviceContent";
import _ from "lodash";

export class Device {
static id(model: string, reference: string) {
Expand All @@ -18,7 +18,7 @@ export class Device {
this._id = _id || Device.id(content.model, content.reference);

this._source = {
metadata: [],
metadata: {},
...content,
};

Expand Down
40 changes: 3 additions & 37 deletions lib/modules/device/DeviceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,18 @@ import _ from "lodash";
import { MeasureNamesLink, LinkRequest, AttachRequest } from "./../asset";
import { DeviceManagerPlugin } from "./../../DeviceManagerPlugin";
import { DeviceManagerConfiguration } from "./../engine";
import { AssetCategoryService } from "../asset-category";

import { DeviceService, DeviceBulkContent } from "./DeviceService";
import { Device } from "./Device";
import { DeviceContent, EsDeviceContent } from "./types/DeviceContent";
import { DeviceContent } from "./types/DeviceContent";

export class DeviceController extends CRUDController {
protected config: DeviceManagerConfiguration;

private deviceService: DeviceService;
private assetCategoryService: AssetCategoryService;

protected get sdk() {
return this.context.accessors.sdk;
}

constructor(
plugin: DeviceManagerPlugin,
deviceService: DeviceService,
assetCategoryService: AssetCategoryService
) {
constructor(plugin: DeviceManagerPlugin, deviceService: DeviceService) {
super(plugin, "devices");
this.assetCategoryService = assetCategoryService;

this.deviceService = deviceService;

Expand All @@ -55,12 +44,6 @@ export class DeviceController extends CRUDController {
{ path: "device-manager/devices/:_id/_detach", verb: "delete" },
],
},
get: {
handler: this.get.bind(this),
http: [
{ path: "device-manager/:engineId/devices/:_id", verb: "get" },
],
},
importDevices: {
handler: this.importDevices.bind(this),
http: [{ path: "device-manager/devices/_import", verb: "post" }],
Expand Down Expand Up @@ -139,28 +122,14 @@ export class DeviceController extends CRUDController {
/* eslint-enable sort-keys */
}

async get(request: KuzzleRequest) {
const id = request.getId();
const engineId = request.getString("engineId");
const document = await this.sdk.document.get<EsDeviceContent>(
engineId,
this.collection,
id
);
this.assetCategoryService.formatDocumentMetadata(document);
return document._source;
}

/**
* Create and provision a new device
*/
async create(request: KuzzleRequest) {
const engineId = request.getString("engineId");
const model = request.getBodyString("model");
const reference = request.getBodyString("reference");
const rawMetadata = request.getBodyObject("metadata", {});
const metadata = this.assetCategoryService.formatMetadataForES(rawMetadata);

const metadata = request.getBodyObject("metadata", {});
const refresh = request.getRefresh();

const assetId = request.getBodyString("assetId", "");
Expand Down Expand Up @@ -207,9 +176,6 @@ export class DeviceController extends CRUDController {

async update(request: KuzzleRequest) {
request.input.args.index = request.getString("engineId");
const rawMetadata = request.getBodyObject("metadata", {});
const metadata = this.assetCategoryService.formatMetadataForES(rawMetadata);
request.input.body.metadata = metadata;

return super.update(request);
}
Expand Down

0 comments on commit c622290

Please sign in to comment.