Project

General

Profile

1
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
2
import { ErrorCodes} from '../../utils/properties/openaireProperties';
3
import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class';
4

    
5
export class FetchDataproviders {
6
  private errorCodes: ErrorCodes;
7

    
8
  public results =[];
9
  public searchUtils:SearchUtilsClass = new SearchUtilsClass();
10
  public sub: any; public subResults: any;
11
  public CSV: any = {  "columnNames":  [ "Title", "Type", "Coutries", "Compatibility" ],
12
                        "export":[]
13
                     };
14
  public CSVDownloaded = false;
15
  public csvParams: string;
16

    
17

    
18
  constructor ( private _searchDataprovidersService: SearchDataprovidersService ) {
19
    this.errorCodes = new ErrorCodes();
20
    this.searchUtils.status = this.errorCodes.LOADING;
21
   }
22

    
23

    
24
  public ngOnDestroy() {
25
    if(this.sub){
26
      this.sub.unsubscribe();
27
    }
28
    if(this.subResults){
29
      this.subResults.unsubscribe();
30
    }
31
  }
32

    
33
  public getResultsByKeyword(keyword:string, page: number, size: number){
34
    var parameters = "";
35
    if(keyword.length > 0){
36
      parameters = "q=" + keyword;
37
    }
38

    
39
    //var errorCodes:ErrorCodes = new ErrorCodes();
40
    this.searchUtils.status = this.errorCodes.LOADING;
41

    
42

    
43
    this.subResults = this._searchDataprovidersService.searchDataproviders(parameters,null, page, size,[]).subscribe(
44
        data => {
45
            this.searchUtils.totalResults = data[0];
46
            console.info("search Content Providers: [Parameters:"+parameters+" ]  [total results:"+this.searchUtils.totalResults+"]");
47
            this.results = data[1];
48

    
49
            //ar errorCodes:ErrorCodes = new ErrorCodes();
50
            this.searchUtils.status = this.errorCodes.DONE;
51
            if(this.searchUtils.totalResults == 0 ){
52
              this.searchUtils.status = this.errorCodes.NONE;
53
            }
54
        },
55
        err => {
56
            console.log(err);
57
             //TODO check erros (service not available, bad request)
58
            // if( ){
59
            //   this.searchUtils.status = ErrorCodes.ERROR;
60
            // }
61
            //var errorCodes:ErrorCodes = new ErrorCodes();
62
            //this.searchUtils.status = errorCodes.ERROR;
63
            if(err.status == '404') {
64
              this.searchUtils.status = this.errorCodes.NOT_FOUND;
65
            } else if(err.status == '500') {
66
              this.searchUtils.status = this.errorCodes.ERROR;
67
            } else {
68
              this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
69
            }
70
        }
71
    );
72
  }
73

    
74
  public getNumForEntity(entity: string, id:string) {
75
      //var errorCodes:ErrorCodes = new ErrorCodes();
76
      this.searchUtils.status = this.errorCodes.LOADING;
77

    
78
      if(id != "" && entity != "") {
79

    
80
          this._searchDataprovidersService.numOfEntityDataproviders(id, entity).subscribe(
81
              data => {
82
                  this.searchUtils.totalResults = data;
83

    
84
                  //var errorCodes:ErrorCodes = new ErrorCodes();
85
                  this.searchUtils.status = this.errorCodes.DONE;
86
                  if(this.searchUtils.totalResults == 0 ){
87
                    this.searchUtils.status = this.errorCodes.NONE;
88
                  }
89
              },
90
              err => {
91
                  console.log(err);
92
                   //TODO check erros (service not available, bad request)
93
                  // if( ){
94
                  //   this.searchUtils.status = ErrorCodes.ERROR;
95
                  // }
96
                  //var errorCodes:ErrorCodes = new ErrorCodes();
97
                  //this.searchUtils.status = errorCodes.ERROR;
98
                  if(err.status == '404') {
99
                    this.searchUtils.status = this.errorCodes.NOT_FOUND;
100
                  } else if(err.status == '500') {
101
                    this.searchUtils.status = this.errorCodes.ERROR;
102
                  } else {
103
                    this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
104
                  }
105
              }
106
          );
107
      }
108
  }
109

    
110
  public getNumForSearch(keyword: string) {
111
      //var errorCodes:ErrorCodes = new ErrorCodes();
112
      this.searchUtils.status = this.errorCodes.LOADING;
113

    
114
      this._searchDataprovidersService.numOfSearchDataproviders(keyword).subscribe(
115
          data => {
116
              this.searchUtils.totalResults = data;
117
              this.searchUtils.status = this.errorCodes.DONE;
118

    
119
              if(this.searchUtils.totalResults == 0) {
120
                this.searchUtils.status = this.errorCodes.NONE;
121
              }
122
          },
123
          err => {
124
              console.log(err);
125
               //TODO check erros (service not available, bad request)
126
              // if( ){
127
              //   this.searchUtils.status = ErrorCodes.ERROR;
128
              // }
129
              //var errorCodes:ErrorCodes = new ErrorCodes();
130
              //this.searchUtils.status = errorCodes.ERROR;
131
              if(err.status == '404') {
132
                this.searchUtils.status = this.errorCodes.NOT_FOUND;
133
              } else if(err.status == '500') {
134
                this.searchUtils.status = this.errorCodes.ERROR;
135
              } else {
136
                this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
137
              }
138
          }
139
      );
140
  }
141

    
142
public getResultsForDeposit(id:string, type:string, page: number,  size: number){
143
    //var errorCodes:ErrorCodes = new ErrorCodes();
144
    this.searchUtils.status = this.errorCodes.LOADING;
145

    
146
  if(id != "") {
147

    
148
      this._searchDataprovidersService.searchDataprovidersForDeposit(id,type, page, size).subscribe(
149
          data => {
150
              this.searchUtils.totalResults = data[0];
151
              console.info("search Dataproviders forDeposit: [id:"+id+", type:"+type+" ]  [total results:"+this.searchUtils.totalResults+"]");
152
              this.results = data[1];
153

    
154
              //var errorCodes:ErrorCodes = new ErrorCodes();
155
              this.searchUtils.status = this.errorCodes.DONE;
156
              if(this.searchUtils.totalResults == 0 ){
157
                this.searchUtils.status = this.errorCodes.NONE;
158
              }
159
          },
160
          err => {
161
              console.log(err);
162
               //TODO check erros (service not available, bad request)
163
              // if( ){
164
              //   this.searchUtils.status = ErrorCodes.ERROR;
165
              // }
166
              //var errorCodes:ErrorCodes = new ErrorCodes();
167
              //this.searchUtils.status = errorCodes.ERROR;
168
              if(err.status == '404') {
169
                this.searchUtils.status = this.errorCodes.NOT_FOUND;
170
              } else if(err.status == '500') {
171
                this.searchUtils.status = this.errorCodes.ERROR;
172
              } else {
173
                this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
174
              }
175
          }
176
      );
177
  }
178
}
179
public getResultsBySubjectsForDeposit(subject:string, type:string, page: number,  size: number){
180
    //var errorCodes:ErrorCodes = new ErrorCodes();
181
    this.searchUtils.status = this.errorCodes.LOADING;
182
      this._searchDataprovidersService.searchDataProvidersBySubjects(subject,type, page, size).subscribe(
183
          data => {
184
              this.searchUtils.totalResults = data[0];
185
              console.info("search Dataproviders forDeposit: [subject:"+subject+", type:"+type+" ]  [total results:"+this.searchUtils.totalResults+"]");
186
              this.results = data[1];
187

    
188
              //var errorCodes:ErrorCodes = new ErrorCodes();
189
              this.searchUtils.status = this.errorCodes.DONE;
190
              if(this.searchUtils.totalResults == 0 ){
191
                this.searchUtils.status = this.errorCodes.NONE;
192
              }
193
          },
194
          err => {
195
              console.log(err);
196
               //TODO check erros (service not available, bad request)
197
              // if( ){
198
              //   this.searchUtils.status = ErrorCodes.ERROR;
199
              // }
200
              //var errorCodes:ErrorCodes = new ErrorCodes();
201
              //this.searchUtils.status = errorCodes.ERROR;
202
              if(err.status == '404') {
203
                this.searchUtils.status = this.errorCodes.NOT_FOUND;
204
              } else if(err.status == '500') {
205
                this.searchUtils.status = this.errorCodes.ERROR;
206
              } else {
207
                this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
208
              }
209
          }
210
      );
211

    
212
}
213
  public getResultsForEntity(entity:string, id:string, page: number, size: number){
214
      //var errorCodes:ErrorCodes = new ErrorCodes();
215
      this.searchUtils.status = this.errorCodes.LOADING;
216

    
217
    var parameters = "";
218

    
219
    if(entity == "organization") {
220
      parameters = "organizations/"+id;
221
    }
222

    
223
    if(parameters != "") {
224

    
225
        this._searchDataprovidersService.searchDataprovidersForEntity(parameters, page, size).subscribe(
226
            data => {
227
                this.searchUtils.totalResults = data[0];
228
                console.info("search Dataproviders for "+entity+": [Parameters:"+parameters+" ]  [total results:"+this.searchUtils.totalResults+"]");
229
                this.results = data[1];
230

    
231
                //var errorCodes:ErrorCodes = new ErrorCodes();
232
                this.searchUtils.status = this.errorCodes.DONE;
233
                if(this.searchUtils.totalResults == 0 ){
234
                  this.searchUtils.status = this.errorCodes.NONE;
235
                }
236
            },
237
            err => {
238
                console.log(err);
239
                 //TODO check erros (service not available, bad request)
240
                // if( ){
241
                //   this.searchUtils.status = ErrorCodes.ERROR;
242
                // }
243
                //var errorCodes:ErrorCodes = new ErrorCodes();
244
                //this.searchUtils.status = errorCodes.ERROR;
245
                if(err.status == '404') {
246
                  this.searchUtils.status = this.errorCodes.NOT_FOUND;
247
                } else if(err.status == '500') {
248
                  this.searchUtils.status = this.errorCodes.ERROR;
249
                } else {
250
                  this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
251
                }
252
            }
253
        );
254
    }
255
  }
256

    
257
  public getResultsForDataproviders(id:string, page: number, size: number){
258
      //var errorCodes:ErrorCodes = new ErrorCodes();
259
      this.searchUtils.status = this.errorCodes.LOADING;
260

    
261
    this._searchDataprovidersService.getDataProvidersforEntityRegistry(id, page, size).subscribe(
262
        data => {
263
            this.searchUtils.totalResults = data[0];
264
            console.info("search Dataproviders for Entity Registry: [Id:"+id+" ]  [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
        },
273
        err => {
274
            console.log(err);
275
             //TODO check erros (service not available, bad request)
276
            // if( ){
277
            //   this.searchUtils.status = ErrorCodes.ERROR;
278
            // }
279
            //var errorCodes:ErrorCodes = new ErrorCodes();
280
            //this.searchUtils.status = errorCodes.ERROR;
281
            if(err.status == '404') {
282
              this.searchUtils.status = this.errorCodes.NOT_FOUND;
283
            } else if(err.status == '500') {
284
              this.searchUtils.status = this.errorCodes.ERROR;
285
            } else {
286
              this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
287
            }
288
        }
289
    );
290
  }
291
}
(1-1/6)