Skip to content

Commit

Permalink
feat: QueryParser implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Jan 3, 2024
1 parent 2f7fdec commit ed99448
Show file tree
Hide file tree
Showing 27 changed files with 1,375 additions and 653 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ASSETS": "projects/aas-server/src/assets",
"USER_STORAGE": "mongodb://localhost:27017/aasportal-users",
"ENDPOINTS": "[\"file:///samples?name=Samples\",\"http://localhost:5001?name=AASXServer&type=AasxServer\"]",
// "AAS_INDEX": "mysql://aasportal:aas-server@localhost:3306"
"AAS_INDEX": "mysql://aasportal:aas-server@localhost:3306"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-portal/src/app/start/start.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@
</div>
<input #textInput type="text" class="form-control" [value]="filter | async"
[placeholder]="'PLACEHOLDER_FILTER' | translate" (change)="setFilter(textInput.value)"
(keydown.enter)="setFilter(textInput.value)">
(keydown.enter)="textInput.blur()">
</div>
</ng-template>
13 changes: 11 additions & 2 deletions projects/aas-portal/src/app/start/start.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Router } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { aas, AASDocument, AASEndpoint, stringFormat } from 'common';
import { aas, AASDocument, AASEndpoint, QueryParser, stringFormat } from 'common';
import { BehaviorSubject, EMPTY, first, from, map, mergeMap, Observable, of, Subscription } from 'rxjs';
import {
AuthService,
Expand Down Expand Up @@ -311,7 +311,16 @@ export class StartComponent implements OnDestroy, AfterViewInit {
}

public setFilter(filter: string): void {
this.store.dispatch(StartActions.getFirstPage({ filter }));
filter = filter.trim();
if (filter.length >= 3) {
const parser = new QueryParser(filter);
try {
parser.check();
this.store.dispatch(StartActions.getFirstPage({ filter }));
} catch (error) {
this.notify.error(error);
}
}
}

public setLimit(limit: number): void {
Expand Down
12 changes: 12 additions & 0 deletions projects/aas-portal/src/assets/i18n/de-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,17 @@
"Acustics": "Akustik",
"Assembly_Installation": "Montage & Installation",
"Material": "Material"
},
"QueryParser": {
"ELEMENT_NAME_EXPECTED": "Submodel-Elementname an Position {0} erwartet.",
"INVALID_ABBREVIATION": "'{0}' ist eine ungültige Modelltyp-Abkürzung an Position {1}.",
"INVALID_DATE_EXPRESSION": "'{0}' ist ein ungültiger Datumsausdruck an Position {1}.",
"INVALID_OPERATOR": "'{0}' ist ein ungültiger Operator an Position {1}.",
"INVALID_RANGE_EXPRESSION": "'{0}' ist ein ungültiger Bereichsausdruck an Position {1}.",
"LINK_EXPECTED": "'||' or '&&' erwartet an Position {0}",
"MIN_LENGTH": "Ein Abfrageausdruck muss mindestens {0} Zeichen enthalten.",
"MODEL_TYPE_EXPECTED": "Modelltypabkürzung an Position {0} erwartet.",
"TERM_EXPECTED": "Term erwartet an Position {0}.",
"END_OF_TEXT_NOT_FOUND": "Das Ende des Textes, beginnend an Position {0}, wurde nicht gefunden."
}
}
12 changes: 12 additions & 0 deletions projects/aas-portal/src/assets/i18n/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,17 @@
"Acustics": "Acustics",
"Assembly_Installation": "Assembly & Installation",
"Material": "Material"
},
"QueryParser": {
"ELEMENT_NAME_EXPECTED": "Submodel element name expected at position {0}.",
"INVALID_ABBREVIATION": "'{0}' is an invalid model type abbreviation at position {1}.",
"INVALID_DATE_EXPRESSION": "'{0}' is an invalid date expression at position {1}.",
"INVALID_OPERATOR": "'{0}' is an invalid operator at position {1}.",
"INVALID_RANGE_EXPRESSION": "'{0}' is an invalid range expression at position {1}.",
"LINK_EXPECTED": "'||' or '&&' expected at position {0}",
"MIN_LENGTH": "A query expression must contain at least {0} characters.",
"MODEL_TYPE_EXPECTED": "Model type abbreviation expected at position {0}.",
"TERM_EXPECTED": "Term expected at position {0}.",
"END_OF_TEXT_NOT_FOUND": "The end of the text, starting at position {0}, was not found."
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
/******************************************************************************
*
* Copyright (c) 2019-2023 Fraunhofer IOSB-INA Lemgo,
* eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
* zur Foerderung der angewandten Forschung e.V.
*
*****************************************************************************/

import { DependencyContainer } from 'tsyringe';
import path from 'path';
import { JSONFile } from 'lowdb/node'
import { Low } from 'lowdb';
import { AASIndex } from './aas-index.js';
import { LowDbIndex } from './lowdb/lowdb-index.js';
import { Variable } from '../variable.js';
import { LowDbData } from './lowdb/lowdb-types.js';
import { MySqlIndex } from './mysql/mysql-index.js';

export class AASIndexFactory {
constructor(
private readonly container: DependencyContainer
) { }

public create(): AASIndex {
const variable = this.container.resolve(Variable);
if (variable.AAS_INDEX) {
const url = new URL(variable.AAS_INDEX);
if (url.protocol === 'mysql:') {
return new MySqlIndex(variable);
}

throw new Error('Not implemented.');
}

const dbFile = path.join(variable.CONTENT_ROOT, 'db.json');
const db = new Low<LowDbData>(new JSONFile(dbFile), { documents: [], endpoints: [], elements: [] });
return new LowDbIndex(db, variable);
}
/******************************************************************************
*
* Copyright (c) 2019-2023 Fraunhofer IOSB-INA Lemgo,
* eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
* zur Foerderung der angewandten Forschung e.V.
*
*****************************************************************************/

import { DependencyContainer } from 'tsyringe';
import path from 'path';
import { JSONFile } from 'lowdb/node'
import { Low } from 'lowdb';
import { AASIndex } from './aas-index.js';
import { LowDbIndex } from './lowdb/lowdb-index.js';
import { Variable } from '../variable.js';
import { LowDbData } from './lowdb/lowdb-types.js';
import { MySqlIndex } from './mysql/mysql-index.js';

export class AASIndexFactory {
constructor(
private readonly container: DependencyContainer
) { }

public create(): AASIndex {
const variable = this.container.resolve(Variable);
if (variable.AAS_INDEX) {
const url = new URL(variable.AAS_INDEX);
if (url.protocol === 'mysql:') {
return new MySqlIndex(variable);
}

throw new Error('Not implemented.');
}

const dbFile = path.join(variable.CONTENT_ROOT, 'db.json');
const db = new Low<LowDbData>(new JSONFile(dbFile), { documents: [], endpoints: [], elements: [] });
return new LowDbIndex(db, variable);
}
}
25 changes: 25 additions & 0 deletions projects/aas-server/src/app/aas-index/aas-index-query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/******************************************************************************
*
* Copyright (c) 2019-2023 Fraunhofer IOSB-INA Lemgo,
* eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
* zur Foerderung der angewandten Forschung e.V.
*
*****************************************************************************/

import { Query, QueryParser } from 'common';

export abstract class AASIndexQuery {
protected constructor(query: string, protected readonly language: string) {
this.queryParser = new QueryParser(query, language);
}

protected readonly queryParser: QueryParser;

protected isText(value: unknown): value is string {
return typeof value === 'string';
}

protected isQuery(value: unknown): value is Query {
return typeof value === 'object' && !Array.isArray(value);
}
}
Loading

0 comments on commit ed99448

Please sign in to comment.