diff --git a/src/app/mapping/mapping.component.html b/src/app/mapping/mapping.component.html index b631d2f17a5bcc54dd3be2aec6df86a6535049c9..aeaadc9c2d2a045af37159fa4e22c222b81f33da 100644 --- a/src/app/mapping/mapping.component.html +++ b/src/app/mapping/mapping.component.html @@ -21,10 +21,10 @@ <nb-form-field> <input - *ngIf=" dataset.identifier !== 'dct:hasVersion' && dataset.identifier !== 'dct:title'" + *ngIf=" dataset.identifier !== 'dct:title'" nbInput fullWidth type="text" value="{{dataset.identifier}} " disabled /> <input - *ngIf=" dataset.identifier === 'dct:hasVersion' || dataset.identifier === 'dct:title' " + *ngIf=" dataset.identifier === 'dct:title' " nbInput fullWidth type="text" value="{{dataset.identifier}} *" disabled /> <button nbSuffix nbTooltip="{{dataset.name}}: {{dataset.usageNote}}" nbTooltipStatus="info" nbButton status="basic" ghost> @@ -38,20 +38,20 @@ <nb-form-field> <input - *ngIf="dataset.identifier === 'dct:hasVersion' || dataset.identifier === 'dct:title' " + *ngIf="dataset.identifier === 'dct:title' " required #autoInput #{{dataset.identifier}}="ngModel" fullWidth id="{{dataset.identifier}}" name="{{dataset.identifier}}" nbInput (ngModelChange)="onModelChange($event)" [nbAutocomplete]="auto" - [(ngModel)]="selectedPaths[index]" autocomplete="false" (focus)="reset()" /> + [(ngModel)]="selectedPaths[index]" (focus)="reset()" /> <div *ngIf="dataset.identifier.invalid && (dataset.identifier.dirty || dataset.identifier.touched)"> champ obligatoire</div> <input - *ngIf=" dataset.identifier !== 'dct:hasVersion' && dataset.identifier !== 'dct:title'" + *ngIf="dataset.identifier !== 'dct:title'" #autoInput #{{dataset.identifier}}="ngModel" fullWidth id="{{dataset.identifier}}" name="{{dataset.identifier}}" nbInput (ngModelChange)="onModelChange($event)" [nbAutocomplete]="auto" - [(ngModel)]="selectedPaths[index]" autocomplete="false" (focus)="reset()" /> + [(ngModel)]="selectedPaths[index]" (focus)="reset()" /> <nb-autocomplete #auto> diff --git a/src/app/mapping/mapping.component.ts b/src/app/mapping/mapping.component.ts index 23778ce644ab88b9df0a9156601a0f2ad9a51666..718dbbc23494c76fabba0ba458c0b803bfa82ef1 100644 --- a/src/app/mapping/mapping.component.ts +++ b/src/app/mapping/mapping.component.ts @@ -45,6 +45,7 @@ export class MappingComponent implements OnInit { constructor(private dataSetService: DatasetCrudService, private dialog: MatDialog, private route: Router, private fileSaverService: FileSaverService) { } ngOnInit() { + console.log(this.type) this.dataSetService.getLocally('./assets/dcat.json').subscribe( dataset => { this.dcatVocabulary = dataset; @@ -60,7 +61,9 @@ export class MappingComponent implements OnInit { this.ids = this.dataSetService.ids; this.ids this.keys = []; - this.type == "Dataverse" ? this.getKeysFromMetadataDataverse(this.itemsdataset[0], '') : this.getKeysFromMetadataDataverse(this.itemsdataset[0], ''); + this.type == "Dataverse" ? this.getKeysFromMetadataDataverse(this.itemsdataset[0], '') : this.getKeysFromMetadataCustom(this.itemsdataset[0], ''); + this.keys = Array.from(new Set(this.keys)); + console.table(this.keys) this.filteredOptions = of(this.keys); } @@ -70,6 +73,7 @@ export class MappingComponent implements OnInit { let mappedMetadata: Map<number, string> = new Map() for (let i = 0; i < this.selectedPaths.length; i++) { if (this.selectedPaths[i]) { + let tab = this.selectedPaths[i].split(' : '); this.type == "Dataverse" ? mappedMetadata.set(i, this.getValueDataverse(tab, item)) : mappedMetadata.set(i, this.getValueCustom(tab, item)); } @@ -79,6 +83,7 @@ export class MappingComponent implements OnInit { } publishDataset() { + let version = false; let data: string = ''; let properties: string = ''; let postedDatastes = []; @@ -89,6 +94,9 @@ export class MappingComponent implements OnInit { properties = ""; this.mappedMetadatas[i].forEach((value: string, index: number) => { let key = this.dcatVocabulary[index].identifier; + if (key === 'dct:hasVersion') { + version = true; + } if (Array.isArray(value)) { if (this.isMultiple(key)) { value.forEach(v => { @@ -102,6 +110,7 @@ export class MappingComponent implements OnInit { } }) + if (!version) properties += "dct:hasVersion \"undefined\";\n" data = '\@prefix dcat: <http://www.w3.org/ns/dcat#>.\n\ @prefix dct: <http://purl.org/dc/terms/>.\n\ @@ -148,34 +157,34 @@ export class MappingComponent implements OnInit { }) } - private writeRdf(key: string, value: string): string{ + private writeRdf(key: string, value: string): string { let properties = ""; (value && typeof value === "string") ? value = this.replaceAll(value, '\n', '') : value; - switch (key) { - case 'dcat:landingPage': - properties += key + ' <' + value + '>;\n'; - break; - case 'dcat:theme': - properties += key + ' <' + value + '>;\n'; - break; - case 'dcat:contactPoint': - properties += key + ' <' + value + '>;\n'; - break; - case 'dct:language': - properties += key + ' <' + value + '>;\n'; - break; - case 'dct:issued': - properties += key + ' "' + value + '"^^xsd:dateTime;\n'; - break; - case 'dct:modified': - properties += key + ' "' + value + '"^^xsd:dateTime;\n'; - break; - default: - properties += key + ' "' + value + '";\n'; - break; - } - return properties; + switch (key) { + case 'dcat:landingPage': + properties += key + ' <' + value + '>;\n'; + break; + case 'dcat:theme': + properties += key + ' <' + value + '>;\n'; + break; + case 'dcat:contactPoint': + properties += key + ' <' + value + '>;\n'; + break; + case 'dct:language': + properties += key + ' <' + value + '>;\n'; + break; + case 'dct:issued': + properties += key + ' "' + value + '"^^xsd:dateTime;\n'; + break; + case 'dct:modified': + properties += key + ' "' + value + '"^^xsd:dateTime;\n'; + break; + default: + properties += key + ' "' + value + '";\n'; + break; + } + return properties; } private replaceAll(str: string, find: string, replace: string) { if (str.includes(find)) { @@ -188,23 +197,31 @@ export class MappingComponent implements OnInit { /* function to get recursively all the keys and values from the JSON object */ + getKeysFromMetadataCustom(obj: Object, keyParent: string) { Object.keys(obj).forEach(key => { - - if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) { - if (keyParent) { - this.getKeysFromMetadataCustom(obj[key], keyParent + ' : ' + key); + if (typeof obj[key] === 'object') { + if (Array.isArray(obj[key])) { + obj[key].forEach(e => { + if (typeof e === 'object') { + Object.keys(e).forEach(k => { + this.keys.push(keyParent + k); + }) + this.getKeysFromMetadataCustom(e, keyParent + key + ' : '); + } + }); + this.keys.push(keyParent + key ) + this.getKeysFromMetadataCustom(obj[key], keyParent + key + ' : '); } else { - this.getKeysFromMetadataCustom(obj[key], key); + this.keys.push(keyParent + key ) + this.getKeysFromMetadataCustom(obj[key], keyParent + key + ' : '); } } else { - if (keyParent) { - this.keys.push(keyParent + ' : ' + key) - } else { - this.keys.push(key) - } + + this.keys.push(keyParent + key ); + } - }) + }); } getKeysFromMetadataDataverse(obj: Object, keyParent: string) { @@ -243,19 +260,37 @@ export class MappingComponent implements OnInit { private getValueCustom(tab: string[], item: Object) { let obj: Object; - for (let i = 0; i < tab.length; i++) { - if (tab.length == 1) { - return item[tab[0]]; - } else { + if (tab.length == 1) { + return item[tab[0]]; + } else { + for (let i = 0; i < tab.length; i++) { if (i == 0) { obj = item[tab[i]] } else if (i < tab.length - 1 && obj[tab[i]]) { obj = obj[tab[i]]; } else { - if (Array.isArray(obj[tab[i]])) { - return obj[tab[i]] + if (Array.isArray(obj) && obj.some(e => typeof e === 'object')) { + let array = []; + obj.forEach(e => { + if (e[tab[i]]){ + array.push(e[tab[i]]); + } + }); + return array; + } else if (typeof obj === 'object' && Object.values(obj).every(e => Array.isArray(e))) { + let array = []; + for (let element in obj) { + obj[element].forEach(e => { + if (e[tab[i]]){ + array.push(e[tab[i]]); + } + }) + } + return array; + } else if (Array.isArray(obj[tab[i]])) { + return Object.values(obj[tab[i]]); } else { - return obj[tab[i]] + return obj[tab[i]]; } } } @@ -370,7 +405,7 @@ export class MappingComponent implements OnInit { for (let i = 0; i < datasetPath.length; i++) { this.selectedPaths[i] = datasetPath[i].path; if (typeof datasetPath[i].dcatProperty !== 'object') { - this.dcatVocabulary[i] = this.vocabularies.filter( v => v.identifier === <string>datasetPath[i].dcatProperty)[0]; + this.dcatVocabulary[i] = this.vocabularies.filter(v => v.identifier === <string>datasetPath[i].dcatProperty)[0]; } else { this.dcatVocabulary[i] = <Dataset>datasetPath[i].dcatProperty; } @@ -382,10 +417,12 @@ export class MappingComponent implements OnInit { addField(index: number) { let addedDcat: Dataset = new Dataset(this.dcatVocabulary[index].name, this.dcatVocabulary[index].identifier, this.dcatVocabulary[index].usageNote, true); this.dcatVocabulary.splice(index + 1, 0, addedDcat); + this.selectedPaths.splice(index + 1, 0, ''); } deleteField(index: number) { this.dcatVocabulary.splice(index, 1); + this.selectedPaths.splice(index, 1); } isMultiple(vocabulary: string): boolean { diff --git a/src/app/publishapi/publishapi.component.ts b/src/app/publishapi/publishapi.component.ts index ace16d9bc23da3a8af8dfadbc796dcc5ad27151c..b86fee9fc69c04379f38ab53a9b938a7ada8a35c 100644 --- a/src/app/publishapi/publishapi.component.ts +++ b/src/app/publishapi/publishapi.component.ts @@ -174,9 +174,10 @@ export class PublishApiComponent implements OnInit { } downloadJson(): void { + let windowVar: any = window.navigator; const newBlob = new Blob([this.openApiService.getPrettyJson(this.openApi)], { type: 'application/json' }); - if (window.navigator && window.navigator.msSaveOrOpenBlob) { - window.navigator.msSaveOrOpenBlob(newBlob); + if (windowVar && windowVar.msSaveOrOpenBlob) { + windowVar.msSaveOrOpenBlob(newBlob); return; } const data = window.URL.createObjectURL(newBlob); diff --git a/src/app/stats/stats.component.ts b/src/app/stats/stats.component.ts index d1b5743d2c6fd62a40a4cb652465da1070efb256..2aba356e6157e19581da8828ee28bed82a7562dc 100644 --- a/src/app/stats/stats.component.ts +++ b/src/app/stats/stats.component.ts @@ -21,7 +21,7 @@ export class StatsComponent implements OnInit { let query1='query=prefix dct: <http://purl.org/dc/terms/>\n\ SELECT (COUNT(?s) AS ?triples) \n\ WHERE { ?s a <http://www.w3.org/ns/dcat#Catalog>;\n\ - dct:isPartOf <'+ environment.fdpUrl +'>\n\ + dct:isPartOf* <'+ environment.fdpUrl +'>\n\ }' this.parserService.getXmlResult(query1).subscribe(data=>{if (data){this.results = []; data.results.bindings.forEach(element => { this.results.push(element);}); this.stats.push(this.results[0]["triples"].value)