import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import {PublicationInfo} from '../../utils/entities/publicationInfo'; import {DeletedByInferenceResult} from '../../utils/entities/deletedByInferenceResult'; import 'rxjs/add/observable/of'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/share'; import 'rxjs/add/operator/map'; import{EnvProperties} from '../../utils/properties/env-properties'; import { ParsingFunctions } from '../landing-utils/parsingFunctions.class'; @Injectable() export class PublicationService { constructor(private http: Http ) { this.parsingFunctions = new ParsingFunctions(); } public parsingFunctions: ParsingFunctions; publicationInfo: PublicationInfo; getPublicationInfo (id: string, properties:EnvProperties):any { let url = properties.searchAPIURLLAst + 'publications/' +id+"?format=json"; let key = url; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity'], res]) .map(res => [ res[1]['oaf:result'], //0 res[1]['oaf:result']['title'], //1 res[1]['oaf:result']['rels']['rel'], //2 res[1]['oaf:result']['children'], //3 res[1]['oaf:result']['pid'], //4 res[1]['oaf:result']['journal'], //5 res[1]['oaf:result']['language'], //6 res[1]['oaf:result']['subject'], //7 res[1]['oaf:result']['bestaccessright'], //8 res[1]['oaf:result']['collectedfrom'], //9 (res[1]['extraInfo']!= undefined && res[1]['extraInfo']['citations']!= undefined)? res[1]['extraInfo']['citations']['citation']:null, //10 res[1]['oaf:result']['context'], //11 res[0], //12 res[1]['oaf:result']['creator'], //13 res[2], //14 res[1]['oaf:result']['country'] //15 ]) .map(res => this.parsePublicationInfo(res, properties)); } private handleError (error: Response) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); return Observable.throw(error || 'Server error'); } parsePublicationInfo (data: any, properties: EnvProperties):any { this.publicationInfo = new PublicationInfo(); this.publicationInfo.record = data[14]; if(data[0] != null) { var date:string = (data[0].dateofacceptance)+""; // transform to string in case it is an integer this.publicationInfo.date = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date; this.publicationInfo.dateofacceptance = data[0].dateofacceptance; this.publicationInfo.publisher = data[0].publisher; if(!Array.isArray(data[0].description)) { this.publicationInfo.description = String(data[0].description); } else { this.publicationInfo.description = String(data[0].description[0]); } this.publicationInfo.embargoEndDate = data[0].embargoenddate; } /* this.publicationInfo.title = {"name": "", "url": "", "accessMode": ""}; if(data[0]['bestaccessright'] && data[0]['bestaccessright'].hasOwnProperty("classid")) { this.publicationInfo.title.accessMode = data[0]['bestaccessright'].classid; } if(data[1] != null) { if(Array.isArray(data[1])) { this.publicationInfo.title['name'] = data[1][0].content; } else { this.publicationInfo.title['name'] = data[1].content; } } */ if(data[0]['bestaccessright'] && data[0]['bestaccessright'].hasOwnProperty("classid")) { this.publicationInfo.accessMode = data[0]['bestaccessright'].classid; } if(data[1] != null) { if(Array.isArray(data[1])) { this.publicationInfo.title = data[1][0].content; } else { this.publicationInfo.title = data[1].content; } } if(data[2] != null) { let relation; let length = Array.isArray(data[2]) ? data[2].length : 1; for(let i=0; i(); //this.publicationInfo.downloadFrom = new Map(); //this.publicationInfo.publishedIn = new Map(); this.publicationInfo.hostedBy_collectedFrom = new Array<{"downloadName": string, "downloadUrl": string[], "collectedName": string, "collectedId": string, "accessMode": string[], "bestAccessMode": string, "type": string, "year":string}>(); this.publicationInfo.types = new Array(); let types = new Set(); let counter = 0; let instance; let length = Array.isArray(data[3]['instance']) ? data[3]['instance'].length : 1; for(let i=0; i>, { "name": string, "url": string}[]] = this.parseBioentitiesAndSoftware(data[3]); this.publicationInfo.bioentities = externalResults[0]; this.publicationInfo.software = externalResults[1]; } } if(data[4] != null) { this.publicationInfo.identifiers = this.parsingFunctions.parseIdentifiers(data[4]); } if(data[5] != null) { this.publicationInfo.journal = {"journal": "", "issn": "", "lissn": "", "eissn": "", "issue": "", "volume": "", "start_page": "", "end_page": ""} this.publicationInfo.journal['journal'] = data[5].content; this.publicationInfo.journal['issn'] = data[5].issn; this.publicationInfo.journal['lissn'] = data[5].lissn; this.publicationInfo.journal['eissn'] = data[5].eissn; this.publicationInfo.journal['issue'] = data[5].iss; this.publicationInfo.journal['volume'] = data[5].vol; this.publicationInfo.journal['start_page'] = data[5].sp; this.publicationInfo.journal['end_page'] = data[5].ep; } if(data[6] != null) { this.publicationInfo.languages = this.parsingFunctions.parseLanguages(data[6]); } if(data[15] != null) { this.publicationInfo.countries = this.parsingFunctions.parseCountries(data[15]); } if(data[7] != null) { let subjectResults: [string[], Map, Map] = this.parsingFunctions.parseAllSubjects(data[7]); this.publicationInfo.subjects = subjectResults[0]; this.publicationInfo.otherSubjects = subjectResults[1]; this.publicationInfo.classifiedSubjects = subjectResults[2]; } // if(data[8] != null) { // this.publicationInfo.bestaccessright = data[8].classid; // } // if(data[9] != null) { // this.publicationInfo.collectedFrom = this.parsingFunctions.parseCollectedFrom(data[9]); // } this.publicationInfo.hostedBy_collectedFrom = this.parsingFunctions.addPublisherToHostedBy_collectedFrom( this.publicationInfo.hostedBy_collectedFrom, this.publicationInfo.publisher, this.publicationInfo.journal, this.publicationInfo.identifiers/*, this.publicationInfo.title*/); if(data[10] != null) { this.publicationInfo.references = this.parsingFunctions.parseReferences(data[10]); } if(data[11] != null) { this.publicationInfo.contexts = this.parsingFunctions.parseContexts(data[11]); } if(data[12] != null && data[12] == "under curation") { this.publicationInfo.underCurationMessage = true; } else { this.publicationInfo.underCurationMessage = false; } if(data[13] != null) { if(this.publicationInfo.authors == undefined) { this.publicationInfo.authors = new Array<{"fullName": string, "orcid": string}>(); } let authors = data[13]; let length = Array.isArray(authors) ? authors.length : 1; for(let i=0; i(); } let organization: { "name": string, "shortname": string, "id": string, "websiteUrl": string, "country": string, "trust": number } = { "name": "", "shortname": "", "id": "", "websiteUrl": "", "country": "", "trust": null }; organization.id = relation['to'].content; organization.name = relation.legalname; organization.shortname = relation.legalshortname; organization.websiteUrl = relation.websiteurl; if(relation.country) { organization.country = relation.country.classname; } if(relation.trust) { organization.trust = Math.round(relation.trust*100); } organizations.push(organization); return organizations; } parseBioentitiesAndSoftware(children: any) : [Map>, { "name": string, "url": string}[]] { let bioentities: Map>; let software: {"name": string, "url": string}[]; let length = Array.isArray(children['externalreference']) ? children['externalreference'].length : 1; let externalreference; for(let i=0; i>(); } if(!bioentities.has(externalreference.sitename)) { bioentities.set(externalreference.sitename, new Map()); } bioentities.get(externalreference.sitename).set(externalreference.refidentifier, externalreference.url); } else if(externalreference['qualifier'].classid == "software") { if(software == undefined) { software = new Array<{"name": string, "url": string}>(); } software.push({"name": externalreference.sitename, "url": externalreference.url}); } } } return [bioentities, software]; } /* parseReferences(citations: any): {"name": string, "url": string}[] { let references = new Array<{"name": string, "url": string}>(); let citation; let length = Array.isArray(citations) ? citations.length : 1; for(let i=0; i(); let openCitation; let length = Array.isArray(openCitations) ? openCitations.length : 1; for(let i=0; i