Skip to content

Commit

Permalink
feat: WebDAV endpoint support
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Feb 24, 2024
1 parent 6f2a7ca commit e3ec10a
Show file tree
Hide file tree
Showing 73 changed files with 7,831 additions and 729 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"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\"]",
"ENDPOINTS": "[\"file:///endpoints/samples?name=Samples\",\"http://localhost:5001?name=AASX%20Server\", \"http://localhost:8080/endpoints/idta?name=IDTA\"]",
}
},
{
Expand Down
4 changes: 4 additions & 0 deletions projects/aas-lib/src/lib/aas-tree/aas-tree-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ export class AASTreeSearch {
}
case 'ReferenceElement': {
const referenceElement = referable as aas.ReferenceElement;
if (!referenceElement.value) {
return false;
}

return referenceElement.value.keys.some(key => this.containsString(key.value, value as string));
}
case 'MultiLanguageProperty': {
Expand Down
13 changes: 0 additions & 13 deletions projects/aas-lib/src/lib/aas-tree/aas-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import {
AASDocument,
convertToString,
toLocale,
EndpointType,
selectSubmodel,
getIdShortPath,
mimeTypeToExtension,
AASEndpointType,
} from 'common';

import { AASTreeRow, AASTreeFeatureState } from './aas-tree.state';
Expand Down Expand Up @@ -513,17 +511,6 @@ export class AASTreeComponent implements OnInit, OnChanges, OnDestroy {
}
}

private toEndpointType(type: AASEndpointType): EndpointType {
switch (type) {
case 'OpcuaServer':
return 'opc';
case 'AasxDirectory':
return 'file';
default:
return 'http';
}
}

private stop(): void {
if (this.webSocketSubject) {
this.webSocketSubject.unsubscribe();
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-lib/src/lib/aas-tree/aas-tree.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class TreeInitialize {
return blob.contentType ? `${blob.idShort}${extension}` : '-';
}
case 'ReferenceElement':
return (referable as aas.ReferenceElement).value.keys.map(item => item.value).join('/');
return (referable as aas.ReferenceElement).value?.keys.map(item => item.value).join('/');
case 'RelationshipElement':
return this.getRelationshipElementValue(referable as aas.RelationshipElement);
case 'MultiLanguageProperty':
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-lib/src/test/assets/test-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function createContainer(url: string, documents: AASDocument[]): AASConta
documents: documents,
url: url,
name: url,
type: 'AasxDirectory'
type: 'FileSystem'
};
}

Expand Down
1 change: 0 additions & 1 deletion projects/aas-lib/src/test/template.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe('TemplateService', () => {
idShort: '',
modelType: 'Property',
endpoint: { type: 'file', address: 'property.json' },
template: null,
};

const url = `/api/v1/templates`;
Expand Down
45 changes: 0 additions & 45 deletions projects/aas-portal/src/app/configuration.ts

This file was deleted.

2 changes: 1 addition & 1 deletion projects/aas-portal/src/app/dashboard/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export class DashboardService {
switch (type) {
case 'OpcuaServer':
return 'opc';
case 'AasxDirectory':
case 'FileSystem':
return 'file';
default:
return 'http';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class AddEndpointFormComponent {
) {
this.items = [
{
name: this.translate.instant('AASEndpointType.AasxServer'),
type: 'AasxServer',
name: this.translate.instant('AASEndpointType.AASServer'),
type: 'AASServer',
value: 'http://',
},
{
Expand All @@ -39,22 +39,27 @@ export class AddEndpointFormComponent {
value: 'opc.tcp://',
},
{
name: this.translate.instant('AASEndpointType.AasxDirectory'),
type: 'AasxDirectory',
name: this.translate.instant('AASEndpointType.WebDAV'),
type: 'WebDAV',
value: 'http://',
},
{
name: this.translate.instant('AASEndpointType.FileSystem'),
type: 'FileSystem',
value: 'file:///',
},
];

this.item = this.items[0];
}

public endpoints: string[] = [];
public endpoints: AASEndpoint[] = [];

public messages: string[] = [];

public name = '';

public version = '3.0';
public version = 'v3';

public readonly items: EndpointItem[];

Expand Down Expand Up @@ -95,8 +100,8 @@ export class AddEndpointFormComponent {
this.messages.push(this.createMessage('ERROR_EMPTY_ENDPOINT_NAME'));
name = undefined;
} else {
for (const workspace of this.endpoints) {
if (workspace.toLocaleLowerCase() === name.toLocaleLowerCase()) {
for (const endpoint of this.endpoints) {
if (endpoint.name.toLocaleLowerCase() === name.toLocaleLowerCase()) {
this.messages.push(this.createMessage('ERROR_ENDPOINT_ALREADY_EXIST', name));
name = undefined;
break;
Expand All @@ -110,22 +115,18 @@ export class AddEndpointFormComponent {
private validateUrl(value: string): URL | undefined {
try {
const url = new URL(value);
switch (url.protocol) {
case 'opc.tcp:':
if (url.pathname === '//') {
throw new Error('Empty pathname.');
}
switch (this.item.type) {
case 'AASServer':
this.validateAASServerEndpoint(url);
break;
case 'FileSystem':
this.validateFileSystemEndpoint(url);
break;
case 'http:':
case 'OpcuaServer':
this.validateOpcuaEndpoint(url);
break;
case 'file:':
if (url.hostname !== '') {
throw new Error(`Invalid host name ${url.hostname}.`);
}

if (url.pathname === '/') {
throw new Error('Empty pathname.');
}
case 'WebDAV':
this.validateWebDAVEndpoint(url);
break;
}

Expand All @@ -139,4 +140,48 @@ export class AddEndpointFormComponent {
private createMessage(id: string, ...args: unknown[]): string {
return stringFormat(this.translate.instant(id), args);
}

private validateAASServerEndpoint(url: URL): void {
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
throw new Error('Protocol "http:" or "https:" expected.');
}

if (url.pathname !== '/') {
throw new Error(`Unexpected pathname "${url.pathname}".`);
}
}

private validateFileSystemEndpoint(url: URL): void {
if (url.protocol !== 'file:') {
throw new Error('Protocol "file:" expected');
}

if (url.hostname !== '') {
throw new Error(`Invalid host name ${url.hostname}.`);
}

if (url.pathname === '/') {
throw new Error('Empty pathname.');
}
}

private validateOpcuaEndpoint(url: URL): void {
if (url.protocol !== 'opc.tcp:') {
throw new Error('Protocol "opc.tcp:" expected.');
}

if (url.pathname === '//' || url.pathname === '/') {
throw new Error('Empty pathname.');
}
}

private validateWebDAVEndpoint(url: URL): void {
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
throw new Error('Protocol "http:" or "https:" expected.');
}

if (url.pathname === '/') {
throw new Error('Empty pathname.');
}
}
}
2 changes: 1 addition & 1 deletion projects/aas-portal/src/app/start/start.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class StartComponent implements OnDestroy, AfterViewInit {
mergeMap(() => this.api.getEndpoints()),
map(endpoints => {
const modalRef = this.modal.open(AddEndpointFormComponent, { backdrop: 'static' });
modalRef.componentInstance.workspaces = endpoints;
modalRef.componentInstance.endpoints = endpoints;
return modalRef;
}),
mergeMap(modalRef => from<Promise<AASEndpoint | undefined>>(modalRef.result)),
Expand Down
6 changes: 3 additions & 3 deletions projects/aas-portal/src/assets/i18n/de-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@
"OPTION_BAR_VERTICAL_CHART": "Balkendiagramm vertikal",
"OPTION_BAR_HORIZONTAL_CHART": "Balkendiagramm horizontal",
"AASEndpointType": {
"AasxDirectory": "Verzeichnis",
"AasxServer": "AASX-Server",
"AASRegistry": "AAS-Registry",
"FileSystem": "Verzeichnis",
"AASServer": "AAS-Server",
"WebDAV": "Cloud-Server",
"OpcuaServer": "OPC-UA-Server"
},
"CustomerFeedback": {
Expand Down
6 changes: 3 additions & 3 deletions projects/aas-portal/src/assets/i18n/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@
"OPTION_BAR_VERTICAL_CHART": "Vertical bar chart",
"OPTION_BAR_HORIZONTAL_CHART": "Horizontal bar chart",
"AASEndpointType": {
"AasxDirectory": "Directory",
"AasxServer": "AASX Server",
"AASRegistry": "AAS Registry",
"FileSystem": "File system",
"AASServer": "AAS server",
"WebDAV": "Cloud server",
"OpcuaServer": "OPC UA Server"
},
"CustomerFeedback": {
Expand Down
51 changes: 29 additions & 22 deletions projects/aas-portal/src/test/aas/new-element-command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ describe('NewElementCommand', function () {

TestBed.configureTestingModule({
declarations: [],
providers: [
],
providers: [],
imports: [
StoreModule.forRoot(
{
aas: aasReducer
}),
]
StoreModule.forRoot({
aas: aasReducer,
}),
],
});

store = TestBed.inject(Store);
Expand All @@ -47,25 +45,34 @@ describe('NewElementCommand', function () {
});

it('can be executed', function (done: DoneFn) {
store.select(state => state.aas.document).pipe(first()).subscribe(document => {
const element = selectElement(document!.content!, 'TechnicalData');
expect(element).toBeDefined();
done();
});
store
.select(state => state.aas.document)
.pipe(first())
.subscribe(document => {
const element = selectElement(document!.content!, 'TechnicalData');
expect(element).toBeDefined();
done();
});
});

it('can be undone/redone', function (done: DoneFn) {
command.undo();
store.select(state => state.aas.document).pipe(first()).subscribe(document => {
const element = selectElement(document!.content!, 'TechnicalData');
expect(element).toBeUndefined();
});
store
.select(state => state.aas.document)
.pipe(first())
.subscribe(document => {
const element = selectElement(document!.content!, 'TechnicalData');
expect(element).toBeUndefined();
});

command.redo();
store.select(state => state.aas.document).pipe(first()).subscribe(document => {
const element = selectElement(document!.content!, 'TechnicalData');
expect(element).toBeDefined();
done();
});
store
.select(state => state.aas.document)
.pipe(first())
.subscribe(document => {
const element = selectElement(document!.content!, 'TechnicalData');
expect(element).toBeDefined();
done();
});
});
});
});
2 changes: 1 addition & 1 deletion projects/aas-portal/src/test/assets/test-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function createContainer(url: string, documents: AASDocument[]): AASConta
documents: documents,
url: url,
name: url,
type: 'AasxServer'
type: 'AASServer'
};
}

Expand Down
Loading

0 comments on commit e3ec10a

Please sign in to comment.