Project

General

Profile

1 50169 argiro.kok
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
2 58275 k.triantaf
import {ErrorCodes} from '../../utils/properties/errorCodes';
3
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
4 56091 argiro.kok
import {SearchCustomFilter, SearchUtilsClass} from '../../searchPages/searchUtils/searchUtils.class';
5 58275 k.triantaf
import {EnvProperties} from '../../utils/properties/env-properties';
6 53593 argiro.kok
import {StringUtils} from '../../utils/string-utils.class';
7 58275 k.triantaf
8 50169 argiro.kok
export class FetchDataproviders {
9
  private errorCodes: ErrorCodes;
10 54870 konstantin
  private errorMessages: ErrorMessagesComponent;
11 58275 k.triantaf
12
  public results = [];
13
  public searchUtils: SearchUtilsClass = new SearchUtilsClass();
14
  public sub: any;
15
  public subResults: any;
16
  public CSV: any = {
17
    "columnNames": ["Title", "Type", "Coutries", "Compatibility"],
18
    "export": []
19
  };
20 50169 argiro.kok
  public CSVDownloaded = false;
21
  public csvParams: string;
22 54755 konstantin
  public loadPaging: boolean = true;
23
  public oldTotalResults: number = 0;
24 58275 k.triantaf
25
  constructor(private _searchDataprovidersService: SearchDataprovidersService) {
26 50169 argiro.kok
    this.errorCodes = new ErrorCodes();
27 54870 konstantin
    this.errorMessages = new ErrorMessagesComponent();
28 50169 argiro.kok
    this.searchUtils.status = this.errorCodes.LOADING;
29 58275 k.triantaf
  }
30
31
32 50169 argiro.kok
  public ngOnDestroy() {
33 58275 k.triantaf
    if (this.sub) {
34 50169 argiro.kok
      this.sub.unsubscribe();
35
    }
36 58275 k.triantaf
    if (this.subResults) {
37 50169 argiro.kok
      this.subResults.unsubscribe();
38
    }
39
  }
40 58275 k.triantaf
41
  public getResultsByKeyword(keyword: string, page: number, size: number, properties: EnvProperties, customFilter: SearchCustomFilter = null) {
42 50169 argiro.kok
    var parameters = "";
43 58275 k.triantaf
    if (keyword.length > 0) {
44 53593 argiro.kok
      parameters = "q=" + StringUtils.URIEncode(keyword);
45 50169 argiro.kok
    }
46 58275 k.triantaf
47 50169 argiro.kok
    //var errorCodes:ErrorCodes = new ErrorCodes();
48
    this.searchUtils.status = this.errorCodes.LOADING;
49 58275 k.triantaf
50 56091 argiro.kok
    var refineParams = null;
51 58275 k.triantaf
    if (customFilter) {
52
      refineParams = (refineParams ? (refineParams + '&') : '') + "&fq=" + StringUtils.URIEncode(customFilter.queryFieldName + " exact " + StringUtils.quote((customFilter.valueId)));
53 56091 argiro.kok
    }
54 58275 k.triantaf
    this.subResults = this._searchDataprovidersService.searchDataproviders(parameters, refineParams, page, size, [], properties).subscribe(
55
      data => {
56
        this.searchUtils.totalResults = data[0];
57
        //console.info("search Content Providers: [Parameters:"+parameters+" ]  [total results:"+this.searchUtils.totalResults+"]");
58
        this.results = data[1];
59
60
        //ar errorCodes:ErrorCodes = new ErrorCodes();
61
        this.searchUtils.status = this.errorCodes.DONE;
62
        if (this.searchUtils.totalResults == 0) {
63
          this.searchUtils.status = this.errorCodes.NONE;
64 50169 argiro.kok
        }
65 58275 k.triantaf
      },
66
      err => {
67
        /*console.log(err);
68
         //TODO check erros (service not available, bad request)
69
        // if( ){
70
        //   this.searchUtils.status = ErrorCodes.ERROR;
71
        // }
72
        //var errorCodes:ErrorCodes = new ErrorCodes();
73
        //this.searchUtils.status = errorCodes.ERROR;
74
        if(err.status == '404') {
75
          this.searchUtils.status = this.errorCodes.NOT_FOUND;
76
        } else if(err.status == '500') {
77
          this.searchUtils.status = this.errorCodes.ERROR;
78
        } else {
79
          this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
80
        }
81
        */
82
        this.handleError("Error getting content providers for keyword: " + keyword, err);
83
        this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
84
      }
85 50169 argiro.kok
    );
86
  }
87 58275 k.triantaf
88
  public getResultsForHome(size: number, properties: EnvProperties) {
89 51996 konstantin
    let page = 1;
90
    var parameters = "&sortBy=resultdateofacceptance,descending";//"orderby=date";
91 58275 k.triantaf
92 51996 konstantin
    this.searchUtils.status = this.errorCodes.LOADING;
93 58275 k.triantaf
94
    this.subResults = this._searchDataprovidersService.searchDataproviders(parameters, null, page, size, [], properties).subscribe(
95
      data => {
96
        this.searchUtils.totalResults = data[0];
97
        //console.info("search Content Providers: [Parameters:"+parameters+" ]  [total results:"+this.searchUtils.totalResults+"]");
98
        this.results = data[1];
99
100
        this.searchUtils.status = this.errorCodes.DONE;
101
        if (this.searchUtils.totalResults == 0) {
102
          this.searchUtils.status = this.errorCodes.NONE;
103
        }
104
      },
105
      err => {
106
        /*console.log(err);
107
         //TODO check erros (service not available, bad request)
108
        if(err.status == '404') {
109
          this.searchUtils.status = this.errorCodes.NOT_FOUND;
110
        } else if(err.status == '500') {
111
          this.searchUtils.status = this.errorCodes.ERROR;
112
        } else {
113
          this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
114
        }*/
115
        this.handleError("Error getting content providers with parameters: " + parameters + " for Home", err);
116
        this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
117
      }
118
    );
119
  }
120
121
  public getNumForEntity(entity: string, id: string, properties: EnvProperties) {
122
    //var errorCodes:ErrorCodes = new ErrorCodes();
123
    this.searchUtils.status = this.errorCodes.LOADING;
124
125
    if (id != "" && entity != "") {
126
127
      this._searchDataprovidersService.numOfEntityDataproviders(id, entity, properties).subscribe(
128 51996 konstantin
        data => {
129 58275 k.triantaf
          this.searchUtils.totalResults = data;
130
131
          //var errorCodes:ErrorCodes = new ErrorCodes();
132
          this.searchUtils.status = this.errorCodes.DONE;
133
          if (this.searchUtils.totalResults == 0) {
134
            this.searchUtils.status = this.errorCodes.NONE;
135
          }
136 51996 konstantin
        },
137
        err => {
138 58275 k.triantaf
          /*console.log(err);
139
           //TODO check erros (service not available, bad request)
140
          // if( ){
141
          //   this.searchUtils.status = ErrorCodes.ERROR;
142
          // }
143
          //var errorCodes:ErrorCodes = new ErrorCodes();
144
          //this.searchUtils.status = errorCodes.ERROR;
145
          if(err.status == '404') {
146
            this.searchUtils.status = this.errorCodes.NOT_FOUND;
147
          } else if(err.status == '500') {
148
            this.searchUtils.status = this.errorCodes.ERROR;
149
          } else {
150
            this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
151
          }*/
152
          this.handleError("Error getting content providers for " + entity + " with id: " + id, err);
153
          this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
154 51996 konstantin
        }
155 58275 k.triantaf
      );
156
    }
157 51996 konstantin
  }
158 58275 k.triantaf
159
  public getNumForSearch(keyword: string, properties: EnvProperties, refineParams: string = null) {
160
    //var errorCodes:ErrorCodes = new ErrorCodes();
161
    this.searchUtils.status = this.errorCodes.LOADING;
162
163
    this._searchDataprovidersService.numOfSearchDataproviders(keyword, properties, refineParams).subscribe(
164
      data => {
165
        this.searchUtils.totalResults = data;
166
        this.searchUtils.status = this.errorCodes.DONE;
167
168
        if (this.searchUtils.totalResults == 0) {
169
          this.searchUtils.status = this.errorCodes.NONE;
170
        }
171
      },
172
      err => {
173
        /*console.log(err);
174
         //TODO check erros (service not available, bad request)
175
        // if( ){
176
        //   this.searchUtils.status = ErrorCodes.ERROR;
177
        // }
178
        //var errorCodes:ErrorCodes = new ErrorCodes();
179
        //this.searchUtils.status = errorCodes.ERROR;
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 number of content providers for keyword: " + keyword, err);
188
        this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
189 50169 argiro.kok
      }
190 58275 k.triantaf
    );
191 50169 argiro.kok
  }
192 58275 k.triantaf
193
  public getResultsForDeposit(id: string, type: string, page: number, size: number, properties: EnvProperties) {
194 50169 argiro.kok
    //var errorCodes:ErrorCodes = new ErrorCodes();
195
    this.searchUtils.status = this.errorCodes.LOADING;
196 54755 konstantin
    this.results = [];
197
    this.searchUtils.totalResults = 0;
198
    this.loadPaging = false;
199 58275 k.triantaf
200
    if (id != "") {
201
202
      this._searchDataprovidersService.searchDataprovidersForDeposit(id, type, page, size, properties).subscribe(
203
        data => {
204
          this.searchUtils.totalResults = data[0];
205
          //console.info("search Dataproviders forDeposit: [id:"+id+", type:"+type+" ]  [total results:"+this.searchUtils.totalResults+"]");
206
          this.results = data[1];
207
208
          //var errorCodes:ErrorCodes = new ErrorCodes();
209
          this.searchUtils.status = this.errorCodes.DONE;
210
          if (this.searchUtils.totalResults == 0) {
211
            this.searchUtils.status = this.errorCodes.NONE;
212 50169 argiro.kok
          }
213 58275 k.triantaf
214
          if (this.searchUtils.status == this.errorCodes.DONE) {
215
            // Page out of limit!!!
216
            let totalPages: any = this.searchUtils.totalResults / (this.searchUtils.size);
217
            if (!(Number.isInteger(totalPages))) {
218
              totalPages = (parseInt(totalPages, 10) + 1);
219
            }
220
            if (totalPages < page) {
221
              this.searchUtils.totalResults = 0;
222
              this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
223
            }
224
          }
225
          this.loadPaging = true;
226
          this.oldTotalResults = this.searchUtils.totalResults;
227
        },
228
        err => {
229
          /*console.log(err);
230
           //TODO check erros (service not available, bad request)
231
          // if( ){
232
          //   this.searchUtils.status = ErrorCodes.ERROR;
233
          // }
234
          //var errorCodes:ErrorCodes = new ErrorCodes();
235
          //this.searchUtils.status = errorCodes.ERROR;
236
          if(err.status == '404') {
237
            this.searchUtils.status = this.errorCodes.NOT_FOUND;
238
          } else if(err.status == '500') {
239
            this.searchUtils.status = this.errorCodes.ERROR;
240
          } else {
241
            this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
242
          }*/
243
          this.handleError("Error getting content providers in share " + type + " for organization with id: " + id, err);
244
          this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
245
246
          this.loadPaging = true;
247
          this.oldTotalResults = 0;
248
        }
249 50169 argiro.kok
      );
250 58275 k.triantaf
    }
251 50169 argiro.kok
  }
