-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update measure model for localization #385
Open
cyrng
wants to merge
10
commits into
2-dev
Choose a base branch
from
KZLPRD-689-etq-utilisateur-jvp-definir-et-internationaliser-les-nomes-des-modeles-de-mesure-et-dassets
base: 2-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+280
−3
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
941ab60
feat: update measure model for localization
cyrng ebad7f4
feat: update asset model for localization and description
cyrng fa7b744
feat: add modelFriendlyName in asset mapping and in asset create endp…
cyrng da8ab39
feat: implement updateModelFriendlyName
cyrng 8dd45fb
feat: add asset history for modelFriendlyName update
cyrng 9b15d97
style: change naming
cyrng e889636
fix: update Container definition for ci
cyrng 44627aa
docs: add documentation for asset model and updateModelLocales endpoint
cyrng c015345
feat: add locales in MeasureModelContent type
cyrng 208a312
fix: let locales optional in measure model
cyrng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
code: true | ||
type: page | ||
title: updateModelLocales | ||
description: Update all assets localization | ||
--- | ||
|
||
# update | ||
|
||
Update all assets localization. | ||
|
||
The `updateModelLocales` operation allows you to update the `locales` of all `assets` related to the specified `asset model`. | ||
The process retrieve the locales values stored in the asset model and update the locales of all the assets with these values. For the moment, this operation has to be done `manually` when the asset model locales changed to make the `search` operation on assets to `be up to date`. | ||
|
||
## Query Syntax | ||
|
||
### HTTP | ||
|
||
```http | ||
URL: http://kuzzle:7512/_/device-manager/assets/modelLocales | ||
Method: PUT | ||
``` | ||
|
||
## Other protocols | ||
|
||
```js | ||
{ | ||
"controller": "device-manager/assets", | ||
"action": "updateModelLocales", | ||
"model": "Container", | ||
"engineGroup": "commons" | ||
} | ||
``` | ||
|
||
## Arguments | ||
|
||
- `engineGroup`: Engine group | ||
- `model`: asset model | ||
|
||
## Response | ||
|
||
```js | ||
{ | ||
"action": "updateModelLocales", | ||
"collection": "assets", | ||
"controller": "device-manager/assets", | ||
"error": null, | ||
"headers": {}, | ||
"index": "engine-ayse", | ||
"node": "knode-gigantic-iago-99422", | ||
"requestId": "3b86b6d1-8004-4273-ba03-94526b019b8a", | ||
"status": 200, | ||
"volatile": null | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ import { | |
import { | ||
AssetHistoryContent, | ||
AssetHistoryEventMetadata, | ||
AssetHistoryEventModelLocales, | ||
} from "./types/AssetHistoryContent"; | ||
|
||
export class AssetService extends DigitalTwinService { | ||
|
@@ -314,6 +315,7 @@ export class AssetService extends DigitalTwinService { | |
measures, | ||
metadata: { ...assetMetadata, ...metadata }, | ||
model, | ||
modelLocales: assetModel.asset.locales, | ||
reference, | ||
softTenant: [], | ||
}, | ||
|
@@ -598,6 +600,82 @@ export class AssetService extends DigitalTwinService { | |
return replacedAssets; | ||
} | ||
|
||
/** | ||
* Retrieve locales with the specified model and search all assets related to the model to update the locales. | ||
* The operation is historized. | ||
* @param request | ||
* @param engineGroup | ||
* @param model | ||
*/ | ||
public async updateModelLocales( | ||
request: KuzzleRequest, | ||
engineGroup: string, | ||
model: string, | ||
): Promise<void> { | ||
const { result } = await this.sdk.query({ | ||
action: "getAsset", | ||
body: {}, | ||
controller: "device-manager/models", | ||
engineGroup, | ||
model, | ||
}); | ||
|
||
const locales = result._source.asset.locales; | ||
|
||
const engines = await ask<AskEngineList>("ask:device-manager:engine:list", { | ||
group: engineGroup, | ||
}); | ||
|
||
const targets = engines.map((engine) => ({ | ||
collections: [InternalCollection.ASSETS], | ||
index: engine.index, | ||
})); | ||
|
||
const assets = await this.sdk.query< | ||
BaseRequest, | ||
DocumentSearchResult<AssetContent> | ||
>({ | ||
action: "search", | ||
body: { query: { equals: { model } } }, | ||
controller: "document", | ||
lang: "koncorde", | ||
targets, | ||
}); | ||
|
||
assets.result.hits.map((asset) => { | ||
asset._source.modelLocales = locales; | ||
}); | ||
|
||
for (const asset of assets.result.hits) { | ||
const updatedAsset = await this.updateDocument<AssetContent>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be optimized using an updateByQuery request |
||
request, | ||
{ | ||
_id: asset._id, | ||
_source: { modelLocales: locales }, | ||
}, | ||
{ | ||
collection: InternalCollection.ASSETS, | ||
engineId: asset.index, | ||
}, | ||
{ source: true }, | ||
); | ||
|
||
await this.assetHistoryService.add<AssetHistoryEventModelLocales>( | ||
asset.index, | ||
[ | ||
{ | ||
asset: updatedAsset._source, | ||
event: { | ||
name: "modelLocales", | ||
}, | ||
id: updatedAsset._id, | ||
timestamp: Date.now(), | ||
}, | ||
], | ||
); | ||
} | ||
} | ||
|
||
private async getEngine(engineId: string): Promise<JSONObject> { | ||
const engine = await this.sdk.document.get( | ||
this.config.adminIndex, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This request will only return 10 results... you should :