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