252 58275 k.triantaf
253
  public getResultsBySubjectsForDeposit(subject: string, type: string, page: number, size: number, properties: EnvProperties) {
254 50169 argiro.kok
    //var errorCodes:ErrorCodes = new ErrorCodes();
255 58275 k.triantaf
256 50169 argiro.kok
    this.searchUtils.status = this.errorCodes.LOADING;
257 54755 konstantin
    this.results = [];
258
    this.searchUtils.totalResults = 0;
259
    this.loadPaging = false;
260 58275 k.triantaf
261
    this._searchDataprovidersService.searchDataProvidersBySubjects(subject, type, page, size, properties).subscribe(
262
      data => {
263
        this.searchUtils.totalResults = data[0];
264
        //console.info("search Dataproviders forDeposit: [subject:"+subject+", type:"+type+" ]  [total results:"+this.searchUtils.totalResults+"]");
265
        this.results = data[1];
266
267
        //var errorCodes:ErrorCodes = new ErrorCodes();
268
        this.searchUtils.status = this.errorCodes.DONE;
269
        if (this.searchUtils.totalResults == 0) {
270
          this.searchUtils.status = this.errorCodes.NONE;
271
        }
272
        if (this.searchUtils.status == this.errorCodes.DONE) {
273
          // Page out of limit!!!
274
          let totalPages: any = this.searchUtils.totalResults / (this.searchUtils.size);
275
          if (!(Number.isInteger(totalPages))) {
276
            totalPages = (parseInt(totalPages, 10) + 1);
277 50169 argiro.kok
          }
278 58275 k.triantaf
          if (totalPages < page) {
279
            this.searchUtils.totalResults = 0;
280
            this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
281
          }
282
        }
283
        this.loadPaging = true;
284
        this.oldTotalResults = this.searchUtils.totalResults;
285
      },
286
      err => {
287
        /*console.log(err);
288
         //TODO check erros (service not available, bad request)
289
        // if( ){
290
        //   this.searchUtils.status = ErrorCodes.ERROR;
291
        // }
292
        //var errorCodes:ErrorCodes = new ErrorCodes();
293
        //this.searchUtils.status = errorCodes.ERROR;
294
        if(err.status == '404') {
295
          this.searchUtils.status = this.errorCodes.NOT_FOUND;
296
        } else if(err.status == '500') {
297
          this.searchUtils.status = this.errorCodes.ERROR;
298
        } else {
299
          this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
300
        }*/
301
        this.handleError("Error getting content providers in share " + type + " by subject: " + subject, err);
302
        this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
303
304
        this.loadPaging = true;
305
        this.oldTotalResults = 0;
306
      }
307
    );
308
309
  }
