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

chore: PolicyDefinition UI Migration #458

Merged
merged 4 commits into from
Aug 30, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ the detailed section referring to by linking pull requests or issues.
- Removed 404-causing login polling from broker UI

- Migrated transfer history page to api wrapper
- Migrated contract definition page to api wrapper
- Migrated policy definition page to api wrapper
- Migrated asset page to api wrapper

#### Removed

Expand Down
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.20230829.91501-main-0b8664eb",
"@sovity.de/edc-client": "0.20230830.143816-main-db6adca7",
"clean-deep": "^3.4.0",
"date-fns": "^2.30.0",
"dotenv": "^16.3.1",
Expand Down
24 changes: 22 additions & 2 deletions src/app/core/services/api/edc-api.service.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import {Inject, Injectable} from '@angular/core';
import {Observable, from} from 'rxjs';
import {
AssetCreateRequest,
AssetDto,
AssetPage,
ConnectorLimits,
ContractAgreementPage,
ContractAgreementTransferRequest,
ContractDefinitionPage,
ContractDefinitionRequest,
EdcClient,
IdResponse,
IdResponseDto,
PolicyDefinitionCreateRequest,
PolicyDefinitionPage,
TransferHistoryPage,
buildEdcClient,
} from '@sovity.de/edc-client';
import {AssetCreateRequest} from '@sovity.de/edc-client/dist/generated/models/AssetCreateRequest';
import {ContractDefinitionRequest} from '@sovity.de/edc-client/dist/generated/models/ContractDefinitionRequest';
import {APP_CONFIG, AppConfig} from '../../config/app-config';
import {EDC_FAKE_BACKEND} from './fake-backend/edc-fake-backend';

Expand Down Expand Up @@ -68,6 +70,24 @@ export class EdcApiService {
);
}

createPolicyDefinition(
policyDefinitionCreateRequest: PolicyDefinitionCreateRequest,
): Observable<IdResponseDto> {
return from(
this.edcClient.uiApi.createPolicyDefinition({
policyDefinitionCreateRequest,
}),
);
}

getPolicyDefinitionPage(): Observable<PolicyDefinitionPage> {
return from(this.edcClient.uiApi.policyDefinitionPage());
}

deletePolicyDefinition(policyId: string): Observable<IdResponseDto> {
return from(this.edcClient.uiApi.deletePolicyDefinition({policyId}));
}

getContractAgreementPage(): Observable<ContractAgreementPage> {
return from(this.edcClient.uiApi.contractAgreementEndpoint());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
ContractDefinitionEntry,
ContractDefinitionPage,
ContractDefinitionRequest,
IdResponseDto,
} from '@sovity.de/edc-client';
import {ContractDefinitionRequest} from '@sovity.de/edc-client/dist/generated/models/ContractDefinitionRequest';
import {AssetProperties} from '../../asset-properties';

export let contractDefinitions: ContractDefinitionEntry[] = [
Expand Down
27 changes: 24 additions & 3 deletions src/app/core/services/api/fake-backend/edc-fake-backend.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import {FetchAPI} from '@sovity.de/edc-client';
import {AssetCreateRequest} from '@sovity.de/edc-client/dist/generated/models/AssetCreateRequest';
import {ContractDefinitionRequest} from '@sovity.de/edc-client/dist/generated/models/ContractDefinitionRequest';
import {
AssetCreateRequest,
ContractDefinitionRequest,
FetchAPI,
PolicyDefinitionCreateRequest,
} from '@sovity.de/edc-client';
import {assetPage, createAsset, deleteAsset} from './asset-fake-service';
import {
contractDefinitionPage,
createContractDefinition,
deleteContractDefinition,
} from './contract-definition-fake-service';
import {
createPolicyDefinition,
deletePolicyDefinition,
policyDefinitionPage,
} from './policy-definition-fake-service';
import {getBody, getMethod, getUrl} from './utils/request-utils';
import {ok} from './utils/response-utils';
import {UrlInterceptor} from './utils/url-interceptor';
Expand Down Expand Up @@ -45,5 +53,18 @@ export const EDC_FAKE_BACKEND: FetchAPI = async (
ok(deleteContractDefinition(contractDefinitionId)),
)

.url('pages/policy-page')
.on('GET', () => ok(policyDefinitionPage()))

.url('pages/policy-page/policy-definitions')
.on('POST', () =>
ok(createPolicyDefinition(body as PolicyDefinitionCreateRequest)),
)

.url('pages/policy-page/policy-definitions/*')
.on('DELETE', (policyDefinitionId) =>
ok(deletePolicyDefinition(policyDefinitionId)),
)

.tryMatch();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
IdResponseDto,
PolicyDefinitionCreateRequest,
PolicyDefinitionDto,
PolicyDefinitionPage,
} from '@sovity.de/edc-client';

