Skip to content

Commit 22cfb3a

Browse files
refactor: add AID support for terms created/modified/support (#1224)
1 parent 33be732 commit 22cfb3a

File tree

3 files changed

+116
-22
lines changed

3 files changed

+116
-22
lines changed

packages/td-tools/src/util/asset-interface-description.ts

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,35 +161,63 @@ export class AssetInterfaceDescriptionUtil {
161161
}
162162
}
163163

164+
const values = [
165+
{
166+
idShort: "title",
167+
valueType: "xs:string",
168+
value: td.title,
169+
modelType: "Property",
170+
semanticId: this.createSemanticId("https://www.w3.org/2019/wot/td#title"),
171+
},
172+
this.createEndpointMetadata(td, protocol, aidID, submodelElementIdShort), // EndpointMetadata like base, security and securityDefinitions
173+
this.createInteractionMetadata(td, protocol), // InteractionMetadata like properties, actions and events
174+
// Note: "ExternalDescriptor" should contain file values --> not applicable to TD
175+
/* {
176+
idShort: "ExternalDescriptor",
177+
semanticId: this.createSemanticId(
178+
"https://admin-shell.io/idta/AssetInterfacesDescription/1/0/ExternalDescriptor"
179+
),
180+
// embeddedDataSpecifications ?
181+
value: [],
182+
modelType: "SubmodelElementCollection",
183+
}, */
184+
];
185+
if (td.created != null) {
186+
values.push({
187+
idShort: "created",
188+
valueType: "xs:dateTime",
189+
value: td.created,
190+
modelType: "Property",
191+
semanticId: this.createSemanticId("http://purl.org/dc/terms/created"),
192+
});
193+
}
194+
if (td.modified != null) {
195+
values.push({
196+
idShort: "modified",
197+
valueType: "xs:dateTime",
198+
value: td.modified,
199+
modelType: "Property",
200+
semanticId: this.createSemanticId("http://purl.org/dc/terms/modified"),
201+
});
202+
}
203+
if (td.support != null) {
204+
values.push({
205+
idShort: "support",
206+
valueType: "xs:anyURI",
207+
value: td.support,
208+
modelType: "Property",
209+
semanticId: this.createSemanticId("https://www.w3.org/2019/wot/td#supportContact"),
210+
});
211+
}
212+
164213
const submdelElement = {
165214
idShort: submodelElementIdShort,
166215
semanticId: this.createSemanticId(
167216
"https://admin-shell.io/idta/AssetInterfacesDescription/1/0/Interface"
168217
),
169218
supplementalSemanticIds,
170219
// embeddedDataSpecifications needed?
171-
value: [
172-
{
173-
idShort: "title",
174-
valueType: "xs:string",
175-
value: td.title,
176-
modelType: "Property",
177-
semanticId: this.createSemanticId("https://www.w3.org/2019/wot/td#title"),
178-
},
179-
// created, modified, support ?
180-
this.createEndpointMetadata(td, protocol, aidID, submodelElementIdShort), // EndpointMetadata like base, security and securityDefinitions
181-
this.createInteractionMetadata(td, protocol), // InteractionMetadata like properties, actions and events
182-
// Note: "ExternalDescriptor" should contain file values --> not applicable to TD
183-
/* {
184-
idShort: "ExternalDescriptor",
185-
semanticId: this.createSemanticId(
186-
"https://admin-shell.io/idta/AssetInterfacesDescription/1/0/ExternalDescriptor"
187-
),
188-
// embeddedDataSpecifications ?
189-
value: [],
190-
modelType: "SubmodelElementCollection",
191-
}, */
192-
],
220+
value: values,
193221
modelType: "SubmodelElementCollection",
194222
};
195223

