Follow AID spec more
This commit is contained in:
+43
-45
@@ -37,28 +37,46 @@ export default class AIMCMapper {
|
||||
const aimc = AIMCParser.parse(this.env);
|
||||
if (aimc === null) return;
|
||||
|
||||
for (const endpointConf of Object.values(aimc)) {
|
||||
for (const entry of endpointConf) {
|
||||
const ep = AIDParser.parseEndpointMetaData(entry.EndpointMetaDataReference);
|
||||
if (ep === null) continue;
|
||||
|
||||
for (const mapping of entry.MappingConfiguration) {
|
||||
//const ifm = AIDParser.parseInterfaceMetaData(mapping.InterfaceMetaDataReference);
|
||||
//if (ifm === null) continue;
|
||||
// Why do we need this? We already have the interface metadata reference in every ssm
|
||||
for (const entry of aimc) {
|
||||
const ep = AIDParser.parseEndpointMetaData(entry.EndpointMetaDataReference);
|
||||
if (ep === null) continue;
|
||||
|
||||
for (const mapping of entry.MappingConfiguration) {
|
||||
//const ifm = AIDParser.parseInterfaceMetaData(mapping.InterfaceMetaDataReference);
|
||||
//if (ifm === null) continue;
|
||||
// Why do we need this? We already have the interface metadata reference in every ssm
|
||||
|
||||
for (const ssm of mapping.SourceSinkMappings) {
|
||||
const resolved = Traverser.resolveRelationship(this.env, ssm);
|
||||
if (resolved === null) continue;
|
||||
for (const ssm of mapping.SourceSinkMappings) {
|
||||
const resolved = Traverser.resolveRelationship(this.env, ssm);
|
||||
if (resolved === null) continue;
|
||||
|
||||
// To know if we currently view a property, action or event, they reference keys can help us.
|
||||
// We know the third to last must be the "InterfaceMetadata" and the second to last must be the "Properties", "Actions" or "Events".
|
||||
// As we _maybe_ don't know if the first and second reference are switched we can check for the third to last.
|
||||
const elemType = (ssm as types.RelationshipElement).first.keys.at(-3)?.value.toLocaleLowerCase() === "interfacemetadata" ? (ssm as types.RelationshipElement).first.keys.at(-2)?.value : (ssm as types.RelationshipElement).second.keys.at(-2)?.value;
|
||||
// To know if we currently view a property, action or event, they reference keys can help us.
|
||||
// We know the third to last must be the "InterfaceMetadata" and the second to last must be the "Properties", "Actions" or "Events".
|
||||
// As we _maybe_ don't know if the first and second reference are switched we can check for the third to last.
|
||||
const elemType = (ssm as types.RelationshipElement).first.keys.at(-3)?.value.toLocaleLowerCase() === "interfacemetadata" ? (ssm as types.RelationshipElement).first.keys.at(-2)?.value : (ssm as types.RelationshipElement).second.keys.at(-2)?.value;
|
||||
|
||||
let {first, second} = resolved;
|
||||
let {first, second} = resolved;
|
||||
|
||||
let parsedPropConf: InterfaceProperty | InterfaceAction | InterfaceEvent | null = null;
|
||||
let parsedPropConf: InterfaceProperty | InterfaceAction | InterfaceEvent | null = null;
|
||||
|
||||
switch (elemType?.toLocaleLowerCase()) {
|
||||
case "properties":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataProperty(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
case "actions":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataAction(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
case "events":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataEvent(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
default:
|
||||
// Error. We have not found a valid type of element to parse.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parsedPropConf === null) {
|
||||
// maybe the property is in the first element
|
||||
[first, second] = [second, first];
|
||||
|
||||
switch (elemType?.toLocaleLowerCase()) {
|
||||
case "properties":
|
||||
@@ -70,35 +88,15 @@ export default class AIMCMapper {
|
||||
case "events":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataEvent(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
default:
|
||||
// Error. We have not found a valid type of element to parse.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parsedPropConf === null) {
|
||||
// maybe the property is in the first element
|
||||
[first, second] = [second, first];
|
||||
|
||||
switch (elemType?.toLocaleLowerCase()) {
|
||||
case "properties":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataProperty(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
case "actions":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataAction(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
case "events":
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataEvent(first as types.SubmodelElementCollection);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (parsedPropConf === null) continue;
|
||||
|
||||
this.map.set(second, ({
|
||||
...ep,
|
||||
...parsedPropConf
|
||||
} as any as ConnectionConfiguration));
|
||||
}
|
||||
|
||||
if (parsedPropConf === null) continue;
|
||||
|
||||
this.map.set(second, ({
|
||||
...ep,
|
||||
...parsedPropConf
|
||||
} as any as ConnectionConfiguration));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ export default class MultiMessageBroker {
|
||||
const interfaceDescription = AIDParser.parse(registration.aas);
|
||||
if (!interfaceDescription) continue;
|
||||
|
||||
const endpoints = Object.values(interfaceDescription).flatMap(idEntries => idEntries.map(entry => entry.EndPointMetadata));
|
||||
const endpoints = interfaceDescription.map(entry => entry.EndPointMetadata);
|
||||
const uniqueProtocols: Record<string, EndpointMetadata[]> = {};
|
||||
|
||||
endpoints.forEach(endpoint => {
|
||||
|
||||
+32
-32
@@ -19,19 +19,13 @@ export default class AIDParser {
|
||||
const sm = Traverser.findSMByIdShort(env, "AssetInterfacesDescription");
|
||||
if (sm === null || sm.submodelElements === null) return null;
|
||||
|
||||
const parsed = {} as AssetInterfacesDescription;
|
||||
const parsed = [] as AssetInterfacesDescription;
|
||||
|
||||
sm.submodelElements.forEach(e => {
|
||||
if (!aasCore.types.isSubmodelElementList(e) || !e.idShort || !e.value) return;
|
||||
|
||||
const endpointProto = endpointAvailable(e.idShort);
|
||||
if (!endpointProto) return;
|
||||
|
||||
parsed[endpointProto] = e.value.map(element => {
|
||||
if (!aasCore.types.isSubmodelElementCollection(element)) return null;
|
||||
|
||||
return AIDParser.parseAIDEntry(element, endpointProto);
|
||||
}).filter(e => e !== null) as InterfaceDescription[];
|
||||
if (!aasCore.types.isSubmodelElementCollection(e) || !e.value) return;
|
||||
const parsedInterface = AIDParser.parseAIDEntry(e);
|
||||
if (parsedInterface === null) return;
|
||||
parsed.push(parsedInterface);
|
||||
});
|
||||
|
||||
return parsed;
|
||||
@@ -43,7 +37,7 @@ export default class AIDParser {
|
||||
* @param endpointProtocol Protocol used in the endpoint, so additional properties can be parsed
|
||||
* @returns Description for one interface or null if not parsable
|
||||
*/
|
||||
private static parseAIDEntry(entry: aasCore.types.SubmodelElementCollection, endpointProtocol?: AvailableEndpoint): InterfaceDescription | null {
|
||||
private static parseAIDEntry(entry: aasCore.types.SubmodelElementCollection): InterfaceDescription | null {
|
||||
const title = Traverser.findElement(entry, element => (element as any).idShort?.toLocaleLowerCase() === "title");
|
||||
const titleString = title !== null && aasCore.types.isProperty(title) && title.value ? title.value : "";
|
||||
|
||||
@@ -51,7 +45,9 @@ export default class AIDParser {
|
||||
const im = Traverser.findElement(entry, element => (element as any).idShort?.toLocaleLowerCase() === "interfacemetadata");
|
||||
if (ep === null || !aasCore.types.isSubmodelElementCollection(ep) || !ep.value || im === null || !aasCore.types.isSubmodelElementCollection(im) || !im.value) return null;
|
||||
|
||||
const parsedEp = AIDParser.parseEndpointMetaData(ep, endpointProtocol);
|
||||
const parsedEp = AIDParser.parseEndpointMetaData(ep);
|
||||
const endpointProtocol = endpointAvailable(parsedEp?.base ?? "");
|
||||
|
||||
const parsedIm = AIDParser.parseInterfaceMetaData(im, endpointProtocol);
|
||||
if (parsedEp === null || parsedIm === null) return null;
|
||||
|
||||
@@ -69,7 +65,7 @@ export default class AIDParser {
|
||||
* @param endpointProtocol Protocol used in the endpoint, so additional properties can be parsed
|
||||
* @returns Parsed EndpointMetaData or null if not parsable
|
||||
*/
|
||||
public static parseEndpointMetaData(endpoint: aasCore.types.SubmodelElementCollection, endpointProtocol?: AvailableEndpoint): EndpointMetadata | null {
|
||||
public static parseEndpointMetaData(endpoint: aasCore.types.SubmodelElementCollection): EndpointMetadata | null {
|
||||
if (!endpoint.value || endpoint.idShort?.toLocaleLowerCase() !== "endpointmetadata") return null;
|
||||
|
||||
const parsed = {} as EndpointMetadata;
|
||||
@@ -82,6 +78,7 @@ export default class AIDParser {
|
||||
|
||||
// TODO
|
||||
// Other values based on endpoint protocol
|
||||
// Protocol is set in base string
|
||||
|
||||
return parsed;
|
||||
}
|
||||
@@ -106,30 +103,33 @@ export default class AIDParser {
|
||||
} as InterfaceMetadata;
|
||||
|
||||
const prop = Traverser.findElement(interfaceMeta, element => (element as any).idShort?.toLocaleLowerCase() === "properties");
|
||||
if (prop === null || !aasCore.types.isSubmodelElementList(prop) || !prop.value) return null; // Mandatory
|
||||
for (const element of prop.overValueOrEmpty()) {
|
||||
if (!aasCore.types.isSubmodelElementCollection(element)) continue;
|
||||
const parsedProp = AIDParser.parseInterfaceMetadataProperty(element, endpointProtocol);
|
||||
if (parsedProp === null) continue;
|
||||
parsed.properties.push(parsedProp);
|
||||
if (prop !== null && aasCore.types.isSubmodelElementCollection(prop)) {
|
||||
for (const element of prop.overValueOrEmpty()) {
|
||||
if (!aasCore.types.isSubmodelElementCollection(element)) continue;
|
||||
const parsedProp = AIDParser.parseInterfaceMetadataProperty(element, endpointProtocol);
|
||||
if (parsedProp === null) continue;
|
||||
parsed.properties.push(parsedProp);
|
||||
}
|
||||
}
|
||||
|
||||
const actions = Traverser.findElement(interfaceMeta, element => (element as any).idShort?.toLocaleLowerCase() === "actions");
|
||||
if (actions === null || !aasCore.types.isSubmodelElementList(actions) || !actions.value) return null; // Mandatory
|
||||
for (const element of actions.overValueOrEmpty()) {
|
||||
if (!aasCore.types.isSubmodelElementCollection(element)) continue;
|
||||
const parsedAction = AIDParser.parseInterfaceMetadataAction(element, endpointProtocol);
|
||||
if (parsedAction === null) continue;
|
||||
parsed.actions.push(parsedAction);
|
||||
if (actions !== null && aasCore.types.isSubmodelElementCollection(actions)) {
|
||||
for (const element of actions.overValueOrEmpty()) {
|
||||
if (!aasCore.types.isSubmodelElementCollection(element)) continue;
|
||||
const parsedAction = AIDParser.parseInterfaceMetadataAction(element, endpointProtocol);
|
||||
if (parsedAction === null) continue;
|
||||
parsed.actions.push(parsedAction);
|
||||
}
|
||||
}
|
||||
|
||||
const events = Traverser.findElement(interfaceMeta, element => (element as any).idShort?.toLocaleLowerCase() === "events");
|
||||
if (events === null || !aasCore.types.isSubmodelElementList(events) || !events.value) return null; // Mandatory
|
||||
for (const element of events.overValueOrEmpty()) {
|
||||
if (!aasCore.types.isSubmodelElementCollection(element)) continue;
|
||||
const parsedEvent = AIDParser.parseInterfaceMetadataEvent(element, endpointProtocol);
|
||||
if (parsedEvent === null) continue;
|
||||
parsed.events.push(parsedEvent);
|
||||
if (events !== null && aasCore.types.isSubmodelElementCollection(events)) {
|
||||
for (const element of events.overValueOrEmpty()) {
|
||||
if (!aasCore.types.isSubmodelElementCollection(element)) continue;
|
||||
const parsedEvent = AIDParser.parseInterfaceMetadataEvent(element, endpointProtocol);
|
||||
if (parsedEvent === null) continue;
|
||||
parsed.events.push(parsedEvent);
|
||||
}
|
||||
}
|
||||
|
||||
return parsed as InterfaceMetadata;
|
||||
|
||||
@@ -19,19 +19,13 @@ export default class AIMCParser {
|
||||
const sm = Traverser.findSMByIdShort(env, "AssetInterfacesMappingConfiguration");
|
||||
if (sm === null || sm.submodelElements === null) return null;
|
||||
|
||||
const parsed = {} as AssetInterfacesMappingConfiguration;
|
||||
const parsed = [] as AssetInterfacesMappingConfiguration;
|
||||
|
||||
sm.submodelElements.forEach(e => {
|
||||
if (!aasCore.types.isSubmodelElementList(e) || !e.idShort || !e.value) return;
|
||||
|
||||
const endpointProto = endpointAvailable(e.idShort);
|
||||
if (!endpointProto) return;
|
||||
|
||||
parsed[endpointProto] = e.value.map(element => {
|
||||
if (!aasCore.types.isSubmodelElementCollection(element)) return null;
|
||||
|
||||
return AIMCParser.parseAIMCEntry(element, env);
|
||||
}).filter(e => e !== null) as MappingConfEntry[];
|
||||
sm.submodelElements.forEach(mapping => {
|
||||
if (!aasCore.types.isSubmodelElementCollection(mapping) || !mapping.value) return;
|
||||
const parsedMapping = AIMCParser.parseAIMCEntry(mapping, env);
|
||||
if (parsedMapping === null) return;
|
||||
parsed.push(parsedMapping);
|
||||
});
|
||||
|
||||
return parsed;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import type { AvailableEndpoint } from "./common";
|
||||
|
||||
export type AssetInterfacesDescription = {
|
||||
[key in AvailableEndpoint]?: InterfaceDescription[];
|
||||
};
|
||||
export type AssetInterfacesDescription = InterfaceDescription[];
|
||||
|
||||
export type InterfaceDescription = {
|
||||
title: string;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { types } from "@aas-core-works/aas-core3.0-typescript";
|
||||
import type { AvailableEndpoint } from "./common";
|
||||
import type { ConnectionConfiguration } from "./requests";
|
||||
|
||||
export type AssetInterfacesMappingConfiguration = Record<AvailableEndpoint, MappingConfEntry[]>;
|
||||
export type AssetInterfacesMappingConfiguration = MappingConfEntry[];
|
||||
|
||||
export type MappingConfEntry = {
|
||||
EndpointMetaDataReference:types.SubmodelElementCollection;
|
||||
|
||||
@@ -3,9 +3,9 @@ import type { types } from "@aas-core-works/aas-core3.0-typescript";
|
||||
export const availableEndpoints = ["HTTP", "MQTT"] as const;
|
||||
export type AvailableEndpoint = typeof availableEndpoints[number];
|
||||
|
||||
export function endpointAvailable(endpoint: string): AvailableEndpoint | null {
|
||||
export function endpointAvailable(endpoint: string): AvailableEndpoint | undefined {
|
||||
const idx = availableEndpoints.map(e => e.toLocaleLowerCase()).findIndex(e => e === endpoint.toLocaleLowerCase());
|
||||
if (idx === -1) return null;
|
||||
if (idx === -1) return undefined;
|
||||
return availableEndpoints[idx];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user