export let policyDefinitions: PolicyDefinitionDto[] = [
{
policyDefinitionId: 'test-policy-definition-1',
policy: {
policyJsonLd: '{"example-policy-jsonld": true}',
constraints: [
{
left: 'REFERRING_CONNECTOR',
operator: 'EQ',
right: {type: 'STRING', value: 'https://my-other-connector'},
},
],
errors: [],
},
},
{
policyDefinitionId: 'test-policy-definition-1-with-errors',
policy: {
policyJsonLd: '{"example-policy-jsonld": true}',
constraints: [
{
left: 'REFERRING_CONNECTOR',
operator: 'EQ',
right: {type: 'STRING', value: 'https://my-other-connector'},
},
],
errors: ['test-error-1'],
},
},
{
policyDefinitionId: 'test-policy-definition-3',
policy: {
policyJsonLd: '{"example-policy-jsonld": true}',
constraints: [],
errors: ['No constraints found!'],
},
},
];
export const policyDefinitionPage = (): PolicyDefinitionPage => {
return {policies: policyDefinitions};
};

export const createPolicyDefinition = (
request: PolicyDefinitionCreateRequest,
): IdResponseDto => {
const newPolicyDefinition: PolicyDefinitionDto = {
policyDefinitionId: request.policyDefinitionId,
policy: {
constraints: request.policy.constraints,
errors: [],
policyJsonLd: '{"example-policy-jsonld": true}',
},
};
policyDefinitions = [newPolicyDefinition, ...policyDefinitions];

return {
id: request.policyDefinitionId,
lastUpdatedDate: new Date(),
};
};

export const deletePolicyDefinition = (id: string): IdResponseDto => {
policyDefinitions = policyDefinitions.filter(
(it) => it.policyDefinitionId !== id,
);
return {id, lastUpdatedDate: new Date()};
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-nocheck
import {ApplicationObservabilityService} from './applicationObservability.service';
import {AssetService} from './asset.service';
import {CatalogService} from './catalog.service';
import {ContractAgreementService} from './contractAgreement.service';
import {ContractDefinitionService} from './contractDefinition.service';
Expand All @@ -9,13 +8,10 @@ import {DataplaneSelectorService} from './dataplaneSelector.service';
import {DefaultService} from './default.service';
import {HTTPProvisionerWebhookService} from './hTTPProvisionerWebhook.service';
import {IdentityHubService} from './identityHub.service';
import {PolicyService} from './policy.service';
import {TransferProcessService} from './transferProcess.service';

export * from './applicationObservability.service';

export * from './asset.service';

export * from './catalog.service';

export * from './contractAgreement.service';
Expand All @@ -32,13 +28,10 @@ export * from './hTTPProvisionerWebhook.service';

export * from './identityHub.service';

export * from './policy.service';

export * from './transferProcess.service';

export const APIS = [
ApplicationObservabilityService,
AssetService,
CatalogService,
ContractAgreementService,
ContractDefinitionService,
Expand All @@ -47,6 +40,5 @@ export const APIS = [
DefaultService,
HTTPProvisionerWebhookService,
IdentityHubService,
PolicyService,
TransferProcessService,
];
Loading
Loading