From a0265254af4fa600f481fbee797cda06b918b946 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Wed, 20 Sep 2023 12:02:00 +0200 Subject: [PATCH] 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(() => {