Skip to content

Commit

Permalink
Merge branch 'feature/435770_upgrade-0-7-1' into 'develop'
Browse files Browse the repository at this point in the history
feature/435770_upgrade-0-7-1

See merge request upm-inesdata/inesdata-connector-interface!20
  • Loading branch information
sasierrassis committed Jul 2, 2024
2 parents 5d6765c + 34c8349 commit 73ead6c
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 131 deletions.
22 changes: 17 additions & 5 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 @@ -35,7 +35,7 @@
"@jsonforms/angular": "^3.2.1",
"@jsonforms/angular-material": "^3.2.1",
"@jsonforms/core": "^3.2.1",
"@think-it-labs/edc-connector-client": "0.4.0",
"@think-it-labs/edc-connector-client": "0.5.0",
"angular-oauth2-oidc": "^17.0.2",
"install": "^0.13.0",
"jexl": "^2.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,5 @@ export class AssetEditorDialog implements OnInit {
}else{
delete this.inesDataStoreAddress.file
}
console.log('Mira',this.inesDataStoreAddress)

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { ContractAgreementService } from "../../../shared/services/contractAgreement.service";
import { firstValueFrom, from, Observable } from "rxjs";
import { firstValueFrom, from } from "rxjs";
import { ContractAgreement, IdResponse, TransferProcessInput } from "../../../shared/models/edc-connector-entities";
import { filter, first, map, switchMap, tap } from "rxjs/operators";
import { filter, first, switchMap, tap } from "rxjs/operators";
import { NotificationService } from "../../../shared/services/notification.service";
import { MatDialog } from "@angular/material/dialog";
import { CatalogBrowserService } from "../../../shared/services/catalog-browser.service";
Expand Down Expand Up @@ -45,7 +45,7 @@ export class ContractViewerComponent implements OnInit {
}

