Project

General

Profile

1
import { HttpClient, HttpHeaders } from '@angular/common/http';
2
import { Injectable } from '@angular/core';
3
import { Observable } from 'rxjs';
4
import { OverviewData } from '../domain/overview-data';
5
import { environment } from '../../environments/environment';
6
import { RawData } from '../domain/raw-data';
7

    
8
const headerOptions = {
9
  headers : new HttpHeaders().set('Content-Type', 'application/json')
10
    .set('Accept', 'application/json'),
11
};
12

    
13
@Injectable ()
14
export class DataService {
15

    
16
  private _jsonURl = 'http://esperos.di.uoa.gr/oss.json';
17

    
18
  private apiURL = environment.API_ENDPOINT + 'raw?json=';
19
  private profileName = environment.profileName;
20

    
21
  constructor(private httpClient: HttpClient) {
22
  }
23

    
24
  public getLastUpdateDate(): Observable<RawData> {
25
    const lastUpdateDateQuery = `{"series":[{"query":{"name":"creation_date","profile":"${this.profileName}"}}],"verbose":true}`;
26
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(lastUpdateDateQuery), headerOptions);
27
  }
28

    
29
  public getOverviewMapData(): Observable<RawData> {
30
    const mapDataQuery = `{"series":[{"query":{"name":"oso.results.affiliated","parameters":["publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.deposited","parameters":["publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.affiliated","parameters":["dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.deposited","parameters":["dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.repositories","profile":"${this.profileName}"}},{"query":{"name":"oso.repositories.doar_re3data","profile":"${this.profileName}"}},{"query":{"name":"oso.journals","profile":"${this.profileName}"}},{"query":{"name":"oso.journals.doaj","profile":"${this.profileName}"}},{"query":{"name":"oso.oa_policies","profile":"${this.profileName}"}}],"verbose":true}`;
31
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(mapDataQuery), headerOptions);
32
  }
33

    
34
  public getCountryOverviewData(countryCode: string): Observable<RawData> {
35
    const countryOverviewDataQuery = `{"series":[{"query":{"name":"oso.results.affiliated.country", "parameters":["${countryCode}","publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.deposited.country", "parameters":["${countryCode}","publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.affiliated.country", "parameters":["${countryCode}","dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.deposited.country", "parameters":["${countryCode}","dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.repositories.doar_re3data.country", "parameters":["${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.journals.doaj.country", "parameters":["${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.oa_policies.country", "parameters":["${countryCode}"],"profile":"${this.profileName}"}}],"verbose":true}`;
36
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(countryOverviewDataQuery), headerOptions);
37
  }
38

    
39
  public getCountryOAData(countryCode: string): Observable<RawData> {
40
    const countryOADataQuery = `{"series":[{"query":{"name":"oso.results.oa_percentage.country", "parameters":["publication","${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.country", "parameters":["dataset","${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.country", "parameters":["software","${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.country", "parameters":["other","${countryCode}"],"profile":"${this.profileName}"}}],"verbose":true}`;
41
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(countryOADataQuery), headerOptions);
42
  }
43

    
44
  public getEuropeOverviewData(): Observable<RawData> {
45
    const overviewRawDataQuery = `{"series":[{"query":{"name":"oso.results.oa_percentage","parameters":["publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage","parameters":["dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.repositories.doar_re3data.validated","profile":"${this.profileName}"}},{"query":{"name":"oso.journals.doaj.validated","profile":"${this.profileName}"}},{"query":{"name":"oso.oa_policies.europe","profile":"${this.profileName}"}}],"verbose":true}`;
46
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(overviewRawDataQuery), headerOptions);
47
  }
