Skip to content
Snippets Groups Projects

Fix/from uc2

Merged Baptiste Toulemonde requested to merge fix/fromUC2 into master
1 file
+ 24
17
Compare changes
  • Side-by-side
  • Inline
@@ -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 {
Loading