1
|
import {Component, Input, ViewChild} from '@angular/core';
|
2
|
import {Location} from '@angular/common';
|
3
|
import { ActivatedRoute} from '@angular/router';
|
4
|
import { Filter, Value} from '../searchUtils/searchHelperClasses.class';
|
5
|
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
6
|
import {SearchResult} from '../../utils/entities/searchResult';
|
7
|
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
|
8
|
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
|
9
|
import {SearchPageComponent } from '../searchUtils/searchPage.component';
|
10
|
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
|
11
|
|
12
|
@Component({
|
13
|
selector: 'search-content-providers',
|
14
|
template: `
|
15
|
|
16
|
<search-page pageTitle="OpenAIRE Content Providers"
|
17
|
formPlaceholderText = "Search for OpenAIRE Content Providers"
|
18
|
type="content providers" entityType="dataprovider" [(filters)] = "filters"
|
19
|
[(results)] = "results" [(searchUtils)] = "searchUtils"
|
20
|
[baseUrl] = "baseUrl" [showResultCount]=false
|
21
|
(queryChange)="queryChanged($event)"
|
22
|
[csvParams]="csvParams" csvPath="resources"
|
23
|
[disableForms]="disableForms"
|
24
|
[tableViewLink]="'/search/content-providers-table'"
|
25
|
searchFormClass="compatibleDatasourcesSearchForm">
|
26
|
</search-page>
|
27
|
|
28
|
`
|
29
|
|
30
|
})
|
31
|
export class SearchCompatibleDataprovidersComponent {
|
32
|
private errorCodes: ErrorCodes;
|
33
|
public results =[];
|
34
|
public filters =[];
|
35
|
public baseUrl:string;
|
36
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
37
|
public sub: any; public subResults: any;
|
38
|
public _location:Location;
|
39
|
public searchFields:SearchFields = new SearchFields();
|
40
|
public refineFields: string[] = this.searchFields.COMPATIBLE_DATAPROVIDER_FIELDS;
|
41
|
public fieldIdsMap= this.searchFields.DATASOURCE_FIELDS;
|
42
|
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"]}];
|
43
|
// ["entityregistry","entityregistry::projects","entityregistry::repositories"]}];
|
44
|
public _prefixQuery: string = "";
|
45
|
|
46
|
public CSV: any = { "columnNames": [ "Title", "Type", "Coutries", "Compatibility" ],
|
47
|
"export":[]
|
48
|
};
|
49
|
public CSVDownloaded = false;
|
50
|
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"))';
|
51
|
public csvParams: string;
|
52
|
public disableForms: boolean = false;
|
53
|
|
54
|
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
55
|
|
56
|
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
|
57
|
this.errorCodes = new ErrorCodes();
|
58
|
this.searchUtils.status = this.errorCodes.LOADING;
|
59
|
this.baseUrl = OpenaireProperties.getLinkToSearchCompatibleDataProviders();
|
60
|
for(var i = 0; i < this._prefixQueryFields.length; i++ ){
|
61
|
for(var j =0; j < this._prefixQueryFields[i].values.length; j++){
|
62
|
this._prefixQuery+="&" + this._prefixQueryFields[i].field + "="
|
63
|
+ this._prefixQueryFields[i].values[j] + "&" +
|
64
|
this._prefixQueryFields[i].opName + "=" + this._prefixQueryFields[i].opValue;
|
65
|
}
|
66
|
}
|
67
|
this._prefixQuery+="&";
|
68
|
}
|
69
|
|
70
|
public ngOnInit() {
|
71
|
this.searchPage.refineFields = this.refineFields;
|
72
|
this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
73
|
this.sub = this.route.queryParams.subscribe(params => {
|
74
|
this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
|
75
|
this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
|
76
|
this.filters = this.createFilters();
|
77
|
var queryParameters = this.searchPage.getIndexQueryParametersFromUrl(params);
|
78
|
console.info("|"+queryParameters+"|");
|
79
|
this._getResults(queryParameters, false, this.searchUtils.page, this.searchUtils.size);
|
80
|
});
|
81
|
}
|
82
|
|
83
|
public ngOnDestroy() {
|
84
|
if(this.sub){
|
85
|
this.sub.unsubscribe();
|
86
|
}
|
87
|
if(this.subResults){
|
88
|
this.subResults.unsubscribe();
|
89
|
} }
|
90
|
private _getResults(parameters:string,refine:boolean, page: number, size: number){
|
91
|
this.csvParams = parameters+this.resourcesQuery+"&type=datasources";
|
92
|
|
93
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
94
|
this.searchUtils.status = this.errorCodes.LOADING;
|
95
|
//this.searchPage.openLoading();
|
96
|
this.disableForms = true;
|
97
|
this.results = [];
|
98
|
this.searchUtils.totalResults = 0;
|
99
|
|
100
|
this.subResults = this._searchDataprovidersService.searchCompatibleDataproviders(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, []).subscribe(
|
101
|
data => {
|
102
|
this.searchUtils.totalResults = data[0];
|
103
|
console.info("search Content Providers: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
104
|
this.results = data[1];
|
105
|
this.searchPage.checkSelectedFilters(this.filters);
|
106
|
this.searchPage.updateBaseUrlWithParameters(this.filters);
|
107
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
108
|
this.searchUtils.status = this.errorCodes.DONE;
|
109
|
if(this.searchUtils.totalResults == 0 ){
|
110
|
this.searchUtils.status = this.errorCodes.NONE;
|
111
|
}
|
112
|
//this.searchPage.closeLoading();
|
113
|
this.disableForms = false;
|
114
|
|
115
|
},
|
116
|
err => {
|
117
|
console.log(err);
|
118
|
//TODO check erros (service not available, bad request)
|
119
|
// if( ){
|
120
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
121
|
// }
|
122
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
123
|
//this.searchUtils.status = errorCodes.ERROR;
|
124
|
if(err.status == '404') {
|
125
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
126
|
} else if(err.status == '500') {
|
127
|
this.searchUtils.status = this.errorCodes.ERROR;
|
128
|
} else {
|
129
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
130
|
}
|
131
|
|
132
|
//this.searchPage.closeLoading();
|
133
|
this.disableForms = false;
|
134
|
|
135
|
}
|
136
|
);
|
137
|
}
|
138
|
private setFilters(){
|
139
|
//TODO set filters from
|
140
|
}
|
141
|
|
142
|
public queryChanged($event) {
|
143
|
var parameters = $event.index;
|
144
|
console.info("queryChanged: Execute search query "+parameters);
|
145
|
|
146
|
this._getResults(parameters, false, this.searchUtils.page, this.searchUtils.size);
|
147
|
}
|
148
|
private createFilters():Filter[] {
|
149
|
var filter_names=["Type","Compatibility Level"];
|
150
|
var filter_ids=["datasourcetypeuiid","datasourcecompatibilityname"];
|
151
|
var searchFields = new SearchFields();
|
152
|
var filter_original_ids = searchFields.COMPATIBLE_DATAPROVIDER_FIELDS;
|
153
|
var value_names=[
|
154
|
/*[
|
155
|
"Institutional Publication Repository","Thematic Publication Repository", "Other Publication Repository",
|
156
|
"Institutional Repositories Aggregators",
|
157
|
"Thematic Repositories Aggregators", "Other Repositories Aggregators",
|
158
|
"Data Repositories", "Data Repositories Aggregators", "Journals", "Journals Aggregators", "CRIS Systems", "Publication Catalogues"],
|
159
|
*/
|
160
|
[
|
161
|
"Institutional Repository", "Thematic Repository", "Publication Repository",
|
162
|
"Institutional Repository Aggregator",
|
163
|
"Thematic Repositories Aggregators", "Publication Repository Aggregator",
|
164
|
"Data Repository", "Data Repository Aggregator", "CRIS Systems", "Publication Catalogue"],
|
165
|
["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)"]];
|
166
|
|
167
|
var value_original_ids=[
|
168
|
["pubsrepository::institutional","pubsrepository::thematic", "pubsrepository::unknown", "aggregator::pubsrepository::institutional","aggregator::pubsrepository::thematic","aggregator::pubsrepository::unknown",
|
169
|
"datarepository::unknown", "aggregator::datarepository", "cris", "pubscatalogue::unknown"],
|
170
|
//["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]
|
171
|
["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)"]];
|
172
|
var filters: Filter[] =[];
|
173
|
for(var i =0 ; i < filter_names.length;i++){
|
174
|
var values:Value[] = [];
|
175
|
for(var j =0 ; j < value_names[i].length;j++){
|
176
|
var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false}
|
177
|
values.push(value);
|
178
|
}
|
179
|
var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId: filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or' };
|
180
|
filters.push(filter);
|
181
|
}
|
182
|
return filters;
|
183
|
}
|
184
|
}
|