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: switch ContractNegotiation to connector client #123

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {MatDialog} from '@angular/material/dialog';
import {BehaviorSubject, Observable, of} from 'rxjs';
import {map, switchMap} from 'rxjs/operators';
import {CatalogBrowserService} from "../../services/catalog-browser.service";
import {ContractNegotiationDto, NegotiationInitiateRequestDto} from "../../../mgmt-api-client";
import {NotificationService} from "../../services/notification.service";
import {Router} from "@angular/router";
import {TransferProcessStates} from "../../models/transfer-process-states";
import {ContractOffer} from "../../models/contract-offer";
import {NegotiationResult} from "../../models/negotiation-result";
import {ContractNegotiation, ContractNegotiationRequest} from "../../../mgmt-api-client/model";

interface RunningTransferProcess {
processId: string;
Expand All @@ -27,7 +27,7 @@ export class CatalogBrowserComponent implements OnInit {
searchText = '';
runningTransferProcesses: RunningTransferProcess[] = [];
runningNegotiations: Map<string, NegotiationResult> = new Map<string, NegotiationResult>(); // contractOfferId, NegotiationResult
finishedNegotiations: Map<string, ContractNegotiationDto> = new Map<string, ContractNegotiationDto>(); // contractOfferId, contractAgreementId
finishedNegotiations: Map<string, ContractNegotiation> = new Map<string, ContractNegotiation>(); // contractOfferId, contractAgreementId
private fetch$ = new BehaviorSubject(null);
private pollingHandleNegotiation?: any;

Expand Down Expand Up @@ -55,19 +55,15 @@ export class CatalogBrowserComponent implements OnInit {
}

onNegotiateClicked(contractOffer: ContractOffer) {
const initiateRequest: NegotiationInitiateRequestDto = {
const initiateRequest: ContractNegotiationRequest = {
connectorAddress: contractOffer.originator,
"@context": {
"edc": "https://w3id.org/edc/v0.0.1/ns/",
"odrl": "http://www.w3.org/ns/odrl/2/"
},
offer: {
offerId: contractOffer.id,
assetId: contractOffer.assetId,
policy: contractOffer.policy,
},
connectorId: 'connector',
protocol: 'dataspace-protocol-http'
providerId: contractOffer["dcat:service"].id
};

const finishedNegotiationStates = [
Expand All @@ -89,7 +85,7 @@ export class CatalogBrowserComponent implements OnInit {

for (const negotiation of this.runningNegotiations.values()) {
this.apiService.getNegotiationState(negotiation.id).subscribe(updatedNegotiation => {
if (finishedNegotiationStates.includes(updatedNegotiation["edc:state"]!)) {
if (finishedNegotiationStates.includes(updatedNegotiation.state!)) {
let offerId = negotiation.offerId;
this.runningNegotiations.delete(offerId);
if (updatedNegotiation["edc:state"] === "VERIFIED") {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/edc-demo/models/contract-offer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {Policy} from "../../mgmt-api-client";
import {DataService} from "./data-service";
import {PolicyInput} from "../../mgmt-api-client/model";

export interface ContractOffer {
id: string;
assetId: string;
properties: any;
"dcat:dataset": Array<any>;
"dcat:service": DataService;
policy: Policy;
policy: PolicyInput;
originator: string;
}
32 changes: 18 additions & 14 deletions src/modules/edc-demo/services/catalog-browser.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import {catchError, map, reduce} from 'rxjs/operators';
import {Catalog} from '../models/catalog';
import {ContractOffer} from '../models/contract-offer';
import {
ContractNegotiationDto,
ContractNegotiationService,
NegotiationInitiateRequestDto,
Policy,
TransferProcessDto,
TransferProcessService,
TransferRequestDto,
} from "../../mgmt-api-client";
import {CONNECTOR_CATALOG_API, CONNECTOR_MANAGEMENT_API} from "../../app/variables";
import TypeEnum = Policy.TypeEnum;
// import TypeEnum = Policy.TypeEnum; //TODO Use TypeEnum https://github.com/Think-iT-Labs/edc-connector-client/issues/103
import {
ContractNegotiationRequest,
ContractNegotiation,
PolicyInput
} from "../../mgmt-api-client/model";



/**
Expand Down Expand Up @@ -54,16 +57,17 @@ export class CatalogBrowserService {
const assetId = dataSet["@id"];

const hasPolicy = dataSet["odrl:hasPolicy"];
const policy: Policy = {
const policy: PolicyInput = {
//currently hardcoded to SET since parsed type is {"@policytype": "set"}
"@type": TypeEnum.Set,
"@id": hasPolicy["@id"],
"@type": "set", //TODO Use TypeEnum https://github.com/Think-iT-Labs/edc-connector-client/issues/103
"@context" : "http://www.w3.org/ns/odrl.jsonld",
"uid": hasPolicy["@id"],
"assignee": hasPolicy["assignee"],
"assigner": hasPolicy["assigner"],
"odrl:obligation": hasPolicy["odrl:obligations"],
"odrl:permission": hasPolicy["odrl:permissions"],
"odrl:prohibition": hasPolicy["odrl:prohibitions"],
"odrl:target": hasPolicy["odrl:target"]
"obligation": hasPolicy["odrl:obligations"],
"permission": hasPolicy["odrl:permissions"],
"prohibition": hasPolicy["odrl:prohibitions"],
"target": hasPolicy["odrl:target"]
};

const newContractOffer: ContractOffer = {
Expand Down Expand Up @@ -97,11 +101,11 @@ export class CatalogBrowserService {
return this.transferProcessService.getTransferProcess(id);
}

initiateNegotiation(initiateDto: NegotiationInitiateRequestDto): Observable<string> {
return this.negotiationService.initiateContractNegotiation(initiateDto, 'body', false,).pipe(map(t => t["@id"]!))
initiateNegotiation(initiate: ContractNegotiationRequest): Observable<string> {
return this.negotiationService.initiateContractNegotiation(initiate).pipe(map(t => t["@id"]!))
}

getNegotiationState(id: string): Observable<ContractNegotiationDto> {
getNegotiationState(id: string): Observable<ContractNegotiation> {
return this.negotiationService.getNegotiation(id);
}

Expand Down
Loading
Loading