From 870fce92478825ec2a0125eb08b6efa18feee959 Mon Sep 17 00:00:00 2001 From: Daniel Kluge Date: Mon, 30 Oct 2023 11:59:53 +0100 Subject: [PATCH] When building a mapper, you should use a map... --- lib/src/parser/AIMCMapper.ts | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/src/parser/AIMCMapper.ts b/lib/src/parser/AIMCMapper.ts index 2d2012d..452f716 100644 --- a/lib/src/parser/AIMCMapper.ts +++ b/lib/src/parser/AIMCMapper.ts @@ -1,5 +1,5 @@ import { types } from "@aas-core-works/aas-core3.0-typescript"; -import { ConnectionConfiguration, ElementMap } from "types/aimcConf"; +import { ConnectionConfiguration, AIMCMap } from "types/aimcConf"; import AIMCParser from "./AIMCParser"; import Traverser from "helper/traverser"; import AIDParser from "./AIDParser"; @@ -7,7 +7,7 @@ import { SubmodelElementCollection } from "@aas-core-works/aas-core3.0-typescrip export class AIMCMapper { - private map: ElementMap = {}; + private map: AIMCMap = new Map(); public constructor(private readonly env: types.Environment) { this.generate(); @@ -31,14 +31,13 @@ export class AIMCMapper { const resolved = Traverser.resolveRelationship(this.env, ssm); if (resolved === null) continue; - const path = ssm.first.keys.join("/"); const parsedPropConf = AIDParser.parseInterfaceMetadataProperty(resolved.second as SubmodelElementCollection); if (parsedPropConf === null) continue; - this.map[path] = { + this.map.set(resolved.first, { ...ep, ...parsedPropConf - } + }); } } @@ -46,15 +45,30 @@ export class AIMCMapper { } } - public getMap(): ElementMap { + public getMap(): AIMCMap { return this.map; } - public get(path: string[]): ConnectionConfiguration | undefined { - return this.map[path.join("/")]; + public get(element: types.Class): ConnectionConfiguration | undefined { + return this.map.get(element); } public getByIdShort(idShort: string): ConnectionConfiguration[] { - return Object.keys(this.map).filter(e => e.endsWith(idShort)).map(e => this.map[e]); + const result = []; + for (const [e, cc] of this.map.entries()) { + if ((e as any).idShort?.toLocaleLowerCase() === idShort.toLocaleLowerCase()) result.push(cc); + } + return result; + } + + public reverseGet(path: string): types.Class[] { + const result = []; + + for (const [e, cc] of this.map.entries()) { + const paths = cc.forms.map(f => cc.base + f.href); + if (paths.includes(path)) result.push(e); + } + + return result; } } \ No newline at end of file