1
|
import {Injectable} from '@angular/core';
|
2
|
import {Http, Response} from '@angular/http';
|
3
|
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
|
4
|
import {Observable, throwError} from 'rxjs';
|
5
|
import {DatasetInfo} from '../../utils/entities/datasetInfo';
|
6
|
|
7
|
|
8
|
|
9
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
10
|
|
11
|
import { ParsingFunctions } from '../landing-utils/parsingFunctions.class';
|
12
|
import {map} from "rxjs/operators";
|
13
|
|
14
|
@Injectable()
|
15
|
export class DatasetService {
|
16
|
|
17
|
constructor(private http: HttpClient ) {
|
18
|
this.parsingFunctions = new ParsingFunctions();
|
19
|
}
|
20
|
|
21
|
public parsingFunctions: ParsingFunctions;
|
22
|
datasetInfo: DatasetInfo;
|
23
|
|
24
|
getDatasetInfo (id: string, properties:EnvProperties):any {
|
25
|
|
26
|
let url = properties.searchAPIURLLAst+'datasets/'+id+"?format=json";
|
27
|
let key = url;
|
28
|
|
29
|
|
30
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
31
|
//.map(res => <any> res.json())
|
32
|
.pipe(map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity']['oaf:result'],res]))
|
33
|
.pipe(map(res => [res[1], //0
|
34
|
res[1]['title'], //1
|
35
|
res[1]['rels']['rel'], //2
|
36
|
res[1]['children'], //3
|
37
|
res[1]['pid'], //4
|
38
|
res[1]['subject'], //5
|
39
|
res[1]['bestaccessright'], //6
|
40
|
res[1]['collectedfrom'], //7
|
41
|
res[1]['context'], //8
|
42
|
//res[1]['resulttype'],
|
43
|
res[0], //9
|
44
|
res[1]['creator'], //10
|
45
|
res[1]['language'], //11
|
46
|
res[1]['country'], //12
|
47
|
res[2], //13
|
48
|
(res[1]['extraInfo']!= undefined && res[1]['extraInfo']['citations']!= undefined)? res[1]['extraInfo']['citations']['citation']:null, //14
|
49
|
res[1]['journal'] //15
|
50
|
]))
|
51
|
.pipe(map(res => this.parseDatasetInfo(res, properties)));
|
52
|
}
|
53
|
|
54
|
private handleError (error: HttpErrorResponse) {
|
55
|
// in a real world app, we may send the error to some remote logging infrastructure
|
56
|
// instead of just logging it to the console
|
57
|
console.log(error);
|
58
|
return throwError(error || 'Server error');
|
59
|
}
|
60
|
|
61
|
parseDatasetInfo (data: any, properties: EnvProperties):any {
|
62
|
this.datasetInfo = new DatasetInfo();
|
63
|
this.datasetInfo.record = data[13];
|
64
|
// ['result']['metadata']['oaf:entity']['oaf:result']
|
65
|
if(data[0] != null) {
|
66
|
var date:string = (data[0].dateofacceptance)+""; // transform to string in case it is an integer
|
67
|
this.datasetInfo.date = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
|
68
|
this.datasetInfo.dateofacceptance = data[0].dateofacceptance;
|
69
|
this.datasetInfo.publisher = data[0].publisher;
|
70
|
if(!Array.isArray(data[0].description)) {
|
71
|
this.datasetInfo.description = String(data[0].description);
|
72
|
} else {
|
73
|
this.datasetInfo.description = String(data[0].description[0]);
|
74
|
}
|
75
|
this.datasetInfo.embargoEndDate = data[0].embargoenddate;
|
76
|
}
|
77
|
/*this.datasetInfo.title = {"name": "", "url": "", "accessMode": ""};
|
78
|
if(data[0]['bestaccessright'] && data[0]['bestaccessright'].hasOwnProperty("classid")) {
|
79
|
this.datasetInfo.title.accessMode = data[0]['bestaccessright'].classid;
|
80
|
}
|
81
|
if(data[1] != null) {
|
82
|
if(Array.isArray(data[1])) {
|
83
|
this.datasetInfo.title['name'] = data[1][0].content;
|
84
|
} else {
|
85
|
this.datasetInfo.title['name'] = data[1].content;
|
86
|
}
|
87
|
}*/
|
88
|
if(data[0]['bestaccessright'] && data[0]['bestaccessright'].hasOwnProperty("classid")) {
|
89
|
this.datasetInfo.accessMode = data[0]['bestaccessright'].classid;
|
90
|
}
|
91
|
// ['result']['metadata']['oaf:entity']['oaf:result']['title']
|
92
|
if(data[1] != null) {
|
93
|
if(Array.isArray(data[1])) {
|
94
|
this.datasetInfo.title = String(data[1][0].content);
|
95
|
if(data[1][1].classid == "subtitle") {
|
96
|
this.datasetInfo.subtitle = String(data[1][1].content);
|
97
|
}
|
98
|
} else {
|
99
|
this.datasetInfo.title = String(data[1].content);
|
100
|
}
|
101
|
}
|
102
|
|
103
|
// ['result']['metadata']['oaf:entity']['oaf:result']['rels']['rel']
|
104
|
if(data[2] != null) {
|
105
|
let relation;
|
106
|
let length = data[2].length!=undefined ? data[2].length : 1;
|
107
|
|
108
|
for(let i=0; i<length; i++) {
|
109
|
relation = data[2].length!=undefined ? data[2][i] : data[2];
|
110
|
if(relation.hasOwnProperty("to")) {
|
111
|
if(relation['to'].class == "isProducedBy") {
|
112
|
this.datasetInfo.fundedByProjects = this.parsingFunctions.parseFundingByProjects(this.datasetInfo.fundedByProjects, relation, this.datasetInfo.projectsProvenanceVocabulary);
|
113
|
} else if(relation['to'].class == "isRelatedTo") {
|
114
|
let provenanceAction: string;
|
115
|
if(relation.provenanceaction in this.datasetInfo.researchResultsProvenanceVocabulary) {
|
116
|
provenanceAction = this.datasetInfo.researchResultsProvenanceVocabulary[relation.provenanceaction];
|
117
|
} else {
|
118
|
provenanceAction = "Other"
|
119
|
}
|
120
|
|
121
|
this.datasetInfo.relatedResearchResults = this.parsingFunctions.parseRelatedResearchResults(this.datasetInfo.relatedResearchResults, relation, provenanceAction);
|
122
|
|
123
|
} else if(relation['to'].class == "hasAmongTopNSimilarDocuments") {
|
124
|
this.datasetInfo.similarResearchResults = this.parsingFunctions.parseSimilarResearchResults(this.datasetInfo.similarResearchResults, relation);
|
125
|
}
|
126
|
}
|
127
|
}
|
128
|
}
|
129
|
|
130
|
// ['result']['metadata']['oaf:entity']['oaf:result']['children']
|
131
|
if(data[3] != null) {
|
132
|
if(data[3].hasOwnProperty("instance")) {
|
133
|
this.datasetInfo.hostedBy_collectedFrom = new Array<{ "downloadName": string, "downloadUrl": string[],
|
134
|
"collectedName": string, "collectedId": string,
|
135
|
"accessMode": string[], "bestAccessMode": string,
|
136
|
"type": string, "year":string}>();
|
137
|
|
138
|
this.datasetInfo.types = new Array<string>();
|
139
|
let types = new Set<string>();
|
140
|
|
141
|
let counter = 0;
|
142
|
let instance;
|
143
|
|
144
|
let length = data[3]['instance'].length!=undefined ? data[3]['instance'].length : 1;
|
145
|
|
146
|
for(let i=0; i<length; i++) {
|
147
|
instance = data[3]['instance'].length!=undefined ? data[3]['instance'][i] : data[3]['instance'];
|
148
|
|
149
|
this.parsingFunctions.parseTypes(this.datasetInfo.types, types, instance);
|
150
|
|
151
|
if(instance.hasOwnProperty("webresource")) {
|
152
|
let url;
|
153
|
if(instance['webresource'].length == undefined) {
|
154
|
url = instance['webresource'].url;
|
155
|
} else{
|
156
|
url = instance['webresource'][0].url;
|
157
|
}
|
158
|
|
159
|
if(instance.hasOwnProperty("hostedby")) {
|
160
|
counter = this.parsingFunctions.parseHostedBy_collectedFrom(this.datasetInfo.hostedBy_collectedFrom, instance, data[0], url, counter/*, this.datasetInfo.title*/, this.datasetInfo.accessMode);
|
161
|
}
|
162
|
}
|
163
|
}
|
164
|
}
|
165
|
}
|
166
|
|
167
|
// ['result']['metadata']['oaf:entity']['oaf:result']['pid']
|
168
|
if(data[4] != null) {
|
169
|
this.datasetInfo.identifiers = this.parsingFunctions.parseIdentifiers(data[4]);
|
170
|
}
|
171
|
|
172
|
// ['result']['metadata']['oaf:entity']['oaf:result']['subject']
|
173
|
if(data[5] != null) {
|
174
|
let subjectResults: [string[], Map<string, string[]>, Map<string, string[]>] = this.parsingFunctions.parseAllSubjects(data[5]);
|
175
|
this.datasetInfo.subjects = subjectResults[0];
|
176
|
this.datasetInfo.otherSubjects = subjectResults[1];
|
177
|
this.datasetInfo.classifiedSubjects = subjectResults[2];
|
178
|
}
|
179
|
|
180
|
this.datasetInfo.hostedBy_collectedFrom = this.parsingFunctions.addPublisherToHostedBy_collectedFrom(
|
181
|
this.datasetInfo.hostedBy_collectedFrom, this.datasetInfo.publisher,
|
182
|
null, this.datasetInfo.identifiers/*, this.datasetInfo.title*/);
|
183
|
|
184
|
// ['result']['metadata']['oaf:entity']['oaf:result']['context']
|
185
|
if(data[8] != null) {
|
186
|
this.datasetInfo.contexts = this.parsingFunctions.parseContexts(data[8]);
|
187
|
}
|
188
|
|
189
|
// if(data[9] != null && this.datasetInfo.type == undefined) {
|
190
|
// if(data[9].hasOwnProperty('classname')) {
|
191
|
// this.datasetInfo.type = data[9].classname;
|
192
|
// }
|
193
|
// }
|
194
|
|
195
|
// ['result']['header']['dri:status']
|
196
|
if(data[9] != null && data[9] == "under curation") {
|
197
|
this.datasetInfo.underCurationMessage = true;
|
198
|
} else {
|
199
|
this.datasetInfo.underCurationMessage = false;
|
200
|
}
|
201
|
|
202
|
// ['result']['metadata']['oaf:entity']['oaf:result']['creator']
|
203
|
if(data[10] != null) {
|
204
|
if(this.datasetInfo.authors == undefined) {
|
205
|
this.datasetInfo.authors = new Array<{"fullName": string, "orcid": string}>();
|
206
|
}
|
207
|
|
208
|
let authors = data[10];
|
209
|
let length = Array.isArray(authors) ? authors.length : 1;
|
210
|
|
211
|
for(let i=0; i<length; i++) {
|
212
|
let author = Array.isArray(authors) ? authors[i] : authors;
|
213
|
if(author) {
|
214
|
/*if (author.ORCID && author.ORCID.indexOf(properties.orcidURL) != -1) {
|
215
|
author.ORCID = author.ORCID.substr(properties.orcidURL.length);
|
216
|
}*/
|
217
|
this.datasetInfo['authors'][author.rank] = {"fullName": author.content, "orcid": author.ORCID};
|
218
|
}
|
219
|
}
|
220
|
this.datasetInfo.authors = this.datasetInfo.authors.filter(function (item) {
|
221
|
return (item != undefined && item.fullName != undefined);
|
222
|
});
|
223
|
}
|
224
|
|
225
|
// ['result']['metadata']['oaf:entity']['oaf:result']['language']
|
226
|
if(data[11] != null) {
|
227
|
this.datasetInfo.languages = this.parsingFunctions.parseLanguages(data[11]);
|
228
|
}
|
229
|
// ['result']['metadata']['oaf:entity']['oaf:result']['country']
|
230
|
if(data[12] != null) {
|
231
|
this.datasetInfo.countries = this.parsingFunctions.parseCountries(data[12]);
|
232
|
}
|
233
|
|
234
|
// ['result']['metadata']['oaf:entity']['oaf:result']['extraInfo']['citations']['citation']
|
235
|
if(data[14] != null) {
|
236
|
this.datasetInfo.references = this.parsingFunctions.parseReferences(data[14]);
|
237
|
}
|
238
|
|
239
|
if(this.datasetInfo.relatedResearchResults) {
|
240
|
let self = this;
|
241
|
this.datasetInfo.relatedResearchResults.forEach(function (value, key, map) {
|
242
|
self.datasetInfo.relatedResearchResults.set(key, self.parsingFunctions.sortByPercentage(value));
|
243
|
});
|
244
|
}
|
245
|
this.datasetInfo.similarResearchResults = this.parsingFunctions.sortByPercentage(this.datasetInfo.similarResearchResults);
|
246
|
if(data[15] != null) {
|
247
|
this.datasetInfo.journal = {"journal": "", "issn": "", "lissn": "", "eissn": "", "issue": "", "volume": "", "start_page": "", "end_page": ""}
|
248
|
|
249
|
this.datasetInfo.journal['journal'] = data[15].content;
|
250
|
this.datasetInfo.journal['issn'] = data[15].issn;
|
251
|
this.datasetInfo.journal['lissn'] = data[15].lissn;
|
252
|
this.datasetInfo.journal['eissn'] = data[15].eissn;
|
253
|
this.datasetInfo.journal['issue'] = data[15].iss;
|
254
|
this.datasetInfo.journal['volume'] = data[15].vol;
|
255
|
this.datasetInfo.journal['start_page'] = data[15].sp;
|
256
|
this.datasetInfo.journal['end_page'] = data[15].ep;
|
257
|
}
|
258
|
|
259
|
return this.datasetInfo;
|
260
|
}
|
261
|
}
|