1
|
import {Injectable} from '@angular/core';
|
2
|
import {HttpClient, HttpErrorResponse, HttpHeaders} from "@angular/common/http";
|
3
|
import {throwError} from 'rxjs';
|
4
|
import {DataProviderInfo} from '../../utils/entities/dataProviderInfo';
|
5
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
6
|
import {map} from "rxjs/operators";
|
7
|
|
8
|
|
9
|
@Injectable()
|
10
|
export class DataProviderService {
|
11
|
|
12
|
constructor(private http: HttpClient ) {}
|
13
|
|
14
|
dataProviderInfo: DataProviderInfo;
|
15
|
|
16
|
getDataproviderInfo (id: string, properties:EnvProperties):any {
|
17
|
let url = properties.searchAPIURLLAst + 'datasources/' +id +"?format=json";
|
18
|
let key = url;
|
19
|
|
20
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
21
|
//.map(res => <any> res.json())
|
22
|
.pipe(map(res => res['result']['metadata']['oaf:entity']))
|
23
|
.pipe(map(res => [res['oaf:datasource'],
|
24
|
res['oaf:datasource']['datasourcetype'],
|
25
|
res['oaf:datasource']['openairecompatibility'],
|
26
|
res['oaf:datasource']['collectedfrom'],
|
27
|
res['oaf:datasource']['accessinfopackage'],
|
28
|
res['oaf:datasource']['rels']['rel'],
|
29
|
res['oaf:datasource']['journal'] //6
|
30
|
]))
|
31
|
.pipe(map(res => this.parseDataProviderInfo(res)));
|
32
|
|
33
|
}
|
34
|
|
35
|
getDataproviderAggregationStatus(original_id: string, properties:EnvProperties):any {
|
36
|
//let headers = new Headers({'Content-Type': 'application/json', 'accept': 'application/json'});
|
37
|
//let options = new RequestOptions({headers: headers});
|
38
|
|
39
|
// const options = {
|
40
|
// headers: new HttpHeaders({
|
41
|
// 'Content-Type': 'application/json',
|
42
|
// 'accept': 'application/json'})
|
43
|
// };
|
44
|
//
|
45
|
// let page: number = 0;
|
46
|
// let size: number = 1;
|
47
|
// return this.http.post(properties.datasourcesAPI+page+"/"+size+"?requestSortBy=id&order=ASCENDING", JSON.stringify({ "id": original_id }), options)
|
48
|
// //.map(res => <any> res.json())
|
49
|
// .pipe(map(res => res['datasourceInfo']))
|
50
|
// .pipe(map(res => this.parseDataproviderAggregationStatus(res)));
|
51
|
|
52
|
return this.http.get(properties.datasourcesAPI+original_id)
|
53
|
.pipe(map(res => res['api']))
|
54
|
.pipe(map(res => this.parseDataproviderAggregationStatus(res)));
|
55
|
}
|
56
|
|
57
|
private handleError (error: HttpErrorResponse) {
|
58
|
// 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
|
return throwError(error || 'Server error');
|
62
|
}
|
63
|
|
64
|
parseDataproviderAggregationStatus(apis: any): any {
|
65
|
// var aggregationStatus: {"fundedContent": string, "indexRecords": string, "fulltexts": string, "lastUpdateDate": string} = null;
|
66
|
// if(data != null && data[0] != null) {
|
67
|
// aggregationStatus = {"fundedContent": "-1", "indexRecords": "-1", "fulltexts": "-1", "lastUpdateDate": null};
|
68
|
// aggregationStatus.fundedContent = data[0].fundedContent;
|
69
|
// aggregationStatus.indexRecords = data[0].indexRecords;
|
70
|
// aggregationStatus.fulltexts = data[0].fulltexts;
|
71
|
//
|
72
|
// if(data[0].hasOwnProperty("aggregationHistory")) {
|
73
|
// let length = Array.isArray(data[0]["aggregationHistory"]) ? data[0]["aggregationHistory"].length : 1;
|
74
|
//
|
75
|
// for(let i=0; i<length; i++) {
|
76
|
// var aggregationHistory = Array.isArray(data[0]["aggregationHistory"]) ? data[0]["aggregationHistory"][i] : data[0]["aggregationHistory"];
|
77
|
// if(aggregationHistory && aggregationHistory.indexedVersion == true) {
|
78
|
// aggregationStatus.lastUpdateDate = aggregationHistory.date;
|
79
|
// break;
|
80
|
// }
|
81
|
// }
|
82
|
// }
|
83
|
// }
|
84
|
|
85
|
var aggregationStatus: {"fulltexts": string} = null;
|
86
|
if(apis != null) {
|
87
|
aggregationStatus = {"fulltexts": "-1"};
|
88
|
|
89
|
let mostRecentDate = null;
|
90
|
let length = Array.isArray(apis) ? apis.length : 1;
|
91
|
|
92
|
for (let i = 0; i < length; i++) {
|
93
|
let api = Array.isArray(apis) ? apis[i] : apis;
|
94
|
if(api.compatibility == "files" && (mostRecentDate == null || mostRecentDate < api.lastDownloadDate)) {
|
95
|
aggregationStatus.fulltexts = api.lastDownloadTotal;
|
96
|
mostRecentDate = api.lastDownloadDate;
|
97
|
}
|
98
|
}
|
99
|
}
|
100
|
|
101
|
return aggregationStatus;
|
102
|
}
|
103
|
|
104
|
parseDataProviderInfo (data: any):any {
|
105
|
this.dataProviderInfo = new DataProviderInfo();
|
106
|
|
107
|
if(data[0] != null) {
|
108
|
this.dataProviderInfo.title = {"name": (data[0].englishname)?data[0].englishname: data[0].officialname, "url": data[0].websiteurl};
|
109
|
this.dataProviderInfo.officialName = data[0].officialname;
|
110
|
|
111
|
var pattern = /.{12}::.+/;
|
112
|
var originalIds =(data[0].originalId)?data[0].originalId:"";
|
113
|
|
114
|
let length = Array.isArray(originalIds) ? originalIds.length : 1;
|
115
|
|
116
|
for(let i=0; i<length; i++) {
|
117
|
var originalId = Array.isArray(originalIds) ? originalIds[i] : originalIds;
|
118
|
var matched = originalId.match(pattern);
|
119
|
|
120
|
if(matched && originalId && originalId != ""){
|
121
|
if(originalId.indexOf("opendoar____::") != -1){
|
122
|
this.dataProviderInfo.openDoarId = originalId.split("opendoar____::")[1];
|
123
|
}else if (originalId.indexOf("re3data_____::") != -1){
|
124
|
this.dataProviderInfo.r3DataId = originalId.split("re3data_____::")[1];
|
125
|
}
|
126
|
this.dataProviderInfo.originalId = originalId;
|
127
|
}
|
128
|
}
|
129
|
|
130
|
this.dataProviderInfo.subjects = [];
|
131
|
length = Array.isArray(data[0]['subjects']) ? data[0]['subjects'].length : 1;
|
132
|
for(let i=0; i<length; i++) {
|
133
|
let subject = Array.isArray(data[0]['subjects']) ? data[0]['subjects'][i] :data[0]['subjects'];
|
134
|
if(subject && subject.content) {
|
135
|
this.dataProviderInfo.subjects.push(subject.content);
|
136
|
}
|
137
|
}
|
138
|
|
139
|
if(!Array.isArray(data[0]['description'])) {
|
140
|
this.dataProviderInfo.description = (data[0]['description']) ? String(data[0]['description']) : "";
|
141
|
} else {
|
142
|
this.dataProviderInfo.description = (data[0]['description'][0]) ? String(data[0]['description'][0]) : "";
|
143
|
}
|
144
|
}
|
145
|
|
146
|
if(data[1] != null) {
|
147
|
this.dataProviderInfo.type = data[1].classname;
|
148
|
|
149
|
if(data[1].classid == "entityregistry" || data[1].classid == "entityregistry::projects" || data[1].classid == "entityregistry::repositories") {
|
150
|
this.dataProviderInfo.registry = true;
|
151
|
} else {
|
152
|
this.dataProviderInfo.registry = false;
|
153
|
}
|
154
|
|
155
|
if(this.dataProviderInfo.tabs == undefined) {
|
156
|
this.dataProviderInfo.tabs = new Array<{"name": string, "content": string}>();
|
157
|
}
|
158
|
this.dataProviderInfo.tabs = [];
|
159
|
if(this.dataProviderInfo.tabsInTypes.publicationsTab.has(data[1].classid)) {
|
160
|
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
|
161
|
this.dataProviderInfo.tabs2.push("Publications");
|
162
|
}
|
163
|
if(this.dataProviderInfo.tabsInTypes.datasetsTab.has(data[1].classid)) {
|
164
|
this.dataProviderInfo.tabs.push({"name": "Research Data", "content": "datasetsTab"});
|
165
|
this.dataProviderInfo.tabs2.push("Research Data");
|
166
|
}
|
167
|
|
168
|
if(this.dataProviderInfo.tabsInTypes.projectsTab.has(data[1].classid)) {
|
169
|
this.dataProviderInfo.tabs.push({"name": "Projects", "content": "projectsTab"});
|
170
|
this.dataProviderInfo.tabs2.push("Projects");
|
171
|
}
|
172
|
if(this.dataProviderInfo.tabsInTypes.datasourcesTab.has(data[1].classid)) {
|
173
|
this.dataProviderInfo.tabs.push({"name": "Content Providers", "content": "datasourcesTab"});
|
174
|
this.dataProviderInfo.tabs2.push("Content Providers");
|
175
|
}
|
176
|
|
177
|
if(this.dataProviderInfo.tabsInTypes.relatedDatasourcesTab.has(data[1].classid)) {
|
178
|
this.dataProviderInfo.tabs.push({"name": "Related Content Providers", "content": "relatedDatasourcesTab"});
|
179
|
this.dataProviderInfo.tabs2.push("Related Content Providers");
|
180
|
}
|
181
|
|
182
|
if(this.dataProviderInfo.tabsInTypes.statisticsTab.has(data[1].classid)) {
|
183
|
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
|
184
|
this.dataProviderInfo.tabs2.push("Statistics");
|
185
|
}
|
186
|
|
187
|
if(this.dataProviderInfo.tabsInTypes.softwareTab.has(data[1].classid)) {
|
188
|
this.dataProviderInfo.tabs.push({"name": "Software", "content": "softwareTab"});
|
189
|
this.dataProviderInfo.tabs2.push("Software");
|
190
|
}
|
191
|
|
192
|
if(this.dataProviderInfo.tabsInTypes.orpsTab.has(data[1].classid)) {
|
193
|
this.dataProviderInfo.tabs.push({"name": "Other Research Products", "content": "orpsTab"});
|
194
|
this.dataProviderInfo.tabs2.push("Other Research Products");
|
195
|
}
|
196
|
|
197
|
if(this.dataProviderInfo.tabsInTypes.metricsTab.has(data[1].classid)) {
|
198
|
this.dataProviderInfo.tabs.push({"name": "Metrics", "content": "metricsTab"});
|
199
|
this.dataProviderInfo.tabs2.push("Metrics");
|
200
|
}
|
201
|
|
202
|
if(this.dataProviderInfo.resultTypes.collectedFrom.has(data[1].classid)) {
|
203
|
this.dataProviderInfo.resultsBy = "collectedFrom";
|
204
|
} else if(this.dataProviderInfo.resultTypes.hostedBy.has(data[1].classid)) {
|
205
|
this.dataProviderInfo.resultsBy = "hostedBy";
|
206
|
}
|
207
|
}
|
208
|
|
209
|
if(!this.dataProviderInfo.registry) {
|
210
|
if(data[2] != null) {
|
211
|
this.dataProviderInfo.compatibility = {"info": "", "name": "", "id": ""};
|
212
|
this.dataProviderInfo.compatibility.info = data[2].classname;
|
213
|
//this.dataProviderInfo.compatibility = data[2].classname;
|
214
|
}
|
215
|
|
216
|
if(data[2] != null && data[2].classid == "hostedBy" && data[3] != null) {
|
217
|
this.dataProviderInfo.compatibility.name = data[3].name;
|
218
|
this.dataProviderInfo.compatibility.id = data[3].id;
|
219
|
|
220
|
if(this.dataProviderInfo.compatibility.name) {
|
221
|
this.dataProviderInfo.compatibility.info = "Collected from ";
|
222
|
}
|
223
|
}
|
224
|
|
225
|
if(data[4] != null) {
|
226
|
let oaiPmhURL:string;
|
227
|
oaiPmhURL = Array.isArray(data[4]) ? data[4][0]:data[4];
|
228
|
if(oaiPmhURL != '' && oaiPmhURL != 'unknown') {
|
229
|
this.dataProviderInfo.oaiPmhURL = oaiPmhURL;
|
230
|
}
|
231
|
}
|
232
|
}
|
233
|
|
234
|
if(data[5] != null) {
|
235
|
let mydata;
|
236
|
let counter = 0;
|
237
|
let countriesSet: Set<string>;
|
238
|
let length = data[5].length!=undefined ? data[5].length : 1;
|
239
|
|
240
|
for(let i=0; i<length; i++) {
|
241
|
mydata = data[5].length!=undefined ? data[5][i] : data[5];
|
242
|
if(mydata.hasOwnProperty("to")) {
|
243
|
if(mydata['to'].class == "isProvidedBy" && mydata['to'].type == "organization") {
|
244
|
//if(this.dataProviderInfo.organizations == undefined) {
|
245
|
if(this.dataProviderInfo.organizations.length == 0) {
|
246
|
//this.dataProviderInfo.organizations = new Array<{"name": string, "url": string}>();
|
247
|
this.dataProviderInfo.countries = new Array<string>();
|
248
|
countriesSet = new Set<string>();
|
249
|
}
|
250
|
|
251
|
this.dataProviderInfo.organizations[counter] = {"acronym": "", "name": "", "id": ""};
|
252
|
//this.dataProviderInfo.organizations[counter]['name'] = (mydata.legalname ? mydata.legalname : "[no title available");
|
253
|
this.dataProviderInfo.organizations[counter]['id'] = mydata['to'].content;
|
254
|
|
255
|
if(mydata.hasOwnProperty("legalshortname")) {
|
256
|
this.dataProviderInfo.organizations[counter]['acronym'] = mydata.legalshortname;
|
257
|
}
|
258
|
if(mydata.hasOwnProperty("legalname")) {
|
259
|
this.dataProviderInfo.organizations[counter]['name'] = mydata.legalname;
|
260
|
}
|
261
|
if(!this.dataProviderInfo.organizations[counter]['acronym'] && !this.dataProviderInfo.organizations[counter]['name']){
|
262
|
// acronym is displayed with link and name only in tooltip
|
263
|
this.dataProviderInfo.organizations[counter]['acronym'] = "[no title available]";
|
264
|
}
|
265
|
|
266
|
if(mydata.country != '' && mydata['country'].classname != '') {
|
267
|
if(!countriesSet.has(mydata['country'].classname)) {
|
268
|
this.dataProviderInfo.countries.push(mydata['country'].classname);
|
269
|
countriesSet.add(mydata['country'].classname);
|
270
|
}
|
271
|
}
|
272
|
|
273
|
counter++;
|
274
|
}
|
275
|
}
|
276
|
}
|
277
|
}
|
278
|
if(data[6] != null) {
|
279
|
this.dataProviderInfo.journal = {"journal": "", "issn": "", "lissn": "", "eissn": ""};
|
280
|
this.dataProviderInfo.journal['journal'] = data[6].content;
|
281
|
this.dataProviderInfo.journal['issn'] = data[6]['issn'];
|
282
|
this.dataProviderInfo.journal['lissn'] = data[6]['lissn'];
|
283
|
this.dataProviderInfo.journal['eissn'] = data[6]['eissn'];
|
284
|
|
285
|
}else{
|
286
|
this.dataProviderInfo.journal = null;
|
287
|
this.dataProviderInfo.journal = {"journal": "", "issn": "", "lissn": "", "eissn": ""};
|
288
|
}
|
289
|
|
290
|
return this.dataProviderInfo;
|
291
|
}
|
292
|
}
|