Skip to content

Commit

Permalink
feat: migrate data address properties (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtreier authored Sep 25, 2023
1 parent cc84938 commit 080d43d
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {APP_CONFIG, AppConfig} from '../config/app-config';
import {DataAddressMapper} from './data-address-mapper';

@Injectable()
export class AssetEntryBuilder {
export class AssetRequestBuilder {
constructor(
@Inject(APP_CONFIG) private config: AppConfig,
private dataAddressMapper: DataAddressMapper,
Expand Down
19 changes: 19 additions & 0 deletions src/app/core/services/data-address-properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const EDC = 'https://w3id.org/edc/v0.0.1/ns/';

export const DataAddressProperty = {
authCode: `${EDC}authCode`,
authKey: `${EDC}authKey`,
baseUrl: `${EDC}baseUrl`,
body: `${EDC}body`,
header: `${EDC}header`,
mediaType: `${EDC}mediaType`,
method: `${EDC}method`,
pathSegments: `${EDC}pathSegments`,
proxyBody: `${EDC}proxyBody`,
proxyMethod: `${EDC}proxyMethod`,
proxyPath: `${EDC}proxyPath`,
proxyQueryParams: `${EDC}proxyQueryParams`,
queryParams: `${EDC}queryParams`,
secretName: `${EDC}secretName`,
type: `${EDC}type`,
};
46 changes: 25 additions & 21 deletions src/app/core/services/http-params-mapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {AssetDatasourceFormValue} from '../../routes/connector-ui/asset-page/ass
import {HttpDatasourceHeaderFormValue} from '../../routes/connector-ui/asset-page/asset-create-dialog/model/http-datasource-header-form-model';
import {HttpDatasourceQueryParamFormValue} from '../../routes/connector-ui/asset-page/asset-create-dialog/model/http-datasource-query-param-form-model';
import {ContractAgreementTransferDialogFormValue} from '../../routes/connector-ui/contract-agreement-page/contract-agreement-transfer-dialog/contract-agreement-transfer-dialog-form-model';
import {removeNullValues} from '../utils/record-utils';
import {mapKeys, removeNullValues} from '../utils/record-utils';
import {everythingAfter, everythingBefore} from '../utils/string-utils';
import {DataAddressProperty} from './data-address-properties';
import {Asset} from './models/asset';
import {HttpRequestParams} from './models/http-request-params';

Expand Down Expand Up @@ -46,33 +47,36 @@ export class HttpRequestParamsMapper {
asset.httpDatasourceHintsProxyBody;

return removeNullValues({
method: proxyMethod ? method : null,
pathSegments: proxyPath ? pathSegments : null,
queryParams: proxyQueryParams ? queryParams : null,
body: proxyBody ? body : null,
mediaType: proxyBody ? contentType : null,
[DataAddressProperty.method]: proxyMethod ? method : null,
[DataAddressProperty.pathSegments]: proxyPath ? pathSegments : null,
[DataAddressProperty.queryParams]: proxyQueryParams ? queryParams : null,
[DataAddressProperty.body]: proxyBody ? body : null,
[DataAddressProperty.mediaType]: proxyBody ? contentType : null,
});
}

encodeHttpRequestParams(
httpRequestParams: HttpRequestParams,
): Record<string, string> {
const bool = (b?: boolean | null) => (b ? 'true' : null);

const props: Record<string, string | null> = {
type: 'HttpData',
baseUrl: httpRequestParams.baseUrl,
method: httpRequestParams.method,
authKey: httpRequestParams.authHeaderName,
authCode: httpRequestParams.authHeaderValue,
secretName: httpRequestParams.authHeaderSecretName,
proxyMethod: httpRequestParams.proxyMethod ? 'true' : null,
proxyPath: httpRequestParams.proxyPath ? 'true' : null,
proxyQueryParams: httpRequestParams.proxyQueryParams ? 'true' : null,
proxyBody: httpRequestParams.proxyBody ? 'true' : null,
queryParams: httpRequestParams.queryParams,
...Object.fromEntries(
Object.entries(httpRequestParams.headers).map(
([headerName, headerValue]) => [`header:${headerName}`, headerValue],
),
[DataAddressProperty.type]: 'HttpData',
[DataAddressProperty.baseUrl]: httpRequestParams.baseUrl,
[DataAddressProperty.method]: httpRequestParams.method,
[DataAddressProperty.authKey]: httpRequestParams.authHeaderName,
[DataAddressProperty.authCode]: httpRequestParams.authHeaderValue,
[DataAddressProperty.secretName]: httpRequestParams.authHeaderSecretName,
[DataAddressProperty.proxyMethod]: bool(httpRequestParams.proxyMethod),
[DataAddressProperty.proxyPath]: bool(httpRequestParams.proxyPath),
[DataAddressProperty.proxyQueryParams]: bool(
httpRequestParams.proxyQueryParams,
),
[DataAddressProperty.proxyBody]: bool(httpRequestParams.proxyBody),
[DataAddressProperty.queryParams]: httpRequestParams.queryParams,
...mapKeys(
httpRequestParams.headers,
(k) => `${DataAddressProperty.header}:${k}`,
),
};
return removeNullValues(props);
Expand Down
16 changes: 16 additions & 0 deletions src/app/core/utils/record-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,19 @@ export function removeNullValues(
Object.entries(obj).filter(([_, v]) => v != null) as [string, string][],
);
}

/**
* Maps keys of a given object
* @param obj object
* @param mapFn key mapper
* @return new object with keys mapped
*/
export function mapKeys<
K extends string | number | symbol,
L extends string | number | symbol,
V,
>(obj: Record<K, V>, mapFn: (key: K) => L): Record<L, V> {
return Object.fromEntries(
Object.entries(obj).map(([k, v]) => [mapFn(k as K), v]),
) as Record<L, V>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {MatDialogRef} from '@angular/material/dialog';
import {Subject} from 'rxjs';
import {finalize, takeUntil} from 'rxjs/operators';
import {EdcApiService} from '../../../../core/services/api/edc-api.service';
import {AssetEntryBuilder} from '../../../../core/services/asset-entry-builder';
import {AssetRequestBuilder} from '../../../../core/services/asset-request-builder';
import {NotificationService} from '../../../../core/services/notification.service';
import {ValidationMessages} from '../../../../core/validators/validation-messages';
import {AssetCreateDialogForm} from './asset-create-dialog-form';
Expand All @@ -19,7 +19,7 @@ import {AssetMetadataFormBuilder} from './model/asset-metadata-form-builder';
AssetAdvancedFormBuilder,
AssetDatasourceFormBuilder,
AssetCreateDialogForm,
AssetEntryBuilder,
AssetRequestBuilder,
AssetMetadataFormBuilder,
],
})
Expand All @@ -32,7 +32,7 @@ export class AssetCreateDialogComponent implements OnDestroy {
private edcApiService: EdcApiService,
public form: AssetCreateDialogForm,
public validationMessages: ValidationMessages,
private assetEntryBuilder: AssetEntryBuilder,
private assetEntryBuilder: AssetRequestBuilder,
private notificationService: NotificationService,
private dialogRef: MatDialogRef<AssetCreateDialogComponent>,
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {Subject} from 'rxjs';
import {finalize} from 'rxjs/operators';
import {ContractAgreementTransferRequest} from '@sovity.de/edc-client';
import {EdcApiService} from '../../../../core/services/api/edc-api.service';
import {AssetEntryBuilder} from '../../../../core/services/asset-entry-builder';
import {DataAddressMapper} from '../../../../core/services/data-address-mapper';
import {HttpRequestParamsMapper} from '../../../../core/services/http-params-mapper.service';
import {NotificationService} from '../../../../core/services/notification.service';
Expand All @@ -17,7 +16,7 @@ import {ContractAgreementTransferDialogResult} from './contract-agreement-transf
@Component({
selector: 'contract-agreement-transfer-dialog',
templateUrl: './contract-agreement-transfer-dialog.component.html',
providers: [ContractAgreementTransferDialogForm, AssetEntryBuilder],
providers: [ContractAgreementTransferDialogForm],
})
export class ContractAgreementTransferDialogComponent implements OnDestroy {
loading = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {Subject} from 'rxjs';
import {finalize, takeUntil} from 'rxjs/operators';
import {PolicyDefinitionDto} from '@sovity.de/edc-client';
import {EdcApiService} from '../../../../core/services/api/edc-api.service';
import {AssetEntryBuilder} from '../../../../core/services/asset-entry-builder';
import {AssetServiceMapped} from '../../../../core/services/asset-service-mapped';
import {ContractDefinitionBuilder} from '../../../../core/services/contract-definition-builder';
import {Asset} from '../../../../core/services/models/asset';
Expand All @@ -16,7 +15,7 @@ import {ContractDefinitionEditorDialogResult} from './contract-definition-editor
@Component({
selector: 'contract-definition-editor-dialog',
templateUrl: './contract-definition-editor-dialog.component.html',
providers: [ContractDefinitionEditorDialogForm, AssetEntryBuilder],
providers: [ContractDefinitionEditorDialogForm],
})
export class ContractDefinitionEditorDialog implements OnInit, OnDestroy {
policies: PolicyDefinitionDto[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {MatDialogRef} from '@angular/material/dialog';
import {Subject} from 'rxjs';
import {finalize, takeUntil} from 'rxjs/operators';
import {EdcApiService} from '../../../../core/services/api/edc-api.service';
import {AssetEntryBuilder} from '../../../../core/services/asset-entry-builder';
import {NotificationService} from '../../../../core/services/notification.service';
import {PolicyDefinitionBuilder} from '../../../../core/services/policy-definition-builder';
import {ValidationMessages} from '../../../../core/validators/validation-messages';
Expand All @@ -13,7 +12,7 @@ import {NewPolicyDialogResult} from './new-policy-dialog-result';
@Component({
selector: 'new-policy-dialog',
templateUrl: './new-policy-dialog.component.html',
providers: [NewPolicyDialogForm, AssetEntryBuilder],
providers: [NewPolicyDialogForm],
})
export class NewPolicyDialogComponent implements OnDestroy {
loading = false;
Expand Down

0 comments on commit 080d43d

Please sign in to comment.