diff --git a/package-lock.json b/package-lock.json index d0e341d7ea6fce9d50d312d50e241a68f0a64617..47ec0b3e3c96e454a344aa447e54f76b36f8a442 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 a1af4183f2d9766ae0bd1cc79c1a34b8dc6eb695..02da5ba68f1ec8713c870d8ee1c9fc3cc77fd204 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 a21703b44ed2bc77d650b22b7abf319dc1dbeb7d..d1e31af8c3f4018d78a2e0c96a6f70f1dd5b7df4 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -35,7 +35,6 @@ 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 } from '@nebular/theme'; @@ -43,6 +42,8 @@ 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,6 +96,13 @@ import { DatasetsDialogComponent } from './datasets/datasets-dialog/datasets-dia NbAutocompleteModule, NbListModule, NbAccordionModule, + NgProgressModule.withConfig({ + + spinnerPosition: "left", + thick: true, + meteor: false + }), + NgProgressHttpModule, NbToastrModule.forRoot(), NbDialogModule.forRoot() ], @@ -102,16 +110,16 @@ import { DatasetsDialogComponent } from './datasets/datasets-dialog/datasets-dia providers: [ AppConfiguration, ParseXmlService, - { + /*{ provide: APP_INITIALIZER, useFactory: AppConfigurationFactory, deps: [AppConfiguration, HttpClient], multi: true - }, + },*/ ], bootstrap: [AppComponent] }) export class AppModule { } -export function AppConfigurationFactory(appConfig: AppConfiguration) { +/*export function AppConfigurationFactory(appConfig: AppConfiguration) { return () => appConfig.ensureInit(); -} +}*/ diff --git a/src/app/authentication/services/token-storage.service.ts b/src/app/authentication/services/token-storage.service.ts index 5efd4714424d1a8284fab6fc24ca20d83abb2373..00b7d5f5237b9b4abea503f4a87c06621aecc0c4 100644 --- a/src/app/authentication/services/token-storage.service.ts +++ b/src/app/authentication/services/token-storage.service.ts @@ -3,7 +3,7 @@ import { AuthService } from './auth.service'; const TOKEN_KEY = 'auth-token'; const USER_KEY = 'auth-user'; -const F2DS_TOKEN_KEY = 'f2ds-token'; +const FDP_TOKEN_KEY = 'fdp-token'; @Injectable({ providedIn: 'root' @@ -17,16 +17,16 @@ export class TokenStorageService { public saveToken(token: string,f2dsToken:string): void { window.sessionStorage.removeItem(TOKEN_KEY); - window.sessionStorage.removeItem(F2DS_TOKEN_KEY); + window.sessionStorage.removeItem(FDP_TOKEN_KEY); window.sessionStorage.setItem(TOKEN_KEY, token); - window.sessionStorage.setItem(F2DS_TOKEN_KEY, f2dsToken); + window.sessionStorage.setItem(FDP_TOKEN_KEY, f2dsToken); } public getToken(): string { return window.sessionStorage.getItem(TOKEN_KEY); } public getFDPToken(): string { - return window.sessionStorage.getItem(F2DS_TOKEN_KEY); + return window.sessionStorage.getItem(FDP_TOKEN_KEY); } public saveUser(user): void { @@ -39,7 +39,7 @@ export class TokenStorageService { } public removeToken(){ window.localStorage.removeItem(TOKEN_KEY); - window.sessionStorage.removeItem(F2DS_TOKEN_KEY); + window.sessionStorage.removeItem(FDP_TOKEN_KEY); } diff --git a/src/app/datasets/datasets.component.html b/src/app/datasets/datasets.component.html index 5fdfcf3a1c98e803c8a4ad6a21e556417f16c2f1..cb290c3da7edaded6483e6ef334316bcf7d5ac09 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/datasets/datasets.component.ts b/src/app/datasets/datasets.component.ts index a730d01c11fad46f205cc8ed90539f3cdb744890..39907f918cc48207a632d24c6213cb7b6c97138c 100644 --- a/src/app/datasets/datasets.component.ts +++ b/src/app/datasets/datasets.component.ts @@ -106,6 +106,7 @@ export class DatasetsComponent implements OnInit, AfterViewChecked, AfterContent this.initValueMap(); this.updateRequestHistorical(); this.dataSetService.resetDataset(); + this.dataSetService.resetUrls(); } initValueMap() { @@ -135,6 +136,49 @@ export class DatasetsComponent implements OnInit, AfterViewChecked, AfterContent } } } + private getUrls(pathName: string, httpMethod: string, datasetId: any): string { + const parameters = this.values.get(pathName).get(httpMethod); + let path = pathName; + + for (const [parameterName, parameterInfo] of parameters) { + if (parameterInfo.type === ParameterType.path) { + let value = parameterInfo.value; + if (parameterInfo.required && datasetId != null) { + value = datasetId.toString(); + } + path = path.replace(`{${parameterName}}`, value); + } + } + const myHeaders: any = {}; + + const url = new URL(this.urlRepo + path); + + for (const [parameterName, parameterInfo] of parameters) { + let value = parameterInfo.value; + if (parameterInfo.required && datasetId != null) { + value = datasetId.toString(); + } + + switch (parameterInfo.type) { + case ParameterType.query: + url.searchParams.set(parameterName, value); + break; + case ParameterType.header: + myHeaders[parameterName] = value; + break; + case ParameterType.cookie: + if (myHeaders.Cookie != null) { + myHeaders.Cookie = myHeaders.Cookie + `; ${parameterName}=${value}`; + } else { + myHeaders.Cookie = `${parameterName}=${value}`; + } + } + } + + const requestHref = url.href; + return requestHref; + + } async launchRequest(pathName: string, httpMethod: string, preview: boolean, datasetId?: number) { if (preview) { @@ -362,22 +406,6 @@ export class DatasetsComponent implements OnInit, AfterViewChecked, AfterContent }).finally(() => this.loading = false); } - private getUrls(datasetRequestPathName: string, datasetRequestHttpMethod: string, id: number): string { - let parameters = this.values.get(datasetRequestPathName).get(datasetRequestHttpMethod); - let path = datasetRequestPathName; - for (const [parameterName, parameterInfo] of parameters) { - if (parameterInfo.type === ParameterType.path) { - let value = parameterInfo.value; - if (parameterInfo.required && id != null) { - value = id.toString(); - } - path = path.replace(`{${parameterName}}`, value); - return this.urlRepo + path; - } - } - - } - private onCloseDatasetDialog(datasetRequestPathName: string, datasetRequestHttpMethod: string, datasetId: number[]) { if (datasetId == null || datasetId.length === 0) { this.ready = false; @@ -388,19 +416,20 @@ export class DatasetsComponent implements OnInit, AfterViewChecked, AfterContent const requestPromises: Promise<any>[] = []; - for (const id of datasetId) { + + for (let i = 0; i < datasetId.length; i++) { + this.dataSetService.saveUrls(this.getUrls(datasetRequestPathName, datasetRequestHttpMethod, datasetId[i]), datasetId[i] ); let requestPromise: Promise<void>; - if (this.openApi.info['x-result'] === "xml") { - this.dataSetService.saveDatasets(this.getUrls(datasetRequestPathName, datasetRequestHttpMethod, id), id); - } else { - requestPromise = this.launchRequest(datasetRequestPathName, datasetRequestHttpMethod, false, id) - .then((dataset) => { - this.dataSetService.saveDatasets(dataset, id); - }); - requestPromises.push(requestPromise); + if (this.openApi.info['x-result'] !== "xml") { + + if (i < 10) { + requestPromise = this.launchRequest(datasetRequestPathName, datasetRequestHttpMethod, false, datasetId[i]) + .then((dataset) => { + this.dataSetService.saveDatasets(dataset, datasetId[i]); + }); + requestPromises.push(requestPromise); + } } - - } Promise.all(requestPromises).then(() => { @@ -437,148 +466,5 @@ export class DatasetsComponent implements OnInit, AfterViewChecked, AfterContent }); } - /*listdatasets() { - var myHeaders = new Headers(); - myHeaders.append("Content-Type", "Application/json"); - var myInit = { method: 'GET', headers: myHeaders }; - - - //appeler smart havester pour récuperer l'api à lancer - - - var myRequest = new Request('https://' + this.urlRepo + '/api/search?q=*&per_page=5&type=dataset&start=50&show_facets=true&show_my_data=true', myInit); - - fetch(myRequest, myInit) - .then(response => { - response.json() - .then(data => { - this.itemsdatasets = data['data']['items']; - // console.log(this.itemsdatasets); - for (var i = 0; i < this.itemsdatasets.length; i++) { - if (!this.dataSetService.findDataSetByTitle(data['data']['items'][i]['name'])) { - if (data['data']['items'][i]['global_id']) { - this.populatecatalogue(data['data']['items'][i]['global_id']); - } - } - } - }); - }); - return null; - } - - - populatecatalogue(id: string) { - var myHeaders = new Headers(); - myHeaders.append("Content-Type", "Application/json"); - var myInit = { method: 'GET', headers: myHeaders }; - - //appeler smart havester pour récuperer l'api à lancer - - var myRequest = new Request('https://' + this.urlRepo + '/api/datasets/export?exporter=dataverse_json&persistentId=' + id, myInit); - - fetch(myRequest, myInit) - .then(response => { - response.json() - .then(data => { - this.itemsdataset = data; - - console.log(this.itemsdataset); - - this.createdataset(data); - //this.createdistribution(this.itemsdataset); - }); - }); - - - - - } - - - - - createdataset(item: any) { - //console.log(item); - let data: string; - let description = ""; - let name = ""; - let url: string; - - for (var i = 0; i < item['datasetVersion']['metadataBlocks']['citation']['fields'].length; i++) { - if (item['datasetVersion']['metadataBlocks']['citation']['fields'][i]['typeName'] == "dsDescription") { - description = JSON.stringify(item['datasetVersion']['metadataBlocks']['citation']['fields'][i]['value']); - } - if (item['datasetVersion']['metadataBlocks']['citation']['fields'][i]['typeName'] == "title") { - name = JSON.stringify(item['datasetVersion']['metadataBlocks']['citation']['fields'][i]['value']); - } - } - - url = JSON.stringify(item['persistentUrl']); - - data = '\@prefix dcat: <http://www.w3.org/ns/dcat#>.\n\ - @prefix dct: <http://purl.org/dc/terms/>.\n\ - @prefix language: <http://id.loc.gov/vocabulary/iso639-1/>.\n\ - @prefix s: <'+ this.FDP_URL + '/>.\n\ - @prefix c: <'+ this.FDP_URL+ '/catalog/>.\n\ - s:new\n\ - a dcat:Dataset, dcat:Resource;\n\ - dct:description ' + description + ';\n\ - dct:hasVersion "1.0";\n\ - dct:isPartOf <https://f2ds.eosc-pillar.eu/catalog/afe472f9-2e70-409c-ad26-f174799e7834>;\n\ - dct:language language:en;\n\ - dct:license <http://rdflicense.appspot.com/rdflicense/cc-by-nc-nd3.0>;\n\ - dct:title '+ name + ';\n\ - dcat:keyword '+ url + '.\n' - - - console.log(data); - // return this.dataSetService.createDataSet(data); - - } - - - - createdistribution(item: any) { - - // si file alors download url https://dataverse.ird.fr/api/access/datafile/['files']['dataFile'][i]['id']] - - console.log(item); - let data: string; - let description: string; - description = JSON.stringify(item['description']); - let name: string; - name = JSON.stringify(item['name']); - let url: string; - url = JSON.stringify(item['url']); - - data = '@prefix dcat: <http://www.w3.org/ns/dcat#>.\n\ - @prefix dct: <http://purl.org/dc/terms/>.\n\ - @prefix language: <http://id.loc.gov/vocabulary/iso639-1/>.\n\ - @prefix ffd: <https://f2ds.eosc-pillar.eu/>.\n\ - @prefix d: <https://f2ds.eosc-pillar.eu/dataset/>.\n\ - @prefix GVW: <https://dataverse.ird.fr/dataset.xhtml?persistentId=doi:10.23708/GVWCA0#>.\n\ - \n\ - ffd:new\n\ - a dcat:Distribution, dcat:Resource;\n\ - dct:description "Botinelli_VNM_2016.png ";\n\ - dct:hasVersion "v1.0";\n\ - dct:isPartOf d:ca1b25a9-901c-4822-8554-b1bb416ee99d;\n\ - dct:language language:fr;\n\ - dct:license <http://rdflicense.appspot.com/rdflicense/cc-by-nc-nd3.0>;\n\ - dct:title "Botinelli_VNM_2016.png ";\n\ - dcat:accessURL GVW:;\n\ - dcat:downloadURL\n\ - <https://dataverse.ird.fr/api/access/datafile/262?imageThumb=400>;\n\ - dcat:format "png";\n\ - dcat:mediaType "png".' - - - return this.dataSetService.createDistribution(data); - - }*/ - - - - } diff --git a/src/app/datasets/services/dataset-crud.service.ts b/src/app/datasets/services/dataset-crud.service.ts index 5501eeb689749f80c38812c5417e19a5a7cbda17..838406e5e8f35aefe9c289a191e54a7f6a84d173 100644 --- a/src/app/datasets/services/dataset-crud.service.ts +++ b/src/app/datasets/services/dataset-crud.service.ts @@ -18,6 +18,8 @@ export class DatasetCrudService { public results: string[] = []; itemsDataset: Object[] = []; ids: number[] = []; + urls: Object[] = []; + idsUrls: number[] = [] constructor( private http: HttpClient, @@ -157,6 +159,16 @@ export class DatasetCrudService { this.ids = []; } + saveUrls(url: Object, id: number) { + this.urls.push(url); + this.idsUrls.push(id); + } + + resetUrls() { + this.urls = []; + this.idsUrls = []; + } + getRequestHistorical(catId: string) { if (this.sessionStorage.getUser().token == null) { return of([]); diff --git a/src/app/mapping/class/dataset.ts b/src/app/mapping/class/dataset.ts index d1834ce91a0ae4b4b0e9a2aad546eef1fee60abf..f1e198cceed173236101d580a585bf7d57a7cb7f 100644 --- a/src/app/mapping/class/dataset.ts +++ b/src/app/mapping/class/dataset.ts @@ -37,11 +37,13 @@ export class DatasetPath { public dcatProperty: Property | string; public path: string; public dcatClass: string; + public card: string; - constructor(dcatProperty: Property, path: string, dcatClass: string) { + constructor(dcatProperty: Property, path: string, dcatClass: string, card: string) { this.dcatProperty = dcatProperty; this.path = path; this.dcatClass = dcatClass; + this.card = card; } } diff --git a/src/app/mapping/class/requestMapping.ts b/src/app/mapping/class/requestMapping.ts new file mode 100644 index 0000000000000000000000000000000000000000..1ee7bfc81f37b2f18da848efd75de518e252120c --- /dev/null +++ b/src/app/mapping/class/requestMapping.ts @@ -0,0 +1,30 @@ +export class RequestMapping { + urls: string[]; + paths: Path[]; + fdpToken: string; + + constructor (urls: string[], paths: Path[], fdpToken: string) { + this.urls = urls; + this.paths = paths; + this.fdpToken = fdpToken; + } +} + +export class Path { + property: string; + path: string; + card: string; + dcatClass: 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/class/stringUtils.ts b/src/app/mapping/class/stringUtils.ts deleted file mode 100644 index d6516a1a0ebd87a6e7c03eff9bb1fafb2a24e938..0000000000000000000000000000000000000000 --- a/src/app/mapping/class/stringUtils.ts +++ /dev/null @@ -1,33 +0,0 @@ -export class StringUtils { - - trimPropertyName(value) { - return value.replace(/\s/g, ''); - } - - getValueFormatByType(value) { - if(value === undefined || value === ''){ - return String(); - } - //is Number - let isNumber = !isNaN(value); - if (isNumber) { - return Number(value); - } - // is Boolean - if(value === "true" || value === "false"){ - return JSON.parse(value.toLowerCase()); - } - return String(value); - } - - hasContent(values) { - if (values.length > 0) { - for (let i = 0; i < values.length; i++) { - if (values[i]) { - return true; - } - } - } - return false; - } -} \ No newline at end of file diff --git a/src/app/mapping/mapping.component.html b/src/app/mapping/mapping.component.html index bcc97e8562041c5e4c4118d6b983a38b58527185..38d1af0836cbb67041ebb3dc1a44df01a5f1e665 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 8c96f2d4980586f229fe1775a043161851cb310b..2116435c639857710464bdeb53df7382f7e2357e 100644 --- a/src/app/mapping/mapping.component.ts +++ b/src/app/mapping/mapping.component.ts @@ -1,19 +1,19 @@ import { HttpResponse } from '@angular/common/http'; -import { AfterContentChecked, AfterViewChecked, ChangeDetectorRef, Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild } from '@angular/core'; -import { FormArray } from '@angular/forms'; +import { ChangeDetectorRef, Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { Router } from '@angular/router'; -import { FileSaverService } from 'ngx-filesaver'; -import { version } from 'process'; + import { Observable, of, Subscription } from 'rxjs'; import { map } from 'rxjs/operators'; import { environment } from 'src/environments/environment.prod'; +import { TokenStorageService } from '../authentication/services/token-storage.service'; import { DatasetCrudService } from '../datasets/services/dataset-crud.service'; import { Property, DatasetPath, Distribution, ResponseFileTsv, OldProperty } from './class/dataset'; +import { Path, RequestMapping, ResponseMapping } from './class/requestMapping'; import { FeedbackDialogComponent } from './dialog/feedback-dialog/feedback-dialog.component'; import { MappingService } from './service/mapping.service'; @@ -25,13 +25,12 @@ import { MappingService } from './service/mapping.service'; }) export class MappingComponent implements OnInit, OnDestroy { - datasetPathArray: DatasetPath[] = []; addDistribution = false check = false; distributions: Property[] = []; ontology: string; - urls: any[] = []; itemsdataset: any[] = [] + urls: any[] = []; datasets: Property[]; vocabularies: Property[]; filteredOptions: Observable<string[]>; @@ -51,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 fileSaverService: FileSaverService, 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(); @@ -60,7 +59,12 @@ export class MappingComponent implements OnInit, OnDestroy { ngOnInit() { console.log(this.type) + this.urls = this.dataSetService.urls; + console.table(this.urls); + this.ids = this.dataSetService.idsUrls; if (this.type !== "ISO 19115") { + this.urls = this.dataSetService.urls; + this.ids = this.dataSetService.idsUrls; this.itemsdataset = this.dataSetService.itemsDataset; console.log(this.itemsdataset) this.ids = this.dataSetService.ids; @@ -68,14 +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); - } else { - this.urls = this.dataSetService.itemsDataset; - this.ids = this.dataSetService.ids; } } - + selectOntology(): void { this.dataSetService.getLocally(`./assets/geodcat.json`).subscribe( @@ -135,41 +136,48 @@ export class MappingComponent implements OnInit, OnDestroy { } publishDataset(): void { - let properties = "" - let data: string = ''; - let postedDatastes = []; + let paths: Path[] = []; + + 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, 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 postedDatasets = []; let notPostedDatasets = []; this.loading = true; const requestPromises: Promise<any>[] = []; - for (let i = 0; i < this.datasetMappedMetadatas.length; i++) { - - properties = this.buildRDF(this.datasets, this.datasetMappedMetadatas, i); - data = this.getDatasetEmpty(properties); + 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);*/ - 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); - const location = resp.headers.get("location"); - const datasetId = location.substring(location.search("dataset/") + 8, location.length); - if (this.distributionMappedMetadatas.length > 0) { - const properties = this.buildRDF(this.distributions, this.distributionMappedMetadatas, i) - const distribution = this.getDistributionEmpty(properties, datasetId) - console.log(datasetId); - this.dataSetService.createDistribution(distribution).subscribe(); - } - }) - requestPromises.push(requestPromise); - } Promise.all(requestPromises).finally(() => { this.loading = false; this.dialog.open(FeedbackDialogComponent, { data: { - postedMetadatas: postedDatastes, + postedMetadatas: postedDatasets, notPostedMetadatas: notPostedDatasets } }).afterClosed().subscribe(); @@ -210,9 +218,9 @@ export class MappingComponent implements OnInit, OnDestroy { let notPostedDatasets = []; this.loading = true; const requestPromises: Promise<any>[] = []; - for (let i = 0; i < this.itemsdataset.length; i++) { + for (let i = 0; i < this.urls.length; i++) { - let requestPromise = this.dataSetService.createDatasetXml(this.itemsdataset[i]).then((resp: HttpResponse<any>) => { + let requestPromise = this.dataSetService.createDatasetXml(this.urls[i]).then((resp: HttpResponse<any>) => { if (resp.status.toString().startsWith('2')) { postedDatastes.push(this.ids[i]); } else { @@ -258,7 +266,7 @@ export class MappingComponent implements OnInit, OnDestroy { } return properties; } - + /* function to get recursively all the keys and values from the JSON object */ @@ -442,24 +450,29 @@ export class MappingComponent implements OnInit, OnDestroy { console.log('index = ' + this.index); } - downloadJson() { + createObjectToExport(): DatasetPath[] { + let datasetPathArray: DatasetPath[] = [] for (let i = 0; i < this.datasets.length; i++) { if (this.selectedPaths[i]) { - this.datasetPathArray.push(new DatasetPath(this.datasets[i], this.selectedPaths[i], 'dcat:dataset')); + datasetPathArray.push(new DatasetPath(this.datasets[i], this.selectedPaths[i], 'dcat:dataset', this.datasets[i].card)); } } for (let i = 0; i < this.distributions.length; i++) { if (this.distributionSelectedPaths[i]) { - this.datasetPathArray.push(new DatasetPath(this.distributions[i], this.distributionSelectedPaths[i], 'dcat:distribution')) + datasetPathArray.push(new DatasetPath(this.distributions[i], this.distributionSelectedPaths[i], 'dcat:distribution', this.distributions[i].card)) } } - console.table(this.datasetPathArray) + return datasetPathArray; + } + + downloadJson() { + + let datasetPathArray = this.createObjectToExport(); + + - /*const fileName = 'paths.json'; - const fileType = this.fileSaverService.genType(fileName); - const txtBlob = new Blob([(JSON.stringify(datasetPathArray)).toString()], { type: fileName }); - this.fileSaverService.save(txtBlob, fileName);*/ - this.mappingService.downloadFile(this.datasetPathArray); + + this.mappingService.downloadFile(datasetPathArray); } openFileInputDialog(): void { @@ -481,7 +494,7 @@ export class MappingComponent implements OnInit, OnDestroy { } } - + importJson(event: Event) { const files: FileList = (event.target as HTMLInputElement).files; const jsonFile = files[0]; @@ -496,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') { @@ -526,22 +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, ''); + } @@ -599,7 +613,8 @@ export class MappingComponent implements OnInit, OnDestroy { } ngOnDestroy(): void { - this.mappingService.postFile(this.datasetPathArray, this.catalogId).subscribe(); + let datasetPathArray = this.createObjectToExport(); + this.mappingService.postFile(datasetPathArray, this.catalogId).subscribe(); } private getDistributionEmpty(properties: string, datasetId: string): string { return `@prefix dcat: <http://www.w3.org/ns/dcat#>. diff --git a/src/app/mapping/service/mapping.service.ts b/src/app/mapping/service/mapping.service.ts index b43b8d434d1f2fec9fa36b418fa31a83a2213405..e1c82833a4a1a60baf19b70dcee6e451e8e41551 100644 --- a/src/app/mapping/service/mapping.service.ts +++ b/src/app/mapping/service/mapping.service.ts @@ -4,6 +4,8 @@ import { TokenStorageService } from 'src/app/authentication/services/token-stora import { SmartHarvesterUser } from 'src/app/user/model/user'; import { environment } from 'src/environments/environment'; import { DatasetPath } from '../class/dataset'; +import { RequestMapping } from '../class/requestMapping'; + @Injectable({ providedIn: 'root' @@ -11,6 +13,8 @@ import { DatasetPath } from '../class/dataset'; export class MappingService { + smartHarvesterUrl = environment.smartharvesterUrl; + fdpUrl = environment.fdpUrl; fds2Token: string = this.storageService.getToken(); constructor(private storageService: TokenStorageService, private http: HttpClient) { } @@ -33,7 +37,7 @@ export class MappingService { const data: FormData = new FormData(); data.append('file', body); - const req = new HttpRequest('POST', `${environment.smartharvesterUrl}/harvester/api/storeMapping/upload/${catalogId}`, data, { + const req = new HttpRequest('POST', `${this.smartHarvesterUrl}/harvester/api/storeMapping/upload/${catalogId}`, data, { headers: new HttpHeaders({ 'Authorization': 'Bearer ' + this.fds2Token @@ -142,4 +146,21 @@ export class MappingService { return result; } + + async postToFdpFropSmartharvester(catalogId: string, data: RequestMapping): Promise<any> { + + if(this.fds2Token) { + const httpOptions = new Headers(); + httpOptions.append('Content-Type', 'application/json'); + httpOptions.append('Accept', 'application/json'); + httpOptions.append('Authorization', `Bearer ${this.fds2Token}`) + let url = `${this.smartHarvesterUrl}/harvester/api/transform/publish?fdpUrl=${this.fdpUrl}&catalogId=${catalogId}`; + + const myInit = { method: 'POST', body: JSON.stringify(data), headers: httpOptions}; + const myRequest = new Request(url, myInit); + + return fetch(myRequest, myInit); + } + + } } diff --git a/src/app/publishapi/publishapi.component.ts b/src/app/publishapi/publishapi.component.ts index a015db018d88a7594af09437e861192492f24d34..f3d443b0fcfc1276a3a5f2a42f1b7a35d59ab6d3 100644 --- a/src/app/publishapi/publishapi.component.ts +++ b/src/app/publishapi/publishapi.component.ts @@ -356,6 +356,7 @@ export class PublishApiComponent implements OnInit { resetDataset() { this.datasetService.resetDataset(); + this.datasetService.resetUrls(); } openDatasetsSelectDialog() {