import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import {AutoCompleteValue} from '../searchPages/searchUtils/searchHelperClasses.class'; import {OpenaireProperties} from '../utils/properties/openaireProperties'; import 'rxjs/add/observable/of'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/share'; import { } from '../shared/cache.service'; import {RefineResultsUtils} from './servicesUtils/refineResults.class'; @Injectable() export class RefineFieldResultsService { // scoobydoo.di.uoa.gr:8181/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/projects?refine=true&fields=funderid&page=1&size=0 constructor(private http: Http ) {} getRefineFieldsResultsByEntityName(fields:string[], entityName:string):any{ let url = OpenaireProperties.getSearchAPIURLForEntity(entityName)+"?format=json&refine=true&page=1&size=0"; for(var i=0; i < fields.length; i++){ url += "&fields="+fields[i]; } return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => [res['meta'].total, RefineResultsUtils.parse(res['refineResults'],fields, entityName)]); } getRefineFieldResultsByFieldName(fieldName:string, entityName:string):any{ let link = OpenaireProperties.getSearchAPIURLForEntity(entityName)+"?fields="+fieldName + "&format=json"; return this.getField(link,fieldName) } getField (link:string,fieldName:string):any{ let url = link+"&refine=true&page=1&size=0"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => res['refineResults']) .map(res => this.parse(res,fieldName)); } parse(data: any,fieldName:string):any { var values:AutoCompleteValue[] = []; if(data){ let field = data[fieldName]; for(let i=0; i