import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import {OpenaireProperties} from '../utils/properties/openaireProperties'; import {SearchResult} from '../utils/entities/searchResult'; import {RefineResultsUtils} from './servicesUtils/refineResults.class'; import 'rxjs/add/observable/of'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/share'; import { } from '../shared/cache.service'; import {StringUtils} from '../utils/string-utils.class'; @Injectable() export class SearchDataprovidersService { constructor(private http: Http ) {} searchDataproviders (params: string, refineParams:string, page: number, size: number, refineFields:string[] ):any { let link = OpenaireProperties. getSearchAPIURLLast()+"datasources"; let url = link+"?"; if(params!= null && params != '' ) { url += params; } if(refineParams!= null && refineParams != '' ) { url += refineParams; } url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) //.do(res => console.info(res)) .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")]); } //((oaftype exact datasource) and(collectedfromdatasourceid exact "openaire____::47ce9e9f4fad46e732cff06419ecaabb")) advancedSearchDataproviders (params: string, page: number, size: number ):any { let url = OpenaireProperties.getSearchResourcesAPIURL(); var basicQuery = "(oaftype exact datasource) " url += "?query="; if(params!= null && params != '' ) { url +=" ( "+basicQuery+ " ) " +" and (" + params + ")"; }else{ url +=" ( "+basicQuery+ " ) "; } url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) //.do(res => console.info(res)) .map(res => [res['meta'].total, this.parseResults(res['results'])]) } searchCompatibleDataprovidersTable ():any { let size: number = 0; let url: string= OpenaireProperties.getSearchResourcesAPIURL(); url += '?query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) not(datasourcetypeuiid = other) not(datasourcetypeuiid exact "pubsrepository::journal") not(datasourcetypeuiid exact "aggregator::pubsrepository::journals"))'; url += "&page=0&size=0&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url).map(res => res.json()) .map(res => res['meta'].total); } searchCompatibleDataproviders (params: string,refineParams:string, page: number, size: number, refineFields:string[] ):any { console.info("in search Compatible Dataproviders service function"); let url: string = OpenaireProperties.getSearchResourcesAPIURL(); url += '?query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) not(datasourcetypeuiid = other) not(datasourcetypeuiid exact "pubsrepository::journal") not(datasourcetypeuiid exact "aggregator::pubsrepository::journals"))'; if(params!= null && params != '' ) { url += params; } if(refineParams!= null && refineParams != '' ) { url += refineParams; } url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) //.do(res => console.info(res)) .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")]); } searchEntityRegistriesTable ():any { let size: number = 0; let url: string= OpenaireProperties.getSearchResourcesAPIURL(); url += "?query=((oaftype exact datasource) and(datasourcetypeuiid = other))"; url += "&page=0&size=0&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url).map(res => res.json()) .map(res => res['meta'].total); } searchEntityRegistries (params: string,refineParams:string, page: number, size: number, refineFields:string[] ):any { let url = OpenaireProperties.getSearchResourcesAPIURL(); url += "?query=((oaftype exact datasource) and(datasourcetypeuiid = other))"; if(params!= null && params != '' ) { url += params; } if(refineParams!= null && refineParams != '' ) { url += refineParams; } url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) //.do(res => console.info(res)) .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")]); } searchJournalsTable ():any { let size: number = 0; let url: string= OpenaireProperties.getSearchResourcesAPIURL(); url += '?query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) and (datasourcetypeuiid exact "pubsrepository::journal" or datasourcetypeuiid exact "aggregator::pubsrepository::journals" ))'; url += "&page=0&size=0&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url).map(res => res.json()) .map(res => res['meta'].total); } searchJournals (params: string,refineParams:string, page: number, size: number, refineFields:string[] ):any { console.info("in search Journals service function"); let url: string = OpenaireProperties.getSearchResourcesAPIURL(); //url += "?query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) not(datasourcetypeuiid = other))" url += '?query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) and (datasourcetypeuiid exact "pubsrepository::journal" or datasourcetypeuiid exact "aggregator::pubsrepository::journals" ))'; if(params!= null && params != '' ) { url += params; } if(refineParams!= null && refineParams != '' ) { url += refineParams; } url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) //.do(res => console.info(res)) .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")]); } searchDataprovidersForDeposit (id: string,type:string, page: number, size: number):any { let link = OpenaireProperties.getSearchResourcesAPIURL(); var compatibilities = ""; if(type == "Research Data"){ compatibilities = " and (datasourcecompatibilityid <> UNKNOWN) and (datasourcecompatibilityid = openaire2.0_data)" }else if(type == "Publications"){ compatibilities = " and (datasourcecompatibilityid <> UNKNOWN) and (datasourcecompatibilityid <> openaire2.0_data)" } let url = link+"?query=(((deletedbyinference = false) AND (oaftype exact datasource)) "+((compatibilities && compatibilities.length > 0)?" "+compatibilities+" ":"")+") and (relorganizationid exact "+id+")"; url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => [res['meta'].total, this.parseResults(res['results'])]); } searchDataProvidersBySubjects(keyword:string, type:string, page: number, size: number):any { let link = OpenaireProperties.getSearchResourcesAPIURL(); var compatibilities = ""; if(type == "Research Data"){ compatibilities = " and (datasourcecompatibilityid <> UNKNOWN) and (datasourcecompatibilityid = openaire2.0_data)" }else if(type == "Publications"){ compatibilities = " and (datasourcecompatibilityid <> UNKNOWN) and (datasourcecompatibilityid <> openaire2.0_data)" } let url = link+"?query=(((deletedbyinference = false) AND (oaftype exact datasource)) "+((compatibilities && compatibilities.length > 0)?" "+ compatibilities+" ":"")+") "+ " and (datasourcesubject all "+'"'+keyword+'"'+") " ; url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => [res['meta'].total, this.parseResults(res['results'])]); } getDataProvidersforEntityRegistry(datasourceId: string, page: number, size: number ):any { let url = OpenaireProperties.getSearchResourcesAPIURL(); var basicQuery = "(oaftype exact datasource) " url += "?query="; if(datasourceId!= null && datasourceId != '' ) { url +=" ( "+basicQuery+ " ) " +" and (collectedfromdatasourceid exact \"" + datasourceId + "\")"; }else{ url +=" ( "+basicQuery+ " ) "; } url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => [res['meta'].total, this.parseResults(res['results'])]); } searchDataprovidersForEntity (params: string, page: number, size: number):any { let link = OpenaireProperties. getSearchAPIURLLast(); let url = link+params+"/datasources?format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => [res['meta'].total, this.parseResults(res['results'])]); } /* searchDataprovidersCSV (params: string, refineParams:string, page: number, size: number):any { let link = OpenaireProperties. getSearchAPIURLLast()+"datasources"; let url = link+"?"; if(params!= null && params != '' ) { url += params; } if(refineParams!= null && refineParams != '' ) { url += refineParams; } url += "&page="+(page-1)+"&size="+size+"&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) //.do(res => console.info(res)) .map(res => this.parseResultsCSV(res['results'])); } */ /* searchEntityRegistriesCSV (params: string,refineParams:string, page: number, size: number):any { let url = OpenaireProperties.getSearchResourcesAPIURL(); url += "?query=((oaftype exact datasource) and(datasourcetypeuiid = other))" if(params!= null && params != '' ) { url += params; } if(refineParams!= null && refineParams != '' ) { url += refineParams; } url += "&page="+(page - 1)+"&size="+size+"&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) //.do(res => console.info(res)) .map(res => this.parseResultsCSV(res['results'])); } */ /* searchCompatibleDataprovidersCSV (params: string,refineParams:string, page: number, size: number):any { let url = OpenaireProperties.getSearchResourcesAPIURL(); url += "?query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) not(datasourcetypeuiid = other))" if(params!= null && params != '' ) { url += params; } if(refineParams!= null && refineParams != '' ) { url += refineParams; } url += "&page="+(page - 1)+"&size="+size+"&format=json"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) //.do(res => console.info(res)) .map(res => this.parseResultsCSV(res['results'])); } */ parseResults(data: any): SearchResult[] { let results: SearchResult[] = []; let length = Array.isArray(data) ? data.length : 1; for(let i=0; i = new Set(); let relLength = Array.isArray(resData['rels']['rel']) ? resData['rels']['rel'].length : 1; for(let i=0; i res.json()) .map(res => res.total); } numOfEntityDataproviders(id: string, entity: string):any { var parameters = ""; if(entity == "organization") { parameters = "organizations/"+id+"/datasources/count"; } let url = OpenaireProperties.getSearchAPIURLLast()+parameters+"?format=json"; return this.numOfDataproviders(url); } numOfSearchDataproviders(params: string):any { let url: string = OpenaireProperties.getSearchAPIURLLast()+"datasources/count?format=json"; if(params != "") { url += "&q=" + params; } return this.numOfDataproviders(url); } /* private quote(word: any): string { return '"'+word+'"'; } */ }