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 {ErrorCodes} from '../../utils/properties/errorCodes';
9
import {ErrorMessagesComponent}    from '../../utils/errorMessages.component';
10
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
11
import {SearchPageComponent } from '../searchUtils/searchPage.component';
12
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
13
import{EnvProperties} from '../../utils/properties/env-properties';
14

    
15
@Component({
16
    selector: 'search-journals',
17
    template: `
18

    
19
    <search-page    pageTitle="OpenAIRE Journals"
20
                    formPlaceholderText = "Search for OpenAIRE Journals"
21
                    type="content providers" entityType="dataprovider" [(filters)] = "filters"
22
                    [(results)] = "results"  [(searchUtils)] = "searchUtils"
23
                    [baseUrl] = "baseUrl" [showResultCount]=false
24
                    
25
                    [csvParams]="csvParams" csvPath="datasources"
26
                    [disableForms]="disableForms"
27
                    searchFormClass="journalsSearchForm"
28
                    [mapUrl]="mapUrl" [mapTooltipType]="'journals'"
29
                    [newQueryButton]="false">
30
    </search-page>
31
    <!--[tableViewLink]="'/search/journals-table'"-->
32
    `
33

    
34
})
35
export class SearchJournalsComponent {
36
  private errorCodes: ErrorCodes;
37
  private errorMessages: ErrorMessagesComponent;
38
  public results =[];
39
  public filters =[];
40
  public baseUrl:string;
41
  public searchUtils:SearchUtilsClass = new SearchUtilsClass();
42
  public sub: any; public subResults: any;
43
  public _location:Location;
44
  public searchFields:SearchFields = new SearchFields();
45
  public refineFields: string[] =  this.searchFields.JOURNAL_FIELDS;
46
  public fieldIdsMap= this.searchFields.DATASOURCE_FIELDS;
47
  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"]}];
48
  // ["entityregistry","entityregistry::projects","entityregistry::repositories"]}];
49
  public _prefixQuery: string = "";
50

    
51
  public CSV: any = {  "columnNames":  [ "Title", "Type", "Coutries", "Compatibility" ],
52
                        "export":[]
53
                     };
54
  public resourcesQuery = '((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) and (datasourcetypeuiid exact "pubsrepository::journal" or datasourcetypeuiid exact "aggregator::pubsrepository::journals" ))';
55
  //"&query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) not(datasourcetypeuiid = other))";
56
  public csvParams: string;
57
  public disableForms: boolean = false;
58
  public mapUrl: string;
59
properties:EnvProperties;
60
  @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
61

    
62
  constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
63
    this.errorCodes = new ErrorCodes();
64
    this.errorMessages = new ErrorMessagesComponent();
65
    this.searchUtils.status = this.errorCodes.LOADING;
66
    for(var i = 0; i < this._prefixQueryFields.length; i++ ){
67
      for(var j =0; j < this._prefixQueryFields[i].values.length; j++){
68
        this._prefixQuery+="&" + this._prefixQueryFields[i].field + "="
69
        + this._prefixQueryFields[i].values[j] + "&" +
70
        this._prefixQueryFields[i].opName + "=" + this._prefixQueryFields[i].opValue;
71
      }
72
    }
73
    this._prefixQuery+="&";
74
  }
75

    
76
  public ngOnInit() {
77
    this.route.data
78
      .subscribe((data: { envSpecific: EnvProperties }) => {
79
        this.properties = data.envSpecific;
80
        this.baseUrl = data.envSpecific.searchLinkToJournals;
81
        this.mapUrl = this.properties.statisticsFrameAPIURL+"markers-test.html?show=journals";
82

    
83
      });
84
    this.searchPage.refineFields = this.refineFields;
85
    this.searchPage.fieldIdsMap = this.fieldIdsMap;
86
    this.sub =  this.route.queryParams.subscribe(params => {
87
      this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
88
      this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
89
      this.filters = this.createFilters();
90
      var queryParameters = this.searchPage.getIndexQueryParametersFromUrl(params);
91
      //console.info("|"+queryParameters+"|");
92
      var csvParameters = this.searchPage.getQueryParametersFromUrl(params);
93

    
94
      this._getResults(queryParameters, csvParameters, false, this.searchUtils.page, this.searchUtils.size);
95
    });
96
  }
