From 22cfb3a3ef4c73c856c34459c05b4dd010ca2d95 Mon Sep 17 00:00:00 2001
From: danielpeintner <daniel.peintner@gmail.com>
Date: Fri, 26 Jan 2024 15:32:24 +0100
Subject: [PATCH] refactor: add AID support for terms created/modified/support
 (#1224)

---
 .../src/util/asset-interface-description.ts   | 72 +++++++++++++------
 .../test/AssetInterfaceDescriptionTest.ts     | 21 ++++++
 .../td-tools/test/util/inverterModbus.json    | 45 ++++++++++++
 3 files changed, 116 insertions(+), 22 deletions(-)

diff --git a/packages/td-tools/src/util/asset-interface-description.ts b/packages/td-tools/src/util/asset-interface-description.ts
index 616c23c20..b3f48fdbe 100644
--- a/packages/td-tools/src/util/asset-interface-description.ts
+++ b/packages/td-tools/src/util/asset-interface-description.ts
@@ -161,6 +161,55 @@ 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(
@@ -168,28 +217,7 @@ export class AssetInterfaceDescriptionUtil {
                 ),
                 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",
             };
 
diff --git a/packages/td-tools/test/AssetInterfaceDescriptionTest.ts b/packages/td-tools/test/AssetInterfaceDescriptionTest.ts
index 462ce9e78..aa68480eb 100644
--- a/packages/td-tools/test/AssetInterfaceDescriptionTest.ts
+++ b/packages/td-tools/test/AssetInterfaceDescriptionTest.ts
@@ -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:idta@submodel.de");
 
         expect(tdObj).to.have.property("securityDefinitions").to.be.an("object");
 
@@ -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:user@foo.com",
         securityDefinitions: {
             basic_sc: {
                 scheme: "basic",
@@ -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:user@foo.com");
             } else if (smValue.idShort === "EndpointMetadata") {
                 hasEndpointMetadata = true;
                 const endpointMetadata = smValue;
@@ -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
diff --git a/packages/td-tools/test/util/inverterModbus.json b/packages/td-tools/test/util/inverterModbus.json
index a1de562ec..e9d4382f9 100644
--- a/packages/td-tools/test/util/inverterModbus.json
+++ b/packages/td-tools/test/util/inverterModbus.json
@@ -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:idta@submodel.de",
+                            "modelType": "Property"
+                        },
                         {
                             "idShort": "EndpointMetadata",
                             "value": [