Skip to content

Commit

Permalink
feat: connector client: switch PolicyService (eclipse-edc#90)
Browse files Browse the repository at this point in the history
* feat: switch PolicyDefinition to connector client (eclipse-edc#38)

* feat: fix id and permission on creating new Policy (eclipse-edc#58)

* feat: use get functions for obligations and prohibition in View (eclipse-edc#58)

* feat: remove unnecessary import (eclipse-edc#58)
  • Loading branch information
janpmeyer authored and farhin23 committed Mar 5, 2024
1 parent c0b195f commit dbd6e9e
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 445 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@angular/platform-browser": "~13.3.5",
"@angular/platform-browser-dynamic": "~13.3.5",
"@angular/router": "~13.3.5",
"@think-it-labs/edc-connector-client": "^0.2.0-beta-5",
"@think-it-labs/edc-connector-client": "^0.2.0-beta-6",
"rxjs": "~7.8.1",
"zone.js": "~0.11.4"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Component, Inject, OnInit} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {
AssetService, PolicyDefinitionResponseDto, PolicyService
AssetService, PolicyService
} from "../../../mgmt-api-client";
import { Asset, ContractDefinitionInput } from "../../../mgmt-api-client/model"
import { Asset, ContractDefinitionInput, PolicyDefinition } from "../../../mgmt-api-client/model"


@Component({
Expand All @@ -13,12 +13,12 @@ import { Asset, ContractDefinitionInput } from "../../../mgmt-api-client/model"
})
export class ContractDefinitionEditorDialog implements OnInit {

policies: Array<PolicyDefinitionResponseDto> = [];
policies: Array<PolicyDefinition> = [];
availableAssets: Asset[] = [];
name: string = '';
editMode = false;
accessPolicy?: PolicyDefinitionResponseDto;
contractPolicy?: PolicyDefinitionResponseDto;
accessPolicy?: PolicyDefinition;
contractPolicy?: PolicyDefinition;
assets: Asset[] = [];
contractDefinition: ContractDefinitionInput = {
"@id": '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- ID -->
<mat-form-field class="form-field-stretch" color="accent" id="form-field-id">
<mat-label>ID</mat-label>
<input [(ngModel)]="policyDefinition['@id']" matInput required>
<input [(ngModel)]="policyDefinition.id" matInput required>
</mat-form-field>

<!-- Assigner / Assignee-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Component, Inject, OnInit} from '@angular/core';
import {Policy, PolicyDefinitionResponseDto, PolicyDefinitionRequestDto} from "../../../mgmt-api-client";
import TypeEnum = Policy.TypeEnum;
import {PolicyDefinitionInput, PolicyInput} from "../../../mgmt-api-client/model";
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";

@Component({
Expand All @@ -10,11 +9,11 @@ import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
})
export class NewPolicyDialogComponent implements OnInit {
editMode: boolean = false;
policy: Policy = {
"@type": TypeEnum.Set
policy: PolicyInput = {
"@type": "set"
};
policyDefinition: PolicyDefinitionResponseDto = {
"edc:policy": this.policy,
policyDefinition: PolicyDefinitionInput = {
"policy": this.policy,
"@id": ''
};
permissionsJson: string = '';
Expand All @@ -30,20 +29,24 @@ export class NewPolicyDialogComponent implements OnInit {

onSave() {
if (this.permissionsJson && this.permissionsJson !== '') {
this.policy["odrl:permission"] = JSON.parse(this.permissionsJson);
this.policy.permission = JSON.parse(this.permissionsJson);
}

if (this.prohibitionsJson && this.prohibitionsJson !== '') {
this.policy["odrl:prohibition"] = JSON.parse(this.prohibitionsJson);
this.policy.prohibition = JSON.parse(this.prohibitionsJson);
}

if (this.obligationsJson && this.obligationsJson !== '') {
this.policy["odrl:obligation"] = JSON.parse(this.obligationsJson);
this.policy.obligation = JSON.parse(this.obligationsJson);
}

this.policy["@context"]="http://www.w3.org/ns/odrl.jsonld"


this.dialogRef.close({
policy: this.policyDefinition['edc:policy'],
id: this.policyDefinition['@id']

policy : this.policyDefinition.policy,
'@id': this.policyDefinition.id
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@
<mat-card *ngFor="let policyDef of policyDefinitions" class="policy-card">
<mat-card-header>
<mat-icon mat-card-avatar>policy</mat-icon>
<mat-card-title><span class="code">{{policyDef['@id']}}</span></mat-card-title>
<mat-card-title><span class="code">{{policyDef.id}}</span></mat-card-title>
</mat-card-header>

<mat-card-content>

<mat-list dense>
<mat-list-item>
<mat-icon mat-list-icon>trip_origin</mat-icon>
<div mat-line>{{policyDef['edc:policy']?.assigner || 'n/a'}}</div>
<div mat-line>{{policyDef.policy?.assigner || 'n/a'}}</div>
<div mat-line>Assigner</div>
</mat-list-item>
<mat-list-item>
<mat-icon mat-list-icon>adjust</mat-icon>
<div mat-line>{{policyDef['edc:policy']?.assignee || 'n/a'}}</div>
<div mat-line>{{policyDef.policy?.assignee || 'n/a'}}</div>
<div mat-line>Assignee</div>
</mat-list-item>
</mat-list>

<!-- Permissions-->
<policy-rules [rules]="policyDef['edc:policy']['odrl:permission']" [title]="'Permissions'"></policy-rules>
<policy-rules [rules]="policyDef.policy.permissions" [title]="'Permissions'"></policy-rules>

<!-- Obligations-->
<policy-rules [rules]="policyDef['edc:policy']['odrl:obligation']" [title]="'Obligations'"></policy-rules>
<policy-rules [rules]="policyDef.policy.obligations" [title]="'Obligations'"></policy-rules>

<!-- Prohibitions-->
<policy-rules [rules]="policyDef['edc:policy']['odrl:prohibition']" [title]="'Prohibitions'"></policy-rules>
<policy-rules [rules]="policyDef.policy.prohibitions" [title]="'Prohibitions'"></policy-rules>

</mat-card-content>
<button (click)="delete(policyDef)" mat-stroked-button color="warn" matSuffix>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Component, OnInit} from '@angular/core';
import {IdResponseDto, PolicyDefinitionResponseDto, PolicyService} from "../../../mgmt-api-client";
import {PolicyService} from "../../../mgmt-api-client";
import {BehaviorSubject, Observable, Observer, of} from "rxjs";
import {first, map, switchMap} from "rxjs/operators";
import {MatDialog} from "@angular/material/dialog";
import {NewPolicyDialogComponent} from "../new-policy-dialog/new-policy-dialog.component";
import {NotificationService} from "../../services/notification.service";
import {ConfirmationDialogComponent, ConfirmDialogModel} from "../confirmation-dialog/confirmation-dialog.component";
import {PolicyDefinition, PolicyDefinitionInput, IdResponse} from "../../../mgmt-api-client/model";

@Component({
selector: 'app-policy-view',
Expand All @@ -14,10 +15,10 @@ import {ConfirmationDialogComponent, ConfirmDialogModel} from "../confirmation-d
})
export class PolicyViewComponent implements OnInit {

filteredPolicies$: Observable<PolicyDefinitionResponseDto[]> = of([]);
filteredPolicies$: Observable<PolicyDefinition[]> = of([]);
searchText: string = '';
private fetch$ = new BehaviorSubject(null);
private readonly errorOrUpdateSubscriber: Observer<IdResponseDto>;
private readonly errorOrUpdateSubscriber: Observer<IdResponse>;

constructor(private policyService: PolicyService,
private notificationService: NotificationService,
Expand All @@ -30,7 +31,7 @@ export class PolicyViewComponent implements OnInit {
this.notificationService.showInfo("Successfully completed")
},
}

}

ngOnInit(): void {
Expand All @@ -50,42 +51,41 @@ export class PolicyViewComponent implements OnInit {

onCreate() {
const dialogRef = this.dialog.open(NewPolicyDialogComponent);
dialogRef.afterClosed().pipe(first()).subscribe({
next: (result: PolicyDefinitionResponseDto) => {
if (result) {
this.policyService.createPolicy(result).subscribe(
dialogRef.afterClosed().pipe(first()).subscribe({ next: (newPolicyDefinition: PolicyDefinitionInput) => {
if (newPolicyDefinition) {
this.policyService.createPolicy(newPolicyDefinition).subscribe(
{
next: (response: IdResponseDto) => this.errorOrUpdateSubscriber.next(response),
next: (response: IdResponse) => this.errorOrUpdateSubscriber.next(response),
error: (error: Error) => this.showError(error, "An error occurred while creating the policy.")
}
);
}
}
});
}

/**
* simple full-text search - serialize to JSON and see if "searchText"
* is contained
*/
private isFiltered(policy: PolicyDefinitionResponseDto, searchText: string) {
private isFiltered(policy: PolicyDefinition, searchText: string) {
return JSON.stringify(policy).includes(searchText);
}

delete(policy: PolicyDefinitionResponseDto) {
delete(policy: PolicyDefinition) {

let policyId = policy['@id']!;
const dialogData = ConfirmDialogModel.forDelete("policy", policyId);

const ref = this.dialog.open(ConfirmationDialogComponent, {maxWidth: '20%', data: dialogData});

ref.afterClosed().subscribe({

next: (res: any) => {
if (res) {
this.policyService.deletePolicy(policyId).subscribe(
{
next: (response: IdResponseDto) => this.errorOrUpdateSubscriber.next(response),
next: (response: IdResponse) => this.errorOrUpdateSubscriber.next(response),
error: (error: Error) => this.showError(error, "An error occurred while deleting the policy.")
}
);
Expand Down
Loading

0 comments on commit dbd6e9e

Please sign in to comment.