diff --git a/src/app/datasets/services/dataset-crud.service.ts b/src/app/datasets/services/dataset-crud.service.ts index 8bf3cae906927101046dfedf3248d386ec84af9b..73ba27ffa86b80dace78a65732911ec4e2bacce9 100644 --- a/src/app/datasets/services/dataset-crud.service.ts +++ b/src/app/datasets/services/dataset-crud.service.ts @@ -19,17 +19,18 @@ export class DatasetCrudService { constructor(private http: HttpClient, private appConfig: AppConfiguration, private parserService: ParseXmlService, private sessionStorage: TokenStorageService) { } - createDataset(data: string): Observable<any> { + async createDataset(data: string): Promise<any> { if (this.fds2Token) { - const httpOptions = { - headers: new HttpHeaders({ - 'Accept': 'text/turtle', - 'Content-Type': 'text/turtle', - 'Authorization': 'Bearer ' + this.fds2Token - }) - }; + const httpOptions = new Headers(); + httpOptions.append( 'Accept', 'text/turtle'); + httpOptions.append('Content-Type', 'text/turtle'); + httpOptions.append('Authorization', 'Bearer '+ this.fds2Token ); + + + const myInit = { method: 'POST', body: data , headers: httpOptions }; + const myRequest = new Request(`${FDP_URL}/dataset`, myInit); - return this.http.post(FDP_URL + "/dataset", data, httpOptions); + return fetch(myRequest, myInit) } } diff --git a/src/app/mapping/dialog/feedback-dialog/feedback-dialog.component.html b/src/app/mapping/dialog/feedback-dialog/feedback-dialog.component.html index 599d87338f11c260ade9f143617887f7fc557105..176c0ca3ffd9bc21f19f36bfdef1cdf3c68d7aad 100644 --- a/src/app/mapping/dialog/feedback-dialog/feedback-dialog.component.html +++ b/src/app/mapping/dialog/feedback-dialog/feedback-dialog.component.html @@ -1,9 +1,9 @@ -<nb-card> +<nb-card [size]="'medium'"> <nb-card-header> <h3 style="text-align: center;">Feedback: </h3> </nb-card-header> <nb-card-body> - <nb-card> + <nb-card > <nb-card-body> <p class="error" *ngIf="data.notPostedMetadatas.length > 0">An error occurred while publishing the following Datasets: </p> <ul class="error" *ngFor="let data of data.notPostedMetadatas"> diff --git a/src/app/mapping/mapping.component.ts b/src/app/mapping/mapping.component.ts index 32b64d448b6c54885117c873215f48239137cade..0b54724dd06582b84f18413325ae0824ed56f5af 100644 --- a/src/app/mapping/mapping.component.ts +++ b/src/app/mapping/mapping.component.ts @@ -1,9 +1,11 @@ + +import { HttpResponse } from '@angular/common/http'; import { Component, Input, OnInit, ViewChild } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { Router } from '@angular/router'; -import { NbDialogService } from '@nebular/theme'; -import { Observable, of } from 'rxjs'; + +import { Observable, of, Subscription } from 'rxjs'; import { map } from 'rxjs/operators'; import { environment } from 'src/environments/environment.prod'; import { DatasetCrudService } from '../datasets/services/dataset-crud.service'; @@ -34,7 +36,7 @@ export class MappingComponent implements OnInit { loadingCr = false; FDP_URL = environment.fdpUrl; - ids: number []; + ids: number[]; @ViewChild('autoInput') input; @Input() catalogId: any; @@ -62,13 +64,9 @@ export class MappingComponent implements OnInit { this.ids = this.dataSetService.ids; this.ids this.keys = []; - for (let i = 0; i < this.itemsdataset.length; i++) { - if (i === 0) { - this.getKeysFromMetadata(this.itemsdataset[i], ''); - this.keysMap.set(this.itemsdataset.length, this.keys); - this.filteredOptions = of(this.keysMap.get(1)); - } - } + this.getKeysFromMetadata(this.itemsdataset[0], ''); + this.keysMap.set(this.itemsdataset.length, this.keys); + this.filteredOptions = of(this.keysMap.get(1)); } createDataset(item: Object): Map<string, string> { @@ -90,7 +88,9 @@ export class MappingComponent implements OnInit { let postedDatastes = []; let notPostedDatasets = []; this.loading = true; + const requestPromises: Promise<any>[] = []; for (let i = 0; i < this.mappedMetadatas.length; i++) { + let title = ""; properties = ""; this.mappedMetadatas[i].forEach((value: string, key: string) => { @@ -129,34 +129,26 @@ export class MappingComponent implements OnInit { dct:title "' + title + '" ;\n\ dct:isPartOf <https://f2ds.eosc-pillar.eu/catalog/' + this.catalogId + '>. } '*/ - this.dataSetService.createDataset(data).subscribe( - (error: Error) => { - notPostedDatasets.push(this.ids[i]); - if (i === this.mappedMetadatas.length - 1) { - this.loading = false; - this.dialog.open(FeedbackDialogComponent, { - data: { - postedMetadatas: postedDatastes, - notPostedMetadatas: notPostedDatasets - } - }).afterClosed().subscribe(() => this.route.navigateByUrl('/dashboard')); - } - }, - () => { - postedDatastes.push(this.ids[i]); - if (i === this.mappedMetadatas.length - 1) { - this.loading = false; - this.dialog.open(FeedbackDialogComponent, { - data: { - postedMetadatas: postedDatastes, - notPostedMetadatas: notPostedDatasets - } - }).afterClosed().subscribe(() => this.route.navigateByUrl('/dashboard')); - - } - }) + let requestPromise = this.dataSetService.createDataset(data).then((resp: HttpResponse<any>) => { + if (resp.status.toString().startsWith('2')) { + postedDatastes.push(this.ids[i]); + } else { + notPostedDatasets.push(this.ids[i]); + } + }) + requestPromises.push(requestPromise); } + Promise.all(requestPromises).finally(() => { + this.loading = false; + this.dialog.open(FeedbackDialogComponent, { + data: { + postedMetadatas: postedDatastes, + notPostedMetadatas: notPostedDatasets + } + }).afterClosed().subscribe(() => this.route.navigateByUrl('/dashboard')); + + }) } /* function to get recursively all the keys and values from the JSON object */