import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import {PublicationInfo} from '../../utils/entities/publicationInfo'; 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 { console.info("getPublicationInfo in service"); 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']]) .map(res => [ res[1]['oaf:result'], res[1]['oaf:result']['title'], res[1]['oaf:result']['rels']['rel'], res[1]['oaf:result']['children'], res[1]['oaf:result']['pid'], res[1]['oaf:result']['journal'], res[1]['oaf:result']['language'], res[1]['oaf:result']['subject'], res[1]['oaf:result']['bestaccessright'], res[1]['oaf:result']['collectedfrom'], (res[1]['extraInfo']!= undefined && res[1]['extraInfo']['citations']!= undefined)? res[1]['extraInfo']['citations']['citation']:null, res[1]['oaf:result']['context'], res[0], res[1]['oaf:result']['creator'] ]) .map(res => this.parsePublicationInfo(res)); } 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):any { this.publicationInfo = new PublicationInfo(); 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 = data[0].description; } else { this.publicationInfo.description = 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[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": ""} this.publicationInfo.journal['journal'] = data[5].content; this.publicationInfo.journal['issn'] = data[5].issn; this.publicationInfo.journal['lissn'] = data[5].lissn; } if(data[6] != null) { this.publicationInfo.languages = this.parsingFunctions.parseLanguages(data[6]); } 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.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(); } 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