openaire-library/landingPages/result/deletedByInference/deletedByInference.service.ts

151 lines
6.0 KiB
TypeScript

import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {ResultLandingInfo} from '../../../utils/entities/resultLandingInfo';
import {EnvProperties} from '../../../utils/properties/env-properties';
import {ParsingFunctions} from '../../landing-utils/parsingFunctions.class';
import {map} from "rxjs/operators";
@Injectable()
export class DeletedByInferenceService {
private sizeOfDescription: number = 270;
constructor(private http: HttpClient ) {
this.parsingFunctions = new ParsingFunctions();
}
public parsingFunctions: ParsingFunctions;
getDeletedByInferenceResults (id: string, size: string, properties:EnvProperties):any {
let url = properties.searchAPIURLLAst + 'deletedByInferenceResults/' +id+"?format=json&size="+size;
let key = url;
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
//.map(res => <any> res.json())
.pipe(map(res => res['results']))
.pipe(map(res => this.parseDeletedByInferenceResults(res)));
}
parseDeletedByInferenceResults (_results: any): ResultLandingInfo[] {
/*title, authors, abstract, List of projects, PIDs,
collectedfrom (link pointing to the download url), access rights*/
let results: ResultLandingInfo[] = [];
if(_results) {
let result : ResultLandingInfo;
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'];
result = new ResultLandingInfo();
if(_result) {
if(_result['oaf:result']) {
let data = _result['oaf:result'];
var date:string = (data.dateofacceptance)+""; // transform to string in case it is an integer
result.date = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
result.dateofacceptance = data.dateofacceptance;
result.embargoEndDate = data.embargoenddate;
if(!Array.isArray(data.description)) {
result.description = data.description;
} else {
result.description = data.description[0];
}
if(result.description && result.description.length > this.sizeOfDescription) {
result.description = result.description.substring(0, this.sizeOfDescription) + "...";
}
if(data['bestaccessright'] && data['bestaccessright'].hasOwnProperty("classid")) {
result.accessMode = data['bestaccessright'].classid;
}
}
if(_result['oaf:result'] && _result['oaf:result']['title']) {
let title = _result['oaf:result']['title'];
if(Array.isArray(title)) {
result.title = title[0].content;
} else {
result.title = title.content;
}
}
if(_result['oaf:result'] && _result['oaf:result']['language']) {
result.languages = this.parsingFunctions.parseLanguages(_result['oaf:result']['language']);
}
if(_result['oaf:result'] && _result['oaf:result']['country']) {
result.countries = this.parsingFunctions.parseCountries(_result['oaf:result']['country']);
}
if(_result['oaf:result'] && _result['oaf:result']['children']) {
let children = _result['oaf:result']['children'];
if(children.hasOwnProperty("instance")) {
result.types = new Array<string>();
let types = new Set<string>();
result.hostedBy_collectedFrom = new Array<{"downloadName": string, "downloadUrl": string[], "collectedName": string, "collectedId": string, "accessMode": string[], "bestAccessMode": string, "type": string, "year":string}>();
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'];
this.parsingFunctions.parseTypes(result.types, types, instance);
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")) {
counter = this.parsingFunctions.parseHostedBy_collectedFrom(result.hostedBy_collectedFrom, instance, _result['oaf:result'], url, counter, result.accessMode);
}
}
}
}
}
if(_result['oaf:result'] && _result['oaf:result']['pid']) {
result.identifiers = this.parsingFunctions.parseIdentifiers(_result['oaf:result']['pid']);
}
if(_result['oaf:result'] && _result['oaf:result']['creator']) {
if(result.authors == undefined) {
result.authors = new Array<{"fullName": string, "orcid": string}>();
}
let authors = _result['oaf:result']['creator'];
let length = Array.isArray(authors) ? authors.length : 1;
for(let i=0; i<length; i++) {
let author = Array.isArray(authors) ? authors[i] : authors;
if(author) {
/*if (author.ORCID && author.ORCID.indexOf(properties.orcidURL) != -1) {
author.ORCID = author.ORCID.substr(properties.orcidURL.length);
}*/
result['authors'][author.rank] = {"fullName": author.content, "orcid": author.ORCID};
}
}
result.authors = result.authors.filter(function (item) {
return (item != undefined && item.fullName != undefined);
});
}
}
results.push(result);
}
}
return results;
}
}