diff --git a/src/app/datasets/services/dataset-crud.service.ts b/src/app/datasets/services/dataset-crud.service.ts index 54921f9b7ad5fb0e073973af546d60ee2661bc85..0199c6eb7dbbf31601e1136f9456867983a54341 100644 --- a/src/app/datasets/services/dataset-crud.service.ts +++ b/src/app/datasets/services/dataset-crud.service.ts @@ -13,65 +13,92 @@ const FDP_URL = environment.fdpUrl; export class DatasetCrudService { fds2Token: string = this.sessionStorage.getFDPToken(); - public results: string[] = []; - itemsDataset: Object[] = [] ; - constructor(private http: HttpClient,private appConfig: AppConfiguration, private parserService: ParseXmlService, private sessionStorage: TokenStorageService) { } - - createDataSet(data:string): Observable<Object> { - if (this.fds2Token) { - const httpOptions = { - headers: new HttpHeaders({ - 'Accept': 'text/turtle', - 'Content-Type': 'text/turtle', - 'Authorization': 'Bearer '+ this.fds2Token - }) - }; - - return this.http.post(FDP_URL +"/dataset", data, httpOptions ); - } - - + public results: string[] = []; + itemsDataset: Object[] = []; + constructor(private http: HttpClient, private appConfig: AppConfiguration, private parserService: ParseXmlService, private sessionStorage: TokenStorageService) { } + + + createDataset(data: string): Observable<any> { + if (this.fds2Token) { + const httpOptions = { + headers: new HttpHeaders({ + 'Accept': 'text/turtle', + 'Content-Type': 'text/turtle', + 'Authorization': 'Bearer ' + this.fds2Token + }) + }; + + return this.http.post(FDP_URL + "/dataset", data, httpOptions); + } + } + + draftDataset(url: string) { + if (this.fds2Token) { + const httpOptions = { + headers: new HttpHeaders({ + 'Content-Type': 'text/turtle', + 'Authorization': 'Bearer ' + this.fds2Token + }) + }; + + return this.http.put(`${url}/meta/state`, { "current": "PUBLISHED" }, httpOptions); + } + } + + updateDataset(data: string, url: string): Observable<Object> { + if (this.fds2Token) { + const httpOptions = { + headers: new HttpHeaders({ + 'Content-Type': 'text/turtle', + 'Authorization': 'Bearer ' + this.fds2Token + }) + }; + + return this.http.put(url, data, httpOptions); + } } - createDistribution(data:string){ + createDistribution(data: string) { if (this.fds2Token) { const httpOptions = { headers: new HttpHeaders({ - 'Accept': 'text/turtle', - 'Content-Type': 'text/turtle', - 'Authorization': 'Bearer '+ this.fds2Token + 'Accept': 'text/turtle', + 'Content-Type': 'text/turtle', + 'Authorization': 'Bearer ' + this.fds2Token }) }; - - let resultat = this.http.post(FDP_URL +"/distribution", data, httpOptions ).subscribe((r)=>{ + + let resultat = this.http.post(FDP_URL + "/distribution", data, httpOptions).subscribe((r) => { console.log('reponse: ', r); return JSON.stringify(resultat); - }) ; + }); } } getDatasetsFromApi(url: string, params: string): Observable<any[]> { const httpOptions = { - headers: new HttpHeaders({'Content-Type': 'Application/json'})}; + headers: new HttpHeaders({ 'Content-Type': 'Application/json' }) + }; return this.http.get<any[]>(`${url}/${params}`, httpOptions); } - findDataSetByTitle(title:string){ + findDataSetByTitle(title: string) { let exist = false; - let query1='query=PREFIX dcterms: <http://purl.org/dc/terms/> SELECT * WHERE { ?uri dcterms:title "'+ escape(title) +'". }' + let query1 = 'query=PREFIX dcterms: <http://purl.org/dc/terms/> SELECT * WHERE { ?uri dcterms:title "' + escape(title) + '". }' this.parserService.getXmlResult(query1).subscribe( - data=>{ - if (data){ - this.results = []; - data.results.bindings.forEach(element => { this.results.push(element);}); - if (this.results[0]) { - - let exist = true; - } - }}); - return exist + data => { + if (data) { + this.results = []; + data.results.bindings.forEach(element => { this.results.push(element); }); + if (this.results[0]) { + + let exist = true; + } + } + }); + return exist } getLocally<T = any>(path: string): Observable<T> { diff --git a/src/app/mapping/mapping.component.html b/src/app/mapping/mapping.component.html index e1becf1b93df1a889658709c218179e3db0154a3..b6983e1cf1a5f8f97521ca56b11833a12a20e972 100644 --- a/src/app/mapping/mapping.component.html +++ b/src/app/mapping/mapping.component.html @@ -12,8 +12,8 @@ <div class="col-4"> <nb-form-field> - <input *ngIf=" dataset.identifier !== 'dct:hasVersion'" nbInput fullWidth type="text" value="{{dataset.identifier}} " disabled /> - <input *ngIf=" dataset.identifier === 'dct:hasVersion' " nbInput fullWidth type="text" value="{{dataset.identifier}} *" disabled /> + <input *ngIf=" dataset.identifier !== 'dct:hasVersion' && dataset.identifier !== 'dct:title'" nbInput fullWidth type="text" value="{{dataset.identifier}} " disabled /> + <input *ngIf=" dataset.identifier === 'dct:hasVersion' || 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> <nb-icon [icon]=" 'question-mark-circle-outline' " pack="eva"> @@ -25,11 +25,11 @@ <div class="col-8"> <nb-form-field> - <input *ngIf=" dataset.identifier === 'dct:hasVersion' " required #autoInput #{{dataset.identifier}} fullWidth id="{{dataset.identifier}}" + <input *ngIf="dataset.identifier === 'dct:hasVersion' || dataset.identifier === 'dct:title' " required #autoInput #{{dataset.identifier}}="ngModel" fullWidth id="{{dataset.identifier}}" name="{{dataset.identifier}}" nbInput (input)="onChange()" placeholder="Enter value" [nbAutocomplete]="auto" [(ngModel)]="selectedPaths[index]" (focus)="reset()" autocomplete="false"/> - - <input *ngIf=" dataset.identifier !== 'dct:hasVersion' " #autoInput #{{dataset.identifier}} fullWidth id="{{dataset.identifier}}" + <div *ngIf="dataset.identifier.invalid && (dataset.identifier.dirty || dataset.identifier.touched)">champ obligatoire</div> + <input *ngIf=" dataset.identifier !== 'dct:hasVersion' && dataset.identifier !== 'dct:title'" #autoInput #{{dataset.identifier}} fullWidth id="{{dataset.identifier}}" nbInput (input)="onChange()" placeholder="Enter value" [nbAutocomplete]="auto" [(ngModel)]="selectedPaths[index]" (focus)="reset()" autocomplete="false"/> diff --git a/src/app/mapping/mapping.component.ts b/src/app/mapping/mapping.component.ts index 2eef9720648b2d21321270774a216f2c56b9f172..03bf259799db9bbe4754d8fde42520c2a8e578b0 100644 --- a/src/app/mapping/mapping.component.ts +++ b/src/app/mapping/mapping.component.ts @@ -4,6 +4,7 @@ import { Observable, of } from 'rxjs'; import { map } from 'rxjs/operators'; import { environment } from 'src/environments/environment.prod'; import { DatasetCrudService } from '../datasets/services/dataset-crud.service'; +import { ParseXmlService } from '../services/parse-xml.service'; import { Dataset } from './class/dataset'; @@ -32,7 +33,7 @@ export class MappingComponent implements OnInit { @ViewChild('autoInput') input; @Input() catalogId: any; - constructor(private dataSetService: DatasetCrudService) { } + constructor(private dataSetService: DatasetCrudService, private parserService: ParseXmlService) { } ngOnInit() { @@ -83,29 +84,56 @@ export class MappingComponent implements OnInit { publishDataset() { let data: string = ''; let properties: string = ''; + let result = ''; this.mappedMetadatas.forEach((value: Map<string, string>, key: number) => { + let title = ""; properties = ""; + value.forEach((value: string, key: string) => { + if (key === 'dct:title') { title = value }; + switch (key) { + case 'dct:landingPage': + properties += key + ' <' + value + '>;\n'; + break; + case 'dcat:theme': + properties += key + ' <' + value + '>;\n'; + break; + case 'dcat:contactPoint': + properties += key + ' <' + value + '>;\n'; + break; + default: + properties += key + ' "' + value + '";\n'; + break; + } - properties += key + ' "' + value + '";\n'; }) + 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\ - \n\ -s:new\n\ -a dcat:Dataset, dcat:Resource;\n\ -dct:isPartOf c:'+ this.catalogId + ';\n' + properties + '.'; + @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\ + \n\ + s:new\n\ + a dcat:Dataset, dcat:Resource;\n\ + dct:isPartOf c:'+ this.catalogId + ';\n' + properties + '.'; + + let query = 'query=PREFIX dcat: <http://www.w3.org/ns/dcat#>\n\ + PREFIX dct: <http://purl.org/dc/terms/>\n\ + SELECT ?dataset\n\ + where {\n\ + ?dataset a dcat:Dataset;\n\ + dct:title "' + title + '" ;\n\ + dct:isPartOf <https://f2ds.eosc-pillar.eu/catalog/' + this.catalogId + '>. } ' console.log('data: ' + data); - this.dataSetService.createDataSet(data).subscribe( - - ); + + + this.dataSetService.createDataset(data).subscribe(r => console.log(r)); + }) } diff --git a/src/app/publishapi/publishapi.component.ts b/src/app/publishapi/publishapi.component.ts index 32c4fa4cdeddd9a7fb4a379981e2a23f6ec61cde..d8f7340b73aac0b0adb6ae3db74674c008483398 100644 --- a/src/app/publishapi/publishapi.component.ts +++ b/src/app/publishapi/publishapi.component.ts @@ -258,6 +258,6 @@ export class PublishApiComponent implements OnInit { } resetDataset() { - + this.datasetService.resetDataset(); } }