diff --git a/package-lock.json b/package-lock.json index f73ba308b..c69106f6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", @@ -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/src/app/core/services/api/edc-api.service.ts b/src/app/core/services/api/edc-api.service.ts index c2337a11e..8097680b6 100644 --- a/src/app/core/services/api/edc-api.service.ts +++ b/src/app/core/services/api/edc-api.service.ts @@ -37,11 +37,7 @@ export class EdcApiService { createAsset( uiAssetCreateRequest: UiAssetCreateRequest, ): Observable { - return from( - this.edcClient.uiApi.createAsset({ - uiAssetCreateRequest, - }), - ); + 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 892bb36aa..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 @@ -4,7 +4,6 @@ import { UiAsset, UiAssetCreateRequest, } from '@sovity.de/edc-client'; -import {AssetProperties} from '../../asset-properties'; import {TestAssets} from './data/test-assets'; export let assets: UiAsset[] = [TestAssets.full, TestAssets.boring]; @@ -17,18 +16,31 @@ export const assetPage = (): AssetPage => { export const createAsset = (asset: UiAssetCreateRequest): IdResponseDto => { assets.push({ - assetId: asset.assetId, - - 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 563cc26a2..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,34 +1,38 @@ -import {AssetDto, UiAsset} 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: UiAsset = { - assetId: 'my-test-asset-1', - name: 'Test Asset 1', - description: 'This is a test asset.', + properties: { + [AssetProperties.id]: 'test-asset-1', + [AssetProperties.name]: 'Test Asset 1', + [AssetProperties.description]: 'This is a test asset.', + }, privateProperties: { 'some-private-property': 'abc', }, }; 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: + [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.', - 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', - + [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: {}, }; @@ -36,17 +40,19 @@ export namespace TestAssets { return { assetId: entry.assetId, createdAt: new Date(), - properties: {}, + properties: entry.properties, }; } export function toDummyAsset(entry: UiAsset): UiAsset { - return dummyAsset(entry.assetId); + return dummyAsset(entry.assetId[AssetProperties.id]); } export function dummyAsset(assetId: string): UiAsset { return { - assetId, + properties: { + [AssetProperties.id]: assetId, + }, privateProperties: {}, }; } 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(() => {