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