Project

General

Profile

1 50169 argiro.kok
import {Injectable} from '@angular/core';
2 51973 konstantin
import {Http, Response,Headers, RequestOptions} from '@angular/http';
3 55964 argiro.kok
import {HttpClient, HttpErrorResponse, HttpHeaders} from "@angular/common/http";
4
import {Observable, throwError} from 'rxjs';
5 50169 argiro.kok
import {DataProviderInfo} from '../../utils/entities/dataProviderInfo';
6 55964 argiro.kok
7
8
9 50586 argiro.kok
import{EnvProperties} from '../../utils/properties/env-properties';
10 55964 argiro.kok
import {map} from "rxjs/operators";
11 50169 argiro.kok
12
13
@Injectable()
14
export class DataProviderService {
15
16 55964 argiro.kok
    constructor(private http: HttpClient ) {}
17 50169 argiro.kok
18
    dataProviderInfo: DataProviderInfo;
19
20 50586 argiro.kok
    getDataproviderInfo (id: string, properties:EnvProperties):any {
21
        let url = properties.searchAPIURLLAst + 'datasources/' +id +"?format=json";
22 50169 argiro.kok
        let key = url;
23
24 50586 argiro.kok
        return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
25 55964 argiro.kok
                    //.map(res => <any> res.json())
26
                    .pipe(map(res => res['result']['metadata']['oaf:entity']))
27
                    .pipe(map(res => [res['oaf:datasource'],
28 50169 argiro.kok
                                 res['oaf:datasource']['datasourcetype'],
29
                                 res['oaf:datasource']['openairecompatibility'],
30 52692 konstantin
                                 res['oaf:datasource']['collectedfrom'],
31 50169 argiro.kok
                                 res['oaf:datasource']['accessinfopackage'],
32 55729 argiro.kok
                                 res['oaf:datasource']['rels']['rel'],
33
                                 res['oaf:datasource']['journal'] //6
34 55964 argiro.kok
                     ]))
35
                     .pipe(map(res => this.parseDataProviderInfo(res)));
36 50169 argiro.kok
37
    }
38
39 51973 konstantin
    getDataproviderAggregationStatus(original_id: string, properties:EnvProperties):any {
40 55964 argiro.kok
        //let headers = new Headers({'Content-Type': 'application/json', 'accept': 'application/json'});
41
        //let options = new RequestOptions({headers: headers});
42 51973 konstantin
43 55964 argiro.kok
      const options = {
44
        headers: new HttpHeaders({
45
          'Content-Type': 'application/json',
46
          'accept': 'application/json'})
47
      };
48
49
      let page: number = 0;
50 51976 konstantin
        let size: number = 1;
51
        return this.http.post(properties.datasourcesAPI+page+"/"+size+"?requestSortBy=id&order=ASCENDING", JSON.stringify({ "id": original_id }), options)
52 55964 argiro.kok
            //.map(res => <any> res.json())
53
            .pipe(map(res => res['datasourceInfo']))
54
            .pipe(map(res => this.parseDataproviderAggregationStatus(res)));
55 51973 konstantin
    }
56
57 55964 argiro.kok
    private handleError (error: HttpErrorResponse) {
58 50169 argiro.kok
    // in a real world app, we may send the error to some remote logging infrastructure
59
    // instead of just logging it to the console
60
        console.log(error);
61 55964 argiro.kok
        return throwError(error  || 'Server error');
62 50169 argiro.kok
    }
63
64 51973 konstantin
    parseDataproviderAggregationStatus(data: any): any {
65 53366 konstantin
        var aggregationStatus: {"fundedContent": string, "indexRecords": string, "fulltexts": string} = null;
66 51973 konstantin
        if(data != null && data[0] != null) {
67 53366 konstantin
          aggregationStatus = {"fundedContent": "-1", "indexRecords": "-1", "fulltexts": "-1"};
68 51973 konstantin
          aggregationStatus.fundedContent = data[0].fundedContent;
69
          aggregationStatus.indexRecords = data[0].indexRecords;
70 53366 konstantin
          aggregationStatus.fulltexts = data[0].fulltexts;
71 51973 konstantin
        }
72
        return aggregationStatus;
73
    }
74
75 50169 argiro.kok
    parseDataProviderInfo (data: any):any {
76
        this.dataProviderInfo = new DataProviderInfo();
77
78
        if(data[0] != null) {
79
            this.dataProviderInfo.title = {"name": (data[0].englishname)?data[0].englishname: data[0].officialname, "url": data[0].websiteurl};
80
            this.dataProviderInfo.officialName =  data[0].officialname;
81
82 55139 konstantin
            var pattern = /.{12}::.+/;
83
            var originalIds =(data[0].originalId)?data[0].originalId:"";
84
85 55140 konstantin
            let length = Array.isArray(originalIds) ? originalIds.length : 1;
86 55139 konstantin
87
            for(let i=0; i<length; i++) {
88 55140 konstantin
              var originalId = Array.isArray(originalIds) ? originalIds[i] : originalIds;
89 55139 konstantin
              var matched = originalId.match(pattern);
90 55141 konstantin
91 55139 konstantin
              if(matched && originalId && originalId != ""){
92
                if(originalId.indexOf("opendoar____::") != -1){
93
                  this.dataProviderInfo.openDoarId = originalId.split("opendoar____::")[1];
94
                }else if (originalId.indexOf("re3data_____::") != -1){
95
                  this.dataProviderInfo.r3DataId = originalId.split("re3data_____::")[1];
96
                }
97
                this.dataProviderInfo.originalId = originalId;
98 50169 argiro.kok
              }
99
            }
100
        }
101
102
        if(data[1] != null) {
103
            this.dataProviderInfo.type = data[1].classname;
104
105
            if(data[1].classid == "entityregistry" || data[1].classid == "entityregistry::projects" || data[1].classid == "entityregistry::repositories") {
106
                this.dataProviderInfo.registry = true;
107
            } else {
108
                this.dataProviderInfo.registry = false;
109
            }
110
111
            if(this.dataProviderInfo.tabs == undefined) {
112
                this.dataProviderInfo.tabs = new Array<{"name": string, "content": string}>();
113
            }
114 52373 argiro.kok
            this.dataProviderInfo.tabs = [];
115 50169 argiro.kok
            if(this.dataProviderInfo.tabsInTypes.publicationsTab.has(data[1].classid)) {
116
                this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
117 52373 argiro.kok
                this.dataProviderInfo.tabs2.push("Publications");
118 50169 argiro.kok
            }
119
            if(this.dataProviderInfo.tabsInTypes.datasetsTab.has(data[1].classid)) {
120
                this.dataProviderInfo.tabs.push({"name": "Research Data", "content": "datasetsTab"});
121 52373 argiro.kok
                this.dataProviderInfo.tabs2.push("Research Data");
122 50169 argiro.kok
            }
123
124
            if(this.dataProviderInfo.tabsInTypes.projectsTab.has(data[1].classid)) {
125
                this.dataProviderInfo.tabs.push({"name": "Projects", "content": "projectsTab"});
126 52373 argiro.kok
                this.dataProviderInfo.tabs2.push("Projects");
127 50169 argiro.kok
            }
128
            if(this.dataProviderInfo.tabsInTypes.datasourcesTab.has(data[1].classid)) {
129
                this.dataProviderInfo.tabs.push({"name": "Content Providers", "content": "datasourcesTab"});
130 52373 argiro.kok
                this.dataProviderInfo.tabs2.push("Content Providers");
131 50169 argiro.kok
            }
132
            this.dataProviderInfo.tabs.push({"name": "Organizations", "content": "organizationsTab"});
133 52373 argiro.kok
            this.dataProviderInfo.tabs2.push("Organizations");
134 50169 argiro.kok
135
            if(this.dataProviderInfo.tabsInTypes.relatedDatasourcesTab.has(data[1].classid)) {
136
                this.dataProviderInfo.tabs.push({"name": "Related Content Providers", "content": "relatedDatasourcesTab"});
137 52373 argiro.kok
                this.dataProviderInfo.tabs2.push("Related Content Providers");
138 50169 argiro.kok
            }
139
140
            if(this.dataProviderInfo.tabsInTypes.statisticsTab.has(data[1].classid)) {
141
                this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
142 52373 argiro.kok
                this.dataProviderInfo.tabs2.push("Statistics");
143 50169 argiro.kok
            }
144
145 51972 konstantin
            if(this.dataProviderInfo.tabsInTypes.softwareTab.has(data[1].classid)) {
146
                this.dataProviderInfo.tabs.push({"name": "Software", "content": "softwareTab"});
147 52373 argiro.kok
                this.dataProviderInfo.tabs2.push("Software");
148 51972 konstantin
            }
149
150 52828 konstantin
            if(this.dataProviderInfo.tabsInTypes.orpsTab.has(data[1].classid)) {
151
                this.dataProviderInfo.tabs.push({"name": "Other Research Products", "content": "orpsTab"});
152
                this.dataProviderInfo.tabs2.push("Other Research Products");
153
            }
154 51972 konstantin
155 54824 konstantin
            if(this.dataProviderInfo.tabsInTypes.metricsTab.has(data[1].classid)) {
156
                this.dataProviderInfo.tabs.push({"name": "Metrics", "content": "metricsTab"});
157
                this.dataProviderInfo.tabs2.push("Metrics");
158
            }
159 50169 argiro.kok
160
            if(this.dataProviderInfo.resultTypes.collectedFrom.has(data[1].classid)) {
161
                this.dataProviderInfo.resultsBy = "collectedFrom";
162
            } else if(this.dataProviderInfo.resultTypes.hostedBy.has(data[1].classid)) {
163
                this.dataProviderInfo.resultsBy = "hostedBy";
164
            }
165
        }
166
167
        if(!this.dataProviderInfo.registry) {
168
            if(data[2] != null) {
169 52692 konstantin
                this.dataProviderInfo.compatibility = {"info": "", "name": "", "id": ""};
170
                this.dataProviderInfo.compatibility.info = data[2].classname;
171
                //this.dataProviderInfo.compatibility = data[2].classname;
172 50169 argiro.kok
            }
173
174 52692 konstantin
            if(data[2] != null && data[2].classid == "hostedBy" && data[3] != null) {
175
              this.dataProviderInfo.compatibility.name = data[3].name;
176
              this.dataProviderInfo.compatibility.id = data[3].id;
177
178
              if(this.dataProviderInfo.compatibility.name) {
179
                this.dataProviderInfo.compatibility.info = "Collected from ";
180
              }
181
            }
182
183
            if(data[4] != null) {
184 54903 k.triantaf
                let oaiPmhURL:string;
185
                oaiPmhURL = Array.isArray(data[4]) ? data[4][0]:data[4];
186 50169 argiro.kok
                if(oaiPmhURL != '' && oaiPmhURL != 'unknown') {
187
                    this.dataProviderInfo.oaiPmhURL = oaiPmhURL;
188
                }
189
            }
190
        }
191
192 52692 konstantin
        if(data[5] != null) {
193 50169 argiro.kok
            let mydata;
194
            let counter = 0;
195
            let countriesSet: Set<string>;
196 52692 konstantin
            let length = data[5].length!=undefined ? data[5].length : 1;
197 50169 argiro.kok
198
            for(let i=0; i<length; i++) {
199 52692 konstantin
                mydata = data[5].length!=undefined ? data[5][i] : data[5];
200 50169 argiro.kok
                if(mydata.hasOwnProperty("to")) {
201
                    if(mydata['to'].class == "provides" && mydata['to'].type == "organization") {
202
                        //if(this.dataProviderInfo.organizations == undefined) {
203
                        if(this.dataProviderInfo.organizations.length == 0) {
204
                            //this.dataProviderInfo.organizations = new Array<{"name": string, "url": string}>();
205
                            this.dataProviderInfo.countries = new Array<string>();
206
                            countriesSet = new Set<string>();
207
                        }
208
209
                        this.dataProviderInfo.organizations[counter] = {"name": "", "id": ""};
210
                        this.dataProviderInfo.organizations[counter]['name'] = mydata.legalname;
211 50586 argiro.kok
                        this.dataProviderInfo.organizations[counter]['id'] = mydata['to'].content;
212 50169 argiro.kok
213
                        if(mydata.country != '' && mydata['country'].classname != '') {
214
                            if(!countriesSet.has(mydata['country'].classname)) {
215
                                this.dataProviderInfo.countries.push(mydata['country'].classname);
216
                                countriesSet.add(mydata['country'].classname);
217
                            }
218
                        }
219
220
                        counter++;
221
                    }
222
                }
223
            }
224
        }
225 55729 argiro.kok
        if(data[6] != null) {
226
            this.dataProviderInfo.journal = {"journal": "", "issn": "", "lissn": "", "eissn": ""};
227
            this.dataProviderInfo.journal['journal'] = data[6].content;
228
            this.dataProviderInfo.journal['issn'] = data[6]['issn'];
229
            this.dataProviderInfo.journal['lissn'] = data[6]['lissn'];
230
            this.dataProviderInfo.journal['eissn'] = data[6]['eissn'];
231 50169 argiro.kok
232 55729 argiro.kok
        }else{
233
            this.dataProviderInfo.journal = null;
234
            this.dataProviderInfo.journal = {"journal": "", "issn": "", "lissn": "", "eissn": ""};
235
        }
236
237 50169 argiro.kok
        return this.dataProviderInfo;
238
    }
239
}