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