When building a mapper, you should use a map...
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { types } from "@aas-core-works/aas-core3.0-typescript";
|
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 AIMCParser from "./AIMCParser";
|
||||||
import Traverser from "helper/traverser";
|
import Traverser from "helper/traverser";
|
||||||
import AIDParser from "./AIDParser";
|
import AIDParser from "./AIDParser";
|
||||||
@@ -7,7 +7,7 @@ import { SubmodelElementCollection } from "@aas-core-works/aas-core3.0-typescrip
|
|||||||
|
|
||||||
export class AIMCMapper {
|
export class AIMCMapper {
|
||||||
|
|
||||||
private map: ElementMap = {};
|
private map: AIMCMap = new Map();
|
||||||
|
|
||||||
public constructor(private readonly env: types.Environment) {
|
public constructor(private readonly env: types.Environment) {
|
||||||
this.generate();
|
this.generate();
|
||||||
@@ -31,14 +31,13 @@ export class AIMCMapper {
|
|||||||
const resolved = Traverser.resolveRelationship(this.env, ssm);
|
const resolved = Traverser.resolveRelationship(this.env, ssm);
|
||||||
if (resolved === null) continue;
|
if (resolved === null) continue;
|
||||||
|
|
||||||
const path = ssm.first.keys.join("/");
|
|
||||||
const parsedPropConf = AIDParser.parseInterfaceMetadataProperty(resolved.second as SubmodelElementCollection);
|
const parsedPropConf = AIDParser.parseInterfaceMetadataProperty(resolved.second as SubmodelElementCollection);
|
||||||
if (parsedPropConf === null) continue;
|
if (parsedPropConf === null) continue;
|
||||||
|
|
||||||
this.map[path] = {
|
this.map.set(resolved.first, {
|
||||||
...ep,
|
...ep,
|
||||||
...parsedPropConf
|
...parsedPropConf
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -46,15 +45,30 @@ export class AIMCMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getMap(): ElementMap {
|
public getMap(): AIMCMap {
|
||||||
return this.map;
|
return this.map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get(path: string[]): ConnectionConfiguration | undefined {
|
public get(element: types.Class): ConnectionConfiguration | undefined {
|
||||||
return this.map[path.join("/")];
|
return this.map.get(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getByIdShort(idShort: string): ConnectionConfiguration[] {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user