1
|
|
2
|
import {Injectable} from '@angular/core';
|
3
|
import {Http, Response} from '@angular/http';
|
4
|
import {Observable} from 'rxjs/Observable';
|
5
|
import {PublicationInfo} from '../../utils/entities/publicationInfo';
|
6
|
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
|
7
|
import 'rxjs/add/observable/of';
|
8
|
import 'rxjs/add/operator/do';
|
9
|
import 'rxjs/add/operator/share';
|
10
|
|
11
|
|
12
|
import { ParsingFunctions } from '../landing-utils/parsingFunctions.class';
|
13
|
|
14
|
@Injectable()
|
15
|
export class PublicationService {
|
16
|
|
17
|
constructor(private http: Http ) {
|
18
|
this.parsingFunctions = new ParsingFunctions();
|
19
|
}
|
20
|
|
21
|
public parsingFunctions: ParsingFunctions;
|
22
|
publicationInfo: PublicationInfo;
|
23
|
|
24
|
getPublicationInfo (id: string):any {
|
25
|
console.info("getPublicationInfo in service");
|
26
|
let url = OpenaireProperties. getSearchAPIURLLast() + 'publications/' +id+"?format=json";
|
27
|
let key = url;
|
28
|
|
29
|
return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url)
|
30
|
.map(res => <any> res.json())
|
31
|
.map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity']])
|
32
|
.map(res => [ res[1]['oaf:result'],
|
33
|
res[1]['oaf:result']['title'],
|
34
|
res[1]['oaf:result']['rels']['rel'],
|
35
|
res[1]['oaf:result']['children'],
|
36
|
res[1]['oaf:result']['pid'],
|
37
|
res[1]['oaf:result']['journal'],
|
38
|
res[1]['oaf:result']['language'],
|
39
|
res[1]['oaf:result']['subject'],
|
40
|
res[1]['oaf:result']['bestaccessright'],
|
41
|
res[1]['oaf:result']['collectedfrom'],
|
42
|
(res[1]['extraInfo']!= undefined && res[1]['extraInfo']['citations']!= undefined)? res[1]['extraInfo']['citations']['citation']:null,
|
43
|
res[1]['oaf:result']['context'],
|
44
|
res[0],
|
45
|
res[1]['oaf:result']['creator']
|
46
|
])
|
47
|
.map(res => this.parsePublicationInfo(res));
|
48
|
}
|
49
|
|
50
|
private handleError (error: Response) {
|
51
|
// in a real world app, we may send the error to some remote logging infrastructure
|
52
|
// instead of just logging it to the console
|
53
|
console.log(error);
|
54
|
return Observable.throw(error || 'Server error');
|
55
|
}
|
56
|
|
57
|
parsePublicationInfo (data: any):any {
|
58
|
this.publicationInfo = new PublicationInfo();
|
59
|
|
60
|
if(data[0] != null) {
|
61
|
var date:string = (data[0].dateofacceptance)+""; // transform to string in case it is an integer
|
62
|
this.publicationInfo.date = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
|
63
|
this.publicationInfo.dateofacceptance = data[0].dateofacceptance;
|
64
|
this.publicationInfo.publisher = data[0].publisher;
|
65
|
if(!Array.isArray(data[0].description)) {
|
66
|
this.publicationInfo.description = data[0].description;
|
67
|
} else {
|
68
|
this.publicationInfo.description = data[0].description[0];
|
69
|
}
|
70
|
this.publicationInfo.embargoEndDate = data[0].embargoenddate;
|
71
|
}
|
72
|
|
73
|
this.publicationInfo.title = {"name": "", "url": "", "accessMode": ""};
|
74
|
if(data[0]['bestaccessright'].hasOwnProperty("classid")) {
|
75
|
this.publicationInfo.title.accessMode = data[0]['bestaccessright'].classid;
|
76
|
}
|
77
|
|
78
|
if(data[1] != null) {
|
79
|
if(Array.isArray(data[1])) {
|
80
|
this.publicationInfo.title['name'] = data[1][0].content;
|
81
|
} else {
|
82
|
this.publicationInfo.title['name'] = data[1].content;
|
83
|
}
|
84
|
}
|
85
|
|
86
|
if(data[2] != null) {
|
87
|
let relation;
|
88
|
let length = Array.isArray(data[2]) ? data[2].length : 1;
|
89
|
|
90
|
for(let i=0; i<length; i++) {
|
91
|
relation = Array.isArray(data[2]) ? data[2][i] : data[2];
|
92
|
if(relation.hasOwnProperty("to")) {
|
93
|
// if(relation['to'].class == "hasAuthor") {
|
94
|
// if(this.publicationInfo.authors == undefined) {
|
95
|
// this.publicationInfo.authors = new Array<{"name": string, "id": string}>();
|
96
|
// }
|
97
|
//
|
98
|
// this.publicationInfo.authors[relation.ranking-1] = {"name": "", "id": ""};
|
99
|
// this.publicationInfo.authors[relation.ranking-1]['name'] = relation.fullname;
|
100
|
/*} else*/ if(relation['to'].class == "isProducedBy") {
|
101
|
this.publicationInfo.fundedByProjects = this.parsingFunctions.parseFundingByProjects(this.publicationInfo.fundedByProjects, relation, this.publicationInfo.projectsProvenanceVocabulary);
|
102
|
} else if(relation['to'].class == "isRelatedTo") {
|
103
|
let provenanceAction: string;
|
104
|
if(relation.provenanceaction in this.publicationInfo.researchResultsProvenanceVocabulary) {
|
105
|
provenanceAction = this.publicationInfo.researchResultsProvenanceVocabulary[relation.provenanceaction];
|
106
|
} else {
|
107
|
provenanceAction = "Other";
|
108
|
}
|
109
|
|
110
|
this.publicationInfo.relatedResearchResults = this.parsingFunctions.parseRelatedResearchResults(this.publicationInfo.relatedResearchResults, relation, provenanceAction);
|
111
|
} else if(relation['to'].class == "hasAmongTopNSimilarDocuments") {
|
112
|
this.publicationInfo.similarResearchResults = this.parsingFunctions.parseSimilarResearchResults(this.publicationInfo.similarResearchResults, relation);
|
113
|
} else if(relation['to'].class == "hasAuthorInstitution") {
|
114
|
this.publicationInfo.organizations = this.parseRelatedOrganizations(this.publicationInfo.organizations, relation);
|
115
|
}
|
116
|
}
|
117
|
}
|
118
|
}
|
119
|
|
120
|
if(data[3] != null) {
|
121
|
if(data[3].hasOwnProperty("instance")) {
|
122
|
this.publicationInfo.downloadFrom = new Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>();
|
123
|
this.publicationInfo.publishedIn = new Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>();
|
124
|
|
125
|
this.publicationInfo.types = new Array<string>();
|
126
|
let types = new Set<string>();
|
127
|
|
128
|
let counter = 0;
|
129
|
let instance;
|
130
|
|
131
|
let length = Array.isArray(data[3]['instance']) ? data[3]['instance'].length : 1;
|
132
|
|
133
|
for(let i=0; i<length; i++) {
|
134
|
instance = Array.isArray(data[3]['instance']) ? data[3]['instance'][i] : data[3]['instance'];
|
135
|
|
136
|
this.parsingFunctions.parseTypes(this.publicationInfo.types, types, instance);
|
137
|
|
138
|
if(instance.hasOwnProperty("webresource")) {
|
139
|
let url;
|
140
|
if(!Array.isArray(instance['webresource'])) {
|
141
|
url = instance['webresource'].url;
|
142
|
} else{
|
143
|
url = instance['webresource'][0].url;
|
144
|
}
|
145
|
|
146
|
if(instance.hasOwnProperty("collectedfrom")) {
|
147
|
this.publicationInfo.collectedFrom = this.parsingFunctions.parseCollectedFrom(instance['collectedfrom']);
|
148
|
}
|
149
|
|
150
|
if(instance.hasOwnProperty("hostedby")) {
|
151
|
if(instance['hostedby'].name != "other resources" && instance['hostedby'].name != "Unknown Repository") {
|
152
|
this.parsingFunctions.parseDownloadFrom(this.publicationInfo.downloadFrom, instance, url);
|
153
|
} else {
|
154
|
counter = this.parsingFunctions.parsePublishedIn(this.publicationInfo.publishedIn, instance, data[0], url, counter);
|
155
|
}
|
156
|
|
157
|
if(this.publicationInfo.title != undefined) {
|
158
|
if(!this.publicationInfo.title['url']) {
|
159
|
this.publicationInfo.title['url'] = url;
|
160
|
}
|
161
|
|
162
|
if(this.parsingFunctions.changeBestAccessMode(this.publicationInfo.title['accessMode'], instance['licence'])) {
|
163
|
this.publicationInfo.title['accessMode'] = instance['licence'].classid;
|
164
|
this.publicationInfo.title['url'] = url;
|
165
|
}
|
166
|
}
|
167
|
}
|
168
|
}
|
169
|
}
|
170
|
}
|
171
|
|
172
|
if(data[3].hasOwnProperty("externalreference")) {
|
173
|
let externalResults: [Map<string, Map<string, string>>, { "name": string, "url": string}[]] = this.parseBioentitiesAndSoftware(data[3]);
|
174
|
this.publicationInfo.bioentities = externalResults[0];
|
175
|
this.publicationInfo.software = externalResults[1];
|
176
|
}
|
177
|
}
|
178
|
|
179
|
if(data[4] != null) {
|
180
|
this.publicationInfo.identifiers = this.parsingFunctions.parseIdentifiers(data[4]);
|
181
|
}
|
182
|
|
183
|
if(data[5] != null) {
|
184
|
this.publicationInfo.journal = {"journal": "", "issn": "", "lissn": ""}
|
185
|
|
186
|
this.publicationInfo.journal['journal'] = data[5].content;
|
187
|
this.publicationInfo.journal['issn'] = data[5].issn;
|
188
|
this.publicationInfo.journal['lissn'] = data[5].lissn;
|
189
|
}
|
190
|
|
191
|
if(data[6] != null) {
|
192
|
this.publicationInfo.languages = new Array<string>();
|
193
|
|
194
|
if(!Array.isArray(data[6])) {
|
195
|
if(data[6].classname != "Undetermined" && data[6].classname) {
|
196
|
this.publicationInfo.languages.push(data[6].classname);
|
197
|
}
|
198
|
} else {
|
199
|
for(let i=0; i<data[6].length; i++) {
|
200
|
if(data[6][i].classname != "Undetermined" && data[6][i].classname) {
|
201
|
this.publicationInfo.languages.push(data[6][i].classname);
|
202
|
}
|
203
|
}
|
204
|
}
|
205
|
}
|
206
|
|
207
|
if(data[7] != null) {
|
208
|
let subjectResults: [string[], Map<string, string[]>, Map<string, string[]>] = this.parsingFunctions.parseAllSubjects(data[7]);
|
209
|
this.publicationInfo.subjects = subjectResults[0];
|
210
|
this.publicationInfo.otherSubjects = subjectResults[1];
|
211
|
this.publicationInfo.classifiedSubjects = subjectResults[2];
|
212
|
}
|
213
|
|
214
|
// if(data[8] != null) {
|
215
|
// this.publicationInfo.bestaccessright = data[8].classid;
|
216
|
// }
|
217
|
|
218
|
// if(data[9] != null) {
|
219
|
// this.publicationInfo.collectedFrom = this.parsingFunctions.parseCollectedFrom(data[9]);
|
220
|
// }
|
221
|
|
222
|
this.publicationInfo.downloadFrom = this.parsingFunctions.addPublisherToDownloadFrom(
|
223
|
this.publicationInfo.downloadFrom, this.publicationInfo.publisher,
|
224
|
this.publicationInfo.journal, this.publicationInfo.identifiers,
|
225
|
this.publicationInfo.title);
|
226
|
|
227
|
if(data[10] != null) {
|
228
|
this.publicationInfo.references = this.parseReferences(data[10]);
|
229
|
}
|
230
|
|
231
|
if(data[11] != null) {
|
232
|
this.publicationInfo.contexts = this.parsingFunctions.parseContexts(data[11]);
|
233
|
}
|
234
|
|
235
|
if(data[12] != null && data[12] == "under curation") {
|
236
|
this.publicationInfo.underCurationMessage = true;
|
237
|
} else {
|
238
|
this.publicationInfo.underCurationMessage = false;
|
239
|
}
|
240
|
|
241
|
if(data[13] != null) {
|
242
|
if(this.publicationInfo.authors == undefined) {
|
243
|
this.publicationInfo.authors = new Array<string>();
|
244
|
}
|
245
|
|
246
|
let authors = data[13];
|
247
|
let length = Array.isArray(authors) ? authors.length : 1;
|
248
|
|
249
|
for(let i=0; i<length; i++) {
|
250
|
let author = Array.isArray(authors) ? authors[i] : authors;
|
251
|
this.publicationInfo.authors[author.rank-1] = author.content;
|
252
|
}
|
253
|
this.publicationInfo.authors = this.publicationInfo.authors.filter(function (item) {
|
254
|
return (item != undefined);
|
255
|
});
|
256
|
}
|
257
|
|
258
|
return this.publicationInfo;
|
259
|
}
|
260
|
|
261
|
parseRelatedOrganizations(organizations: {"name": string, "shortname":string, "id": string, "websiteUrl": string, "country": string, "trust": number}[], relation: any):
|
262
|
{"name": string, "shortname":string, "id": string, "websiteUrl": string, "country": string, "trust": number}[] {
|
263
|
if(organizations == undefined) {
|
264
|
organizations = new Array<{
|
265
|
"name": string, "shortname": string,
|
266
|
"id": string, "websiteUrl": string,
|
267
|
"country": string, "trust": number}>();
|
268
|
}
|
269
|
|
270
|
let organization: { "name": string, "shortname": string,
|
271
|
"id": string, "websiteUrl": string,
|
272
|
"country": string, "trust": number
|
273
|
} = {
|
274
|
"name": "", "shortname": "",
|
275
|
"id": "", "websiteUrl": "",
|
276
|
"country": "", "trust": null
|
277
|
};
|
278
|
|
279
|
organization.id = relation['to'].content;
|
280
|
organization.name = relation.legalname;
|
281
|
organization.shortname = relation.legalshortname;
|
282
|
organization.websiteUrl = relation.websiteurl;
|
283
|
if(relation.country) {
|
284
|
organization.country = relation.country.classname;
|
285
|
}
|
286
|
if(relation.trust) {
|
287
|
organization.trust = Math.round(relation.trust*100);
|
288
|
}
|
289
|
|
290
|
organizations.push(organization);
|
291
|
return organizations;
|
292
|
}
|
293
|
|
294
|
parseBioentitiesAndSoftware(children: any) : [Map<string, Map<string, string>>, { "name": string, "url": string}[]] {
|
295
|
let bioentities: Map<string, Map<string, string>>;
|
296
|
let software: {"name": string, "url": string}[];
|
297
|
|
298
|
let length = Array.isArray(children['externalreference']) ? children['externalreference'].length : 1;
|
299
|
|
300
|
let externalreference;
|
301
|
for(let i=0; i<length; i++) {
|
302
|
externalreference = Array.isArray(children['externalreference']) ? children['externalreference'][i] : children['externalreference'];
|
303
|
|
304
|
if(externalreference.hasOwnProperty("qualifier")) {
|
305
|
if(externalreference['qualifier'].classid == "accessionNumber") {
|
306
|
|
307
|
if(bioentities == undefined) {
|
308
|
bioentities = new Map<string, Map<string, string>>();
|
309
|
}
|
310
|
|
311
|
if(!bioentities.has(externalreference.sitename)) {
|
312
|
bioentities.set(externalreference.sitename, new Map<string, string>());
|
313
|
}
|
314
|
bioentities.get(externalreference.sitename).set(externalreference.refidentifier, externalreference.url);
|
315
|
|
316
|
} else if(externalreference['qualifier'].classid == "software") {
|
317
|
|
318
|
if(software == undefined) {
|
319
|
software = new Array<{"name": string, "url": string}>();
|
320
|
}
|
321
|
|
322
|
software.push({"name": externalreference.sitename, "url": externalreference.url});
|
323
|
}
|
324
|
}
|
325
|
}
|
326
|
|
327
|
return [bioentities, software];
|
328
|
}
|
329
|
|
330
|
parseReferences(citations: any): {"name": string, "url": string}[] {
|
331
|
let references = new Array<{"name": string, "url": string}>();
|
332
|
|
333
|
let citation;
|
334
|
let length = Array.isArray(citations) ? citations.length : 1;
|
335
|
for(let i=0; i<length; i++) {
|
336
|
citation = Array.isArray(citations) ? citations[i] : citations;
|
337
|
|
338
|
let url;
|
339
|
if(citation.hasOwnProperty("id")) {
|
340
|
let citationId;
|
341
|
let length1 = Array.isArray(citation['id']) ? citation['id'].length : 1;
|
342
|
for(let j=0; j<length1; j++) {
|
343
|
citationId = Array.isArray(citation['id']) ? citation['id'][j] : citation['id'];
|
344
|
|
345
|
if(citationId.type == "pmid") {
|
346
|
url = OpenaireProperties.getPmidURL()+citationId.value;
|
347
|
}
|
348
|
}
|
349
|
}
|
350
|
|
351
|
references[citation.position-1] = { "name": "", "url": ""};
|
352
|
references[citation.position-1]['name'] = citation.rawText;
|
353
|
references[citation.position-1]['url'] = url;
|
354
|
}
|
355
|
return references;
|
356
|
}
|
357
|
}
|