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
|
|
53
|
private handleError (error: HttpErrorResponse) {
|
54
|
// in a real world app, we may send the error to some remote logging infrastructure
|
55
|
// instead of just logging it to the console
|
56
|
console.log(error);
|
57
|
return throwError(error || 'Server error');
|
58
|
}
|
59
|
|
60
|
parseDataproviderAggregationStatus(data: any): any {
|
61
|
var aggregationStatus: {"fundedContent": string, "indexRecords": string, "fulltexts": string, "lastUpdateDate": string} = null;
|
62
|
if(data != null && data[0] != null) {
|
63
|
aggregationStatus = {"fundedContent": "-1", "indexRecords": "-1", "fulltexts": "-1", "lastUpdateDate": null};
|
64
|
aggregationStatus.fundedContent = data[0].fundedContent;
|
65
|
aggregationStatus.indexRecords = data[0].indexRecords;
|
66
|
aggregationStatus.fulltexts = data[0].fulltexts;
|
67
|
|
68
|
if(data[0].hasOwnProperty("aggregationHistory")) {
|
69
|
let length = Array.isArray(data[0]["aggregationHistory"]) ? data[0]["aggregationHistory"].length : 1;
|
70
|
|
71
|
for(let i=0; i<length; i++) {
|
72
|
var aggregationHistory = Array.isArray(data[0]["aggregationHistory"]) ? data[0]["aggregationHistory"][i] : data[0]["aggregationHistory"];
|
73
|
if(aggregationHistory && aggregationHistory.indexedVersion == true) {
|
74
|
aggregationStatus.lastUpdateDate = aggregationHistory.date;
|
75
|
break;
|
76
|
}
|
77
|
}
|
78
|
}
|
79
|
}
|
80
|
return aggregationStatus;
|
81
|
}
|
82
|
|
83
|
parseDataProviderInfo (data: any):any {
|
84
|
this.dataProviderInfo = new DataProviderInfo();
|
85
|
|
86
|
if(data[0] != null) {
|
87
|
this.dataProviderInfo.title = {"name": (data[0].englishname)?data[0].englishname: data[0].officialname, "url": data[0].websiteurl};
|
88
|
this.dataProviderInfo.officialName = data[0].officialname;
|
89
|
|
90
|
var pattern = /.{12}::.+/;
|
91
|
var originalIds =(data[0].originalId)?data[0].originalId:"";
|
92
|
|
93
|
let length = Array.isArray(originalIds) ? originalIds.length : 1;
|
94
|
|
95
|
for(let i=0; i<length; i++) {
|
96
|
var originalId = Array.isArray(originalIds) ? originalIds[i] : originalIds;
|
97
|
var matched = originalId.match(pattern);
|
98
|
|
99
|
if(matched && originalId && originalId != ""){
|
100
|
if(originalId.indexOf("opendoar____::") != -1){
|
101
|
this.dataProviderInfo.openDoarId = originalId.split("opendoar____::")[1];
|
102
|
}else if (originalId.indexOf("re3data_____::") != -1){
|
103
|
this.dataProviderInfo.r3DataId = originalId.split("re3data_____::")[1];
|
104
|
}
|
105
|
this.dataProviderInfo.originalId = originalId;
|
106
|
}
|
107
|
}
|
108
|
|
109
|
this.dataProviderInfo.subjects = [];
|
110
|
length = Array.isArray(data[0]['subjects']) ? data[0]['subjects'].length : 1;
|
111
|
for(let i=0; i<length; i++) {
|
112
|
let subject = Array.isArray(data[0]['subjects']) ? data[0]['subjects'][i] :data[0]['subjects'];
|
113
|
if(subject && subject.content) {
|
114
|
this.dataProviderInfo.subjects.push(subject.content);
|
115
|
}
|
116
|
}
|
117
|
|
118
|
if(!Array.isArray(data[0]['description'])) {
|
119
|
this.dataProviderInfo.description = (data[0]['description']) ? String(data[0]['description']) : "";
|
120
|
} else {
|
121
|
this.dataProviderInfo.description = (data[0]['description'][0]) ? String(data[0]['description'][0]) : "";
|
122
|
}
|
123
|
}
|
124
|
|
125
|
if(data[1] != null) {
|
126
|
this.dataProviderInfo.type = data[1].classname;
|
127
|
|
128
|
if(data[1].classid == "entityregistry" || data[1].classid == "entityregistry::projects" || data[1].classid == "entityregistry::repositories") {
|
129
|
this.dataProviderInfo.registry = true;
|
130
|
} else {
|
131
|
this.dataProviderInfo.registry = false;
|
132
|
}
|
133
|
|
134
|
if(this.dataProviderInfo.tabs == undefined) {
|
135
|
this.dataProviderInfo.tabs = new Array<{"name": string, "content": string}>();
|
136
|
}
|
137
|
this.dataProviderInfo.tabs = [];
|
138
|
if(this.dataProviderInfo.tabsInTypes.publicationsTab.has(data[1].classid)) {
|
139
|
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
|
140
|
this.dataProviderInfo.tabs2.push("Publications");
|
141
|
}
|
142
|
if(this.dataProviderInfo.tabsInTypes.datasetsTab.has(data[1].classid)) {
|
143
|
this.dataProviderInfo.tabs.push({"name": "Research Data", "content": "datasetsTab"});
|
144
|
this.dataProviderInfo.tabs2.push("Research Data");
|
145
|
}
|
146
|
|
147
|
if(this.dataProviderInfo.tabsInTypes.projectsTab.has(data[1].classid)) {
|
148
|
this.dataProviderInfo.tabs.push({"name": "Projects", "content": "projectsTab"});
|
149
|
this.dataProviderInfo.tabs2.push("Projects");
|
150
|
}
|
151
|
if(this.dataProviderInfo.tabsInTypes.datasourcesTab.has(data[1].classid)) {
|
152
|
this.dataProviderInfo.tabs.push({"name": "Content Providers", "content": "datasourcesTab"});
|
153
|
this.dataProviderInfo.tabs2.push("Content Providers");
|
154
|
}
|
155
|
|
156
|
if(this.dataProviderInfo.tabsInTypes.relatedDatasourcesTab.has(data[1].classid)) {
|
157
|
this.dataProviderInfo.tabs.push({"name": "Related Content Providers", "content": "relatedDatasourcesTab"});
|
158
|
this.dataProviderInfo.tabs2.push("Related Content Providers");
|
159
|
}
|
160
|
|
161
|
if(this.dataProviderInfo.tabsInTypes.statisticsTab.has(data[1].classid)) {
|
162
|
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
|
163
|
this.dataProviderInfo.tabs2.push("Statistics");
|
164
|
}
|
165
|
|
166
|
if(this.dataProviderInfo.tabsInTypes.softwareTab.has(data[1].classid)) {
|
167
|
this.dataProviderInfo.tabs.push({"name": "Software", "content": "softwareTab"});
|
168
|
this.dataProviderInfo.tabs2.push("Software");
|
169
|
}
|
170
|
|
171
|
if(this.dataProviderInfo.tabsInTypes.orpsTab.has(data[1].classid)) {
|
172
|
this.dataProviderInfo.tabs.push({"name": "Other Research Products", "content": "orpsTab"});
|
173
|
this.dataProviderInfo.tabs2.push("Other Research Products");
|
174
|
}
|
175
|
|
176
|
if(this.dataProviderInfo.tabsInTypes.metricsTab.has(data[1].classid)) {
|
177
|
this.dataProviderInfo.tabs.push({"name": "Metrics", "content": "metricsTab"});
|
178
|
this.dataProviderInfo.tabs2.push("Metrics");
|
179
|
}
|
180
|
|
181
|
if(this.dataProviderInfo.resultTypes.collectedFrom.has(data[1].classid)) {
|
182
|
this.dataProviderInfo.resultsBy = "collectedFrom";
|
183
|
} else if(this.dataProviderInfo.resultTypes.hostedBy.has(data[1].classid)) {
|
184
|
this.dataProviderInfo.resultsBy = "hostedBy";
|
185
|
}
|
186
|
}
|
187
|
|
188
|
if(!this.dataProviderInfo.registry) {
|
189
|
if(data[2] != null) {
|
190
|
this.dataProviderInfo.compatibility = {"info": "", "name": "", "id": ""};
|
191
|
this.dataProviderInfo.compatibility.info = data[2].classname;
|
192
|
//this.dataProviderInfo.compatibility = data[2].classname;
|
193
|
}
|
194
|
|
195
|
if(data[2] != null && data[2].classid == "hostedBy" && data[3] != null) {
|
196
|
this.dataProviderInfo.compatibility.name = data[3].name;
|
197
|
this.dataProviderInfo.compatibility.id = data[3].id;
|
198
|
|
199
|
if(this.dataProviderInfo.compatibility.name) {
|
200
|
this.dataProviderInfo.compatibility.info = "Collected from ";
|
201
|
}
|
202
|
}
|
203
|
|
204
|
if(data[4] != null) {
|
205
|
let oaiPmhURL:string;
|
206
|
oaiPmhURL = Array.isArray(data[4]) ? data[4][0]:data[4];
|
207
|
if(oaiPmhURL != '' && oaiPmhURL != 'unknown') {
|
208
|
this.dataProviderInfo.oaiPmhURL = oaiPmhURL;
|
209
|
}
|
210
|
}
|
211
|
}
|
212
|
|
213
|
if(data[5] != null) {
|
214
|
let mydata;
|
215
|
let counter = 0;
|
216
|
let countriesSet: Set<string>;
|
217
|
let length = data[5].length!=undefined ? data[5].length : 1;
|
218
|
|
219
|
for(let i=0; i<length; i++) {
|
220
|
mydata = data[5].length!=undefined ? data[5][i] : data[5];
|
221
|
if(mydata.hasOwnProperty("to")) {
|
222
|
if(mydata['to'].class == "provides" && mydata['to'].type == "organization") {
|
223
|
//if(this.dataProviderInfo.organizations == undefined) {
|
224
|
if(this.dataProviderInfo.organizations.length == 0) {
|
225
|
//this.dataProviderInfo.organizations = new Array<{"name": string, "url": string}>();
|
226
|
this.dataProviderInfo.countries = new Array<string>();
|
227
|
countriesSet = new Set<string>();
|
228
|
}
|
229
|
|
230
|
this.dataProviderInfo.organizations[counter] = {"acronym": "", "name": "", "id": ""};
|
231
|
//this.dataProviderInfo.organizations[counter]['name'] = (mydata.legalname ? mydata.legalname : "[no title available");
|
232
|
this.dataProviderInfo.organizations[counter]['id'] = mydata['to'].content;
|
233
|
|
234
|
if(mydata.hasOwnProperty("legalshortname")) {
|
235
|
this.dataProviderInfo.organizations[counter]['acronym'] = mydata.legalshortname;
|
236
|
}
|
237
|
if(mydata.hasOwnProperty("legalname")) {
|
238
|
this.dataProviderInfo.organizations[counter]['name'] = mydata.legalname;
|
239
|
}
|
240
|
if(!this.dataProviderInfo.organizations[counter]['acronym'] && !this.dataProviderInfo.organizations[counter]['name']){
|
241
|
// acronym is displayed with link and name only in tooltip
|
242
|
this.dataProviderInfo.organizations[counter]['acronym'] = "[no title available]";
|
243
|
}
|
244
|
|
245
|
if(mydata.country != '' && mydata['country'].classname != '') {
|
246
|
if(!countriesSet.has(mydata['country'].classname)) {
|
247
|
this.dataProviderInfo.countries.push(mydata['country'].classname);
|
248
|
countriesSet.add(mydata['country'].classname);
|
249
|
}
|
250
|
}
|
251
|
|
252
|
counter++;
|
253
|
}
|
254
|
}
|
255
|
}
|
256
|
}
|
257
|
if(data[6] != null) {
|
258
|
this.dataProviderInfo.journal = {"journal": "", "issn": "", "lissn": "", "eissn": ""};
|
259
|
this.dataProviderInfo.journal['journal'] = data[6].content;
|
260
|
this.dataProviderInfo.journal['issn'] = data[6]['issn'];
|
261
|
this.dataProviderInfo.journal['lissn'] = data[6]['lissn'];
|
262
|
this.dataProviderInfo.journal['eissn'] = data[6]['eissn'];
|
263
|
|
264
|
}else{
|
265
|
this.dataProviderInfo.journal = null;
|
266
|
this.dataProviderInfo.journal = {"journal": "", "issn": "", "lissn": "", "eissn": ""};
|
267
|
}
|
268
|
|
269
|
return this.dataProviderInfo;
|
270
|
}
|
271
|
}
|