Split lib from modules
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import { types } from "@aas-core-works/aas-core3.0-typescript";
|
||||
import { ConnectionConfiguration, AIMCMap } from "./types/aimcConf";
|
||||
import AIMCParser from "./parser/AIMCParser";
|
||||
import Traverser from "./helper/traverser";
|
||||
import AIDParser from "./parser/AIDParser";
|
||||
import { SubmodelElementCollection } from "@aas-core-works/aas-core3.0-typescript/dist/types/types";
|
||||
|
||||
export default class AIMCMapper {
|
||||
|
||||
private map: AIMCMap = new Map();
|
||||
|
||||
public constructor(private readonly env: types.Environment) {
|
||||
this.generate();
|
||||
}
|
||||
|
||||
private generate(): void {
|
||||
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 ssm of mapping.SourceSinkMappings) {
|
||||
const resolved = Traverser.resolveRelationship(this.env, ssm);
|
||||
if (resolved === null) continue;
|
||||
|
||||
let {first, second} = resolved;
|
||||
|
||||
let parsedPropConf = AIDParser.parseInterfaceMetadataProperty(first as SubmodelElementCollection);
|
||||
if (parsedPropConf === null) {
|
||||
// maybe the property is in the first element
|
||||
[first, second] = [second, first];
|
||||
parsedPropConf = AIDParser.parseInterfaceMetadataProperty(first as SubmodelElementCollection);
|
||||
}
|
||||
if (parsedPropConf === null) continue;
|
||||
|
||||
this.map.set(second, {
|
||||
...ep,
|
||||
...parsedPropConf
|
||||
});
|
||||
}
|
||||
console.log(this.map)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getMap(): AIMCMap {
|
||||
return this.map;
|
||||
}
|
||||
|
||||
public get(element: types.Class): ConnectionConfiguration | undefined {
|
||||
return this.map.get(element);
|
||||
}
|
||||
|
||||
public getByIdShort(idShort: string): ConnectionConfiguration[] {
|
||||
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 formsPath = cc.base + cc.forms.href;
|
||||
if (formsPath === path) result.push(e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user