Mercurial > hg > ng2-query-ismi
annotate app/query.service.ts @ 1:59b7c3afcc6b
first interface and http request.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 11 Jan 2016 19:25:53 +0100 |
parents | |
children | 80270f5a5735 |
rev | line source |
---|---|
1
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1 import {Injectable} from 'angular2/core'; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
2 import {Http, Headers} from 'angular2/http'; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
3 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
4 import 'rxjs/Rx'; // import all RxJS operators |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
5 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
6 import {QueryMode} from './query-mode'; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
7 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
8 @Injectable() |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
9 export class QueryService { |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
10 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
11 public QUERY_MODES: QueryMode[] = [ |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
12 {id: 'type_is', label:'Object type is'}, |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
13 {id: 'att_contains', label: 'Attribute contains'}]; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
14 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
15 constructor(private _http: Http) {} |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
16 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
17 getQueryModes(): QueryMode[] { |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
18 return this.QUERY_MODES; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
19 } |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
20 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
21 getQueryOptions(queryMode: string) { |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
22 var options = ['a1', 'b1', 'c1']; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
23 if (queryMode == 'Attribute contains') { |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
24 options = ['d', 'e', 'f']; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
25 } |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
26 return Promise.resolve(options); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
27 } |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
28 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
29 getIsmiObjectTypes() { |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
30 var headers = new Headers(); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
31 headers.append('Authorization', 'Basic ' + btoa('neo4j'+':'+'neo5j')); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
32 headers.append('Content-Type', 'application/json'); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
33 headers.append('Accept', 'application/json'); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
34 var data = { |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
35 'query': `MATCH (n) |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
36 WITH DISTINCT labels(n) AS labels |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
37 UNWIND labels AS label |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
38 RETURN DISTINCT label |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
39 ORDER BY label`, |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
40 'params': {} |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
41 }; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
42 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
43 console.debug("http:", this._http, " headers:", headers, " data:", data); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
44 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
45 var post = this._http.post('http://localhost:7474/db/data/cypher/', JSON.stringify(data), {'headers': headers}); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
46 console.debug("post:", post); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
47 var map = post.map(res => res.json()); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
48 console.debug("map:", map); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
49 map.subscribe( |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
50 data => console.debug("neo4j data=", data), |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
51 err => console.error("neo4j error=", err), |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
52 () => console.debug('neo4j query Complete') |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
53 ); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
54 } |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
55 } |