Revision 55964
Added by Argiro Kokogiannaki almost 5 years ago
searchDatasets.service.ts | ||
---|---|---|
1 | 1 |
import {Injectable} from '@angular/core'; |
2 |
import {Http, Response} from '@angular/http'; |
|
3 |
import {Observable} from 'rxjs/Observable'; |
|
4 |
import {SearchResult} from '../utils/entities/searchResult'; |
|
2 |
import {HttpClient} from "@angular/common/http"; |
|
3 |
import {SearchResult} from '../utils/entities/searchResult'; |
|
5 | 4 |
import {RefineResultsUtils} from './servicesUtils/refineResults.class'; |
6 |
import 'rxjs/add/observable/of'; |
|
7 |
import 'rxjs/add/operator/do'; |
|
8 |
import 'rxjs/add/operator/share'; |
|
5 |
|
|
6 |
|
|
9 | 7 |
import {DOI, StringUtils} from '../utils/string-utils.class'; |
10 |
import { ParsingFunctions } from '../landingPages/landing-utils/parsingFunctions.class'; |
|
11 |
import{EnvProperties} from '../utils/properties/env-properties'; |
|
8 |
import {ParsingFunctions} from '../landingPages/landing-utils/parsingFunctions.class'; |
|
9 |
import {EnvProperties} from '../utils/properties/env-properties'; |
|
10 |
import {map} from "rxjs/operators"; |
|
12 | 11 |
|
13 | 12 |
@Injectable() |
14 | 13 |
export class SearchDatasetsService { |
15 | 14 |
private sizeOfDescription: number = 270; |
16 | 15 |
public parsingFunctions: ParsingFunctions = new ParsingFunctions(); |
17 | 16 |
|
18 |
constructor(private http: Http ) {} |
|
17 |
constructor(private http: HttpClient ) {}
|
|
19 | 18 |
|
20 | 19 |
searchDatasets (params: string, refineParams:string, page: number, size: number, sortBy: string, refineFields:string[], properties:EnvProperties ):any { |
21 | 20 |
|
... | ... | |
35 | 34 |
|
36 | 35 |
|
37 | 36 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) |
38 |
.map(res => <any> res.json()) |
|
37 |
//.map(res => <any> res.json())
|
|
39 | 38 |
//.do(res => console.info(res)) |
40 |
.map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "dataset")]); |
|
39 |
.pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "dataset")])); |
|
40 |
|
|
41 | 41 |
} |
42 | 42 |
searchDatasetById (id: string , properties:EnvProperties):any { |
43 | 43 |
|
44 | 44 |
let url = properties.searchAPIURLLAst+"datasets/"+id+"?format=json"; |
45 | 45 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) |
46 |
.map(res => <any> res.json()) |
|
47 |
.map(res => this.parseResults(res, properties));
|
|
46 |
//.map(res => <any> res.json())
|
|
47 |
.pipe(map(res => this.parseResults(res, properties)));
|
|
48 | 48 |
} |
49 | 49 |
|
50 | 50 |
searchAggregators (id: string, params: string, refineParams:string, page: number, size: number, properties:EnvProperties ):any { |
... | ... | |
63 | 63 |
|
64 | 64 |
|
65 | 65 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) |
66 |
.map(res => <any> res.json()) |
|
67 |
.map(res => this.parseRefineResults(id, res['refineResults']))
|
|
66 |
//.map(res => <any> res.json())
|
|
67 |
.pipe(map(res => this.parseRefineResults(id, res['refineResults'])))
|
|
68 | 68 |
} |
69 | 69 |
|
70 | 70 |
searchDatasetsByDois (DOIs: string[], refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any { |
... | ... | |
86 | 86 |
|
87 | 87 |
|
88 | 88 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) |
89 |
.map(res => <any> res.json()) |
|
89 |
//.map(res => <any> res.json())
|
|
90 | 90 |
//.do(res => console.info(res)) |
91 |
.pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "dataset")])); |
|
91 | 92 |
|
92 |
.map(res => [res['meta'].total, this.parseResults(res['results'], properties),RefineResultsUtils.parse(res['refineResults'],refineFields, "dataset")]); |
|
93 | 93 |
} |
94 | 94 |
advancedSearchDatasets (params: string, page: number, size: number, sortBy: string, properties:EnvProperties ):any { |
95 | 95 |
let url = properties.searchResourcesAPIURL; |
... | ... | |
110 | 110 |
url += "&format=json"; |
111 | 111 |
|
112 | 112 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) |
113 |
.map(res => <any> res.json()) |
|
113 |
//.map(res => <any> res.json())
|
|
114 | 114 |
//.do(res => console.info(res)) |
115 |
.map(res => [res['meta'].total, this.parseResults(res['results'], properties)]);
|
|
115 |
.pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)]));
|
|
116 | 116 |
} |
117 | 117 |
searchDatasetsForEntity (params: string, page: number, size: number, properties:EnvProperties):any { |
118 | 118 |
let link = properties.searchAPIURLLAst; |
119 | 119 |
let url = link+params+"/datasets"+"?format=json"; |
120 | 120 |
|
121 | 121 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) |
122 |
.map(res => <any> res.json()) |
|
123 |
.map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); |
|
122 |
//.map(res => <any> res.json()) |
|
123 |
.pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); |
|
124 |
|
|
124 | 125 |
} |
125 | 126 |
|
126 | 127 |
searchDatasetsForDataproviders(params: string, page: number, size: number, properties:EnvProperties):any { |
127 | 128 |
let link = properties.searchAPIURLLAst; |
128 | 129 |
let url = link+params+ "&page="+(page-1)+"&size="+size + "&format=json"; |
129 | 130 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) |
130 |
.map(res => <any> res.json()) |
|
131 |
.map(res => [res['meta'].total, this.parseResults(res['results'], properties)]); |
|
131 |
//.map(res => <any> res.json()) |
|
132 |
.pipe(map(res => [res['meta'].total, this.parseResults(res['results'], properties)])); |
|
133 |
|
|
132 | 134 |
} |
133 | 135 |
|
134 | 136 |
parseResults(data: any, properties: EnvProperties): SearchResult[] { |
... | ... | |
347 | 349 |
numOfDatasets(url: string, properties:EnvProperties):any { |
348 | 350 |
|
349 | 351 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) |
350 |
.map(res => <any> res.json()) |
|
351 |
.map(res => res.total);
|
|
352 |
//.map(res => <any> res.json())
|
|
353 |
.pipe(map(res => res['total']));
|
|
352 | 354 |
} |
353 | 355 |
|
354 | 356 |
numOfEntityDatasets(id: string, entity: string, properties:EnvProperties):any { |
Also available in: Unified diff
[Library|Trunk]
Merge into trunk branch angular7 rev 55729