From 95549185d91e436df8824c9e691ba82b011b5037 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Mon, 30 May 2022 10:39:10 +0300 Subject: [PATCH] [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 | Use instead of . 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 instead of . 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". --- .../dataProvider/dataProvider.component.html | 11 +++- .../dataProvider/dataProvider.component.ts | 21 +++++-- .../dataProvider/dataProvider.service.ts | 62 ++++++++++++++----- .../landing-header.component.ts | 5 +- .../result/resultLanding.component.html | 11 +++- .../result/resultLanding.component.ts | 2 +- .../searchUtils/newSearchPage.component.ts | 6 +- services/metrics.service.ts | 1 - services/searchDataproviders.service.ts | 5 ++ utils/entities/dataProviderInfo.ts | 3 + .../result-preview.component.ts | 2 +- utils/string-utils.class.ts | 4 +- 12 files changed, 98 insertions(+), 35 deletions(-) diff --git a/landingPages/dataProvider/dataProvider.component.html b/landingPages/dataProvider/dataProvider.component.html index 416fe498..146e2207 100644 --- a/landingPages/dataProvider/dataProvider.component.html +++ b/landingPages/dataProvider/dataProvider.component.html @@ -75,7 +75,7 @@
- + + + { this.dataProviderInfo = data; this.getProvenanceUrls(); + this.datasourceId = this.dataProviderInfo.objIdentifier; + let pid:Identifier = Identifier.getPIDFromIdentifiers(this.dataProviderInfo.identifiers); + this.canonicalUrl = this.properties.domain+ properties.baseLink + ( pid ? (this.linkToLandingPage.split("?")[0] + "?pid=" + encodeURIComponent(pid.id)): + (this.linkToLandingPage + this.dataProviderInfo.relcanId)); + this.seoService.createLinkForCanonicalURL(this.canonicalUrl); + this.updateUrl(this.canonicalUrl); this.seoService.createLinkForCanonicalURL(this.properties.domain +this.properties.baseLink + this._router.url); if (typeof document !== 'undefined') { this.getDataProviderAggregationStatus(this.dataProviderInfo.originalId); @@ -352,7 +363,7 @@ export class DataProviderComponent { }, err => { //console.log(err); - this.handleError("Error getting "+this.openaireEntities.DATASOURCE+" for id: " + this.datasourceId, err); + this.handleError("Error getting " + this.type + " for " + (this.datasourceId ? ("id: " + this.datasourceId) : ("pid: " + this.identifier.id + " ("+this.identifier.class+")")), err); if (err.status == 404) { this._router.navigate([this.properties.errorLink], { queryParams: { diff --git a/landingPages/dataProvider/dataProvider.service.ts b/landingPages/dataProvider/dataProvider.service.ts index ab6f237e..f1c8598a 100644 --- a/landingPages/dataProvider/dataProvider.service.ts +++ b/landingPages/dataProvider/dataProvider.service.ts @@ -6,6 +6,8 @@ import{EnvProperties} from '../../utils/properties/env-properties'; import {map} from "rxjs/operators"; import {ParsingFunctions} from "../landing-utils/parsingFunctions.class"; import {OpenaireEntities} from "../../utils/properties/searchFields"; +import {Identifier} from "../../utils/string-utils.class"; +import {properties} from "../../../../environments/environment"; @Injectable() @@ -18,24 +20,46 @@ export class DataProviderService { dataProviderInfo: DataProviderInfo; public parsingFunctions: ParsingFunctions; - getDataproviderInfo (id: string, properties:EnvProperties, typePathParam: string):any { - let url = properties.searchAPIURLLAst + typePathParam+ '/' +id +"?format=json"; - let key = url; - - return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - //.map(res => res.json()) - .pipe(map(res => res['result']['metadata']['oaf:entity'])) - .pipe(map(res => [res['oaf:datasource'], - res['oaf:datasource']['datasourcetype'], - res['oaf:datasource']['openairecompatibility'], - res['oaf:datasource']['collectedfrom'], - res['oaf:datasource']['accessinfopackage'], - res['oaf:datasource']['rels']['rel'], - res['oaf:datasource']['journal'] //6 - ])) - .pipe(map(res => this.parseDataProviderInfo(res))); - + private buildDatasourceLandingInfoUrl(id: string, identifier: Identifier, typePathParam: string): string { + if (id) { + return properties.searchAPIURLLAst + typePathParam + "/" + id + '?format=json'; + } else if (identifier) { + return properties.searchAPIURLLAst + "resources2?pid="+encodeURIComponent(identifier.id) + "&pidtype=" + identifier.class + "&type="+typePathParam+"&format=json"; } + } + + getDataproviderInfo (id: string, identifier: Identifier, properties: EnvProperties, typePathParam: string): any { + let url: string = this.buildDatasourceLandingInfoUrl(id, identifier, typePathParam); + let finalUrl: string = (properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url; + return this.http.get(finalUrl) + .pipe(map(res => { + if(!id && identifier) { + if(!res['results'] || res['results'].length == 0) { + throw new HttpErrorResponse({ + status: 404, + statusText: "Not found", + url: finalUrl, + error: "Http failure response for "+finalUrl+": 404 Not Found" + }); + } + return res['results'][0]; + } else { + return res; + } + })) + .pipe(map(res => [res['result']['metadata']['oaf:entity'], res])) + .pipe(map(res => [ + res[0]['oaf:datasource'], // 0 + res[0]['oaf:datasource']['datasourcetype'], // 1 + res[0]['oaf:datasource']['openairecompatibility'], // 2 + res[0]['oaf:datasource']['collectedfrom'], // 3 + res[0]['oaf:datasource']['accessinfopackage'], // 4 + res[0]['oaf:datasource']['rels']['rel'], // 5 + res[0]['oaf:datasource']['journal'], // 6 + res[1] // 7 + ])) + .pipe(map(res => this.parseDataProviderInfo(res))); + } getDataproviderAggregationStatus(original_id: string, properties:EnvProperties):any { //let headers = new Headers({'Content-Type': 'application/json', 'accept': 'application/json'}); @@ -109,6 +133,10 @@ export class DataProviderService { parseDataProviderInfo (data: any):any { this.dataProviderInfo = new DataProviderInfo(); + this.dataProviderInfo.record = data[7]; + this.dataProviderInfo.objIdentifier = data[7]["result"]["header"]["dri:objIdentifier"]; + this.dataProviderInfo.relcanId = ParsingFunctions.parseRelCanonicalId(this.dataProviderInfo.record, "datasource"); + if(data[0] != null) { this.dataProviderInfo.title = {"name": (data[0].englishname)?data[0].englishname: data[0].officialname, "url": data[0].websiteurl}; this.dataProviderInfo.officialName = data[0].officialname; diff --git a/landingPages/landing-utils/landing-header/landing-header.component.ts b/landingPages/landing-utils/landing-header/landing-header.component.ts index a64ebf59..805ded09 100644 --- a/landingPages/landing-utils/landing-header/landing-header.component.ts +++ b/landingPages/landing-utils/landing-header/landing-header.component.ts @@ -6,7 +6,7 @@ import {AlertModal} from "../../../utils/modal/alert"; @Component({ selector: 'landing-header', template: ` -
+
{{entityType}} @@ -49,7 +49,7 @@ import {AlertModal} from "../../../utils/modal/alert"; class="uk-text-primary">Under curation
-
+
@@ -78,6 +78,7 @@ export class LandingHeaderComponent { @Input() modal: AlertModal; @Input() titleClass: string = null; @Input() isTitleH1:boolean =true; + @Input() isSticky: boolean = false; public removeUnknown(array: string[], type: boolean = false): string[] { if (type) { return this.removeDuplicates(array).filter(value => value.toLowerCase() !== 'unknown'); diff --git a/landingPages/result/resultLanding.component.html b/landingPages/result/resultLanding.component.html index c7424b7e..f5980b18 100644 --- a/landingPages/result/resultLanding.component.html +++ b/landingPages/result/resultLanding.component.html @@ -173,7 +173,16 @@ uk-sticky="bottom: true; media: @m" [attr.offset]="offset" cls-active="active">
- + + + ): Identifier { - let classes:string [] = ["doi", "handle", "pmc", "pmid"]; + public static getPIDFromIdentifiers(identifiers: Map): Identifier { + let classes:string [] = ["doi", "handle", "pmc", "pmid", "re3data"]; if(identifiers) { for (let cl of classes){ if(identifiers.get(cl)){