Skip to content

Commit

Permalink
chore: fix transfer endpoints (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtreier authored Oct 13, 2023
1 parent 8d5e732 commit 67360f4
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 35 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@ng-apimock/core": "^3.11.0",
"@ngxs/store": "^3.8.1",
"@sovity.de/broker-server-client": "0.20230712.71619-main-a4860cff",
"@sovity.de/edc-client": "0.20231006.85703-main-5ece112d",
"@sovity.de/edc-client": "0.20231013.91512-main-9754e5d2",
"clean-deep": "^3.4.0",
"date-fns": "^2.30.0",
"dotenv": "^16.3.1",
Expand Down
17 changes: 14 additions & 3 deletions src/app/core/services/api/edc-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import {
AssetPage,
ConnectorLimits,
ContractAgreementPage,
ContractAgreementTransferRequest,
ContractDefinitionPage,
ContractDefinitionRequest,
ContractNegotiationRequest,
DashboardPage,
EdcClient,
IdResponseDto,
InitiateCustomTransferRequest,
InitiateTransferRequest,
PolicyDefinitionCreateRequest,
PolicyDefinitionPage,
TransferHistoryPage,
Expand Down Expand Up @@ -126,10 +127,20 @@ export class EdcApiService {
}

initiateTransfer(
contractAgreementTransferRequest: ContractAgreementTransferRequest,
initiateTransferRequest: InitiateTransferRequest,
): Observable<IdResponseDto> {
return from(
this.edcClient.uiApi.initiateTransfer({contractAgreementTransferRequest}),
this.edcClient.uiApi.initiateTransfer({initiateTransferRequest}),
);
}

initiateCustomTransfer(
initiateCustomTransferRequest: InitiateCustomTransferRequest,
): Observable<IdResponseDto> {
return from(
this.edcClient.uiApi.initiateCustomTransfer({
initiateCustomTransferRequest,
}),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/core/services/api/fake-backend/edc-fake-backend.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
AssetPageToJSON,
ContractAgreementPageToJSON,
ContractAgreementTransferRequestFromJSON,
ContractDefinitionPageToJSON,
ContractDefinitionRequestFromJSON,
ContractNegotiationRequestFromJSON,
DashboardPageToJSON,
FetchAPI,
IdResponseDtoToJSON,
InitiateTransferRequestFromJSON,
PolicyDefinitionCreateRequestFromJSON,
PolicyDefinitionPageToJSON,
TransferHistoryPageToJSON,
Expand Down Expand Up @@ -161,7 +161,7 @@ export const EDC_FAKE_BACKEND: FetchAPI = async (

.url('pages/contract-agreement-page/transfers')
.on('POST', () => {
const transferRequest = ContractAgreementTransferRequestFromJSON(body);
const transferRequest = InitiateTransferRequestFromJSON(body);
const created = contractAgreementInitiateTransfer(transferRequest);
return ok(IdResponseDtoToJSON(created));
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
ContractAgreementCard,
ContractAgreementPage,
ContractAgreementTransferProcess,
ContractAgreementTransferRequest,
IdResponseDto,
InitiateTransferRequest,
} from '@sovity.de/edc-client';
import {Patcher, patchObj} from '../../../../utils/object-utils';
import {TestAssets} from './data/test-assets';
Expand Down Expand Up @@ -132,9 +132,9 @@ export const addContractAgreement = (
};

export const contractAgreementInitiateTransfer = (
request: ContractAgreementTransferRequest,
request: InitiateTransferRequest,
): IdResponseDto => {
const contractAgreementId = request?.params?.contractAgreementId ?? '';
const contractAgreementId = request?.contractAgreementId ?? '';
const transferProcessId =
'transfer-process-' + Math.random().toString().substring(2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {Component, Inject, OnDestroy} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {Subject} from 'rxjs';
import {Observable, Subject} from 'rxjs';
import {finalize} from 'rxjs/operators';
import {ContractAgreementTransferRequest} from '@sovity.de/edc-client';
import {
IdResponseDto,
InitiateCustomTransferRequest,
InitiateTransferRequest,
} from '@sovity.de/edc-client';
import {EdcApiService} from '../../../../core/services/api/edc-api.service';
import {DataAddressMapper} from '../../../../core/services/data-address-mapper';
import {HttpRequestParamsMapper} from '../../../../core/services/http-params-mapper.service';
Expand Down Expand Up @@ -83,8 +87,17 @@ export class ContractAgreementTransferDialogComponent implements OnDestroy {
this.loading = true;
this.form.all.disable();

this.edcApiService
.initiateTransfer(this.buildTransferRequest(this.form.value))
const value = this.form.value;
let request$: Observable<IdResponseDto>;
if (value.dataAddressType === 'Custom-Transfer-Process-Request') {
const request = this.buildCustomTransferRequest(value);
request$ = this.edcApiService.initiateCustomTransfer(request);
} else {
const request = this.buildTransferRequest(value);
request$ = this.edcApiService.initiateTransfer(request);
}

request$
.pipe(
finalize(() => {
this.loading = false;
Expand Down Expand Up @@ -117,18 +130,7 @@ export class ContractAgreementTransferDialogComponent implements OnDestroy {

private buildTransferRequest(
value: ContractAgreementTransferDialogFormValue,
): ContractAgreementTransferRequest {
if (value.dataAddressType === 'Custom-Transfer-Process-Request') {
const customJson: any = JSON.parse(
value.transferProcessRequest?.trim() ?? '',
);

return {
type: 'CUSTOM_JSON',
customJson: JSON.stringify(customJson),
};
}

): InitiateTransferRequest {
const transferProcessProperties =
this.httpRequestParamsMapper.encodeHttpProxyTransferRequestProperties(
this.data.asset,
Expand All @@ -139,12 +141,18 @@ export class ContractAgreementTransferDialogComponent implements OnDestroy {
this.dataAddressMapper.buildDataAddressProperties(value) ?? {};

return {
type: 'PARAMS_ONLY',
params: {
contractAgreementId: this.data.contractId,
transferProcessProperties,
dataSinkProperties,
},
contractAgreementId: this.data.contractId,
transferProcessProperties,
dataSinkProperties,
};
}

private buildCustomTransferRequest(
value: ContractAgreementTransferDialogFormValue,
): InitiateCustomTransferRequest {
return {
contractAgreementId: this.data.contractId,
transferProcessRequestJsonLd: value.transferProcessRequest,
};
}
}

0 comments on commit 67360f4

Please sign in to comment.