1
|
import {Injectable} from '@angular/core';
|
2
|
import {HttpClient} from "@angular/common/http";
|
3
|
import {ResultLandingInfo} from '../../../utils/entities/resultLandingInfo';
|
4
|
import {EnvProperties} from '../../../utils/properties/env-properties';
|
5
|
import {ParsingFunctions} from '../../landing-utils/parsingFunctions.class';
|
6
|
import {map} from "rxjs/operators";
|
7
|
import {HostedByCollectedFrom} from "../../../utils/result-preview/result-preview";
|
8
|
|
9
|
@Injectable()
|
10
|
export class DeletedByInferenceService {
|
11
|
private sizeOfDescription: number = 270;
|
12
|
|
13
|
constructor(private http: HttpClient ) {
|
14
|
this.parsingFunctions = new ParsingFunctions();
|
15
|
}
|
16
|
|
17
|
public parsingFunctions: ParsingFunctions;
|
18
|
|
19
|
getDeletedByInferenceResults (id: string, size: string, properties:EnvProperties):any {
|
20
|
let url = properties.searchAPIURLLAst + 'deletedByInferenceResults/' +id+"?format=json&size="+size;
|
21
|
let key = url;
|
22
|
|
23
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
24
|
//.map(res => <any> res.json())
|
25
|
.pipe(map(res => res['results']))
|
26
|
.pipe(map(res => this.parseDeletedByInferenceResults(res)));
|
27
|
}
|
28
|
|
29
|
parseDeletedByInferenceResults (_results: any): ResultLandingInfo[] {
|
30
|
/*title, authors, abstract, List of projects, PIDs,
|
31
|
collectedfrom (link pointing to the download url), access rights*/
|
32
|
|
33
|
let results: ResultLandingInfo[] = [];
|
34
|
if(_results) {
|
35
|
let result : ResultLandingInfo;
|
36
|
|
37
|
let length = Array.isArray(_results) ? _results.length : 1;
|
38
|
for(let i=0; i<length; i++) {
|
39
|
var _result = Array.isArray(_results) ? _results[i]['result']['metadata']['oaf:entity'] : _results['result']['metadata']['oaf:entity'];
|
40
|
|
41
|
result = new ResultLandingInfo();
|
42
|
|
43
|
if(_result) {
|
44
|
if(_result['oaf:result']) {
|
45
|
let data = _result['oaf:result'];
|
46
|
|
47
|
var date:string = (data.dateofacceptance)+""; // transform to string in case it is an integer
|
48
|
result.date = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
|
49
|
result.dateofacceptance = data.dateofacceptance;
|
50
|
result.embargoEndDate = data.embargoenddate;
|
51
|
|
52
|
if(!Array.isArray(data.description)) {
|
53
|
result.description = data.description;
|
54
|
} else {
|
55
|
result.description = data.description[0];
|
56
|
}
|
57
|
if(result.description && result.description.length > this.sizeOfDescription) {
|
58
|
result.description = result.description.substring(0, this.sizeOfDescription) + "...";
|
59
|
}
|
60
|
|
61
|
if(data['bestaccessright'] && data['bestaccessright'].hasOwnProperty("classname")) {
|
62
|
result.accessMode = data['bestaccessright'].classname;
|
63
|
}
|
64
|
}
|
65
|
|
66
|
if(_result['oaf:result'] && _result['oaf:result']['title']) {
|
67
|
let title = _result['oaf:result']['title'];
|
68
|
|
69
|
if(Array.isArray(title)) {
|
70
|
for(let i=0; i<title.length; i++) {
|
71
|
if(title[i] && title[i].content) {
|
72
|
if(!result.title || title[i].classid == "main title") {
|
73
|
result.title = String(title[i].content);
|
74
|
}
|
75
|
if(title[i].classid == "main title") {
|
76
|
break;
|
77
|
}
|
78
|
}
|
79
|
}
|
80
|
if(!result.title) {
|
81
|
result.title = "";
|
82
|
}
|
83
|
//result.title = title[0].content;
|
84
|
} else {
|
85
|
result.title = String(title.content);
|
86
|
}
|
87
|
}
|
88
|
|
89
|
if(_result['oaf:result'] && _result['oaf:result']['language']) {
|
90
|
result.languages = this.parsingFunctions.parseLanguages(_result['oaf:result']['language']);
|
91
|
}
|
92
|
if(_result['oaf:result'] && _result['oaf:result']['country']) {
|
93
|
result.countries = this.parsingFunctions.parseCountries(_result['oaf:result']['country']);
|
94
|
}
|
95
|
|
96
|
if(_result['oaf:result'] && _result['oaf:result']['children']) {
|
97
|
let children = _result['oaf:result']['children'];
|
98
|
|
99
|
if(children.hasOwnProperty("instance")) {
|
100
|
result.types = new Array<string>();
|
101
|
let types = new Set<string>();
|
102
|
|
103
|
result.hostedBy_collectedFrom = new Array<HostedByCollectedFrom>();
|
104
|
|
105
|
let counter = 0;
|
106
|
let instance;
|
107
|
|
108
|
let length = Array.isArray(children['instance']) ? children['instance'].length : 1;
|
109
|
|
110
|
for(let i=0; i<length; i++) {
|
111
|
instance = Array.isArray(children['instance']) ? children['instance'][i] : children['instance'];
|
112
|
|
113
|
this.parsingFunctions.parseTypes(result.types, types, instance);
|
114
|
|
115
|
if(instance.hasOwnProperty("webresource")) {
|
116
|
let url;
|
117
|
if(!Array.isArray(instance['webresource'])) {
|
118
|
url = instance['webresource'].url;
|
119
|
} else{
|
120
|
url = instance['webresource'][0].url;
|
121
|
}
|
122
|
|
123
|
if(instance.hasOwnProperty("hostedby")) {
|
124
|
counter = this.parsingFunctions.parseHostedBy_collectedFrom(result.hostedBy_collectedFrom, instance, _result['oaf:result'], url, counter, result.accessMode);
|
125
|
}
|
126
|
}
|
127
|
}
|
128
|
}
|
129
|
}
|
130
|
|
131
|
if(_result['oaf:result'] && _result['oaf:result']['pid']) {
|
132
|
result.identifiers = this.parsingFunctions.parseIdentifiers(_result['oaf:result']['pid']);
|
133
|
}
|
134
|
|
135
|
if(_result['oaf:result'] && _result['oaf:result']['creator']) {
|
136
|
if(result.authors == undefined) {
|
137
|
result.authors = new Array<{"fullName": string, "orcid": string, "orcid_pending": string}>();
|
138
|
}
|
139
|
|
140
|
let authors = _result['oaf:result']['creator'];
|
141
|
let length = Array.isArray(authors) ? authors.length : 1;
|
142
|
|
143
|
for(let i=0; i<length; i++) {
|
144
|
let author = Array.isArray(authors) ? authors[i] : authors;
|
145
|
if(author) {
|
146
|
/*if (author.orcid && author.orcid.indexOf(properties.orcidURL) != -1) {
|
147
|
author.orcid = author.orcid.substr(properties.orcidURL.length);
|
148
|
}*/
|
149
|
if(author.orcid) {
|
150
|
author.orcid = author.orcid.toUpperCase();
|
151
|
}
|
152
|
if(author.orcid_pending) {
|
153
|
author.orcid_pending = author.orcid_pending.toUpperCase();
|
154
|
}
|
155
|
result['authors'][author.rank] = {"fullName": author.content, "orcid": author.orcid, "orcid_pending": author.orcid_pending};
|
156
|
}
|
157
|
}
|
158
|
result.authors = result.authors.filter(function (item) {
|
159
|
return (item != undefined && item.fullName != undefined);
|
160
|
});
|
161
|
}
|
162
|
|
163
|
}
|
164
|
results.push(result);
|
165
|
}
|
166
|
}
|
167
|
|
168
|
return results;
|
169
|
}
|
170
|
}
|