Skip to content

Commit

Permalink
feat: TemplateScan implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
raronpxcsw committed Mar 4, 2024
1 parent 49f72e9 commit 2b576db
Show file tree
Hide file tree
Showing 49 changed files with 1,111 additions and 5,723 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"WEB_ROOT": "projects/aas-portal/dist",
"ASSETS": "projects/aas-server/src/assets",
"USER_STORAGE": "mongodb://localhost:27017/aasportal-users",
"TEMPLATE_STORAGE": "http://localhost:8080/templates",
"AAS_INDEX": "mysql://localhost:3306",
"ENDPOINTS": "[\"file:///endpoints/samples?name=Samples\",\"http://localhost:5001?name=AASX%20Server\", \"http://localhost:8080/endpoints/idta?name=IDTA\"]",
// "TEMPLATE_STORAGE": "http://localhost:8080/templates",
// "AAS_INDEX": "mysql://localhost:3306",
"ENDPOINTS": "[\"file:///endpoints/samples?name=Samples\",\"http://localhost:5001?name=AASX%20Server\"]",
}
},
{
Expand Down
282 changes: 141 additions & 141 deletions projects/aas-lib/src/lib/index-change.service.ts
Original file line number Diff line number Diff line change
@@ -1,141 +1,141 @@
/******************************************************************************
*
* Copyright (c) 2019-2023 Fraunhofer IOSB-INA Lemgo,
* eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
* zur Foerderung der angewandten Forschung e.V.
*
*****************************************************************************/

import { EventEmitter, Injectable } from '@angular/core';
import { WebSocketData, AASServerMessage } from 'common';
import { BehaviorSubject, Observable, map } from 'rxjs';
import { WebSocketSubject } from 'rxjs/webSocket';
import { WebSocketFactoryService } from './web-socket-factory.service';
import { NotifyService } from '../public-api';

interface State {
addedDocuments: number;
changedDocuments: number;
removedDocuments: number;
addedEndpoints: number;
removedEndpoints: number;
}

@Injectable({
providedIn: 'root',
})
export class IndexChangeService {
private webSocketSubject?: WebSocketSubject<WebSocketData>;
private readonly _reset = new EventEmitter<void>();
private readonly state$ = new BehaviorSubject<State>({
addedDocuments: 0,
changedDocuments: 0,
removedDocuments: 0,
addedEndpoints: 0,
removedEndpoints: 0,
});

public constructor(
private readonly webSocketFactory: WebSocketFactoryService,
private readonly notify: NotifyService,
) {
this.subscribeIndexChanged();

this.count = this.state$
.asObservable()
.pipe(
map(
state =>
state.addedDocuments +
state.changedDocuments +
state.removedDocuments +
state.addedEndpoints +
state.removedEndpoints,
),
);
}

public readonly reset = new EventEmitter();

public count: Observable<number>;

public clear(): void {
this.state$.next({
addedDocuments: 0,
changedDocuments: 0,
removedDocuments: 0,
addedEndpoints: 0,
removedEndpoints: 0,
});
}

private subscribeIndexChanged = (): void => {
this.webSocketSubject = this.webSocketFactory.create();
this.webSocketSubject.subscribe({
next: (data: WebSocketData): void => {
if (data.type === 'AASServerMessage') {
this.update(data.data as AASServerMessage);
}
},
error: (): void => {
setTimeout(this.subscribeIndexChanged, 2000);
},
});

this.webSocketSubject.next(this.createMessage());
};

private createMessage(): WebSocketData {
return {
type: 'IndexChange',
data: null,
} as WebSocketData;
}

private update(data: AASServerMessage): void {
switch (data.type) {
case 'Added':
this.documentAdded();
break;
case 'Removed':
this.documentRemoved();
break;
case 'Changed':
this.documentChanged();
break;
case 'EndpointAdded':
this.endpointAdded();
break;
case 'EndpointRemoved':
this.endpointRemoved();
break;
case 'Reset':
break;
}
}

private documentAdded(): void {
const state = this.state$.getValue();
this.state$.next({ ...state, addedDocuments: state.addedDocuments + 1 });
}

private documentRemoved(): void {
const state = this.state$.getValue();
this.state$.next({ ...state, removedDocuments: state.removedDocuments + 1 });
}

private documentChanged(): void {
const state = this.state$.getValue();
this.state$.next({ ...state, changedDocuments: state.changedDocuments + 1 });
}

private endpointAdded(): void {
const state = this.state$.getValue();
this.state$.next({ ...state, addedEndpoints: state.addedEndpoints + 1 });
}

private endpointRemoved(): void {
const state = this.state$.getValue();
this.state$.next({ ...state, removedEndpoints: state.removedEndpoints + 1 });
}
}
/******************************************************************************
*
* Copyright (c) 2019-2024 Fraunhofer IOSB-INA Lemgo,
* eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
* zur Foerderung der angewandten Forschung e.V.
*
*****************************************************************************/

import { EventEmitter, Injectable } from '@angular/core';
import { WebSocketData, AASServerMessage } from 'common';
import { BehaviorSubject, Observable, map } from 'rxjs';
import { WebSocketSubject } from 'rxjs/webSocket';
import { WebSocketFactoryService } from './web-socket-factory.service';
import { NotifyService } from '../public-api';

interface State {
addedDocuments: number;
changedDocuments: number;
removedDocuments: number;
addedEndpoints: number;
removedEndpoints: number;
}

@Injectable({
providedIn: 'root',
})
export class IndexChangeService {
private webSocketSubject?: WebSocketSubject<WebSocketData>;
private readonly _reset = new EventEmitter<void>();
private readonly state$ = new BehaviorSubject<State>({
addedDocuments: 0,
changedDocuments: 0,
removedDocuments: 0,
addedEndpoints: 0,
removedEndpoints: 0,
});

public constructor(
private readonly webSocketFactory: WebSocketFactoryService,
private readonly notify: NotifyService,
) {
this.subscribeIndexChanged();

this.count = this.state$
.asObservable()
.pipe(
map(
state =>
state.addedDocuments +
state.changedDocuments +
state.removedDocuments +
state.addedEndpoints +
state.removedEndpoints,
),
);
}

public readonly reset = new EventEmitter();

public count: Observable<number>;

public clear(): void {
this.state$.next({
addedDocuments: 0,
changedDocuments: 0,
removedDocuments: 0,
addedEndpoints: 0,
removedEndpoints: 0,
});
}

private subscribeIndexChanged = (): void => {
this.webSocketSubject = this.webSocketFactory.create();
this.webSocketSubject.subscribe({
next: (data: WebSocketData): void => {
if (data.type === 'AASServerMessage') {
this.update(data.data as AASServerMessage);
}
},
error: (): void => {
setTimeout(this.subscribeIndexChanged, 2000);
},
});

this.webSocketSubject.next(this.createMessage());
};

private createMessage(): WebSocketData {
return {
type: 'IndexChange',
data: null,
} as WebSocketData;
}

private update(data: AASServerMessage): void {
switch (data.type) {
case 'Added':
this.documentAdded();
break;
case 'Removed':
this.documentRemoved();
break;
case 'Changed':
this.documentChanged();
break;
case 'EndpointAdded':
this.endpointAdded();
break;
case 'EndpointRemoved':
this.endpointRemoved();
break;
case 'Reset':
break;
}
}

private documentAdded(): void {
const state = this.state$.getValue();
this.state$.next({ ...state, addedDocuments: state.addedDocuments + 1 });
}

private documentRemoved(): void {
const state = this.state$.getValue();
this.state$.next({ ...state, removedDocuments: state.removedDocuments + 1 });
}

private documentChanged(): void {
const state = this.state$.getValue();
this.state$.next({ ...state, changedDocuments: state.changedDocuments + 1 });
}

private endpointAdded(): void {
const state = this.state$.getValue();
this.state$.next({ ...state, addedEndpoints: state.addedEndpoints + 1 });
}

private endpointRemoved(): void {
const state = this.state$.getValue();
this.state$.next({ ...state, removedEndpoints: state.removedEndpoints + 1 });
}
}
4 changes: 2 additions & 2 deletions projects/aas-lib/src/lib/template.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class TemplateService {
* @param endpoint The template endpoint.
* @returns The template.
*/
public getTemplate(endpoint: Endpoint): Observable<aas.Referable> {
return this.http.get<aas.Referable>(`/api/v1/templates/${encodeBase64Url(endpoint.address)}`);
public getTemplate(endpoint: Endpoint): Observable<aas.Referable | aas.Environment> {
return this.http.get<aas.Referable | aas.Environment>(`/api/v1/templates/${encodeBase64Url(endpoint.address)}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Component } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { Observable, map } from 'rxjs';
import { TemplateService } from 'aas-lib';
import { TemplateDescriptor, aas, getChildren } from 'common';
import { TemplateDescriptor, aas, getChildren, isEnvironment } from 'common';
import { head } from 'lodash-es';

@Component({
Expand Down Expand Up @@ -108,7 +108,11 @@ export class NewElementFormComponent {
this.clearMessages();
if (this.validate()) {
this.api.getTemplate(this._template!.endpoint!).subscribe(template => {
template.idShort = this.idShort;
if (isEnvironment(template)) {
template.submodels[0].idShort = this.idShort;
} else {
template.idShort = this.idShort;
}
return this.modal.close(template);
});
}
Expand Down
Loading

0 comments on commit 2b576db

Please sign in to comment.