2017-12-19 13:53:46 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {HttpClient} from "@angular/common/http";
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
import {SearchResult} from '../utils/entities/searchResult';
|
|
|
|
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
|
2018-02-05 14:14:59 +01:00
|
|
|
import{EnvProperties} from '../utils/properties/env-properties';
|
2018-10-30 12:37:52 +01:00
|
|
|
import {StringUtils} from '../utils/string-utils.class';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {map} from "rxjs/operators";
|
2022-05-05 19:29:55 +02:00
|
|
|
import {ParsingFunctions} from "../landingPages/landing-utils/parsingFunctions.class";
|
2017-12-19 13:53:46 +01:00
|
|
|
@Injectable()
|
|
|
|
export class SearchProjectsService {
|
|
|
|
private sizeOfDescription: number = 270;
|
2022-05-05 19:29:55 +02:00
|
|
|
public parsingFunctions: ParsingFunctions = new ParsingFunctions();
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2022-05-05 19:29:55 +02:00
|
|
|
constructor(private http: HttpClient ) {}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
searchProjects (params: string, refineParams:string, page: number, size: number, refineFields:string[] , properties:EnvProperties ):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
let link = properties.searchAPIURLLAst+"projects";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
let url = link+"?";
|
|
|
|
if(params!= null && params != '' ) {
|
|
|
|
url += params;
|
|
|
|
}
|
|
|
|
if(refineParams!= null && refineParams != '' ) {
|
|
|
|
url += refineParams;
|
|
|
|
}
|
|
|
|
url += "&page="+(page-1)+"&size="+size + "&format=json";
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => <any> res.json())
|
|
|
|
.pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "project")]));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
getProjectsforDataProvider (datasourceId: string, page: number, size: number, properties:EnvProperties ):any {
|
|
|
|
let url = properties.searchResourcesAPIURL;
|
2017-12-19 13:53:46 +01:00
|
|
|
var basicQuery = "(oaftype exact project) "
|
|
|
|
url += "?query=";
|
|
|
|
if(datasourceId!= null && datasourceId != '' ) {
|
2020-03-16 14:09:46 +01:00
|
|
|
url +=" ( "+basicQuery+ " ) " +" and (collectedfromdatasourceid exact \"" + datasourceId + "\" or resulthostingdatasourceid exact \""+ datasourceId + "\")";
|
2017-12-19 13:53:46 +01:00
|
|
|
}else{
|
|
|
|
url +=" ( "+basicQuery+ " ) ";
|
|
|
|
}
|
|
|
|
|
|
|
|
url += "&page="+(page-1)+"&size="+size;
|
|
|
|
url += "&format=json";
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => <any> res.json())
|
|
|
|
.pipe(map(res => [res['meta'].total, this.parseResults(res['results'])]));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2023-12-14 17:14:57 +01:00
|
|
|
advancedSearchProjects (params: string, page: number, size: number, properties:EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null, minRef: boolean = false):any {
|
2020-02-24 14:45:22 +01:00
|
|
|
// &type=projects
|
|
|
|
let url = properties.searchAPIURLLAst+"resources2/?format=json";
|
2020-02-13 15:44:51 +01:00
|
|
|
// var basicQuery = "(oaftype exact project) "
|
|
|
|
// url += "?query=";
|
2017-12-19 13:53:46 +01:00
|
|
|
if(params!= null && params != '' ) {
|
2020-02-13 15:44:51 +01:00
|
|
|
url +="&query=(" + params + ")";
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-02-13 15:44:51 +01:00
|
|
|
// else{
|
|
|
|
// url +=" ( "+basicQuery+ " ) ";
|
|
|
|
// }
|
2020-02-11 15:56:20 +01:00
|
|
|
if(refineParams!= null && refineParams != '' ) {
|
|
|
|
url += refineParams;
|
|
|
|
}
|
|
|
|
if(refineQuery) {
|
|
|
|
url += "&" + refineQuery;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
url += "&page="+(page-1)+"&size="+size;
|
2023-12-14 17:14:57 +01:00
|
|
|
url += minRef ? "&minRef=true" : "";
|
|
|
|
|
2020-02-13 15:44:51 +01:00
|
|
|
// url += "&format=json";
|
2024-02-08 17:05:27 +01:00
|
|
|
// return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
|
|
return this.http.get((properties.useLongCache && size == 0 && !params && (!refineQuery || !refineQuery.includes("fq="))) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
|
|
|
|
//.map(res => <any> res.json())
|
2020-02-11 15:56:20 +01:00
|
|
|
.pipe(map(res => [res['meta'].total, this.parseResults(res['results']), RefineResultsUtils.parse(res['refineResults'],refineFields, "project")]));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-03-16 14:09:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
getProjectsForOrganizations (organizationId: string, filterquery: string, page: number, size: number, refineFields:string[] , properties:EnvProperties ):any {
|
|
|
|
let url = properties.searchResourcesAPIURL;
|
2017-12-19 13:53:46 +01:00
|
|
|
var basicQuery = "(oaftype exact project) "
|
|
|
|
url += "?query=";
|
|
|
|
if(filterquery!= null && filterquery != '' ) {
|
|
|
|
url +="( ( "+basicQuery+ " ) and (relorganizationid exact \"" + organizationId + "\")"+" " + filterquery + ")";
|
|
|
|
}else{
|
|
|
|
url +=" (( "+basicQuery+ " ) " +" and (relorganizationid exact \"" + organizationId + "\"))";
|
|
|
|
}
|
|
|
|
if(refineFields!= null && refineFields.length > 0 ) {
|
|
|
|
url +="&refine=true";
|
|
|
|
for(let i=0; i< refineFields.length ; i++ ){
|
|
|
|
url +="&fields="+refineFields[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
url += "&page="+(page-1)+"&size="+size;
|
|
|
|
url += "&format=json";
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => <any> res.json())
|
|
|
|
.pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "project")]));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2022-07-05 00:31:56 +02:00
|
|
|
getFunders(params: string, properties:EnvProperties ):any {
|
|
|
|
let url = properties.searchAPIURLLAst+"projects?refine=true&fields=funder"+(params ? "&"+params : "")+"&size=0"+ "&format=json";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => <any> res.json())
|
2022-07-05 00:31:56 +02:00
|
|
|
.pipe(map(res => [res['meta'].total, RefineResultsUtils.parse(res['refineResults'], ['funder'], 'project')]));
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
searchForProjectsObs(keyword:string, funderId:string, properties:EnvProperties ):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
let url = 'search?action=search&sTransformer=projects_openaire&query='+
|
|
|
|
'%28oaftype+exact+project%29+and+%28%28projecttitle+%3D+%22'+keyword+'%22%29+or+%28projectacronym+%3D+%22'+keyword+'%22%29+or+%28projectcode+%3D+%22'+keyword+'%22%29%29+and+%28funder+exact+'+funderId+'%29&size=10&locale=en_GB&format=json';
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).toPromise()
|
2017-12-19 13:53:46 +01:00
|
|
|
.then(request =>{
|
2019-06-03 15:20:36 +02:00
|
|
|
//return (request.json().response.results)?request.json().response.results.result:request.json().response.result;
|
|
|
|
return (request['response'].results)?request['response'].results.result:request['response'].result;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
}) ;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
parseResults(data: any): SearchResult[] {
|
|
|
|
let results: SearchResult[] = [];
|
|
|
|
|
|
|
|
let length = Array.isArray(data) ? data.length : 1;
|
|
|
|
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
let resData = Array.isArray(data) ? data[i]['result']['metadata']['oaf:entity']['oaf:project'] : data['result']['metadata']['oaf:entity']['oaf:project'];
|
|
|
|
|
|
|
|
var result: SearchResult = new SearchResult();
|
2018-10-23 15:11:25 +02:00
|
|
|
result.openAccessMandatePublications = (resData['oamandatepublications'])?true:false;
|
2022-06-15 12:54:49 +02:00
|
|
|
if(resData.hasOwnProperty("oamandatedata")) {
|
|
|
|
result.openAccessMandateDatasets = (resData['oamandatedata'])?true:false;
|
|
|
|
} else {
|
|
|
|
result.openAccessMandateDatasets = (resData['ecarticle29_3'])?true:false;
|
|
|
|
}
|
|
|
|
result['title'] = {"name": '', "accessMode": ''};
|
2018-03-16 15:54:44 +01:00
|
|
|
// if(resData['acronym'] != undefined && resData['acronym'] != "") {
|
|
|
|
// result['title'].name = resData['acronym'] + " - ";
|
|
|
|
// }
|
2022-11-28 18:22:01 +01:00
|
|
|
if(resData['title']) {
|
|
|
|
if (Array.isArray(resData['title'])) {
|
|
|
|
result['title'].name += StringUtils.HTMLToString(String(resData['title'][0]));
|
2017-12-19 13:53:46 +01:00
|
|
|
} else {
|
2022-11-28 18:22:01 +01:00
|
|
|
result['title'].name += StringUtils.HTMLToString(String(resData['title']));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2022-11-28 18:22:01 +01:00
|
|
|
} else {
|
|
|
|
result['title'].name = "";
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-03-16 15:54:44 +01:00
|
|
|
// if(result['title'].name != '') {
|
|
|
|
// result['title'].name += " ("+resData['code']+")"
|
|
|
|
// }
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2022-06-15 12:54:49 +02:00
|
|
|
// if(resData['ecsc39'] == true) {
|
|
|
|
// result['title'].sc39 = "sc39";
|
|
|
|
// }
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-03-16 15:54:44 +01:00
|
|
|
result.acronym = resData['acronym'];
|
|
|
|
result.code = resData['code'];
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2020-03-16 14:09:46 +01:00
|
|
|
result.budget = resData.totalcost;//"10000";
|
|
|
|
result.contribution = resData.fundedamount;//"200100";
|
|
|
|
result.currency = resData.currency;//"EUR";
|
|
|
|
|
2018-03-16 15:54:44 +01:00
|
|
|
result.id = Array.isArray(data) ? data[i]['result']['header']['dri:objIdentifier'] : data['result']['header']['dri:objIdentifier'];
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2022-09-21 12:32:21 +02:00
|
|
|
let abstracts = this.parsingFunctions.parseDescription(resData.summary, true);
|
|
|
|
result.description = abstracts;
|
2022-11-28 18:22:01 +01:00
|
|
|
// if (result.description && result.description.length > this.sizeOfDescription) {
|
|
|
|
// result.description = result.description.substring(0, this.sizeOfDescription) + "...";
|
|
|
|
// }
|
2020-03-12 11:44:51 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
if(resData['rels'].hasOwnProperty("rel")) {
|
|
|
|
let relLength = Array.isArray(resData['rels']['rel']) ? resData['rels']['rel'].length : 1;
|
|
|
|
|
|
|
|
for(let j=0; j<relLength; j++) {
|
|
|
|
let relation = Array.isArray(resData['rels']['rel']) ? resData['rels']['rel'][j] : resData['rels']['rel'];
|
|
|
|
|
|
|
|
if(relation.hasOwnProperty("to")) {
|
2021-09-27 11:19:24 +02:00
|
|
|
if(relation['to'].class && relation['to'].class.toLowerCase() == "hasparticipant") {
|
2017-12-19 13:53:46 +01:00
|
|
|
if(result['organizations'] == undefined) {
|
|
|
|
result['organizations'] = new Array<
|
|
|
|
{ "name": string, "id": string}>();
|
|
|
|
}
|
|
|
|
|
|
|
|
let countOrganizations = result['organizations'].length;
|
|
|
|
|
|
|
|
result['organizations'][countOrganizations] = { "name": "", "id": "" }
|
|
|
|
|
|
|
|
result['organizations'][countOrganizations]['id'] =
|
|
|
|
/*OpenaireProperties.getsearchLinkToOrganization() + */relation['to'].content;
|
|
|
|
if(relation.legalshortname) {
|
|
|
|
result['organizations'][countOrganizations]['name'] = relation.legalshortname;
|
|
|
|
} else {
|
|
|
|
result['organizations'][countOrganizations]['name'] = relation.legalname;
|
|
|
|
}
|
2020-03-17 11:04:17 +01:00
|
|
|
if(!result['organizations'][countOrganizations]['name']) {
|
|
|
|
result['organizations'][countOrganizations]['name'] = "[no title available]";
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(resData.hasOwnProperty("fundingtree")) {
|
2018-03-16 15:54:44 +01:00
|
|
|
/*let funderSet: Set<string>;
|
2017-12-19 13:53:46 +01:00
|
|
|
if(result['funders'] == undefined) {
|
|
|
|
result['funders'] = new Array<
|
|
|
|
{"funderShortname": string, "funderName": string}>();
|
2018-03-16 15:54:44 +01:00
|
|
|
funderSet = new Set<string>();
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let fundingLength = Array.isArray(resData['fundingtree']) ? resData['fundingtree'].length : 1;
|
|
|
|
|
|
|
|
for(let z=0; z<fundingLength; z++) {
|
|
|
|
let fundingData = Array.isArray(resData['fundingtree']) ? resData['fundingtree'][z] : resData['fundingtree'];
|
|
|
|
if(fundingData.hasOwnProperty("funder")) {
|
2018-03-16 15:54:44 +01:00
|
|
|
if(!funderSet.has(fundingData['funder'].shortname)) {
|
|
|
|
let countFunders = result['funders'].length;
|
|
|
|
|
|
|
|
result['funders'][countFunders] = {"funderShortname": "", "funderName": ""};
|
|
|
|
result['funders'][countFunders]['funderShortname'] = fundingData['funder'].shortname;
|
|
|
|
result['funders'][countFunders]['funderName'] = fundingData['funder'].name;
|
|
|
|
funderSet.add(fundingData['funder'].shortname);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2018-03-16 15:54:44 +01:00
|
|
|
}*/
|
|
|
|
let fundingLength = Array.isArray(resData['fundingtree']) ? resData['fundingtree'].length : 1;
|
|
|
|
|
|
|
|
for(let z=0; z<fundingLength; z++) {
|
|
|
|
let fundingData = Array.isArray(resData['fundingtree']) ? resData['fundingtree'][z] : resData['fundingtree'];
|
|
|
|
if(fundingData.hasOwnProperty("funder")) {
|
|
|
|
result['funderShortname'] = fundingData['funder'].shortname;
|
2019-07-23 14:23:12 +02:00
|
|
|
result['funderId'] = fundingData['funder'].id;
|
|
|
|
result['jurisdiction'] = (fundingData['funder']['id']['jurisdiction'] )?fundingData['funder']['id']['jurisdiction']:"";
|
|
|
|
|
|
|
|
if(fundingData['funding_level_2']){
|
|
|
|
result['fundingLevel0'] = (fundingData['funding_level_2'] && fundingData['funding_level_2']['parent'] &&
|
|
|
|
fundingData['funding_level_2']['parent']['funding_level_1'] && fundingData['funding_level_2']['parent']['funding_level_1']['parent']
|
|
|
|
&& fundingData['funding_level_2']['parent']['funding_level_1']['parent']['funding_level_0'])?
|
|
|
|
fundingData['funding_level_2']['parent']['funding_level_1']['parent']['funding_level_0']['name']:"";
|
|
|
|
}else if(fundingData['funding_level_1']){
|
|
|
|
result['fundingLevel0'] = (fundingData['funding_level_1'] && fundingData['funding_level_1']['parent'] && fundingData['funding_level_1']['parent']['funding_level_0'])?
|
|
|
|
fundingData['funding_level_1']['parent']['funding_level_0']['name']:"";
|
|
|
|
}else if(fundingData['funding_level_0']){
|
|
|
|
result['fundingLevel0'] = (fundingData['funding_level_0'] )?fundingData['funding_level_0']['name']:"";
|
|
|
|
}else {
|
|
|
|
result['fundingLevel0']="";
|
|
|
|
}
|
2018-03-16 15:54:44 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-19 15:38:16 +02:00
|
|
|
if(resData.hasOwnProperty("startdate") && resData['startdate']) {
|
2017-12-19 13:53:46 +01:00
|
|
|
result.startYear = resData.startdate.split('-')[0];
|
|
|
|
}
|
2023-09-19 15:38:16 +02:00
|
|
|
if(resData.hasOwnProperty("enddate") && resData['enddate']) {
|
2017-12-19 13:53:46 +01:00
|
|
|
result.endYear = resData.enddate.split('-')[0];
|
|
|
|
}
|
2023-05-02 11:00:40 +02:00
|
|
|
// Measure
|
|
|
|
result.measure = this.parsingFunctions.parseMeasures(resData['measure']);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
results.push(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
numOfProjects(url: string, properties:EnvProperties ):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => <any> res.json())
|
|
|
|
.pipe(map(res => res['total']));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
numOfEntityProjects(id: string, entity: string, properties:EnvProperties ):any {
|
|
|
|
//let url = properties.searchAPIURLLAst+params+(params.indexOf("?") == -1 ?"?":"&")+"format=json";
|
2017-12-19 13:53:46 +01:00
|
|
|
var parameters: string = "";
|
|
|
|
if(entity == "organization") {
|
|
|
|
parameters = "organizations/"+id+"/projects/count";
|
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
let url = properties.searchAPIURLLAst+parameters+ "?format=json";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.numOfProjects(url, properties);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-06-14 15:06:58 +02:00
|
|
|
numOfSearchProjects(params: string, properties:EnvProperties, refineParams:string=null ):any {
|
2018-02-05 14:14:59 +01:00
|
|
|
let url = properties.searchAPIURLLAst+"projects/count?format=json";
|
2017-12-19 13:53:46 +01:00
|
|
|
if(params != "") {
|
2018-10-30 12:37:52 +01:00
|
|
|
url += "&q=" + StringUtils.URIEncode(params);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-06-14 15:06:58 +02:00
|
|
|
if(refineParams!= null && refineParams != '' ) {
|
|
|
|
url += refineParams;
|
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.numOfProjects(url, properties);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-04-07 13:11:31 +02:00
|
|
|
numOfSearchProjects2(params: string, properties:EnvProperties, refineParams:string=null ):any {
|
|
|
|
let url = properties.searchAPIURLLAst+"resources2/?format=json&size=0&type=projects";
|
|
|
|
if(params != "") {
|
|
|
|
url += "&query=" + params;
|
|
|
|
}
|
|
|
|
if(refineParams!= null && refineParams != '' ) {
|
|
|
|
url += refineParams;
|
|
|
|
}
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
|
|
|
.pipe(map(res => res['meta']['total']));
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|