1
|
import {Injectable} from '@angular/core';
|
2
|
import {HttpClient} from "@angular/common/http";
|
3
|
import {DeletedByInferenceResult} from '../../../utils/entities/deletedByInferenceResult';
|
4
|
import {EnvProperties} from '../../../utils/properties/env-properties';
|
5
|
import {ParsingFunctions} from '../parsingFunctions.class';
|
6
|
import {map} from "rxjs/operators";
|
7
|
|
8
|
@Injectable()
|
9
|
export class DeletedByInferenceService {
|
10
|
private sizeOfDescription: number = 270;
|
11
|
|
12
|
constructor(private http: HttpClient ) {
|
13
|
this.parsingFunctions = new ParsingFunctions();
|
14
|
}
|
15
|
|
16
|
public parsingFunctions: ParsingFunctions;
|
17
|
|
18
|
getDeletedByInferencePublications (id: string, properties:EnvProperties):any {
|
19
|
let url = properties.searchAPIURLLAst + 'deletedByInferencePublications/' +id+"?format=json";
|
20
|
let key = url;
|
21
|
|
22
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
23
|
//.map(res => <any> res.json())
|
24
|
.pipe(map(res => res['result']['metadata']['oaf:entity']))
|
25
|
.pipe(map(res => this.parseDeletedByInferencePublications(res, properties)));
|
26
|
}
|
27
|
|
28
|
parseDeletedByInferencePublications (result: any, properties: EnvProperties): DeletedByInferenceResult {
|
29
|
/*title, authors, abstract, List of projects, PIDs,
|
30
|
collectedfrom (link pointing to the download url), access rights*/
|
31
|
|
32
|
//let publications: DeletedByInferenceResult[] = [];
|
33
|
//if(results) {
|
34
|
let publication : DeletedByInferenceResult;
|
35
|
|
36
|
//let length = Array.isArray(results) ? results.length : 1;
|
37
|
//for(let i=0; i<length; i++) {
|
38
|
//var result = Array.isArray(results) ? results[i] : results;
|
39
|
|
40
|
publication = new DeletedByInferenceResult();
|
41
|
|
42
|
if(result) {
|
43
|
if(result['oaf:result']) {
|
44
|
let data = result['oaf:result'];
|
45
|
|
46
|
var date:string = (data.dateofacceptance)+""; // transform to string in case it is an integer
|
47
|
publication.date = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
|
48
|
publication.dateofacceptance = data.dateofacceptance;
|
49
|
publication.embargoEndDate = data.embargoenddate;
|
50
|
|
51
|
if(!Array.isArray(data.description)) {
|
52
|
publication.description = data.description;
|
53
|
} else {
|
54
|
publication.description = data.description[0];
|
55
|
}
|
56
|
if(publication.description && publication.description.length > this.sizeOfDescription) {
|
57
|
publication.description = publication.description.substring(0, this.sizeOfDescription) + "...";
|
58
|
}
|
59
|
|
60
|
if(data['bestaccessright'] && data['bestaccessright'].hasOwnProperty("classid")) {
|
61
|
publication.accessMode = data['bestaccessright'].classid;
|
62
|
}
|
63
|
}
|
64
|
|
65
|
if(result['oaf:result'] && result['oaf:result']['title']) {
|
66
|
let title = result['oaf:result']['title'];
|
67
|
|
68
|
if(Array.isArray(title)) {
|
69
|
publication.title = title[0].content;
|
70
|
} else {
|
71
|
publication.title = title.content;
|
72
|
}
|
73
|
}
|
74
|
|
75
|
if(result['oaf:result'] && result['oaf:result']['language']) {
|
76
|
publication.languages = this.parsingFunctions.parseLanguages(result['oaf:result']['language']);
|
77
|
}
|
78
|
if(result['oaf:result'] && result['oaf:result']['country']) {
|
79
|
publication.countries = this.parsingFunctions.parseCountries(result['oaf:result']['country']);
|
80
|
}
|
81
|
|
82
|
if(result['oaf:result'] && result['oaf:result']['rels'] && result['oaf:result']['rels']['rel']) {
|
83
|
let relation;
|
84
|
let length = Array.isArray(result['oaf:result']['rels']['rel']) ? result['oaf:result']['rels']['rel'].length : 1;
|
85
|
|
86
|
for(let i=0; i<length; i++) {
|
87
|
relation = Array.isArray(result['oaf:result']['rels']['rel']) ? result['oaf:result']['rels']['rel'][i] : result['oaf:result']['rels']['rel'];
|
88
|
if(relation.hasOwnProperty("to")) {
|
89
|
if(relation['to'].class == "isProducedBy") {
|
90
|
publication.fundedByProjects = this.parsingFunctions.parseFundingByProjects(publication.fundedByProjects, relation, publication.projectsProvenanceVocabulary);
|
91
|
}
|
92
|
}
|
93
|
}
|
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
|
publication.types = new Array<string>();
|
101
|
let types = new Set<string>();
|
102
|
|
103
|
publication.hostedBy_collectedFrom = new Array<{"downloadName": string, "downloadUrl": string[], "collectedName": string, "collectedId": string, "accessMode": string[], "bestAccessMode": string, "type": string, "year":string}>();
|
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(publication.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(publication.hostedBy_collectedFrom, instance, result['oaf:result'], url, counter, publication.accessMode);
|
125
|
}
|
126
|
}
|
127
|
}
|
128
|
}
|
129
|
}
|
130
|
|
131
|
if(result['oaf:result'] && result['oaf:result']['pid']) {
|
132
|
publication.identifiers = this.parsingFunctions.parseIdentifiers(result['oaf:result']['pid']);
|
133
|
}
|
134
|
|
135
|
if(result['oaf:result'] && result['oaf:result']['creator']) {
|
136
|
if(publication.authors == undefined) {
|
137
|
publication.authors = new Array<{"fullName": string, "orcid": 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
|
publication['authors'][author.rank] = {"fullName": author.content, "orcid": author.ORCID};
|
150
|
}
|
151
|
}
|
152
|
publication.authors = publication.authors.filter(function (item) {
|
153
|
return (item != undefined && item.fullName != undefined);
|
154
|
});
|
155
|
}
|
156
|
|
157
|
//}
|
158
|
//publications.push(publication);
|
159
|
//}
|
160
|
}
|
161
|
|
162
|
return publication;
|
163
|
}
|
164
|
}
|