import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; import {Observable} from 'rxjs/Observable'; 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 { ParsingFunctions } from '../landingPages/landing-utils/parsingFunctions.class'; import{EnvProperties} from '../utils/properties/env-properties'; @Injectable() export class SearchSoftwareService { private sizeOfDescription: number = 270; public parsingFunctions: ParsingFunctions = new ParsingFunctions(); constructor(private http: Http ) {} searchSoftware (params: string, refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any { let link = properties.searchAPIURLLAst+"software"; 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((properties.useCache)? (properties.cacheUrl+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, "software")]); } searchSoftwareById (id: string, properties:EnvProperties ):any { let url = properties.searchAPIURLLAst+"software/"+id+"?format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => this.parseResults(res)); } searchAggregators (id: string, params: string, refineParams:string, page: number, size: number, properties:EnvProperties ):any { let link = properties.searchAPIURLLAst+"software"; let url = link+"?"+"&format=json"; if(params!= null && params != '' ) { url += params; } if(refineParams!= null && refineParams != '' ) { url += refineParams; } url += "&page="+(page-1)+"&size="+size; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => this.parseRefineResults(id, res['refineResults'])) } searchSoftwareByDois (DOIs: string[], refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties ):any { let link = properties.searchResourcesAPIURL+"software"; let url = link+"?"; var doisParams = ""; for(var i =0 ;i < DOIs.length; i++){ doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"'; } if(doisParams.length > 0){ url += "&"+doisParams; } if(refineParams!= null && refineParams != '' ) { url += refineParams; } url += "&page="+ (page-1) +"&size="+size+"&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+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, "software")]); } advancedSearchSoftware (params: string, page: number, size: number, properties:EnvProperties ):any { let url = properties.searchResourcesAPIURL; var basicQuery = "(oaftype exact result) and (resulttypeid exact software) " 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((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) .map(res => res.json()) //.do(res => console.info(res)) .map(res => [res['meta'].total, this.parseResults(res['results'])]); } searchSoftwareForEntity (params: string, page: number, size: number, properties:EnvProperties):any { let link = properties.searchAPIURLLAst; let url = link+params+"/software"+"?format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => [res['meta'].total, this.parseResults(res['results'])]); } searchSoftwareForDataproviders(params: string, page: number, size: number, properties:EnvProperties):any { let link = properties.searchAPIURLLAst; let url = link+params+ "&page="+(page-1)+"&size="+size + "&format=json"; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) .map(res => res.json()) .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(); result.types = new Array(); let types = new Set(); let counter = 0; let instance; let length = Array.isArray(resData['children']['instance']) ? resData['children']['instance'].length : 1; for(let i=0; i(); } result['authors'].push({"name": relation.fullname, "id": relation['to'].content}); } else */if(relation['to'].class == "isProducedBy") { result['projects'] = this.parseProjects(result['projects'], relation); } } } } if(resData.hasOwnProperty("creator") && resData['creator'] != null) { if(result['authors'] == undefined) { result['authors'] = new Array(); } let authors = resData['creator']; let length = Array.isArray(authors) ? authors.length : 1; for(let i=0; i this.sizeOfDescription) { result.description = result.description.substring(0, this.sizeOfDescription)+"..."; } result.embargoEndDate = resData.embargoenddate; if(!Array.isArray(resData.publisher)) { result.publisher = resData.publisher; } else { for(let i=0; i(); } let countProjects = projects.length; projects[countProjects] = { "id": "", "acronym": "", "title": "", "funderShortname": "", "funderName": "", "code": "" } if(relation.title != 'unidentified') { projects[countProjects]['id'] = /*OpenaireProperties.getsearchLinkToProject() + */relation['to'].content; projects[countProjects]['acronym'] = relation.acronym; projects[countProjects]['title'] = relation.title; projects[countProjects]['code'] = relation.code; } else { projects[countProjects]['id'] = ""; projects[countProjects]['acronym'] = ""; projects[countProjects]['title'] = ""; 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); } numOfEntitySoftware(id: string, entity: string, properties:EnvProperties):any { var parameters = ""; if(entity == "project") { parameters = "projects/"+id+"/software/count"; } let url = properties.searchAPIURLLAst+parameters+"?format=json"; return this.numOfSoftware(url, properties); } numOfSearchSoftware(params: string, properties:EnvProperties):any { let url = properties.searchAPIURLLAst+"software/count?format=json"; if(params != "") { url += "&q=" + params; } return this.numOfSoftware(url, properties); } }