import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import 'rxjs/add/observable/of'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/share'; import { } from '../shared/cache.service'; import {OpenaireProperties} from '../utils/properties/openaireProperties'; import {SearchResult} from '../utils/entities/searchResult'; import {RefineResultsUtils} from './servicesUtils/refineResults.class'; @Injectable() export class SearchOrganizationsService { constructor(private http: Http ) {} parseResultsForDeposit(data: any): {"name": string, "id": string}[] { let results: {"name": string, "id": string}[] = []; let length = Array.isArray(data) ? data.length : 1; for(let i=0; i res.json()) //.do(res => console.info(res)) .map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "organization")]); } advancedSearchOrganizations (params: string, page: number, size: number ):any { let url = OpenaireProperties.getSearchResourcesAPIURL(); var basicQuery = "(oaftype exact organization) " url += "?query="; if(params!= null && params != '' ) { url +=" ( "+basicQuery+ " ) " +" and (" + params + ")"; }else{ url +=" ( "+basicQuery+ " ) "; } url += "&page="+(page-1)+"&size="+size; url += "&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'])]); } parseResults(data: any): SearchResult[] { let results: SearchResult[] = []; let length = Array.isArray(data) ? data.length : 1; for(let i=0; i(); } let countProjects = result['projects'].length; result['projects'][countProjects] = { "id": "", "acronym": "", "title": "", "funderShortname": "", "funderName": "", "code": "" } if(relation.title != 'unidentified') { result['projects'][countProjects]['id'] = /*OpenaireProperties.getsearchLinkToProject() + */relation['to'].content; result['projects'][countProjects]['acronym'] = relation.acronym; result['projects'][countProjects]['title'] = relation.title; result['projects'][countProjects]['code'] = relation.code; } else { result['projects'][countProjects]['id'] = ""; result['projects'][countProjects]['acronym'] = ""; result['projects'][countProjects]['title'] = ""; result['projects'][countProjects]['code'] = ""; } if(relation.hasOwnProperty("funding")) { let fundingLength = Array.isArray(relation['funding']) ? relation['funding'].length : 1; for(let z=0; z res.json()) .map(res => res.total); } numOfEntityOrganizations(id: string, entity: string):any { // currently not used - if used fix entity comparison below var parameters: string = ""; if(entity == "organization") { parameters = "organizations/"+id+"/organizations/count"; } let url = OpenaireProperties.getSearchAPIURLLast()+parameters+"?format=json"; return this.numOfOrganizations(url); } numOfSearchOrganizations(params: string):any { let url = OpenaireProperties.getSearchAPIURLLast()+"organizations/count?format=json"; if(params != "") { url += "&q=" + params; } return this.numOfOrganizations(url); } }