1
|
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
2
|
import { ErrorCodes} from '../../utils/properties/openaireProperties';
|
3
|
import {ExportCSVComponent} from '../../utils/exportCSV.class';
|
4
|
import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class';
|
5
|
|
6
|
export class FetchDataproviders {
|
7
|
public results =[];
|
8
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
9
|
public sub: any; public subResults: any;
|
10
|
public CSV: any = { "columnNames": [ "Title", "Type", "Coutries", "Compatibility" ],
|
11
|
"export":[]
|
12
|
};
|
13
|
public CSVDownloaded = false;
|
14
|
public csvParams: string;
|
15
|
|
16
|
|
17
|
constructor ( private _searchDataprovidersService: SearchDataprovidersService ) {
|
18
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
19
|
this.searchUtils.status =errorCodes.LOADING;
|
20
|
}
|
21
|
|
22
|
|
23
|
public ngOnDestroy() {
|
24
|
if(this.sub){
|
25
|
this.sub.unsubscribe();
|
26
|
}
|
27
|
if(this.subResults){
|
28
|
this.subResults.unsubscribe();
|
29
|
}
|
30
|
}
|
31
|
|
32
|
public getResultsByKeyword(keyword:string, page: number, size: number){
|
33
|
var parameters = "";
|
34
|
if(keyword.length > 0){
|
35
|
parameters = "q=" + keyword;
|
36
|
}
|
37
|
|
38
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
39
|
this.searchUtils.status = errorCodes.LOADING;
|
40
|
|
41
|
|
42
|
this.subResults = this._searchDataprovidersService.searchDataproviders(parameters,null, page, size,[]).subscribe(
|
43
|
data => {
|
44
|
this.searchUtils.totalResults = data[0];
|
45
|
console.info("search Data Providers: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
46
|
this.results = data[1];
|
47
|
|
48
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
49
|
this.searchUtils.status = errorCodes.DONE;
|
50
|
if(this.searchUtils.totalResults == 0 ){
|
51
|
this.searchUtils.status = errorCodes.NONE;
|
52
|
}
|
53
|
},
|
54
|
err => {
|
55
|
console.log(err);
|
56
|
//TODO check erros (service not available, bad request)
|
57
|
// if( ){
|
58
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
59
|
// }
|
60
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
61
|
this.searchUtils.status = errorCodes.ERROR;
|
62
|
}
|
63
|
);
|
64
|
}
|
65
|
|
66
|
public getNumForEntity(entity: string, id:string) {
|
67
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
68
|
this.searchUtils.status = errorCodes.LOADING;
|
69
|
|
70
|
if(id != "" && entity != "") {
|
71
|
|
72
|
this._searchDataprovidersService.numOfEntityDataproviders(id, entity).subscribe(
|
73
|
data => {
|
74
|
this.searchUtils.totalResults = data;
|
75
|
|
76
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
77
|
this.searchUtils.status = errorCodes.DONE;
|
78
|
if(this.searchUtils.totalResults == 0 ){
|
79
|
this.searchUtils.status = errorCodes.NONE;
|
80
|
}
|
81
|
},
|
82
|
err => {
|
83
|
console.log(err);
|
84
|
//TODO check erros (service not available, bad request)
|
85
|
// if( ){
|
86
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
87
|
// }
|
88
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
89
|
this.searchUtils.status = errorCodes.ERROR;
|
90
|
}
|
91
|
);
|
92
|
}
|
93
|
}
|
94
|
|
95
|
public getNumForSearch(keyword: string) {
|
96
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
97
|
this.searchUtils.status = errorCodes.LOADING;
|
98
|
|
99
|
this._searchDataprovidersService.numOfSearchDataproviders(keyword).subscribe(
|
100
|
data => {
|
101
|
this.searchUtils.totalResults = data;
|
102
|
this.searchUtils.status = errorCodes.DONE;
|
103
|
|
104
|
if(this.searchUtils.totalResults == 0) {
|
105
|
this.searchUtils.status = errorCodes.NONE;
|
106
|
}
|
107
|
},
|
108
|
err => {
|
109
|
console.log(err);
|
110
|
//TODO check erros (service not available, bad request)
|
111
|
// if( ){
|
112
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
113
|
// }
|
114
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
115
|
this.searchUtils.status = errorCodes.ERROR;
|
116
|
}
|
117
|
);
|
118
|
}
|
119
|
|
120
|
public getResultsForDeposit(id:string, type:string, page: number, size: number){
|
121
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
122
|
this.searchUtils.status = errorCodes.LOADING;
|
123
|
|
124
|
if(id != "") {
|
125
|
|
126
|
this._searchDataprovidersService.searchDataprovidersForDeposit(id,type, page, size).subscribe(
|
127
|
data => {
|
128
|
this.searchUtils.totalResults = data[0];
|
129
|
console.info("search Dataproviders forDeposit: [id:"+id+", type:"+type+" ] [total results:"+this.searchUtils.totalResults+"]");
|
130
|
this.results = data[1];
|
131
|
|
132
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
133
|
this.searchUtils.status = errorCodes.DONE;
|
134
|
if(this.searchUtils.totalResults == 0 ){
|
135
|
this.searchUtils.status = errorCodes.NONE;
|
136
|
}
|
137
|
},
|
138
|
err => {
|
139
|
console.log(err);
|
140
|
//TODO check erros (service not available, bad request)
|
141
|
// if( ){
|
142
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
143
|
// }
|
144
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
145
|
this.searchUtils.status = errorCodes.ERROR;
|
146
|
}
|
147
|
);
|
148
|
}
|
149
|
}
|
150
|
public getResultsBySubjectsForDeposit(subject:string, type:string, page: number, size: number){
|
151
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
152
|
this.searchUtils.status = errorCodes.LOADING;
|
153
|
this._searchDataprovidersService.searchDataProvidersBySubjects(subject,type, page, size).subscribe(
|
154
|
data => {
|
155
|
this.searchUtils.totalResults = data[0];
|
156
|
console.info("search Dataproviders forDeposit: [subject:"+subject+", type:"+type+" ] [total results:"+this.searchUtils.totalResults+"]");
|
157
|
this.results = data[1];
|
158
|
|
159
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
160
|
this.searchUtils.status = errorCodes.DONE;
|
161
|
if(this.searchUtils.totalResults == 0 ){
|
162
|
this.searchUtils.status = errorCodes.NONE;
|
163
|
}
|
164
|
},
|
165
|
err => {
|
166
|
console.log(err);
|
167
|
//TODO check erros (service not available, bad request)
|
168
|
// if( ){
|
169
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
170
|
// }
|
171
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
172
|
this.searchUtils.status = errorCodes.ERROR;
|
173
|
}
|
174
|
);
|
175
|
|
176
|
}
|
177
|
public getResultsForEntity(entity:string, id:string, page: number, size: number){
|
178
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
179
|
this.searchUtils.status = errorCodes.LOADING;
|
180
|
|
181
|
var parameters = "";
|
182
|
|
183
|
if(entity == "organization") {
|
184
|
parameters = "organizations/"+id;
|
185
|
}
|
186
|
|
187
|
if(parameters != "") {
|
188
|
|
189
|
this._searchDataprovidersService.searchDataprovidersForEntity(parameters, page, size).subscribe(
|
190
|
data => {
|
191
|
this.searchUtils.totalResults = data[0];
|
192
|
console.info("search Dataproviders for "+entity+": [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
193
|
this.results = data[1];
|
194
|
|
195
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
196
|
this.searchUtils.status = errorCodes.DONE;
|
197
|
if(this.searchUtils.totalResults == 0 ){
|
198
|
this.searchUtils.status = errorCodes.NONE;
|
199
|
}
|
200
|
},
|
201
|
err => {
|
202
|
console.log(err);
|
203
|
//TODO check erros (service not available, bad request)
|
204
|
// if( ){
|
205
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
206
|
// }
|
207
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
208
|
this.searchUtils.status = errorCodes.ERROR;
|
209
|
}
|
210
|
);
|
211
|
}
|
212
|
}
|
213
|
|
214
|
public getResultsForDataproviders(id:string, page: number, size: number){
|
215
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
216
|
this.searchUtils.status = errorCodes.LOADING;
|
217
|
|
218
|
this._searchDataprovidersService.getDataProvidersforEntityRegistry(id, page, size).subscribe(
|
219
|
data => {
|
220
|
this.searchUtils.totalResults = data[0];
|
221
|
console.info("search Dataproviders for Entity Registry: [Id:"+id+" ] [total results:"+this.searchUtils.totalResults+"]");
|
222
|
this.results = data[1];
|
223
|
|
224
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
225
|
this.searchUtils.status = errorCodes.DONE;
|
226
|
if(this.searchUtils.totalResults == 0 ){
|
227
|
this.searchUtils.status = errorCodes.NONE;
|
228
|
}
|
229
|
},
|
230
|
err => {
|
231
|
console.log(err);
|
232
|
//TODO check erros (service not available, bad request)
|
233
|
// if( ){
|
234
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
235
|
// }
|
236
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
237
|
this.searchUtils.status = errorCodes.ERROR;
|
238
|
}
|
239
|
);
|
240
|
}
|
241
|
|
242
|
|
243
|
|
244
|
public downloadClicked($event) {
|
245
|
if(!this.CSVDownloaded) {
|
246
|
this.CSVDownloaded = false;
|
247
|
|
248
|
var parameters = $event.value;
|
249
|
|
250
|
//this.getResultsCSV(parameters, false, 1, 1000);
|
251
|
|
252
|
this._searchDataprovidersService.searchDataprovidersCSV(parameters, "", 1, 1000).subscribe(
|
253
|
data => {
|
254
|
this.CSV.export = data;
|
255
|
ExportCSVComponent.downloadCSV(this.CSV, "dataproviders.csv");
|
256
|
|
257
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
258
|
this.searchUtils.status = errorCodes.DONE;
|
259
|
if(this.searchUtils.totalResults == 0 ){
|
260
|
this.searchUtils.status = errorCodes.NONE;
|
261
|
}
|
262
|
},
|
263
|
err => {
|
264
|
console.log(err);
|
265
|
//TODO check erros (service not available, bad request)
|
266
|
// if( ){
|
267
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
268
|
// }
|
269
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
270
|
this.searchUtils.status = errorCodes.ERROR;
|
271
|
}
|
272
|
);
|
273
|
/*
|
274
|
this.CSV.export.push(
|
275
|
[
|
276
|
this.quote(project.name),
|
277
|
this.quote(project.acronym),
|
278
|
this.quote(project.code),
|
279
|
this.quote(project.funder),
|
280
|
this.quote(project.fundingStream),
|
281
|
this.quote(project.fundingLevel1),
|
282
|
this.quote(project.fundingLevel2),
|
283
|
this.quote(project.sc39),
|
284
|
this.quote(project.startDate),
|
285
|
this.quote(project.endDate)
|
286
|
]);
|
287
|
}*/
|
288
|
}
|
289
|
}
|
290
|
|
291
|
}
|