packages/td-tools/test/AssetInterfaceDescriptionTest.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ class AssetInterfaceDescriptionUtilTest {
205205
const tdObj = JSON.parse(td);
206206
expect(tdObj).to.have.property("@context").that.equals("https://www.w3.org/2022/wot/td/v1.1");
207207
expect(tdObj).to.have.property("title").that.equals("Inverter GEN44"); // should come form AAS
208+
expect(tdObj).to.have.property("created").that.equals("2020-12-09T16:09:53+00:00");
209+
expect(tdObj).to.have.property("modified").that.equals("2023-01-09T18:09:12+01:01");
210+
expect(tdObj).to.have.property("support").that.equals("mailto:idta@submodel.de");
208211

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

@@ -512,6 +515,9 @@ class AssetInterfaceDescriptionUtilTest {
512515
"@context": "https://www.w3.org/2022/wot/td/v1.1",
513516
title: "testTD",
514517
id: "urn:uuid:0804d572-cce8-422a-bb7c-4412fcd56f03",
518+
created: "2021-12-09T16:09:53+00:00",
519+
modified: "2024-01-09T18:09:12+01:01",
520+
support: "mailto:user@foo.com",
515521
securityDefinitions: {
516522
basic_sc: {
517523
scheme: "basic",
@@ -581,11 +587,23 @@ class AssetInterfaceDescriptionUtilTest {
581587
.to.be.an("array")
582588
.to.have.lengthOf.greaterThan(1); // default WoT-TD and http
583589
let hasThingTitle = false;
590+
let hasThingCreated = false;
591+
let hasThingModified = false;
592+
let hasThingSupport = false;
584593
let hasEndpointMetadata = false;
585594
for (const smValue of smInterface.value) {
586595
if (smValue.idShort === "title") {
587596
hasThingTitle = true;
588597
expect(smValue).to.have.property("value").to.equal("testTD");
598+
} else if (smValue.idShort === "created") {
599+
hasThingCreated = true;
600+
expect(smValue).to.have.property("value").to.equal("2021-12-09T16:09:53+00:00");
601+
} else if (smValue.idShort === "modified") {
602+
hasThingModified = true;
603+
expect(smValue).to.have.property("value").to.equal("2024-01-09T18:09:12+01:01");
604+
} else if (smValue.idShort === "support") {
605+
hasThingSupport = true;
606+
expect(smValue).to.have.property("value").to.equal("mailto:user@foo.com");
589607
} else if (smValue.idShort === "EndpointMetadata") {
590608
hasEndpointMetadata = true;
591609
const endpointMetadata = smValue;
@@ -667,6 +685,9 @@ class AssetInterfaceDescriptionUtilTest {
667685
}
668686
}
669687
expect(hasThingTitle, "No thing title").to.equal(true);
688+
expect(hasThingCreated, "No thing created").to.equal(true);
689+
expect(hasThingModified, "No thing modified").to.equal(true);
690+
expect(hasThingSupport, "No thing support").to.equal(true);
670691
expect(hasEndpointMetadata, "No EndpointMetadata").to.equal(true);
671692

672693
// InteractionMetadata with properties etc

packages/td-tools/test/util/inverterModbus.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,51 @@
3939
"value": "Inverter GEN44",
4040
"modelType": "Property"
4141
},
42+
{
43+
"idShort": "created",
44+
"semanticId": {
45+
"type": "ExternalReference",
46+
"keys": [
47+
{
48+
"type": "GlobalReference",
49+
"value": "http://purl.org/dc/terms/created"
50+
}
51+
]
52+
},
53+
"valueType": "xs:dateTime",
54+
"value": "2020-12-09T16:09:53+00:00",
55+
"modelType": "Property"
56+
},
57+
{
58+
"idShort": "modified",
59+
"semanticId": {
60+
"type": "ExternalReference",
61+
"keys": [
62+
{
63+
"type": "GlobalReference",
64+
"value": "http://purl.org/dc/terms/modified"
65+
}
66+
]
67+
},
68+
"valueType": "xs:dateTime",
69+
"value": "2023-01-09T18:09:12+01:01",
70+
"modelType": "Property"
71+
},
72+
{
73+
"idShort": "support",
74+
"semanticId": {
75+
"type": "ExternalReference",
76+
"keys": [
77+
{
78+
"type": "GlobalReference",
79+
"value": "https://www.w3.org/2019/wot/td#supportContact"
80+
}
81+
]
82+
},
83+
"valueType": "xs:anyURI",
84+
"value": "mailto:idta@submodel.de",
85+
"modelType": "Property"
86+
},
4287
{
4388
"idShort": "EndpointMetadata",
4489
"value": [

0 commit comments

Comments
 (0)