From a8e2a509d5ccbb9b9541d8cd689f1f2f27dba083 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Mon, 21 Oct 2024 15:30:44 +0300 Subject: [PATCH] [new-search-json | WIP | CHANGED]: Updated parsing according to new json schema. 1. dataProvider.service.ts: Parse jurisdiction (label instead of classname) according to new schema. 2. organization/deletedByInference/deletedByInference.service.ts & result/deletedByInference/deletedByInference.service.ts: Not used - added @deprecated annotation to methods "getDeletedByInferenceResults()" and "parseDeletedByInferenceResults()". 3. project.service.ts: Added @deprecated annotation to method "getHTMLInfo()". 4. result/deletedByInference/deletedByInference.component.ts: Updated parsing of versions (previously children, now links with relations "merges") according to new json schema. 5. resultLanding.component.html: In updated parameter [id]="resultLandingInfo.record['header']['id']". 6. resultLanding.service.ts: Exclude relation "merges" from the related research. 7. organization.service.ts: Updated parsing according to new json schema for methods "getOrganizationNameAndUrlById()" and "parseOrganizationNameAndUrl()". 8. searchDataproviders.service.ts: Updated parsing of "eosctype" field and added TODO comment to check if parsing is correct. 9. searchOrganizations.service.ts: Added @deprecated annotation to method "parseResultsForDeposit()". 10. searchProjects.service.ts: Removed a console.log. 11. entitiesAutoComplete.component.ts: Commented @Input() public depositType:string and everything related to it. 12. entitySearch.service.ts: Added @deprecated annotation to method "searchByDepositType()" | Updated parsing according to new json schema for methods "searchByType()", "fetchByType()", "parse()". --- .../dataProvider/dataProvider.service.ts | 2 +- .../deletedByInference.service.ts | 6 + landingPages/project/project.service.ts | 3 + .../deletedByInference.component.ts | 34 +-- .../deletedByInference.service.ts | 6 + .../result/resultLanding.component.html | 16 +- landingPages/result/resultLanding.service.ts | 2 +- services/organization.service.ts | 9 +- services/searchDataproviders.service.ts | 3 +- services/searchOrganizations.service.ts | 43 +-- services/searchProjects.service.ts | 1 - .../open-aire-jsonld-converter.service.ts | 1 + .../entitiesAutoComplete.component.ts | 26 +- .../entitySearch.service.ts | 286 +++++++++--------- 14 files changed, 226 insertions(+), 212 deletions(-) diff --git a/landingPages/dataProvider/dataProvider.service.ts b/landingPages/dataProvider/dataProvider.service.ts index 48777621..99835dfb 100644 --- a/landingPages/dataProvider/dataProvider.service.ts +++ b/landingPages/dataProvider/dataProvider.service.ts @@ -195,7 +195,7 @@ export class DataProviderService { this.dataProviderInfo.thematic = datasource.thematic; if(datasource.jurisdiction) { - this.dataProviderInfo.jurisdiction = datasource.jurisdiction.classname; + this.dataProviderInfo.jurisdiction = datasource.jurisdiction.label; } // TODO: Add check for array diff --git a/landingPages/organization/deletedByInference/deletedByInference.service.ts b/landingPages/organization/deletedByInference/deletedByInference.service.ts index fc07dafa..e05a7258 100644 --- a/landingPages/organization/deletedByInference/deletedByInference.service.ts +++ b/landingPages/organization/deletedByInference/deletedByInference.service.ts @@ -13,6 +13,9 @@ export class OrganizationsDeletedByInferenceService { public parsingFunctions: ParsingFunctions; + /** + * @deprecated + */ getDeletedByInferenceResults(id: string, size: string, properties: EnvProperties): any { let url = properties.searchAPIURLLAst + 'deletedByInferenceOrganizations/' + id + "?format=json&size=" + size; @@ -21,6 +24,9 @@ export class OrganizationsDeletedByInferenceService { .pipe(map(res => this.parseDeletedByInferenceResults(res, properties))); } + /** + * @deprecated + */ parseDeletedByInferenceResults(_results: any, properties: EnvProperties): OrganizationInfo[] { let results: OrganizationInfo[] = []; if (_results) { diff --git a/landingPages/project/project.service.ts b/landingPages/project/project.service.ts index 5ce159de..fa5c77fb 100644 --- a/landingPages/project/project.service.ts +++ b/landingPages/project/project.service.ts @@ -58,6 +58,9 @@ export class ProjectService { } + /** + * @deprecated + */ getHTMLInfo(id: string, properties: EnvProperties): any { let url = properties.searchAPIURLLAst + 'projects/' + id + "?format=json"; let key = url; diff --git a/landingPages/result/deletedByInference/deletedByInference.component.ts b/landingPages/result/deletedByInference/deletedByInference.component.ts index be2402b5..96208f35 100644 --- a/landingPages/result/deletedByInference/deletedByInference.component.ts +++ b/landingPages/result/deletedByInference/deletedByInference.component.ts @@ -92,33 +92,27 @@ export class DeletedByInferenceComponent { for (let i = 0; i < length; i++) { let result = Array.isArray(this.children) ? this.children[i] : this.children; let preview = new ResultPreview(); - if(result.hasOwnProperty("creator")) { + if(result["author"]) { preview.authors = []; - let authorsLength = Array.isArray(result.creator) ? result.creator.length : 1; + let authorsLength = Array.isArray(result.author) ? result.author.length : 1; for (let j = 0; j < authorsLength; j++) { - let author = {"fullName": Array.isArray(result.creator) ? result.creator[j] : result.creator, "orcid": null, "orcid_pending": null}; + let author = {"fullName": Array.isArray(result.author) ? result.author[j] : result.author, "orcid": null, "orcid_pending": null}; preview.authors.push(author); } } if(result.hasOwnProperty("dateofacceptance")) { preview.year = new Date(result.dateofacceptance).getFullYear().toString(); } - if(result.hasOwnProperty("title")) { - let titleLength = Array.isArray(result.title) ? result.title.length : 1; - for (let j = 0; j < titleLength; j++) { - let title = Array.isArray(result.title) ? result.title[j] : result.title; - if (!preview.title || title.classid == "main title") { - preview.title = StringUtils.HTMLToString(String(title.content)); - } - } + if (result['title']) { + preview.title = StringUtils.HTMLToString(String(result['title'])); } + if(result.hasOwnProperty("description")) { preview.description = result.description; } - preview.resultType = result?.resulttype?.classid ? result.resulttype.classid : this.resultType; + preview.resultType = result?.resulttype ? result.resulttype : this.resultType; - - if (result.hasOwnProperty("instance")) { + if (result.hasOwnProperty("instances")) { preview.hostedBy_collectedFrom = new Array(); preview.types = new Array(); @@ -127,10 +121,10 @@ export class DeletedByInferenceComponent { let counter = 0; let instance; - let instanesLength = Array.isArray(result['instance']) ? result['instance'].length : 1; + let instanesLength = Array.isArray(result['instances']) ? result['instances'].length : 1; for (let j = 0; j < instanesLength; j++) { - instance = Array.isArray(result['instance']) ? result['instance'][j] : result['instance']; + instance = Array.isArray(result['instances']) ? result['instances'][j] : result['instances']; if(result.hasOwnProperty('collectedfrom')) { if(Array.isArray(result['collectedfrom'])) { // not sure if this is correct mapping @@ -142,12 +136,12 @@ export class DeletedByInferenceComponent { parsingFunctions.parseTypes(preview.types, types, instance); - if (instance.hasOwnProperty("webresource")) { + if (instance.hasOwnProperty("url")) { let url; - if (!Array.isArray(instance['webresource'])) { - url = instance['webresource'].url; + if (!Array.isArray(instance['url'])) { + url = instance['url']; } else { - url = instance['webresource'][0].url; + url = instance['url'][0]; } if (url.includes('&')) { url = url.replace(/&/gmu, '&'); diff --git a/landingPages/result/deletedByInference/deletedByInference.service.ts b/landingPages/result/deletedByInference/deletedByInference.service.ts index f3b3754c..5914e08e 100644 --- a/landingPages/result/deletedByInference/deletedByInference.service.ts +++ b/landingPages/result/deletedByInference/deletedByInference.service.ts @@ -16,6 +16,9 @@ export class DeletedByInferenceService { public parsingFunctions: ParsingFunctions; + /** + * @deprecated + */ getDeletedByInferenceResults (id: string, size: string, properties:EnvProperties):any { let url = properties.searchAPIURLLAst + 'deletedByInferenceResults/' +id+"?format=json&size="+size; let key = url; @@ -26,6 +29,9 @@ export class DeletedByInferenceService { .pipe(map(res => this.parseDeletedByInferenceResults(res))); } + /** + * @deprecated + */ parseDeletedByInferenceResults (_results: any): ResultLandingInfo[] { /*title, authors, abstract, List of projects, PIDs, collectedfrom (link pointing to the download url), access rights*/ diff --git a/landingPages/result/resultLanding.component.html b/landingPages/result/resultLanding.component.html index f11ea7ce..757f884a 100644 --- a/landingPages/result/resultLanding.component.html +++ b/landingPages/result/resultLanding.component.html @@ -721,25 +721,25 @@ res.json()) - .pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:organization'])) + // .pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:organization'])) .pipe(map(res => this.parseOrganizationNameAndUrl(res))); } @@ -111,7 +111,12 @@ export class OrganizationService { return this.organizationInfo; } - parseOrganizationNameAndUrl(organization: any): any { + parseOrganizationNameAndUrl(res: any): any { + if(!res || res.organization) { + return null; + } + let organization = res.organization; + let title: {"name": string, "url": string} = {"name": "", "url": ""}; if(organization != null) { diff --git a/services/searchDataproviders.service.ts b/services/searchDataproviders.service.ts index 35653c30..e9a75bb1 100644 --- a/services/searchDataproviders.service.ts +++ b/services/searchDataproviders.service.ts @@ -132,7 +132,8 @@ export class SearchDataprovidersService { result['type'] = this.getDataproviderType(resData); if (resData['eosctype']) { - result.entityType = resData['eosctype'].classname == "Service" ? "service" : "dataprovider"; + // TODO: Check if field is available, .label is correct? + result.entityType = resData['eosctype'].label == "Service" ? "service" : "dataprovider"; } let abstracts = this.parsingFunctions.parseDescription(resData.description, true); diff --git a/services/searchOrganizations.service.ts b/services/searchOrganizations.service.ts index 86ca6b22..bc22c009 100644 --- a/services/searchOrganizations.service.ts +++ b/services/searchOrganizations.service.ts @@ -17,26 +17,29 @@ export class SearchOrganizationsService { constructor(private http: HttpClient ) {} - 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 { - var results = this._search.searchByDepositType(term, this.depositType, this.properties); - this.showLoading = false; - this.results = results.length; - return results; - }),); - - }else{ + // if(this.entityType == "organization" && this.depositType ){ + // this.filtered = this.searchTermStream.pipe( + // debounceTime(300),distinctUntilChanged(), + // switchMap((term: string) => { + // var results = this._search.searchByDepositType(term, this.depositType, this.properties); + // this.showLoading = false; + // this.results = results.length; + // return results; + // }),); + // + // }else{ this.filtered = this.searchTermStream.pipe( debounceTime(300), @@ -140,7 +140,7 @@ export class EntitiesAutocompleteComponent { }),); this.getSelectedNameFromGivenId(); - } + // } } ngOnDestroy(){ diff --git a/utils/entitiesAutoComplete/entitySearch.service.ts b/utils/entitiesAutoComplete/entitySearch.service.ts index 78d8a47a..9ca8974e 100644 --- a/utils/entitiesAutoComplete/entitySearch.service.ts +++ b/utils/entitiesAutoComplete/entitySearch.service.ts @@ -7,6 +7,8 @@ import {throwError} from 'rxjs'; import{EnvProperties} from '../properties/env-properties'; import {catchError, map} from "rxjs/operators"; +import {StringUtils} from "../string-utils.class"; + @Injectable() export class EntitiesSearchService { public ready:boolean = false; @@ -40,79 +42,79 @@ export class EntitiesSearchService { }*/ // not used - /** - * @deprecated - */ - searchByDepositType(keyword:string, DepositType:string, properties:EnvProperties ):any { - this.ready = false; - - let link = properties.searchResourcesAPIURL; - - let url = link+"?query="; - if(keyword!= null && keyword != '' ) { - /*url += "((oaftype exact organization and deletedbyinference=false and "+ - "(reldatasourcecompatibilityid=driver or reldatasourcecompatibilityid=driver-openaire2.0 or reldatasourcecompatibilityid=openaire2.0 or reldatasourcecompatibilityid=openaire3.0 or reldatasourcecompatibilityid=openaire2.0_data or reldatasourcecompatibilityid=hostedBy or relprojectid=* or reldatasourcecompatibilityid = native))"+ - " and ((organizationlegalname all "+'"'+keyword+'"'+") or (organizationlegalshortname all "+'"'+keyword+'"'+")) " + - // "and " + this.quote(params) + " " + - "and (collectedfrom exact "+StringUtils.quote(StringUtils.URIEncode(DepositType))+")) "*/ - - // in search there is this filter: - //reldatasourcecompatibilityid exact driver or reldatasourcecompatibilityid exact driver-openaire2.0 or reldatasourcecompatibilityid exact openaire2.0 or reldatasourcecompatibilityid exact openaire3.0 or reldatasourcecompatibilityid exact openaire2.0_data or reldatasourcecompatibilityid exact hostedBy or relproject=* - - - //url += "((oaftype exact organization and deletedbyinference=false )"+ - url += "((oaftype exact organization and deletedbyinference=false and"+ - "(reldatasourcecompatibilityid=driver or reldatasourcecompatibilityid=driver-openaire2.0 or reldatasourcecompatibilityid=openaire2.0 or reldatasourcecompatibilityid=openaire3.0 or reldatasourcecompatibilityid=openaire4.0 or reldatasourcecompatibilityid=openaire2.0_data or reldatasourcecompatibilityid=hostedBy or relprojectid=* or reldatasourcecompatibilityid = native))"+ - " and ((organizationlegalname all "+'"'+keyword+'"'+") or (organizationlegalshortname all "+'"'+keyword+'"'+")) " + - // "and " + this.quote(params) + " " + - //"and (collectedfrom exact "+StringUtils.quote(StringUtils.URIEncode(DepositType))+")) " - ")"; - } - - url += "&page=0&size=10"; - url += "&format=json"; - - // let url = properties.searchAPIURLLAst+"projects?"+((keyword && keyword.length > 0)?("q=" +keyword):"")+((funderId && funderId.length > 0 )?"&fq=funderid exact " + '"'+funderId+ '"':"")+"&size=10&page=0&format=json"; - return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).toPromise() - .then(request => - { - //request = request.json().results; - request = request['results']; - //console.log(request); - this.ready = true; - return this.parse(request,"oaf:organization","organization"); - }).catch((ex) => { - console.error('An error occured', ex); - return [{id:'-2',label:'Error'}]; - }); - } + // /** + // * @deprecated + // */ + // searchByDepositType(keyword:string, DepositType:string, properties:EnvProperties ):any { + // this.ready = false; + // + // let link = properties.searchResourcesAPIURL; + // + // let url = link+"?query="; + // if(keyword!= null && keyword != '' ) { + // /*url += "((oaftype exact organization and deletedbyinference=false and "+ + // "(reldatasourcecompatibilityid=driver or reldatasourcecompatibilityid=driver-openaire2.0 or reldatasourcecompatibilityid=openaire2.0 or reldatasourcecompatibilityid=openaire3.0 or reldatasourcecompatibilityid=openaire2.0_data or reldatasourcecompatibilityid=hostedBy or relprojectid=* or reldatasourcecompatibilityid = native))"+ + // " and ((organizationlegalname all "+'"'+keyword+'"'+") or (organizationlegalshortname all "+'"'+keyword+'"'+")) " + + // // "and " + this.quote(params) + " " + + // "and (collectedfrom exact "+StringUtils.quote(StringUtils.URIEncode(DepositType))+")) "*/ + // + // // in search there is this filter: + // //reldatasourcecompatibilityid exact driver or reldatasourcecompatibilityid exact driver-openaire2.0 or reldatasourcecompatibilityid exact openaire2.0 or reldatasourcecompatibilityid exact openaire3.0 or reldatasourcecompatibilityid exact openaire2.0_data or reldatasourcecompatibilityid exact hostedBy or relproject=* + // + // + // //url += "((oaftype exact organization and deletedbyinference=false )"+ + // url += "((oaftype exact organization and deletedbyinference=false and"+ + // "(reldatasourcecompatibilityid=driver or reldatasourcecompatibilityid=driver-openaire2.0 or reldatasourcecompatibilityid=openaire2.0 or reldatasourcecompatibilityid=openaire3.0 or reldatasourcecompatibilityid=openaire4.0 or reldatasourcecompatibilityid=openaire2.0_data or reldatasourcecompatibilityid=hostedBy or relprojectid=* or reldatasourcecompatibilityid = native))"+ + // " and ((organizationlegalname all "+'"'+keyword+'"'+") or (organizationlegalshortname all "+'"'+keyword+'"'+")) " + + // // "and " + this.quote(params) + " " + + // //"and (collectedfrom exact "+StringUtils.quote(StringUtils.URIEncode(DepositType))+")) " + // ")"; + // } + // + // url += "&page=0&size=10"; + // url += "&format=json"; + // + // // let url = properties.searchAPIURLLAst+"projects?"+((keyword && keyword.length > 0)?("q=" +keyword):"")+((funderId && funderId.length > 0 )?"&fq=funderid exact " + '"'+funderId+ '"':"")+"&size=10&page=0&format=json"; + // return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url).toPromise() + // .then(request => + // { + // //request = request.json().results; + // request = request['results']; + // //console.log(request); + // this.ready = true; + // return this.parse(request,"oaf:organization","organization"); + // }).catch((ex) => { + // console.error('An error occured', ex); + // return [{id:'-2',label:'Error'}]; + // }); + // } searchByType(keyword:string,type:string, properties:EnvProperties ){ if (type == "project"){ - return this.searchEntity(keyword,"projects","oaf:project","project", properties); + return this.searchEntity(keyword,"projects","project","project", properties); }else if (type == "dataset"){ - return this.searchEntity(keyword,"datasets","oaf:result","dataset", properties); + return this.searchEntity(keyword,"datasets","result","dataset", properties); }else if (type == "datasource" || type == "hostedBy" || type== "collectedFrom"){ - return this.searchEntity(keyword,"datasources","oaf:datasource","datasource", properties); + return this.searchEntity(keyword,"datasources","datasource","datasource", properties); }else if (type == "publication"){ - return this.searchEntity(keyword,"publications","oaf:result","publication", properties); + return this.searchEntity(keyword,"publications","result","publication", properties); }else if (type == "organization"){ - return this.searchEntity(keyword,"organizations","oaf:organization","organization", properties); + return this.searchEntity(keyword,"organizations","organization","organization", properties); } } fetchByType(id:string,type:string, properties:EnvProperties ){ if (type == "project"){ - return this.fetchEntity(id,"projects","oaf:project","project", properties); + return this.fetchEntity(id,"projects","project","project", properties); }else if (type == "dataset"){ - return this.fetchEntity(id,"datasets","oaf:result","dataset", properties); + return this.fetchEntity(id,"datasets","result","dataset", properties); }else if (type == "datasource" || type == "hostedBy" || type== "collectedFrom"){ - return this.fetchEntity(id,"datasources","oaf:datasource","datasource", properties); + return this.fetchEntity(id,"datasources","datasource","datasource", properties); }else if (type == "publication"){ - return this.fetchEntity(id,"publications","oaf:result","publication", properties); + return this.fetchEntity(id,"publications","result","publication", properties); }else if (type == "organization"){ - return this.fetchEntity(id,"organizations","oaf:organization","organization", properties); + return this.fetchEntity(id,"organizations","organization","organization", properties); } @@ -174,105 +176,99 @@ private fetch (link,id,oafEntityType,type, properties:EnvProperties ){ } private parse(data: any,oafEntityType:string, type:string){ - var array:any =[] + let results: any[] = []; let length = Array.isArray(data) ? data.length : 1; - for(let i=0; i