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"; import {HostedByCollectedFrom} from "../../../utils/result-preview/result-preview"; @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 => 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 this.sizeOfDescription) { result.description = result.description.substring(0, this.sizeOfDescription) + "..."; } if(data['bestaccessright'] && data['bestaccessright'].hasOwnProperty("classname")) { result.accessMode = data['bestaccessright'].classname; } } 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(); let types = new Set(); result.hostedBy_collectedFrom = new Array(); let counter = 0; let instance; let length = Array.isArray(children['instance']) ? children['instance'].length : 1; for(let i=0; i(); } let authors = _result['oaf:result']['creator']; let length = Array.isArray(authors) ? authors.length : 1; for(let i=0; i