310
311
  public getResultsForEntity(entity: string, id: string, page: number, size: number, properties: EnvProperties) {
312
    //var errorCodes:ErrorCodes = new ErrorCodes();
313
    this.searchUtils.status = this.errorCodes.LOADING;
314
315 50169 argiro.kok
    var parameters = "";
316 58275 k.triantaf
317
    if (entity == "organization") {
318
      parameters = "organizations/" + id;
319 50169 argiro.kok
    }
320 58275 k.triantaf
321
    if (parameters != "") {
322
323
      this._searchDataprovidersService.searchDataprovidersForEntity(parameters, page, size, properties).subscribe(
324 50169 argiro.kok
        data => {
325 58275 k.triantaf
          this.searchUtils.totalResults = data[0];
326
          //console.info("search Dataproviders for "+entity+": [Parameters:"+parameters+" ]  [total results:"+this.searchUtils.totalResults+"]");
327
          this.results = data[1];
328
329
          //var errorCodes:ErrorCodes = new ErrorCodes();
330
          this.searchUtils.status = this.errorCodes.DONE;
331
          if (this.searchUtils.totalResults == 0) {
332
            this.searchUtils.status = this.errorCodes.NONE;
333
          }
334 50169 argiro.kok
        },
335
        err => {
336 58275 k.triantaf
          /*console.log(err);
337
           //TODO check erros (service not available, bad request)
338
          // if( ){
339
          //   this.searchUtils.status = ErrorCodes.ERROR;
340
          // }
341
          //var errorCodes:ErrorCodes = new ErrorCodes();
342
          //this.searchUtils.status = errorCodes.ERROR;
343
          if(err.status == '404') {
344
            this.searchUtils.status = this.errorCodes.NOT_FOUND;
345
          } else if(err.status == '500') {
346
            this.searchUtils.status = this.errorCodes.ERROR;
347
          } else {
348
            this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
349
          }*/
350
          this.handleError("Error getting content providers for " + entity + " with id: " + id, err);
351
          this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
352 50169 argiro.kok
        }
353 58275 k.triantaf
      );
354
    }
355
  }
