import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import {DatasetInfo} from '../../utils/entities/datasetInfo'; import 'rxjs/add/observable/of'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/share'; import{EnvProperties} from '../../utils/properties/env-properties'; import { ParsingFunctions } from '../landing-utils/parsingFunctions.class'; @Injectable() export class DatasetService { constructor(private http: Http ) { this.parsingFunctions = new ParsingFunctions(); } public parsingFunctions: ParsingFunctions; datasetInfo: DatasetInfo; getDatasetInfo (id: string, properties:EnvProperties):any { console.info("getDatasetInfo in service"); let url = properties.searchAPIURLLAst+'datasets/'+id+"?format=json"; let key = url; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) .map(res => res.json()) .do(res => console.info(res['result']['metadata']['oaf:entity'])) .map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity']['oaf:result'],res]) .map(res => [res[1], res[1]['title'], res[1]['rels']['rel'], res[1]['children'], res[1]['pid'], res[1]['subject'], res[1]['bestaccessright'], res[1]['collectedfrom'], res[1]['context'], //res[1]['resulttype'], res[0], res[1]['creator'], res[1]['language'], res[2] ]).map(res => this.parseDatasetInfo(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'); } parseDatasetInfo (data: any):any { this.datasetInfo = new DatasetInfo(); this.datasetInfo.record = data[12]; if(data[0] != null) { var date:string = (data[0].dateofacceptance)+""; // transform to string in case it is an integer this.datasetInfo.date = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date; this.datasetInfo.dateofacceptance = data[0].dateofacceptance; this.datasetInfo.publisher = data[0].publisher; if(!Array.isArray(data[0].description)) { this.datasetInfo.description = data[0].description; } else { this.datasetInfo.description = data[0].description[0]; } this.datasetInfo.embargoEndDate = data[0].embargoenddate; } this.datasetInfo.title = {"name": "", "url": "", "accessMode": ""}; if(data[0]['bestaccessright'] && data[0]['bestaccessright'].hasOwnProperty("classid")) { this.datasetInfo.title.accessMode = data[0]['bestaccessright'].classid; } if(data[1] != null) { if(Array.isArray(data[1])) { this.datasetInfo.title['name'] = data[1][0].content; } else { this.datasetInfo.title['name'] = data[1].content; } } if(data[2] != null) { let relation; let length = data[2].length!=undefined ? data[2].length : 1; for(let i=0; i(); this.datasetInfo.types = new Array(); let types = new Set(); let counter = 0; let instance; let length = data[3]['instance'].length!=undefined ? data[3]['instance'].length : 1; for(let i=0; i, Map] = this.parsingFunctions.parseAllSubjects(data[5]); this.datasetInfo.subjects = subjectResults[0]; this.datasetInfo.otherSubjects = subjectResults[1]; this.datasetInfo.classifiedSubjects = subjectResults[2]; } this.datasetInfo.hostedBy_collectedFrom = this.parsingFunctions.addPublisherToHostedBy_collectedFrom( this.datasetInfo.hostedBy_collectedFrom, this.datasetInfo.publisher, null, this.datasetInfo.identifiers, this.datasetInfo.title); if(data[8] != null) { this.datasetInfo.contexts = this.parsingFunctions.parseContexts(data[8]); } // if(data[9] != null && this.datasetInfo.type == undefined) { // if(data[9].hasOwnProperty('classname')) { // this.datasetInfo.type = data[9].classname; // } // } if(data[9] != null && data[9] == "under curation") { this.datasetInfo.underCurationMessage = true; } else { this.datasetInfo.underCurationMessage = false; } if(data[10] != null) { if(this.datasetInfo.authors == undefined) { this.datasetInfo.authors = new Array(); } let authors = data[10]; let length = Array.isArray(authors) ? authors.length : 1; for(let i=0; i