1 |
43785
|
argiro.kok
|
import {Injectable} from '@angular/core';
|
2 |
|
|
import {Http, Response} from '@angular/http';
|
3 |
|
|
import {Observable} from 'rxjs/Observable';
|
4 |
|
|
import {DataProviderInfo} from '../utils/entities/dataProviderInfo';
|
5 |
|
|
import {OpenaireProperties} from '../utils/properties/openaireProperties';
|
6 |
44638
|
argiro.kok
|
import 'rxjs/add/observable/of';
|
7 |
|
|
import 'rxjs/add/operator/do';
|
8 |
|
|
import 'rxjs/add/operator/share';
|
9 |
|
|
import { CacheService } from '../shared/cache.service';
|
10 |
43785
|
argiro.kok
|
|
11 |
|
|
@Injectable()
|
12 |
|
|
export class DataProviderService {
|
13 |
|
|
|
14 |
44638
|
argiro.kok
|
constructor(private http: Http, public _cache: CacheService) {}
|
15 |
43785
|
argiro.kok
|
|
16 |
|
|
dataProviderInfo: DataProviderInfo;
|
17 |
|
|
|
18 |
44882
|
konstantin
|
getDataproviderInfo (id: string):any {
|
19 |
43785
|
argiro.kok
|
console.info("getDataProviderInfo in service");
|
20 |
44766
|
argiro.kok
|
let url = OpenaireProperties.getSearchAPIURLLast() + 'datasources/' +id +"?format=json";
|
21 |
44638
|
argiro.kok
|
let key = url;
|
22 |
|
|
if (this._cache.has(key)) {
|
23 |
44907
|
argiro.kok
|
return Observable.of(this._cache.get(key)).map(res => this.parseDataProviderInfo(res));
|
24 |
44638
|
argiro.kok
|
}
|
25 |
43785
|
argiro.kok
|
return this.http.get(url)
|
26 |
|
|
.map(res => <any> res.json())
|
27 |
|
|
.map(res => res['result']['metadata']['oaf:entity'])
|
28 |
|
|
.map(res => [res['oaf:datasource'],
|
29 |
|
|
res['oaf:datasource']['datasourcetype'],
|
30 |
|
|
res['oaf:datasource']['openairecompatibility'],
|
31 |
|
|
res['oaf:datasource']['accessinfopackage'],
|
32 |
|
|
res['oaf:datasource']['rels']['rel']
|
33 |
44907
|
argiro.kok
|
]).do(res => {
|
34 |
|
|
this._cache.set(key, res);
|
35 |
|
|
})
|
36 |
|
|
.map(res => this.parseDataProviderInfo(res));
|
37 |
43785
|
argiro.kok
|
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
private handleError (error: Response) {
|
41 |
|
|
// in a real world app, we may send the error to some remote logging infrastructure
|
42 |
|
|
// instead of just logging it to the console
|
43 |
44907
|
argiro.kok
|
console.log(error);
|
44 |
43785
|
argiro.kok
|
return Observable.throw(error || 'Server error');
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
parseDataProviderInfo (data: any):any {
|
48 |
|
|
this.dataProviderInfo = new DataProviderInfo();
|
49 |
|
|
|
50 |
|
|
if(data[0] != null) {
|
51 |
|
|
this.dataProviderInfo.title = {"name": data[0].officialname, "url": data[0].websiteurl};
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
if(data[1] != null) {
|
55 |
|
|
this.dataProviderInfo.type = data[1].classname;
|
56 |
|
|
|
57 |
44796
|
konstantin
|
if(data[1].classid == "entityregistry" || data[1].classid == "entityregistry::projects" || data[1].classid == "entityregistry::repositories") {
|
58 |
|
|
this.dataProviderInfo.registry = true;
|
59 |
|
|
console.info("true");
|
60 |
|
|
} else {
|
61 |
|
|
this.dataProviderInfo.registry = false;
|
62 |
|
|
console.info("false");
|
63 |
|
|
}
|
64 |
|
|
console.info(this.dataProviderInfo.type);
|
65 |
|
|
|
66 |
43785
|
argiro.kok
|
if(this.dataProviderInfo.tabs == undefined) {
|
67 |
|
|
this.dataProviderInfo.tabs = new Array<{"name": string, "content": string}>();
|
68 |
|
|
}
|
69 |
|
|
if(this.dataProviderInfo.tabsInTypes.publicationsTab.has(data[1].classid)) {
|
70 |
|
|
this.dataProviderInfo.tabs.push({"name": "Publications", "content": "publicationsTab"});
|
71 |
|
|
}
|
72 |
|
|
if(this.dataProviderInfo.tabsInTypes.datasetsTab.has(data[1].classid)) {
|
73 |
|
|
this.dataProviderInfo.tabs.push({"name": "Datasets", "content": "datasetsTab"});
|
74 |
|
|
}
|
75 |
45402
|
konstantin
|
|
76 |
43785
|
argiro.kok
|
if(this.dataProviderInfo.tabsInTypes.projectsTab.has(data[1].classid)) {
|
77 |
|
|
this.dataProviderInfo.tabs.push({"name": "Projects", "content": "projectsTab"});
|
78 |
|
|
}
|
79 |
|
|
if(this.dataProviderInfo.tabsInTypes.datasourcesTab.has(data[1].classid)) {
|
80 |
|
|
this.dataProviderInfo.tabs.push({"name": "Datasources", "content": "datasourcesTab"});
|
81 |
|
|
}
|
82 |
44796
|
konstantin
|
this.dataProviderInfo.tabs.push({"name": "Organizations", "content": "organizationsTab"});
|
83 |
44382
|
konstantin
|
|
84 |
44882
|
konstantin
|
if(this.dataProviderInfo.tabsInTypes.relatedDatasourcesTab.has(data[1].classid)) {
|
85 |
|
|
this.dataProviderInfo.tabs.push({"name": "Related Data Providers", "content": "relatedDatasourcesTab"});
|
86 |
|
|
}
|
87 |
|
|
|
88 |
45402
|
konstantin
|
if(this.dataProviderInfo.tabsInTypes.statisticsTab.has(data[1].classid)) {
|
89 |
|
|
this.dataProviderInfo.tabs.push({"name": "Statistics", "content": "statisticsTab"});
|
90 |
|
|
}
|
91 |
|
|
|
92 |
44882
|
konstantin
|
this.dataProviderInfo.tabs.push({"name": "Metrics", "content": "metricsTab"});
|
93 |
|
|
|
94 |
44382
|
konstantin
|
if(this.dataProviderInfo.resultTypes.collectedFrom.has(data[1].classid)) {
|
95 |
|
|
this.dataProviderInfo.resultsBy = "collectedFrom";
|
96 |
|
|
} else if(this.dataProviderInfo.resultTypes.hostedBy.has(data[1].classid)) {
|
97 |
|
|
this.dataProviderInfo.resultsBy = "hostedBy";
|
98 |
|
|
}
|
99 |
43785
|
argiro.kok
|
}
|
100 |
|
|
|
101 |
44796
|
konstantin
|
if(!this.dataProviderInfo.registry) {
|
102 |
|
|
if(data[2] != null) {
|
103 |
|
|
this.dataProviderInfo.compatibility = data[2].classname;
|
104 |
43785
|
argiro.kok
|
}
|
105 |
44641
|
konstantin
|
|
106 |
44796
|
konstantin
|
if(data[3] != null) {
|
107 |
|
|
let oaiPmhURL: string;
|
108 |
|
|
if(Array.isArray(data[3])) {
|
109 |
|
|
oaiPmhURL = data[3][0];
|
110 |
|
|
}
|
111 |
|
|
else {
|
112 |
|
|
oaiPmhURL = data[3];
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
if(oaiPmhURL != '' && oaiPmhURL != 'unknown') {
|
116 |
|
|
this.dataProviderInfo.oaiPmhURL = oaiPmhURL;
|
117 |
|
|
}
|
118 |
44641
|
konstantin
|
}
|
119 |
43785
|
argiro.kok
|
}
|
120 |
|
|
|
121 |
|
|
if(data[4] != null) {
|
122 |
|
|
let mydata;
|
123 |
|
|
let counter = 0;
|
124 |
44583
|
konstantin
|
let countriesSet: Set<string>;
|
125 |
43785
|
argiro.kok
|
let length = data[4].length!=undefined ? data[4].length : 1;
|
126 |
|
|
|
127 |
|
|
for(let i=0; i<length; i++) {
|
128 |
44907
|
argiro.kok
|
mydata = data[4].length!=undefined ? data[4][i] : data[4];
|
129 |
43785
|
argiro.kok
|
if(mydata.hasOwnProperty("to")) {
|
130 |
|
|
if(mydata['to'].class == "provides" && mydata['to'].type == "organization") {
|
131 |
44796
|
konstantin
|
//if(this.dataProviderInfo.organizations == undefined) {
|
132 |
|
|
if(this.dataProviderInfo.organizations.length == 0) {
|
133 |
|
|
//this.dataProviderInfo.organizations = new Array<{"name": string, "url": string}>();
|
134 |
44583
|
konstantin
|
this.dataProviderInfo.countries = new Array<string>();
|
135 |
|
|
countriesSet = new Set<string>();
|
136 |
43785
|
argiro.kok
|
}
|
137 |
|
|
|
138 |
|
|
this.dataProviderInfo.organizations[counter] = {"name": "", "url": ""};
|
139 |
|
|
this.dataProviderInfo.organizations[counter]['name'] = mydata.legalname;
|
140 |
43956
|
konstantin
|
this.dataProviderInfo.organizations[counter]['url'] = OpenaireProperties.getsearchLinkToOrganization()+mydata['to'].content;
|
141 |
43785
|
argiro.kok
|
|
142 |
44583
|
konstantin
|
if(mydata.country != '' && mydata['country'].classname != '') {
|
143 |
|
|
if(!countriesSet.has(mydata['country'].classname)) {
|
144 |
|
|
this.dataProviderInfo.countries.push(mydata['country'].classname);
|
145 |
|
|
countriesSet.add(mydata['country'].classname);
|
146 |
|
|
}
|
147 |
|
|
}
|
148 |
|
|
|
149 |
43785
|
argiro.kok
|
counter++;
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
//this.printPublicationInfo();
|
156 |
|
|
return this.dataProviderInfo;
|
157 |
|
|
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
printDataProviderInfo() {
|
161 |
|
|
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
}
|