From c21771c437616c493e231d4054cd1f10f8ca2082 Mon Sep 17 00:00:00 2001 From: Ralf Aron Date: Tue, 10 Sep 2024 13:37:58 +0200 Subject: [PATCH] fix: about page updated --- Dockerfile | 4 +- create-app-info.ts | 19 +-- package-lock.json | 4 +- projects/aas-core/src/lib/types.ts | 23 ++-- .../library-table/library-table.component.ts | 24 ---- .../license-info.component.html} | 9 +- .../license-info.component.scss} | 0 .../license-info/license-info.component.ts | 64 +++++++++ projects/aas-lib/src/public-api.ts | 2 +- .../library-table.component.spec.ts | 125 ------------------ .../license-info.component.spec.ts | 67 ++++++++++ ...er-api.service.ts => about-api.service.ts} | 8 +- .../src/app/about/about.component.html | 16 ++- .../src/app/about/about.component.ts | 12 +- .../aas-portal/src/assets/i18n/de-de.json | 2 + .../aas-portal/src/assets/i18n/en-us.json | 2 + .../src/test/about/about.component.spec.ts | 12 +- .../aas-server/src/app/application-info.ts | 15 ++- .../src/app/controller/app-controller.ts | 8 +- .../src/test/application-info.spec.ts | 22 +-- .../aas-server/src/test/assets/app-info.json | 1 + .../test/controller/app-controller.spec.ts | 7 +- 22 files changed, 221 insertions(+), 225 deletions(-) delete mode 100644 projects/aas-lib/src/lib/library-table/library-table.component.ts rename projects/aas-lib/src/lib/{library-table/library-table.component.html => license-info/license-info.component.html} (51%) rename projects/aas-lib/src/lib/{library-table/library-table.component.scss => license-info/license-info.component.scss} (100%) create mode 100644 projects/aas-lib/src/lib/license-info/license-info.component.ts delete mode 100644 projects/aas-lib/src/test/library-table/library-table.component.spec.ts create mode 100644 projects/aas-lib/src/test/license-info/license-info.component.spec.ts rename projects/aas-portal/src/app/about/{server-api.service.ts => about-api.service.ts} (79%) diff --git a/Dockerfile b/Dockerfile index 45c4b801..e0f7afcd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Dockerfile to build server and client parts -FROM node:lts-alpine3.19 AS build +FROM node:alpine3.19 AS build WORKDIR /usr/src/app COPY . . # RUN apk add g++ make py3-pip @@ -7,7 +7,7 @@ RUN npm install RUN node --no-warnings --loader ts-node/esm create-app-info.ts RUN npm run build -FROM node:lts-alpine3.19 AS aasportal +FROM node:alpine3.19 AS aasportal RUN apk upgrade --update-cache --available && apk add openssl && rm -rf /var/cache/apk/* WORKDIR /usr/src/app COPY projects/aas-server/package.json package.json diff --git a/create-app-info.ts b/create-app-info.ts index b99c5fcc..5844b295 100644 --- a/create-app-info.ts +++ b/create-app-info.ts @@ -66,16 +66,17 @@ await main(); async function main(): Promise { const project: Package = await read(resolve(__dirname, 'package.json')); - const file = resolve(__dirname, 'projects/aas-server/src/assets/app-info.json'); - const appInfo = await read(file); - appInfo.name = project.name; - appInfo.version = project.version; - appInfo.description = project.description; - appInfo.author = project.author; - appInfo.homepage = project.homepage; - appInfo.license = project.license; - appInfo.libraries = await readLibrariesAsync(project); + const appInfo: ApplicationInfo = { + name: project.name, + version: project.version, + description: project.description, + author: project.author, + homepage: project.homepage, + license: project.license, + libraries: await readLibrariesAsync(project), + }; + const file = resolve(__dirname, 'projects/aas-server/src/assets/app-info.json'); await write(file, appInfo); } diff --git a/package-lock.json b/package-lock.json index ff5fdd97..0e38e394 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "aas-portal-project", - "version": "3.0.0-development.85", + "version": "3.0.0-development.87", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "aas-portal-project", - "version": "3.0.0-development.85", + "version": "3.0.0-development.87", "license": "Apache-2.0", "workspaces": [ "projects/fhg-jest", diff --git a/projects/aas-core/src/lib/types.ts b/projects/aas-core/src/lib/types.ts index be15861b..25053dd7 100644 --- a/projects/aas-core/src/lib/types.ts +++ b/projects/aas-core/src/lib/types.ts @@ -138,7 +138,8 @@ export interface LiveRequest { nodes: LiveNode[]; } -export interface PackageInfo { +/** Provides information about the current application. */ +export interface AppInfo { name: string; version: string; author: string; @@ -148,6 +149,16 @@ export interface PackageInfo { libraries: Library[]; } +/** Provides information about a 3rd-party package. */ +export interface Library { + name: string; + version: string; + description: string; + license: string; + licenseText: string; + homepage?: string; +} + export type DirEntry = { type: 'file' | 'dir'; name: string; @@ -166,16 +177,6 @@ export interface ErrorData { args: unknown[]; } -/** Provides information about a 3rd-party package. */ -export interface Library { - name: string; - version: string; - description: string; - license: string; - licenseText: string; - homepage?: string; -} - /** Defines the message types. */ export type MessageType = 'Error' | 'Warning' | 'Info'; diff --git a/projects/aas-lib/src/lib/library-table/library-table.component.ts b/projects/aas-lib/src/lib/library-table/library-table.component.ts deleted file mode 100644 index a11825ee..00000000 --- a/projects/aas-lib/src/lib/library-table/library-table.component.ts +++ /dev/null @@ -1,24 +0,0 @@ -/****************************************************************************** - * - * Copyright (c) 2019-2024 Fraunhofer IOSB-INA Lemgo, - * eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft - * zur Foerderung der angewandten Forschung e.V. - * - *****************************************************************************/ - -import { ChangeDetectionStrategy, Component, input } from '@angular/core'; -import { NgbPagination } from '@ng-bootstrap/ng-bootstrap'; -import { TranslateModule } from '@ngx-translate/core'; -import { Library } from 'aas-core'; - -@Component({ - selector: 'fhg-library-table', - templateUrl: './library-table.component.html', - styleUrls: ['./library-table.component.scss'], - standalone: true, - imports: [NgbPagination, TranslateModule], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class LibraryTableComponent { - public readonly libraries = input([]); -} diff --git a/projects/aas-lib/src/lib/library-table/library-table.component.html b/projects/aas-lib/src/lib/license-info/license-info.component.html similarity index 51% rename from projects/aas-lib/src/lib/library-table/library-table.component.html rename to projects/aas-lib/src/lib/license-info/license-info.component.html index fa90f3f4..18f0cbd6 100644 --- a/projects/aas-lib/src/lib/library-table/library-table.component.html +++ b/projects/aas-lib/src/lib/license-info/license-info.component.html @@ -6,9 +6,8 @@ ! !----------------------------------------------------------------------------> -
- @for (library of libraries(); track library.name) { -

{{library.name}}

-
{{library.licenseText}}
- } + +
+
{{text()}}
\ No newline at end of file diff --git a/projects/aas-lib/src/lib/library-table/library-table.component.scss b/projects/aas-lib/src/lib/license-info/license-info.component.scss similarity index 100% rename from projects/aas-lib/src/lib/library-table/library-table.component.scss rename to projects/aas-lib/src/lib/license-info/license-info.component.scss diff --git a/projects/aas-lib/src/lib/license-info/license-info.component.ts b/projects/aas-lib/src/lib/license-info/license-info.component.ts new file mode 100644 index 00000000..617dc3f5 --- /dev/null +++ b/projects/aas-lib/src/lib/license-info/license-info.component.ts @@ -0,0 +1,64 @@ +/****************************************************************************** + * + * Copyright (c) 2019-2024 Fraunhofer IOSB-INA Lemgo, + * eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft + * zur Foerderung der angewandten Forschung e.V. + * + *****************************************************************************/ + +import { ChangeDetectionStrategy, Component, computed, input, signal } from '@angular/core'; +import { NgbCollapseModule, NgbPagination } from '@ng-bootstrap/ng-bootstrap'; +import { TranslateModule } from '@ngx-translate/core'; +import { Library } from 'aas-core'; + +@Component({ + selector: 'fhg-license-info', + templateUrl: './license-info.component.html', + styleUrls: ['./license-info.component.scss'], + standalone: true, + imports: [NgbPagination, NgbCollapseModule, TranslateModule], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class LicenseInfoComponent { + public readonly libraries = input([]); + + public readonly isCollapsed = signal(true); + + public readonly text = computed(() => { + return this.generateLicensesText(this.libraries()); + }); + + private generateLicensesText(libraries: Library[]): string { + const licenses = new Map(); + for (const library of libraries) { + let value = licenses.get(library.licenseText); + if (!value) { + value = [library]; + licenses.set(library.licenseText, value); + } else { + value.push(library); + } + } + + let text = ''; + for (const [key, value] of licenses) { + if (value.length === 1) { + text += 'The following npm package may be included in this product:\n\n'; + text += ` - ${value[0].name}@${value[0].version}\n\n`; + text += 'This package contains the following license and notice below:\n\n'; + } else if (value.length > 1) { + text += 'The following npm packages may be included in this product:\n\n'; + for (const item of value) { + text += ` - ${item.name}@${value[0].version}\n`; + } + + text += '\nThese packages each contain the following license and notice below:\n\n'; + } + + text += key; + text += '\n-----------\n\n'; + } + + return text; + } +} diff --git a/projects/aas-lib/src/public-api.ts b/projects/aas-lib/src/public-api.ts index bd07b315..50ac0ca5 100644 --- a/projects/aas-lib/src/public-api.ts +++ b/projects/aas-lib/src/public-api.ts @@ -30,7 +30,7 @@ export * from './lib/auth/login-form/login-form.component'; export * from './lib/auth/profile-form/profile-form.component'; export * from './lib/auth/register-form/register-form.component'; -export * from './lib/library-table/library-table.component'; +export * from './lib/license-info/license-info.component'; export * from './lib/submodel-template/submodel-template'; diff --git a/projects/aas-lib/src/test/library-table/library-table.component.spec.ts b/projects/aas-lib/src/test/library-table/library-table.component.spec.ts deleted file mode 100644 index 8a7fa3a0..00000000 --- a/projects/aas-lib/src/test/library-table/library-table.component.spec.ts +++ /dev/null @@ -1,125 +0,0 @@ -/****************************************************************************** - * - * Copyright (c) 2019-2024 Fraunhofer IOSB-INA Lemgo, - * eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft - * zur Foerderung der angewandten Forschung e.V. - * - *****************************************************************************/ - -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core'; -import { Library } from 'aas-core'; - -import { LibraryTableComponent } from '../../lib/library-table/library-table.component'; - -describe('LibraryTableComponent', () => { - let component: LibraryTableComponent; - let fixture: ComponentFixture; - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot({ - defaultLanguage: 'en-us', - loader: { - provide: TranslateLoader, - useClass: TranslateFakeLoader, - }, - }), - ], - }); - - fixture = TestBed.createComponent(LibraryTableComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); - - it('has an initial page size of 10', () => { - expect(component.pageSize()).toEqual(10); - }); - - it('shows page 1', () => { - expect(component.page()).toEqual(1); - }); - - describe('with pagination', () => { - let size: number; - - beforeEach(() => { - const collection: Library[] = []; - - size = component.pageSize() + 1; - for (let i = 1; i <= size; i++) { - collection.push({ - name: 'Library ' + i, - description: 'Description library ' + i, - license: 'MIT', - homepage: 'https://www.fraunhofer.de', - version: '1.' + i, - }); - } - - fixture.componentRef.setInput('collection', collection); - fixture.detectChanges(); - }); - - it('has 11 libraries', () => { - expect(component.size()).toEqual(size); - }); - - it('displays the first page with 10 entries', () => { - expect(component.libraries().length).toEqual(component.pageSize()); - }); - - it('provides 2 pages', () => { - expect(component.page()).toEqual(1); - expect(component.libraries().length).toEqual(10); - - component.page.set(2); - fixture.detectChanges(); - expect(component.libraries().length).toEqual(1); - }); - }); - - describe('show/hide pagination', () => { - let size: number; - - beforeEach(() => { - const collection: Library[] = []; - - size = 10; - for (let i = 1; i <= size; i++) { - collection.push({ - name: 'Library ' + i, - description: 'Description library ' + i, - license: 'MIT', - homepage: 'https://www.fraunhofer.de', - version: '1.' + i, - }); - } - - fixture.componentRef.setInput('collection', collection); - fixture.detectChanges(); - }); - - it('hides pagination if size <= pageSize', () => { - fixture.componentRef.setInput('pageSize', component.size); - fixture.detectChanges(); - const element: HTMLElement = fixture.debugElement.nativeElement; - const pagination: HTMLElement | null = element.querySelector('ngb-pagination'); - expect(pagination).toBeNull(); - }); - - it('shows pagination if size > pageSize', () => { - fixture.componentRef.setInput('pageSize', component.size() - 1); - fixture.detectChanges(); - const element: HTMLElement = fixture.debugElement.nativeElement; - const pagination: HTMLElement | null = element.querySelector('ngb-pagination'); - expect(pagination).toBeDefined(); - }); - }); -}); diff --git a/projects/aas-lib/src/test/license-info/license-info.component.spec.ts b/projects/aas-lib/src/test/license-info/license-info.component.spec.ts new file mode 100644 index 00000000..485d12b6 --- /dev/null +++ b/projects/aas-lib/src/test/license-info/license-info.component.spec.ts @@ -0,0 +1,67 @@ +/****************************************************************************** + * + * Copyright (c) 2019-2024 Fraunhofer IOSB-INA Lemgo, + * eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft + * zur Foerderung der angewandten Forschung e.V. + * + *****************************************************************************/ + +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core'; + +import { LicenseInfoComponent } from '../../lib/license-info/license-info.component'; + +describe('LicenseInfoComponent', () => { + let component: LicenseInfoComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ + TranslateModule.forRoot({ + defaultLanguage: 'en-us', + loader: { + provide: TranslateLoader, + useClass: TranslateFakeLoader, + }, + }), + ], + }); + + fixture = TestBed.createComponent(LicenseInfoComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + fixture.componentRef.setInput('libraries', [ + { + name: '@angular-devkit/build-angular', + version: '18.2.3', + description: 'Angular Webpack Build Facade', + license: 'MIT', + licenseText: 'License text...', + homepage: 'https://github.com/angular/angular-cli', + }, + { + name: '@angular-eslint/builder', + version: '18.3.0', + description: 'Angular CLI builder for ESLint', + license: 'MIT', + licenseText: 'License text...', + }, + { + name: '@angular-eslint/eslint-plugin', + version: '18.3.0', + description: 'ESLint plugin for Angular applications, following https://angular.dev/style-guide', + license: 'MIT', + licenseText: 'License text...', + }, + ]); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it('provides a license text', () => { + expect(component.text()).toBeDefined(); + }); +}); diff --git a/projects/aas-portal/src/app/about/server-api.service.ts b/projects/aas-portal/src/app/about/about-api.service.ts similarity index 79% rename from projects/aas-portal/src/app/about/server-api.service.ts rename to projects/aas-portal/src/app/about/about-api.service.ts index 956bbed1..f00dfba0 100644 --- a/projects/aas-portal/src/app/about/server-api.service.ts +++ b/projects/aas-portal/src/app/about/about-api.service.ts @@ -8,18 +8,18 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { PackageInfo, Message } from 'aas-core'; +import { AppInfo, Message } from 'aas-core'; import { Observable } from 'rxjs'; /** Realizes the IServer service. */ @Injectable({ providedIn: 'root', }) -export class ServerApiService { +export class AboutApiService { public constructor(private readonly http: HttpClient) {} - public getInfo(): Observable { - return this.http.get('/api/v1/app/info'); + public getInfo(): Observable { + return this.http.get('/api/v1/app/info'); } public getMessages(): Observable { diff --git a/projects/aas-portal/src/app/about/about.component.html b/projects/aas-portal/src/app/about/about.component.html index 9f0e0c0c..1179b5fb 100644 --- a/projects/aas-portal/src/app/about/about.component.html +++ b/projects/aas-portal/src/app/about/about.component.html @@ -6,19 +6,23 @@ ! !----------------------------------------------------------------------------> -
+

AASPortal

-

The AASPortal is a web portal for the visualization and management of Asset Administration Shells (AAS) licensed under the Apache License 2.0.

-

The implementation uses the concepts of the document "Details of the Asset Administration Shell" published on www.plattform-i40.de which is licensed under Creative Commons CC BY 4.0.

-

Copyright (c) 2019-2024 Fraunhofer IOSB-INA Lemgo, eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft -zur Foerderung der angewandten Forschung e.V.

+

The AASPortal is a web portal for the visualization and management of Asset Administration Shells (AAS) licensed + under the Apache License 2.0.

+

The implementation uses the concepts of the document "Details of the Asset Administration Shell" published on + www.plattform-i40.de which is licensed under Creative Commons CC BY 4.0.

+

Copyright (c) 2019-2024 Fraunhofer IOSB-INA Lemgo, eine rechtlich nicht selbstaendige Einrichtung der + Fraunhofer-Gesellschaft + zur Foerderung der angewandten Forschung e.V.

Internet: {{homepage()}}

Third-party Libraries

The application is based on some third-party libraries for which specific copyright statements and licenses apply.

- + +

Server Messages

diff --git a/projects/aas-portal/src/app/about/about.component.ts b/projects/aas-portal/src/app/about/about.component.ts index 90861ccc..6b0bf2c9 100644 --- a/projects/aas-portal/src/app/about/about.component.ts +++ b/projects/aas-portal/src/app/about/about.component.ts @@ -17,8 +17,8 @@ import { ChangeDetectionStrategy, } from '@angular/core'; import { Library, Message } from 'aas-core'; -import { LibraryTableComponent, MessageTableComponent } from 'aas-lib'; -import { ServerApiService } from './server-api.service'; +import { LicenseInfoComponent, MessageTableComponent } from 'aas-lib'; +import { AboutApiService } from './about-api.service'; import { ToolbarService } from '../toolbar.service'; import { environment } from '../../environments/environment'; @@ -27,7 +27,7 @@ import { environment } from '../../environments/environment'; templateUrl: './about.component.html', styleUrls: ['./about.component.scss'], standalone: true, - imports: [LibraryTableComponent, MessageTableComponent], + imports: [LicenseInfoComponent, MessageTableComponent], changeDetection: ChangeDetectionStrategy.OnPush, }) export class AboutComponent implements OnInit, OnDestroy, AfterViewInit { @@ -36,7 +36,7 @@ export class AboutComponent implements OnInit, OnDestroy, AfterViewInit { private readonly _messages = signal([]); public constructor( - private serverApi: ServerApiService, + private api: AboutApiService, private toolbar: ToolbarService, ) {} @@ -52,12 +52,12 @@ export class AboutComponent implements OnInit, OnDestroy, AfterViewInit { public readonly messages = this._messages.asReadonly(); public ngOnInit(): void { - this.serverApi.getInfo().subscribe(info => { + this.api.getInfo().subscribe(info => { this._serverVersion.set(info.version); this._libraries.set(info.libraries ?? []); }); - this.serverApi.getMessages().subscribe(messages => this._messages.set(messages)); + this.api.getMessages().subscribe(messages => this._messages.set(messages)); } public ngAfterViewInit(): void { diff --git a/projects/aas-portal/src/assets/i18n/de-de.json b/projects/aas-portal/src/assets/i18n/de-de.json index 3b1b0b15..e7ce96b3 100644 --- a/projects/aas-portal/src/assets/i18n/de-de.json +++ b/projects/aas-portal/src/assets/i18n/de-de.json @@ -53,6 +53,8 @@ "CMD_VIEW_USER_FEEDBACK": "Nutzer-Feedback", "CMD_VIEW_NAMEPLATE": "Typenschild", "CMD_ADD_NEW_FAVORITES_LIST": "Neue Favoritenliste", + "CMD_SHOW_LICENSE_TEXT": "Lizenztext anzeigen", + "CMD_HIDE_LICENSE_TEXT": "Lizenztext verbergen", "COLUMN_VARIANT": "Variante", "COLUMN_NAME": "Name", "COLUMN_MODEL_TYPE": "Modeltyp", diff --git a/projects/aas-portal/src/assets/i18n/en-us.json b/projects/aas-portal/src/assets/i18n/en-us.json index 2e06457e..cf300cf0 100644 --- a/projects/aas-portal/src/assets/i18n/en-us.json +++ b/projects/aas-portal/src/assets/i18n/en-us.json @@ -53,6 +53,8 @@ "CMD_VIEW_USER_FEEDBACK": "User feedback", "CMD_VIEW_NAMEPLATE": "Nameplate", "CMD_ADD_NEW_FAVORITES_LIST": "New favorites list", + "CMD_SHOW_LICENSE_TEXT": "Show license text", + "CMD_HIDE_LICENSE_TEXT": "Hide license text", "COLUMN_NAME": "Name", "COLUMN_MODEL_TYPE": "Model type", "COLUMN_SIZE": "Size", diff --git a/projects/aas-portal/src/test/about/about.component.spec.ts b/projects/aas-portal/src/test/about/about.component.spec.ts index e876ae27..ef7545ea 100644 --- a/projects/aas-portal/src/test/about/about.component.spec.ts +++ b/projects/aas-portal/src/test/about/about.component.spec.ts @@ -9,20 +9,20 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core'; import { of } from 'rxjs'; -import { PackageInfo } from 'aas-core'; +import { AppInfo } from 'aas-core'; import { AboutComponent } from '../../app/about/about.component'; -import { ServerApiService } from '../../app/about/server-api.service'; +import { AboutApiService } from '../../app/about/about-api.service'; import { ToolbarService } from '../../app/toolbar.service'; import { signal } from '@angular/core'; describe('AboutComponent', () => { let component: AboutComponent; let fixture: ComponentFixture; - let api: jasmine.SpyObj; + let api: jasmine.SpyObj; beforeEach(() => { - const info: PackageInfo = { + const info: AppInfo = { name: 'Test', version: '1.0', author: 'FHG', @@ -32,14 +32,14 @@ describe('AboutComponent', () => { libraries: [], }; - api = jasmine.createSpyObj(['getInfo', 'getMessages']); + api = jasmine.createSpyObj(['getInfo', 'getMessages']); api.getInfo.and.returnValue(of(info)); api.getMessages.and.returnValue(of([])); TestBed.configureTestingModule({ providers: [ { - provide: ServerApiService, + provide: AboutApiService, useValue: api, }, { diff --git a/projects/aas-server/src/app/application-info.ts b/projects/aas-server/src/app/application-info.ts index 54bb7469..fb5e3c32 100644 --- a/projects/aas-server/src/app/application-info.ts +++ b/projects/aas-server/src/app/application-info.ts @@ -7,7 +7,7 @@ *****************************************************************************/ import { isAbsolute, resolve } from 'path/posix'; -import { Message, PackageInfo } from 'aas-core'; +import { Message, AppInfo } from 'aas-core'; import { Logger } from './logging/logger.js'; import { readFile } from 'fs/promises'; import { inject, singleton } from 'tsyringe'; @@ -15,16 +15,19 @@ import { Variable } from './variable.js'; @singleton() export class ApplicationInfo { - private data?: PackageInfo; + private data?: AppInfo; public constructor( @inject('Logger') private readonly logger: Logger, @inject(Variable) private readonly variable: Variable, - ) {} + data?: AppInfo, + ) { + this.data = data; + } - public async getAsync(file?: string): Promise { + public async getAsync(): Promise { if (!this.data) { - this.data = await this.readAsync(file); + this.data = await this.readAsync(); } return this.data; @@ -34,7 +37,7 @@ export class ApplicationInfo { return this.logger.getMessages(); } - private async readAsync(file?: string): Promise { + private async readAsync(file?: string): Promise { try { let path: string; if (file) { diff --git a/projects/aas-server/src/app/controller/app-controller.ts b/projects/aas-server/src/app/controller/app-controller.ts index a32aa5a8..1b32b524 100644 --- a/projects/aas-server/src/app/controller/app-controller.ts +++ b/projects/aas-server/src/app/controller/app-controller.ts @@ -13,7 +13,7 @@ import { Logger } from '../logging/logger.js'; import { AASController } from './aas-controller.js'; import { AuthService } from '../auth/auth-service.js'; import { Variable } from '../variable.js'; -import { Message, PackageInfo } from 'aas-core'; +import { Message, AppInfo } from 'aas-core'; @injectable() @Route('/api/v1/app') @@ -29,13 +29,13 @@ export class AppController extends AASController { } /** - * @summary Gets the license info. - * @returns ToDo + * @summary Gets the application info. + * @returns The application info. */ @Get('info') @Security('bearerAuth', ['guest']) @OperationId('getInfo') - public async getInfo(): Promise { + public async getInfo(): Promise { try { this.logger.start('getInfo'); return await this.applicationInfo.getAsync(); diff --git a/projects/aas-server/src/test/application-info.spec.ts b/projects/aas-server/src/test/application-info.spec.ts index 432e310a..4348ec83 100644 --- a/projects/aas-server/src/test/application-info.spec.ts +++ b/projects/aas-server/src/test/application-info.spec.ts @@ -7,27 +7,27 @@ *****************************************************************************/ import 'reflect-metadata'; -import { describe, beforeEach, it, expect } from '@jest/globals'; -import { resolve } from 'path/posix'; +import { describe, beforeEach, it, expect, jest } from '@jest/globals'; +import { AppInfo } from 'aas-core'; +import { createSpyObj } from 'fhg-jest'; import { ApplicationInfo } from '../app/application-info.js'; import { Logger } from '../app/logging/logger.js'; -import { readFile } from 'fs/promises'; -import { PackageInfo } from 'aas-core'; -import { createSpyObj } from 'fhg-jest'; +import { Variable } from '../app/variable.js'; + +import appInfo from '../assets/app-info.json' with { type: 'json ' }; describe('Application Info service', () => { - let logger: Logger; + let logger: jest.Mocked; + let variable: jest.Mocked; let applicationInfo: ApplicationInfo; - let file: string; beforeEach(() => { logger = createSpyObj(['error', 'warning', 'info', 'debug', 'start', 'stop']); - file = resolve('.', 'src/test/assets/app-info.json'); - applicationInfo = new ApplicationInfo(logger); + variable = createSpyObj({}, { ASSETS: './' }); + applicationInfo = new ApplicationInfo(logger, variable, appInfo as AppInfo); }); it('gets the AASServer package info', async () => { - const expected: PackageInfo = JSON.parse((await readFile(file)).toString()); - await expect(applicationInfo.getAsync(file)).resolves.toEqual(expected); + await expect(applicationInfo.getAsync()).resolves.toEqual(appInfo); }); }); diff --git a/projects/aas-server/src/test/assets/app-info.json b/projects/aas-server/src/test/assets/app-info.json index af535a43..b2efdce3 100644 --- a/projects/aas-server/src/test/assets/app-info.json +++ b/projects/aas-server/src/test/assets/app-info.json @@ -11,6 +11,7 @@ "version": "1.0", "description": "A library.", "license": "MIT", + "licenseText": "License text...", "homepage": "https://www.iosb-ina.fraunhofer.de/" } ] diff --git a/projects/aas-server/src/test/controller/app-controller.spec.ts b/projects/aas-server/src/test/controller/app-controller.spec.ts index e4d8ada8..0e773574 100644 --- a/projects/aas-server/src/test/controller/app-controller.spec.ts +++ b/projects/aas-server/src/test/controller/app-controller.spec.ts @@ -12,7 +12,7 @@ import express, { Express, json, urlencoded } from 'express'; import morgan from 'morgan'; import request from 'supertest'; import { Logger } from '../../app/logging/logger.js'; -import { Message, PackageInfo } from 'aas-core'; +import { Message, AppInfo } from 'aas-core'; import { describe, beforeEach, it, expect, jest } from '@jest/globals'; import { ApplicationInfo } from '../../app/application-info.js'; @@ -66,7 +66,7 @@ describe('AppController', function () { }); it('getInfo: /api/v1/app/info', async function () { - const data: PackageInfo = { + const data: AppInfo = { name: 'aas-portal-project', version: '2.0.0', description: 'Web-based visualization and control of asset administration shells.', @@ -79,12 +79,13 @@ describe('AppController', function () { version: '1.0', description: 'A library.', license: 'MIT', + licenseText: 'License text...', homepage: 'https://www.iosb-ina.fraunhofer.de/', }, ], }; - applicationInfo.getAsync.mockReturnValue(new Promise(resolve => resolve(data))); + applicationInfo.getAsync.mockReturnValue(new Promise(resolve => resolve(data))); const response = await request(app).get('/api/v1/app/info').set('Authorization', `Bearer ${getToken()}`); expect(response.statusCode).toBe(200);