From c5d098b38e1c888d247743680300f90ea69171d8 Mon Sep 17 00:00:00 2001 From: Baptiste Toulemonde <toulemonde@cines.fr> Date: Fri, 19 Nov 2021 18:00:31 +0100 Subject: [PATCH] add request to post distribution --- package-lock.json | 35 +++++++++++ package.json | 1 + src/app/app.module.ts | 14 +++-- src/app/datasets/datasets.component.html | 2 + src/app/mapping/class/requestMapping.ts | 9 ++- src/app/mapping/mapping.component.html | 1 + src/app/mapping/mapping.component.ts | 79 ++++++++++++++---------- 7 files changed, 102 insertions(+), 39 deletions(-) diff --git a/package-lock.json b/package-lock.json index d0e341d7e..47ec0b3e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "file-saver": "^2.0.2", "ng2-cookies": "^1.0.12", "ngx-filesaver": "^9.0.0", + "ngx-progressbar": "^6.1.1", "rxjs": "^6.6.3", "stream": "0.0.2", "swagger-editor-dist": "^3.11.5", @@ -10911,6 +10912,25 @@ "resolved": "https://registry.npmjs.org/ngx-filesaver/-/ngx-filesaver-9.0.0.tgz", "integrity": "sha512-AfkxygiFb/Ibpuem3mn97tDeCf2A3op6iORM6p3gpfI/bvNsPQg96gDRWB+1aBimEZHVsDrWF8xDu4L5dpyKUw==" }, + "node_modules/ngx-progressbar": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/ngx-progressbar/-/ngx-progressbar-6.1.1.tgz", + "integrity": "sha512-6FbCxbhy+lwX0hzfrr+pp4wAf0tX85664j1tnEdRd6LIfSTlUtXARiyUbGAEMyDS9MCbXhQhJyIylsJrB3gYOg==", + "dependencies": { + "tslib": "^2.0.0" + }, + "peerDependencies": { + "@angular/common": ">=8.0.0", + "@angular/core": ">=8.0.0", + "@angular/router": ">=8.0.0", + "rxjs": ">=6.0.0" + } + }, + "node_modules/ngx-progressbar/node_modules/tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + }, "node_modules/nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", @@ -27431,6 +27451,21 @@ "resolved": "https://registry.npmjs.org/ngx-filesaver/-/ngx-filesaver-9.0.0.tgz", "integrity": "sha512-AfkxygiFb/Ibpuem3mn97tDeCf2A3op6iORM6p3gpfI/bvNsPQg96gDRWB+1aBimEZHVsDrWF8xDu4L5dpyKUw==" }, + "ngx-progressbar": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/ngx-progressbar/-/ngx-progressbar-6.1.1.tgz", + "integrity": "sha512-6FbCxbhy+lwX0hzfrr+pp4wAf0tX85664j1tnEdRd6LIfSTlUtXARiyUbGAEMyDS9MCbXhQhJyIylsJrB3gYOg==", + "requires": { + "tslib": "^2.0.0" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + } + } + }, "nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", diff --git a/package.json b/package.json index a1af4183f..02da5ba68 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "file-saver": "^2.0.2", "ng2-cookies": "^1.0.12", "ngx-filesaver": "^9.0.0", + "ngx-progressbar": "^6.1.1", "rxjs": "^6.6.3", "stream": "0.0.2", "swagger-editor-dist": "^3.11.5", diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8b4c78bb9..d1e31af8c 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -35,14 +35,15 @@ import { SearchModule } from './search/search.module'; import { StatsComponent } from './stats/stats.component'; import { MappingComponent } from './mapping/mapping.component'; import { NebularModule } from './nebular.module'; - import { AppRoutingModule } from './app-routing.module'; -import { NbLayoutModule, NbThemeModule, NbTooltipModule, NbSpinnerModule, NbSelectModule, NbTabsetModule, NbAutocompleteModule, NbListModule, NbAccordionModule, NbDialogModule, NbProgressBarModule } from '@nebular/theme'; +import { NbLayoutModule, NbThemeModule, NbTooltipModule, NbSpinnerModule, NbSelectModule, NbTabsetModule, NbAutocompleteModule, NbListModule, NbAccordionModule, NbDialogModule } from '@nebular/theme'; import { DashboardComponent } from './dashboard/dashboard.component'; import { FeedbackDialogComponent } from './mapping/dialog/feedback-dialog/feedback-dialog.component'; import { NbToastrModule } from '@nebular/theme'; import { DatasetsDialogComponent } from './datasets/datasets-dialog/datasets-dialog.component'; +import { NgProgressModule } from 'ngx-progressbar'; +import { NgProgressHttpModule } from 'ngx-progressbar/http'; @@ -95,7 +96,13 @@ import { DatasetsDialogComponent } from './datasets/datasets-dialog/datasets-dia NbAutocompleteModule, NbListModule, NbAccordionModule, - NbProgressBarModule, + NgProgressModule.withConfig({ + + spinnerPosition: "left", + thick: true, + meteor: false + }), + NgProgressHttpModule, NbToastrModule.forRoot(), NbDialogModule.forRoot() ], @@ -103,7 +110,6 @@ import { DatasetsDialogComponent } from './datasets/datasets-dialog/datasets-dia providers: [ AppConfiguration, ParseXmlService, - /*{ provide: APP_INITIALIZER, useFactory: AppConfigurationFactory, diff --git a/src/app/datasets/datasets.component.html b/src/app/datasets/datasets.component.html index 5fdfcf3a1..cb290c3da 100644 --- a/src/app/datasets/datasets.component.html +++ b/src/app/datasets/datasets.component.html @@ -1,3 +1,4 @@ +<ng-progress></ng-progress> <mat-sidenav-container> @@ -52,6 +53,7 @@ </nb-accordion-item> </nb-accordion> </nb-card> + <div *ngIf="loading" class="overlay"> <mat-spinner class="spinner"> </mat-spinner> diff --git a/src/app/mapping/class/requestMapping.ts b/src/app/mapping/class/requestMapping.ts index 475fa2ca6..1ee7bfc81 100644 --- a/src/app/mapping/class/requestMapping.ts +++ b/src/app/mapping/class/requestMapping.ts @@ -14,10 +14,17 @@ export class Path { property: string; path: string; card: string; + dcatClass: string; - constructor (property: string, path: string, card: string) { + constructor (property: string, path: string, card: string, dcatClass: string) { this.property = property; this.path = path; this.card = card; + this.dcatClass = dcatClass; } +} + +export class ResponseMapping { + notPublishedUrl: string[]; + publishedUrl: string[]; } \ No newline at end of file diff --git a/src/app/mapping/mapping.component.html b/src/app/mapping/mapping.component.html index bcc97e856..38d1af083 100644 --- a/src/app/mapping/mapping.component.html +++ b/src/app/mapping/mapping.component.html @@ -1,3 +1,4 @@ +<ng-progress></ng-progress> <ng-container *ngIf="type !== 'ISO 19115'; else xml"> <nb-card> <nb-card-body> diff --git a/src/app/mapping/mapping.component.ts b/src/app/mapping/mapping.component.ts index 231b5fcb1..62b94148c 100644 --- a/src/app/mapping/mapping.component.ts +++ b/src/app/mapping/mapping.component.ts @@ -13,7 +13,7 @@ import { TokenStorageService } from '../authentication/services/token-storage.se import { DatasetCrudService } from '../datasets/services/dataset-crud.service'; import { Property, DatasetPath, Distribution, ResponseFileTsv, OldProperty } from './class/dataset'; -import { Path, RequestMapping } from './class/requestMapping'; +import { Path, RequestMapping, ResponseMapping } from './class/requestMapping'; import { FeedbackDialogComponent } from './dialog/feedback-dialog/feedback-dialog.component'; import { MappingService } from './service/mapping.service'; @@ -50,7 +50,7 @@ export class MappingComponent implements OnInit, OnDestroy { @Input() type: string; @Input() catalogId: any; - constructor(private ref: ChangeDetectorRef,private dataSetService: DatasetCrudService, private dialog: MatDialog, private route: Router, private tokenStorage: TokenStorageService, private mappingService: MappingService) { + constructor(private ref: ChangeDetectorRef, private dataSetService: DatasetCrudService, private dialog: MatDialog, private route: Router, private tokenStorage: TokenStorageService, private mappingService: MappingService) { ref.detach(); setInterval(() => { this.ref.detectChanges(); @@ -72,11 +72,11 @@ export class MappingComponent implements OnInit, OnDestroy { this.type == "Dataverse" ? this.getKeysFromMetadataCustom(this.itemsdataset[0], '') : this.getKeysFromMetadataCustom(this.itemsdataset[0], ''); this.keys = Array.from(new Set(this.keys)); this.filteredOptions = of(this.keys); - } + } } - + selectOntology(): void { this.dataSetService.getLocally(`./assets/geodcat.json`).subscribe( @@ -140,33 +140,44 @@ export class MappingComponent implements OnInit, OnDestroy { for (let i = 0; i < this.datasets.length; i++) { if (this.selectedPaths[i]) { - paths.push(new Path(this.datasets[i].uri, this.selectedPaths[i], this.datasets[i].card)); + paths.push(new Path(this.datasets[i].uri, this.selectedPaths[i], this.datasets[i].card, this.datasets[i].dcatClass)); + } + } + for (let i = 0; i < this.distributions.length; i++) { + if (this.distributionSelectedPaths[i]) { + paths.push(new Path(this.distributions[i].uri, this.distributionSelectedPaths[i], this.distributions[i].card, this.distributions[i].dcatClass)); } } - - let data: RequestMapping = new RequestMapping(this.urls, paths , this.tokenStorage.getFDPToken()); - let postedDatastes = []; + let data: RequestMapping = new RequestMapping(this.urls, paths, this.tokenStorage.getFDPToken()); + + let postedDatasets = []; let notPostedDatasets = []; this.loading = true; const requestPromises: Promise<any>[] = []; - - let requestPromise = this.mappingService.postToFdpFropSmartharvester(this.catalogId, data).then((resp: HttpResponse<any>) => { - console.log(resp.body); - - const location = resp.headers.get("location"); - const datasetId = location.substring(location.search("dataset/") + 8, location.length); - - }) - requestPromises.push(requestPromise); + let requestPromise = this.mappingService.postToFdpFropSmartharvester(this.catalogId, data).then( resp => { + if (resp) { + console.log(resp); + resp.json().then((data: any) => { + console.log(data.message); + data.publishedUrl.forEach(e => postedDatasets.push(e)); + data.notPublishedUrl.forEach(e => notPostedDatasets.push(e)); + }); + } + /*const location = resp.headers.get("location"); + const datasetId = location.substring(location.search("dataset/") + 8, location.length);*/ + + }); + requestPromises.push(requestPromise); + Promise.all(requestPromises).finally(() => { this.loading = false; this.dialog.open(FeedbackDialogComponent, { data: { - postedMetadatas: postedDatastes, + postedMetadatas: postedDatasets, notPostedMetadatas: notPostedDatasets } }).afterClosed().subscribe(); @@ -255,7 +266,7 @@ export class MappingComponent implements OnInit, OnDestroy { } return properties; } - + /* function to get recursively all the keys and values from the JSON object */ @@ -457,10 +468,10 @@ export class MappingComponent implements OnInit, OnDestroy { downloadJson() { let datasetPathArray = this.createObjectToExport(); - - - + + + this.mappingService.downloadFile(datasetPathArray); } @@ -483,7 +494,7 @@ export class MappingComponent implements OnInit, OnDestroy { } } - + importJson(event: Event) { const files: FileList = (event.target as HTMLInputElement).files; const jsonFile = files[0]; @@ -498,28 +509,28 @@ export class MappingComponent implements OnInit, OnDestroy { paths.forEach(path => { (path.object_category.includes('dataset')) ? datasetPath.push(path) : distributionPath.push(path); }) - + console.log(datasetPath) console.log(distributionPath) if (distributionPath.length > 0) this.addDistribution = true; this.fillFromTsv(this.datasets, this.selectedPaths, datasetPath, 'dcat:dataset'); this.fillFromTsv(this.distributions, this.distributionSelectedPaths, distributionPath, 'dcat:distribution'); } else { - let paths: DatasetPath[] = <DatasetPath[]> JSON.parse(reader.result as string); + let paths: DatasetPath[] = <DatasetPath[]>JSON.parse(reader.result as string); console.table(paths) - + for (let i = 0; i < paths.length; i++) { if (i > 0 && paths[i].dcatProperty === paths[i - 1].dcatProperty) { const voc: Property = this.datasets.find(e => e.uri === (<Property>paths[i].dcatProperty).uri); this.datasets.splice(i + 1, 0, voc); this.selectedPaths.splice(i + 1, 0, paths[i].path); - + if (typeof paths[i].dcatProperty !== 'object') { this.datasets[i] = this.vocabularies.filter(e => e.dcatClass === 'dcat:dataset').find(v => v.uri === <string>paths[i].dcatProperty); } else { this.datasets[i] = this.vocabularies.filter(e => e.dcatClass === 'dcat:dataset').find(v => v.uri === (<OldProperty><unknown>paths[i].dcatProperty).identifier); } - + } else { this.selectedPaths[i] = paths[i].path; if (typeof paths[i].dcatProperty !== 'object') { @@ -528,23 +539,23 @@ export class MappingComponent implements OnInit, OnDestroy { this.datasets[i] = this.vocabularies.find(v => v.uri === (<OldProperty><unknown>paths[i].dcatProperty).identifier); } } - - + + } } } reader.readAsText(jsonFile); this.ref.markForCheck() - - + + } addField(index: number, properties: Property[], paths: string[]) { let addedDcat: Property = properties.find(e => e.uri === properties[index].uri); properties.splice(index + 1, 0, addedDcat); - + paths.splice(index + 1, 0, ''); - + } deleteField(index: number, properties: Property[], paths: string[]) { -- GitLab