Revision 50586
Added by Argiro Kokogiannaki about 6 years ago
searchSoftware.service.ts | ||
---|---|---|
1 | 1 |
import {Injectable} from '@angular/core'; |
2 | 2 |
import {Http, Response} from '@angular/http'; |
3 | 3 |
import {Observable} from 'rxjs/Observable'; |
4 |
import {OpenaireProperties} from '../utils/properties/openaireProperties'; |
|
5 | 4 |
import {SearchResult} from '../utils/entities/searchResult'; |
6 | 5 |
import {RefineResultsUtils} from './servicesUtils/refineResults.class'; |
7 | 6 |
import 'rxjs/add/observable/of'; |
8 | 7 |
import 'rxjs/add/operator/do'; |
9 | 8 |
import 'rxjs/add/operator/share'; |
10 | 9 |
import { ParsingFunctions } from '../landingPages/landing-utils/parsingFunctions.class'; |
10 |
import{EnvProperties} from '../utils/properties/env-properties'; |
|
11 | 11 |
|
12 | 12 |
@Injectable() |
13 | 13 |
export class SearchSoftwareService { |
... | ... | |
16 | 16 |
|
17 | 17 |
constructor(private http: Http ) {} |
18 | 18 |
|
19 |
searchSoftware (params: string, refineParams:string, page: number, size: number, refineFields:string[] ):any { |
|
19 |
searchSoftware (params: string, refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any {
|
|
20 | 20 |
|
21 |
let link = OpenaireProperties.getSearchAPIURLLast()+"software";
|
|
21 |
let link = properties.searchAPIURLLAst+"software";
|
|
22 | 22 |
|
23 | 23 |
let url = link+"?"; |
24 | 24 |
if(params!= null && params != '' ) { |
... | ... | |
30 | 30 |
url += "&page="+ (page-1) +"&size="+size+"&format=json"; |
31 | 31 |
|
32 | 32 |
|
33 |
return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url)
|
|
33 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
34 | 34 |
.map(res => <any> res.json()) |
35 | 35 |
//.do(res => console.info(res)) |
36 | 36 |
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "software")]); |
37 | 37 |
} |
38 |
searchSoftwareById (id: string ):any { |
|
38 |
searchSoftwareById (id: string, properties:EnvProperties ):any {
|
|
39 | 39 |
|
40 |
let url = OpenaireProperties.getSearchAPIURLLast()+"software/"+id+"?format=json";
|
|
40 |
let url = properties.searchAPIURLLAst+"software/"+id+"?format=json";
|
|
41 | 41 |
|
42 | 42 |
|
43 |
return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url)
|
|
43 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
44 | 44 |
.map(res => <any> res.json()) |
45 | 45 |
.map(res => this.parseResults(res)); |
46 | 46 |
} |
47 | 47 |
|
48 |
searchAggregators (id: string, params: string, refineParams:string, page: number, size: number ):any { |
|
48 |
searchAggregators (id: string, params: string, refineParams:string, page: number, size: number, properties:EnvProperties ):any {
|
|
49 | 49 |
|
50 |
let link = OpenaireProperties.getSearchAPIURLLast()+"software";
|
|
50 |
let link = properties.searchAPIURLLAst+"software";
|
|
51 | 51 |
|
52 | 52 |
let url = link+"?"+"&format=json"; |
53 | 53 |
if(params!= null && params != '' ) { |
... | ... | |
59 | 59 |
url += "&page="+(page-1)+"&size="+size; |
60 | 60 |
|
61 | 61 |
|
62 |
return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url)
|
|
62 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
63 | 63 |
.map(res => <any> res.json()) |
64 | 64 |
.map(res => this.parseRefineResults(id, res['refineResults'])) |
65 | 65 |
} |
66 | 66 |
|
67 |
searchSoftwareByDois (DOIs: string[], refineParams:string, page: number, size: number, refineFields:string[] ):any { |
|
68 |
let link = OpenaireProperties.getSearchAPIURLLast()+"software";
|
|
67 |
searchSoftwareByDois (DOIs: string[], refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any {
|
|
68 |
let link = properties.searchResourcesAPIURL+"software";
|
|
69 | 69 |
let url = link+"?"; |
70 | 70 |
var doisParams = ""; |
71 | 71 |
|
... | ... | |
82 | 82 |
url += "&page="+ (page-1) +"&size="+size+"&format=json"; |
83 | 83 |
|
84 | 84 |
|
85 |
return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url)
|
|
85 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
86 | 86 |
.map(res => <any> res.json()) |
87 | 87 |
//.do(res => console.info(res)) |
88 | 88 |
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "software")]); |
89 | 89 |
} |
90 |
advancedSearchSoftware (params: string, page: number, size: number ):any { |
|
91 |
let url = OpenaireProperties.getSearchResourcesAPIURL();
|
|
90 |
advancedSearchSoftware (params: string, page: number, size: number, properties:EnvProperties ):any {
|
|
91 |
let url = properties.searchResourcesAPIURL;
|
|
92 | 92 |
var basicQuery = "(oaftype exact result) and (resulttypeid exact software) " |
93 | 93 |
url += "?query="; |
94 | 94 |
if(params!= null && params != '' ) { |
... | ... | |
100 | 100 |
url += "&page="+(page-1)+"&size="+size; |
101 | 101 |
url += "&format=json"; |
102 | 102 |
|
103 |
return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url)
|
|
103 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
104 | 104 |
.map(res => <any> res.json()) |
105 | 105 |
//.do(res => console.info(res)) |
106 | 106 |
.map(res => [res['meta'].total, this.parseResults(res['results'])]); |
107 | 107 |
} |
108 |
searchSoftwareForEntity (params: string, page: number, size: number):any { |
|
109 |
let link = OpenaireProperties.getSearchAPIURLLast();
|
|
108 |
searchSoftwareForEntity (params: string, page: number, size: number, properties:EnvProperties):any {
|
|
109 |
let link = properties.searchAPIURLLAst;
|
|
110 | 110 |
let url = link+params+"/software"+"?format=json"; |
111 | 111 |
|
112 |
return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url)
|
|
112 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
113 | 113 |
.map(res => <any> res.json()) |
114 | 114 |
.map(res => [res['meta'].total, this.parseResults(res['results'])]); |
115 | 115 |
} |
116 | 116 |
|
117 |
searchSoftwareForDataproviders(params: string, page: number, size: number):any { |
|
118 |
let link = OpenaireProperties.getSearchAPIURLLast();
|
|
117 |
searchSoftwareForDataproviders(params: string, page: number, size: number, properties:EnvProperties):any {
|
|
118 |
let link = properties.searchAPIURLLAst;
|
|
119 | 119 |
let url = link+params+ "&page="+(page-1)+"&size="+size + "&format=json"; |
120 | 120 |
|
121 |
return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url)
|
|
121 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
122 | 122 |
.map(res => <any> res.json()) |
123 | 123 |
.map(res => [res['meta'].total, this.parseResults(res['results'])]); |
124 | 124 |
} |
... | ... | |
315 | 315 |
return results; |
316 | 316 |
} |
317 | 317 |
|
318 |
numOfSoftware(url: string):any { |
|
318 |
numOfSoftware(url: string, properties:EnvProperties):any {
|
|
319 | 319 |
|
320 |
return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url)
|
|
320 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
321 | 321 |
.map(res => <any> res.json()) |
322 | 322 |
.map(res => res.total); |
323 | 323 |
} |
324 | 324 |
|
325 |
numOfEntitySoftware(id: string, entity: string):any { |
|
325 |
numOfEntitySoftware(id: string, entity: string, properties:EnvProperties):any {
|
|
326 | 326 |
var parameters = ""; |
327 | 327 |
|
328 | 328 |
if(entity == "project") { |
329 | 329 |
parameters = "projects/"+id+"/software/count"; |
330 | 330 |
} |
331 | 331 |
|
332 |
let url = OpenaireProperties.getSearchAPIURLLast()+parameters+"?format=json";
|
|
333 |
return this.numOfSoftware(url); |
|
332 |
let url = properties.searchAPIURLLAst+parameters+"?format=json";
|
|
333 |
return this.numOfSoftware(url, properties);
|
|
334 | 334 |
} |
335 | 335 |
|
336 |
numOfSearchSoftware(params: string):any { |
|
337 |
let url = OpenaireProperties.getSearchAPIURLLast()+"software/count?format=json";
|
|
336 |
numOfSearchSoftware(params: string, properties:EnvProperties):any {
|
|
337 |
let url = properties.searchAPIURLLAst+"software/count?format=json";
|
|
338 | 338 |
if(params != "") { |
339 | 339 |
url += "&q=" + params; |
340 | 340 |
} |
341 |
return this.numOfSoftware(url); |
|
341 |
return this.numOfSoftware(url, properties);
|
|
342 | 342 |
} |
343 | 343 |
} |
Also available in: Unified diff
USe a json file to read properties | replace openaire Properties | parameterize menu (use params, community, ) | parameterize search pages (hide community information)