Commit e206063f authored by Paulo's avatar Paulo
Browse files

Ajout d'un service qui recupere les donees sparql

parent e9083b0b
......@@ -34,6 +34,7 @@ import { AppConfiguration } from './AppConfiguration';
import { ElasticsearchComponent } from './elasticsearch/elasticsearch.component';
import { PublishapiComponent } from './publishapi/publishapi.component';
import { SearchComponent } from './search/search.component'
import { ParseXmlService } from './services/parse-xml.service';
......@@ -73,6 +74,7 @@ import { SearchComponent } from './search/search.component'
],
providers: [
AppConfiguration,
ParseXmlService,
{
provide: APP_INITIALIZER,
useFactory: AppConfigurationFactory,
......
......@@ -10,7 +10,7 @@
<th>Uri dataset</th>
</tr>
<tr *ngFor="let item of xmlItems">
<td>{{item.uri}}</td>
<td>{{item}}</td>
</tr>
</table>
</div>
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import xml2js from 'xml2js';
import { ParseXmlService } from '../services/parse-xml.service';
@Component({
......@@ -14,10 +15,11 @@ import xml2js from 'xml2js';
export class SearchComponent implements OnInit {
public xmlItems: any;
public xmlItems: string[] = [];
constructor(
private http: HttpClient
private http: HttpClient,
private parserService: ParseXmlService
) { }
ngOnInit(): void {
......@@ -29,7 +31,6 @@ export class SearchComponent implements OnInit {
let query: string;
let parser = new xml2js.Parser();
query ='query=SELECT * where {?s a <http://www.w3.org/ns/dcat#Dataset> }'
const httpOptions = {
......@@ -39,7 +40,7 @@ export class SearchComponent implements OnInit {
'responseType': 'text'
})
};
/*
this.http.post("http://10.6.10.9:8888/blazegraph/sparql",
query,
{headers: new HttpHeaders()
......@@ -54,26 +55,39 @@ export class SearchComponent implements OnInit {
.then((data) => {
this.xmlItems = data;
});
});
}); */
this.parserService.getXmlResult("http://10.6.10.9:8888/blazegraph/sparql",query).subscribe(
data=>{
if (data){
console.log("Data : ", data.results.bindings[0].s.value);
data.results.bindings.forEach(element => {
console.log("element : ", element.s.value)
this.xmlItems.push(element.s.value);
});
}
})
console.log("All data : ", this.xmlItems)
return null;
}
parseXML(data) {
return new Promise(resolve => {
var k: string | number,
arr = [],
parser = new xml2js.Parser(
{
trim: true,
explicitArray: true
});
parser.parseString(data, function (err, result) {
var obj = result.results;
for (k in obj.result) {
var item = obj.result[k];
let k: string | number,
arr = [],
parser = new xml2js.Parser(
{
trim: true,
explicitArray: true
});
parser.parseString(data, (err, result) => {
console.error("Object found : ", result);
var obj = result.results;
for (k in obj.result.bindings.s) {
var item = obj.result.bindings.s[k];
arr.push({
uri: item.uri[0]
uri: item.uri[0]
});
}
resolve(arr);
......
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class ParseXmlService {
constructor(private http:HttpClient) { }
deserializedXmlObject = new BehaviorSubject(null);
getXmlResult(path,body): Observable<any> {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
'responseType': 'application/sparql-results+xml'
})
};
return this.http.post(path,body, httpOptions);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment