Skip to content

Commit

Permalink
Merge branch '472-use-new-type-safe-asset-in-ui' of https://github.co…
Browse files Browse the repository at this point in the history
…m/sovity/edc-ui into 394-use-new-create-contract-definition-endpoint-in-ui

# Conflicts:
#	src/app/core/services/api/edc-api.service.ts
#	src/app/core/services/api/fake-backend/asset-fake-service.ts
#	src/app/core/services/api/fake-backend/data/test-assets.ts
  • Loading branch information
SaadEGI committed Sep 20, 2023
2 parents 4793366 + a026525 commit c8f0868
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 49 deletions.
30 changes: 26 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/app/core/services/api/edc-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ export class EdcApiService {
createAsset(
uiAssetCreateRequest: UiAssetCreateRequest,
): Observable<IdResponseDto> {
return from(
this.edcClient.uiApi.createAsset({
uiAssetCreateRequest,
}),
);
return from(this.edcClient.uiApi.createAsset({uiAssetCreateRequest}));
}

getAssetPage(): Observable<AssetPage> {
Expand Down
24 changes: 18 additions & 6 deletions src/app/core/services/api/fake-backend/asset-fake-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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()};
};
54 changes: 30 additions & 24 deletions src/app/core/services/api/fake-backend/data/test-assets.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,58 @@
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: {},
};

export function toAssetDto(entry: UiAsset): AssetDto {
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: {},
};
}
Expand Down
55 changes: 47 additions & 8 deletions src/app/core/services/asset-entry-builder.ts
Original file line number Diff line number Diff line change
@@ -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: {},
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit c8f0868

Please sign in to comment.