Skip to content

Commit

Permalink
feat: allow to configure aasId and aasIdShort (#53)
Browse files Browse the repository at this point in the history
* feat: allow to configure aasId and aasIdShort

* refactor: run format
  • Loading branch information
danielpeintner authored Oct 8, 2024
1 parent fc146ca commit a6943fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion node/aas-aid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Note: make sure that the file `counterHTTP.json` is in the same folder as the sc

The example `td-to-aid.js` loads the online [counter TD](http://plugfest.thingweb.io:8083/counter/) and converts it to an AID submodel in JSON format.

Note: by using the option `createAAS` a full AAS form is created (instead of the AID submodel only).
Note: by using the option `createAAS` a full AAS form is created (instead of the AID submodel only). The AAS can be configured with `aasId` and `aasIdShort` also.

```js
// td-to-aid.js
Expand Down
9 changes: 6 additions & 3 deletions node/aas-aid/src/asset-interfaces-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const logError = debug(`${namespace}:error`);

export interface Options {
createAAS?: boolean;
aasId?: string;
aasIdShort?: string;
}

export class AssetInterfacesDescription {
Expand Down Expand Up @@ -82,7 +84,7 @@ export class AssetInterfacesDescription {
* Transform WoT ThingDescription (TD) to AID submodel in JSON format
*
* @param td input TD
* @param options options such as creating AAS wrapper
* @param options options such as creating AAS wrapper with providing id/idShort
* @param protocols protocol prefixes of interest (e.g., ["http", "coap"]) or optional if all
* @returns transformed AAS in JSON format
*/
Expand All @@ -96,8 +98,9 @@ export class AssetInterfacesDescription {
const submodelId = submodelObj.id;

// configuration
const aasName = "SampleAAS";
const aasId = "https://example.com/ids/aas/7474_9002_6022_1115";
const aasName = !!options.aasIdShort ? options.aasIdShort : "SampleAAS";
const aasId =
options.aasId?.length !== 0 ? options.aasId : "https://example.com/ids/aas/7474_9002_6022_1115";

const aas = {
assetAdministrationShells: [
Expand Down
13 changes: 9 additions & 4 deletions node/aas-aid/test/asset-interfaces-description-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,12 +921,17 @@ class AssetInterfaceDescriptionTest {
}

@test async "should correctly transform sample TD1 into JSON AAS"() {
const sm = this.assetInterfacesDescription.transformTD2AID(JSON.stringify(this.td1), { createAAS: true }, [
"http",
]);
const sm = this.assetInterfacesDescription.transformTD2AID(
JSON.stringify(this.td1),
{ createAAS: true, aasIdShort: "FooAAS", aasId: "https://example.com/1234" },
["http"]
);

const aasObj = JSON.parse(sm);
expect(aasObj).to.have.property("assetAdministrationShells").to.be.an("array");
expect(aasObj).to.have.property("assetAdministrationShells").to.be.an("array").to.have.lengthOf(1);
const aas = aasObj.assetAdministrationShells[0];
expect(aas).to.have.property("idShort").to.eql("FooAAS");
expect(aas).to.have.property("id").to.eql("https://example.com/1234");
expect(aasObj).to.have.property("submodels").to.be.an("array").to.have.lengthOf(1);

// Note: proper AID submodel checks done in previous test-cases
Expand Down

0 comments on commit a6943fa

Please sign in to comment.