From a0265254af4fa600f481fbee797cda06b918b946 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Wed, 20 Sep 2023 12:02:00 +0200 Subject: [PATCH 1/9] chore: use UI-safe Asset --- package-lock.json | 38 ++++++++++--- package.json | 2 +- src/app/core/services/api/edc-api.service.ts | 5 +- .../api/fake-backend/asset-fake-service.ts | 30 +++++++--- .../api/fake-backend/data/test-assets.ts | 57 +++++++++---------- src/app/core/services/asset-entry-builder.ts | 55 +++++++++++++++--- .../asset-create-dialog.component.ts | 4 +- 7 files changed, 132 insertions(+), 59 deletions(-) diff --git a/package-lock.json b/package-lock.json index a4e976ea1..c69106f6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "@ng-apimock/core": "^3.11.0", "@ngxs/store": "^3.8.1", "@sovity.de/broker-server-client": "0.20230712.71619-main-a4860cff", - "@sovity.de/edc-client": "0.20230830.155424-main-b314d7e2", + "@sovity.de/edc-client": "0.20230919.111550-main-118ea199", "clean-deep": "^3.4.0", "date-fns": "^2.30.0", "dotenv": "^16.3.1", @@ -33,6 +33,7 @@ "rxjs": "7.8.1", "tslib": "^2.6.2", "url-join": "^5.0.0", + "uuid": "^9.0.1", "zone.js": "^0.12.0" }, "devDependencies": { @@ -779,6 +780,15 @@ "yarn": ">= 1.13.0" } }, + "node_modules/@angular/cli/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@angular/common": { "version": "14.3.0", "resolved": "https://registry.npmjs.org/@angular/common/-/common-14.3.0.tgz", @@ -3598,9 +3608,9 @@ "integrity": "sha512-305vHJj38Ma9x9YADM3SJh3sdqePeLcrUB1hHlYsuPdx7wYe9vwgb503KYStJ+5iN/ojP2xu8k6Unt+y+Bu5iQ==" }, "node_modules/@sovity.de/edc-client": { - "version": "0.20230830.155424-main-b314d7e2", - "resolved": "https://registry.npmjs.org/@sovity.de/edc-client/-/edc-client-0.20230830.155424-main-b314d7e2.tgz", - "integrity": "sha512-kOx2ZclD3rfhq/hC+9bKVAQRQh8vtWbcp4u3DI4X9chR5/euB41UlJQ1E8vokPkGdEeVmjMTwVOuXwpLRWJj7g==" + "version": "0.20230919.111550-main-118ea199", + "resolved": "https://registry.npmjs.org/@sovity.de/edc-client/-/edc-client-0.20230919.111550-main-118ea199.tgz", + "integrity": "sha512-Q0VlZUzwk/0PaYpUug+Asq1bBokQ9E1LceGNCWxS9CzOvukB1rIMg1x+SQqNtoEXXRqBE0WW6eI8B8RMN8ClNQ==" }, "node_modules/@tootallnate/once": { "version": "2.0.0", @@ -12079,6 +12089,15 @@ "websocket-driver": "^0.7.4" } }, + "node_modules/sockjs/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/socks": { "version": "2.7.1", "resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz", @@ -13184,10 +13203,13 @@ } }, "node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true, + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { "uuid": "dist/bin/uuid" } diff --git a/package.json b/package.json index 9c0c164ca..7fe4393bd 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@ng-apimock/core": "^3.11.0", "@ngxs/store": "^3.8.1", "@sovity.de/broker-server-client": "0.20230712.71619-main-a4860cff", - "@sovity.de/edc-client": "0.20230830.155424-main-b314d7e2", + "@sovity.de/edc-client": "0.20230919.111550-main-118ea199", "clean-deep": "^3.4.0", "date-fns": "^2.30.0", "dotenv": "^16.3.1", diff --git a/src/app/core/services/api/edc-api.service.ts b/src/app/core/services/api/edc-api.service.ts index b43450612..bf6282bcd 100644 --- a/src/app/core/services/api/edc-api.service.ts +++ b/src/app/core/services/api/edc-api.service.ts @@ -15,6 +15,7 @@ import { PolicyDefinitionCreateRequest, PolicyDefinitionPage, TransferHistoryPage, + UiAssetCreateRequest, buildEdcClient, } from '@sovity.de/edc-client'; import {APP_CONFIG, AppConfig} from '../../config/app-config'; @@ -35,9 +36,9 @@ export class EdcApiService { } createAsset( - assetCreateRequest: AssetCreateRequest, + uiAssetCreateRequest: UiAssetCreateRequest, ): Observable { - return from(this.edcClient.uiApi.createAsset({assetCreateRequest})); + return from(this.edcClient.uiApi.createAsset({uiAssetCreateRequest})); } getAssetPage(): Observable { diff --git a/src/app/core/services/api/fake-backend/asset-fake-service.ts b/src/app/core/services/api/fake-backend/asset-fake-service.ts index 8e062ee34..21fe672ae 100644 --- a/src/app/core/services/api/fake-backend/asset-fake-service.ts +++ b/src/app/core/services/api/fake-backend/asset-fake-service.ts @@ -1,13 +1,12 @@ import { - AssetCreateRequest, - AssetEntry, AssetPage, IdResponseDto, + UiAsset, + UiAssetCreateRequest, } from '@sovity.de/edc-client'; -import {AssetProperties} from '../../asset-properties'; import {TestAssets} from './data/test-assets'; -export let assets: AssetEntry[] = [TestAssets.full, TestAssets.boring]; +export let assets: UiAsset[] = [TestAssets.full, TestAssets.boring]; export const assetPage = (): AssetPage => { return { @@ -15,18 +14,33 @@ export const assetPage = (): AssetPage => { }; }; -export const createAsset = (asset: AssetCreateRequest): IdResponseDto => { +export const createAsset = (asset: UiAssetCreateRequest): IdResponseDto => { assets.push({ - properties: asset.properties, + assetId: asset.id, + name: asset.name, + description: asset.description, + creatorOrganizationName: asset.creatorOrganizationName, + publisherHomepage: asset.publisherHomepage, + licenseUrl: asset.licenseUrl, + version: asset.version, + keywords: asset.keywords, + mediaType: asset.mediaType, + landingPageUrl: asset.landingPageUrl, + dataCategory: asset.dataCategory, + dataSubcategory: asset.dataSubcategory, + dataModel: asset.dataModel, + geoReferenceMethod: asset.geoReferenceMethod, + transportMode: asset.transportMode, + additionalProperties: asset.additionalProperties, privateProperties: asset.privateProperties, }); return { - id: asset.properties[AssetProperties.id], + id: asset.id, lastUpdatedDate: new Date(), }; }; export const deleteAsset = (id: string): IdResponseDto => { - assets = assets.filter((it) => it.properties[AssetProperties.id] !== id); + assets = assets.filter((it) => it.assetId !== id); return {id, lastUpdatedDate: new Date()}; }; diff --git a/src/app/core/services/api/fake-backend/data/test-assets.ts b/src/app/core/services/api/fake-backend/data/test-assets.ts index 054f790c6..637136c76 100644 --- a/src/app/core/services/api/fake-backend/data/test-assets.ts +++ b/src/app/core/services/api/fake-backend/data/test-assets.ts @@ -1,8 +1,8 @@ -import {AssetDto, AssetEntry} from '@sovity.de/edc-client'; +import {AssetDto, AssetEntry, UiAsset} from '@sovity.de/edc-client'; import {AssetProperties} from '../../../asset-properties'; export namespace TestAssets { - export const boring: AssetEntry = { + export const boring: UiAsset = { properties: { [AssetProperties.id]: 'test-asset-1', [AssetProperties.name]: 'Test Asset 1', @@ -13,45 +13,42 @@ export namespace TestAssets { }, }; - export const full: AssetEntry = { - properties: { - [AssetProperties.id]: 'urn:artifact:my-test-asset-4', - [AssetProperties.name]: 'Rail Network 2023 NRW - RailDesigner Export', - [AssetProperties.version]: '1.1', - [AssetProperties.originatorOrganization]: 'Deutsche Bahn AG', - [AssetProperties.keywords]: 'db, bahn, rail, Rail-Designer', - [AssetProperties.contentType]: 'application/json', - [AssetProperties.description]: - 'Train Network Map released on 10.01.2023, valid until 31.02.2023. \nFile format is xyz as exported by Rail-Designer.', - [AssetProperties.language]: 'https://w3id.org/idsa/code/EN', - [AssetProperties.publisher]: 'https://my.cool-api.gg/about', - [AssetProperties.standardLicense]: 'https://my.cool-api.gg/license', - [AssetProperties.endpointDocumentation]: 'https://my.cool-api.gg/docs', - [AssetProperties.dataCategory]: 'Infrastructure and Logistics', - [AssetProperties.dataSubcategory]: - 'General Information About Planning Of Routes', - [AssetProperties.dataModel]: 'my-data-model-001', - [AssetProperties.geoReferenceMethod]: 'my-geo-reference-method', - [AssetProperties.transportMode]: 'Rail', - 'asset:prop:some-unsupported-property': - 'F10E2821BBBEA527EA02200352313BC059445190', - }, + export const full: UiAsset = { + [AssetProperties.id]: 'urn:artifact:my-test-asset-4', + [AssetProperties.name]: 'Rail Network 2023 NRW - RailDesigner Export', + [AssetProperties.version]: '1.1', + [AssetProperties.originatorOrganization]: 'Deutsche Bahn AG', + [AssetProperties.keywords]: 'db, bahn, rail, Rail-Designer', + [AssetProperties.contentType]: 'application/json', + [AssetProperties.description]: + 'Train Network Map released on 10.01.2023, valid until 31.02.2023. \nFile format is xyz as exported by Rail-Designer.', + [AssetProperties.language]: 'https://w3id.org/idsa/code/EN', + [AssetProperties.publisher]: 'https://my.cool-api.gg/about', + [AssetProperties.standardLicense]: 'https://my.cool-api.gg/license', + [AssetProperties.endpointDocumentation]: 'https://my.cool-api.gg/docs', + [AssetProperties.dataCategory]: 'Infrastructure and Logistics', + [AssetProperties.dataSubcategory]: + 'General Information About Planning Of Routes', + [AssetProperties.dataModel]: 'my-data-model-001', + [AssetProperties.geoReferenceMethod]: 'my-geo-reference-method', + [AssetProperties.transportMode]: 'Rail', + additionalProperties: {}, privateProperties: {}, }; - export function toAssetDto(entry: AssetEntry): AssetDto { + export function toAssetDto(entry: UiAsset): AssetDto { return { - assetId: entry.properties[AssetProperties.id], + assetId: entry.assetId, createdAt: new Date(), properties: entry.properties, }; } - export function toDummyAsset(entry: AssetEntry): AssetEntry { - return dummyAsset(entry.properties[AssetProperties.id]); + export function toDummyAsset(entry: UiAsset): UiAsset { + return dummyAsset(entry.assetId[AssetProperties.id]); } - export function dummyAsset(assetId: string): AssetEntry { + export function dummyAsset(assetId: string): UiAsset { return { properties: { [AssetProperties.id]: assetId, diff --git a/src/app/core/services/asset-entry-builder.ts b/src/app/core/services/asset-entry-builder.ts index 1561b158f..e1da51c3f 100644 --- a/src/app/core/services/asset-entry-builder.ts +++ b/src/app/core/services/asset-entry-builder.ts @@ -1,28 +1,67 @@ -import {Injectable} from '@angular/core'; -import {AssetCreateRequest} from '@sovity.de/edc-client'; +import {Inject, Injectable} from '@angular/core'; +import {UiAssetCreateRequest} from '@sovity.de/edc-client'; import {AssetEditorDialogFormValue} from '../../routes/connector-ui/asset-page/asset-create-dialog/asset-editor-dialog-form-model'; -import {AssetPropertyMapper} from './asset-property-mapper'; +import {APP_CONFIG, AppConfig} from '../config/app-config'; import {DataAddressMapper} from './data-address-mapper'; @Injectable() export class AssetEntryBuilder { constructor( - private assetPropertyMapper: AssetPropertyMapper, + @Inject(APP_CONFIG) private config: AppConfig, private dataAddressMapper: DataAddressMapper, ) {} /** - * Build {@link AssetCreateRequest} from {@link AssetEditorDialogFormValue} + * Build {@link UiAssetCreateRequest} from {@link AssetEditorDialogFormValue} * * @param formValue form value * @return asset create dto */ buildAssetCreateRequest( formValue: AssetEditorDialogFormValue, - ): AssetCreateRequest { - let properties = this.assetPropertyMapper.buildProperties(formValue); + ): UiAssetCreateRequest { + let id = formValue.metadata?.id ?? 'no-id-was-set'; + let name = formValue.metadata?.name; + let version = formValue.metadata?.version; + let description = formValue.metadata?.description; + let language = formValue.metadata?.language?.id; + let keywords = formValue.metadata?.keywords; + let licenseUrl = formValue.metadata?.standardLicense; + let creatorOrganizationName = this.config.curatorOrganizationName; + let publisherHomepage = formValue.metadata?.publisher; + let mediaType = formValue.metadata?.contentType; + + let dataCategory = formValue.advanced?.dataModel; + let dataSubcategory = formValue.advanced?.dataSubcategory?.id; + let transportMode = formValue.advanced?.transportMode?.id; + let geoReferenceMethod = formValue.advanced?.geoReferenceMethod; + let dataModel = formValue.advanced?.dataModel; + + let landingPageUrl = formValue.datasource?.httpUrl; + const dataAddressProperties = this.dataAddressMapper.buildDataAddressProperties(formValue.datasource); - return {properties, dataAddressProperties, privateProperties: {}}; + return { + id, + name, + language, + description, + creatorOrganizationName, + publisherHomepage, + licenseUrl, + version, + keywords, + mediaType, + landingPageUrl, + dataCategory, + dataSubcategory, + dataModel, + geoReferenceMethod, + transportMode, + dataAddressProperties, + additionalProperties: {}, + privateProperties: {}, + additionalJsonProperties: {}, + }; } } diff --git a/src/app/routes/connector-ui/asset-page/asset-create-dialog/asset-create-dialog.component.ts b/src/app/routes/connector-ui/asset-page/asset-create-dialog/asset-create-dialog.component.ts index 71a6966ed..b3542a0fa 100644 --- a/src/app/routes/connector-ui/asset-page/asset-create-dialog/asset-create-dialog.component.ts +++ b/src/app/routes/connector-ui/asset-page/asset-create-dialog/asset-create-dialog.component.ts @@ -39,13 +39,13 @@ export class AssetCreateDialogComponent implements OnDestroy { onSave() { const formValue = this.form.value; - const assetEntry = + const uiAssetCreateRequest = this.assetEntryBuilder.buildAssetCreateRequest(formValue); this.form.all.disable(); this.loading = true; this.edcApiService - .createAsset(assetEntry) + .createAsset(uiAssetCreateRequest) .pipe( takeUntil(this.ngOnDestroy$), finalize(() => { From 479336634220a5f0a8c9559ac2f8a15fb78c0862 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Wed, 20 Sep 2023 14:31:45 +0200 Subject: [PATCH 2/9] chore: use UI-safe Criterion --- package-lock.json | 8 +-- package.json | 2 +- .../core/services/api/criterion-type-ext.ts | 11 +++ src/app/core/services/api/edc-api.service.ts | 10 ++- .../api/fake-backend/asset-fake-service.ts | 10 +-- .../api/fake-backend/data/test-assets.ts | 71 ++++++++----------- .../api/fake-backend/edc-fake-backend.ts | 4 +- .../services/contract-definition-builder.ts | 4 +- .../contract-definition-card-builder.ts | 10 +-- 9 files changed, 69 insertions(+), 61 deletions(-) create mode 100644 src/app/core/services/api/criterion-type-ext.ts diff --git a/package-lock.json b/package-lock.json index a4e976ea1..f73ba308b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "@ng-apimock/core": "^3.11.0", "@ngxs/store": "^3.8.1", "@sovity.de/broker-server-client": "0.20230712.71619-main-a4860cff", - "@sovity.de/edc-client": "0.20230830.155424-main-b314d7e2", + "@sovity.de/edc-client": "0.20230919.111550-main-118ea199", "clean-deep": "^3.4.0", "date-fns": "^2.30.0", "dotenv": "^16.3.1", @@ -3598,9 +3598,9 @@ "integrity": "sha512-305vHJj38Ma9x9YADM3SJh3sdqePeLcrUB1hHlYsuPdx7wYe9vwgb503KYStJ+5iN/ojP2xu8k6Unt+y+Bu5iQ==" }, "node_modules/@sovity.de/edc-client": { - "version": "0.20230830.155424-main-b314d7e2", - "resolved": "https://registry.npmjs.org/@sovity.de/edc-client/-/edc-client-0.20230830.155424-main-b314d7e2.tgz", - "integrity": "sha512-kOx2ZclD3rfhq/hC+9bKVAQRQh8vtWbcp4u3DI4X9chR5/euB41UlJQ1E8vokPkGdEeVmjMTwVOuXwpLRWJj7g==" + "version": "0.20230919.111550-main-118ea199", + "resolved": "https://registry.npmjs.org/@sovity.de/edc-client/-/edc-client-0.20230919.111550-main-118ea199.tgz", + "integrity": "sha512-Q0VlZUzwk/0PaYpUug+Asq1bBokQ9E1LceGNCWxS9CzOvukB1rIMg1x+SQqNtoEXXRqBE0WW6eI8B8RMN8ClNQ==" }, "node_modules/@tootallnate/once": { "version": "2.0.0", diff --git a/package.json b/package.json index 9c0c164ca..7fe4393bd 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@ng-apimock/core": "^3.11.0", "@ngxs/store": "^3.8.1", "@sovity.de/broker-server-client": "0.20230712.71619-main-a4860cff", - "@sovity.de/edc-client": "0.20230830.155424-main-b314d7e2", + "@sovity.de/edc-client": "0.20230919.111550-main-118ea199", "clean-deep": "^3.4.0", "date-fns": "^2.30.0", "dotenv": "^16.3.1", diff --git a/src/app/core/services/api/criterion-type-ext.ts b/src/app/core/services/api/criterion-type-ext.ts new file mode 100644 index 000000000..c305dab14 --- /dev/null +++ b/src/app/core/services/api/criterion-type-ext.ts @@ -0,0 +1,11 @@ +import {UiCriterionOperatorEnum} from '@sovity.de/edc-client'; + +export type UiCriterionOperator = + | UiCriterionOperatorEnum + | UiCriterionOperatorEnum; + +export const CRITERION_OPERATOR_SYMBOLS: Record = { + EQ: '=', + IN: 'in', + LIKE: 'like', +}; diff --git a/src/app/core/services/api/edc-api.service.ts b/src/app/core/services/api/edc-api.service.ts index b43450612..c2337a11e 100644 --- a/src/app/core/services/api/edc-api.service.ts +++ b/src/app/core/services/api/edc-api.service.ts @@ -1,7 +1,6 @@ import {Inject, Injectable} from '@angular/core'; import {Observable, from} from 'rxjs'; import { - AssetCreateRequest, AssetDto, AssetPage, ConnectorLimits, @@ -15,6 +14,7 @@ import { PolicyDefinitionCreateRequest, PolicyDefinitionPage, TransferHistoryPage, + UiAssetCreateRequest, buildEdcClient, } from '@sovity.de/edc-client'; import {APP_CONFIG, AppConfig} from '../../config/app-config'; @@ -35,9 +35,13 @@ export class EdcApiService { } createAsset( - assetCreateRequest: AssetCreateRequest, + uiAssetCreateRequest: UiAssetCreateRequest, ): Observable { - return from(this.edcClient.uiApi.createAsset({assetCreateRequest})); + return from( + this.edcClient.uiApi.createAsset({ + uiAssetCreateRequest, + }), + ); } getAssetPage(): Observable { diff --git a/src/app/core/services/api/fake-backend/asset-fake-service.ts b/src/app/core/services/api/fake-backend/asset-fake-service.ts index 8e062ee34..892bb36aa 100644 --- a/src/app/core/services/api/fake-backend/asset-fake-service.ts +++ b/src/app/core/services/api/fake-backend/asset-fake-service.ts @@ -1,13 +1,13 @@ import { - AssetCreateRequest, - AssetEntry, AssetPage, IdResponseDto, + UiAsset, + UiAssetCreateRequest, } from '@sovity.de/edc-client'; import {AssetProperties} from '../../asset-properties'; import {TestAssets} from './data/test-assets'; -export let assets: AssetEntry[] = [TestAssets.full, TestAssets.boring]; +export let assets: UiAsset[] = [TestAssets.full, TestAssets.boring]; export const assetPage = (): AssetPage => { return { @@ -15,8 +15,10 @@ export const assetPage = (): AssetPage => { }; }; -export const createAsset = (asset: AssetCreateRequest): IdResponseDto => { +export const createAsset = (asset: UiAssetCreateRequest): IdResponseDto => { assets.push({ + assetId: asset.assetId, + properties: asset.properties, privateProperties: asset.privateProperties, }); diff --git a/src/app/core/services/api/fake-backend/data/test-assets.ts b/src/app/core/services/api/fake-backend/data/test-assets.ts index 054f790c6..563cc26a2 100644 --- a/src/app/core/services/api/fake-backend/data/test-assets.ts +++ b/src/app/core/services/api/fake-backend/data/test-assets.ts @@ -1,61 +1,52 @@ -import {AssetDto, AssetEntry} from '@sovity.de/edc-client'; -import {AssetProperties} from '../../../asset-properties'; +import {AssetDto, UiAsset} from '@sovity.de/edc-client'; export namespace TestAssets { - export const boring: AssetEntry = { - properties: { - [AssetProperties.id]: 'test-asset-1', - [AssetProperties.name]: 'Test Asset 1', - [AssetProperties.description]: 'This is a test asset.', - }, + export const boring: UiAsset = { + assetId: 'my-test-asset-1', + name: 'Test Asset 1', + description: 'This is a test asset.', privateProperties: { 'some-private-property': 'abc', }, }; - export const full: AssetEntry = { - properties: { - [AssetProperties.id]: 'urn:artifact:my-test-asset-4', - [AssetProperties.name]: 'Rail Network 2023 NRW - RailDesigner Export', - [AssetProperties.version]: '1.1', - [AssetProperties.originatorOrganization]: 'Deutsche Bahn AG', - [AssetProperties.keywords]: 'db, bahn, rail, Rail-Designer', - [AssetProperties.contentType]: 'application/json', - [AssetProperties.description]: - 'Train Network Map released on 10.01.2023, valid until 31.02.2023. \nFile format is xyz as exported by Rail-Designer.', - [AssetProperties.language]: 'https://w3id.org/idsa/code/EN', - [AssetProperties.publisher]: 'https://my.cool-api.gg/about', - [AssetProperties.standardLicense]: 'https://my.cool-api.gg/license', - [AssetProperties.endpointDocumentation]: 'https://my.cool-api.gg/docs', - [AssetProperties.dataCategory]: 'Infrastructure and Logistics', - [AssetProperties.dataSubcategory]: - 'General Information About Planning Of Routes', - [AssetProperties.dataModel]: 'my-data-model-001', - [AssetProperties.geoReferenceMethod]: 'my-geo-reference-method', - [AssetProperties.transportMode]: 'Rail', - 'asset:prop:some-unsupported-property': - 'F10E2821BBBEA527EA02200352313BC059445190', - }, + export const full: UiAsset = { + assetId: 'urn:artifact:my-test-asset-2', + name: 'Rail Network 2023 NRW - RailDesigner Export', + version: '1.1', + creatorOrganizationName: 'Deutsche Bahn AG', + keywords: ['db', 'bahn', 'rail', 'Rail-Designer'], + mediaType: 'application/json', + description: + 'Train Network Map released on 10.01.2023, valid until 31.02.2023. \nFile format is xyz as exported by Rail-Designer.', + language: 'https://w3id.org/idsa/code/EN', + publisherHomepage: 'https://my.cool-api.gg/about', + licenseUrl: 'https://my.cool-api.gg/license', + landingPageUrl: 'https://my.cool-api.gg/docs', + dataCategory: 'Infrastructure and Logistics', + dataSubcategory: 'General Information About Planning Of Routes', + dataModel: 'my-data-model-001', + geoReferenceMethod: 'my-geo-reference-method', + transportMode: 'Rail', + privateProperties: {}, }; - export function toAssetDto(entry: AssetEntry): AssetDto { + export function toAssetDto(entry: UiAsset): AssetDto { return { - assetId: entry.properties[AssetProperties.id], + assetId: entry.assetId, createdAt: new Date(), - properties: entry.properties, + properties: {}, }; } - export function toDummyAsset(entry: AssetEntry): AssetEntry { - return dummyAsset(entry.properties[AssetProperties.id]); + export function toDummyAsset(entry: UiAsset): UiAsset { + return dummyAsset(entry.assetId); } - export function dummyAsset(assetId: string): AssetEntry { + export function dummyAsset(assetId: string): UiAsset { return { - properties: { - [AssetProperties.id]: assetId, - }, + assetId, privateProperties: {}, }; } diff --git a/src/app/core/services/api/fake-backend/edc-fake-backend.ts b/src/app/core/services/api/fake-backend/edc-fake-backend.ts index 70563ba20..4c4b46b1f 100644 --- a/src/app/core/services/api/fake-backend/edc-fake-backend.ts +++ b/src/app/core/services/api/fake-backend/edc-fake-backend.ts @@ -1,5 +1,4 @@ import { - AssetCreateRequestFromJSON, AssetDtoToJSON, AssetPageToJSON, ContractAgreementPageToJSON, @@ -11,6 +10,7 @@ import { PolicyDefinitionCreateRequestFromJSON, PolicyDefinitionPageToJSON, TransferHistoryPageToJSON, + UiAssetCreateRequestFromJSON, } from '@sovity.de/edc-client'; import {assetPage, createAsset, deleteAsset} from './asset-fake-service'; import { @@ -55,7 +55,7 @@ export const EDC_FAKE_BACKEND: FetchAPI = async ( .url('pages/asset-page/assets') .on('POST', () => { - let createRequest = AssetCreateRequestFromJSON(body); + let createRequest = UiAssetCreateRequestFromJSON(body); let created = createAsset(createRequest); return ok(IdResponseDtoToJSON(created)); }) diff --git a/src/app/core/services/contract-definition-builder.ts b/src/app/core/services/contract-definition-builder.ts index 48f4bc1ef..7971b7c5b 100644 --- a/src/app/core/services/contract-definition-builder.ts +++ b/src/app/core/services/contract-definition-builder.ts @@ -1,7 +1,7 @@ import {Injectable} from '@angular/core'; import { ContractDefinitionRequest, - UiCriterionLiteralDtoTypeEnum, + UiCriterionLiteralTypeEnum, } from '@sovity.de/edc-client'; import {ContractDefinitionEditorDialogFormValue} from '../../routes/connector-ui/contract-definition-page/contract-definition-editor-dialog/contract-definition-editor-dialog-form-model'; import {AssetProperties} from './asset-properties'; @@ -28,7 +28,7 @@ export class ContractDefinitionBuilder { operandLeft: AssetProperties.id, operator: 'IN', operandRight: { - type: UiCriterionLiteralDtoTypeEnum.ValueList, + type: UiCriterionLiteralTypeEnum.ValueList, valueList: formValue.assets!.map((it) => it.id), }, }, diff --git a/src/app/routes/connector-ui/contract-definition-page/contract-definition-cards/contract-definition-card-builder.ts b/src/app/routes/connector-ui/contract-definition-page/contract-definition-cards/contract-definition-card-builder.ts index fff2eb7b9..9b1a857b1 100644 --- a/src/app/routes/connector-ui/contract-definition-page/contract-definition-cards/contract-definition-card-builder.ts +++ b/src/app/routes/connector-ui/contract-definition-page/contract-definition-cards/contract-definition-card-builder.ts @@ -3,9 +3,9 @@ import { ContractDefinitionEntry, ContractDefinitionPage, PolicyDefinitionDto, - UiCriterionDto, + UiCriterion, } from '@sovity.de/edc-client'; -import {OPERATOR_SYMBOLS} from '../../../../core/services/api/policy-type-ext'; +import {CRITERION_OPERATOR_SYMBOLS} from '../../../../core/services/api/criterion-type-ext'; import {AssetProperties} from '../../../../core/services/asset-properties'; import {Asset} from '../../../../core/services/models/asset'; import {associateBy} from '../../../../core/utils/map-utils'; @@ -73,7 +73,7 @@ export class ContractDefinitionCardBuilder { }; } - private extractCriterionOperation(criterion: UiCriterionDto): string { + private extractCriterionOperation(criterion: UiCriterion): string { const {operandLeft, operator} = criterion; if ( operandLeft.toLowerCase() === AssetProperties.id.toLowerCase() && @@ -82,12 +82,12 @@ export class ContractDefinitionCardBuilder { return 'Assets'; } - let operatorStr = OPERATOR_SYMBOLS[operator] ?? operator; + let operatorStr = CRITERION_OPERATOR_SYMBOLS[operator] ?? operator; return `${operandLeft} ${operatorStr}`; } private extractCriterionValues( - criterion: UiCriterionDto, + criterion: UiCriterion, assetsById: Map, ): ContractDefinitionCardCriterionValue[] { let {operandLeft, operandRight} = criterion; From d015c9da34ca67b80bd0a1b6fae5b6d8d59b7be7 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Wed, 20 Sep 2023 16:52:31 +0200 Subject: [PATCH 3/9] chore: use UI-safe Criterion && update UiCriterion --- .../services/api/contract-offer.service.ts | 2 +- .../api/fake-backend/data/test-assets.ts | 52 +++--- .../api/fake-backend/data/test-policies.ts | 8 +- .../transfer-history-fake-service.ts | 11 +- .../core/services/asset-property-mapper.ts | 155 +++++++++++++----- src/app/core/services/asset-service-mapped.ts | 2 +- .../services/models/contract-offer-dto.ts | 4 +- .../mapping/broker-catalog-mapper.ts | 2 +- .../contract-agreement-card-mapped.service.ts | 2 +- .../transfer-history-page.component.ts | 2 +- 10 files changed, 149 insertions(+), 91 deletions(-) diff --git a/src/app/core/services/api/contract-offer.service.ts b/src/app/core/services/api/contract-offer.service.ts index e486c3e35..f4235c3c3 100644 --- a/src/app/core/services/api/contract-offer.service.ts +++ b/src/app/core/services/api/contract-offer.service.ts @@ -61,7 +61,7 @@ export class ContractOfferService { ...contractOfferDto, asset: this.assetPropertyMapper.buildAsset({ connectorEndpoint, - properties: contractOfferDto.asset.properties, + asset: contractOfferDto.asset, }), }; } diff --git a/src/app/core/services/api/fake-backend/data/test-assets.ts b/src/app/core/services/api/fake-backend/data/test-assets.ts index 637136c76..df968ee71 100644 --- a/src/app/core/services/api/fake-backend/data/test-assets.ts +++ b/src/app/core/services/api/fake-backend/data/test-assets.ts @@ -1,37 +1,33 @@ -import {AssetDto, AssetEntry, UiAsset} from '@sovity.de/edc-client'; -import {AssetProperties} from '../../../asset-properties'; +import {AssetDto, UiAsset} from '@sovity.de/edc-client'; export namespace TestAssets { export const boring: UiAsset = { - properties: { - [AssetProperties.id]: 'test-asset-1', - [AssetProperties.name]: 'Test Asset 1', - [AssetProperties.description]: 'This is a test asset.', - }, + assetId: 'test-asset-1', + name: 'Test Asset 1', + description: 'This is a test asset.', privateProperties: { 'some-private-property': 'abc', }, }; export const full: UiAsset = { - [AssetProperties.id]: 'urn:artifact:my-test-asset-4', - [AssetProperties.name]: 'Rail Network 2023 NRW - RailDesigner Export', - [AssetProperties.version]: '1.1', - [AssetProperties.originatorOrganization]: 'Deutsche Bahn AG', - [AssetProperties.keywords]: 'db, bahn, rail, Rail-Designer', - [AssetProperties.contentType]: 'application/json', - [AssetProperties.description]: + assetId: 'urn:artifact:my-test-asset-4', + name: 'Rail Network 2023 NRW - RailDesigner Export', + version: '1.1', + creatorOrganizationName: 'Deutsche Bahn AG', + keywords: ['db', 'bahn', 'rail', 'Rail-Designer'], + mediaType: 'application/json', + description: 'Train Network Map released on 10.01.2023, valid until 31.02.2023. \nFile format is xyz as exported by Rail-Designer.', - [AssetProperties.language]: 'https://w3id.org/idsa/code/EN', - [AssetProperties.publisher]: 'https://my.cool-api.gg/about', - [AssetProperties.standardLicense]: 'https://my.cool-api.gg/license', - [AssetProperties.endpointDocumentation]: 'https://my.cool-api.gg/docs', - [AssetProperties.dataCategory]: 'Infrastructure and Logistics', - [AssetProperties.dataSubcategory]: - 'General Information About Planning Of Routes', - [AssetProperties.dataModel]: 'my-data-model-001', - [AssetProperties.geoReferenceMethod]: 'my-geo-reference-method', - [AssetProperties.transportMode]: 'Rail', + language: 'https://w3id.org/idsa/code/EN', + publisherHomepage: 'https://my.cool-api.gg/about', + licenseUrl: 'https://my.cool-api.gg/license', + landingPageUrl: 'https://my.cool-api.gg/docs', + dataCategory: 'Infrastructure and Logistics', + dataSubcategory: 'General Information About Planning Of Routes', + dataModel: 'my-data-model-001', + geoReferenceMethod: 'my-geo-reference-method', + transportMode: 'Rail', additionalProperties: {}, privateProperties: {}, }; @@ -40,19 +36,17 @@ export namespace TestAssets { return { assetId: entry.assetId, createdAt: new Date(), - properties: entry.properties, + properties: {}, }; } export function toDummyAsset(entry: UiAsset): UiAsset { - return dummyAsset(entry.assetId[AssetProperties.id]); + return dummyAsset(entry.assetId); } export function dummyAsset(assetId: string): UiAsset { return { - properties: { - [AssetProperties.id]: assetId, - }, + assetId, privateProperties: {}, }; } diff --git a/src/app/core/services/api/fake-backend/data/test-policies.ts b/src/app/core/services/api/fake-backend/data/test-policies.ts index 08dfee54b..97e2ddf53 100644 --- a/src/app/core/services/api/fake-backend/data/test-policies.ts +++ b/src/app/core/services/api/fake-backend/data/test-policies.ts @@ -1,7 +1,7 @@ -import {UiPolicyDto} from '@sovity.de/edc-client'; +import {UiPolicy} from '@sovity.de/edc-client'; export namespace TestPolicies { - export const connectorRestricted: UiPolicyDto = { + export const connectorRestricted: UiPolicy = { policyJsonLd: '{"example-policy-jsonld": true}', constraints: [ { @@ -13,7 +13,7 @@ export namespace TestPolicies { errors: [], }; - export const warnings: UiPolicyDto = { + export const warnings: UiPolicy = { policyJsonLd: '{"example-policy-jsonld": true}', constraints: [ { @@ -24,7 +24,7 @@ export namespace TestPolicies { ], errors: ['$.duties: Duties are currently unsupported.'], }; - export const failedMapping: UiPolicyDto = { + export const failedMapping: UiPolicy = { policyJsonLd: '{"example-policy-jsonld": true}', constraints: [], errors: ['No constraints found!'], diff --git a/src/app/core/services/api/fake-backend/transfer-history-fake-service.ts b/src/app/core/services/api/fake-backend/transfer-history-fake-service.ts index 09532dbca..37cc92b61 100644 --- a/src/app/core/services/api/fake-backend/transfer-history-fake-service.ts +++ b/src/app/core/services/api/fake-backend/transfer-history-fake-service.ts @@ -3,7 +3,6 @@ import { TransferHistoryEntry, TransferHistoryPage, } from '@sovity.de/edc-client'; -import {AssetProperties} from '../../asset-properties'; import {assets} from './asset-fake-service'; import {TestAssets} from './data/test-assets'; @@ -67,8 +66,10 @@ export let transferHistoryEntries: TransferHistoryEntry[] = [ contractAgreementId: 'test-asset-4-cd:f52a5d30-6356-4a55-a75a-3c45d7a88c3e', direction: 'PROVIDING', counterPartyConnectorEndpoint: 'https://sovity-demo2-edc/api/v1/ids/data', - assetName: TestAssets.full.properties[AssetProperties.name], - assetId: TestAssets.full.properties[AssetProperties.id], + assetName: TestAssets.full.name + ? TestAssets.full.name + : TestAssets.full.assetId, + assetId: TestAssets.full.assetId, }, ]; @@ -89,9 +90,7 @@ export const transferProcessAsset = (transferProcessId: string): AssetDto => { TestAssets.dummyAsset(assetId), ); - const assetEntry = assets.find( - (it) => it.properties[AssetProperties.id] === assetId, - ); + const assetEntry = assets.find((it) => it.assetId === assetId); return isProviding && assetEntry ? TestAssets.toAssetDto(assetEntry) diff --git a/src/app/core/services/asset-property-mapper.ts b/src/app/core/services/asset-property-mapper.ts index 3ff3d3c8b..f853b63b5 100644 --- a/src/app/core/services/asset-property-mapper.ts +++ b/src/app/core/services/asset-property-mapper.ts @@ -1,4 +1,5 @@ import {Inject, Injectable} from '@angular/core'; +import {UiAsset} from '@sovity.de/edc-client'; import {AssetEditorDialogFormValue} from '../../routes/connector-ui/asset-page/asset-create-dialog/asset-editor-dialog-form-model'; import {DataCategorySelectItemService} from '../../routes/connector-ui/asset-page/data-category-select/data-category-select-item.service'; import {DataSubcategorySelectItemService} from '../../routes/connector-ui/asset-page/data-subcategory-select/data-subcategory-select-item.service'; @@ -27,76 +28,133 @@ export class AssetPropertyMapper { private activeFeatureSet: ActiveFeatureSet, ) {} - buildAsset(opts: { - connectorEndpoint: string; - properties: Record; - }): Asset { - const props = opts.properties; - const lookup = (key: string, fn: (id: string) => T) => - props[key] ? fn(props[key]!) : null; + buildAsset(opts: {connectorEndpoint: string; asset: UiAsset}): Asset { + const asset = opts.asset; - const language = lookup(AssetProperties.language, (id) => - this.languageSelectItemService.findById(id), - ); - const dataCategory = lookup(AssetProperties.dataCategory, (id) => - this.dataCategorySelectItemService.findById(id), - ); - const dataSubcategory = lookup(AssetProperties.dataSubcategory, (id) => - this.dataSubcategorySelectItemService.findById(id), - ); - const transportMode = lookup(AssetProperties.transportMode, (id) => - this.transportModeSelectItemService.findById(id), - ); - const keywords = (props[AssetProperties.keywords] ?? '') - .split(',') - .map((it) => it.trim()) - .filter((it) => it); + const language = asset.language + ? this.languageSelectItemService.findById(asset.language) + : null; + const dataCategory = asset.dataCategory + ? this.dataCategorySelectItemService.findById(asset.dataCategory) + : null; + const dataSubcategory = asset.dataSubcategory + ? this.dataSubcategorySelectItemService.findById(asset.dataSubcategory) + : null; + const transportMode = asset.transportMode + ? this.transportModeSelectItemService.findById(asset.transportMode) + : null; - const id = props[AssetProperties.id] ?? 'no-id-was-set'; - const additionalProperties = this.buildAdditionalProperties(props); + const keywords = asset.keywords ?? []; + + const id = asset.assetId ?? 'no-id-was-set'; + const additionalProperties = this.buildAdditionalProperties( + asset.additionalProperties, + ); return { id, - name: props[AssetProperties.name] ?? id, - version: props[AssetProperties.version], - contentType: props[AssetProperties.contentType], + name: asset.name ?? id, + version: asset.version ?? null, + contentType: asset.mediaType ?? null, originator: opts.connectorEndpoint, originatorOrganization: - props[AssetProperties.curatorOrganizationName] ?? - 'Unknown Organization', + asset.creatorOrganizationName ?? 'Unknown Organization', keywords, - description: props[AssetProperties.description], + description: trimmedOrNull(asset.description), language, - publisher: props[AssetProperties.publisher], - standardLicense: props[AssetProperties.standardLicense], - endpointDocumentation: props[AssetProperties.endpointDocumentation], + publisher: asset.publisherHomepage ?? null, + standardLicense: asset.licenseUrl ?? null, + endpointDocumentation: asset.landingPageUrl ?? null, dataCategory, dataSubcategory, - dataModel: props[AssetProperties.dataModel], - geoReferenceMethod: props[AssetProperties.geoReferenceMethod], + dataModel: asset.dataModel ?? null, + geoReferenceMethod: asset.geoReferenceMethod ?? null, transportMode, - httpProxyMethod: this._parseBoolean( + httpProxyMethod: this._parseBoolean(asset.httpDatasourceHintsProxyMethod), + httpProxyPath: this._parseBoolean(asset.httpDatasourceHintsProxyPath), + httpProxyQueryParams: this._parseBoolean( + asset.httpDatasourceHintsProxyBody, + ), + httpProxyBody: this._parseBoolean(asset.httpDatasourceHintsProxyBody), + additionalProperties, + }; + } + + buildUiAssetfromprops(props: Record): UiAsset { + return { + assetId: props[AssetProperties.id] ?? '', + name: props[AssetProperties.name] ?? '', + version: props[AssetProperties.version] ?? '', + creatorOrganizationName: + props[AssetProperties.curatorOrganizationName] ?? '', + keywords: props[AssetProperties.keywords] + ?.split(',') + .map((it) => it.trim()), + mediaType: props[AssetProperties.contentType] ?? '', + description: props[AssetProperties.description] ?? '', + language: props[AssetProperties.language] ?? '', + publisherHomepage: props[AssetProperties.publisher] ?? '', + licenseUrl: props[AssetProperties.standardLicense] ?? '', + landingPageUrl: props[AssetProperties.endpointDocumentation] ?? '', + dataCategory: props[AssetProperties.dataCategory] ?? '', + dataSubcategory: props[AssetProperties.dataSubcategory] ?? '', + dataModel: props[AssetProperties.dataModel] ?? '', + geoReferenceMethod: props[AssetProperties.geoReferenceMethod] ?? '', + transportMode: props[AssetProperties.transportMode] ?? '', + + httpDatasourceHintsProxyMethod: this._parseBooleanfromString( props[AssetProperties.httpProxyMethod], ), - httpProxyPath: this._parseBoolean(props[AssetProperties.httpProxyPath]), - httpProxyQueryParams: this._parseBoolean( + httpDatasourceHintsProxyPath: this._parseBooleanfromString( + props[AssetProperties.httpProxyPath], + ), + httpDatasourceHintsProxyQueryParams: this._parseBooleanfromString( props[AssetProperties.httpProxyQueryParams], ), - httpProxyBody: this._parseBoolean(props[AssetProperties.httpProxyBody]), - additionalProperties, + httpDatasourceHintsProxyBody: this._parseBooleanfromString( + props[AssetProperties.httpProxyBody], + ), + + additionalProperties: this.buildAdditionalPropertiesforUiAsset(props), }; } - private buildAdditionalProperties(props: Record) { + private buildAdditionalProperties( + props: Record | undefined, + ): Array<{key: string; value: string}> { + if (!props) { + return []; + } + const knownKeys = Object.values(AssetProperties); return Object.entries(props) - .filter(([k, _]) => !knownKeys.includes(k)) + .filter(([k]) => !knownKeys.includes(k)) .map(([key, value]) => ({ key, value: value ?? '', })); } + private buildAdditionalPropertiesforUiAsset( + props: Record | undefined, + ): {[key: string]: string} { + if (!props) { + return {}; + } + + const knownKeys = Object.values(AssetProperties); + const filteredEntries = Object.entries(props).filter( + ([k]) => !knownKeys.includes(k), + ); + + const result: {[key: string]: string} = {}; + for (const [key, value] of filteredEntries) { + result[key] = value ?? ''; + } + + return result; + } + buildProperties( formValue: AssetEditorDialogFormValue, ): Record { @@ -153,10 +211,17 @@ export class AssetPropertyMapper { return removeNullValues(props); } - private _parseBoolean(value: string | null): boolean | null { - if (!value) { + private _parseBoolean(value: boolean | null | undefined): boolean | null { + if (value != true && value != false) { return null; } + return value; + } + + private _parseBooleanfromString(value: string | null): boolean | undefined { + if (!value) { + return undefined; + } return value === 'true'; } diff --git a/src/app/core/services/asset-service-mapped.ts b/src/app/core/services/asset-service-mapped.ts index 1aee8348f..d5ec2cd5c 100644 --- a/src/app/core/services/asset-service-mapped.ts +++ b/src/app/core/services/asset-service-mapped.ts @@ -25,7 +25,7 @@ export class AssetServiceMapped { assetPage.assets.map((asset) => this.assetPropertyMapper.buildAsset({ connectorEndpoint: this.config.connectorEndpoint, - properties: asset.properties, + asset: asset, }), ), ), diff --git a/src/app/core/services/models/contract-offer-dto.ts b/src/app/core/services/models/contract-offer-dto.ts index 7bf30c169..e47bf7901 100644 --- a/src/app/core/services/models/contract-offer-dto.ts +++ b/src/app/core/services/models/contract-offer-dto.ts @@ -1,5 +1,5 @@ +import {UiAsset} from '@sovity.de/edc-client'; import {Policy} from '../api/legacy-managent-api-client'; -import {AssetDto} from './asset-dto'; /** * Contract Offer (API Model) @@ -9,5 +9,5 @@ export interface ContractOfferDto { policy: Policy; provider: string; consumer: string; - asset: AssetDto; + asset: UiAsset; } diff --git a/src/app/routes/broker-ui/catalog-page/catalog-page/mapping/broker-catalog-mapper.ts b/src/app/routes/broker-ui/catalog-page/catalog-page/mapping/broker-catalog-mapper.ts index ae712e881..26fcce85c 100644 --- a/src/app/routes/broker-ui/catalog-page/catalog-page/mapping/broker-catalog-mapper.ts +++ b/src/app/routes/broker-ui/catalog-page/catalog-page/mapping/broker-catalog-mapper.ts @@ -23,7 +23,7 @@ export class BrokerCatalogMapper { ...offer, asset: this.assetPropertyMapper.buildAsset({ connectorEndpoint: offer.connectorEndpoint, - properties: offer.properties, + asset: this.assetPropertyMapper.buildUiAssetfromprops(offer.properties), }), }; } diff --git a/src/app/routes/connector-ui/contract-agreement-page/contract-agreement-cards/contract-agreement-card-mapped.service.ts b/src/app/routes/connector-ui/contract-agreement-page/contract-agreement-cards/contract-agreement-card-mapped.service.ts index 7365af173..17aa5930e 100644 --- a/src/app/routes/connector-ui/contract-agreement-page/contract-agreement-cards/contract-agreement-card-mapped.service.ts +++ b/src/app/routes/connector-ui/contract-agreement-page/contract-agreement-cards/contract-agreement-card-mapped.service.ts @@ -20,7 +20,7 @@ export class ContractAgreementCardMappedService { ): ContractAgreementCardMapped { let asset = this.assetPropertyMapper.buildAsset({ connectorEndpoint: contractAgreement.counterPartyAddress, - properties: contractAgreement.asset.properties, + asset: contractAgreement.asset, }); return { diff --git a/src/app/routes/connector-ui/transfer-history-page/transfer-history-page/transfer-history-page.component.ts b/src/app/routes/connector-ui/transfer-history-page/transfer-history-page/transfer-history-page.component.ts index 695d4b9ab..d43968978 100644 --- a/src/app/routes/connector-ui/transfer-history-page/transfer-history-page/transfer-history-page.component.ts +++ b/src/app/routes/connector-ui/transfer-history-page/transfer-history-page/transfer-history-page.component.ts @@ -65,7 +65,7 @@ export class TransferHistoryPageComponent implements OnInit, OnDestroy { map((asset) => this.assetPropertyMapper.buildAsset({ connectorEndpoint: item.counterPartyConnectorEndpoint, - properties: asset.properties, + asset: asset, }), ), ); From b5d8e9c7a26345a2146e6b3afd8085f9ea71e6a3 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Thu, 21 Sep 2023 15:14:49 +0200 Subject: [PATCH 4/9] chore: use UI-safe Criterion && update UiCriterion --- package-lock.json | 21 +-- package.json | 2 +- .../asset-detail-dialog.component.html | 4 +- .../asset-detail-dialog.component.ts | 8 +- .../asset-property-grid-group-builder.ts | 22 +-- .../contract-offer-cards.component.html | 4 +- .../api/contract-negotiation.service.ts | 8 +- .../services/api/contract-offer.service.ts | 4 +- .../core/services/api/criterion-type-ext.ts | 4 +- src/app/core/services/api/edc-api.service.ts | 4 +- .../api/fake-backend/asset-fake-service.ts | 2 +- .../api/fake-backend/data/test-assets.ts | 14 +- .../api/fake-backend/edc-fake-backend.ts | 4 +- .../transfer-history-fake-service.ts | 10 +- .../core/services/asset-property-mapper.ts | 130 ++++++------------ src/app/core/services/asset-service-mapped.ts | 2 +- .../services/contract-definition-builder.ts | 2 +- .../services/http-params-mapper.service.ts | 12 +- src/app/core/services/models/asset.ts | 43 ++---- src/app/core/utils/search-utils.ts | 2 +- .../mapping/broker-catalog-mapper.ts | 4 +- .../data-offer-cards.component.html | 4 +- .../asset-cards/asset-cards.component.html | 4 +- .../assets-id-validator-builder.ts | 2 +- .../contract-agreement-card-mapped.service.ts | 2 +- ...act-agreement-transfer-dialog.component.ts | 23 ++-- .../contract-definition-card-builder.ts | 2 +- .../transfer-history-page.component.ts | 29 +++- 28 files changed, 159 insertions(+), 213 deletions(-) diff --git a/package-lock.json b/package-lock.json index c69106f6f..b24ec3946 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "@ng-apimock/core": "^3.11.0", "@ngxs/store": "^3.8.1", "@sovity.de/broker-server-client": "0.20230712.71619-main-a4860cff", - "@sovity.de/edc-client": "0.20230919.111550-main-118ea199", + "@sovity.de/edc-client": "0.20230921.115850-main-5e87f14f", "clean-deep": "^3.4.0", "date-fns": "^2.30.0", "dotenv": "^16.3.1", @@ -33,7 +33,6 @@ "rxjs": "7.8.1", "tslib": "^2.6.2", "url-join": "^5.0.0", - "uuid": "^9.0.1", "zone.js": "^0.12.0" }, "devDependencies": { @@ -3608,9 +3607,9 @@ "integrity": "sha512-305vHJj38Ma9x9YADM3SJh3sdqePeLcrUB1hHlYsuPdx7wYe9vwgb503KYStJ+5iN/ojP2xu8k6Unt+y+Bu5iQ==" }, "node_modules/@sovity.de/edc-client": { - "version": "0.20230919.111550-main-118ea199", - "resolved": "https://registry.npmjs.org/@sovity.de/edc-client/-/edc-client-0.20230919.111550-main-118ea199.tgz", - "integrity": "sha512-Q0VlZUzwk/0PaYpUug+Asq1bBokQ9E1LceGNCWxS9CzOvukB1rIMg1x+SQqNtoEXXRqBE0WW6eI8B8RMN8ClNQ==" + "version": "0.20230921.115850-main-5e87f14f", + "resolved": "https://registry.npmjs.org/@sovity.de/edc-client/-/edc-client-0.20230921.115850-main-5e87f14f.tgz", + "integrity": "sha512-G875A/e88tKgsqcZCq6NS4bHb8FLMcxjjpixJ7qnnG9BNety3cG76IM+Iesii8Ino4+T/J2+9MG9lGquV+Au2g==" }, "node_modules/@tootallnate/once": { "version": "2.0.0", @@ -13202,18 +13201,6 @@ "node": ">= 0.4.0" } }, - "node_modules/uuid": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", - "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", - "funding": [ - "https://github.com/sponsors/broofa", - "https://github.com/sponsors/ctavan" - ], - "bin": { - "uuid": "dist/bin/uuid" - } - }, "node_modules/validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", diff --git a/package.json b/package.json index 7fe4393bd..78d738497 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@ng-apimock/core": "^3.11.0", "@ngxs/store": "^3.8.1", "@sovity.de/broker-server-client": "0.20230712.71619-main-a4860cff", - "@sovity.de/edc-client": "0.20230919.111550-main-118ea199", + "@sovity.de/edc-client": "0.20230921.115850-main-5e87f14f", "clean-deep": "^3.4.0", "date-fns": "^2.30.0", "dotenv": "^16.3.1", diff --git a/src/app/component-library/catalog/asset-detail-dialog/asset-detail-dialog.component.html b/src/app/component-library/catalog/asset-detail-dialog/asset-detail-dialog.component.html index 22dd75f8f..af0ebcb10 100644 --- a/src/app/component-library/catalog/asset-detail-dialog/asset-detail-dialog.component.html +++ b/src/app/component-library/catalog/asset-detail-dialog/asset-detail-dialog.component.html @@ -20,7 +20,7 @@ {{ asset.name }}
- {{ asset.originatorOrganization }} + {{ asset.creatorOrganizationName }}
@@ -44,7 +44,7 @@ -
+
{{ keyword }} diff --git a/src/app/component-library/catalog/asset-detail-dialog/asset-detail-dialog.component.ts b/src/app/component-library/catalog/asset-detail-dialog/asset-detail-dialog.component.ts index d6672950a..2c0969fcb 100644 --- a/src/app/component-library/catalog/asset-detail-dialog/asset-detail-dialog.component.ts +++ b/src/app/component-library/catalog/asset-detail-dialog/asset-detail-dialog.component.ts @@ -7,6 +7,7 @@ import { import {Observable, Subject, isObservable} from 'rxjs'; import {filter, finalize, takeUntil} from 'rxjs/operators'; import {ContractNegotiationService} from '../../../core/services/api/contract-negotiation.service'; +import {EdcApiService} from '../../../core/services/api/edc-api.service'; import {Asset} from '../../../core/services/models/asset'; import {NotificationService} from '../../../core/services/notification.service'; import {ContractAgreementTransferDialogData} from '../../../routes/connector-ui/contract-agreement-page/contract-agreement-transfer-dialog/contract-agreement-transfer-dialog-data'; @@ -18,7 +19,6 @@ import { import {PropertyGridGroup} from '../../property-grid/property-grid-group/property-grid-group'; import {AssetDetailDialogData} from './asset-detail-dialog-data'; import {AssetDetailDialogResult} from './asset-detail-dialog-result'; -import {EdcApiService} from "../../../core/services/api/edc-api.service"; /** * Asset Detail Dialog @@ -76,10 +76,10 @@ export class AssetDetailDialogComponent implements OnDestroy { onDeleteClick() { this.confirmDelete().subscribe(() => { this.blockingRequest({ - successMessage: `Deleted asset ${this.asset.id}.`, - failureMessage: `Failed deleting asset ${this.asset.id}.`, + successMessage: `Deleted asset ${this.asset.assetId}.`, + failureMessage: `Failed deleting asset ${this.asset.assetId}.`, onsuccess: () => this.close({refreshList: true}), - req: () => this.edcApiService.deleteAsset(this.asset.id), + req: () => this.edcApiService.deleteAsset(this.asset.assetId), }); }); } diff --git a/src/app/component-library/catalog/asset-detail-dialog/asset-property-grid-group-builder.ts b/src/app/component-library/catalog/asset-detail-dialog/asset-property-grid-group-builder.ts index a9b09d19b..a11e451e4 100644 --- a/src/app/component-library/catalog/asset-detail-dialog/asset-property-grid-group-builder.ts +++ b/src/app/component-library/catalog/asset-detail-dialog/asset-property-grid-group-builder.ts @@ -36,7 +36,7 @@ export class AssetPropertyGridGroupBuilder { icon: 'category', label: 'ID', labelTitle: AssetProperties.id, - ...this.propertyGridUtils.guessValue(asset.id), + ...this.propertyGridUtils.guessValue(asset.assetId), }, { icon: 'file_copy', @@ -48,38 +48,38 @@ export class AssetPropertyGridGroupBuilder { icon: 'language', label: 'Language', labelTitle: AssetProperties.language, - ...this.propertyGridUtils.guessValue(asset.language?.label), + ...this.propertyGridUtils.guessValue(asset.language), }, { icon: 'apartment', label: 'Publisher', labelTitle: AssetProperties.publisher, - ...this.propertyGridUtils.guessValue(asset.publisher), + ...this.propertyGridUtils.guessValue(asset.publisherHomepage), }, { icon: 'bookmarks', label: 'Endpoint Documentation', labelTitle: AssetProperties.endpointDocumentation, - ...this.propertyGridUtils.guessValue(asset.endpointDocumentation), + ...this.propertyGridUtils.guessValue(asset.landingPageUrl), }, { icon: 'gavel', label: 'Standard License', labelTitle: AssetProperties.standardLicense, - ...this.propertyGridUtils.guessValue(asset.standardLicense), + ...this.propertyGridUtils.guessValue(asset.licenseUrl), }, - this.buildConnectorEndpointField(asset.originator!!), + this.buildConnectorEndpointField(asset.connectorEndpoint), { icon: 'account_circle', label: 'Organization', labelTitle: AssetProperties.originatorOrganization, - ...this.propertyGridUtils.guessValue(asset.originatorOrganization), + ...this.propertyGridUtils.guessValue(asset.creatorOrganizationName), }, { icon: 'category', label: 'Content Type', labelTitle: AssetProperties.contentType, - ...this.propertyGridUtils.guessValue(asset.contentType), + ...this.propertyGridUtils.guessValue(asset.mediaType), }, ]; @@ -124,7 +124,7 @@ export class AssetPropertyGridGroupBuilder { icon: 'commute', label: 'Transport Mode', labelTitle: AssetProperties.transportMode, - ...this.propertyGridUtils.guessValue(asset.transportMode?.label), + ...this.propertyGridUtils.guessValue(asset.transportMode), }); } if (includeEmpty || asset.dataCategory) { @@ -132,7 +132,7 @@ export class AssetPropertyGridGroupBuilder { icon: 'commute', label: 'Data Category', labelTitle: AssetProperties.dataCategory, - ...this.propertyGridUtils.guessValue(asset.dataCategory?.label), + ...this.propertyGridUtils.guessValue(asset.dataCategory), }); } if (includeEmpty || asset.dataSubcategory) { @@ -140,7 +140,7 @@ export class AssetPropertyGridGroupBuilder { icon: 'commute', label: 'Data Subcategory', labelTitle: AssetProperties.dataSubcategory, - ...this.propertyGridUtils.guessValue(asset.dataSubcategory?.label), + ...this.propertyGridUtils.guessValue(asset.dataSubcategory), }); } if (includeEmpty || asset.dataModel) { diff --git a/src/app/component-library/catalog/contract-offer-cards/contract-offer-cards.component.html b/src/app/component-library/catalog/contract-offer-cards/contract-offer-cards.component.html index bc5b818cd..1788ca50e 100644 --- a/src/app/component-library/catalog/contract-offer-cards/contract-offer-cards.component.html +++ b/src/app/component-library/catalog/contract-offer-cards/contract-offer-cards.component.html @@ -12,7 +12,7 @@ {{ asset.name }} - {{ asset.originatorOrganization }} + {{ asset.creatorOrganizationName }} @@ -29,7 +29,7 @@
-
+
{{ asset.version diff --git a/src/app/core/services/api/contract-negotiation.service.ts b/src/app/core/services/api/contract-negotiation.service.ts index 055a26418..730af9f86 100644 --- a/src/app/core/services/api/contract-negotiation.service.ts +++ b/src/app/core/services/api/contract-negotiation.service.ts @@ -56,7 +56,7 @@ export class ContractNegotiationService { return ( this.runningNegotiations.get(contractOffer.id) !== undefined || !!this.runningTransferProcesses.find( - (tp) => tp.assetId === contractOffer.asset.id, + (tp) => tp.assetId === contractOffer.asset.assetId, ) ); } @@ -67,7 +67,7 @@ export class ContractNegotiationService { getState(contractOffer: ContractOffer): string { const transferProcess = this.runningTransferProcesses.find( - (tp) => tp.assetId === contractOffer.asset.id, + (tp) => tp.assetId === contractOffer.asset.assetId, ); if (transferProcess) { return TransferProcessStates[transferProcess.state]; @@ -83,11 +83,11 @@ export class ContractNegotiationService { negotiate(contractOffer: ContractOffer) { const initiateRequest: NegotiationInitiateRequestDto = { - connectorAddress: contractOffer.asset.originator!, + connectorAddress: contractOffer.asset.connectorEndpoint!, offer: { offerId: contractOffer.id, - assetId: contractOffer.asset.id, + assetId: contractOffer.asset.assetId, policy: contractOffer.policy, }, connectorId: 'my-connector', diff --git a/src/app/core/services/api/contract-offer.service.ts b/src/app/core/services/api/contract-offer.service.ts index f4235c3c3..3d6521e78 100644 --- a/src/app/core/services/api/contract-offer.service.ts +++ b/src/app/core/services/api/contract-offer.service.ts @@ -60,8 +60,8 @@ export class ContractOfferService { return { ...contractOfferDto, asset: this.assetPropertyMapper.buildAsset({ - connectorEndpoint, - asset: contractOfferDto.asset, + connectorEndpoint: connectorEndpoint, + uiAsset: contractOfferDto.asset, }), }; } diff --git a/src/app/core/services/api/criterion-type-ext.ts b/src/app/core/services/api/criterion-type-ext.ts index c305dab14..11fa57459 100644 --- a/src/app/core/services/api/criterion-type-ext.ts +++ b/src/app/core/services/api/criterion-type-ext.ts @@ -1,8 +1,6 @@ import {UiCriterionOperatorEnum} from '@sovity.de/edc-client'; -export type UiCriterionOperator = - | UiCriterionOperatorEnum - | UiCriterionOperatorEnum; +export type UiCriterionOperator = UiCriterionOperatorEnum; export const CRITERION_OPERATOR_SYMBOLS: Record = { EQ: '=', diff --git a/src/app/core/services/api/edc-api.service.ts b/src/app/core/services/api/edc-api.service.ts index 8097680b6..809904320 100644 --- a/src/app/core/services/api/edc-api.service.ts +++ b/src/app/core/services/api/edc-api.service.ts @@ -1,7 +1,6 @@ import {Inject, Injectable} from '@angular/core'; import {Observable, from} from 'rxjs'; import { - AssetDto, AssetPage, ConnectorLimits, ContractAgreementPage, @@ -14,6 +13,7 @@ import { PolicyDefinitionCreateRequest, PolicyDefinitionPage, TransferHistoryPage, + UiAsset, UiAssetCreateRequest, buildEdcClient, } from '@sovity.de/edc-client'; @@ -104,7 +104,7 @@ export class EdcApiService { return from(this.edcClient.uiApi.transferHistoryPageEndpoint()); } - getTransferProcessAsset(transferProcessId: string): Observable { + getTransferProcessAsset(transferProcessId: string): Observable { return from( this.edcClient.uiApi.getTransferProcessAsset({transferProcessId}), ); diff --git a/src/app/core/services/api/fake-backend/asset-fake-service.ts b/src/app/core/services/api/fake-backend/asset-fake-service.ts index 21fe672ae..79a245189 100644 --- a/src/app/core/services/api/fake-backend/asset-fake-service.ts +++ b/src/app/core/services/api/fake-backend/asset-fake-service.ts @@ -17,7 +17,7 @@ export const assetPage = (): AssetPage => { export const createAsset = (asset: UiAssetCreateRequest): IdResponseDto => { assets.push({ assetId: asset.id, - name: asset.name, + name: asset.name ?? asset.id, description: asset.description, creatorOrganizationName: asset.creatorOrganizationName, publisherHomepage: asset.publisherHomepage, diff --git a/src/app/core/services/api/fake-backend/data/test-assets.ts b/src/app/core/services/api/fake-backend/data/test-assets.ts index df968ee71..1ec0498d5 100644 --- a/src/app/core/services/api/fake-backend/data/test-assets.ts +++ b/src/app/core/services/api/fake-backend/data/test-assets.ts @@ -1,4 +1,4 @@ -import {AssetDto, UiAsset} from '@sovity.de/edc-client'; +import {UiAsset} from '@sovity.de/edc-client'; export namespace TestAssets { export const boring: UiAsset = { @@ -28,15 +28,18 @@ export namespace TestAssets { dataModel: 'my-data-model-001', geoReferenceMethod: 'my-geo-reference-method', transportMode: 'Rail', - additionalProperties: {}, + additionalProperties: { + 'asset:prop:some-unsupported-property': + 'F10E2821BBBEA527EA02200352313BC059445190', + }, privateProperties: {}, }; - export function toAssetDto(entry: UiAsset): AssetDto { + export function toAssetDto(entry: UiAsset): UiAsset { return { assetId: entry.assetId, - createdAt: new Date(), - properties: {}, + name: entry.name, + additionalProperties: {}, }; } @@ -47,6 +50,7 @@ export namespace TestAssets { export function dummyAsset(assetId: string): UiAsset { return { assetId, + name: 'Dummy Asset', privateProperties: {}, }; } diff --git a/src/app/core/services/api/fake-backend/edc-fake-backend.ts b/src/app/core/services/api/fake-backend/edc-fake-backend.ts index 4c4b46b1f..fd2c4d850 100644 --- a/src/app/core/services/api/fake-backend/edc-fake-backend.ts +++ b/src/app/core/services/api/fake-backend/edc-fake-backend.ts @@ -1,5 +1,4 @@ import { - AssetDtoToJSON, AssetPageToJSON, ContractAgreementPageToJSON, ContractAgreementTransferRequestFromJSON, @@ -11,6 +10,7 @@ import { PolicyDefinitionPageToJSON, TransferHistoryPageToJSON, UiAssetCreateRequestFromJSON, + UiAssetToJSON, } from '@sovity.de/edc-client'; import {assetPage, createAsset, deleteAsset} from './asset-fake-service'; import { @@ -126,7 +126,7 @@ export const EDC_FAKE_BACKEND: FetchAPI = async ( .url('pages/transfer-history-page/transfer-processes/*/asset') .on('GET', (transferProcessId) => { let asset = transferProcessAsset(transferProcessId); - return ok(AssetDtoToJSON(asset)); + return ok(UiAssetToJSON(asset)); }) .tryMatch(); diff --git a/src/app/core/services/api/fake-backend/transfer-history-fake-service.ts b/src/app/core/services/api/fake-backend/transfer-history-fake-service.ts index 37cc92b61..f972331e9 100644 --- a/src/app/core/services/api/fake-backend/transfer-history-fake-service.ts +++ b/src/app/core/services/api/fake-backend/transfer-history-fake-service.ts @@ -1,7 +1,7 @@ import { - AssetDto, TransferHistoryEntry, TransferHistoryPage, + UiAsset, } from '@sovity.de/edc-client'; import {assets} from './asset-fake-service'; import {TestAssets} from './data/test-assets'; @@ -66,9 +66,7 @@ export let transferHistoryEntries: TransferHistoryEntry[] = [ contractAgreementId: 'test-asset-4-cd:f52a5d30-6356-4a55-a75a-3c45d7a88c3e', direction: 'PROVIDING', counterPartyConnectorEndpoint: 'https://sovity-demo2-edc/api/v1/ids/data', - assetName: TestAssets.full.name - ? TestAssets.full.name - : TestAssets.full.assetId, + assetName: TestAssets.full.name || TestAssets.full.assetId, assetId: TestAssets.full.assetId, }, ]; @@ -79,14 +77,14 @@ export const transferHistoryPage = (): TransferHistoryPage => { }; }; -export const transferProcessAsset = (transferProcessId: string): AssetDto => { +export const transferProcessAsset = (transferProcessId: string): UiAsset => { let transfer = transferHistoryEntries.find( (it) => it.transferProcessId === transferProcessId, ); const assetId = transfer?.assetId ?? 'unknown'; const isProviding = transfer?.direction === 'PROVIDING'; - const dummyAsset: AssetDto = TestAssets.toAssetDto( + const dummyAsset: UiAsset = TestAssets.toAssetDto( TestAssets.dummyAsset(assetId), ); diff --git a/src/app/core/services/asset-property-mapper.ts b/src/app/core/services/asset-property-mapper.ts index f853b63b5..650abe0e8 100644 --- a/src/app/core/services/asset-property-mapper.ts +++ b/src/app/core/services/asset-property-mapper.ts @@ -1,16 +1,12 @@ import {Inject, Injectable} from '@angular/core'; import {UiAsset} from '@sovity.de/edc-client'; import {AssetEditorDialogFormValue} from '../../routes/connector-ui/asset-page/asset-create-dialog/asset-editor-dialog-form-model'; -import {DataCategorySelectItemService} from '../../routes/connector-ui/asset-page/data-category-select/data-category-select-item.service'; -import {DataSubcategorySelectItemService} from '../../routes/connector-ui/asset-page/data-subcategory-select/data-subcategory-select-item.service'; -import {LanguageSelectItemService} from '../../routes/connector-ui/asset-page/language-select/language-select-item.service'; -import {TransportModeSelectItemService} from '../../routes/connector-ui/asset-page/transport-mode-select/transport-mode-select-item.service'; import {ActiveFeatureSet} from '../config/active-feature-set'; import {APP_CONFIG, AppConfig} from '../config/app-config'; import {removeNullValues} from '../utils/record-utils'; import {trimmedOrNull} from '../utils/string-utils'; import {AssetProperties} from './asset-properties'; -import {Asset} from './models/asset'; +import {AdditionalAssetProperty, Asset} from './models/asset'; /** * Maps between EDC Asset and our type safe asset @@ -21,65 +17,9 @@ import {Asset} from './models/asset'; export class AssetPropertyMapper { constructor( @Inject(APP_CONFIG) private config: AppConfig, - private languageSelectItemService: LanguageSelectItemService, - private transportModeSelectItemService: TransportModeSelectItemService, - private dataCategorySelectItemService: DataCategorySelectItemService, - private dataSubcategorySelectItemService: DataSubcategorySelectItemService, private activeFeatureSet: ActiveFeatureSet, ) {} - buildAsset(opts: {connectorEndpoint: string; asset: UiAsset}): Asset { - const asset = opts.asset; - - const language = asset.language - ? this.languageSelectItemService.findById(asset.language) - : null; - const dataCategory = asset.dataCategory - ? this.dataCategorySelectItemService.findById(asset.dataCategory) - : null; - const dataSubcategory = asset.dataSubcategory - ? this.dataSubcategorySelectItemService.findById(asset.dataSubcategory) - : null; - const transportMode = asset.transportMode - ? this.transportModeSelectItemService.findById(asset.transportMode) - : null; - - const keywords = asset.keywords ?? []; - - const id = asset.assetId ?? 'no-id-was-set'; - const additionalProperties = this.buildAdditionalProperties( - asset.additionalProperties, - ); - - return { - id, - name: asset.name ?? id, - version: asset.version ?? null, - contentType: asset.mediaType ?? null, - originator: opts.connectorEndpoint, - originatorOrganization: - asset.creatorOrganizationName ?? 'Unknown Organization', - keywords, - description: trimmedOrNull(asset.description), - language, - publisher: asset.publisherHomepage ?? null, - standardLicense: asset.licenseUrl ?? null, - endpointDocumentation: asset.landingPageUrl ?? null, - dataCategory, - dataSubcategory, - dataModel: asset.dataModel ?? null, - geoReferenceMethod: asset.geoReferenceMethod ?? null, - transportMode, - httpProxyMethod: this._parseBoolean(asset.httpDatasourceHintsProxyMethod), - httpProxyPath: this._parseBoolean(asset.httpDatasourceHintsProxyPath), - httpProxyQueryParams: this._parseBoolean( - asset.httpDatasourceHintsProxyBody, - ), - httpProxyBody: this._parseBoolean(asset.httpDatasourceHintsProxyBody), - additionalProperties, - }; - } - buildUiAssetfromprops(props: Record): UiAsset { return { assetId: props[AssetProperties.id] ?? '', @@ -102,16 +42,16 @@ export class AssetPropertyMapper { geoReferenceMethod: props[AssetProperties.geoReferenceMethod] ?? '', transportMode: props[AssetProperties.transportMode] ?? '', - httpDatasourceHintsProxyMethod: this._parseBooleanfromString( + httpDatasourceHintsProxyMethod: this._parseBooleanFromString( props[AssetProperties.httpProxyMethod], ), - httpDatasourceHintsProxyPath: this._parseBooleanfromString( + httpDatasourceHintsProxyPath: this._parseBooleanFromString( props[AssetProperties.httpProxyPath], ), - httpDatasourceHintsProxyQueryParams: this._parseBooleanfromString( + httpDatasourceHintsProxyQueryParams: this._parseBooleanFromString( props[AssetProperties.httpProxyQueryParams], ), - httpDatasourceHintsProxyBody: this._parseBooleanfromString( + httpDatasourceHintsProxyBody: this._parseBooleanFromString( props[AssetProperties.httpProxyBody], ), @@ -119,20 +59,47 @@ export class AssetPropertyMapper { }; } - private buildAdditionalProperties( - props: Record | undefined, - ): Array<{key: string; value: string}> { - if (!props) { - return []; + buildAsset(opts: {uiAsset: UiAsset; connectorEndpoint: string}): Asset { + const { + additionalProperties, + additionalJsonProperties, + privateProperties, + privateJsonProperties, + ...assetProperties + } = opts.uiAsset; + + return { + ...assetProperties, + additionalProperties: this.convertToAdditionalProperties(opts.uiAsset), + connectorEndpoint: opts.connectorEndpoint, + }; + } + + convertToAdditionalProperties(asset: UiAsset): AdditionalAssetProperty[] { + let result: AdditionalAssetProperty[] = []; + type AssetKey = + | 'additionalProperties' + | 'additionalJsonProperties' + | 'privateProperties' + | 'privateJsonProperties'; + + const propertiesToConvert: AssetKey[] = [ + 'additionalProperties', + 'additionalJsonProperties', + 'privateProperties', + 'privateJsonProperties', + ]; + + for (let propName of propertiesToConvert) { + const propValue = asset[propName as AssetKey]; + if (propValue) { + for (let key in propValue) { + result.push({key: key, value: propValue[key]}); + } + } } - const knownKeys = Object.values(AssetProperties); - return Object.entries(props) - .filter(([k]) => !knownKeys.includes(k)) - .map(([key, value]) => ({ - key, - value: value ?? '', - })); + return result; } private buildAdditionalPropertiesforUiAsset( @@ -211,14 +178,7 @@ export class AssetPropertyMapper { return removeNullValues(props); } - private _parseBoolean(value: boolean | null | undefined): boolean | null { - if (value != true && value != false) { - return null; - } - return value; - } - - private _parseBooleanfromString(value: string | null): boolean | undefined { + private _parseBooleanFromString(value: string | null): boolean | undefined { if (!value) { return undefined; } diff --git a/src/app/core/services/asset-service-mapped.ts b/src/app/core/services/asset-service-mapped.ts index d5ec2cd5c..d38eddbe0 100644 --- a/src/app/core/services/asset-service-mapped.ts +++ b/src/app/core/services/asset-service-mapped.ts @@ -25,7 +25,7 @@ export class AssetServiceMapped { assetPage.assets.map((asset) => this.assetPropertyMapper.buildAsset({ connectorEndpoint: this.config.connectorEndpoint, - asset: asset, + uiAsset: asset, }), ), ), diff --git a/src/app/core/services/contract-definition-builder.ts b/src/app/core/services/contract-definition-builder.ts index 7971b7c5b..d51e31c9a 100644 --- a/src/app/core/services/contract-definition-builder.ts +++ b/src/app/core/services/contract-definition-builder.ts @@ -29,7 +29,7 @@ export class ContractDefinitionBuilder { operator: 'IN', operandRight: { type: UiCriterionLiteralTypeEnum.ValueList, - valueList: formValue.assets!.map((it) => it.id), + valueList: formValue.assets!.map((it) => it.assetId), }, }, ], diff --git a/src/app/core/services/http-params-mapper.service.ts b/src/app/core/services/http-params-mapper.service.ts index 4f2ba77b0..52a71b523 100644 --- a/src/app/core/services/http-params-mapper.service.ts +++ b/src/app/core/services/http-params-mapper.service.ts @@ -33,13 +33,17 @@ export class HttpRequestParamsMapper { const contentType = value.httpProxiedBodyContentType?.trim() || null; let proxyMethod = - value.showAllHttpParameterizationFields || asset.httpProxyMethod; + value.showAllHttpParameterizationFields || + asset.httpDatasourceHintsProxyMethod; let proxyPath = - value.showAllHttpParameterizationFields || asset.httpProxyPath; + value.showAllHttpParameterizationFields || + asset.httpDatasourceHintsProxyPath; let proxyQueryParams = - value.showAllHttpParameterizationFields || asset.httpProxyQueryParams; + value.showAllHttpParameterizationFields || + asset.httpDatasourceHintsProxyQueryParams; let proxyBody = - value.showAllHttpParameterizationFields || asset.httpProxyBody; + value.showAllHttpParameterizationFields || + asset.httpDatasourceHintsProxyBody; return removeNullValues({ method: proxyMethod ? method : null, diff --git a/src/app/core/services/models/asset.ts b/src/app/core/services/models/asset.ts index e3b131692..7f2ed1294 100644 --- a/src/app/core/services/models/asset.ts +++ b/src/app/core/services/models/asset.ts @@ -1,44 +1,21 @@ -import {DataCategorySelectItem} from '../../../routes/connector-ui/asset-page/data-category-select/data-category-select-item'; -import {DataSubcategorySelectItem} from '../../../routes/connector-ui/asset-page/data-subcategory-select/data-subcategory-select-item'; -import {LanguageSelectItem} from '../../../routes/connector-ui/asset-page/language-select/language-select-item'; -import {TransportModeSelectItem} from '../../../routes/connector-ui/asset-page/transport-mode-select/transport-mode-select-item'; +import {UiAsset} from '@sovity.de/edc-client'; /** * Asset (UI Dto / Type Safe) * * Also includes full items / labels for fixed vocabulary values, e.g. language */ -export interface Asset { - id: string; - name: string; - version: string | null; - contentType: string | null; - originator: string | null; - originatorOrganization: string | null; - keywords: string[]; - - description: string | null; - language: LanguageSelectItem | null; - publisher: string | null; - standardLicense: string | null; - endpointDocumentation: string | null; - - // MDS Specific - dataCategory: DataCategorySelectItem | null; - dataSubcategory: DataSubcategorySelectItem | null; - dataModel: string | null; - geoReferenceMethod: string | null; - transportMode: TransportModeSelectItem | null; - - // HTTP Parameterization Metadata - httpProxyMethod: boolean | null; - httpProxyPath: boolean | null; - httpProxyQueryParams: boolean | null; - httpProxyBody: boolean | null; - +export type Asset = Omit< + UiAsset, + | 'additionalProperties' + | 'additionalJsonProperties' + | 'privateProperties' + | 'privateJsonProperties' +> & { + connectorEndpoint: string; // Unhandled Additional Properties additionalProperties: AdditionalAssetProperty[]; -} +}; export interface AdditionalAssetProperty { key: string; diff --git a/src/app/core/utils/search-utils.ts b/src/app/core/utils/search-utils.ts index 287bcceed..ea2bf2cb2 100644 --- a/src/app/core/utils/search-utils.ts +++ b/src/app/core/utils/search-utils.ts @@ -30,5 +30,5 @@ export function search( * @param asset */ export function assetSearchTargets(asset: Asset): (string | null)[] { - return [asset.id, asset.name, ...asset.keywords]; + return [asset.assetId, asset.name, ...(asset.keywords ?? [])]; } diff --git a/src/app/routes/broker-ui/catalog-page/catalog-page/mapping/broker-catalog-mapper.ts b/src/app/routes/broker-ui/catalog-page/catalog-page/mapping/broker-catalog-mapper.ts index 26fcce85c..8d5487bef 100644 --- a/src/app/routes/broker-ui/catalog-page/catalog-page/mapping/broker-catalog-mapper.ts +++ b/src/app/routes/broker-ui/catalog-page/catalog-page/mapping/broker-catalog-mapper.ts @@ -23,7 +23,9 @@ export class BrokerCatalogMapper { ...offer, asset: this.assetPropertyMapper.buildAsset({ connectorEndpoint: offer.connectorEndpoint, - asset: this.assetPropertyMapper.buildUiAssetfromprops(offer.properties), + uiAsset: this.assetPropertyMapper.buildUiAssetfromprops( + offer.properties, + ), }), }; } diff --git a/src/app/routes/broker-ui/catalog-page/data-offer-cards/data-offer-cards.component.html b/src/app/routes/broker-ui/catalog-page/data-offer-cards/data-offer-cards.component.html index 512664537..6992bcffa 100644 --- a/src/app/routes/broker-ui/catalog-page/data-offer-cards/data-offer-cards.component.html +++ b/src/app/routes/broker-ui/catalog-page/data-offer-cards/data-offer-cards.component.html @@ -14,7 +14,7 @@ {{ asset.name }} - {{ asset.originatorOrganization }} + {{ asset.creatorOrganizationName }} @@ -25,7 +25,7 @@
-
+
{{ asset.version diff --git a/src/app/routes/connector-ui/asset-page/asset-cards/asset-cards.component.html b/src/app/routes/connector-ui/asset-page/asset-cards/asset-cards.component.html index 3eddc3448..052a6e926 100644 --- a/src/app/routes/connector-ui/asset-page/asset-cards/asset-cards.component.html +++ b/src/app/routes/connector-ui/asset-page/asset-cards/asset-cards.component.html @@ -9,7 +9,7 @@ {{ asset.name }} - {{ asset.originatorOrganization }} + {{ asset.creatorOrganizationName }} @@ -18,7 +18,7 @@
-
+
{{ asset.version diff --git a/src/app/routes/connector-ui/asset-page/asset-create-dialog/assets-id-validator-builder.ts b/src/app/routes/connector-ui/asset-page/asset-create-dialog/assets-id-validator-builder.ts index 32c641ffc..8776d6f84 100644 --- a/src/app/routes/connector-ui/asset-page/asset-create-dialog/assets-id-validator-builder.ts +++ b/src/app/routes/connector-ui/asset-page/asset-create-dialog/assets-id-validator-builder.ts @@ -30,6 +30,6 @@ export class AssetsIdValidatorBuilder { private fetchAssetIds(): Observable> { return this.assetServiceMapped .fetchAssets() - .pipe(map((assets) => new Set(assets.map((asset) => asset.id)))); + .pipe(map((assets) => new Set(assets.map((asset) => asset.assetId)))); } } diff --git a/src/app/routes/connector-ui/contract-agreement-page/contract-agreement-cards/contract-agreement-card-mapped.service.ts b/src/app/routes/connector-ui/contract-agreement-page/contract-agreement-cards/contract-agreement-card-mapped.service.ts index 17aa5930e..13ec5226b 100644 --- a/src/app/routes/connector-ui/contract-agreement-page/contract-agreement-cards/contract-agreement-card-mapped.service.ts +++ b/src/app/routes/connector-ui/contract-agreement-page/contract-agreement-cards/contract-agreement-card-mapped.service.ts @@ -19,8 +19,8 @@ export class ContractAgreementCardMappedService { contractAgreement: ContractAgreementCard, ): ContractAgreementCardMapped { let asset = this.assetPropertyMapper.buildAsset({ + uiAsset: contractAgreement.asset, connectorEndpoint: contractAgreement.counterPartyAddress, - asset: contractAgreement.asset, }); return { diff --git a/src/app/routes/connector-ui/contract-agreement-page/contract-agreement-transfer-dialog/contract-agreement-transfer-dialog.component.ts b/src/app/routes/connector-ui/contract-agreement-page/contract-agreement-transfer-dialog/contract-agreement-transfer-dialog.component.ts index b03f5ba1c..f1f533580 100644 --- a/src/app/routes/connector-ui/contract-agreement-page/contract-agreement-transfer-dialog/contract-agreement-transfer-dialog.component.ts +++ b/src/app/routes/connector-ui/contract-agreement-page/contract-agreement-transfer-dialog/contract-agreement-transfer-dialog.component.ts @@ -28,37 +28,37 @@ export class ContractAgreementTransferDialogComponent implements OnDestroy { get proxyMethod(): boolean { return ( this.showAllHttpParameterizationFields || - this.data.asset.httpProxyMethod == true + this.data.asset.httpDatasourceHintsProxyMethod == true ); } get proxyPath(): boolean { return ( this.showAllHttpParameterizationFields || - this.data.asset.httpProxyPath == true + this.data.asset.httpDatasourceHintsProxyPath == true ); } get proxyQueryParams(): boolean { return ( this.showAllHttpParameterizationFields || - this.data.asset.httpProxyQueryParams == true + this.data.asset.httpDatasourceHintsProxyQueryParams == true ); } get proxyBody(): boolean { return ( this.showAllHttpParameterizationFields || - this.data.asset.httpProxyBody == true + this.data.asset.httpDatasourceHintsProxyBody == true ); } get showHttpParameterizationToggleButton(): boolean { return ( - this.data.asset.httpProxyMethod !== true || - this.data.asset.httpProxyPath !== true || - this.data.asset.httpProxyQueryParams !== true || - this.data.asset.httpProxyBody !== true + this.data.asset.httpDatasourceHintsProxyMethod !== true || + this.data.asset.httpDatasourceHintsProxyPath !== true || + this.data.asset.httpDatasourceHintsProxyQueryParams !== true || + this.data.asset.httpDatasourceHintsProxyBody !== true ); } @@ -123,9 +123,9 @@ export class ContractAgreementTransferDialogComponent implements OnDestroy { const customJson: any = JSON.parse( value.transferProcessRequest?.trim() ?? '', ); - customJson.assetId = this.data.asset.id; + customJson.assetId = this.data.asset.assetId; customJson.contractId = this.data.contractId; - customJson.connectorAddress = this.data.asset.originator; + customJson.connectorAddress = this.data.asset.connectorEndpoint; return { type: 'CUSTOM_JSON', @@ -139,7 +139,8 @@ export class ContractAgreementTransferDialogComponent implements OnDestroy { value, ); - let dataSinkProperties = this.dataAddressMapper.buildDataAddressProperties(value) ?? {}; + let dataSinkProperties = + this.dataAddressMapper.buildDataAddressProperties(value) ?? {}; return { type: 'PARAMS_ONLY', diff --git a/src/app/routes/connector-ui/contract-definition-page/contract-definition-cards/contract-definition-card-builder.ts b/src/app/routes/connector-ui/contract-definition-page/contract-definition-cards/contract-definition-card-builder.ts index 9b1a857b1..4ea383009 100644 --- a/src/app/routes/connector-ui/contract-definition-page/contract-definition-cards/contract-definition-card-builder.ts +++ b/src/app/routes/connector-ui/contract-definition-page/contract-definition-cards/contract-definition-card-builder.ts @@ -23,7 +23,7 @@ export class ContractDefinitionCardBuilder { assets: Asset[], policyDefinitions: PolicyDefinitionDto[], ): ContractDefinitionCard[] { - const assetById = associateBy(assets, (asset) => asset.id); + const assetById = associateBy(assets, (asset) => asset.assetId); const policyDefinitionById = associateBy( policyDefinitions, (policyDefinition) => policyDefinition.policyDefinitionId, diff --git a/src/app/routes/connector-ui/transfer-history-page/transfer-history-page/transfer-history-page.component.ts b/src/app/routes/connector-ui/transfer-history-page/transfer-history-page/transfer-history-page.component.ts index d43968978..ffd2b59fa 100644 --- a/src/app/routes/connector-ui/transfer-history-page/transfer-history-page/transfer-history-page.component.ts +++ b/src/app/routes/connector-ui/transfer-history-page/transfer-history-page/transfer-history-page.component.ts @@ -9,7 +9,11 @@ import { switchMap, } from 'rxjs'; import {catchError, map} from 'rxjs/operators'; -import {TransferHistoryEntry, TransferHistoryPage} from '@sovity.de/edc-client'; +import { + TransferHistoryEntry, + TransferHistoryPage, + UiAsset, +} from '@sovity.de/edc-client'; import {AssetDetailDialogDataService} from '../../../../component-library/catalog/asset-detail-dialog/asset-detail-dialog-data.service'; import {AssetDetailDialogService} from '../../../../component-library/catalog/asset-detail-dialog/asset-detail-dialog.service'; import {JsonDialogService} from '../../../../component-library/json-dialog/json-dialog/json-dialog.service'; @@ -57,17 +61,28 @@ export class TransferHistoryPageComponent implements OnInit, OnDestroy { this.ngOnDestroy$, ); } - loadAssetDetails(item: TransferHistoryEntry): Observable { return this.edcApiService .getTransferProcessAsset(item.transferProcessId) .pipe( - map((asset) => - this.assetPropertyMapper.buildAsset({ + map((asset: UiAsset) => { + // Destructure properties to exclude from the main object + const { + additionalProperties, + additionalJsonProperties, + privateProperties, + privateJsonProperties, + ...assetProperties + } = asset; + + // Return the Asset type structure + return { + ...assetProperties, // Spread the rest of UiAsset properties connectorEndpoint: item.counterPartyConnectorEndpoint, - asset: asset, - }), - ), + additionalProperties: + this.assetPropertyMapper.convertToAdditionalProperties(asset), + }; + }), ); } From 445bf9f579c2eb8deb00230dd99ee0cdcc108fb4 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Thu, 21 Sep 2023 15:19:47 +0200 Subject: [PATCH 5/9] fix: remove dead Code --- .../core/services/asset-property-mapper.ts | 75 +------------------ 1 file changed, 2 insertions(+), 73 deletions(-) diff --git a/src/app/core/services/asset-property-mapper.ts b/src/app/core/services/asset-property-mapper.ts index 650abe0e8..26fc1bb38 100644 --- a/src/app/core/services/asset-property-mapper.ts +++ b/src/app/core/services/asset-property-mapper.ts @@ -1,10 +1,5 @@ -import {Inject, Injectable} from '@angular/core'; +import {Injectable} from '@angular/core'; import {UiAsset} from '@sovity.de/edc-client'; -import {AssetEditorDialogFormValue} from '../../routes/connector-ui/asset-page/asset-create-dialog/asset-editor-dialog-form-model'; -import {ActiveFeatureSet} from '../config/active-feature-set'; -import {APP_CONFIG, AppConfig} from '../config/app-config'; -import {removeNullValues} from '../utils/record-utils'; -import {trimmedOrNull} from '../utils/string-utils'; import {AssetProperties} from './asset-properties'; import {AdditionalAssetProperty, Asset} from './models/asset'; @@ -15,11 +10,6 @@ import {AdditionalAssetProperty, Asset} from './models/asset'; providedIn: 'root', }) export class AssetPropertyMapper { - constructor( - @Inject(APP_CONFIG) private config: AppConfig, - private activeFeatureSet: ActiveFeatureSet, - ) {} - buildUiAssetfromprops(props: Record): UiAsset { return { assetId: props[AssetProperties.id] ?? '', @@ -91,14 +81,13 @@ export class AssetPropertyMapper { ]; for (let propName of propertiesToConvert) { - const propValue = asset[propName as AssetKey]; + const propValue = asset[propName]; if (propValue) { for (let key in propValue) { result.push({key: key, value: propValue[key]}); } } } - return result; } @@ -122,70 +111,10 @@ export class AssetPropertyMapper { return result; } - buildProperties( - formValue: AssetEditorDialogFormValue, - ): Record { - const {metadata, advanced, datasource} = formValue; - const props: Record = {}; - props[AssetProperties.id] = trimmedOrNull(metadata?.id); - props[AssetProperties.name] = trimmedOrNull(metadata?.name); - props[AssetProperties.version] = trimmedOrNull(metadata?.version); - props[AssetProperties.curatorOrganizationName] = trimmedOrNull( - this.config.curatorOrganizationName, - ); - props[AssetProperties.keywords] = trimmedOrNull( - metadata?.keywords?.join(', '), - ); - props[AssetProperties.contentType] = trimmedOrNull(metadata?.contentType); - props[AssetProperties.description] = trimmedOrNull(metadata?.description); - props[AssetProperties.language] = metadata?.language?.id ?? null; - - props[AssetProperties.publisher] = trimmedOrNull(metadata?.publisher); - props[AssetProperties.standardLicense] = trimmedOrNull( - metadata?.standardLicense, - ); - props[AssetProperties.endpointDocumentation] = trimmedOrNull( - metadata?.endpointDocumentation, - ); - - if (this.activeFeatureSet.hasMdsFields()) { - props[AssetProperties.dataCategory] = advanced?.dataCategory?.id ?? null; - props[AssetProperties.dataSubcategory] = - advanced?.dataSubcategory?.id ?? null; - props[AssetProperties.dataModel] = trimmedOrNull(advanced?.dataModel); - props[AssetProperties.geoReferenceMethod] = trimmedOrNull( - advanced?.geoReferenceMethod, - ); - props[AssetProperties.transportMode] = - advanced?.transportMode?.id ?? null; - } - - if (datasource?.dataAddressType === 'Http') { - props[AssetProperties.httpProxyMethod] = this._encodeBoolean( - datasource?.httpProxyMethod, - ); - props[AssetProperties.httpProxyPath] = this._encodeBoolean( - datasource?.httpProxyPath, - ); - props[AssetProperties.httpProxyQueryParams] = this._encodeBoolean( - datasource?.httpProxyQueryParams, - ); - props[AssetProperties.httpProxyBody] = this._encodeBoolean( - datasource?.httpProxyBody, - ); - } - - return removeNullValues(props); - } - private _parseBooleanFromString(value: string | null): boolean | undefined { if (!value) { return undefined; } return value === 'true'; } - - private _encodeBoolean(value?: boolean | null): string { - return value ? 'true' : 'false'; - } } From 90ed2e450e05c2f8de38dbbd0d9f38afa5cf196e Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Thu, 21 Sep 2023 15:27:18 +0200 Subject: [PATCH 6/9] fix: use buildAsset function --- .../transfer-history-page.component.ts | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/app/routes/connector-ui/transfer-history-page/transfer-history-page/transfer-history-page.component.ts b/src/app/routes/connector-ui/transfer-history-page/transfer-history-page/transfer-history-page.component.ts index ffd2b59fa..b696a95dc 100644 --- a/src/app/routes/connector-ui/transfer-history-page/transfer-history-page/transfer-history-page.component.ts +++ b/src/app/routes/connector-ui/transfer-history-page/transfer-history-page/transfer-history-page.component.ts @@ -61,27 +61,16 @@ export class TransferHistoryPageComponent implements OnInit, OnDestroy { this.ngOnDestroy$, ); } + loadAssetDetails(item: TransferHistoryEntry): Observable { return this.edcApiService .getTransferProcessAsset(item.transferProcessId) .pipe( - map((asset: UiAsset) => { - // Destructure properties to exclude from the main object - const { - additionalProperties, - additionalJsonProperties, - privateProperties, - privateJsonProperties, - ...assetProperties - } = asset; - - // Return the Asset type structure - return { - ...assetProperties, // Spread the rest of UiAsset properties + map((uiAsset: UiAsset) => { + return this.assetPropertyMapper.buildAsset({ + uiAsset, connectorEndpoint: item.counterPartyConnectorEndpoint, - additionalProperties: - this.assetPropertyMapper.convertToAdditionalProperties(asset), - }; + }); }), ); } From 51b7f9464355c6ac5e8f5d0141e89af06308152a Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Thu, 21 Sep 2023 16:21:03 +0200 Subject: [PATCH 7/9] fix:buildAsset & remove Dead Code --- .../asset-property-grid-group-builder.ts | 8 +- .../core/services/api/criterion-type-ext.ts | 7 +- .../api/fake-backend/data/test-assets.ts | 4 + src/app/core/services/asset-entry-builder.ts | 4 +- .../core/services/asset-property-mapper.ts | 105 ++++++------------ src/app/core/services/asset-service-mapped.ts | 4 +- src/app/core/services/models/asset.ts | 16 +++ .../mapping/broker-catalog-mapper.ts | 7 +- 8 files changed, 73 insertions(+), 82 deletions(-) diff --git a/src/app/component-library/catalog/asset-detail-dialog/asset-property-grid-group-builder.ts b/src/app/component-library/catalog/asset-detail-dialog/asset-property-grid-group-builder.ts index a11e451e4..1f2b82730 100644 --- a/src/app/component-library/catalog/asset-detail-dialog/asset-property-grid-group-builder.ts +++ b/src/app/component-library/catalog/asset-detail-dialog/asset-property-grid-group-builder.ts @@ -48,7 +48,7 @@ export class AssetPropertyGridGroupBuilder { icon: 'language', label: 'Language', labelTitle: AssetProperties.language, - ...this.propertyGridUtils.guessValue(asset.language), + ...this.propertyGridUtils.guessValue(asset.language?.label), }, { icon: 'apartment', @@ -124,7 +124,7 @@ export class AssetPropertyGridGroupBuilder { icon: 'commute', label: 'Transport Mode', labelTitle: AssetProperties.transportMode, - ...this.propertyGridUtils.guessValue(asset.transportMode), + ...this.propertyGridUtils.guessValue(asset.transportMode?.label), }); } if (includeEmpty || asset.dataCategory) { @@ -132,7 +132,7 @@ export class AssetPropertyGridGroupBuilder { icon: 'commute', label: 'Data Category', labelTitle: AssetProperties.dataCategory, - ...this.propertyGridUtils.guessValue(asset.dataCategory), + ...this.propertyGridUtils.guessValue(asset.dataCategory?.label), }); } if (includeEmpty || asset.dataSubcategory) { @@ -140,7 +140,7 @@ export class AssetPropertyGridGroupBuilder { icon: 'commute', label: 'Data Subcategory', labelTitle: AssetProperties.dataSubcategory, - ...this.propertyGridUtils.guessValue(asset.dataSubcategory), + ...this.propertyGridUtils.guessValue(asset.dataSubcategory?.label), }); } if (includeEmpty || asset.dataModel) { diff --git a/src/app/core/services/api/criterion-type-ext.ts b/src/app/core/services/api/criterion-type-ext.ts index 11fa57459..94aa87aa0 100644 --- a/src/app/core/services/api/criterion-type-ext.ts +++ b/src/app/core/services/api/criterion-type-ext.ts @@ -1,8 +1,9 @@ import {UiCriterionOperatorEnum} from '@sovity.de/edc-client'; -export type UiCriterionOperator = UiCriterionOperatorEnum; - -export const CRITERION_OPERATOR_SYMBOLS: Record = { +export const CRITERION_OPERATOR_SYMBOLS: Record< + UiCriterionOperatorEnum, + string +> = { EQ: '=', IN: 'in', LIKE: 'like', diff --git a/src/app/core/services/api/fake-backend/data/test-assets.ts b/src/app/core/services/api/fake-backend/data/test-assets.ts index 1ec0498d5..e0f243934 100644 --- a/src/app/core/services/api/fake-backend/data/test-assets.ts +++ b/src/app/core/services/api/fake-backend/data/test-assets.ts @@ -28,6 +28,10 @@ export namespace TestAssets { dataModel: 'my-data-model-001', geoReferenceMethod: 'my-geo-reference-method', transportMode: 'Rail', + httpDatasourceHintsProxyQueryParams: true, + httpDatasourceHintsProxyPath: false, + httpDatasourceHintsProxyMethod: false, + httpDatasourceHintsProxyBody: false, additionalProperties: { 'asset:prop:some-unsupported-property': 'F10E2821BBBEA527EA02200352313BC059445190', diff --git a/src/app/core/services/asset-entry-builder.ts b/src/app/core/services/asset-entry-builder.ts index e1da51c3f..8fa491d37 100644 --- a/src/app/core/services/asset-entry-builder.ts +++ b/src/app/core/services/asset-entry-builder.ts @@ -20,8 +20,8 @@ export class AssetEntryBuilder { buildAssetCreateRequest( formValue: AssetEditorDialogFormValue, ): UiAssetCreateRequest { - let id = formValue.metadata?.id ?? 'no-id-was-set'; - let name = formValue.metadata?.name; + let id = formValue.metadata?.id!; + let name = formValue.metadata?.name!; let version = formValue.metadata?.version; let description = formValue.metadata?.description; let language = formValue.metadata?.language?.id; diff --git a/src/app/core/services/asset-property-mapper.ts b/src/app/core/services/asset-property-mapper.ts index 26fc1bb38..dbae21b6b 100644 --- a/src/app/core/services/asset-property-mapper.ts +++ b/src/app/core/services/asset-property-mapper.ts @@ -1,6 +1,9 @@ import {Injectable} from '@angular/core'; import {UiAsset} from '@sovity.de/edc-client'; -import {AssetProperties} from './asset-properties'; +import {DataCategorySelectItemService} from '../../routes/connector-ui/asset-page/data-category-select/data-category-select-item.service'; +import {DataSubcategorySelectItemService} from '../../routes/connector-ui/asset-page/data-subcategory-select/data-subcategory-select-item.service'; +import {LanguageSelectItemService} from '../../routes/connector-ui/asset-page/language-select/language-select-item.service'; +import {TransportModeSelectItemService} from '../../routes/connector-ui/asset-page/transport-mode-select/transport-mode-select-item.service'; import {AdditionalAssetProperty, Asset} from './models/asset'; /** @@ -10,44 +13,12 @@ import {AdditionalAssetProperty, Asset} from './models/asset'; providedIn: 'root', }) export class AssetPropertyMapper { - buildUiAssetfromprops(props: Record): UiAsset { - return { - assetId: props[AssetProperties.id] ?? '', - name: props[AssetProperties.name] ?? '', - version: props[AssetProperties.version] ?? '', - creatorOrganizationName: - props[AssetProperties.curatorOrganizationName] ?? '', - keywords: props[AssetProperties.keywords] - ?.split(',') - .map((it) => it.trim()), - mediaType: props[AssetProperties.contentType] ?? '', - description: props[AssetProperties.description] ?? '', - language: props[AssetProperties.language] ?? '', - publisherHomepage: props[AssetProperties.publisher] ?? '', - licenseUrl: props[AssetProperties.standardLicense] ?? '', - landingPageUrl: props[AssetProperties.endpointDocumentation] ?? '', - dataCategory: props[AssetProperties.dataCategory] ?? '', - dataSubcategory: props[AssetProperties.dataSubcategory] ?? '', - dataModel: props[AssetProperties.dataModel] ?? '', - geoReferenceMethod: props[AssetProperties.geoReferenceMethod] ?? '', - transportMode: props[AssetProperties.transportMode] ?? '', - - httpDatasourceHintsProxyMethod: this._parseBooleanFromString( - props[AssetProperties.httpProxyMethod], - ), - httpDatasourceHintsProxyPath: this._parseBooleanFromString( - props[AssetProperties.httpProxyPath], - ), - httpDatasourceHintsProxyQueryParams: this._parseBooleanFromString( - props[AssetProperties.httpProxyQueryParams], - ), - httpDatasourceHintsProxyBody: this._parseBooleanFromString( - props[AssetProperties.httpProxyBody], - ), - - additionalProperties: this.buildAdditionalPropertiesforUiAsset(props), - }; - } + constructor( + private languageSelectItemService: LanguageSelectItemService, + private transportModeSelectItemService: TransportModeSelectItemService, + private dataCategorySelectItemService: DataCategorySelectItemService, + private dataSubcategorySelectItemService: DataSubcategorySelectItemService, + ) {} buildAsset(opts: {uiAsset: UiAsset; connectorEndpoint: string}): Asset { const { @@ -55,17 +26,42 @@ export class AssetPropertyMapper { additionalJsonProperties, privateProperties, privateJsonProperties, + language, + dataCategory, + dataSubcategory, + transportMode, ...assetProperties } = opts.uiAsset; + const languageSelectItem = + language == null + ? null + : this.languageSelectItemService.findById(language); + const dataCategorySelectItem = + dataCategory == null + ? null + : this.dataCategorySelectItemService.findById(dataCategory); + const dataSubcategorySelectItem = + dataSubcategory == null + ? null + : this.dataSubcategorySelectItemService.findById(dataSubcategory); + const transportModeSelectItem = + transportMode == null + ? null + : this.transportModeSelectItemService.findById(transportMode); + return { ...assetProperties, - additionalProperties: this.convertToAdditionalProperties(opts.uiAsset), + additionalProperties: this.buildAdditionalProperties(opts.uiAsset), + language: languageSelectItem, + dataCategory: dataCategorySelectItem, + dataSubcategory: dataSubcategorySelectItem, + transportMode: transportModeSelectItem, connectorEndpoint: opts.connectorEndpoint, }; } - convertToAdditionalProperties(asset: UiAsset): AdditionalAssetProperty[] { + buildAdditionalProperties(asset: UiAsset): AdditionalAssetProperty[] { let result: AdditionalAssetProperty[] = []; type AssetKey = | 'additionalProperties' @@ -90,31 +86,4 @@ export class AssetPropertyMapper { } return result; } - - private buildAdditionalPropertiesforUiAsset( - props: Record | undefined, - ): {[key: string]: string} { - if (!props) { - return {}; - } - - const knownKeys = Object.values(AssetProperties); - const filteredEntries = Object.entries(props).filter( - ([k]) => !knownKeys.includes(k), - ); - - const result: {[key: string]: string} = {}; - for (const [key, value] of filteredEntries) { - result[key] = value ?? ''; - } - - return result; - } - - private _parseBooleanFromString(value: string | null): boolean | undefined { - if (!value) { - return undefined; - } - return value === 'true'; - } } diff --git a/src/app/core/services/asset-service-mapped.ts b/src/app/core/services/asset-service-mapped.ts index d38eddbe0..1a29ec0e6 100644 --- a/src/app/core/services/asset-service-mapped.ts +++ b/src/app/core/services/asset-service-mapped.ts @@ -22,10 +22,10 @@ export class AssetServiceMapped { fetchAssets(): Observable { return this.edcApiService.getAssetPage().pipe( map((assetPage) => - assetPage.assets.map((asset) => + assetPage.assets.map((uiAsset) => this.assetPropertyMapper.buildAsset({ connectorEndpoint: this.config.connectorEndpoint, - uiAsset: asset, + uiAsset: uiAsset, }), ), ), diff --git a/src/app/core/services/models/asset.ts b/src/app/core/services/models/asset.ts index 7f2ed1294..c08f5ecdd 100644 --- a/src/app/core/services/models/asset.ts +++ b/src/app/core/services/models/asset.ts @@ -1,4 +1,8 @@ import {UiAsset} from '@sovity.de/edc-client'; +import {DataCategorySelectItem} from '../../../routes/connector-ui/asset-page/data-category-select/data-category-select-item'; +import {DataSubcategorySelectItem} from '../../../routes/connector-ui/asset-page/data-subcategory-select/data-subcategory-select-item'; +import {LanguageSelectItem} from '../../../routes/connector-ui/asset-page/language-select/language-select-item'; +import {TransportModeSelectItem} from '../../../routes/connector-ui/asset-page/transport-mode-select/transport-mode-select-item'; /** * Asset (UI Dto / Type Safe) @@ -7,12 +11,24 @@ import {UiAsset} from '@sovity.de/edc-client'; */ export type Asset = Omit< UiAsset, + | 'language' + | 'dataCategory' + | 'dataSubcategory' + | 'transportMode' | 'additionalProperties' | 'additionalJsonProperties' | 'privateProperties' | 'privateJsonProperties' > & { connectorEndpoint: string; + + language: LanguageSelectItem | null; + + // MDS Specific + dataCategory: DataCategorySelectItem | null; + dataSubcategory: DataSubcategorySelectItem | null; + transportMode: TransportModeSelectItem | null; + // Unhandled Additional Properties additionalProperties: AdditionalAssetProperty[]; }; diff --git a/src/app/routes/broker-ui/catalog-page/catalog-page/mapping/broker-catalog-mapper.ts b/src/app/routes/broker-ui/catalog-page/catalog-page/mapping/broker-catalog-mapper.ts index 8d5487bef..e376b3f7e 100644 --- a/src/app/routes/broker-ui/catalog-page/catalog-page/mapping/broker-catalog-mapper.ts +++ b/src/app/routes/broker-ui/catalog-page/catalog-page/mapping/broker-catalog-mapper.ts @@ -23,9 +23,10 @@ export class BrokerCatalogMapper { ...offer, asset: this.assetPropertyMapper.buildAsset({ connectorEndpoint: offer.connectorEndpoint, - uiAsset: this.assetPropertyMapper.buildUiAssetfromprops( - offer.properties, - ), + uiAsset: { + assetId: offer.properties['asset:prop:id'], + name: offer.properties['asset:prop:id'], + }, }), }; } From 1eaa7b37aab293813f61709f7016e5ab42bedfd7 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Fri, 22 Sep 2023 08:05:59 +0200 Subject: [PATCH 8/9] Update asset-service-mapped.ts --- src/app/core/services/asset-service-mapped.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/core/services/asset-service-mapped.ts b/src/app/core/services/asset-service-mapped.ts index 1a29ec0e6..3a6aade51 100644 --- a/src/app/core/services/asset-service-mapped.ts +++ b/src/app/core/services/asset-service-mapped.ts @@ -25,7 +25,7 @@ export class AssetServiceMapped { assetPage.assets.map((uiAsset) => this.assetPropertyMapper.buildAsset({ connectorEndpoint: this.config.connectorEndpoint, - uiAsset: uiAsset, + uiAsset, }), ), ), From 034f523d844ae53c16edb7d6b2486ce5ec3ddd9f Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Fri, 22 Sep 2023 08:08:44 +0200 Subject: [PATCH 9/9] Update contract-offer.service.ts --- src/app/core/services/api/contract-offer.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/core/services/api/contract-offer.service.ts b/src/app/core/services/api/contract-offer.service.ts index 3d6521e78..2e1dce287 100644 --- a/src/app/core/services/api/contract-offer.service.ts +++ b/src/app/core/services/api/contract-offer.service.ts @@ -60,7 +60,7 @@ export class ContractOfferService { return { ...contractOfferDto, asset: this.assetPropertyMapper.buildAsset({ - connectorEndpoint: connectorEndpoint, + connectorEndpoint, uiAsset: contractOfferDto.asset, }), };