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