48

    
49
  public getOverviewTableAbsoluteData(content: string): Observable<RawData> {
50
    let overviewTableAbsoluteDataQuery = '';
51
    if (content === 'affiliated') {
52
      overviewTableAbsoluteDataQuery = `{"series":[{"query":{"name":"oso.results.affiliated","parameters":["publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.affiliated","parameters":["dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.affiliated","parameters":["software"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.affiliated","parameters":["other"],"profile":"${this.profileName}"}},{"query":{"name":"oso.repositories","profile":"${this.profileName}"}},{"query":{"name":"oso.journals","profile":"${this.profileName}"}},{"query":{"name":"oso.oa_policies","profile":"${this.profileName}"}}],"verbose":true}`;
53
    } else if (content === 'affiliated_peer_reviewed') {
54
      overviewTableAbsoluteDataQuery = `{"series":[{"query":{"name":"oso.results.affiliated.peer_reviewed","parameters":["publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.affiliated.peer_reviewed","parameters":["dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.affiliated.peer_reviewed","parameters":["software"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.affiliated.peer_reviewed","parameters":["other"],"profile":"${this.profileName}"}},{"query":{"name":"oso.repositories","profile":"${this.profileName}"}},{"query":{"name":"oso.journals","profile":"${this.profileName}"}},{"query":{"name":"oso.oa_policies","profile":"${this.profileName}"}}],"verbose":true}`;
55
    } else if (content === 'deposited') {
56
      overviewTableAbsoluteDataQuery = `{"series":[{"query":{"name":"oso.results.deposited","parameters":["publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.deposited","parameters":["dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.deposited","parameters":["software"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.deposited","parameters":["other"],"profile":"${this.profileName}"}},{"query":{"name":"oso.repositories","profile":"${this.profileName}"}},{"query":{"name":"oso.journals","profile":"${this.profileName}"}},{"query":{"name":"oso.oa_policies","profile":"${this.profileName}"}}],"verbose":true}`;
57
    } else if (content === 'deposited_peer_reviewed') {
58
      overviewTableAbsoluteDataQuery = `{"series":[{"query":{"name":"oso.results.deposited.peer_reviewed","parameters":["publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.deposited.peer_reviewed","parameters":["dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.deposited.peer_reviewed","parameters":["software"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.deposited.peer_reviewed","parameters":["other"],"profile":"${this.profileName}"}},{"query":{"name":"oso.repositories","profile":"${this.profileName}"}},{"query":{"name":"oso.journals","profile":"${this.profileName}"}},{"query":{"name":"oso.oa_policies","profile":"${this.profileName}"}}],"verbose":true}`;
59
    }
60
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(overviewTableAbsoluteDataQuery), headerOptions);
61
  }
62

    
63
  public getOverviewTablePercentageData(content: string): Observable<RawData> {
64
    let overviewTablePercentageDataQuery = '';
65
    if (content === 'affiliated') {
66
      overviewTablePercentageDataQuery = `{"series":[{"query":{"name":"oso.results.oa_percentage.bycountry","parameters":["publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.bycountry","parameters":["dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.bycountry","parameters":["software"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.bycountry","parameters":["other"],"profile":"${this.profileName}"}},{"query":{"name":"oso.repositories.doar_re3data.validated.bycountry","profile":"${this.profileName}"}},{"query":{"name":"oso.journals.doaj.validated.bycountry","profile":"${this.profileName}"}}],"verbose":true}`;
67
    } else if (content === 'affiliated_peer_reviewed') {
68
      overviewTablePercentageDataQuery = `{"series":[{"query":{"name":"oso.results.oa_percentage.affiliated.peer_reviewed.bycountry","parameters":["publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.affiliated.peer_reviewed.bycountry","parameters":["dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.affiliated.peer_reviewed.bycountry","parameters":["software"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.affiliated.peer_reviewed.bycountry","parameters":["other"],"profile":"${this.profileName}"}},{"query":{"name":"oso.repositories.doar_re3data.validated.bycountry","profile":"${this.profileName}"}},{"query":{"name":"oso.journals.doaj.validated.bycountry","profile":"${this.profileName}"}}],"verbose":true}`;
69
    } else if (content === 'deposited') {
70
      overviewTablePercentageDataQuery = `{"series":[{"query":{"name":"oso.results.oa_percentage.deposited.bycountry","parameters":["publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.deposited.bycountry","parameters":["dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.deposited.bycountry","parameters":["software"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.deposited.bycountry","parameters":["other"],"profile":"${this.profileName}"}},{"query":{"name":"oso.repositories.doar_re3data.validated.bycountry","profile":"${this.profileName}"}},{"query":{"name":"oso.journals.doaj.validated.bycountry","profile":"${this.profileName}"}}],"verbose":true}`;
71
    } else if (content === 'deposited_peer_reviewed') {
72
      overviewTablePercentageDataQuery = `{"series":[{"query":{"name":"oso.results.oa_percentage.deposited.peer_reviewed.bycountry","parameters":["publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.deposited.peer_reviewed.bycountry","parameters":["dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.deposited.peer_reviewed.bycountry","parameters":["software"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.deposited.peer_reviewed.bycountry","parameters":["other"],"profile":"${this.profileName}"}},{"query":{"name":"oso.repositories.doar_re3data.validated.bycountry","profile":"${this.profileName}"}},{"query":{"name":"oso.journals.doaj.validated.bycountry","profile":"${this.profileName}"}}],"verbose":true}`;
73
    }
74
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(overviewTablePercentageDataQuery), headerOptions);
75
  }
