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';
|
|
|
|
import {StringUtils} from '../utils/string-utils.class';
|
2018-02-05 14:14:59 +01:00
|
|
|
import{EnvProperties} from '../utils/properties/env-properties';
|
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";
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
@Injectable()
|
|
|
|
export class SearchDataprovidersService {
|
2020-03-12 11:44:51 +01:00
|
|
|
private sizeOfDescription: number = 270;
|
2022-05-05 19:29:55 +02:00
|
|
|
public parsingFunctions: ParsingFunctions = new ParsingFunctions();
|
2020-03-12 11:44:51 +01:00
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
constructor(private http: HttpClient ) {}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-15 18:11:07 +02:00
|
|
|
searchDataproviders (params: string, refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties, usedBy: string="search" ):any {
|
2018-02-05 14:14:59 +01:00
|
|
|
let link = properties.searchAPIURLLAst+"datasources";
|
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-07-15 18:11:07 +02:00
|
|
|
.pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource", usedBy)]));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2022-08-03 17:21:14 +02:00
|
|
|
|
2020-03-12 18:03:35 +01:00
|
|
|
advancedSearchDataproviders (params: string, page: number, size: number, properties: EnvProperties, refineParams:string=null, refineFields:string[] =null, refineQuery:string = null, depositQuery:boolean = false ):any {
|
|
|
|
let url = properties.searchAPIURLLAst+"resources"+(depositQuery?'':2)+"/?format=json";
|
2020-02-13 15:44:51 +01:00
|
|
|
|
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-11 15:56:20 +01:00
|
|
|
if(refineParams!= null && refineParams != '' ) {
|
|
|
|
url += refineParams;
|
|
|
|
}
|
|
|
|
if(refineQuery) {
|
|
|
|
url += "&" + refineQuery;
|
|
|
|
}
|
2020-02-13 15:44:51 +01:00
|
|
|
url += "&page="+(page-1)+"&size="+size;
|
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)
|
2020-02-11 15:56:20 +01:00
|
|
|
.pipe(map(res => [res['meta'].total, this.parseResults(res['results']), RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")]));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
searchDataprovidersForDeposit (id: string,type:string, page: number, size: number, properties:EnvProperties):any {
|
|
|
|
let link = properties.searchResourcesAPIURL;
|
2017-12-19 13:53:46 +01:00
|
|
|
var compatibilities = "";
|
|
|
|
if(type == "Research Data"){
|
2019-02-12 12:15:21 +01:00
|
|
|
//compatibilities = " and (datasourcecompatibilityid <> UNKNOWN) and (datasourcecompatibilityid = openaire2.0_data)"
|
|
|
|
compatibilities = " and (datasourcecompatibilityid = openaire2.0_data)";
|
2017-12-19 13:53:46 +01:00
|
|
|
}else if(type == "Publications"){
|
2019-02-12 12:15:21 +01:00
|
|
|
//compatibilities = " and (datasourcecompatibilityid <> UNKNOWN) and (datasourcecompatibilityid <> openaire2.0_data)"
|
|
|
|
compatibilities = " and (datasourcecompatibilityid <> openaire2.0_data)";
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-04-02 17:33:01 +02:00
|
|
|
let url = link+"?query=(((deletedbyinference = false) AND (oaftype exact datasource)) "+((compatibilities && compatibilities.length > 0)?" "+compatibilities+" ":"")+") and (relorganizationid exact \""+id+"\")";
|
2017-12-19 13:53:46 +01:00
|
|
|
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'])]));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-15 18:11:07 +02:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
getDataProvidersforEntityRegistry(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 datasource) "
|
|
|
|
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+"&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
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
searchDataprovidersForEntity (params: string, page: number, size: number, properties:EnvProperties):any {
|
|
|
|
let link = properties.searchAPIURLLAst;
|
2017-12-19 13:53:46 +01:00
|
|
|
let url = link+params+"/datasources?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
|
|
|
}
|
|
|
|
|
|
|
|
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:datasource'] : data['result']['metadata']['oaf:entity']['oaf:datasource'];
|
|
|
|
|
|
|
|
var result: SearchResult = new SearchResult();
|
|
|
|
|
2022-06-15 12:54:49 +02:00
|
|
|
result['title'] = {"name": '', "accessMode": ''};
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2022-11-28 18:22:01 +01:00
|
|
|
if(resData.officialname) {
|
|
|
|
result['title'].name = StringUtils.HTMLToString(String(resData.officialname));
|
|
|
|
}
|
|
|
|
if(resData.englishname) {
|
|
|
|
result['englishname'] = StringUtils.HTMLToString(String(resData.englishname));
|
|
|
|
} else {
|
|
|
|
result['englishname'] = "";
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
//result['title'].url = OpenaireProperties.getsearchLinkToDataProvider();
|
|
|
|
//result['title'].url += Array.isArray(data) ? data[i]['result']['header']['dri:objIdentifier'] : data['result']['header']['dri:objIdentifier'];
|
|
|
|
result['id'] = Array.isArray(data) ? data[i]['result']['header']['dri:objIdentifier'] : data['result']['header']['dri:objIdentifier'];
|
2022-05-30 09:39:10 +02:00
|
|
|
let canId = ParsingFunctions.parseRelCanonicalId(Array.isArray(data) ? data[i] : data, "datasource");
|
|
|
|
if (canId) {
|
|
|
|
result['id'] = canId;
|
|
|
|
}
|
|
|
|
result['relcanId'] = result['id'];
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
result['type'] = this.getDataproviderType(resData);
|
2022-05-13 14:57:31 +02:00
|
|
|
if (resData['eosctype']) {
|
|
|
|
result.entityType = resData['eosctype'].classname == "Service" ? "service" : "dataprovider";
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2022-09-21 12:32:21 +02:00
|
|
|
let abstracts = this.parsingFunctions.parseDescription(resData.description, 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
|
|
|
let typeid: string = resData['datasourcetype'].classid;
|
|
|
|
if(typeid != "entityregistry" && typeid != "entityregistry::projects" && typeid != "entityregistry::repositories") {
|
|
|
|
|
|
|
|
if(resData.hasOwnProperty('accessinfopackage')) {
|
|
|
|
let OAIPMHURL: string;
|
|
|
|
if(Array.isArray(resData['accessinfopackage'])) {
|
|
|
|
OAIPMHURL = resData['accessinfopackage'][0];
|
|
|
|
} else {
|
|
|
|
OAIPMHURL = resData['accessinfopackage'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(OAIPMHURL != '' && OAIPMHURL != 'unknown') {
|
|
|
|
result['OAIPMHURL'] = OAIPMHURL;
|
|
|
|
}
|
|
|
|
}
|
2019-02-12 12:15:21 +01:00
|
|
|
let compatibility = this.getDataproviderCompatibility(resData);
|
|
|
|
result['compatibility'] = compatibility.classname;
|
|
|
|
if(compatibility.classid == "UNKNOWN") {
|
|
|
|
result['compatibilityUNKNOWN'] = true;
|
|
|
|
}
|
2018-03-01 14:14:35 +01:00
|
|
|
} else {
|
2019-02-12 12:15:21 +01:00
|
|
|
result['compatibility'] = "";
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
result['websiteURL'] = resData.websiteurl;
|
|
|
|
|
|
|
|
let res:[string[], {"name":string, "id":string}[]] = this.getDataproviderCountriesOrganizations(resData, true, true);
|
|
|
|
result['organizations'] = res[1];
|
|
|
|
result['countries'] = res[0];
|
|
|
|
result['subjects'] = this.getDataproviderSubjects(resData);
|
2022-05-16 16:01:35 +02:00
|
|
|
|
|
|
|
if(resData['pid']) {
|
|
|
|
result.identifiers = this.parsingFunctions.parseIdentifiers(resData['pid']);
|
|
|
|
}
|
|
|
|
|
|
|
|
results.push(result);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
getDataproviderSubjects(resData: any): string [] {
|
|
|
|
var subjects:string [] = [];
|
|
|
|
|
|
|
|
let length = Array.isArray(resData['subjects']) ? resData['subjects'].length : 1;
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
let subject = Array.isArray(resData['subjects']) ? resData['subjects'][i] :resData['subjects'];
|
2020-03-12 18:03:35 +01:00
|
|
|
if(subject && subject.content) {
|
2019-10-31 12:10:39 +01:00
|
|
|
subjects.push(subject.content);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
return subjects;
|
|
|
|
}
|
|
|
|
getDataproviderType(resData: any): string {
|
|
|
|
if(resData['datasourcetype'].hasOwnProperty("classname")) {
|
|
|
|
return resData['datasourcetype'].classname;
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-12 12:15:21 +01:00
|
|
|
getDataproviderCompatibility(resData: any): {"classid": string, "classname": string} {
|
2017-12-19 13:53:46 +01:00
|
|
|
if(resData.hasOwnProperty('openairecompatibility')) {
|
2019-02-12 12:15:21 +01:00
|
|
|
return {"classid": resData['openairecompatibility'].classid, "classname": resData['openairecompatibility'].classname};
|
2017-12-19 13:53:46 +01:00
|
|
|
} else {
|
2019-02-12 12:15:21 +01:00
|
|
|
return {"classid": "", "classname": ""};
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getDataproviderCountriesOrganizations(resData: any, getCountries: boolean, getOrganizations: boolean): [string[], {"name": string, "id": string}[]] {
|
|
|
|
let countries: string[] = [];
|
|
|
|
let organizations: {"name": string, "id": string}[] = [];
|
|
|
|
|
|
|
|
if(resData['rels'].hasOwnProperty("rel")) {
|
|
|
|
let countriesSet: Set<string> = new Set<string>();
|
|
|
|
|
|
|
|
let relLength = Array.isArray(resData['rels']['rel']) ? resData['rels']['rel'].length : 1;
|
|
|
|
|
|
|
|
for(let i=0; i<relLength; i++) {
|
|
|
|
let relation = Array.isArray(resData['rels']['rel']) ? resData['rels']['rel'][i] : resData['rels']['rel'];
|
|
|
|
|
|
|
|
if(relation.hasOwnProperty("to")) {
|
2021-09-27 11:19:24 +02:00
|
|
|
if(relation['to'].class && relation['to'].class.toLowerCase() == "isprovidedby" && relation['to'].type == "organization") {
|
2017-12-19 13:53:46 +01:00
|
|
|
if(getOrganizations) {
|
|
|
|
let item: {"name":string, "id":string} = {"name": "", "id": ""};
|
|
|
|
//item['name'] = relation.legalname;
|
|
|
|
if(relation.legalshortname) {
|
|
|
|
item['name'] = relation.legalshortname;
|
|
|
|
} else {
|
|
|
|
item['name'] = relation.legalname;
|
|
|
|
}
|
2020-03-17 11:04:17 +01:00
|
|
|
if(!item['name']) {
|
|
|
|
item['name'] = "[no title available]";
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
item['id'] = /*OpenaireProperties.getsearchLinkToOrganization()+*/relation['to'].content;
|
|
|
|
organizations.push(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(getCountries) {
|
|
|
|
if(relation.hasOwnProperty('country') &&
|
|
|
|
relation.country.hasOwnProperty('classname')) {
|
|
|
|
if(!countriesSet.has(relation.country.classname)) {
|
|
|
|
countriesSet.add(relation.country.classname);
|
|
|
|
countries.push(relation.country.classname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [countries, organizations];
|
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
numOfDataproviders(url: string, properties:EnvProperties):any {
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2019-06-03 15:20:36 +02:00
|
|
|
.pipe(map(res => res['total']));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
numOfEntityDataproviders(id: string, entity: string, properties:EnvProperties):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
var parameters = "";
|
|
|
|
if(entity == "organization") {
|
|
|
|
parameters = "organizations/"+id+"/datasources/count";
|
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
let url = properties.searchAPIURLLAst+parameters+"?format=json";
|
|
|
|
return this.numOfDataproviders(url, properties);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-06-14 15:27:46 +02:00
|
|
|
numOfSearchDataproviders(params: string, properties:EnvProperties, refineQuery:string=null):any {
|
2018-02-05 14:14:59 +01:00
|
|
|
let url: string = properties.searchAPIURLLAst+"datasources/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(refineQuery!= null && refineQuery != '' ) {
|
|
|
|
url += refineQuery;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.numOfDataproviders(url, properties);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2022-05-13 14:57:31 +02:00
|
|
|
numOfSearchDataproviders2(params: string, properties:EnvProperties, refineQuery:string=null, typePathParam: string="datasources"):any {
|
|
|
|
let url: string = properties.searchAPIURLLAst+"resources2/?format=json&size=0&type="+typePathParam;
|
2020-04-07 13:11:31 +02:00
|
|
|
if(params != "") {
|
|
|
|
url += "&query=" +params;
|
|
|
|
}
|
|
|
|
if(refineQuery!= null && refineQuery != '' ) {
|
|
|
|
url += refineQuery;
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|