Skip to content

Commit

Permalink
fix; aas types updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Mar 22, 2024
1 parent 5dea13e commit 2d4b2aa
Show file tree
Hide file tree
Showing 27 changed files with 1,123 additions and 527 deletions.
964 changes: 759 additions & 205 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"semantic-release": "^23.0.2",
"supertest": "^6.3.4",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tsx": "^4.7.1",
"typescript": "^5.2.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const semanticIdMap = new Map<string, string>([
[CustomerFeedback, CustomerFeedback],
]);

export function resolveSemanticId(value: aas.HasSemantic | aas.Reference | string): string | undefined {
export function resolveSemanticId(value: aas.HasSemantics | aas.Reference | string): string | undefined {
let semanticId: string | undefined;
if (value) {
if (typeof value === 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ describe('OperationCallFormComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [OperationCallFormComponent],
providers: [
NgbModal,
NgbActiveModal
],
providers: [NgbModal, NgbActiveModal],
imports: [
HttpClientTestingModule,
CommonModule,
Expand All @@ -41,10 +38,10 @@ describe('OperationCallFormComponent', () => {
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateFakeLoader
}
})
]
useClass: TranslateFakeLoader,
},
}),
],
});

api = TestBed.inject(AASTreeApiService);
Expand All @@ -56,14 +53,13 @@ describe('OperationCallFormComponent', () => {

operation = {
category: 'CONSTANT',
kind: 'Instance',
methodId: '123',
modelType: 'Operation',
idShort: 'convert',
objectId: 'abc',
inputVariables: [],
inoutputVariables: [],
outputVariables: []
outputVariables: [],
};
});

