1
|
import {SearchDatasetsService} from '../../services/searchDatasets.service';
|
2
|
import { ErrorCodes} from '../../utils/properties/openaireProperties';
|
3
|
import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class';
|
4
|
import {DOI} from '../../utils/string-utils.class';
|
5
|
import {Subject} from 'rxjs/Subject';
|
6
|
|
7
|
export class FetchDatasets{
|
8
|
private errorCodes: ErrorCodes;
|
9
|
|
10
|
public results =[];
|
11
|
public requestComplete: Subject<void>;
|
12
|
|
13
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
14
|
private sub: any;
|
15
|
private subResults: any;
|
16
|
|
17
|
public csvParams: string;
|
18
|
|
19
|
constructor ( private _searchDatasetsService: SearchDatasetsService ) {
|
20
|
|
21
|
this.errorCodes = new ErrorCodes();
|
22
|
this.searchUtils.status = this.errorCodes.LOADING;
|
23
|
|
24
|
this.requestComplete = new Subject<void>();
|
25
|
}
|
26
|
|
27
|
|
28
|
|
29
|
public ngOnDestroy() {
|
30
|
if(this.sub){
|
31
|
this.sub.unsubscribe();
|
32
|
}
|
33
|
if(this.subResults){
|
34
|
this.subResults.unsubscribe();
|
35
|
}
|
36
|
}
|
37
|
|
38
|
|
39
|
public getResultsByKeyword(keyword:string, page: number, size: number){
|
40
|
var parameters = "";
|
41
|
if(keyword.length > 0){
|
42
|
var DOIs:string[] = DOI.getDOIsFromString(keyword);
|
43
|
var doisParams = "";
|
44
|
|
45
|
for(var i =0 ;i < DOIs.length; i++){
|
46
|
doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
47
|
}
|
48
|
if(doisParams.length > 0){
|
49
|
parameters += "&"+doisParams;
|
50
|
}else{
|
51
|
parameters = "q=" + keyword;
|
52
|
}
|
53
|
}
|
54
|
|
55
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
56
|
this.searchUtils.status = this.errorCodes.LOADING;
|
57
|
|
58
|
this.subResults = this._searchDatasetsService.searchDatasets(parameters,null, page, size, []).subscribe(
|
59
|
data => {
|
60
|
this.searchUtils.totalResults = data[0];
|
61
|
console.info("search Research Data: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
62
|
this.results = data[1];
|
63
|
|
64
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
65
|
this.searchUtils.status = this.errorCodes.DONE;
|
66
|
if(this.searchUtils.totalResults == 0 ){
|
67
|
this.searchUtils.status = this.errorCodes.NONE;
|
68
|
}
|
69
|
},
|
70
|
err => {
|
71
|
console.log(err);
|
72
|
//TODO check erros (service not available, bad request)
|
73
|
// if( ){
|
74
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
75
|
// }
|
76
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
77
|
//this.searchUtils.status = errorCodes.ERROR;
|
78
|
if(err.status == '404') {
|
79
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
80
|
} else if(err.status == '500') {
|
81
|
this.searchUtils.status = this.errorCodes.ERROR;
|
82
|
} else {
|
83
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
84
|
}
|
85
|
}
|
86
|
);
|
87
|
}
|
88
|
|
89
|
public getNumForEntity(entity:string, id:string){
|
90
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
91
|
this.searchUtils.status = this.errorCodes.LOADING;
|
92
|
|
93
|
|
94
|
if(id != "" && entity != "") {
|
95
|
this._searchDatasetsService.numOfEntityDatasets(id, entity).subscribe(
|
96
|
data => {
|
97
|
this.searchUtils.totalResults = data;
|
98
|
|
99
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
100
|
this.searchUtils.status = this.errorCodes.DONE;
|
101
|
if(this.searchUtils.totalResults == 0 ){
|
102
|
this.searchUtils.status = this.errorCodes.NONE;
|
103
|
}
|
104
|
},
|
105
|
err => {
|
106
|
console.log(err);
|
107
|
//TODO check erros (service not available, bad request)
|
108
|
// if( ){
|
109
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
110
|
// }
|
111
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
112
|
//this.searchUtils.status = errorCodes.ERROR;
|
113
|
if(err.status == '404') {
|
114
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
115
|
} else if(err.status == '500') {
|
116
|
this.searchUtils.status = this.errorCodes.ERROR;
|
117
|
} else {
|
118
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
119
|
}
|
120
|
}
|
121
|
);
|
122
|
}
|
123
|
}
|
124
|
|
125
|
public getResultsForEntity(entity:string, id:string, page: number, size: number){
|
126
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
127
|
this.searchUtils.status = this.errorCodes.LOADING;
|
128
|
|
129
|
var parameters = "";
|
130
|
|
131
|
if(entity == "project") {
|
132
|
parameters = "projects/"+id;
|
133
|
}
|
134
|
|
135
|
if(parameters != "") {
|
136
|
|
137
|
this._searchDatasetsService.searchDatasetsForEntity(parameters, page, size).subscribe(
|
138
|
data => {
|
139
|
this.searchUtils.totalResults = data[0];
|
140
|
console.info("search Research Data for "+entity+": [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
141
|
this.results = data[1];
|
142
|
|
143
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
144
|
this.searchUtils.status = this.errorCodes.DONE;
|
145
|
if(this.searchUtils.totalResults == 0 ){
|
146
|
this.searchUtils.status = this.errorCodes.NONE;
|
147
|
}
|
148
|
},
|
149
|
err => {
|
150
|
console.log(err);
|
151
|
//TODO check erros (service not available, bad request)
|
152
|
// if( ){
|
153
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
154
|
// }
|
155
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
156
|
//this.searchUtils.status = errorCodes.ERROR;
|
157
|
if(err.status == '404') {
|
158
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
159
|
} else if(err.status == '500') {
|
160
|
this.searchUtils.status = this.errorCodes.ERROR;
|
161
|
} else {
|
162
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
163
|
}
|
164
|
}
|
165
|
);
|
166
|
}
|
167
|
}
|
168
|
|
169
|
public getResultsForDataproviders(id:string, resultsFrom:string, page: number, size: number){
|
170
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
171
|
this.searchUtils.status = this.errorCodes.LOADING;
|
172
|
|
173
|
var parameters;
|
174
|
if(resultsFrom == "collectedFrom") {
|
175
|
parameters = "datasets?fq=collectedfromdatasourceid exact "+'"'+id+'"';
|
176
|
} else if(resultsFrom == "hostedBy") {
|
177
|
parameters = "datasets?fq=resulthostingdatasourceid exact "+'"'+id+'"';
|
178
|
}
|
179
|
|
180
|
if(parameters != "") {
|
181
|
|
182
|
this._searchDatasetsService.searchDatasetsForDataproviders(parameters, page, size).subscribe(
|
183
|
data => {
|
184
|
this.searchUtils.totalResults = data[0];
|
185
|
console.info("search Research Data for Dataproviders: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
186
|
this.results = data[1];
|
187
|
|
188
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
189
|
this.searchUtils.status = this.errorCodes.DONE;
|
190
|
if(this.searchUtils.totalResults == 0 ){
|
191
|
this.searchUtils.status = this.errorCodes.NONE;
|
192
|
}
|
193
|
},
|
194
|
err => {
|
195
|
console.log(err);
|
196
|
//TODO check erros (service not available, bad request)
|
197
|
// if( ){
|
198
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
199
|
// }
|
200
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
201
|
//this.searchUtils.status = errorCodes.ERROR;
|
202
|
if(err.status == '404') {
|
203
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
204
|
} else if(err.status == '500') {
|
205
|
this.searchUtils.status = this.errorCodes.ERROR;
|
206
|
} else {
|
207
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
208
|
}
|
209
|
}
|
210
|
);
|
211
|
}
|
212
|
}
|
213
|
|
214
|
public getAggregatorResults(id:string, page: number, size: number){
|
215
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
216
|
this.searchUtils.status = this.errorCodes.LOADING;
|
217
|
|
218
|
this.subResults = this._searchDatasetsService.searchAggregators(id, '&fq=collectedfromdatasourceid exact "'+id+'"',"&refine=true&fields=resulthostingdatasource" , page, size).subscribe(
|
219
|
data => {
|
220
|
this.results = data;
|
221
|
this.searchUtils.totalResults = this.results.length;
|
222
|
|
223
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
224
|
this.searchUtils.status = this.errorCodes.DONE;
|
225
|
if(this.searchUtils.totalResults == 0 ){
|
226
|
this.searchUtils.status = this.errorCodes.NONE;
|
227
|
}
|
228
|
|
229
|
this.requestComplete.complete();
|
230
|
},
|
231
|
err => {
|
232
|
console.log(err);
|
233
|
console.info("status: "+err.status);
|
234
|
//TODO check erros (service not available, bad request)
|
235
|
// if( ){
|
236
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
237
|
// }
|
238
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
239
|
//this.searchUtils.status = errorCodes.ERROR;
|
240
|
if(err.status == '404') {
|
241
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
242
|
} else if(err.status == '500') {
|
243
|
this.searchUtils.status = this.errorCodes.ERROR;
|
244
|
} else {
|
245
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
246
|
}
|
247
|
|
248
|
this.requestComplete.complete();
|
249
|
}
|
250
|
);
|
251
|
}
|
252
|
|
253
|
}
|