explore-services/portal-2/src/app/services/dataProvider.service.ts

165 lines
8.7 KiB
TypeScript

import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {DataProviderInfo} from '../utils/entities/dataProviderInfo';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
@Injectable()
export class DataProviderService {
constructor(private http: Http) {}
dataProviderInfo: DataProviderInfo;
getPublicationInfo (id: string):any {
console.info("getDataProviderInfo in service");
let url = OpenaireProperties.getSearchAPIURL() + 'datasources/' +id;
return this.http.get(url)
.map(res => <any> res.json())
.do(res => console.info(res['result']['metadata']['oaf:entity']['oaf:datasource']))
.map(res => res['result']['metadata']['oaf:entity'])
.map(res => [res['oaf:datasource'],
res['oaf:datasource']['datasourcetype'],
res['oaf:datasource']['openairecompatibility'],
res['oaf:datasource']['accessinfopackage'],
res['oaf:datasource']['rels']['rel']
])
.map(res => this.parseDataProviderInfo(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.error(error);
return Observable.throw(error || 'Server error');
}
parseDataProviderInfo (data: any):any {
this.dataProviderInfo = new DataProviderInfo();
if(data[0] != null) {
this.dataProviderInfo.title = {"name": data[0].officialname, "url": data[0].websiteurl};
}
if(data[1] != null) {
this.dataProviderInfo.type = data[1].classname;
if(this.dataProviderInfo.tabs == undefined) {
this.dataProviderInfo.tabs = new Array<{"name": string, "content": string}>();
}
console.info(data[1].classid);
if(this.dataProviderInfo.tabsInTypes.publicationsTab.has(data[1].classid)) {
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
}
if(this.dataProviderInfo.tabsInTypes.datasetsTab.has(data[1].classid)) {
this.dataProviderInfo.tabs.push({"name": "Datasets", "content": "datasetsTab"});
}
if(this.dataProviderInfo.tabsInTypes.statisticsTab.has(data[1].classid)) {
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
}
if(this.dataProviderInfo.tabsInTypes.projectsTab.has(data[1].classid)) {
this.dataProviderInfo.tabs.push({"name": "Projects", "content": "projectsTab"});
}
if(this.dataProviderInfo.tabsInTypes.datasourcesTab.has(data[1].classid)) {
this.dataProviderInfo.tabs.push({"name": "Datasources", "content": "datasourcesTab"});
}
/*
if(this.dataProviderInfo.type == 'Aggregator of Data Repositories') {
this.dataProviderInfo.tabs.push({"name": "Datasets", "content": "datasetsTab"});
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
} else if(this.dataProviderInfo.type == 'Aggregator of Institutional Publication Repositories') {
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
} else if(this.dataProviderInfo.type == 'Aggregator of Publication Repositories') {
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
} else if(this.dataProviderInfo.type == 'Aggregator/Publisher of Journals') {
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
} else if(this.dataProviderInfo.type == 'CRIS System') {
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
this.dataProviderInfo.tabs.push({"name": "Datasets", "content": "datasetsTab"});
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
} else if(this.dataProviderInfo.type == 'Data Repository') {
this.dataProviderInfo.tabs.push({"name": "Datasets", "content": "datasetsTab"});
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
} else if(this.dataProviderInfo.type == 'Registry of Data Providers') {
this.dataProviderInfo.tabs.push({"name": "Datasources", "content": "datasourcesTab"});
} else if(this.dataProviderInfo.type == 'Registry of Projects') {
this.dataProviderInfo.tabs.push({"name": "Projects", "content": "projectsTab"});
} else if(this.dataProviderInfo.type == 'Information Space') {
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
} else if(this.dataProviderInfo.type == 'Institutional Publication Repository') {
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
} else if(this.dataProviderInfo.type == 'Journal Platform') {
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
} else if(this.dataProviderInfo.type == 'Mock Publication Repository') {
} else if(this.dataProviderInfo.type == 'Other Source') {
//openaire____::fb98a192f6a055ba495ef414c330834b
} else if(this.dataProviderInfo.type == 'Publication Repository') {
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
} else if(this.dataProviderInfo.type == 'Scholarly Communication Infrastructure') {
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
} else if(this.dataProviderInfo.type == 'Thematic Publication Repository') {
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
} else if(this.dataProviderInfo.type == 'Publication Catalogue') {
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
}
*/
}
if(data[2] != null) {
this.dataProviderInfo.compatibility = data[2].classname;
}
if(data[3] != null) {
if(Array.isArray(data[3])) {
this.dataProviderInfo.oaiPmhURL = data[3][0];
} else {
this.dataProviderInfo.oaiPmhURL = data[3];
}
}
if(data[4] != null) {
let mydata;
let counter = 0;
let length = data[4].length!=undefined ? data[4].length : 1;
for(let i=0; i<length; i++) {
mydata = length > 1 ? data[4][i] : data[4];
if(mydata.hasOwnProperty("to")) {
if(mydata['to'].class == "provides" && mydata['to'].type == "organization") {
if(this.dataProviderInfo.organizations == undefined) {
this.dataProviderInfo.organizations = new Array<{"name": string, "url": string}>();
}
this.dataProviderInfo.organizations[counter] = {"name": "", "url": ""};
this.dataProviderInfo.organizations[counter]['name'] = mydata.legalname;
this.dataProviderInfo.organizations[counter]['url'] = mydata.websiteUrl;
counter++;
}
}
}
}
//this.printPublicationInfo();
return this.dataProviderInfo;
}
printDataProviderInfo() {
}
}