Skip to content

Commit

Permalink
rename: AssetInterfaceDescriptionUtil to AssetInterfacesDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeintner committed Mar 21, 2024
1 parent a0fdd71 commit 487ffb5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
14 changes: 7 additions & 7 deletions node/aas-aid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The [IDTA Asset Interface Description (AID) working group](https://github.com/ad

### AAS/AID to WoT TD

The file `counterHTTP.json` describes the counter sample in AAS/AID format for http binding. The `AssetInterfaceDescriptionUtil` utility class allows to transform the AID format to a valid WoT TD format which in the end can be properly consumed by node-wot.
The file `counterHTTP.json` describes the counter sample in AAS/AID format for http binding. The `AssetInterfacesDescription` utility class allows to transform the AID format to a valid WoT TD format which in the end can be properly consumed by node-wot.

The example `aid-to-td.js` tries to transform an AID submodel (from an AAS file) into a regular WoT TD.
Note: Besides converting the AID submodel it is also possible to convert a full AAS file (see `transformTD2AAS(...)`).
Expand All @@ -27,13 +27,13 @@ Servient = require("@node-wot/core").Servient;
HttpClientFactory = require("@node-wot/binding-http").HttpClientFactory;

// AID Util
AssetInterfaceDescriptionUtil = require("@node-wot/td-tools").AssetInterfaceDescriptionUtil;
AssetInterfacesDescription = require("@node-wot/td-tools").AssetInterfacesDescription;

// create Servient and add HTTP binding
let servient = new Servient();
servient.addClientFactory(new HttpClientFactory(null));

let assetInterfaceDescriptionUtil = new AssetInterfaceDescriptionUtil();
let assetInterfacesDescription = new AssetInterfacesDescription();

async function example() {
try {
Expand All @@ -44,7 +44,7 @@ async function example() {
const aid = JSON.stringify(JSON.parse(aas).submodels[0]);

// transform AID to WoT TD
const tdAID = assetInterfaceDescriptionUtil.transformSM2TD(aid, `{"title": "counter"}`);
const tdAID = assetInterfacesDescription.transformSM2TD(aid, `{"title": "counter"}`);
// Note: transformSM2TD() may have up to 3 input parameters
// * aid (required): AID submodel in JSON format
// * template (optional): Initial TD template
Expand Down Expand Up @@ -74,16 +74,16 @@ Note: Besides converting it into an AID submodel it is also possible to convert

```js
// td-to-aid.js
AssetInterfaceDescriptionUtil = require("@node-wot/td-tools").AssetInterfaceDescriptionUtil;
AssetInterfacesDescription = require("@node-wot/td-tools").AssetInterfacesDescription;

let assetInterfaceDescriptionUtil = new AssetInterfaceDescriptionUtil();
let assetInterfacesDescription = new AssetInterfacesDescription();

async function example() {
try {
const response = await fetch("http://plugfest.thingweb.io:8083/counter");
const counterTD = await response.json();

const sm = assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(counterTD), ["http", "coap"]);
const sm = assetInterfacesDescription.transformTD2SM(JSON.stringify(counterTD), ["http", "coap"]);

// print JSON format of AID submodel
console.log(sm);
Expand Down
2 changes: 1 addition & 1 deletion node/aas-aid/src/asset-interface-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const logError = debug(`${namespace}:error`);
*
*/

export class AssetInterfaceDescriptionUtil {
export class AssetInterfacesDescription {
/**
* Transform AAS in JSON format to a WoT ThingDescription (TD)
*
Expand Down
34 changes: 17 additions & 17 deletions node/aas-aid/test/AssetInterfaceDescriptionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { suite, test } from "@testdeck/mocha";
import { expect } from "chai";

import { AssetInterfaceDescriptionUtil } from "../src/asset-interface-description";
import { AssetInterfacesDescription } from "../src/asset-interface-description";
import { promises as fs } from "fs";
import { ThingDescription } from "wot-typescript-definitions";

Expand All @@ -27,8 +27,8 @@ const aidSchema = AIDSchema;
const ajv = new Ajv({ strict: false });

@suite("tests to verify the Asset Interface Description Utils")
class AssetInterfaceDescriptionUtilTest {
private assetInterfaceDescriptionUtil = new AssetInterfaceDescriptionUtil();
class AssetInterfaceDescriptionTest {
private assetInterfacesDescription = new AssetInterfacesDescription();

aidValidator = ajv.compile(aidSchema) as ValidateFunction;

Expand All @@ -53,7 +53,7 @@ class AssetInterfaceDescriptionUtilTest {
const isValid = this.validateAID(modelAIDobj.submodels[0]);
expect(isValid.valid, isValid.errors).to.equal(true);

const td = this.assetInterfaceDescriptionUtil.transformAAS2TD(modelAID, `{"title": "bla"}`);
const td = this.assetInterfacesDescription.transformAAS2TD(modelAID, `{"title": "bla"}`);

const tdObj = JSON.parse(td);
expect(tdObj).to.have.property("@context").that.equals("https://www.w3.org/2022/wot/td/v1.1");
Expand Down Expand Up @@ -173,7 +173,7 @@ class AssetInterfaceDescriptionUtilTest {
// TODO actions and events for counter thing (TBD by AAS)

// check RegEx capability with fully qualified submodel
const td2 = this.assetInterfaceDescriptionUtil.transformAAS2TD(
const td2 = this.assetInterfacesDescription.transformAAS2TD(
modelAID,
`{"title": "counter"}`,
"InterfaceHTTP"
Expand All @@ -182,12 +182,12 @@ class AssetInterfaceDescriptionUtilTest {
expect(tdObj).to.deep.equal(td2Obj);

// check RegEx capability with search pattern for submodel
const td3 = this.assetInterfaceDescriptionUtil.transformAAS2TD(modelAID, `{"title": "counter"}`, "HTTP*");
const td3 = this.assetInterfacesDescription.transformAAS2TD(modelAID, `{"title": "counter"}`, "HTTP*");
const td3Obj = JSON.parse(td3);
expect(tdObj).to.deep.equal(td3Obj);

// check RegEx capability with fully unknown submodel
const td4 = this.assetInterfaceDescriptionUtil.transformAAS2TD(modelAID, `{"title": "counter"}`, "OPC*");
const td4 = this.assetInterfacesDescription.transformAAS2TD(modelAID, `{"title": "counter"}`, "OPC*");
const td4Obj = JSON.parse(td4);
expect(td4Obj).to.not.have.property("properties");
}
Expand All @@ -200,7 +200,7 @@ class AssetInterfaceDescriptionUtilTest {
const isValid = this.validateAID(modelAIDobj.submodels[0]);
expect(isValid.valid, isValid.errors).to.equal(true);

const td = this.assetInterfaceDescriptionUtil.transformAAS2TD(modelAID, `{"title": "bla"}`);
const td = this.assetInterfacesDescription.transformAAS2TD(modelAID, `{"title": "bla"}`);

const tdObj = JSON.parse(td);
expect(tdObj).to.have.property("@context").that.equals("https://www.w3.org/2022/wot/td/v1.1");
Expand Down Expand Up @@ -277,9 +277,9 @@ class AssetInterfaceDescriptionUtilTest {

@test async "should correctly roundtrip inverterModbus from/to AID"() {
const aasInput = (await fs.readFile("test/inverterModbus.json")).toString();
const td = this.assetInterfaceDescriptionUtil.transformAAS2TD(aasInput);
const td = this.assetInterfacesDescription.transformAAS2TD(aasInput);

const aidOutput = this.assetInterfaceDescriptionUtil.transformTD2SM(td);
const aidOutput = this.assetInterfacesDescription.transformTD2SM(td);

const smObj = JSON.parse(aidOutput);
const isValid = this.validateAID(smObj);
Expand Down Expand Up @@ -564,7 +564,7 @@ class AssetInterfaceDescriptionUtilTest {
};

@test async "should correctly transform sample TD1 into AID submodel"() {
const sm = this.assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(this.td1), ["https"]);
const sm = this.assetInterfacesDescription.transformTD2SM(JSON.stringify(this.td1), ["https"]);

const smObj = JSON.parse(sm);
const isValid = this.validateAID(smObj);
Expand Down Expand Up @@ -835,14 +835,14 @@ class AssetInterfaceDescriptionUtilTest {

// Test to use all possible prefixes -> in this case it is only https
// Note: id is autogenerated (if not present) -> needs to be exluded/removed/set in TD
const sm2 = this.assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(this.td1));
const sm2 = this.assetInterfacesDescription.transformTD2SM(JSON.stringify(this.td1));
const sm2Obj = JSON.parse(sm2);
expect(smObj).to.eql(sm2Obj);
}

@test
async "should transform sample TD1 into JSON submodel without any properties due to unknown protocol prefix"() {
const sm = this.assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(this.td1), ["unknown"]);
const sm = this.assetInterfacesDescription.transformTD2SM(JSON.stringify(this.td1), ["unknown"]);

const smObj = JSON.parse(sm);
expect(smObj).to.have.property("idShort").that.equals("AssetInterfacesDescription");
Expand All @@ -867,7 +867,7 @@ class AssetInterfaceDescriptionUtilTest {
}

@test async "should correctly transform sample TD1 into JSON AAS"() {
const sm = this.assetInterfaceDescriptionUtil.transformTD2AAS(JSON.stringify(this.td1), ["http"]);
const sm = this.assetInterfacesDescription.transformTD2AAS(JSON.stringify(this.td1), ["http"]);

const aasObj = JSON.parse(sm);
expect(aasObj).to.have.property("assetAdministrationShells").to.be.an("array");
Expand Down Expand Up @@ -900,7 +900,7 @@ class AssetInterfaceDescriptionUtilTest {
};

@test async "should correctly transform sample TD2 into AID submodel"() {
const sm = this.assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(this.td2));
const sm = this.assetInterfacesDescription.transformTD2SM(JSON.stringify(this.td2));

const smObj = JSON.parse(sm);
// console.log("###\n\n" + JSON.stringify(smObj) + "\n\n###");
Expand Down Expand Up @@ -1079,7 +1079,7 @@ class AssetInterfaceDescriptionUtilTest {
};

@test async "should correctly transform sample TD3 into AID submodel"() {
const sm = this.assetInterfaceDescriptionUtil.transformTD2SM(JSON.stringify(this.td3));
const sm = this.assetInterfacesDescription.transformTD2SM(JSON.stringify(this.td3));

const smObj = JSON.parse(sm);
// console.log("###\n\n" + JSON.stringify(smObj) + "\n\n###");
Expand Down Expand Up @@ -1251,7 +1251,7 @@ class AssetInterfaceDescriptionUtilTest {
const response = await fetch("http://plugfest.thingweb.io:8083/counter");
const counterTD = await response.json();

const sm = this.assetInterfaceDescriptionUtil.transformTD2AAS(JSON.stringify(counterTD), ["http"]); // "coap"
const sm = this.assetInterfacesDescription.transformTD2AAS(JSON.stringify(counterTD), ["http"]); // "coap"
console.log("XXX AAS\n\n" + sm + "\n\nXXX");

const aasObj = JSON.parse(sm);
Expand Down

0 comments on commit 487ffb5

Please sign in to comment.