Project

General

Profile

1
import {Component, Input, ViewChild} from '@angular/core';
2
import { ActivatedRoute} from '@angular/router';
3

    
4
import { Filter, Value} from '../searchUtils/searchHelperClasses.class';
5

    
6
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
7
import {SearchResult}     from '../../utils/entities/searchResult';
8
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
9
import {SearchFields} from '../../utils/properties/searchFields';
10
import {SearchPageComponent } from '../searchUtils/searchPage.component';
11
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
12

    
13
@Component({
14
    selector: 'search-content-providers',
15
    template: `
16

    
17
    <search-page    pageTitle="OpenAIRE Content Providers"
18
                    formPlaceholderText = "Search for OpenAIRE Content Providers"
19
                    type="content providers" entityType="dataprovider" [(filters)] = "filters"
20
                    [(results)] = "results"  [(searchUtils)] = "searchUtils"
21
                    [baseUrl] = "baseUrl" [showResultCount]=false
22
                    (queryChange)="queryChanged($event)"
23
                    [csvParams]="csvParams" csvPath="resources"
24
                    [disableForms]="disableForms"
25
                    [tableViewLink]="'/search/content-providers-table'"
26
                    searchFormClass="compatibleDatasourcesSearchForm">
27
    </search-page>
28
    <!--table-view  [(datasources)] = results></table-view-->
29

    
30
    `
31

    
32
})
33
export class SearchCompatibleDataprovidersComponent {
34
  private errorCodes: ErrorCodes;
35
  public results =[];
36
  public filters =[];
37
  public baseUrl:string;
38
  public searchUtils:SearchUtilsClass = new SearchUtilsClass();
39
  public sub: any; public subResults: any;
40
  public _location:Location;
41
  public searchFields:SearchFields = new SearchFields();
42
  public refineFields: string[] =  this.searchFields.COMPATIBLE_DATAPROVIDER_FIELDS;
43
  public fieldIdsMap= this.searchFields.DATASOURCE_FIELDS;
44
  public _prefixQueryFields: {field:string,opName:string,opValue:string,values:string[]}[] =[{field:"compatibility",opName:"cm",opValue:"not", values:["UNKNOWN","hostedBy","notCompatible"]},{field:"type",opName:"tp",opValue:"not",values: ["other"]}];
45
  // ["entityregistry","entityregistry::projects","entityregistry::repositories"]}];
46
  public _prefixQuery: string = "";
47

    
48
  public CSV: any = {  "columnNames":  [ "Title", "Type", "Coutries", "Compatibility" ],
49
                        "export":[]
50
                     };
51
  public CSVDownloaded = false;
52
  public resourcesQuery = '&query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) not(datasourcetypeuiid = other) not(datasourcetypeuiid exact "pubsrepository::journal") not(datasourcetypeuiid exact "aggregator::pubsrepository::journals"))';
53
  public csvParams: string;
54
  public disableForms: boolean = false;
55

    
56
  @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
57

    
58
  constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
59
    this.errorCodes = new ErrorCodes();
60
    this.searchUtils.status = this.errorCodes.LOADING;
61
    this.baseUrl = OpenaireProperties.getLinkToSearchCompatibleDataProviders();
62
    for(var i = 0; i < this._prefixQueryFields.length; i++ ){
63
      for(var j =0; j < this._prefixQueryFields[i].values.length; j++){
64
        this._prefixQuery+="&" + this._prefixQueryFields[i].field + "="
65
        + this._prefixQueryFields[i].values[j] + "&" +
66
        this._prefixQueryFields[i].opName + "=" + this._prefixQueryFields[i].opValue;
67
      }
68
    }
69
    this._prefixQuery+="&";
70
  }
71

    
72
  public ngOnInit() {
73
    this.searchPage.refineFields = this.refineFields;
74
    this.searchPage.fieldIdsMap = this.fieldIdsMap;
75
    this.sub =  this.route.queryParams.subscribe(params => {
76
      this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
77
      this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
78
      this.filters = this.createFilters();
79
      var queryParameters = this.searchPage.getIndexQueryParametersFromUrl(params);
80
      console.info("|"+queryParameters+"|");
81
      this._getResults(queryParameters, false, this.searchUtils.page, this.searchUtils.size);
82
    });
83
  }
84

    
85
  public ngOnDestroy() {
86
    if(this.sub){
87
      this.sub.unsubscribe();
88
    }
89
    if(this.subResults){
90
      this.subResults.unsubscribe();
91
    }  }