76

    
77
  public getLeadingOpenScienceMobileData(): Observable<RawData> {
78
    const leadingOpenScienceMobileDataQuery = `{"series":[{"query":{"name":"oso.mobile.overview","profile":"${this.profileName}"}}],"verbose":true}`;
79
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(leadingOpenScienceMobileDataQuery), headerOptions);
80
  }
81

    
82
  public getEuropeOAPercentages(): Observable<RawData> {
83
    const europeOAPercentagesQuery = `{"series":[{"query":{"name":"oso.results.oa_percentage","parameters":["publication"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage","parameters":["dataset"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage","parameters":["software"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage","parameters":["other"],"profile":"${this.profileName}"}}],"verbose":true}`;
84
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(europeOAPercentagesQuery), headerOptions);
85
  }
86

    
87
  public getCountryPageOverviewData(countryCode: string): Observable<RawData> {
88
    const countryPageOverviewDataQuery = `{"series":[{"query":{"name":"oso.results.oa_percentage.country", "parameters":["publication","${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.deposited.country", "parameters":["publication","${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.country", "parameters":["dataset","${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.oa_percentage.deposited.country", "parameters":["dataset","${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.repositories.doar_re3data.validated.country", "parameters":["${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.journals.doaj.validated.country", "parameters":["${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.oa_policies.country", "parameters":["${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.rnd.country", "parameters":["${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.funder.country", "parameters":["${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.funding_organizations.country", "parameters":["${countryCode}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.ec_funded_organizations.country", "parameters":["${countryCode}"],"profile":"${this.profileName}"}}],"verbose":true}`;
89
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(countryPageOverviewDataQuery), headerOptions);
90
  }
91

    
92
  public getFundersResults(): Observable<RawData> {
93
    const fundersResultsQuery = `{"series":[{"query":{"name":"oso.funders.results","profile":"${this.profileName}"}}],"verbose":true}`;
94
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(fundersResultsQuery), headerOptions);
95
  }
96

    
97
  public getFundersResultsByType(type: string): Observable<RawData> {
98
    const fundersResultsByTypeQuery = `{"series":[{"query":{"name":"oso.funders.results.type", "parameters":["${type}"],"profile":"${this.profileName}"}}],"verbose":true}`;
99
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(fundersResultsByTypeQuery), headerOptions);
100
  }
101

    
102
  public getFundersResultsByTypeForPID(type: string): Observable<RawData> {
103
    const fundersResultsByTypeForPIDQuery = `{"series":[{"query":{"name":"oso.results.pid.affiliated.byfunder", "parameters":["${type}"],"profile":"${this.profileName}"}}],"verbose":true}`;
104
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(fundersResultsByTypeForPIDQuery), headerOptions);
105
  }
106

    
107
  public getFundersResultsByTypeForLicence(type: string): Observable<RawData> {
108
    const fundersResultsByTypeForLicenceQuery = `{"series":[{"query":{"name":"oso.results.licence.affiliated.byfunder", "parameters":["${type}"],"profile":"${this.profileName}"}}],"verbose":true}`;
109
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(fundersResultsByTypeForLicenceQuery), headerOptions);
110
  }
111

    
112
  public getFundersResultsByTypeForGold(type: string): Observable<RawData> {
113
    const fundersResultsByTypeForGoldQuery = `{"series":[{"query":{"name":"oso.results.gold.affiliated.byfunder", "parameters":["${type}"],"profile":"${this.profileName}"}}],"verbose":true}`;
114
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(fundersResultsByTypeForGoldQuery), headerOptions);
115
  }
