2019-03-05 10:45:42 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {HttpClient} from "@angular/common/http";
|
2019-09-30 13:02:06 +02:00
|
|
|
import {ResultLandingInfo} from '../../../utils/entities/resultLandingInfo';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {EnvProperties} from '../../../utils/properties/env-properties';
|
2019-09-30 13:02:06 +02:00
|
|
|
import {ParsingFunctions} from '../../landing-utils/parsingFunctions.class';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {map} from "rxjs/operators";
|
2020-07-01 14:11:57 +02:00
|
|
|
import {HostedByCollectedFrom} from "../../../utils/result-preview/result-preview";
|
2019-03-05 10:45:42 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class DeletedByInferenceService {
|
|
|
|
private sizeOfDescription: number = 270;
|
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
constructor(private http: HttpClient ) {
|
2019-03-05 10:45:42 +01:00
|
|
|
this.parsingFunctions = new ParsingFunctions();
|
|
|
|
}
|
|
|
|
|
|
|
|
public parsingFunctions: ParsingFunctions;
|
|
|
|
|
2019-07-17 21:48:19 +02:00
|
|
|
getDeletedByInferenceResults (id: string, size: string, properties:EnvProperties):any {
|
|
|
|
let url = properties.searchAPIURLLAst + 'deletedByInferenceResults/' +id+"?format=json&size="+size;
|
2019-03-05 10:45:42 +01:00
|
|
|
let key = url;
|
|
|
|
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => <any> res.json())
|
2019-07-17 21:48:19 +02:00
|
|
|
.pipe(map(res => res['results']))
|
2019-10-10 13:59:50 +02:00
|
|
|
.pipe(map(res => this.parseDeletedByInferenceResults(res)));
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
|
|
|
|
2019-10-10 13:59:50 +02:00
|
|
|
parseDeletedByInferenceResults (_results: any): ResultLandingInfo[] {
|
2019-03-05 10:45:42 +01:00
|
|
|
/*title, authors, abstract, List of projects, PIDs,
|
|
|
|
collectedfrom (link pointing to the download url), access rights*/
|
|
|
|
|
2019-09-30 13:02:06 +02:00
|
|
|
let results: ResultLandingInfo[] = [];
|
2019-07-17 21:48:19 +02:00
|
|
|
if(_results) {
|
2019-09-30 13:02:06 +02:00
|
|
|
let result : ResultLandingInfo;
|
2019-03-05 10:45:42 +01:00
|
|
|
|
2019-07-17 21:48:19 +02:00
|
|
|
let length = Array.isArray(_results) ? _results.length : 1;
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
var _result = Array.isArray(_results) ? _results[i]['result']['metadata']['oaf:entity'] : _results['result']['metadata']['oaf:entity'];
|
2019-03-05 10:45:42 +01:00
|
|
|
|
2019-09-30 13:02:06 +02:00
|
|
|
result = new ResultLandingInfo();
|
2019-03-05 10:45:42 +01:00
|
|
|
|
2019-07-17 21:48:19 +02:00
|
|
|
if(_result) {
|
|
|
|
if(_result['oaf:result']) {
|
|
|
|
let data = _result['oaf:result'];
|
2019-03-05 10:45:42 +01:00
|
|
|
|
|
|
|
var date:string = (data.dateofacceptance)+""; // transform to string in case it is an integer
|
2019-07-17 21:48:19 +02:00
|
|
|
result.date = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
|
|
|
|
result.dateofacceptance = data.dateofacceptance;
|
|
|
|
result.embargoEndDate = data.embargoenddate;
|
2019-03-05 10:45:42 +01:00
|
|
|
|
2022-11-28 13:37:37 +01:00
|
|
|
result.description = this.parsingFunctions.parseDescription(data.description, true);
|
2019-03-05 10:45:42 +01:00
|
|
|
|
2020-02-07 14:05:07 +01:00
|
|
|
if(data['bestaccessright'] && data['bestaccessright'].hasOwnProperty("classname")) {
|
|
|
|
result.accessMode = data['bestaccessright'].classname;
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-17 21:48:19 +02:00
|
|
|
if(_result['oaf:result'] && _result['oaf:result']['title']) {
|
|
|
|
let title = _result['oaf:result']['title'];
|
2019-03-05 10:45:42 +01:00
|
|
|
|
|
|
|
if(Array.isArray(title)) {
|
2021-02-20 10:20:05 +01:00
|
|
|
for(let i=0; i<title.length; i++) {
|
|
|
|
if(title[i] && title[i].content) {
|
|
|
|
if(!result.title || title[i].classid == "main title") {
|
|
|
|
result.title = String(title[i].content);
|
|
|
|
}
|
|
|
|
if(title[i].classid == "main title") {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!result.title) {
|
|
|
|
result.title = "";
|
|
|
|
}
|
|
|
|
//result.title = title[0].content;
|
2019-03-05 10:45:42 +01:00
|
|
|
} else {
|
2021-02-20 10:20:05 +01:00
|
|
|
result.title = String(title.content);
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-17 21:48:19 +02:00
|
|
|
if(_result['oaf:result'] && _result['oaf:result']['language']) {
|
|
|
|
result.languages = this.parsingFunctions.parseLanguages(_result['oaf:result']['language']);
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
2019-07-17 21:48:19 +02:00
|
|
|
if(_result['oaf:result'] && _result['oaf:result']['country']) {
|
|
|
|
result.countries = this.parsingFunctions.parseCountries(_result['oaf:result']['country']);
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
|
|
|
|
2019-07-17 21:48:19 +02:00
|
|
|
if(_result['oaf:result'] && _result['oaf:result']['children']) {
|
|
|
|
let children = _result['oaf:result']['children'];
|
2019-03-05 10:45:42 +01:00
|
|
|
|
|
|
|
if(children.hasOwnProperty("instance")) {
|
2019-07-17 21:48:19 +02:00
|
|
|
result.types = new Array<string>();
|
2019-03-05 10:45:42 +01:00
|
|
|
let types = new Set<string>();
|
|
|
|
|
2020-07-01 14:11:57 +02:00
|
|
|
result.hostedBy_collectedFrom = new Array<HostedByCollectedFrom>();
|
2019-03-05 10:45:42 +01:00
|
|
|
|
|
|
|
let counter = 0;
|
|
|
|
let instance;
|
|
|
|
|
|
|
|
let length = Array.isArray(children['instance']) ? children['instance'].length : 1;
|
|
|
|
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
instance = Array.isArray(children['instance']) ? children['instance'][i] : children['instance'];
|
|
|
|
|
2019-07-17 21:48:19 +02:00
|
|
|
this.parsingFunctions.parseTypes(result.types, types, instance);
|
2019-03-05 10:45:42 +01:00
|
|
|
|
|
|
|
if(instance.hasOwnProperty("webresource")) {
|
|
|
|
let url;
|
|
|
|
if(!Array.isArray(instance['webresource'])) {
|
|
|
|
url = instance['webresource'].url;
|
|
|
|
} else{
|
|
|
|
url = instance['webresource'][0].url;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(instance.hasOwnProperty("hostedby")) {
|
2022-01-07 11:01:22 +01:00
|
|
|
this.parsingFunctions.parseHostedBy_collectedFrom(result.hostedBy_collectedFrom, instance, url, result.accessMode);
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-17 22:15:47 +02:00
|
|
|
if(_result['oaf:result'] && _result['oaf:result']['pid']) {
|
2019-07-17 21:48:19 +02:00
|
|
|
result.identifiers = this.parsingFunctions.parseIdentifiers(_result['oaf:result']['pid']);
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
|
|
|
|
2019-07-17 21:48:19 +02:00
|
|
|
if(_result['oaf:result'] && _result['oaf:result']['creator']) {
|
|
|
|
if(result.authors == undefined) {
|
2021-02-20 10:20:05 +01:00
|
|
|
result.authors = new Array<{"fullName": string, "orcid": string, "orcid_pending": string}>();
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
|
|
|
|
2019-07-17 21:48:19 +02:00
|
|
|
let authors = _result['oaf:result']['creator'];
|
2019-03-05 10:45:42 +01:00
|
|
|
let length = Array.isArray(authors) ? authors.length : 1;
|
|
|
|
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
let author = Array.isArray(authors) ? authors[i] : authors;
|
2019-05-29 14:24:43 +02:00
|
|
|
if(author) {
|
2020-09-08 14:51:43 +02:00
|
|
|
/*if (author.orcid && author.orcid.indexOf(properties.orcidURL) != -1) {
|
|
|
|
author.orcid = author.orcid.substr(properties.orcidURL.length);
|
2019-05-29 15:25:51 +02:00
|
|
|
}*/
|
2021-03-11 13:16:13 +01:00
|
|
|
if(author.orcid) {
|
|
|
|
author.orcid = author.orcid.toUpperCase();
|
|
|
|
}
|
|
|
|
if(author.orcid_pending) {
|
|
|
|
author.orcid_pending = author.orcid_pending.toUpperCase();
|
|
|
|
}
|
2024-04-15 16:11:38 +02:00
|
|
|
if(result['authors'][author.rank] && result['authors'][author.rank].fullName == author.content) {
|
2024-01-24 16:03:15 +01:00
|
|
|
if(!author.orcid && result['authors'][author.rank].orcid) {
|
|
|
|
author.orcid = result['authors'][author.rank].orcid;
|
|
|
|
} else if(!author.orcid_pending && result['authors'][author.rank].orcid_pending) {
|
|
|
|
author.orcid_pending = result['authors'][author.rank].orcid_pending;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-20 10:20:05 +01:00
|
|
|
result['authors'][author.rank] = {"fullName": author.content, "orcid": author.orcid, "orcid_pending": author.orcid_pending};
|
2019-05-29 14:24:43 +02:00
|
|
|
}
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
2019-07-17 21:48:19 +02:00
|
|
|
result.authors = result.authors.filter(function (item) {
|
2019-05-29 14:24:43 +02:00
|
|
|
return (item != undefined && item.fullName != undefined);
|
2019-03-05 10:45:42 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-17 21:48:19 +02:00
|
|
|
}
|
|
|
|
results.push(result);
|
|
|
|
}
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
|
|
|
|
2019-07-17 21:48:19 +02:00
|
|
|
return results;
|
2019-03-05 10:45:42 +01:00
|
|
|
}
|
|
|
|
}
|