Skip to content

Commit

Permalink
fix:buildAsset & remove Dead Code
Browse files Browse the repository at this point in the history
  • Loading branch information
SaadEGI committed Sep 21, 2023
1 parent 90ed2e4 commit 51b7f94
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -124,23 +124,23 @@ 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) {
fields.push({
icon: 'commute',
label: 'Data Category',
labelTitle: AssetProperties.dataCategory,
...this.propertyGridUtils.guessValue(asset.dataCategory),
...this.propertyGridUtils.guessValue(asset.dataCategory?.label),
});
}
if (includeEmpty || asset.dataSubcategory) {
fields.push({
icon: 'commute',
label: 'Data Subcategory',
labelTitle: AssetProperties.dataSubcategory,
...this.propertyGridUtils.guessValue(asset.dataSubcategory),
...this.propertyGridUtils.guessValue(asset.dataSubcategory?.label),
});
}
if (includeEmpty || asset.dataModel) {
Expand Down
7 changes: 4 additions & 3 deletions src/app/core/services/api/criterion-type-ext.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {UiCriterionOperatorEnum} from '@sovity.de/edc-client';

export type UiCriterionOperator = UiCriterionOperatorEnum;

export const CRITERION_OPERATOR_SYMBOLS: Record<UiCriterionOperator, string> = {
export const CRITERION_OPERATOR_SYMBOLS: Record<
UiCriterionOperatorEnum,
string
> = {
EQ: '=',
IN: 'in',
LIKE: 'like',
Expand Down
4 changes: 4 additions & 0 deletions src/app/core/services/api/fake-backend/data/test-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/services/asset-entry-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
105 changes: 37 additions & 68 deletions src/app/core/services/asset-property-mapper.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -10,62 +13,55 @@ import {AdditionalAssetProperty, Asset} from './models/asset';
providedIn: 'root',
})
export class AssetPropertyMapper {
buildUiAssetfromprops(props: Record<string, string>): 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 {
additionalProperties,
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'
Expand All @@ -90,31 +86,4 @@ export class AssetPropertyMapper {
}
return result;
}

private buildAdditionalPropertiesforUiAsset(
props: Record<string, string> | 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';
}
}
4 changes: 2 additions & 2 deletions src/app/core/services/asset-service-mapped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export class AssetServiceMapped {
fetchAssets(): Observable<Asset[]> {
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,
}),
),
),
Expand Down
16 changes: 16 additions & 0 deletions src/app/core/services/models/asset.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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[];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
}),
};
}
Expand Down

0 comments on commit 51b7f94

Please sign in to comment.