openaire-library/services/searchDataproviders.service.ts

289 lines
13 KiB
TypeScript
Raw Normal View History

import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {SearchResult} from '../utils/entities/searchResult';
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
import {StringUtils} from '../utils/string-utils.class';
import{EnvProperties} from '../utils/properties/env-properties';
import {map} from "rxjs/operators";
import {ParsingFunctions} from "../landingPages/landing-utils/parsingFunctions.class";
@Injectable()
export class SearchDataprovidersService {
private sizeOfDescription: number = 270;
public parsingFunctions: ParsingFunctions = new ParsingFunctions();
constructor(private http: HttpClient ) {}
searchDataproviders (params: string, refineParams:string, page: number, size: number, refineFields:string[], properties:EnvProperties, usedBy: string="search" ):any {
let link = properties.searchAPIURLLAst+"datasources";
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)
.pipe(map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource", usedBy)]));
}
[Explore | Library | new-theme]: Added more refine filters in Repositories, Journals, Registries pages | Search & Datasource landing: Show not compatible datasources | Result Landing: get relations names by relationsVocabulary (dnet:relation_relClass.json). 1. env-properties.ts & environments/: Removed old properties searchLinkToEntityRegistriesDataProvidersTable and searchLinkToJournalsTable. 2. fetchDataproviders.class.ts & searchDataproviders.service.ts: Removed old unused methods related to subjects/ tables/ csv. 3. searchFields.ts: Added more refine filters in Repositories, Journals, Registries pages (COMPATIBLE_DATAPROVIDER_FIELDS, ENTITY_REGISTRIES_FIELDS, JOURNAL_FIELDS). 4. result-preview.component.ts: Added field @Input() deposit: boolean = false; 5. result-preview.component.html: a. Added link to landing page even for not compatible datasources. b. Added class "uk-label-danger" when compatibility = "not available" only when deposit=true. 6. searchResultsInDeposit.component.html: In <result-preview> added parameter deposit="true". 7. dataProvider.component.html: a. Added class "uk-label-danger" when compatibility = "not available". b. Show custom "Not yet registered" compatibility label when compatibility = "not available". 8. ISVocabularies.service.ts: Added methods for getting relationsVocabulary (dnet:relation_relClass.json). 9. resultLanding.service.ts & parsingFunctions.class.ts: When parsing relations, get relationName from relationsVocabulary. 10. resultLanding.component.ts: Get relationsVocabulary and pass it to "getResultLandingInfo()". 11. orcid-work.component.ts: When calling "getResultLandingInfo()", added null parameter for relationsVocabulary. 12. configuration.service.ts: [Bug fix] Added more checks in method "isPageEnabledByStateAsync()".
2022-08-03 17:21:14 +02: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";
if(params!= null && params != '' ) {
url +="&query=(" + params + ")";
}
if(refineParams!= null && refineParams != '' ) {
url += refineParams;
}
if(refineQuery) {
url += "&" + refineQuery;
}
url += "&page="+(page-1)+"&size="+size;
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
.pipe(map(res => [res['meta'].total, this.parseResults(res['results']), RefineResultsUtils.parse(res['refineResults'],refineFields, "datasource")]));
}
searchDataprovidersForDeposit (id: string,type:string, page: number, size: number, properties:EnvProperties):any {
let link = properties.searchResourcesAPIURL;
var compatibilities = "";
if(type == "Research Data"){
//compatibilities = " and (datasourcecompatibilityid <> UNKNOWN) and (datasourcecompatibilityid = openaire2.0_data)"
compatibilities = " and (datasourcecompatibilityid = openaire2.0_data)";
}else if(type == "Publications"){
//compatibilities = " and (datasourcecompatibilityid <> UNKNOWN) and (datasourcecompatibilityid <> openaire2.0_data)"
compatibilities = " and (datasourcecompatibilityid <> openaire2.0_data)";
}
let url = link+"?query=(((deletedbyinference = false) AND (oaftype exact datasource)) "+((compatibilities && compatibilities.length > 0)?" "+compatibilities+" ":"")+") and (relorganizationid exact \""+id+"\")";
url += "&page="+(page-1)+"&size="+size+"&format=json";
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
//.map(res => <any> res.json())
.pipe(map(res => [res['meta'].total, this.parseResults(res['results'])]));
}
getDataProvidersforEntityRegistry(datasourceId: string, page: number, size: number , properties:EnvProperties):any {
let url = properties.searchResourcesAPIURL;
var basicQuery = "(oaftype exact datasource) "
url += "?query=";
if(datasourceId!= null && datasourceId != '' ) {
url +=" ( "+basicQuery+ " ) " +" and (collectedfromdatasourceid exact \"" + datasourceId + "\" or resulthostingdatasourceid exact \""+ datasourceId + "\")";
}else{
url +=" ( "+basicQuery+ " ) ";
}
url += "&page="+(page-1)+"&size="+size+"&format=json";
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
//.map(res => <any> res.json())
.pipe(map(res => [res['meta'].total, this.parseResults(res['results'])]));
}
searchDataprovidersForEntity (params: string, page: number, size: number, properties:EnvProperties):any {
let link = properties.searchAPIURLLAst;
let url = link+params+"/datasources?format=json";
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
//.map(res => <any> res.json())
.pipe(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<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();
result['title'] = {"name": '', "accessMode": ''};
if(resData.officialname) {
result['title'].name = StringUtils.HTMLToString(String(resData.officialname));
}
if(resData.englishname) {
result['englishname'] = StringUtils.HTMLToString(String(resData.englishname));
} else {
result['englishname'] = "";
}
//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'];
[Library | new-theme]: Allow also ?pid url parameter in datasource landing | Fixes in newSearchPage for service filters. 1. dataProvider.component.ts: [Bug fix] Allow also ?pid url parameter, query accordingly and set canonicalUrl to use it in seoService and scema2jsonld. 2. dataProvider.component.html: Set canonicalUrl into URL of <schema2jsonld> | Use <landing-header> instead of <showTitle>. 3. dataProvider.service.ts: Set url for querying a datasource by pid (if ?pid in landing url param) and parse also the whole record, the objIdentifier and the relcanId. 4. landing-header.component.ts: Added @Input() isSticky: boolean = false; to set less margins when sticky. 5. resultLanding.component.html: Use <landing-header> instead of <showTitle>. 6. resultLanding.component.ts: Use renamed Identifier.getResultPIDFromIdentifiers --> Identifier.getPIDFromIdentifiers. 7. metrics.service.ts: Removed console.log. 8. searchDataproviders.service.ts: Added parsing for relcanId. 9. dataProviderInfo.ts: Added relcanId, objIdentifier, record. 10. result-preview.component.ts: Use renamed Identifier.getResultPIDFromIdentifiers --> Identifier.getPIDFromIdentifiers. 11. string-utils.class.ts: Renamed Identifier.getResultPIDFromIdentifiers --> Identifier.getPIDFromIdentifiers. 12. [SITEMAPS] extractUrlsFromSearch.ts: Use renamed Identifier.getResultPIDFromIdentifiers --> Identifier.getPIDFromIdentifiers. 13. newSearchPage.component.ts: [Bug fix] a. entityType for datasources is "dataprovider". b. Added service filter options only when entityType == "service".
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'];
result['type'] = this.getDataproviderType(resData);
2022-05-13 14:57:31 +02:00
if (resData['eosctype']) {
result.entityType = resData['eosctype'].classname == "Service" ? "service" : "dataprovider";
}
let abstracts = this.parsingFunctions.parseDescription(resData.description, true);
result.description = abstracts;
// if (result.description && result.description.length > this.sizeOfDescription) {
// result.description = result.description.substring(0, this.sizeOfDescription) + "...";
// }
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;
}
}
let compatibility = this.getDataproviderCompatibility(resData);
result['compatibility'] = compatibility.classname;
if(compatibility.classid == "UNKNOWN") {
result['compatibilityUNKNOWN'] = true;
}
} else {
result['compatibility'] = "";
}
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);
if(resData['pid']) {
result.identifiers = this.parsingFunctions.parseIdentifiers(resData['pid']);
}
results.push(result);
}
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'];
if(subject && subject.content) {
subjects.push(subject.content);
}
}
return subjects;
}
getDataproviderType(resData: any): string {
if(resData['datasourcetype'].hasOwnProperty("classname")) {
return resData['datasourcetype'].classname;
} else {
return '';
}
}
getDataproviderCompatibility(resData: any): {"classid": string, "classname": string} {
if(resData.hasOwnProperty('openairecompatibility')) {
return {"classid": resData['openairecompatibility'].classid, "classname": resData['openairecompatibility'].classname};
} else {
return {"classid": "", "classname": ""};
}
}
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")) {
if(relation['to'].class && relation['to'].class.toLowerCase() == "isprovidedby" && relation['to'].type == "organization") {
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;
}
if(!item['name']) {
item['name'] = "[no title available]";
}
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];
}
numOfDataproviders(url: string, properties:EnvProperties):any {
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
.pipe(map(res => res['total']));
}
numOfEntityDataproviders(id: string, entity: string, properties:EnvProperties):any {
var parameters = "";
if(entity == "organization") {
parameters = "organizations/"+id+"/datasources/count";
}
let url = properties.searchAPIURLLAst+parameters+"?format=json";
return this.numOfDataproviders(url, properties);
}
numOfSearchDataproviders(params: string, properties:EnvProperties, refineQuery:string=null):any {
let url: string = properties.searchAPIURLLAst+"datasources/count?format=json";
if(params != "") {
url += "&q=" + StringUtils.URIEncode(params);
}
if(refineQuery!= null && refineQuery != '' ) {
url += refineQuery;
}
return this.numOfDataproviders(url, properties);
}
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;
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']));
}
}