Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use CreateDataOffer API #825

Merged
merged 28 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ the detailed section referring to by linking pull requests or issues.

#### Patch

- Used createDataOffer endpoint to create an asset, policies and a contract
definition in a single call
([#841](https://github.com/sovity/edc-ui/issues/841))

### Deployment Migration Notes

_No special deployment migration steps required_
Expand All @@ -36,10 +40,14 @@ Various bugfixes.

#### Patch

- Changed wording on the data offer creation page ([#817](https://github.com/sovity/edc-ui/issues/795))
- Data Offer details now display the contract ID for each contract offer ([#795](https://github.com/sovity/edc-ui/issues/795))
- Warn the user when using an invalid Policy Id ([#746](https://github.com/sovity/edc-ui/issues/746))
- Warn the user when using an invalid Data Offer Id ([#745](https://github.com/sovity/edc-ui/issues/745))
- Changed wording on the data offer creation page
([#817](https://github.com/sovity/edc-ui/issues/795))
- Data Offer details now display the contract ID for each contract offer
([#795](https://github.com/sovity/edc-ui/issues/795))
- Warn the user when using an invalid Policy Id
([#746](https://github.com/sovity/edc-ui/issues/746))
- Warn the user when using an invalid Data Offer Id
([#745](https://github.com/sovity/edc-ui/issues/745))
- Fixed time restriction upper bound "local day to datetime" conversion issues
([#815](https://github.com/sovity/edc-ui/issues/815))

Expand Down
14 changes: 7 additions & 7 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 @@
"@angular/router": "^14.3.0",
"@ng-apimock/core": "^3.11.0",
"@ngxs/store": "^3.8.1",
"@sovity.de/edc-client": "0.20240805.72446-main-4f0ae71b",
"@sovity.de/edc-client": "10.4.0",
"clean-deep": "^3.4.0",
"date-fns": "^2.30.0",
"date-fns-tz": "^2.0.1",
Expand Down
9 changes: 9 additions & 0 deletions src/app/core/services/api/edc-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ContractDefinitionPage,
ContractDefinitionRequest,
ContractNegotiationRequest,
CreateDataOfferRequest,
DashboardPage,
EdcClient,
GetContractAgreementPageRequest,
Expand Down Expand Up @@ -129,6 +130,14 @@ export class EdcApiService {
);
}

createDataOffer(
dataOfferCreationRequest: CreateDataOfferRequest,
): Observable<IdResponseDto> {
return toObservable(() =>
this.edcClient.uiApi.createDataOffer(dataOfferCreationRequest),
);
}

getCatalogPageDataOffers(
connectorEndpoint: string,
): Observable<UiDataOffer[]> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {
DataOfferCreationRequest,
DataOfferCreationRequestPolicyEnum,
IdResponseDto,
UiCriterionLiteralType,
} from '@sovity.de/edc-client';
import {ALWAYS_TRUE_POLICY_ID} from 'src/app/component-library/edit-asset-form/edit-asset-form/form/model/always-true-policy-id';
import {assetIdAvailable, createAsset} from './asset-fake-service';
import {
contractDefinitionIdAvailable,
createContractDefinition,
} from './contract-definition-fake-service';
import {
createPolicyDefinitionV2,
policyDefinitionIdAvailable,
} from './policy-definition-fake-service';

const checkIdAvailability = (id: string): void => {
if (
!policyDefinitionIdAvailable(id).available ||
!assetIdAvailable(id).available ||
!contractDefinitionIdAvailable(id).available
) {
throw new Error('Id already exists');
}
};

export const createDataOffer = (
request: DataOfferCreationRequest,
): IdResponseDto => {
const commonId = request.uiAssetCreateRequest.id;
let accessPolicyId = null;
let contractPolicyId = null;

checkIdAvailability(commonId);
createAsset(request.uiAssetCreateRequest);

switch (request.policy) {
case DataOfferCreationRequestPolicyEnum.DontPublish:
return {id: commonId, lastUpdatedDate: new Date()};
case DataOfferCreationRequestPolicyEnum.PublishRestricted:
createPolicyDefinitionV2({
policyDefinitionId: commonId,
expression: request.uiPolicyExpression!,
});
accessPolicyId = commonId;
contractPolicyId = commonId;
break;
case DataOfferCreationRequestPolicyEnum.PublishUnrestricted:
accessPolicyId = ALWAYS_TRUE_POLICY_ID;
contractPolicyId = ALWAYS_TRUE_POLICY_ID;
break;
}

createContractDefinition({
contractDefinitionId: commonId,
accessPolicyId,
contractPolicyId,
assetSelector: [
{
operandLeft: commonId,
operator: 'EQ',
operandRight: {
type: UiCriterionLiteralType.Value,
value: commonId,
},
},
],
});

return {id: commonId, lastUpdatedDate: new Date()};
};
14 changes: 12 additions & 2 deletions src/app/core/services/api/fake-backend/edc-fake-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ContractNegotiationRequestFromJSON,
ContractTerminationRequestFromJSON,
DashboardPageToJSON,
DataOfferCreationRequestFromJSON,
FetchAPI,
IdAvailabilityResponseToJSON,
IdResponseDtoToJSON,
Expand Down Expand Up @@ -46,6 +47,7 @@ import {
} from './connector-fake-impl/contract-negotiation-fake-service';
import {initiateContractTermination} from './connector-fake-impl/contract-termination-fake-service';
import {dashboardPage} from './connector-fake-impl/dashboard-fake-service';
import {createDataOffer} from './connector-fake-impl/data-offer-fake-service';
import {connectorLimits} from './connector-fake-impl/ee-fake-service';
import {
createPolicyDefinition,
Expand Down Expand Up @@ -194,8 +196,10 @@ export const EDC_FAKE_BACKEND: FetchAPI = async (
.url('ui/pages/contract-agreement-page/*')
.on('GET', (contractAgreementId: String) => {
return ok(
contractAgreementPage().contractAgreements
.find( (contractAgreement) => contractAgreement.contractAgreementId === contractAgreementId)
contractAgreementPage().contractAgreements.find(
(contractAgreement) =>
contractAgreement.contractAgreementId === contractAgreementId,
),
);
})

Expand Down Expand Up @@ -234,6 +238,12 @@ export const EDC_FAKE_BACKEND: FetchAPI = async (
return ok(ConnectorLimitsToJSON(limits));
})

.url('ui/pages/create-data-offer')
.on('POST', () => {
const response = createDataOffer(DataOfferCreationRequestFromJSON(body));
return ok(IdResponseDtoToJSON(response));
})

.url('ui/pages/data-offer-page/validate-asset-id/*')
.on('GET', (assetId) => {
const response = assetIdAvailable(assetId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {EMPTY, Observable, catchError, concat, finalize, tap} from 'rxjs';
import {EMPTY, Observable, catchError, finalize, tap} from 'rxjs';
import {
DataOfferCreationRequestPolicyEnum,
IdResponseDto,
UiAssetEditRequest,
UiCriterionLiteralType,
} from '@sovity.de/edc-client';
import {AssetAdvancedFormBuilder} from 'src/app/component-library/edit-asset-form/edit-asset-form/form/asset-advanced-form-builder';
import {AssetDatasourceFormBuilder} from 'src/app/component-library/edit-asset-form/edit-asset-form/form/asset-datasource-form-builder';
import {AssetGeneralFormBuilder} from 'src/app/component-library/edit-asset-form/edit-asset-form/form/asset-general-form-builder';
import {EditAssetForm} from 'src/app/component-library/edit-asset-form/edit-asset-form/form/edit-asset-form';
import {EditAssetFormInitializer} from 'src/app/component-library/edit-asset-form/edit-asset-form/form/edit-asset-form-initializer';
import {ALWAYS_TRUE_POLICY_ID} from 'src/app/component-library/edit-asset-form/edit-asset-form/form/model/always-true-policy-id';
import {EditAssetFormValue} from 'src/app/component-library/edit-asset-form/edit-asset-form/form/model/edit-asset-form-model';
import {ExpressionFormControls} from 'src/app/component-library/policy-editor/editor/expression-form-controls';
import {ExpressionFormHandler} from 'src/app/component-library/policy-editor/editor/expression-form-handler';
import {EdcApiService} from 'src/app/core/services/api/edc-api.service';
import {AssetRequestBuilder} from 'src/app/core/services/asset-request-builder';
import {AssetService} from 'src/app/core/services/asset.service';
import {AssetProperty} from 'src/app/core/services/models/asset-properties';
import {Fetched} from 'src/app/core/services/models/fetched';
import {UiAssetMapped} from 'src/app/core/services/models/ui-asset-mapped';
import {NotificationService} from 'src/app/core/services/notification.service';
Expand Down Expand Up @@ -130,21 +128,30 @@ export class AssetEditPageComponent implements OnInit {
this.assetRequestBuilder.buildAssetCreateRequest(formValue);

if (publishMode === 'PUBLISH_UNRESTRICTED') {
return concat(
this.edcApiService.createAsset(assetCreateRequest),
this.createContractDefinition(assetId, ALWAYS_TRUE_POLICY_ID),
);
return this.edcApiService.createDataOffer({
dataOfferCreationRequest: {
uiAssetCreateRequest: assetCreateRequest,
policy: DataOfferCreationRequestPolicyEnum.PublishUnrestricted,
uiPolicyExpression:
this.expressionFormHandler.toUiPolicyExpression(),
},
});
} else if (publishMode === 'PUBLISH_RESTRICTED') {
return concat(
this.edcApiService.createAsset(assetCreateRequest),
this.edcApiService.createPolicyDefinitionV2({
policyDefinitionId: assetId,
expression: this.expressionFormHandler.toUiPolicyExpression(),
}),
this.createContractDefinition(assetId, assetId),
);
return this.edcApiService.createDataOffer({
dataOfferCreationRequest: {
uiAssetCreateRequest: assetCreateRequest,
policy: DataOfferCreationRequestPolicyEnum.PublishRestricted,
uiPolicyExpression:
this.expressionFormHandler.toUiPolicyExpression(),
},
});
} else {
return this.edcApiService.createAsset(assetCreateRequest);
return this.edcApiService.createDataOffer({
dataOfferCreationRequest: {
uiAssetCreateRequest: assetCreateRequest,
policy: DataOfferCreationRequestPolicyEnum.DontPublish,
},
});
}
}

Expand All @@ -164,25 +171,4 @@ export class AssetEditPageComponent implements OnInit {

throw new Error(`Unsupported mode: ${mode}`);
}

private createContractDefinition(
assetId: string,
policyId: string,
): Observable<IdResponseDto> {
return this.edcApiService.createContractDefinition({
accessPolicyId: policyId,
contractPolicyId: policyId,
contractDefinitionId: assetId,
assetSelector: [
{
operandLeft: AssetProperty.id,
operator: 'IN',
operandRight: {
type: UiCriterionLiteralType.ValueList,
valueList: [assetId],
},
},
],
});
}
}
Loading