Skip to content

Commit

Permalink
in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Nov 4, 2024
1 parent 682ece5 commit 4464509
Show file tree
Hide file tree
Showing 20 changed files with 369 additions and 86 deletions.
9 changes: 8 additions & 1 deletion projects/aas-core/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export type AASAbbreviation =
| 'SME'
| 'SML';

/** The schedule type. */
export interface AASEndpointSchedule {
type: 'never' | 'once' | 'every' | 'daily' | 'weekly';
values?: (string | number)[];
}

/** The kind of AAS container or server. */
export type AASEndpointType = 'FileSystem' | 'AAS_API' | 'OPC_UA' | 'WebDAV';

Expand All @@ -53,6 +59,7 @@ export type AASEndpoint = {
name: string;
url: string;
type: AASEndpointType;
schedule?: AASEndpointSchedule;
version?: string;
headers?: Record<string, string>;
};
Expand Down Expand Up @@ -99,7 +106,7 @@ export interface AASDocument extends AASDocumentId {
}

/** Represents a page of AAS documents from the total set. */
export interface AASPage {
export interface AASPagedResult {
previous: AASDocumentId | null;
next: AASDocumentId | null;
documents: AASDocument[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,30 @@ <h4 class="modal-title">
(input)="inputValue()">
</div>
@if (selectedItem().type === 'AAS_API') {
<button type="button" class="btn btn-primary my-2" (click)="collapse.toggle()"
<button type="button" class="btn btn-primary mt-3 mb-2" (click)="collapse.toggle()"
[attr.aria-expanded]="isCollapsed() === false" aria-controls="collapseExample" translate>
AddEndpointForm.ADVANCED_SETTINGS
</button>
<div #collapse="ngbCollapse" [(ngbCollapse)]="isCollapsed">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="scheduleType" id="scheduleTypeNever" value="never">
<label class="form-check-label" for="scheduleTypeNever">Never</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="scheduleType" id="scheduleTypeOnce" value="once">
<label class="form-check-label" for="scheduleTypeOnce">Once</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="scheduleType" id="scheduleTypeEvery" value="every">
<label class="form-check-label" for="scheduleTypeEvery">Every</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="scheduleType" id="scheduleTypeEach" value="daily">
<label class="form-check-label" for="scheduleTypeEach">Each</label>
</div>
<div class="col-12 mt-2" style="max-height: 200px; overflow-y: auto;">
<table class="table table-sm table-striped table-borderless">
<caption class="caption-top">Headers</caption>
<thead>
<tr>
<th scope="col" class="text-center" [style.width]="'32px'">#</th>
Expand Down
6 changes: 3 additions & 3 deletions projects/aas-portal/src/app/start/start-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { AASCursor, AASDocument, AASEndpoint, AASPage, aas } from 'aas-core';
import { AASCursor, AASDocument, AASEndpoint, AASPagedResult, aas } from 'aas-core';
import { encodeBase64Url } from 'aas-lib';

/** The client side AAS provider service. */
Expand Down Expand Up @@ -65,7 +65,7 @@ export class StartApiService {
* @param language The language to used for the filter.
* @returns The document page.
*/
public getPage(cursor: AASCursor, filter?: string, language?: string): Observable<AASPage> {
public getPage(cursor: AASCursor, filter?: string, language?: string): Observable<AASPagedResult> {
let url = `/api/v1/documents?cursor=${encodeBase64Url(JSON.stringify(cursor))}`;
if (filter) {
url += `&filter=${encodeBase64Url(filter)}`;
Expand All @@ -74,7 +74,7 @@ export class StartApiService {
}
}

return this.http.get<AASPage>(url);
return this.http.get<AASPagedResult>(url);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions projects/aas-portal/src/app/start/start.store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable, computed, signal } from '@angular/core';
import { Observable, catchError, concat, from, map, mergeMap, of } from 'rxjs';
import { ViewMode } from 'aas-lib';
import { AASDocument, AASDocumentId, AASPage, aas, equalArray } from 'aas-core';
import { AASDocument, AASDocumentId, AASPagedResult, aas, equalArray } from 'aas-core';
import { StartApiService } from './start-api.service';
import { TranslateService } from '@ngx-translate/core';
import { FavoritesService } from './favorites.service';
Expand Down Expand Up @@ -198,7 +198,7 @@ export class StartStore {
return { id: document.id, endpoint: document.endpoint };
}

private setPageAndLoadContents(page: AASPage, limit?: number, filter?: string): Observable<void> {
private setPageAndLoadContents(page: AASPagedResult, limit?: number, filter?: string): Observable<void> {
return concat(
of(this.setPage(page, limit, filter)),
from(page.documents).pipe(
Expand All @@ -212,7 +212,7 @@ export class StartStore {
);
}

private setPage(page: AASPage, limit: number | undefined, filter: string | undefined): void {
private setPage(page: AASPagedResult, limit: number | undefined, filter: string | undefined): void {
this._viewMode.set(ViewMode.List);
this._activeFavorites.set('');
this._documents.set(page.documents);
Expand Down
4 changes: 2 additions & 2 deletions projects/aas-server/src/app/aas-index/aas-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
AASCursor,
AASDocument,
AASEndpoint,
AASPage,
AASPagedResult,
aas,
baseType,
getAbbreviation,
Expand Down Expand Up @@ -40,7 +40,7 @@ export abstract class AASIndex {

public abstract removeEndpoint(endpointName: string): Promise<boolean>;

public abstract getDocuments(cursor: AASCursor, query?: string, language?: string): Promise<AASPage>;
public abstract getDocuments(cursor: AASCursor, query?: string, language?: string): Promise<AASPagedResult>;

public abstract nextPage(
endpointName: string,
Expand Down
13 changes: 7 additions & 6 deletions projects/aas-server/src/app/aas-index/lowdb/lowdb-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import {
AASDocument,
AASDocumentId,
AASEndpoint,
AASPage,
AASPagedResult,
ApplicationError,
BaseValueType,
aas,
flat,
isIdentifiable,
} from 'aas-core';

import { AASIndex } from '../aas-index.js';
import { LowDbQuery } from './lowdb-query.js';
import { Variable } from '../../variable.js';
Expand Down Expand Up @@ -154,7 +155,7 @@ export class LowDbIndex extends AASIndex {
return { result, paging_metadata: { cursor: encodeBase64Url(items[k].id) } };
}

public override async getDocuments(cursor: AASCursor, query?: string, language?: string): Promise<AASPage> {
public override async getDocuments(cursor: AASCursor, query?: string, language?: string): Promise<AASPagedResult> {
await this.promise;

let filter: LowDbQuery | undefined;
Expand Down Expand Up @@ -293,7 +294,7 @@ export class LowDbIndex extends AASIndex {
return index;
}

private getFirstPage(limit: number, filter?: LowDbQuery): AASPage {
private getFirstPage(limit: number, filter?: LowDbQuery): AASPagedResult {
const documents: AASDocument[] = [];
if (this.db.data.documents.length === 0) {
return { previous: null, documents, next: null };
Expand Down Expand Up @@ -324,7 +325,7 @@ export class LowDbIndex extends AASIndex {
};
}

private getNextPage(current: AASDocumentId, limit: number, filter?: LowDbQuery): AASPage {
private getNextPage(current: AASDocumentId, limit: number, filter?: LowDbQuery): AASPagedResult {
const documents: AASDocument[] = [];
if (this.db.data.documents.length === 0) {
return { previous: null, documents, next: null };
Expand Down Expand Up @@ -362,7 +363,7 @@ export class LowDbIndex extends AASIndex {
};
}

private getPreviousPage(current: AASDocumentId, limit: number, filter?: LowDbQuery): AASPage {
private getPreviousPage(current: AASDocumentId, limit: number, filter?: LowDbQuery): AASPagedResult {
const documents: AASDocument[] = [];
if (this.db.data.documents.length === 0) {
return { previous: null, documents, next: null };
Expand Down Expand Up @@ -400,7 +401,7 @@ export class LowDbIndex extends AASIndex {
};
}

private getLastPage(limit: number, filter?: LowDbQuery): AASPage {
private getLastPage(limit: number, filter?: LowDbQuery): AASPagedResult {
const documents: AASDocument[] = [];
if (this.db.data.documents.length === 0) {
return { previous: null, documents, next: null };
Expand Down
63 changes: 40 additions & 23 deletions projects/aas-server/src/app/aas-index/mysql/mysql-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@
import { v4 } from 'uuid';
import isEmpty from 'lodash-es/isEmpty.js';
import mysql, { Connection, ResultSetHeader } from 'mysql2/promise';
import { AASEndpoint, AASCursor, AASPage, AASDocument, flat, aas, AASDocumentId, isIdentifiable } from 'aas-core';
import {
AASEndpoint,
AASCursor,
AASDocument,
flat,
aas,
AASDocumentId,
isIdentifiable,
AASPagedResult,
} from 'aas-core';

import { AASIndex } from '../aas-index.js';
import { Variable } from '../../variable.js';
import { urlToEndpoint } from '../../configuration.js';
Expand Down Expand Up @@ -48,19 +58,19 @@ export class MySqlIndex extends AASIndex {
public override async getCount(endpoint?: string): Promise<number> {
if (endpoint === undefined) {
return (
await (await this.connection).query<DocumentCount[]>('SELECT COUNT(*) FROM `documents` AS count')
await (await this.connection).query<DocumentCount[]>('SELECT COUNT(*) FROM `documents` AS count;')
)[0][0].count;
}

return (
await (
await this.connection
).query<DocumentCount[]>('SELECT COUNT(*) FROM `documents` WHERE endpoint = ? AS count', [endpoint])
).query<DocumentCount[]>('SELECT COUNT(*) FROM `documents` WHERE endpoint = ? AS count;', [endpoint])
)[0][0].count;
}

public override async getEndpoints(): Promise<AASEndpoint[]> {
return (await (await this.connection).query<MySqlEndpoint[]>('SELECT * FROM `endpoints`'))[0].map(
return (await (await this.connection).query<MySqlEndpoint[]>('SELECT * FROM `endpoints`;'))[0].map(
row =>
({
name: row.name,
Expand All @@ -75,7 +85,7 @@ export class MySqlIndex extends AASIndex {
public override async getEndpoint(name: string): Promise<AASEndpoint> {
const [results] = await (
await this.connection
).query<MySqlEndpoint[]>('SELECT * FROM `endpoints` WHERE name = ?', [name]);
).query<MySqlEndpoint[]>('SELECT * FROM `endpoints` WHERE name = ?;', [name]);

if (results.length === 0) {
throw new Error(`An endpoint with the name "${name}" does not exist.`);
Expand All @@ -96,27 +106,34 @@ export class MySqlIndex extends AASIndex {
endpoint.headers = JSON.parse(result.headers);
}

if (result.schedule) {
endpoint.schedule = JSON.parse(result.schedule);
}

return endpoint;
}

public override async hasEndpoint(name: string): Promise<boolean> {
const [results] = await (
await this.connection
).query<MySqlEndpoint[]>('SELECT * FROM `endpoints` WHERE name = ?', [name]);
).query<MySqlEndpoint[]>('SELECT * FROM `endpoints` WHERE name = ?;', [name]);

return results.length > 0;
}

public override async addEndpoint(endpoint: AASEndpoint): Promise<void> {
await (
await this.connection
).query<ResultSetHeader>('INSERT INTO `endpoints` (name, url, type, version, headers) VALUES (?, ?, ?, ?, ?)', [
endpoint.name,
endpoint.url,
endpoint.type,
endpoint.version,
endpoint.headers ? JSON.stringify(endpoint.headers) : undefined,
]);
).query<ResultSetHeader>(
'INSERT INTO `endpoints` (name, url, type, version, headers) VALUES (?, ?, ?, ?, ?);',
[
endpoint.name,
endpoint.url,
endpoint.type,
endpoint.version,
endpoint.headers ? JSON.stringify(endpoint.headers) : undefined,
],
);
}

public override async removeEndpoint(endpointName: string): Promise<boolean> {
Expand All @@ -126,7 +143,7 @@ export class MySqlIndex extends AASIndex {

const result = await (
await this.connection
).query<ResultSetHeader>('DELETE FROM `endpoints` WHERE name = ?', [endpointName]);
).query<ResultSetHeader>('DELETE FROM `endpoints` WHERE name = ?;', [endpointName]);

this.removeDocuments(endpointName);

Expand All @@ -138,7 +155,7 @@ export class MySqlIndex extends AASIndex {
}
}

public override getDocuments(cursor: AASCursor, query?: string, language?: string): Promise<AASPage> {
public override getDocuments(cursor: AASCursor, query?: string, language?: string): Promise<AASPagedResult> {
let q: MySqlQuery | undefined;
if (query) {
q = new MySqlQuery(query, language ?? 'en');
Expand Down Expand Up @@ -200,7 +217,7 @@ export class MySqlIndex extends AASIndex {

const uuid = result[0][0].uuid;
await connection.query<ResultSetHeader>(
'UPDATE `documents` SET address = ?, crc32 = ?, idShort = ?, onlineReady = ?, readonly = ?, timestamp = ?, thumbnail = ? WHERE uuid = ?',
'UPDATE `documents` SET address = ?, crc32 = ?, idShort = ?, onlineReady = ?, readonly = ?, timestamp = ?, thumbnail = ? WHERE uuid = ?;',
[
document.address,
document.crc32,
Expand Down Expand Up @@ -231,7 +248,7 @@ export class MySqlIndex extends AASIndex {
await connection.beginTransaction();
const uuid = v4();
await connection.query<ResultSetHeader>(
'INSERT INTO `documents` (uuid, address, crc32, endpoint, id, idShort, assetId, onlineReady, readonly, thumbnail, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
'INSERT INTO `documents` (uuid, address, crc32, endpoint, id, idShort, assetId, onlineReady, readonly, thumbnail, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);',
[
uuid,
document.address,
Expand Down Expand Up @@ -320,17 +337,17 @@ export class MySqlIndex extends AASIndex {
private async removeDocuments(endpointName: string): Promise<void> {
const connection = await this.connection;
const documents = (
await connection.query<MySqlDocument[]>('SELECT * FROM `documents` WHERE endpoint = ?', [endpointName])
await connection.query<MySqlDocument[]>('SELECT * FROM `documents` WHERE endpoint = ?;', [endpointName])
)[0];

await connection.query<ResultSetHeader>('DELETE FROM `documents` WHERE endpoint = ?', [endpointName]);
await connection.query<ResultSetHeader>('DELETE FROM `documents` WHERE endpoint = ?;', [endpointName]);

for (const document of documents) {
await connection.query<ResultSetHeader>('DELETE FROM `elements` WHERE uuid = ?;', [document.uuid]);
}
}

private async getFirstPage(limit: number, query?: MySqlQuery): Promise<AASPage> {
private async getFirstPage(limit: number, query?: MySqlQuery): Promise<AASPagedResult> {
const connection = await this.connection;
let sql: string;
const values: unknown[] = [];
Expand Down Expand Up @@ -361,7 +378,7 @@ export class MySqlIndex extends AASIndex {
};
}

private async getNextPage(current: AASDocumentId, limit: number, query?: MySqlQuery): Promise<AASPage> {
private async getNextPage(current: AASDocumentId, limit: number, query?: MySqlQuery): Promise<AASPagedResult> {
const connection = await this.connection;
let sql: string;
const values: unknown[] = [current.endpoint + current.id];
Expand Down Expand Up @@ -393,7 +410,7 @@ export class MySqlIndex extends AASIndex {
};
}

private async getPreviousPage(current: AASDocumentId, limit: number, query?: MySqlQuery): Promise<AASPage> {
private async getPreviousPage(current: AASDocumentId, limit: number, query?: MySqlQuery): Promise<AASPagedResult> {
const connection = await this.connection;
let sql: string;
const values: unknown[] = [current.endpoint + current.id];
Expand Down Expand Up @@ -425,7 +442,7 @@ export class MySqlIndex extends AASIndex {
};
}

private async getLastPage(limit: number, query?: MySqlQuery): Promise<AASPage> {
private async getLastPage(limit: number, query?: MySqlQuery): Promise<AASPagedResult> {
const connection = await this.connection;
let sql: string;
const values: unknown[] = [];
Expand Down
1 change: 1 addition & 0 deletions projects/aas-server/src/app/aas-index/mysql/mysql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface MySqlEndpoint extends RowDataPacket {
type: AASEndpointType;
version?: string;
headers?: string;
schedule?: string;
}

export interface MySqlDocument extends AASDocument, RowDataPacket {
Expand Down
Loading

0 comments on commit 4464509

Please sign in to comment.