Skip to content

Commit

Permalink
fix: AASCache, admin.shell-io.com support
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Jul 26, 2024
1 parent dd87950 commit de97475
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 110 deletions.
13 changes: 11 additions & 2 deletions projects/aas-lib/src/lib/aas-tree/aas-tree-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ class TreeInitialize {
switch (referable.modelType) {
case 'Blob': {
const blob = referable as aas.Blob;
const extension = mimeTypeToExtension(blob.contentType) ?? '';
return blob.contentType ? `${blob.idShort}${extension}` : '-';
const extension = mimeTypeToExtension(blob.contentType);
return blob.contentType ? `${blob.idShort}${extension}` : this.getSemanticId(blob);
}
case 'Entity':
return (referable as aas.Entity).globalAssetId ?? '-';
Expand Down Expand Up @@ -279,6 +279,15 @@ class TreeInitialize {
return '';
}

private getSemanticId(hasSemantics: aas.HasSemantics): string {
const keys = hasSemantics.semanticId?.keys;
if (keys && keys.length > 0) {
return keys[0].value;
}

return '-';
}

private hasChildren(referable: aas.Referable): boolean {
switch (referable.modelType) {
case 'AssetAdministrationShell': {
Expand Down
48 changes: 25 additions & 23 deletions projects/aas-lib/src/lib/aas-tree/aas-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,32 +268,34 @@ export class AASTreeComponent implements OnInit, OnDestroy {

public async openBlob(blob: aas.Blob | undefined): Promise<void> {
const document = this.document();
if (!blob?.value || !document || !blob.parent || this.state() === 'online') return;
if (!blob || !document || !blob.parent || this.state() === 'online') return;

let name = blob.idShort;
const extension = mimeTypeToExtension(blob.contentType);
if (extension) {
const name = blob.idShort + extension;
if (blob.value) {
if (blob.contentType.startsWith('image/')) {
await this.showImageAsync(name, `data:${blob.contentType};base64,${blob.value}`);
} else if (blob.contentType.startsWith('video/')) {
await this.showVideoAsync(name, `data:${blob.contentType};base64,${blob.value}`);
}
} else {
const endpoint = encodeBase64Url(document.endpoint);
const id = encodeBase64Url(document.id);
const smId = encodeBase64Url(blob.parent.keys[0].value);
const path = getIdShortPath(blob);
const url = `/api/v1/containers/${endpoint}/documents/${id}/submodels/${smId}/blobs/${path}/value`;
if (blob.contentType.startsWith('image/')) {
await this.showImageAsync(name, url);
} else if (blob.contentType.startsWith('video/')) {
await this.showVideoAsync(name, url);
} else if (blob.contentType.endsWith('/pdf')) {
this.window.open(url);
} else if (blob) {
await this.downloadFileAsync(name, url);
}
name += extension;
}

if (blob.value) {
if (blob.contentType.startsWith('image/')) {
await this.showImageAsync(name, `data:${blob.contentType};base64,${blob.value}`);
} else if (blob.contentType.startsWith('video/')) {
await this.showVideoAsync(name, `data:${blob.contentType};base64,${blob.value}`);
}
} else {
const endpoint = encodeBase64Url(document.endpoint);
const id = encodeBase64Url(document.id);
const smId = encodeBase64Url(blob.parent.keys[0].value);
const path = getIdShortPath(blob);
const url = `/api/v1/containers/${endpoint}/documents/${id}/submodels/${smId}/submodel-elements/${path}/value`;
if (blob.contentType.startsWith('image/')) {
await this.showImageAsync(name, url);
} else if (blob.contentType.startsWith('video/')) {
await this.showVideoAsync(name, url);
} else if (blob.contentType.endsWith('/pdf')) {
this.window.open(url);
} else if (blob) {
await this.downloadFileAsync(name, url);
}
}
}
Expand Down
64 changes: 64 additions & 0 deletions projects/aas-server/src/app/aas-provider/aas-cache.ts
Original file line number Diff line number Diff line change
@@ -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 { aas } from 'aas-core';

/**
* Provides an AAS cache with a 2nd chance strategy.
*/
export class AASCache {
private first = new Map<string, aas.Environment>();
private second = new Map<string, aas.Environment>();

public constructor(private readonly size: number = 100) {}

public has(endpointName: string, id: string): boolean {
const key = endpointName + '#' + id;
return this.first.has(key) || this.second.has(key);
}

public get(endpointName: string, id: string): aas.Environment | undefined {
const key = endpointName + '#' + id;
let env = this.first.get(key);
if (!env) {
env = this.second.get(key);
}

return env;
}

public set(endpointName: string, id: string, env: aas.Environment): void {
const key = endpointName + '#' + id;
if (this.first.has(key)) {
this.first.set(key, env);
} else if (this.second.has(key)) {
this.second.set(key, env);
} else {
if (this.first.size >= this.size) {
this.second = this.first;
this.first = new Map<string, aas.Environment>();
}

this.first.set(key, env);
}
}

public remove(endpointName: string, id: string): void {
const key = endpointName + '#' + id;
if (this.first.has(key)) {
this.first.delete(key);
} else if (this.second.has(key)) {
this.second.delete(key);
}
}

public clear(): void {
this.first.clear();
this.second.clear();
}
}
Loading

0 comments on commit de97475

Please sign in to comment.