92
    private _getResults(parameters:string,refine:boolean, page: number, size: number){
93
        this.csvParams = parameters+this.resourcesQuery+"&type=datasources";
94

    
95
      //var errorCodes:ErrorCodes = new ErrorCodes();
96
      this.searchUtils.status = this.errorCodes.LOADING;
97
      //this.searchPage.openLoading();
98
      this.disableForms = true;
99
      this.results = [];
100
      this.searchUtils.totalResults = 0;
101

    
102
      this.subResults = this._searchDataprovidersService.searchCompatibleDataproviders(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, []).subscribe(
103
          data => {
104
              this.searchUtils.totalResults = data[0];
105
              console.info("search Content Providers: [Parameters:"+parameters+" ]  [total results:"+this.searchUtils.totalResults+"]");
106
              this.results = data[1];
107
              this.searchPage.checkSelectedFilters(this.filters);
108
              this.searchPage.updateBaseUrlWithParameters(this.filters);
109
              //var errorCodes:ErrorCodes = new ErrorCodes();
110
              this.searchUtils.status = this.errorCodes.DONE;
111
              if(this.searchUtils.totalResults == 0 ){
112
                this.searchUtils.status = this.errorCodes.NONE;
113
              }
114
              //this.searchPage.closeLoading();
115
              this.disableForms = false;
116

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

    
134
              //this.searchPage.closeLoading();
135
              this.disableForms = false;
136

    
137
          }
138
      );
139
    }
140
  private setFilters(){
141
    //TODO set filters from
142
  }
143

    
144
  public queryChanged($event) {
145
    var parameters = $event.index;
146
    console.info("queryChanged: Execute search query "+parameters);
147

    
148
    this._getResults(parameters, false, this.searchUtils.page, this.searchUtils.size);
149
  }
150
  private createFilters():Filter[] {
151
    var filter_names=["Type","Compatibility Level"];
152
    var filter_ids=["datasourcetypeuiid","datasourcecompatibilityname"];
153
    var searchFields = new SearchFields();
154
    var filter_original_ids = searchFields.COMPATIBLE_DATAPROVIDER_FIELDS;
155
    var value_names=[
156
      /*[
157
      "Institutional Publication Repository","Thematic Publication Repository", "Other Publication Repository",
158
     "Institutional Repositories Aggregators",
159
     "Thematic Repositories Aggregators", "Other Repositories Aggregators",
160
      "Data Repositories", "Data Repositories Aggregators", "Journals", "Journals Aggregators", "CRIS Systems", "Publication Catalogues"],
161
      */
162
      [
163
      "Institutional Repository", "Thematic Repository", "Publication Repository",
164
      "Institutional Repository Aggregator",
165
      "Thematic Repositories Aggregators", "Publication Repository Aggregator",
166
      "Data Repository", "Data Repository Aggregator", "CRIS Systems", "Publication Catalogue"],
167
      ["OpenAIRE Basic (DRIVER OA)","OpenAIRE 2.0 (EC funding)", "OpenAIRE 2.0+ (DRIVER OA, EC funding)", "OpenAIRE 3.0 (OA, funding)","OpenAIRE Data (funded, referenced datasets)"]];
168

    
169
    var value_original_ids=[
170
      ["pubsrepository::institutional","pubsrepository::thematic", "pubsrepository::unknown", "aggregator::pubsrepository::institutional","aggregator::pubsrepository::thematic","aggregator::pubsrepository::unknown",
171
      "datarepository::unknown", "aggregator::datarepository", "cris", "pubscatalogue::unknown"],
172
      //["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]
173
    ["OpenAIRE Basic (DRIVER OA)","OpenAIRE 2.0 (EC funding)", "OpenAIRE 2.0+ (DRIVER OA, EC funding)", "OpenAIRE 3.0 (OA, funding)","OpenAIRE Data (funded, referenced datasets)"]];
174
    var filters: Filter[] =[];
175
    for(var i =0 ; i < filter_names.length;i++){
176
      var values:Value[] = [];
177
      for(var j =0 ; j < value_names[i].length;j++){
178
        var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false}
179
        values.push(value);
180
      }
181
       var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId:  filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or' };
182
       filters.push(filter);
183
    }
184
    return filters;
185
    }
186
}
(2-2/18)