116

    
117
  public getFundersResultsByTypeForGreen(type: string): Observable<RawData> {
118
    const fundersResultsByTypeForGreenQuery = `{"series":[{"query":{"name":"oso.results.green.affiliated.byfunder", "parameters":["${type}"],"profile":"${this.profileName}"}}],"verbose":true}`;
119
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(fundersResultsByTypeForGreenQuery), headerOptions);
120
  }
121

    
122
  public getFundersResultsByTypeForCountry(type: string, countryCode: string): Observable<RawData> {
123
    const fundersResultsByTypeForCountryQuery = `{"series":[{"query":{"name":"oso.results.affiliated.byfunder.country", "parameters":["${countryCode}","${type}"],"profile":"${this.profileName}"}}],"verbose":true}`;
124
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(fundersResultsByTypeForCountryQuery), headerOptions);
125
  }
126

    
127
  public getFundersResultsByTypeForIndicatorForCountry(type: string, indicator: string, countryCode: string): Observable<RawData> {
128
    const fundersResultsByTypeForPIDForCountryQuery = `{"series":[{"query":{"name":"oso.results.${indicator}.affiliated.byfunder.country", "parameters":["${type}","${countryCode}"],"profile":"${this.profileName}"}}],"verbose":true}`;
129
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(fundersResultsByTypeForPIDForCountryQuery), headerOptions);
130
  }
131

    
132
  public getIndicatorsTableData(type: string, content: string): Observable<RawData> {
133

    
134
    let indicatorsTableDataQuery = '';
135
    if (content === 'affiliated') {
136
      indicatorsTableDataQuery = `{"series":[{"query":{"name":"oso.results.pid_percentage.affiliated.bycountry","parameters":["${type}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.licence_percentage.affiliated.bycountry","parameters":["${type}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.green_percentage.affiliated.bycountry","parameters":["${type}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.gold_percentage.affiliated.bycountry","parameters":["${type}"],"profile":"${this.profileName}"}}],"verbose":true}`;
137
    } else if (content === 'affiliated_peer_reviewed') {
138
      indicatorsTableDataQuery = `{"series":[{"query":{"name":"oso.results.pid_percentage.affiliated.peer_reviewed.bycountry","parameters":["${type}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.licence_percentage.affiliated.peer_reviewed.bycountry","parameters":["${type}","${type}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.green_percentage.affiliated.peer_reviewed.bycountry","parameters":["${type}","${type}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.gold_percentage.affiliated.peer_reviewed.bycountry","parameters":["${type}","${type}"],"profile":"${this.profileName}"}}],"verbose":true}`;
139
    } else if (content === 'deposited') {
140
      indicatorsTableDataQuery = `{"series":[{"query":{"name":"oso.results.pid_percentage.deposited.bycountry","parameters":["${type}","${type}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.licence_percentage.deposited.bycountry","parameters":["${type}","${type}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.green_percentage.deposited.bycountry","parameters":["${type}","${type}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.gold_percentage.deposited.bycountry","parameters":["${type}","${type}"],"profile":"${this.profileName}"}}],"verbose":true}`;
141
    } else if (content === 'deposited_peer_reviewed') {
142
      indicatorsTableDataQuery = `{"series":[{"query":{"name":"oso.results.pid_percentage.deposited.peer_reviewed.bycountry","parameters":["${type}","${type}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.licence_percentage.deposited.peer_reviewed.bycountry","parameters":["${type}","${type}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.green_percentage.deposited.peer_reviewed.bycountry","parameters":["${type}","${type}"],"profile":"${this.profileName}"}},{"query":{"name":"oso.results.gold_percentage.deposited.peer_reviewed.bycountry","parameters":["${type}","${type}"],"profile":"${this.profileName}"}}],"verbose":true}`;
143
    }
144
    return this.httpClient.get<RawData>(this.apiURL + encodeURIComponent(indicatorsTableDataQuery), headerOptions);
145
  }
146

    
147

    
148
  public getOverviewData(): Observable<OverviewData> {
149
    return this.httpClient.get<OverviewData>(this._jsonURl, headerOptions);
150
  }
151

    
152
  public getCountryData(countryName: string) {
153
    return this.httpClient.get<OverviewData>(this._jsonURl, headerOptions);
154
  }
155
}
(2-2/4)