1
|
import {SearchOrpsService} from '../../services/searchOrps.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 FetchOrps{
|
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 _searchOrpsService: SearchOrpsService ) {
|
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
|
this.searchUtils.status = this.errorCodes.LOADING;
|
61
|
var refineParams = (connectCommunityId)?("&fq="+StringUtils.URIEncode("communityId exact " + StringUtils.quote((connectCommunityId )))):null;
|
62
|
this.subResults = this._searchOrpsService.searchOrps(parameters,refineParams, page, size, "", [], properties).subscribe(
|
63
|
data => {
|
64
|
this.searchUtils.totalResults = data[0];
|
65
|
//console.info("search Other Research Products: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
66
|
this.results = data[1];
|
67
|
|
68
|
this.searchUtils.status = this.errorCodes.DONE;
|
69
|
if(this.searchUtils.totalResults == 0 ){
|
70
|
this.searchUtils.status = this.errorCodes.NONE;
|
71
|
}
|
72
|
},
|
73
|
err => {
|
74
|
/*
|
75
|
console.log(err);
|
76
|
//TODO check erros (service not available, bad request)
|
77
|
if(err.status == '404') {
|
78
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
79
|
} else if(err.status == '500') {
|
80
|
this.searchUtils.status = this.errorCodes.ERROR;
|
81
|
} else {
|
82
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
83
|
}*/
|
84
|
this.handleError("Error getting other research products for keyword: "+keyword+ (doisParams ? "(DOI)" : ""), err);
|
85
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
86
|
}
|
87
|
);
|
88
|
}
|
89
|
|
90
|
public getNumForEntity(entity:string, id:string, properties:EnvProperties){
|
91
|
this.searchUtils.status = this.errorCodes.LOADING;
|
92
|
|
93
|
|
94
|
if(id != "" && entity != "") {
|
95
|
this._searchOrpsService.numOfEntityOrps(id, entity, properties).subscribe(
|
96
|
data => {
|
97
|
this.searchUtils.totalResults = data;
|
98
|
|
99
|
this.searchUtils.status = this.errorCodes.DONE;
|
100
|
if(this.searchUtils.totalResults == 0 ){
|
101
|
this.searchUtils.status = this.errorCodes.NONE;
|
102
|
}
|
103
|
},
|
104
|
err => {
|
105
|
/*console.log(err);
|
106
|
//TODO check erros (service not available, bad request)
|
107
|
if(err.status == '404') {
|
108
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
109
|
} else if(err.status == '500') {
|
110
|
this.searchUtils.status = this.errorCodes.ERROR;
|
111
|
} else {
|
112
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
113
|
}*/
|
114
|
this.handleError("Error getting number of other research products for "+entity+" with id: "+id, err);
|
115
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
116
|
}
|
117
|
);
|
118
|
}
|
119
|
}
|
120
|
|
121
|
public getResultsForEntity(entity:string, id:string, page: number, size: number, properties:EnvProperties){
|
122
|
this.searchUtils.status = this.errorCodes.LOADING;
|
123
|
|
124
|
var parameters = "";
|
125
|
|
126
|
if(entity == "project") {
|
127
|
parameters = "projects/"+id;
|
128
|
}
|
129
|
|
130
|
if(parameters != "") {
|
131
|
|
132
|
this._searchOrpsService.searchOrpsForEntity(parameters, page, size, properties).subscribe(
|
133
|
data => {
|
134
|
this.searchUtils.totalResults = data[0];
|
135
|
//console.info("search Other Research Products for "+entity+": [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
136
|
this.results = data[1];
|
137
|
|
138
|
this.searchUtils.status = this.errorCodes.DONE;
|
139
|
if(this.searchUtils.totalResults == 0 ){
|
140
|
this.searchUtils.status = this.errorCodes.NONE;
|
141
|
}
|
142
|
},
|
143
|
err => {
|
144
|
/*console.log(err);
|
145
|
//TODO check erros (service not available, bad request)
|
146
|
if(err.status == '404') {
|
147
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
148
|
} else if(err.status == '500') {
|
149
|
this.searchUtils.status = this.errorCodes.ERROR;
|
150
|
} else {
|
151
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
152
|
}*/
|
153
|
this.handleError("Error getting other research products for "+entity+" with id: "+id, err);
|
154
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
155
|
}
|
156
|
);
|
157
|
}
|
158
|
}
|
159
|
|
160
|
public getResultsForDataproviders(id:string, resultsFrom:string, page: number, size: number, properties:EnvProperties){
|
161
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
162
|
this.searchUtils.status = this.errorCodes.LOADING;
|
163
|
|
164
|
var parameters;
|
165
|
if(resultsFrom == "collectedFrom") {
|
166
|
parameters = "other?fq=collectedfromdatasourceid exact "+'"'+id+'"';
|
167
|
} else if(resultsFrom == "hostedBy") {
|
168
|
parameters = "other?fq=resulthostingdatasourceid exact "+'"'+id+'"';
|
169
|
}
|
170
|
|
171
|
if(parameters != "") {
|
172
|
|
173
|
this._searchOrpsService.searchOrpsForDataproviders(parameters, page, size, properties).subscribe(
|
174
|
data => {
|
175
|
this.searchUtils.totalResults = data[0];
|
176
|
//console.info("search Other Research Products for Dataproviders: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
177
|
this.results = data[1];
|
178
|
|
179
|
this.searchUtils.status = this.errorCodes.DONE;
|
180
|
if(this.searchUtils.totalResults == 0 ){
|
181
|
this.searchUtils.status = this.errorCodes.NONE;
|
182
|
}
|
183
|
},
|
184
|
err => {
|
185
|
/*console.log(err);
|
186
|
//TODO check erros (service not available, bad request)
|
187
|
if(err.status == '404') {
|
188
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
189
|
} else if(err.status == '500') {
|
190
|
this.searchUtils.status = this.errorCodes.ERROR;
|
191
|
} else {
|
192
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
193
|
}*/
|
194
|
this.handleError("Error getting other research products for content provider ("+resultsFrom+") with id: "+id, err);
|
195
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
196
|
}
|
197
|
);
|
198
|
}
|
199
|
}
|
200
|
|
201
|
public getAggregatorResults(id:string, page: number, size: number, properties:EnvProperties){
|
202
|
this.searchUtils.status = this.errorCodes.LOADING;
|
203
|
|
204
|
this.subResults = this._searchOrpsService.searchAggregators(id, '&fq=collectedfromdatasourceid exact "'+id+'"',"&refine=true&fields=resulthostingdatasource" , page, size, properties).subscribe(
|
205
|
data => {
|
206
|
this.results = data;
|
207
|
this.searchUtils.totalResults = this.results.length;
|
208
|
|
209
|
this.searchUtils.status = this.errorCodes.DONE;
|
210
|
if(this.searchUtils.totalResults == 0 ){
|
211
|
this.searchUtils.status = this.errorCodes.NONE;
|
212
|
}
|
213
|
|
214
|
this.requestComplete.complete();
|
215
|
},
|
216
|
err => {
|
217
|
/*console.log(err);
|
218
|
//console.info("status: "+err.status);
|
219
|
//TODO check erros (service not available, bad request)
|
220
|
if(err.status == '404') {
|
221
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
222
|
} else if(err.status == '500') {
|
223
|
this.searchUtils.status = this.errorCodes.ERROR;
|
224
|
} else {
|
225
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
226
|
}*/
|
227
|
this.handleError("Error getting other research products for aggrgator with id: "+id, err);
|
228
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
229
|
|
230
|
this.requestComplete.complete();
|
231
|
}
|
232
|
);
|
233
|
}
|
234
|
|
235
|
private handleError(message: string, error) {
|
236
|
console.error("Fetch Other Research Data (class): "+message, error);
|
237
|
}
|
238
|
}
|