97

    
98
  public ngOnDestroy() {
99
    if(this.sub){
100
      this.sub.unsubscribe();
101
    }
102
    if(this.subResults){
103
      this.subResults.unsubscribe();
104
    }  }
105
    private _getResults(parameters:string, csv_parameters:string, refine:boolean, page: number, size: number){
106
      if(csv_parameters.indexOf("fq=") != -1) {
107
        this.csvParams = csv_parameters+" and "+this.resourcesQuery;
108
      } else {
109
        this.csvParams = csv_parameters+"&fq="+this.resourcesQuery;
110
      }
111

    
112
      //var errorCodes:ErrorCodes = new ErrorCodes();
113
      this.searchUtils.status = this.errorCodes.LOADING;
114
      //this.searchPage.openLoading();
115
      this.disableForms = true;
116
      this.results = [];
117
      this.searchUtils.totalResults = 0;
118

    
119
      this.subResults = this._searchDataprovidersService.searchJournals(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, [],this.properties).subscribe(
120
          data => {
121
              this.searchUtils.totalResults = data[0];
122
              this.results = data[1];
123
              this.searchPage.checkSelectedFilters(this.filters);
124
              this.searchPage.updateBaseUrlWithParameters(this.filters);
125
              //var errorCodes:ErrorCodes = new ErrorCodes();
126
              this.searchUtils.status = this.errorCodes.DONE;
127
              if(this.searchUtils.totalResults == 0 ){
128
                this.searchUtils.status = this.errorCodes.NONE;
129
              }
130
              //this.searchPage.closeLoading();
131
              this.disableForms = false;
132

    
133
          },
134
          err => {
135
              //console.log(err);
136
              this.handleError("Error getting journals", err);
137
              this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
138

    
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

    
153
              //this.searchPage.closeLoading();
154
              this.disableForms = false;
155

    
156
          }
157
      );
158
    }
159
  private setFilters(){
160
    //TODO set filters from
161
  }
162

    
163
  private createFilters():Filter[] {
164
    var filter_names=["Type","Compatibility Level"];
165
    var filter_ids=["datasourcetypeuiid","datasourcecompatibilityname"];
166
    var searchFields = new SearchFields();
167
    var filter_original_ids = searchFields.JOURNAL_FIELDS;
168
    var value_names=[
169
      /*[
170
      "Institutional Publication Repository","Thematic Publication Repository", "Other Publication Repository",
171
     "Institutional Repositories Aggregators",
172
     "Thematic Repositories Aggregators", "Other Repositories Aggregators",
173
      "Data Repositories", "Data Repositories Aggregators", "Journals", "Journals Aggregators", "CRIS Systems", "Publication Catalogues"],
174
      */
175
      ["Journal", "Journal Aggregator\/Publisher"],
176
      ["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)",
177
       "collected from a compatible aggregator", "proprietary", "under validation"]];
178

    
179
    var value_original_ids=[
180
      ["pubsrepository::journal", "aggregator::pubsrepository::journals"],
181
      //["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]
182
    ["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)",
183
     "collected from a compatible aggregator", "proprietary", "under validation"]];
184
    var filters: Filter[] =[];
185
    for(var i =0 ; i < filter_names.length;i++){
186
      var values:Value[] = [];
187
      for(var j =0 ; j < value_names[i].length;j++){
188
        var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false}
189
        values.push(value);
190
      }
191
       var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId:  filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or', valueIsExact: true, filterType: "checkbox" };
192
       filters.push(filter);
193
    }
194
    return filters;
195
    }
196

    
197
    private handleError(message: string, error) {
198
      console.error("Journals Search Page: "+message, error);
199
    }
200
}
(9-9/12)