Skip to content

Commit

Permalink
refactor: add AID support for terms created/modified/support (#1224)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeintner authored Jan 26, 2024
1 parent 33be732 commit 22cfb3a
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 22 deletions.
72 changes: 50 additions & 22 deletions packages/td-tools/src/util/asset-interface-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,35 +161,63 @@ export class AssetInterfaceDescriptionUtil {
}
}

const values = [
{
idShort: "title",
valueType: "xs:string",
value: td.title,
modelType: "Property",
semanticId: this.createSemanticId("https://www.w3.org/2019/wot/td#title"),
},
this.createEndpointMetadata(td, protocol, aidID, submodelElementIdShort), // EndpointMetadata like base, security and securityDefinitions
this.createInteractionMetadata(td, protocol), // InteractionMetadata like properties, actions and events
// Note: "ExternalDescriptor" should contain file values --> not applicable to TD
/* {
idShort: "ExternalDescriptor",
semanticId: this.createSemanticId(
"https://admin-shell.io/idta/AssetInterfacesDescription/1/0/ExternalDescriptor"
),
// embeddedDataSpecifications ?
value: [],
modelType: "SubmodelElementCollection",
}, */
];
if (td.created != null) {
values.push({
idShort: "created",
valueType: "xs:dateTime",
value: td.created,
modelType: "Property",
semanticId: this.createSemanticId("http://purl.org/dc/terms/created"),
});
}
if (td.modified != null) {
values.push({
idShort: "modified",
valueType: "xs:dateTime",
value: td.modified,
modelType: "Property",
semanticId: this.createSemanticId("http://purl.org/dc/terms/modified"),
});
}
if (td.support != null) {
values.push({
idShort: "support",
valueType: "xs:anyURI",
value: td.support,
modelType: "Property",
semanticId: this.createSemanticId("https://www.w3.org/2019/wot/td#supportContact"),
});
}

const submdelElement = {
idShort: submodelElementIdShort,
semanticId: this.createSemanticId(
"https://admin-shell.io/idta/AssetInterfacesDescription/1/0/Interface"
),
supplementalSemanticIds,
// embeddedDataSpecifications needed?
value: [
{
idShort: "title",
valueType: "xs:string",
value: td.title,
modelType: "Property",
semanticId: this.createSemanticId("https://www.w3.org/2019/wot/td#title"),
},
// created, modified, support ?
this.createEndpointMetadata(td, protocol, aidID, submodelElementIdShort), // EndpointMetadata like base, security and securityDefinitions
this.createInteractionMetadata(td, protocol), // InteractionMetadata like properties, actions and events
// Note: "ExternalDescriptor" should contain file values --> not applicable to TD
/* {
idShort: "ExternalDescriptor",
semanticId: this.createSemanticId(
"https://admin-shell.io/idta/AssetInterfacesDescription/1/0/ExternalDescriptor"
),
// embeddedDataSpecifications ?
value: [],
modelType: "SubmodelElementCollection",
}, */
],
value: values,
modelType: "SubmodelElementCollection",
};

Expand Down
21 changes: 21 additions & 0 deletions packages/td-tools/test/AssetInterfaceDescriptionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ class AssetInterfaceDescriptionUtilTest {
const tdObj = JSON.parse(td);
expect(tdObj).to.have.property("@context").that.equals("https://www.w3.org/2022/wot/td/v1.1");
expect(tdObj).to.have.property("title").that.equals("Inverter GEN44"); // should come form AAS
expect(tdObj).to.have.property("created").that.equals("2020-12-09T16:09:53+00:00");
expect(tdObj).to.have.property("modified").that.equals("2023-01-09T18:09:12+01:01");
expect(tdObj).to.have.property("support").that.equals("mailto:[email protected]");

expect(tdObj).to.have.property("securityDefinitions").to.be.an("object");

Expand Down Expand Up @@ -512,6 +515,9 @@ class AssetInterfaceDescriptionUtilTest {
"@context": "https://www.w3.org/2022/wot/td/v1.1",
title: "testTD",
id: "urn:uuid:0804d572-cce8-422a-bb7c-4412fcd56f03",
created: "2021-12-09T16:09:53+00:00",
modified: "2024-01-09T18:09:12+01:01",
support: "mailto:[email protected]",
securityDefinitions: {
basic_sc: {
scheme: "basic",
Expand Down Expand Up @@ -581,11 +587,23 @@ class AssetInterfaceDescriptionUtilTest {
.to.be.an("array")
.to.have.lengthOf.greaterThan(1); // default WoT-TD and http
let hasThingTitle = false;
let hasThingCreated = false;
let hasThingModified = false;
let hasThingSupport = false;
let hasEndpointMetadata = false;
for (const smValue of smInterface.value) {
if (smValue.idShort === "title") {
hasThingTitle = true;
expect(smValue).to.have.property("value").to.equal("testTD");
} else if (smValue.idShort === "created") {
hasThingCreated = true;
expect(smValue).to.have.property("value").to.equal("2021-12-09T16:09:53+00:00");
} else if (smValue.idShort === "modified") {
hasThingModified = true;
expect(smValue).to.have.property("value").to.equal("2024-01-09T18:09:12+01:01");
} else if (smValue.idShort === "support") {
hasThingSupport = true;
expect(smValue).to.have.property("value").to.equal("mailto:[email protected]");
} else if (smValue.idShort === "EndpointMetadata") {
hasEndpointMetadata = true;
const endpointMetadata = smValue;
Expand Down Expand Up @@ -667,6 +685,9 @@ class AssetInterfaceDescriptionUtilTest {
}
}
expect(hasThingTitle, "No thing title").to.equal(true);
expect(hasThingCreated, "No thing created").to.equal(true);
expect(hasThingModified, "No thing modified").to.equal(true);
expect(hasThingSupport, "No thing support").to.equal(true);
expect(hasEndpointMetadata, "No EndpointMetadata").to.equal(true);

// InteractionMetadata with properties etc
Expand Down
45 changes: 45 additions & 0 deletions packages/td-tools/test/util/inverterModbus.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,51 @@
"value": "Inverter GEN44",
"modelType": "Property"
},
{
"idShort": "created",
"semanticId": {
"type": "ExternalReference",
"keys": [
{
"type": "GlobalReference",
"value": "http://purl.org/dc/terms/created"
}
]
},
"valueType": "xs:dateTime",
"value": "2020-12-09T16:09:53+00:00",
"modelType": "Property"
},
{
"idShort": "modified",
"semanticId": {
"type": "ExternalReference",
"keys": [
{
"type": "GlobalReference",
"value": "http://purl.org/dc/terms/modified"
}
]
},
"valueType": "xs:dateTime",
"value": "2023-01-09T18:09:12+01:01",
"modelType": "Property"
},
{
"idShort": "support",
"semanticId": {
"type": "ExternalReference",
"keys": [
{
"type": "GlobalReference",
"value": "https://www.w3.org/2019/wot/td#supportContact"
}
]
},
"valueType": "xs:anyURI",
"value": "mailto:[email protected]",
"modelType": "Property"
},
{
"idShort": "EndpointMetadata",
"value": [
Expand Down

0 comments on commit 22cfb3a

Please sign in to comment.