356
357
  public getResultsForDataproviders(id: string, page: number, size: number, properties: EnvProperties) {
358
    //var errorCodes:ErrorCodes = new ErrorCodes();
359
    this.searchUtils.status = this.errorCodes.LOADING;
360
361
    this._searchDataprovidersService.getDataProvidersforEntityRegistry(id, page, size, properties).subscribe(
362
      data => {
363
        this.searchUtils.totalResults = data[0];
364
        //console.info("search Dataproviders for Entity Registry: [Id:"+id+" ]  [total results:"+this.searchUtils.totalResults+"]");
365
        this.results = data[1];
366
367
        //var errorCodes:ErrorCodes = new ErrorCodes();
368
        this.searchUtils.status = this.errorCodes.DONE;
369
        if (this.searchUtils.totalResults == 0) {
370
          this.searchUtils.status = this.errorCodes.NONE;
371
        }
372
      },
373
      err => {
374
        /*console.log(err);
375
         //TODO check erros (service not available, bad request)
376
        // if( ){
377
        //   this.searchUtils.status = ErrorCodes.ERROR;
378
        // }
379
        //var errorCodes:ErrorCodes = new ErrorCodes();
380
        //this.searchUtils.status = errorCodes.ERROR;
381
        if(err.status == '404') {
382
          this.searchUtils.status = this.errorCodes.NOT_FOUND;
383
        } else if(err.status == '500') {
384
          this.searchUtils.status = this.errorCodes.ERROR;
385
        } else {
386
          this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
387
        }*/
388
        this.handleError("Error getting content providers for entity registry with id: " + id, err);
389
        this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
390
      }
391 50169 argiro.kok
    );
392
  }
393 58275 k.triantaf
394 54870 konstantin
  private handleError(message: string, error) {
395 58275 k.triantaf
    console.error("Fetch Content Providers (class): " + message, error);
396 54870 konstantin
  }
397 50169 argiro.kok
}