Revision 59816
Added by Argiro Kokogiannaki over 3 years ago
fetchResearchResults.class.ts | ||
---|---|---|
4 | 4 |
import {SearchFields} from '../../utils/properties/searchFields'; |
5 | 5 |
import {SearchCustomFilter, SearchUtilsClass} from '../../searchPages/searchUtils/searchUtils.class'; |
6 | 6 |
import {DOI, StringUtils} from '../../utils/string-utils.class'; |
7 |
import {Subject} from 'rxjs'; |
|
7 |
import {Subject, Subscriber} from 'rxjs';
|
|
8 | 8 |
import {EnvProperties} from '../../utils/properties/env-properties'; |
9 | 9 |
|
10 | 10 |
export class FetchResearchResults { |
... | ... | |
16 | 16 |
public requestComplete: Subject<void>; |
17 | 17 |
|
18 | 18 |
public searchUtils:SearchUtilsClass = new SearchUtilsClass(); |
19 |
public sub: any; |
|
20 |
public subResults: any; |
|
19 |
subscriptions = []; |
|
21 | 20 |
public searchFields:SearchFields = new SearchFields(); |
22 | 21 |
|
23 | 22 |
public CSV: any = { |
... | ... | |
38 | 37 |
this.requestComplete = new Subject<void>(); |
39 | 38 |
} |
40 | 39 |
|
41 |
public ngOnDestroy() { |
|
42 |
if(this.sub){ |
|
43 |
this.sub.unsubscribe(); |
|
44 |
} |
|
45 |
if(this.subResults){ |
|
46 |
this.subResults.unsubscribe(); |
|
47 |
} |
|
40 |
public clearSubscriptions() { |
|
41 |
this.subscriptions.forEach(subscription => { |
|
42 |
if (subscription instanceof Subscriber) { |
|
43 |
subscription.unsubscribe(); |
|
44 |
} |
|
45 |
}); |
|
48 | 46 |
} |
49 | 47 |
|
50 | 48 |
public getResultsForCommunity(resultType:string, communityId: string, page: number, size: number, properties:EnvProperties) { |
51 | 49 |
this.searchUtils.status = this.errorCodes.LOADING; |
52 | 50 |
|
53 |
this.subResults = this._searchResearchResultsService.search(resultType, "", "&fq=communityid=" + communityId, page, size, "resultdateofacceptance,descending", [], properties).subscribe(
|
|
51 |
this.subscriptions.push(this._searchResearchResultsService.search(resultType, "", "&fq=communityid=" + communityId, page, size, "resultdateofacceptance,descending", [], properties).subscribe(
|
|
54 | 52 |
data => { |
55 | 53 |
this.searchUtils.totalResults = data[0]; |
56 | 54 |
this.results = data[1]; |
... | ... | |
64 | 62 |
this.handleError("Error getting "+this.getEntityName(resultType,true)+" for community: "+communityId, err); |
65 | 63 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
66 | 64 |
} |
67 |
); |
|
65 |
));
|
|
68 | 66 |
} |
69 | 67 |
|
70 | 68 |
public getNumForCommunity(resultType:string, communityId: string, properties:EnvProperties) { |
71 | 69 |
this.searchUtils.status = this.errorCodes.LOADING; |
72 | 70 |
|
73 |
this.subResults = this._searchResearchResultsService.countTotalResults(resultType, properties, "&fq=communityid=" + communityId).subscribe(
|
|
71 |
this.subscriptions.push(this._searchResearchResultsService.countTotalResults(resultType, properties, "&fq=communityid=" + communityId).subscribe(
|
|
74 | 72 |
data => { |
75 | 73 |
this.searchUtils.totalResults = data; |
76 | 74 |
|
... | ... | |
83 | 81 |
this.handleError("Error getting number of "+this.getEntityName(resultType,true)+" for community: "+communityId, err); |
84 | 82 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
85 | 83 |
} |
86 |
); |
|
84 |
));
|
|
87 | 85 |
} |
88 | 86 |
|
89 | 87 |
public getResultsByKeyword(resultType:string, keyword:string, page: number, size: number, properties:EnvProperties, customFilter:SearchCustomFilter=null){ |
... | ... | |
107 | 105 |
if(customFilter){ |
108 | 106 |
refineParams = (refineParams?(refineParams+'&'):'')+"&fq="+StringUtils.URIEncode(customFilter.queryFieldName + " exact " + StringUtils.quote((customFilter.valueId ))); |
109 | 107 |
} |
110 |
this.subResults = this._searchResearchResultsService.search(this.getEntityName(resultType,false), parameters,refineParams, page, size, "", [], properties).subscribe(
|
|
108 |
this.subscriptions.push(this._searchResearchResultsService.search(this.getEntityName(resultType,false), parameters,refineParams, page, size, "", [], properties).subscribe(
|
|
111 | 109 |
data => { |
112 | 110 |
this.searchUtils.totalResults = data[0]; |
113 | 111 |
this.results = data[1]; |
... | ... | |
135 | 133 |
this.handleError("Error getting "+this.getEntityName(resultType,true)+" for keyword: "+keyword + (doisParams ? "(DOI)" : ""), err); |
136 | 134 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
137 | 135 |
} |
138 |
); |
|
136 |
));
|
|
139 | 137 |
} |
140 | 138 |
|
141 | 139 |
public getNumForEntity(resultType: string, entity:string, id:string, properties:EnvProperties){ |
142 | 140 |
this.searchUtils.status = this.errorCodes.LOADING; |
143 | 141 |
|
144 | 142 |
if(id != "" && entity != "") { |
145 |
this._searchResearchResultsService.numOfEntityResults(this.getEntityName(resultType,false), id, entity, properties).subscribe( |
|
143 |
this.subscriptions.push(this._searchResearchResultsService.numOfEntityResults(this.getEntityName(resultType,false), id, entity, properties).subscribe(
|
|
146 | 144 |
data => { |
147 | 145 |
this.searchUtils.totalResults = data; |
148 | 146 |
|
... | ... | |
169 | 167 |
this.handleError("Error getting "+this.getEntityName(resultType,true)+" for "+entity+" with id: "+id, err); |
170 | 168 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
171 | 169 |
} |
172 |
); |
|
170 |
));
|
|
173 | 171 |
} |
174 | 172 |
} |
175 | 173 |
|
... | ... | |
186 | 184 |
} |
187 | 185 |
|
188 | 186 |
if(parameters != "") { |
189 |
this._searchResearchResultsService.searchResultForEntity(this.getEntityName(resultType,false), parameters, page, size, properties).subscribe( |
|
187 |
this.subscriptions.push(this._searchResearchResultsService.searchResultForEntity(this.getEntityName(resultType,false), parameters, page, size, properties).subscribe(
|
|
190 | 188 |
data => { |
191 | 189 |
this.searchUtils.totalResults = data[0]; |
192 | 190 |
this.results = data[1]; |
... | ... | |
215 | 213 |
this.handleError("Error getting "+this.getEntityName(resultType,true)+" for "+entity+" with id: "+id, err); |
216 | 214 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
217 | 215 |
} |
218 |
); |
|
216 |
));
|
|
219 | 217 |
} |
220 | 218 |
} |
221 | 219 |
|
... | ... | |
233 | 231 |
|
234 | 232 |
if(parameters != "") { |
235 | 233 |
|
236 |
this._searchResearchResultsService.searchForDataproviders(this.getEntityName(resultType,false), parameters, page, size, properties).subscribe( |
|
234 |
this.subscriptions.push(this._searchResearchResultsService.searchForDataproviders(this.getEntityName(resultType,false), parameters, page, size, properties).subscribe(
|
|
237 | 235 |
data => { |
238 | 236 |
this.searchUtils.totalResults = data[0]; |
239 | 237 |
this.results = data[1]; |
... | ... | |
261 | 259 |
this.handleError("Error getting "+this.getEntityName(resultType,true)+" for content provider ("+resultsFrom+") with id: "+id, err); |
262 | 260 |
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); |
263 | 261 |
} |
264 |
); |
|
262 |
));
|
|
265 | 263 |
} |
266 | 264 |
} |
267 | 265 |
|
... | ... | |
269 | 267 |
this.searchUtils.status = this.errorCodes.LOADING; |
270 | 268 |
|
271 | 269 |
// this.getEntityName(resultType,false) |
272 |
this.subResults = this._searchResearchResultsService.searchAggregators(resultType, id, '&fq=(collectedfromdatasourceid exact "'+id+'" or resulthostingdatasourceid exact "'+id+'")',"&refine=true&fields=resulthostingdatasource&type="+resultType , page, size, properties).subscribe(
|
|
270 |
this.subscriptions.push(this._searchResearchResultsService.searchAggregators(resultType, id, '&fq=(collectedfromdatasourceid exact "'+id+'" or resulthostingdatasourceid exact "'+id+'")',"&refine=true&fields=resulthostingdatasource&type="+resultType , page, size, properties).subscribe(
|
|
273 | 271 |
data => { |
274 | 272 |
this.results = data; |
275 | 273 |
this.searchUtils.totalResults = this.results.length; |
... | ... | |
301 | 299 |
|
302 | 300 |
this.requestComplete.complete(); |
303 | 301 |
} |
304 |
); |
|
302 |
));
|
|
305 | 303 |
} |
306 | 304 |
|
307 | 305 |
private handleError(message: string, error) { |
Also available in: Unified diff
[Library|Trunk]
code clean up:
-remove app.* files from library
-remove unused imports, code, files (Old search pages for results, dataproviders, map search page, etc)
-remove Freeguard from modules
-unsubscribe all subscriptions
-Services: configuration, isvocabularies, user management: unsubscribe from app component or the component that uses them (clearSubscriptions())
-Fetchers: unsubscribe from the component that uses them (clearSubscriptions())