private static isFinishedState(storageType: string, state: string): boolean {
if (storageType === 'HttpData' && state === 'STARTED') {
if (storageType === 'HttpData-PULL' && state === 'STARTED') {
return true;
} else {
return [
Expand Down Expand Up @@ -79,31 +79,67 @@ export class ContractViewerComponent implements OnInit {
});
}

asDate(epochSeconds?: number): string {
if (epochSeconds) {
const d = new Date(0);
d.setUTCSeconds(epochSeconds);
return d.toLocaleDateString();
}
return '';
}

isTransferInProgress(contractId: string): boolean {
return !!this.runningTransfers.find(rt => rt.contractId === contractId);
}

changePage(event: PageEvent) {
const offset = event.pageIndex * event.pageSize;
this.pageSize = event.pageSize;
this.currentPage = event.pageIndex;
this.loadContractAgreements(offset);
}

private loadContractAgreements(offset: number) {
const querySpec: QuerySpec = {
offset: offset,
limit: this.pageSize
}

this.contractAgreementService.queryAllAgreements(querySpec)
.subscribe(results => {
this.contracts = results;
});
}

private countContractAgreements() {
this.contractAgreementService.count()
.subscribe(result => {
this.paginatorLength = result;
});
}

private async createTransferRequest(contract: ContractAgreement, dataAddress: DataAddress): Promise<TransferProcessInput> {
const dataOffer = await this.getDatasetFromFederatedCatalog(contract.assetId, contract.providerId);

const transferType = this.getTransferType(dataAddress.type);

const iniateTransfer: TransferProcessInput = {
assetId: dataOffer.assetId,
counterPartyAddress: dataOffer.endpointUrl,
contractId: contract.id,
transferType: dataAddress.type,
transferType: transferType,
dataDestination: dataAddress
};

return iniateTransfer;
}

asDate(epochSeconds?: number): string {
if (epochSeconds) {
const d = new Date(0);
d.setUTCSeconds(epochSeconds);
return d.toLocaleDateString();
private getTransferType(type: string) {
if(type === 'HttpData') {
return 'HttpData-PULL'
} else {
return 'AmazonS3-PUSH'
}
return '';
}

isTransferInProgress(contractId: string): boolean {
return !!this.runningTransfers.find(rt => rt.contractId === contractId);
}

/**
Expand All @@ -112,7 +148,7 @@ export class ContractViewerComponent implements OnInit {
* @param assetId Asset ID of the asset that is associated with the contract.
* @param provider Participant ID of the catalog which owns the asset
*/
private async getDatasetFromFederatedCatalog(assetId: string, provider: string): Promise<DataOffer> {
private async getDatasetFromFederatedCatalog(assetId: string, provider: string): Promise<DataOffer> {

const querySpec: QuerySpec = {
offset: 0,
Expand Down Expand Up @@ -158,7 +194,7 @@ export class ContractViewerComponent implements OnInit {
return () => {
from(this.runningTransfers) //create from array
.pipe(switchMap(runningTransferProcess => this.catalogService.getTransferProcessesById(runningTransferProcess.processId)), // fetch from API
filter(transferprocess => ContractViewerComponent.isFinishedState(transferprocess.type, transferprocess.state)), // only use finished ones
filter(transferprocess => ContractViewerComponent.isFinishedState(transferprocess['https://w3id.org/edc/v0.0.1/ns/transferType'][0]['@value'], transferprocess.state)), // only use finished ones
tap(transferProcess => {
// remove from in-progress
this.runningTransfers = this.runningTransfers.filter(rtp => rtp.processId !== transferProcess.id)
Expand All @@ -176,30 +212,4 @@ export class ContractViewerComponent implements OnInit {
}

}

changePage(event: PageEvent) {
const offset = event.pageIndex * event.pageSize;
this.pageSize = event.pageSize;
this.currentPage = event.pageIndex;
this.loadContractAgreements(offset);
}

loadContractAgreements(offset: number) {
const querySpec: QuerySpec = {
offset: offset,
limit: this.pageSize
}

this.contractAgreementService.queryAllAgreements(querySpec)
.subscribe(results => {
this.contracts = results;
});
}

countContractAgreements() {
this.contractAgreementService.count()
.subscribe(result => {
this.paginatorLength = result;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export class NewPolicyDialogComponent implements OnInit {

onSave() {
try {
this.policy.permission = this.parseAndVerifyJson(this.permissionsJson, "Permissions");
this.policy.prohibition = this.parseAndVerifyJson(this.prohibitionsJson, "Prohibitions");
this.policy.obligation = this.parseAndVerifyJson(this.obligationsJson, "Obligations");
this.policy.permission = this.parseAndVerifyJson(this.permissionsJson);
this.policy.prohibition = this.parseAndVerifyJson(this.prohibitionsJson);
this.policy.obligation = this.parseAndVerifyJson(this.obligationsJson);

this.dialogRef.close({
'@id': this.policyId,
Expand All @@ -48,78 +48,22 @@ export class NewPolicyDialogComponent implements OnInit {
this.notificationService.showError("Error parsing JSON: " + error.message);
console.error(error);
}
if (error instanceof VerifyJsonKeysError) {
this.notificationService.showError(error.message);
console.error(error);
}
}
}

/**
* Parse and verify a JSON from the policy
*
* @param json JSON to parse and verify
* @param property property of the policy which containst the JSON to verify (permissions, prohibitons or obligations)
* @returns the parsed JSON or null if it is empty
*/
private parseAndVerifyJson(json: string, property: string): any {
private parseAndVerifyJson(json: string): any {
if (json.trim() != '') {
const parsedJson = JSON.parse(json);
let requiredKeys = ["target", "action"];
let allowedKeys = [...requiredKeys, "constraint", "duty"];

if (property === 'Obligations') {
allowedKeys = [...requiredKeys, "constraint"];
requiredKeys = [];
}

if (!this.verifyKeys(parsedJson, requiredKeys, allowedKeys)) {
throw new VerifyJsonKeysError(property + ' JSON is not valid');
}

return parsedJson;
}

return null;
}

/**
* Checks if a JSON has the required keys and if it has invalid keys
*
* @param json the JSON to verify
* @param requiredKeys requiered keys that must be included in the JSON
* @param allowedKeys allowed keys that may be included in the JSON
* @returns true if keys are valid, false otherwise
*/
private verifyKeys(json: any, requiredKeys: string[], allowedKeys: string[]): boolean {
const keysFromJson = Object.keys(json);

if (requiredKeys.length > 0) {
for (const key of requiredKeys) {
if (!keysFromJson.includes(key)) {
return false;
}
}
}

for (const key of keysFromJson) {
if (!allowedKeys.includes(key)) {
return false;
}
}

return true;
}

}

/**
* Error class to throw when JSON keys are wrong
*/
class VerifyJsonKeysError extends Error {
constructor(msg: string) {
super(msg);

Object.setPrototypeOf(this, VerifyJsonKeysError.prototype);
}
}
6 changes: 5 additions & 1 deletion src/app/shared/services/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export class AssetService {
delete assetEntryDto?.blob
let body = {
...assetEntryDto,
"@context": JSON_LD_DEFAULT_CONTEXT,
"@context": {
"@vocab": EDC_CONTEXT,
"dcterms": CONTEXTS.dcterms,
"dcat": CONTEXTS.dcat
}
}

delete body.dataAddress.file
Expand Down
10 changes: 5 additions & 5 deletions src/assets/config/app.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@
"count": "/pagination/count?type=asset"
},
"contractAgreement": {
"baseUrl": "/v2/contractagreements",
"baseUrl": "/v3/contractagreements",
"get": "/",
"getAll": "/request",
"getNegotiation": "/negotiation",
"count": "/pagination/count?type=contractAgreement"
},
"policy": {
"baseUrl": "/v2/policydefinitions",
"baseUrl": "/v3/policydefinitions",
"get": "/",
"getAll": "/request",
"count": "/pagination/count?type=policyDefinition"
},
"contractDefinition": {
"baseUrl": "/v2/contractdefinitions",
"baseUrl": "/v3/contractdefinitions",
"get": "/",
"getAll": "/request",
"count": "/pagination/count?type=contractDefinition"
},
"contractNegotiation": {
"baseUrl": "/v2/contractnegotiations",
"baseUrl": "/v3/contractnegotiations",
"get": "/",
"agreement": "/agreement",
"state": "/state",
"terminate": "/terminate",
"getAll": "/request"
},
"transferProcess": {
"baseUrl": "/v2/transferprocesses",
"baseUrl": "/v3/transferprocesses",
"get": "/",
"deprovision": "/deprovision",
"state": "/state",
Expand Down
10 changes: 5 additions & 5 deletions src/assets/config/app.config.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@
"count": "/pagination/count?type=asset"
},
"contractAgreement": {
"baseUrl": "/v2/contractagreements",
"baseUrl": "/v3/contractagreements",
"get": "/",
"getAll": "/request",
"getNegotiation": "/negotiation",
"count": "/pagination/count?type=contractAgreement"
},
"policy": {
"baseUrl": "/v2/policydefinitions",
"baseUrl": "/v3/policydefinitions",
"get": "/",
"getAll": "/request",
"count": "/pagination/count?type=policyDefinition"
},
"contractDefinition": {
"baseUrl": "/v2/contractdefinitions",
"baseUrl": "/v3/contractdefinitions",
"get": "/",
"getAll": "/request",
"count": "/pagination/count?type=contractDefinition"
},
"contractNegotiation": {
"baseUrl": "/v2/contractnegotiations",
"baseUrl": "/v3/contractnegotiations",
"get": "/",
"agreement": "/agreement",
"state": "/state",
"terminate": "/terminate",
"getAll": "/request"
},
"transferProcess": {
"baseUrl": "/v2/transferprocesses",
"baseUrl": "/v3/transferprocesses",
"get": "/",
"deprovision": "/deprovision",
"state": "/state",
Expand Down
Loading

0 comments on commit 73ead6c

Please sign in to comment.