Skip to content

Commit

Permalink
refactor: support title and descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeintner committed Sep 7, 2023
1 parent c69a1a8 commit 6b8fffb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
32 changes: 28 additions & 4 deletions packages/td-tools/src/util/asset-interface-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ const logInfo = debug(`${namespace}:info`);
/** Utilities around Asset Interface Description
* https://github.com/admin-shell-io/submodel-templates/tree/main/development/Asset%20Interface%20Description/1/0
*
* e.g, transform to TD
* e.g, transform AAS (or AID submodel) to TD or vicerversa transform TD to AAS (or AID submodel)
*
*/

/*
* TODOs
* - Support desription(s) and title(s)
* - transformToTD without any binding prefix (Idea: collect first all possible bindings)
* - what is the desired input/output? string, object, ... ?
* - what are options that would be desired? (context version, id, security, ...) -> template mechanism fine?
Expand Down Expand Up @@ -679,7 +678,13 @@ export class AssetInterfaceDescriptionUtil {
// semanticId needed?
// embeddedDataSpecifications needed?
value: [
// support
{
idShort: "title",
valueType: "xs:string",
value: td.title,
modelType: "Property",
},
// support and other?
this.createEndpointMetadata(td), // EndpointMetadata like base, security and securityDefinitions
this.createInterfaceMetadata(td, protocol), // InterfaceMetadata like properties, actions and events
// externalDescriptor ?
Expand Down Expand Up @@ -870,9 +875,28 @@ export class AssetInterfaceDescriptionUtil {
});
}

let description;
if (propertyValue.descriptions) {
description = [];
for (const langKey in propertyValue.descriptions) {
const langValue = propertyValue.descriptions[langKey];
description.push({
language: langKey,
text: langValue,
});
}
} else if (propertyValue.description) {
// fallback
description = [];
description.push({
language: "en", // TODO where to get language identifier
text: propertyValue.description,
});
}

properties.push({
idShort: propertyKey,
// TODO description
description: description,
value: propertyValues,
modelType: "SubmodelElementCollection",
});
Expand Down
28 changes: 27 additions & 1 deletion packages/td-tools/test/AssetInterfaceDescriptionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ class AssetInterfaceDescriptionUtilTest {
status: {
type: "string",
observable: true,
descriptions: {
en: "Statistic",
de: "Statistik",
},
forms: [
{
href: "stat",
Expand All @@ -201,9 +205,13 @@ class AssetInterfaceDescriptionUtilTest {
expect(smObj).to.have.property("submodelElements").to.be.an("array").to.have.lengthOf.greaterThan(0);
const smInterface = smObj.submodelElements[0];
expect(smInterface).to.have.property("value").to.be.an("array").to.have.lengthOf.greaterThan(0);
let hasThingTitle = false;
let hasEndpointMetadata = false;
for (const smValue of smInterface.value) {
if (smValue.idShort === "EndpointMetadata") {
if (smValue.idShort === "title") {
hasThingTitle = true;
expect(smValue).to.have.property("value").to.equal("testTD");
} else if (smValue.idShort === "EndpointMetadata") {
hasEndpointMetadata = true;
const endpointMetadata = smValue;
expect(endpointMetadata).to.have.property("value").to.be.an("array").to.have.lengthOf.greaterThan(0);
Expand Down Expand Up @@ -257,6 +265,7 @@ class AssetInterfaceDescriptionUtilTest {
expect(hasSecurityDefinitions).to.equal(true);
}
}
expect(hasThingTitle, "No thing title").to.equal(true);
expect(hasEndpointMetadata, "No EndpointMetadata").to.equal(true);

// InterfaceMetadata with properties etc
Expand All @@ -274,6 +283,7 @@ class AssetInterfaceDescriptionUtilTest {
.to.be.an("array")
.to.have.lengthOf.greaterThan(0);
let hasPropertyStatus = false;
let hasPropertyStatusDescription = false;
for (const propertyValue of interactionValues.value) {
if (propertyValue.idShort === "status") {
hasPropertyStatus = true;
Expand Down Expand Up @@ -333,8 +343,24 @@ class AssetInterfaceDescriptionUtilTest {
expect(hasObservable).to.equal(true);
expect(hasForms).to.equal(true);
}
if (propertyValue.description) {
hasPropertyStatusDescription = true;
expect(propertyValue)
.to.have.property("description")
.to.eql([
{
language: "en",
text: "Statistic",
},
{
language: "de",
text: "Statistik",
},
]);
}
}
expect(hasPropertyStatus).to.equal(true);
expect(hasPropertyStatusDescription).to.equal(true);
}
}
expect(hasProperties).to.equal(true);
Expand Down

0 comments on commit 6b8fffb

Please sign in to comment.