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
|
|
6
|
export class FetchDatasets{
|
7
|
public results =[];
|
8
|
|
9
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
10
|
private sub: any;
|
11
|
private subResults: any;
|
12
|
|
13
|
public csvParams: string;
|
14
|
|
15
|
constructor ( private _searchDatasetsService: SearchDatasetsService ) {
|
16
|
|
17
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
18
|
this.searchUtils.status =errorCodes.LOADING;
|
19
|
|
20
|
}
|
21
|
|
22
|
|
23
|
|
24
|
public ngOnDestroy() {
|
25
|
if(this.sub){
|
26
|
this.sub.unsubscribe();
|
27
|
}
|
28
|
if(this.subResults){
|
29
|
this.subResults.unsubscribe();
|
30
|
}
|
31
|
}
|
32
|
|
33
|
|
34
|
public getResultsByKeyword(keyword:string, page: number, size: number){
|
35
|
var parameters = "";
|
36
|
if(keyword.length > 0){
|
37
|
var DOIs:string[] = DOI.getDOIsFromString(keyword);
|
38
|
var doisParams = "";
|
39
|
|
40
|
for(var i =0 ;i < DOIs.length; i++){
|
41
|
doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
42
|
}
|
43
|
if(doisParams.length > 0){
|
44
|
parameters += "&"+doisParams;
|
45
|
}else{
|
46
|
parameters = "q=" + keyword;
|
47
|
}
|
48
|
}
|
49
|
|
50
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
51
|
this.searchUtils.status = errorCodes.LOADING;
|
52
|
|
53
|
this.subResults = this._searchDatasetsService.searchDatasets(parameters,null, page, size, []).subscribe(
|
54
|
data => {
|
55
|
this.searchUtils.totalResults = data[0];
|
56
|
console.info("search Datasets: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
57
|
this.results = data[1];
|
58
|
|
59
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
60
|
this.searchUtils.status = errorCodes.DONE;
|
61
|
if(this.searchUtils.totalResults == 0 ){
|
62
|
this.searchUtils.status = errorCodes.NONE;
|
63
|
}
|
64
|
},
|
65
|
err => {
|
66
|
console.log(err);
|
67
|
//TODO check erros (service not available, bad request)
|
68
|
// if( ){
|
69
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
70
|
// }
|
71
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
72
|
this.searchUtils.status = errorCodes.ERROR;
|
73
|
}
|
74
|
);
|
75
|
}
|
76
|
|
77
|
|
78
|
public getResultsForEntity(entity:string, id:string, page: number, size: number){
|
79
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
80
|
this.searchUtils.status = errorCodes.LOADING;
|
81
|
|
82
|
var parameters = "";
|
83
|
|
84
|
if(entity == "project") {
|
85
|
parameters = "projects/"+id;
|
86
|
} else if(entity == "person") {
|
87
|
parameters = "people/"+id;
|
88
|
}
|
89
|
|
90
|
if(parameters != "") {
|
91
|
|
92
|
this._searchDatasetsService.searchDatasetsForEntity(parameters, page, size).subscribe(
|
93
|
data => {
|
94
|
this.searchUtils.totalResults = data[0];
|
95
|
console.info("search Datasets for "+entity+": [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
96
|
this.results = data[1];
|
97
|
|
98
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
99
|
this.searchUtils.status = errorCodes.DONE;
|
100
|
if(this.searchUtils.totalResults == 0 ){
|
101
|
this.searchUtils.status = errorCodes.NONE;
|
102
|
}
|
103
|
},
|
104
|
err => {
|
105
|
console.log(err);
|
106
|
//TODO check erros (service not available, bad request)
|
107
|
// if( ){
|
108
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
109
|
// }
|
110
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
111
|
this.searchUtils.status = errorCodes.ERROR;
|
112
|
}
|
113
|
);
|
114
|
}
|
115
|
}
|
116
|
|
117
|
public getResultsForDataproviders(id:string, resultsFrom:string, page: number, size: number){
|
118
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
119
|
this.searchUtils.status = errorCodes.LOADING;
|
120
|
|
121
|
var parameters;
|
122
|
if(resultsFrom == "collectedFrom") {
|
123
|
parameters = "datasets?fq=collectedfromdatasourceid exact "+'"'+id+'"';
|
124
|
} else if(resultsFrom == "hostedBy") {
|
125
|
parameters = "datasets?fq=resulthostingdatasourceid exact "+'"'+id+'"';
|
126
|
}
|
127
|
|
128
|
if(parameters != "") {
|
129
|
|
130
|
this._searchDatasetsService.searchDatasetsForDataproviders(parameters, page, size).subscribe(
|
131
|
data => {
|
132
|
this.searchUtils.totalResults = data[0];
|
133
|
console.info("search Datasets for Dataproviders: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
134
|
this.results = data[1];
|
135
|
|
136
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
137
|
this.searchUtils.status = errorCodes.DONE;
|
138
|
if(this.searchUtils.totalResults == 0 ){
|
139
|
this.searchUtils.status = errorCodes.NONE;
|
140
|
}
|
141
|
},
|
142
|
err => {
|
143
|
console.log(err);
|
144
|
//TODO check erros (service not available, bad request)
|
145
|
// if( ){
|
146
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
147
|
// }
|
148
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
149
|
this.searchUtils.status = errorCodes.ERROR;
|
150
|
}
|
151
|
);
|
152
|
}
|
153
|
}
|
154
|
|
155
|
public getAggregatorResults(id:string, page: number, size: number){
|
156
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
157
|
this.searchUtils.status = errorCodes.LOADING;
|
158
|
|
159
|
this.subResults = this._searchDatasetsService.searchAggregators(id, '&fq=collectedfromdatasourceid exact "'+id+'"',"&refine=true&fields=resulthostingdatasource" , page, size).subscribe(
|
160
|
data => {
|
161
|
this.results = data;
|
162
|
|
163
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
164
|
this.searchUtils.status = errorCodes.DONE;
|
165
|
if(this.searchUtils.totalResults == 0 ){
|
166
|
this.searchUtils.status = errorCodes.NONE;
|
167
|
}
|
168
|
},
|
169
|
err => {
|
170
|
console.log(err);
|
171
|
//TODO check erros (service not available, bad request)
|
172
|
// if( ){
|
173
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
174
|
// }
|
175
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
176
|
this.searchUtils.status = errorCodes.ERROR;
|
177
|
}
|
178
|
);
|
179
|
}
|
180
|
|
181
|
}
|