Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dad
FFDS-register-front
Commits
e206063f
Commit
e206063f
authored
Sep 25, 2020
by
Paulo
Browse files
Ajout d'un service qui recupere les donees sparql
parent
e9083b0b
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/app/app.module.ts
View file @
e206063f
...
...
@@ -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
,
...
...
src/app/search/search.component.html
View file @
e206063f
...
...
@@ -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>
src/app/search/search.component.ts
View file @
e206063f
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
);
...
...
src/app/services/parse-xml.service.ts
0 → 100644
View file @
e206063f
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
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment