Skip to content

Commit

Permalink
feat: leagacy create asset (part I)
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit committed Aug 5, 2024
1 parent 72a0c7f commit 58dd027
Show file tree
Hide file tree
Showing 51 changed files with 4,012 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function patchAsset(assetId: string, patcher: Patcher<UiAsset>): UiAsset {
}

export const createAsset = (asset: UiAssetCreateRequest): IdResponseDto => {
console.log();
const assetId = asset.id;
assets.push({
assetId,
Expand Down
103 changes: 103 additions & 0 deletions src/app/core/services/asset-data-source-mapper-legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import {Injectable} from '@angular/core';
import {UiDataSource} from '@sovity.de/edc-client';
import {AssetDatasourceFormValue} from '../../routes/connector-ui/asset-page/asset-edit-dialog/form/model/asset-datasource-form-model';
import {HttpDatasourceHeaderFormValue} from '../../routes/connector-ui/asset-page/asset-edit-dialog/form/model/http-datasource-header-form-model';
import {getAuthFields} from '../utils/form-value-utils';
import {QueryParamsMapper} from './query-params-mapper';

@Injectable({providedIn: 'root'})
export class AssetDataSourceMapperLegacy {
constructor(private queryParamsMapper: QueryParamsMapper) {}

buildDataSourceOrNullLegacy(
formValue: AssetDatasourceFormValue,
): UiDataSource | null {
if (formValue.dataAddressType === 'Unchanged') {
return null;
}
return this.buildDataSourceLegacy(formValue);
}

buildDataSourceLegacy(formValue: AssetDatasourceFormValue): UiDataSource {
switch (formValue?.dataAddressType) {
case 'Custom-Data-Address-Json':
return this.buildCustomDataSourceLegacy(formValue);
case 'On-Request':
return this.buildOnRequestDataSourceLegacy(formValue);
case 'Http':
return this.buildHttpDataSourceLegacy(formValue);
default:
throw new Error(
`Invalid Data Address Type ${formValue?.dataAddressType}`,
);
}
}

private buildCustomDataSourceLegacy(
formValue: AssetDatasourceFormValue,
): UiDataSource {
const json = JSON.parse(formValue.dataDestination?.trim()!!);
return {
type: 'CUSTOM',
customProperties: json,
};
}

private buildHttpDataSourceLegacy(
formValue: AssetDatasourceFormValue,
): UiDataSource {
const baseUrl = this.queryParamsMapper.getBaseUrlWithoutQueryParams(
formValue.httpUrl!,
)!;
const queryString = this.queryParamsMapper.getFullQueryString(
formValue.httpUrl!,
formValue.httpQueryParams ?? [],
);

const authFields = getAuthFields(formValue);

return {
type: 'HTTP_DATA',
httpData: {
method: formValue.httpMethod,
baseUrl,
queryString: queryString ?? undefined,
authHeaderName: authFields.authHeaderName ?? undefined,
authHeaderValue: {
secretName: authFields.authHeaderSecretName ?? undefined,
rawValue: authFields.authHeaderValue ?? undefined,
},
headers: this.buildHttpHeaders(formValue.httpHeaders ?? []),
enableMethodParameterization: formValue.httpProxyMethod,
enablePathParameterization: formValue.httpProxyPath,
enableQueryParameterization: formValue.httpProxyQueryParams,
enableBodyParameterization: formValue.httpProxyBody,
},
};
}

private buildOnRequestDataSourceLegacy(
formValue: AssetDatasourceFormValue,
): UiDataSource {
return {
type: 'ON_REQUEST',
onRequest: {
contactEmail: formValue.contactEmail!!,
contactPreferredEmailSubject: formValue.contactPreferredEmailSubject!!,
},
};
}

private buildHttpHeaders(
headers: HttpDatasourceHeaderFormValue[],
): Record<string, string> {
return Object.fromEntries(
headers
.map((header) => [
header.headerName?.trim() || '',
header.headerValue?.trim() || '',
])
.filter((a) => a[0] && a[1]),
);
}
}
111 changes: 111 additions & 0 deletions src/app/core/services/asset-request-builder-legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import {Injectable} from '@angular/core';
import {UiAssetCreateRequest, UiAssetEditRequest} from '@sovity.de/edc-client';
import {AssetEditorDialogFormValue} from '../../routes/connector-ui/asset-page/asset-edit-dialog/form/model/asset-editor-dialog-form-model';
import {toGmtZeroHourDate} from '../utils/date-utils';
import {AssetDataSourceMapperLegacy} from './asset-data-source-mapper-legacy';
import {AssetRequestCommonMetadata} from './asset-request-common-metadata';

@Injectable()
export class AssetRequestBuilderLegacy {
constructor(private assetDataSourceMapper: AssetDataSourceMapperLegacy) {}

buildAssetCreateRequestLegacy(
formValue: AssetEditorDialogFormValue,
): UiAssetCreateRequest {
const id = formValue.metadata?.id!;
const metadata = this.buildAssetRequestCommonMetadataLegacy(formValue);
const dataSource = this.assetDataSourceMapper.buildDataSourceLegacy(
formValue.datasource!,
);
return {
id,
...metadata,
dataSource,
};
}

buildAssetEditRequestLegacy(
formValue: AssetEditorDialogFormValue,
): UiAssetEditRequest {
const metadata = this.buildAssetRequestCommonMetadataLegacy(formValue);
const dataSourceOrNull =
this.assetDataSourceMapper.buildDataSourceOrNullLegacy(
formValue.datasource!,
);
return {
...metadata,
dataSourceOverrideOrNull: dataSourceOrNull ?? undefined,
};
}

buildAssetRequestCommonMetadataLegacy(
formValue: AssetEditorDialogFormValue,
): AssetRequestCommonMetadata {
const title = formValue.metadata?.title!;
const version = formValue.metadata?.version;
const description = formValue.metadata?.description;
const language = formValue.metadata?.language?.id;
const keywords = formValue.metadata?.keywords;
const licenseUrl = formValue.metadata?.standardLicense;
const publisherHomepage = formValue.metadata?.publisher;
const mediaType = formValue.metadata?.contentType;
const landingPageUrl = formValue.metadata?.endpointDocumentation;

const dataCategory = formValue.advanced?.dataCategory?.id;
const dataSubcategory = formValue.advanced?.dataSubcategory?.id;
const transportMode = formValue.advanced?.transportMode?.id;
const geoReferenceMethod = formValue.advanced?.geoReferenceMethod;
const dataModel = formValue.advanced?.dataModel;

const sovereignLegalName = formValue.advanced?.sovereignLegalName;
const geoLocation = formValue.advanced?.geoLocation;
const nutsLocations = formValue.advanced?.nutsLocations;
const dataSampleUrls = formValue.advanced?.dataSampleUrls;
const referenceFileUrls = formValue.advanced?.referenceFileUrls;
const referenceFilesDescription =
formValue.advanced?.referenceFilesDescription;
const conditionsForUse = formValue.advanced?.conditionsForUse;
const dataUpdateFrequency = formValue.advanced?.dataUpdateFrequency;
let temporalCoverageFrom =
formValue.advanced?.temporalCoverage?.from || undefined;
let temporalCoverageToInclusive =
formValue.advanced?.temporalCoverage?.toInclusive || undefined;
temporalCoverageFrom = temporalCoverageFrom
? toGmtZeroHourDate(temporalCoverageFrom)
: undefined;
temporalCoverageToInclusive = temporalCoverageToInclusive
? toGmtZeroHourDate(temporalCoverageToInclusive)
: undefined;

return {
title,
language,
description,
publisherHomepage,
licenseUrl,
version,
keywords,
mediaType,
landingPageUrl,
dataCategory,
dataSubcategory,
dataModel,
geoReferenceMethod,
transportMode,
sovereignLegalName,
geoLocation,
nutsLocations,
dataSampleUrls,
referenceFileUrls,
referenceFilesDescription,
conditionsForUse,
dataUpdateFrequency,
temporalCoverageFrom,
temporalCoverageToInclusive,
customJsonAsString: undefined,
customJsonLdAsString: undefined,
privateCustomJsonAsString: undefined,
privateCustomJsonLdAsString: undefined,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {AssetEditorDialogFormValue} from './form/model/asset-editor-dialog-form-model';

export interface AssetEditDialogData {
initialFormValue: AssetEditorDialogFormValue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type AssetEditDialogMode = 'CREATE' | 'EDIT';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {UiAssetMapped} from '../../../../core/services/models/ui-asset-mapped';

export interface AssetEditDialogResult {
/**
* Updated asset list for the asset page
*/
refreshedList: UiAssetMapped[];

/**
* The updated / created asset
*/
asset: UiAssetMapped;
}
Loading

0 comments on commit 58dd027

Please sign in to comment.