diff --git a/lib/src/aasStore.ts b/lib/src/aasStore.ts index 9952a10..7b9c0fa 100644 --- a/lib/src/aasStore.ts +++ b/lib/src/aasStore.ts @@ -4,7 +4,7 @@ import { types, jsonization } from "@aas-core-works/aas-core3.0rc02-typescript"; export default class AASStore { private static instance: AASStore; - private shells: Array = []; + private envs: Array = []; private constructor() { } @@ -17,17 +17,17 @@ export default class AASStore { } public addAAS(aas: types.Environment): void { - this.shells.push(aas); + this.envs.push(aas); } public getAll(): Array { - return this.shells; + return this.envs; } public addAASByPath(path: string): void { if (!path.endsWith(".json")) throw new Error("File must be a JSON file"); - const file = getAASFileContent(path); + const file = readFileSync(path, { encoding: "utf-8" }); const aas = JSON.parse(file); const aasJson = jsonization.environmentFromJsonable(aas); @@ -39,7 +39,7 @@ export default class AASStore { public addAllAASFromPath(path: string): void { const errors: any[] = []; - getAllAASFiles(path).forEach(file => { + this.getAllAASFilePaths(path).forEach(file => { try { this.addAASByPath(file); } catch (e) { @@ -50,24 +50,43 @@ export default class AASStore { throw errors; } -} - -export function getAllAASFiles(aasPath: string): string[] { - const files = readdirSync(aasPath); - return files.filter(file => file.endsWith(".json")).map(file => `${aasPath}/${file}`); -} - -export function getAASFileContent(aasPath: string): string { - const content = readFileSync(aasPath, { encoding: "utf-8" }); - return content; -} - -export function getAllAASFileContents(aasPath: string): string[] { - const files = getAllAASFiles(aasPath) - const content = []; - for (const file of files) { - content.push(getAASFileContent(file)); + private getAllAASFilePaths(aasPath: string): string[] { + const files = readdirSync(aasPath); + return files.filter(file => file.endsWith(".json")).map(file => `${aasPath}/${file}`); } - return content; + public findAASById(id: string): types.AssetAdministrationShell | null { + for (const env of this.envs) { + if (env.assetAdministrationShells === null) continue; + + for (const aas of env.assetAdministrationShells) { + if (aas.id === id) return aas; + } + } + + return null; + } + + public findSMById(id: string): types.Submodel | null { + for (const env of this.envs) { + if (env.submodels === null) continue; + + for (const sm of env.submodels) { + if (sm.id === id) return sm; + } + } + + return null; + } + + public findElement(submodelId: string, elementIdShort: string): types.Class | null { + const sm = this.findSMById(submodelId); + if (!sm) return null; + + for (const element of sm.descend()) { + if ((element as any).idShort === elementIdShort) return element; + } + + return null; + } } \ No newline at end of file diff --git a/lib/src/interfaceConnectionObject.ts b/lib/src/interfaceConnectionObject.ts index caee23b..d8aa99c 100644 --- a/lib/src/interfaceConnectionObject.ts +++ b/lib/src/interfaceConnectionObject.ts @@ -6,13 +6,14 @@ export type OnResponseCallback = (response: any) => void export default abstract class InterfaceConnectionObject { protected abstract readonly name: string; + protected abstract readonly uriProtocol: string[]|string; protected abstract readonly connectionType: ConnectionType; protected abstract readonly supportsSubscriptions: boolean; protected config: ConfigInterface; private onResponseCallback: OnResponseCallback; - constructor(config: ConfigInterface, onResponseCallback: OnResponseCallback) { + public constructor(config: ConfigInterface, onResponseCallback: OnResponseCallback) { this.config = config; this.onResponseCallback = onResponseCallback; } diff --git a/lib/src/multimessageBroker.ts b/lib/src/multimessageBroker.ts index d9ed2e0..c6eaed9 100644 --- a/lib/src/multimessageBroker.ts +++ b/lib/src/multimessageBroker.ts @@ -1,6 +1,6 @@ import { types } from "@aas-core-works/aas-core3.0rc02-typescript"; import type AASInterfaceServer from "server"; -import type { PossibleRequests } from "server"; +import type { Request } from "types/requests"; import type InterfaceConnectionObject from "interfaceConnectionObject"; import AASStore from "aasStore"; @@ -9,11 +9,11 @@ class MultiMessageBroker { private serverInterfaces: Array = []; private serverInterfaceConfigs: Array = []; - private serverInstances: Array|null> = []; + private serverInstances: Array|null> = []; private connectorInterfaces: Array = []; private connectorConfigs: Array = []; - private connectorInstances: Array|null> = []; + private connectorInstances: Array|null> = []; public constructor() {} @@ -51,7 +51,11 @@ class MultiMessageBroker { }); } - private onInterfaceRequest(request: PossibleRequests) { + private connectorConfigsFromAAS(aas: types.Environment): void { + // TODO + } + + private onInterfaceRequest(request: Request) { // TODO } diff --git a/lib/src/server.ts b/lib/src/server.ts index b4e68e9..e0d223a 100644 --- a/lib/src/server.ts +++ b/lib/src/server.ts @@ -1,16 +1,16 @@ import { types } from "@aas-core-works/aas-core3.0rc02-typescript"; - -export type PossibleRequests = "TODO"; - -export type OnRequestCallback = (request: PossibleRequests) => void +import type { Request, OnRequestCallback } from "types/requests"; export default abstract class AASInterfaceServer { protected abstract readonly name: string; protected config: ConfigInterface; - private onRequestCallback: OnRequestCallback; + protected abstract readonly supportsSubscriptions: boolean; + protected readonly aas: types.Environment; + private onRequestCallback: OnRequestCallback constructor(config: ConfigInterface, aas: types.Environment, onRequestCallback: OnRequestCallback) { this.config = config; + this.aas = aas; this.onRequestCallback = onRequestCallback; } @@ -19,5 +19,24 @@ export default abstract class AASInterfaceServer { public abstract stop(): void; public abstract notify(event: any): void; - protected abstract findElementByRequest(request: PossibleRequests): any | null; + protected abstract findElementByRequest(request: Request): any | null; + + protected findElementBySemanticId(id: string): types.Class | null { + for (const element of this.aas.descend()) { + if ((element as any).semanticId === id) { + return element; + } + } + return null; + } + + protected findElementByShortId(id: string): types.Class | null { + for (const element of this.aas.descend()) { + if ((element as any).idShort === id) { + return element; + } + } + return null; + } + } \ No newline at end of file diff --git a/lib/src/types/requests.ts b/lib/src/types/requests.ts new file mode 100644 index 0000000..053f1f3 --- /dev/null +++ b/lib/src/types/requests.ts @@ -0,0 +1,3 @@ +export type Request = "TODO" + +export type OnRequestCallback = (request: Request) => void \ No newline at end of file