Expand All @@ -79,7 +75,7 @@ describe('OperationCallFormComponent', () => {
(resultOp.inputVariables![0].value as aas.Property).value = 'Hello World!';
(resultOp.outputVariables![0].value as aas.Property).value = 'Hello World!'.toUpperCase();

spyOn(api, 'invoke').and.returnValue(new Promise<aas.Operation>((result) => result(resultOp)))
spyOn(api, 'invoke').and.returnValue(new Promise<aas.Operation>(result => result(resultOp)));
component.document = document;
component.operation = operation;
component.inputVariables[0].value = 'Hello World!';
Expand All @@ -98,7 +94,7 @@ describe('OperationCallFormComponent', () => {
(resultOp.inputVariables![0].value as aas.Property).value = 'false';
(resultOp.outputVariables![0].value as aas.Property).value = 'true';

spyOn(api, 'invoke').and.returnValue(new Promise<aas.Operation>((result) => result(resultOp)))
spyOn(api, 'invoke').and.returnValue(new Promise<aas.Operation>(result => result(resultOp)));
component.document = document;
component.operation = operation;
component.inputVariables[0].value = false;
Expand All @@ -117,7 +113,7 @@ describe('OperationCallFormComponent', () => {
(resultOp.inputVariables![0].value as aas.Property).value = '42';
(resultOp.outputVariables![0].value as aas.Property).value = '43';

spyOn(api, 'invoke').and.returnValue(new Promise<aas.Operation>((result) => result(resultOp)))
spyOn(api, 'invoke').and.returnValue(new Promise<aas.Operation>(result => result(resultOp)));
component.document = document;
component.operation = operation;
component.inputVariables[0].value = '42';
Expand Down Expand Up @@ -154,7 +150,7 @@ describe('OperationCallFormComponent', () => {
operation.outputVariables = [createVariable('out', 'xs:int', 0)];

const dummy = cloneDeep(operation);
spyOn(api, 'invoke').and.returnValue(new Promise<aas.Operation>((result) => result(dummy)))
spyOn(api, 'invoke').and.returnValue(new Promise<aas.Operation>(result => result(dummy)));

component.document = document;
component.operation = operation;
Expand All @@ -166,15 +162,14 @@ describe('OperationCallFormComponent', () => {
expect(component.canCall).toBeTrue();
});

function createVariable(name: string, valueType?: aas.DataTypeDefXsd, value?: any): aas.OperationVariable {
function createVariable(name: string, valueType?: aas.DataTypeDefXsd, value?: unknown): aas.OperationVariable {
return {
value: {
modelType: 'Property',
idShort: name,
kind: 'Instance',
valueType: valueType,
value: convertToString(value)
} as aas.Property
value: convertToString(value),
} as aas.Property,
};
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ export class EditElementFormComponent {

private initMultiLanguageProperty(): void {
const multiLangProperty = this.element as aas.MultiLanguageProperty;
this.langStrings = multiLangProperty.value.map(
(item, index) => ({ ...item, selected: false, index }) as LangStringRow,
);
this.langStrings = multiLangProperty.value
? multiLangProperty.value.map((item, index) => ({ ...item, selected: false, index }) as LangStringRow)
: [];

this.langStrings.push({ language: '', text: '', selected: false, index: -1 });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ describe('EditElementFormComponent', () => {
idShort: 'Text',
modelType: 'Property',
category: 'CONSTANT',
kind: 'Instance',
valueType: 'xs:string',
};

Expand Down Expand Up @@ -127,7 +126,6 @@ describe('EditElementFormComponent', () => {
idShort: 'A multi language property',
modelType: 'MultiLanguageProperty',
category: 'CONSTANT',
kind: 'Instance',
value: [{ language: 'de', text: 'Hallo Welt!' }],
};

Expand Down
14 changes: 7 additions & 7 deletions projects/aas-server/src/app/aas-provider/aas-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class AASProvider {
try {
await resource.openAsync();
if (!document.content) {
document.content = await resource.createPackage(document.address).readEnvironmentAsync();
document.content = await resource.createPackage(document.address).getEnvironmentAsync();
}

return document;
Expand All @@ -108,7 +108,7 @@ export class AASProvider {
const resource = this.resourceFactory.create(endpoint);
try {
await resource.openAsync();
return await resource.createPackage(document.address).readEnvironmentAsync();
return await resource.createPackage(document.address).getEnvironmentAsync();
} finally {
await resource.closeAsync();
}
Expand Down Expand Up @@ -141,7 +141,7 @@ export class AASProvider {
await resource.openAsync();
const pkg = resource.createPackage(document.address);
if (!document.content) {
document.content = await pkg.readEnvironmentAsync();
document.content = await pkg.getEnvironmentAsync();
}

const dataElement: aas.DataElement | undefined = selectElement(document.content, smId, path);
Expand Down Expand Up @@ -253,10 +253,10 @@ export class AASProvider {
await resource.openAsync();
const pkg = resource.createPackage(document.address);
if (!document.content) {
document.content = await pkg.readEnvironmentAsync();
document.content = await pkg.getEnvironmentAsync();
}

return await pkg.commitDocumentAsync(document, content);
return await pkg.setEnvironmentAsync(content, document.content);
} finally {
await resource.closeAsync();
}
Expand Down Expand Up @@ -421,7 +421,7 @@ export class AASProvider {
const document = await this.index.get(message.endpoint, message.id);
const resource = this.resourceFactory.create(endpoint);
await resource.openAsync();
const env = await resource.createPackage(document.address).readEnvironmentAsync();
const env = await resource.createPackage(document.address).getEnvironmentAsync();
return resource.createSubscription(client, message, env);
}

Expand Down Expand Up @@ -574,7 +574,7 @@ export class AASProvider {
const resource = this.resourceFactory.create(endpoint);
try {
await resource.openAsync();
return await resource.createPackage(document.address).readEnvironmentAsync();
return await resource.createPackage(document.address).getEnvironmentAsync();
} finally {
await resource.closeAsync();
}
Expand Down
14 changes: 8 additions & 6 deletions projects/aas-server/src/app/packages/aas-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ export abstract class AASPackage {
*/
public abstract openReadStreamAsync(env: aas.Environment, file: aas.File): Promise<NodeJS.ReadableStream>;

/**
* Gets the AAS environment from the package.
* */
public abstract getEnvironmentAsync(): Promise<aas.Environment>;

/**
* Applies the state of the source document into the destination document.
* @param source The source document.
* @param content The new document content.
* @param env The new AAS environment.
* @param reference The previous state.
*/
public abstract commitDocumentAsync(source: AASDocument, content: aas.Environment): Promise<string[]>;

/** Reads the AAS environment. */
public abstract readEnvironmentAsync(): Promise<aas.Environment>;
public abstract setEnvironmentAsync(env: aas.Environment, reference?: aas.Environment): Promise<string[]>;

protected normalize(path: string): string {
path = path.replace(/\\/g, '/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ export class AASServerPackage extends AASPackage {
return document;
}

public override async readEnvironmentAsync(): Promise<aas.Environment> {
public override async getEnvironmentAsync(): Promise<aas.Environment> {
return await this.server.readEnvironmentAsync(this.idShort);
}

public async commitDocumentAsync(target: AASDocument, content: aas.Environment): Promise<string[]> {
public async setEnvironmentAsync(content: aas.Environment, reference?: aas.Environment): Promise<string[]> {
let messages: string[] | undefined;
if (target.content && content) {
const diffs = await diffAsync(content, target.content);
if (reference && content) {
const diffs = await diffAsync(content, reference);
if (diffs.length > 0) {
messages = await this.server.commitAsync(content, target.content, diffs);
messages = await this.server.commitAsync(content, reference, diffs);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class AasxDirectory extends AASResource {

public override readonly version = '';

public readonly readOnly = true;
public readonly readOnly = false;

public readonly onlineReady = false;

Expand Down
27 changes: 22 additions & 5 deletions projects/aas-server/src/app/packages/file-system/aasx-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
*****************************************************************************/

import fs from 'fs';
import { basename, extname } from 'path/posix';
import jszip from 'jszip';
import xpath from 'xpath';
Expand All @@ -20,6 +21,7 @@ import { AASReader } from '../aas-reader.js';
import { ImageProcessing } from '../../image-processing.js';
import { createXmlReader } from '../create-xml-reader.js';
import { createJsonReader } from '../create-json-reader.js';
import { XmlWriter } from '../xml-writer.js';

export class AasxPackage extends AASPackage {
private readonly file: string;
Expand Down Expand Up @@ -65,15 +67,20 @@ export class AasxPackage extends AASPackage {
return document;
}

public override async readEnvironmentAsync(): Promise<aas.Environment> {
public override async getEnvironmentAsync(): Promise<aas.Environment> {
return (await this.createReaderAsync()).readEnvironment();
}

public commitDocumentAsync(): Promise<string[]> {
throw new Error('Method not implemented.');
public override async setEnvironmentAsync(env: aas.Environment): Promise<string[]> {
const writer = new XmlWriter();
const xml = writer.write(env);
const path = await this.getOriginNameAsync();
(await this.zip).file(path, xml, { compression: 'DEFLATE' });
await this.saveAsync();
return [`${this.file} successfully written.`];
}

public async openReadStreamAsync(_: aas.Environment, file: aas.File): Promise<NodeJS.ReadableStream> {
public override async openReadStreamAsync(_: aas.Environment, file: aas.File): Promise<NodeJS.ReadableStream> {
if (!file.value) {
throw new Error('Invalid operation.');
}
Expand All @@ -87,7 +94,7 @@ export class AasxPackage extends AASPackage {
return stream;
}

public async getThumbnailAsync(): Promise<NodeJS.ReadableStream> {
public override async getThumbnailAsync(): Promise<NodeJS.ReadableStream> {
let stream: NodeJS.ReadableStream | undefined;
const relationships = await this.getRelationshipsAsync('_rels/.rels');
for (const relationship of relationships) {
Expand Down Expand Up @@ -177,6 +184,16 @@ export class AasxPackage extends AASPackage {
return (await file.async(contentType)) as string;
}

private async saveAsync(): Promise<void> {
const zip = await this.zip;
await new Promise<void>((resolve, reject) => {
zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
.pipe(fs.createWriteStream(this.file))
.on('finish', () => resolve())
.on('error', error => reject(error));
});
}

private getContentType(fileName: string): jszip.OutputType {
let contentType: jszip.OutputType;
const extension = this.getExtension(fileName);
Expand Down
10 changes: 5 additions & 5 deletions projects/aas-server/src/app/packages/json-reader-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ export class JsonReaderV2 extends AASReader {
return this.readDataTypeDefXsd(source.dataObjectType?.name) as aas.DataTypeDefXsd;
}

private readHasSemantic(source: aasv2.HasSemantic): aas.HasSemantic {
const hasSemantic: aas.HasSemantic = {};
private readHasSemantic(source: aasv2.HasSemantic): aas.HasSemantics {
const hasSemantic: aas.HasSemantics = {};
if (source.semanticId) {
hasSemantic.semanticId = this.readReference(source.semanticId);
}
Expand Down Expand Up @@ -657,7 +657,7 @@ export class JsonReaderV2 extends AASReader {
}

if (source.levelType) {
iec61360.levelType = source.levelType;
iec61360.levelType = { ...source.levelType };
}

if (source.shortName) {
Expand Down Expand Up @@ -804,7 +804,7 @@ export class JsonReaderV2 extends AASReader {
}
}

private readDataTypeIEC61360(source: string): aas.DataTypeIEC61360 {
private readDataTypeIEC61360(source: string): aas.DataTypeIec61360 {
switch (source) {
case 'DATE':
return 'DATE';
Expand Down Expand Up @@ -837,7 +837,7 @@ export class JsonReaderV2 extends AASReader {
case 'TIMESTAMP':
return 'TIMESTAMP';
default:
return source as aas.DataTypeIEC61360;
return source as aas.DataTypeIec61360;
}
}
}
Loading

0 comments on commit 2d4b2aa

Please sign in to comment.