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