From 0a1e0fbd8a631e568f7f511134ee12caa043459e Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Thu, 16 Feb 2023 16:33:40 +0200 Subject: [PATCH] Add measures and hosteby collected from in search result objects --- .../landing-utils/parsingFunctions.class.ts | 386 +++++++++++------ landingPages/result/resultLanding.service.ts | 361 ++++++---------- .../searchUtils/searchResult.component.html | 6 +- .../searchUtils/searchResult.component.ts | 110 ++--- services/searchResearchResults.service.ts | 390 +++++++++--------- utils/entities/searchResult.ts | 28 +- .../result-preview.component.html | 187 +++++---- .../result-preview.component.less | 21 +- .../result-preview.component.ts | 77 ++-- utils/result-preview/result-preview.ts | 71 ++-- 10 files changed, 852 insertions(+), 785 deletions(-) diff --git a/landingPages/landing-utils/parsingFunctions.class.ts b/landingPages/landing-utils/parsingFunctions.class.ts index 0111e941..06830c66 100644 --- a/landingPages/landing-utils/parsingFunctions.class.ts +++ b/landingPages/landing-utils/parsingFunctions.class.ts @@ -1,5 +1,5 @@ import {HostedByCollectedFrom, Journal, Project, RelationResult} from "../../utils/result-preview/result-preview"; -import {Context, Reference} from "../../utils/entities/resultLandingInfo"; +import {Context, Measure, Reference} from "../../utils/entities/resultLandingInfo"; import {Injectable} from '@angular/core'; import {properties} from "../../../../environments/environment"; import {StringUtils} from "../../utils/string-utils.class"; @@ -8,18 +8,34 @@ import {StringUtils} from "../../utils/string-utils.class"; providedIn: 'root' }) export class ParsingFunctions { - public eoscSubjects = [ - {label: 'EOSC::Jupyter Notebook', link: 'https://' + (properties.environment != 'production'?'beta.':'') + 'marketplace.eosc-portal.eu/services?tag=EOSC%3A%3AJupyter+Notebook', value: 'Jupyter Notebook'}, - {label: 'EOSC::RO-crate', link: 'https://' + (properties.environment != 'production'?'beta.':'') + 'marketplace.eosc-portal.eu/datasources/eosc.psnc.6f0470e3bb9203ec3a7553f3a72a7a1f?q=ROHub', value: 'RO-crate'}, - {label: 'EOSC::Galaxy Workflow', link: 'https://' + (properties.environment != 'production'?'beta.':'') + 'marketplace.eosc-portal.eu/services?tag=EOSC%3A%3AGalaxy+Workflow', value: 'Galaxy Workflow'}, - {label: 'EOSC::Twitter Data', link: 'https://' + (properties.environment != 'production'?'beta.':'') + 'marketplace.eosc-portal.eu/services?tag=EOSC%3A%3ATwitter+Data', value: 'Twitter Data'} - ] + public eoscSubjects = [ + { + label: 'EOSC::Jupyter Notebook', + link: 'https://' + (properties.environment != 'production' ? 'beta.' : '') + 'marketplace.eosc-portal.eu/services?tag=EOSC%3A%3AJupyter+Notebook', + value: 'Jupyter Notebook' + }, + { + label: 'EOSC::RO-crate', + link: 'https://' + (properties.environment != 'production' ? 'beta.' : '') + 'marketplace.eosc-portal.eu/datasources/eosc.psnc.6f0470e3bb9203ec3a7553f3a72a7a1f?q=ROHub', + value: 'RO-crate' + }, + { + label: 'EOSC::Galaxy Workflow', + link: 'https://' + (properties.environment != 'production' ? 'beta.' : '') + 'marketplace.eosc-portal.eu/services?tag=EOSC%3A%3AGalaxy+Workflow', + value: 'Galaxy Workflow' + }, + { + label: 'EOSC::Twitter Data', + link: 'https://' + (properties.environment != 'production' ? 'beta.' : '') + 'marketplace.eosc-portal.eu/services?tag=EOSC%3A%3ATwitter+Data', + value: 'Twitter Data' + } + ] public notebookInSubjects: boolean = false; private notebookKeyword: string = "eosc jupyter notebook"; private notebook_label: string = "EOSC"; private notebook_value: string = "EOSC Jupyter Notebook"; - + public open = 'open_access'; public closed = 'closed_access'; public unknown = 'question_mark'; @@ -28,30 +44,30 @@ export class ParsingFunctions { constructor() { } - + public ngOnDestroy() { } - + public parseFundingByProjects(fundedByProjects: Project[], relation: any): Project[] { if (fundedByProjects == undefined) { fundedByProjects = []; } - + let fundedByProject: Project = { "id": "", "acronym": "", "title": "", "funderShortname": "", "funderName": "", "funding": "", "code": "", "provenanceAction": "", "validated": false }; - + if (relation.title != 'unidentified') { fundedByProject['id'] = relation['to'].content; fundedByProject['acronym'] = relation.acronym; fundedByProject['title'] = relation.title; fundedByProject['code'] = relation.code; - if(relation.validated && relation.validated.date) { + if (relation.validated && relation.validated.date) { fundedByProject['validated'] = true; } - fundedByProject['provenanceAction'] = relation.provenanceaction; + fundedByProject['provenanceAction'] = relation.provenanceaction; } else { fundedByProject['id'] = ""; fundedByProject['acronym'] = ""; @@ -59,11 +75,11 @@ export class ParsingFunctions { fundedByProject['code'] = ""; fundedByProject['provenanceAction'] = ""; } - + if (relation.hasOwnProperty("funding")) { let funding: { "funderName": string, "funderShortname": string, "stream": string }; funding = this.parseFundingTrees(relation.funding); - + if (funding.funderName) { fundedByProject['funderName'] = funding.funderName; } @@ -77,7 +93,7 @@ export class ParsingFunctions { fundedByProjects.push(fundedByProject); return fundedByProjects; } - + // publication & research data : for fundedByProjects | project landing : for funding public parseFundingTrees(fundingTree: any): { "funderName": string, "funderShortname": string, "stream": string } { let funding: { "funderName": string, "funderShortname": string, "stream": string } = { @@ -86,64 +102,64 @@ export class ParsingFunctions { "stream": "" }; let length = Array.isArray(fundingTree) ? fundingTree.length : 1; - + for (let i = 0; i < length; i++) { let fundingData = Array.isArray(fundingTree) ? fundingTree[i] : fundingTree; - + if (fundingData.hasOwnProperty("funder")) { funding.funderShortname = fundingData['funder'].shortname; funding.funderName = fundingData['funder'].name; } - + funding.stream = this.addFundingLevel0(fundingData, funding.stream); - + funding.stream = this.addFundingLevel1(fundingData, funding.stream); - + funding.stream = this.addFundingLevel2(fundingData, funding.stream); } return funding; } - + addFundingLevel0(parent: string, fundingStream: string): string { if (parent.hasOwnProperty("funding_level_0")) { let level0 = parent['funding_level_0']; - + fundingStream += (fundingStream) ? " ; " : ""; fundingStream += level0.name; } return fundingStream; } - + addFundingLevel1(parent: string, fundingStream: string): string { if (parent.hasOwnProperty("funding_level_1")) { let level1 = parent['funding_level_1']; - + // For projects' parsing if (level1.hasOwnProperty("parent")) { fundingStream = this.addFundingLevel0(level1.parent, fundingStream); } - + fundingStream += (fundingStream) ? " | " : ""; fundingStream += level1.name; } return fundingStream; } - + addFundingLevel2(parent: string, fundingStream: string): string { if (parent.hasOwnProperty("funding_level_2")) { let level2 = parent['funding_level_2']; - + // For projects' parsing if (level2.hasOwnProperty("parent")) { fundingStream = this.addFundingLevel1(level2.parent, fundingStream); } - + fundingStream += (fundingStream) ? " | " : ""; fundingStream += level2.name; } return fundingStream; } - + // publication & dataset landing : for collectedFrom parseCollectedFrom(collectedFrom: { "name": string, "id": string }[], _collectedFrom: any) { @@ -152,10 +168,10 @@ export class ParsingFunctions { collectedFrom[length]['name'] = _collectedFrom.name; collectedFrom[length]['id'] = _collectedFrom.id; } - + // publication & dataset landing : for downloadFrom addPublisherToHostedBy_collectedFrom(hostedBy_collectedFrom: HostedByCollectedFrom[], - publisher: string, journal: Journal, + publisher: string, journal: string, identifiers: Map/*, title: { "name": string, "url": string, "accessMode": string}*/) { if (!this.instanceWithDoiExists && publisher && identifiers != null && identifiers.has('doi')) { if (hostedBy_collectedFrom == null) { @@ -171,13 +187,13 @@ export class ParsingFunctions { accessRightIcon: "" }; - if (journal && journal.journal) { + if (journal) { available.downloadNames.push(publisher + "/ " + journal['journal']); } else { available.downloadNames.push(publisher); } - available.downloadUrl = properties.doiURL + identifiers.get("doi")[0];; + available.downloadUrl = properties.doiURL + identifiers.get("doi")[0]; available.accessRightIcon = this.unknown; /* if(title != undefined && title['url'] == "") { @@ -188,16 +204,16 @@ export class ParsingFunctions { } return hostedBy_collectedFrom; } - + // publication & dataset landing : for downloadFrom parseDownloadFrom(downloadFrom: Map, instance: any, url: string) { let key: string = instance['hostedby'].name; - + if (key) { this.addUrlAndAccessMode(downloadFrom, instance, key, url); } } - + // publication & dataset landing : for publishedIn parsePublishedIn(publishedIn: Map, instance: any, result: any, url: string, counter: number): number { if (result != null && result.hasOwnProperty("source")) { @@ -210,7 +226,7 @@ export class ParsingFunctions { } else { key = result['source']; } - + if (key) { this.addUrlAndAccessMode(publishedIn, instance, key, url); counter++; @@ -218,30 +234,30 @@ export class ParsingFunctions { } return counter; } - + // publication & dataset landing : for downloadFrom and publishedIn addUrlAndAccessMode(mapStructure: Map, instance: any, key: string, url: string) { if (!mapStructure.has(key)) { mapStructure.set(key, {"url": null, "accessMode": null, "bestAccessMode": null}); } - + if (mapStructure.get(key)['url'] == null) { mapStructure.get(key)['url'] = new Array(); } - + if (url) { mapStructure.get(key)['url'].push(url); } - + if (mapStructure.get(key)['accessMode'] == null) { mapStructure.get(key)['accessMode'] = new Array(); } - + if (instance.hasOwnProperty("accessright")) { if (url) { mapStructure.get(key)['accessMode'].push(instance['accessright'].classname); } - + if (this.changeBestAccessMode(mapStructure.get(key)['bestAccessMode'], instance['accessright'])) { mapStructure.get(key)['bestAccessMode'] = instance['accessright'].classname; } @@ -252,7 +268,7 @@ export class ParsingFunctions { parseHostedBy_collectedFrom(hostedBy_collectedFrom: HostedByCollectedFrom[], instance: any, url: string, globalAccessRight: string) { - if(!url) { + if (!url) { return; } @@ -287,7 +303,7 @@ export class ParsingFunctions { let length = Array.isArray(instance['collectedfrom']) ? instance['collectedfrom'].length : 1; for (let i = 0; i < length; i++) { let collectedFrom = Array.isArray(instance['collectedfrom']) ? instance['collectedfrom'][i] : instance['collectedfrom']; - if(collectedFrom.name && collectedFrom.id) { + if (collectedFrom.name && collectedFrom.id) { available.collectedNamesAndIds.set(String(collectedFrom.name), collectedFrom.id); } } @@ -298,7 +314,7 @@ export class ParsingFunctions { let length = Array.isArray(instance['instancetype']) ? instance['instancetype'].length : 1; for (let i = 0; i < length; i++) { let instanceType = Array.isArray(instance['instancetype']) ? instance['instancetype'][i] : instance['instancetype']; - if(instanceType.classname && instanceType.classname.toLowerCase() !== "unknown") { + if (instanceType.classname && instanceType.classname.toLowerCase() !== "unknown") { types.add(instanceType.classname); } } @@ -317,7 +333,7 @@ export class ParsingFunctions { } available['downloadUrl'] = url; - if(url.includes("doi.org/")) { + if (url.includes("doi.org/")) { this.instanceWithDoiExists = true; } @@ -348,20 +364,56 @@ export class ParsingFunctions { available.accessRightIcon = this.unknown; } - if(instance.hasOwnProperty("license")) { + if (instance.hasOwnProperty("license")) { available.license = Array.isArray(instance['license']) ? instance['license'][0] : instance['license']; } hostedBy_collectedFrom.push(available); } - + + compareHostedByCollectedFrom(a: HostedByCollectedFrom, b: HostedByCollectedFrom) { + let firstAccessRight: string = (a.accessRight ? a.accessRight.toLowerCase() : null); + let secondAccessRight: string = (b.accessRight ? b.accessRight.toLowerCase() : null); + + if (firstAccessRight === secondAccessRight) { + return 0; + } else { + if (firstAccessRight === 'open access') { + return -1; + } else if (secondAccessRight === 'open access') { + return 1; + } else if (firstAccessRight === "open source") { + return -1; + } else if (secondAccessRight === "open source") { + return 1; + } else if (firstAccessRight === "embargo") { + return -1; + } else if (secondAccessRight === "embargo") { + return 1; + } else if (firstAccessRight === "restricted") { + return -1; + } else if (secondAccessRight === "restricted") { + return 1; + } else if (firstAccessRight === "closed access") { + return -1; + } else if (secondAccessRight === "closed access") { + return 1; + } else if (firstAccessRight === "not available") { + return -1; + } else if (secondAccessRight === "not available") { + return 1; + } + } + return 0; + } + // publication & dataset landing : for downloadFrom and publishedIn changeBestAccessMode(currentAccessMode: string, accessMode: any): boolean { if (!accessMode) { return false; } accessMode = accessMode.classid; - + switch (currentAccessMode) { case null: if (accessMode != "UNKNOWN") { @@ -370,22 +422,22 @@ export class ParsingFunctions { return false; case "CLOSED": if (accessMode == "OPEN" || - accessMode == "OPEN SOURCE" || - accessMode == "EMBARGO" || - accessMode == "RESTRICTED") { + accessMode == "OPEN SOURCE" || + accessMode == "EMBARGO" || + accessMode == "RESTRICTED") { return true; } return false; case "RESTRICTED": if (accessMode == "OPEN" || - accessMode == "OPEN SOURCE" || - accessMode == "EMBARGO") { + accessMode == "OPEN SOURCE" || + accessMode == "EMBARGO") { return true; } return false; case "EMBARGO": if (accessMode == "OPEN" || - accessMode == "OPEN SOURCE") { + accessMode == "OPEN SOURCE") { return true; } return false; @@ -397,7 +449,7 @@ export class ParsingFunctions { } return false; } - + // publication & dataset & software & orp landing : for relatedResearchResults parseResults(researchResults: RelationResult[], relation, provenanceAction: string, relationName: string): RelationResult[] { if (researchResults == undefined) { @@ -417,7 +469,7 @@ export class ParsingFunctions { // researchResult.relationName = relation.to.class; - if(relation['resulttype']) { + if (relation['resulttype']) { if (relation['resulttype'].classname == "publication") { researchResult['class'] = "publication"; } else if (relation['resulttype'].classname == "dataset") { @@ -429,10 +481,10 @@ export class ParsingFunctions { } } researchResult['id'] = relation['to'].content; - if(Array.isArray(relation['title'])) { - for(let i=0; i { let identifiers = new Map(); - + if (pid.hasOwnProperty("classid") && pid['classid'] != "") { if (pid.classid == "doi" || pid.classid == "pmc" || pid.classid == "handle" || pid.classid == "pmid" || pid.classid == "re3data") { if (!identifiers.has(pid.classid)) { identifiers.set(pid.classid, new Array()); } - identifiers.get(pid.classid).push(pid.content+""); + identifiers.get(pid.classid).push(pid.content + ""); } } else { for (let i = 0; i < pid.length; i++) { @@ -488,7 +540,7 @@ export class ParsingFunctions { if (!identifiers.has(pid[i].classid)) { identifiers.set(pid[i].classid, new Array()); } - identifiers.get(pid[i].classid).push(pid[i].content+""); + identifiers.get(pid[i].classid).push(pid[i].content + ""); } } } @@ -505,10 +557,10 @@ export class ParsingFunctions { for (let i = 0; i < length; i++) { subject = Array.isArray(_subjects) ? _subjects[i] : _subjects; - let content: string = subject.code+""; + let content: string = subject.code + ""; let checkAndAddEoscSubjectResp = this.checkAndAddEoscSubject(setOfEoscSubjects, eoscSubjectsFound, subject, content); let found: boolean = checkAndAddEoscSubjectResp["found"]; - if(found) { + if (found) { setOfEoscSubjects = checkAndAddEoscSubjectResp["setOfEoscSubject"]; eoscSubjectsFound = checkAndAddEoscSubjectResp["eoscSubjectsFound"]; } @@ -518,7 +570,7 @@ export class ParsingFunctions { } // publication & dataset landing : for subjects and otherSubjects and classifiedSubjects - parseAllSubjects(_subjects: any, vocabulary: any): [string[], Map, Map, string[], string[], ] { + parseAllSubjects(_subjects: any, vocabulary: any): [string[], Map, Map, string[], string[],] { // let eoscSubjectsFound = []; let subjects: string[]; let otherSubjects: Map; @@ -535,7 +587,7 @@ export class ParsingFunctions { subject = Array.isArray(_subjects) ? _subjects[i] : _subjects; if (subject.classid != "") { if (subject.classid == "keyword") { - let content: string = subject.content+""; + let content: string = subject.content + ""; // let checkAndAddEoscSubjectResp = this.checkAndAddEoscSubject(setOfEoscSubjects, eoscSubjectsFound, subject, content); // let found: boolean = checkAndAddEoscSubjectResp["found"]; // if(found) { @@ -549,22 +601,22 @@ export class ParsingFunctions { // } } else if (!vocabulary || vocabulary[subject.classid] || subject.classid === "SDG" || subject.classid === "FOS") { // if (subject.inferred && subject.inferred == true) { - if(subject.classid === "SDG") { + if (subject.classid === "SDG") { if (sdg == undefined) { sdg = new Array(); } - sdg.push(subject.content+""); - } else if(subject.classid === "FOS") { + sdg.push(subject.content + ""); + } else if (subject.classid === "FOS") { if (fos == undefined) { fos = new Array(); } - fos.push(subject.content+""); + fos.push(subject.content + ""); } else { if (classifiedSubjects == undefined) { classifiedSubjects = new Map(); } - let content: string = subject.content+""; + let content: string = subject.content + ""; // let checkAndAddEoscSubjectResp = this.checkAndAddEoscSubject(setOfEoscSubjects, eoscSubjectsFound, subject, content); // let found: boolean = checkAndAddEoscSubjectResp["found"]; // if(found) { @@ -578,7 +630,7 @@ export class ParsingFunctions { // } } } else { - let content: string = subject.content+""; + let content: string = subject.content + ""; // let checkAndAddEoscSubjectResp = this.checkAndAddEoscSubject(setOfEoscSubjects, eoscSubjectsFound, subject, content); // let found: boolean = checkAndAddEoscSubjectResp["found"]; // if(found) { @@ -600,7 +652,7 @@ export class ParsingFunctions { checkAndAddEoscSubject(setOfEoscSubjects: Set, eoscSubjectsFound, subject, content) { let found: boolean = false; - if(!setOfEoscSubjects.has(content)) { + if (!setOfEoscSubjects.has(content)) { // looping through our declared array this.eoscSubjects.forEach(item => { if (content && content == item.label) { @@ -612,7 +664,7 @@ export class ParsingFunctions { } return {"found": found, "setOfEoscSubject": setOfEoscSubjects, "eoscSubjectsFound": eoscSubjectsFound}; } - + parseContexts(_contexts: any): Context[] { let contexts = new Array(); @@ -623,7 +675,7 @@ export class ParsingFunctions { for (let i = 0; i < length; i++) { let numOfCategories: number = 0; // count categories with label context = Array.isArray(_contexts) ? _contexts[i] : _contexts; - + if (context.label && context.hasOwnProperty("type") && (context['type'] == "community" || context['type'] == "ri")) { if (context.hasOwnProperty("category")) { let category; @@ -639,7 +691,7 @@ export class ParsingFunctions { // initalize if there is concept label or this is the last concept of the category and there were no concepts // otherwise we could have multiple entries for the same category but without concepts - if(categoryConcept.label || (numOfConcepts == 0 && j == (length1 - 1))) { + if (categoryConcept.label || (numOfConcepts == 0 && j == (length1 - 1))) { contexts[position] = { "labelContext": "", "idContext": "", "labelCategory": "", "idCategory": "", @@ -656,10 +708,12 @@ export class ParsingFunctions { numOfConcepts++; } } - } else if(category.label || (numOfCategories == 0 && z == (length2 - 1))) { - contexts[position] = {"labelContext": "", "idContext": "", - "labelCategory": "", "idCategory": "", - "labelConcept": "", "idConcept": ""}; + } else if (category.label || (numOfCategories == 0 && z == (length2 - 1))) { + contexts[position] = { + "labelContext": "", "idContext": "", + "labelCategory": "", "idCategory": "", + "labelConcept": "", "idConcept": "" + }; contexts[position]['labelContext'] = context.label; contexts[position]['idContext'] = context.id; contexts[position]['labelCategory'] = category.label ? category.label : null; @@ -671,9 +725,11 @@ export class ParsingFunctions { } } } else { - contexts[position] = {"labelContext": "", "idContext": "", - "labelCategory": "", "idCategory": "", - "labelConcept": "", "idConcept": ""}; + contexts[position] = { + "labelContext": "", "idContext": "", + "labelCategory": "", "idCategory": "", + "labelConcept": "", "idConcept": "" + }; contexts[position]['labelContext'] = context.label; contexts[position]['idContext'] = context.id; contexts[position]['labelCategory'] = null; @@ -687,11 +743,15 @@ export class ParsingFunctions { } return contexts; } - public static getEnermapsConceptId(contexts: any): string{ - let enermapsconcepts = contexts.filter(c=> {return c.idCategory == "enermaps::selection" && c.idConcept}); - return enermapsconcepts && enermapsconcepts.length > 0?enermapsconcepts[0].idConcept.split("enermaps::selection::")[1]:null; + + public static getEnermapsConceptId(contexts: any): string { + let enermapsconcepts = contexts.filter(c => { + return c.idCategory == "enermaps::selection" && c.idConcept + }); + return enermapsconcepts && enermapsconcepts.length > 0 ? enermapsconcepts[0].idConcept.split("enermaps::selection::")[1] : null; // return "hotmaps_heat_tot_curr_density" } + parseTypes(types: string[], uniqueTypes: Set, instance: any) { if (instance && instance.hasOwnProperty("instancetype") && instance['instancetype'].classname) { if (!uniqueTypes.has(instance['instancetype'].classname)) { @@ -700,7 +760,7 @@ export class ParsingFunctions { } } } - + parseLanguages(_languages: any) { var languages = new Array(); @@ -717,10 +777,10 @@ export class ParsingFunctions { } return languages; } - + parseCountries(_countries: any) { var countries = new Array(); - + if (!Array.isArray(_countries)) { if (_countries.classname != "Undetermined" && _countries.classname) { countries.push(_countries.classname); @@ -734,10 +794,10 @@ export class ParsingFunctions { } return countries; } - + parseProgrammingLanguages(_pLanguages) { var pLanguages = new Array(); - + if (!Array.isArray(_pLanguages)) { if (_pLanguages.classname != "Undetermined" && _pLanguages.classname) { pLanguages.push(_pLanguages.classname); @@ -751,16 +811,16 @@ export class ParsingFunctions { } return pLanguages; } - + parseReferences(citations: any): Reference[] { let references: Reference[] = []; citations = Array.isArray(citations) ? citations : [citations]; citations.forEach(citation => { let reference: Reference = {name: null, ids: []}; - if(citation.rawText) { + if (citation.rawText) { reference.name = citation.rawText; } - if(citation.id) { + if (citation.id) { let ids: any[] = Array.isArray(citation.id) ? citation.id : [citation.id]; ids.forEach(id => { reference.ids.push({ @@ -774,35 +834,117 @@ export class ParsingFunctions { }); return references; } - static parseRelCanonicalId(record, type){ - try{ - if(record["result"]["metadata"]["oaf:entity"][("oaf:"+type)]["children"] && record["result"]["metadata"]["oaf:entity"][("oaf:"+type)]["children"][type]){ - for(let child of record["result"]["metadata"]["oaf:entity"][("oaf:"+type)]["children"][type]){ + + static parseRelCanonicalId(record, type) { + try { + if (record["result"]["metadata"]["oaf:entity"][("oaf:" + type)]["children"] && record["result"]["metadata"]["oaf:entity"][("oaf:" + type)]["children"][type]) { + for (let child of record["result"]["metadata"]["oaf:entity"][("oaf:" + type)]["children"][type]) { return child["objidentifier"]; } } - }catch(e){ + } catch (e) { // console.error(e); } - return record["result"]["header"]["dri:objIdentifier"]; + return record["result"]["header"]["dri:objIdentifier"]; } - parseDescription(description, stripHTML: boolean = false):string { + parseDescription(description, stripHTML: boolean = false): string { let abstracts = []; - if(!Array.isArray(description)) { + if (!Array.isArray(description)) { abstracts = [description ? String(description) : ""]; } else { - abstracts = description.map( x => String(x)); + abstracts = description.map(x => String(x)); } - try{ - abstracts = abstracts.map( x => StringUtils.HTMLToString(x)); - } catch (e) {} - abstracts = abstracts.sort((a,b) => b.length - a.length); - if(stripHTML) { - return abstracts.join(' '); - } else { - return abstracts.length > 0 ? ('

' + abstracts.join('

') + '

') : abstracts.join(' '); - } + try { + abstracts = abstracts.map(x => StringUtils.HTMLToString(x)); + } catch (e) { + } + abstracts = abstracts.sort((a, b) => b.length - a.length); + if (stripHTML) { + return abstracts.join(' '); + } else { + return abstracts.length > 0 ? ('

' + abstracts.join('

') + '

') : abstracts.join(' '); + } + } + + parseMeasures(measures: any[]): Measure { + if (measures.length) { + let parsed: Measure = { + "downloads": null, + "views": null, + "popularity": null, + "influence": null, + "citations": null, + "impulse": null + }; + measures.forEach(measure => { + if (measure.id == 'downloads') { + // parsed.downloads = measure.count == 0 ? ' - ' : measure.count; + parsed.downloads = measure.count; + } + if (measure.id == 'views') { + // parsed.views = measure.count == 0 ? ' - ' : measure.count; + parsed.views = measure.count; + } + if (measure.id == 'influence') { + if (measure.class == 'C1') { + parsed.influence = 'Top 0.01%'; + } else if (measure.class == 'C2') { + parsed.influence = 'Top 0.1%'; + } else if (measure.class == 'C3') { + parsed.influence = 'Top 1%'; + } else if (measure.class == 'C4') { + parsed.influence = 'Top 10%'; + } else if (measure.class == 'A') { + parsed.influence = 'Exceptional'; + } else if (measure.class == 'B') { + parsed.influence = 'Substantial'; + } else { + parsed.influence = 'Average'; + } + } + if (measure.id == 'popularity') { + if (measure.class == 'C1') { + parsed.popularity = 'Top 0.01%'; + } else if (measure.class == 'C2') { + parsed.popularity = 'Top 0.1%'; + } else if (measure.class == 'C3') { + parsed.popularity = 'Top 1%'; + } else if (measure.class == 'C4') { + parsed.popularity = 'Top 10%'; + } else if (measure.class == 'A') { + parsed.popularity = 'Exceptional'; + } else if (measure.class == 'B') { + parsed.popularity = 'Substantial'; + } else { + parsed.popularity = 'Average'; + } + } + if (measure.id == 'influence_alt') { + // parsed['citations'] = measure.score == 0 ? ' - ' : measure.score; + parsed.citations = measure.score; + } + if (measure.id == 'impulse') { + if (measure.class == 'C1') { + parsed.impulse = 'Top 0.01%'; + } else if (measure.class == 'C2') { + parsed.impulse = 'Top 0.1%'; + } else if (measure.class == 'C3') { + parsed.impulse = 'Top 1%'; + } else if (measure.class == 'C4') { + parsed.impulse = 'Top 10%'; + } else if (measure.class == 'A') { + parsed.impulse = 'Exceptional'; + } else if (measure.class == 'B') { + parsed.impulse = 'Substantial'; + } else { + parsed.impulse = 'Average'; + } + } + }); + return parsed; + } + return null; } } diff --git a/landingPages/result/resultLanding.service.ts b/landingPages/result/resultLanding.service.ts index ee715a76..e0b90f92 100644 --- a/landingPages/result/resultLanding.service.ts +++ b/landingPages/result/resultLanding.service.ts @@ -13,7 +13,7 @@ import {HelperFunctions} from "../../utils/HelperFunctions.class"; @Injectable() export class ResultLandingService { - constructor(private http: HttpClient ) { + constructor(private http: HttpClient) { this.parsingFunctions = new ParsingFunctions(); } @@ -39,7 +39,7 @@ export class ResultLandingService { } else if (identifier) { // pid = "10.3389/fphys.2014.00466"; let url = properties.searchAPIURLLAst + "resources2"; - url += "?pid="+encodeURIComponent(identifier.id) + "&pidtype=" + identifier.class + "&type="; + url += "?pid=" + encodeURIComponent(identifier.id) + "&pidtype=" + identifier.class + "&type="; if (type === 'publication') { url += 'publications'; } else if (type === 'dataset') { @@ -56,50 +56,50 @@ export class ResultLandingService { } } - getResultLandingInfo (id: string, identifier: Identifier, type: string, - subjectsVocabulary: any, - properties: EnvProperties): any { + getResultLandingInfo(id: string, identifier: Identifier, type: string, + subjectsVocabulary: any, + properties: EnvProperties): any { let url: string = this.buildResultLandingInfoUrl(id, identifier, type); 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" - }); + .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; } - return res['results'][0]; - } else { - return res; - } - })) - .pipe(map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity'], res])) - .pipe(map(res => [ - res[1]['oaf:result'], // 0 - res[1]['oaf:result']['title'], // 1 - res[1]['oaf:result']['rels']['rel'], // 2 - res[1]['oaf:result']['children'], // 3 - res[1]['oaf:result']['pid'], // 4 - res[1]['oaf:result']['journal'], // 5 - res[1]['oaf:result']['language'], // 6 - res[1]['oaf:result']['eoscifguidelines'], // 7 - res[1]['oaf:result']['subject'], // 8 - res[1]['oaf:result']['context'], // 9 - res[1]['oaf:result']['creator'], // 10 - res[1]['oaf:result']['country'] , // 11 - res[1]['oaf:result']['programmingLanguage'], // 12 - software - //res[1]['oaf:result']['resulttype'], - (res[1]['extraInfo'] !== undefined && res[1]['extraInfo']['references'] !== undefined) - ? res[1]['extraInfo']['references']['reference'] : null, // 13 - res[0], // 14 - res[2], // 15 - ])) - .pipe(map(res => this.parseResultLandingInfo(res, subjectsVocabulary, properties))); + })) + .pipe(map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity'], res])) + .pipe(map(res => [ + res[1]['oaf:result'], // 0 + res[1]['oaf:result']['title'], // 1 + res[1]['oaf:result']['rels']['rel'], // 2 + res[1]['oaf:result']['children'], // 3 + res[1]['oaf:result']['pid'], // 4 + res[1]['oaf:result']['journal'], // 5 + res[1]['oaf:result']['language'], // 6 + res[1]['oaf:result']['eoscifguidelines'], // 7 + res[1]['oaf:result']['subject'], // 8 + res[1]['oaf:result']['context'], // 9 + res[1]['oaf:result']['creator'], // 10 + res[1]['oaf:result']['country'], // 11 + res[1]['oaf:result']['programmingLanguage'], // 12 - software + //res[1]['oaf:result']['resulttype'], + (res[1]['extraInfo'] !== undefined && res[1]['extraInfo']['references'] !== undefined) + ? res[1]['extraInfo']['references']['reference'] : null, // 13 + res[0], // 14 + res[2], // 15 + ])) + .pipe(map(res => this.parseResultLandingInfo(res, subjectsVocabulary, properties))); } // getProvenanceActionVocabulary (properties: EnvProperties): any { @@ -118,15 +118,15 @@ export class ResultLandingService { // return provenanceActionVocabulary; // } - private handleError (error: HttpErrorResponse) { + private handleError(error: HttpErrorResponse) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console console.log(error); - return throwError(error || 'Server error'); + return throwError(error || 'Server error'); } - parseResultLandingInfo (data: any, subjectsVocabulary: any, properties: EnvProperties): any { - this.resultLandingInfo = new ResultLandingInfo(); + parseResultLandingInfo(data: any, subjectsVocabulary: any, properties: EnvProperties): any { + this.resultLandingInfo = new ResultLandingInfo(); // res this.resultLandingInfo.record = data[15]; this.resultLandingInfo.objIdentifier = data[15]["result"]["header"]["dri:objIdentifier"]; @@ -136,25 +136,25 @@ export class ResultLandingService { // res['result']['metadata']['oaf:entity']['oaf:result'] if (data[0] != null) { let date: string = (data[0].dateofacceptance ? data[0].dateofacceptance : '') + ''; // transform to string in case it is an integer - this.resultLandingInfo.date = (date && (date).indexOf('-') !== -1) ? date.split('-')[0] : date; - this.resultLandingInfo.dateofacceptance = data[0].dateofacceptance?Dates.getDate(data[0].dateofacceptance):null; + this.resultLandingInfo.date = (date && (date).indexOf('-') !== -1) ? date.split('-')[0] : date; + this.resultLandingInfo.dateofacceptance = data[0].dateofacceptance ? Dates.getDate(data[0].dateofacceptance) : null; this.resultLandingInfo.publisher = data[0].publisher; - this.resultLandingInfo.description = this.parsingFunctions.parseDescription(data[0] && data[0].description?data[0].description:[]); - this.resultLandingInfo.embargoEndDate = data[0].embargoenddate?Dates.getDate(data[0].embargoenddate):null; + this.resultLandingInfo.description = this.parsingFunctions.parseDescription(data[0] && data[0].description ? data[0].description : []); + this.resultLandingInfo.embargoEndDate = data[0].embargoenddate ? Dates.getDate(data[0].embargoenddate) : null; } - if(data[0]['bestaccessright'] && data[0]['bestaccessright'].hasOwnProperty("classname")) { + if (data[0]['bestaccessright'] && data[0]['bestaccessright'].hasOwnProperty("classname")) { this.resultLandingInfo.accessMode = data[0]['bestaccessright'].classname; } // res['result']['metadata']['oaf:entity']['oaf:result']['title'] - if(data[1] != null) { - if(Array.isArray(data[1])) { - for(let i=0; i(); @@ -226,26 +226,24 @@ export class ResultLandingService { let length = Array.isArray(data[3]['instance']) ? data[3]['instance'].length : 1; - for(let i=0; i { - let firstAccessRight: string = (a.accessRight ? a.accessRight.toLowerCase() : null); - let secondAccessRight: string = (b.accessRight ? b.accessRight.toLowerCase() : null); - - if (firstAccessRight === secondAccessRight) { - return 0; - } else { - if (firstAccessRight === 'open access') { - return -1; - } else if (secondAccessRight === 'open access') { - return 1; - } else if (firstAccessRight === "open source") { - return -1; - } else if (secondAccessRight === "open source") { - return 1; - } else if (firstAccessRight === "embargo") { - return -1; - } else if (secondAccessRight === "embargo") { - return 1; - } else if (firstAccessRight === "restricted") { - return -1; - } else if (secondAccessRight === "restricted") { - return 1; - } else if (firstAccessRight === "closed access") { - return -1; - } else if (secondAccessRight === "closed access") { - return 1; - } else if (firstAccessRight === "not available") { - return -1; - } else if (secondAccessRight === "not available") { - return 1; - } - } - return 0; - }); + this.resultLandingInfo.hostedBy_collectedFrom.sort(this.parsingFunctions.compareHostedByCollectedFrom); } - if(data[3].hasOwnProperty("externalreference")) { + if (data[3].hasOwnProperty("externalreference")) { let externalResults: Map> = this.parseBioentitiesAndSoftware(data[3]); this.resultLandingInfo.bioentities = externalResults; } } // res['result']['metadata']['oaf:entity']['oaf:result']['pid'] - if(data[4] != null) { + if (data[4] != null) { this.resultLandingInfo.identifiers = this.parsingFunctions.parseIdentifiers(data[4]); } // res['result']['metadata']['oaf:entity']['oaf:result']['journal'] - if(data[5] != null) { - this.resultLandingInfo.journal = {"journal": "", "issn": "", "lissn": "", "eissn": "", "issue": "", "volume": "", "start_page": "", "end_page": ""} + if (data[5] != null) { + this.resultLandingInfo.journal = { + "journal": "", + "issn": "", + "lissn": "", + "eissn": "", + "issue": "", + "volume": "", + "start_page": "", + "end_page": "" + } this.resultLandingInfo.journal['journal'] = data[5].content; this.resultLandingInfo.journal['issn'] = data[5].issn; @@ -316,7 +289,7 @@ export class ResultLandingService { } // res['result']['metadata']['oaf:entity']['oaf:result']['language'] - if(data[6] != null) { + if (data[6] != null) { this.resultLandingInfo.languages = this.parsingFunctions.parseLanguages(data[6]); // let languagesAndCodes: string[][] = this.parsingFunctions.parseLanguages(data[6]); // this.resultLandingInfo.languages = languagesAndCodes[0]; @@ -324,27 +297,27 @@ export class ResultLandingService { } // res['result']['metadata']['oaf:entity']['oaf:result']['country'] - if(data[11] != null) { + if (data[11] != null) { this.resultLandingInfo.countries = this.parsingFunctions.parseCountries(data[11]); } // res['result']['metadata']['oaf:entity']['oaf:result']['eoscifguidelines'] - if(data[7] != null) { + if (data[7] != null) { this.resultLandingInfo.eoscSubjects = this.parsingFunctions.parseEoscSubjects(data[7]); } // res['result']['metadata']['oaf:entity']['oaf:result']['subject'] - if(data[8] != null) { + if (data[8] != null) { let subjectResults: [string[], Map, Map, string[], string[]] = this.parsingFunctions.parseAllSubjects(data[8], subjectsVocabulary); this.resultLandingInfo.subjects = subjectResults[0]; this.resultLandingInfo.otherSubjects = subjectResults[1]; this.resultLandingInfo.classifiedSubjects = subjectResults[2]; this.resultLandingInfo.fos = subjectResults[3]; - if(this.resultLandingInfo.fos) { + if (this.resultLandingInfo.fos) { this.resultLandingInfo.fos.sort((a, b) => a.localeCompare(b)) } this.resultLandingInfo.sdg = subjectResults[4]; - if(this.resultLandingInfo.sdg) { + if (this.resultLandingInfo.sdg) { this.resultLandingInfo.sdg.sort((a, b) => { return HelperFunctions.sortSDGs(a, b); }) @@ -356,50 +329,54 @@ export class ResultLandingService { } this.resultLandingInfo.hostedBy_collectedFrom = this.parsingFunctions.addPublisherToHostedBy_collectedFrom( - this.resultLandingInfo.hostedBy_collectedFrom, this.resultLandingInfo.publisher, - this.resultLandingInfo.journal, this.resultLandingInfo.identifiers); + this.resultLandingInfo.hostedBy_collectedFrom, this.resultLandingInfo.publisher, + this.resultLandingInfo.journal.journal, this.resultLandingInfo.identifiers); // res['result']['metadata']['oaf:entity']['oaf:result']['programmingLanguage'] - if(data[12] != null) { + if (data[12] != null) { this.resultLandingInfo.programmingLanguages = this.parsingFunctions.parseProgrammingLanguages(data[12]); } // res['result']['metadata']['oaf:entity']['extraInfo']['references']['reference'] - if(data[13] != null) { + if (data[13] != null) { this.resultLandingInfo.references = this.parsingFunctions.parseReferences(data[13]); } // res['result']['metadata']['oaf:entity']['oaf:result']['context'] - if(data[9] != null) { + if (data[9] != null) { this.resultLandingInfo.contexts = this.parsingFunctions.parseContexts(data[9]); } // res['result']['header']['dri:status'] - if(data[14] != null && data[14] == "under curation") { + if (data[14] != null && data[14] == "under curation") { this.resultLandingInfo.underCurationMessage = true; } else { this.resultLandingInfo.underCurationMessage = false; } // res['result']['metadata']['oaf:entity']['oaf:result']['creator'] - if(data[10] != null) { - if(this.resultLandingInfo.authors == undefined) { - this.resultLandingInfo.authors = new Array<{"fullName": string, "orcid": string, "orcid_pending": string}>(); + if (data[10] != null) { + if (this.resultLandingInfo.authors == undefined) { + this.resultLandingInfo.authors = new Array<{ "fullName": string, "orcid": string, "orcid_pending": string }>(); } let authors = data[10]; let length = Array.isArray(authors) ? authors.length : 1; - for(let i=0; i> { + parseBioentitiesAndSoftware(children: any): Map> { let bioentities: Map>; let length = Array.isArray(children['externalreference']) ? children['externalreference'].length : 1; let externalreference; - for(let i=0; i>(); } - if(!bioentities.has(externalreference.sitename)) { + if (!bioentities.has(externalreference.sitename)) { bioentities.set(externalreference.sitename, new Map()); } bioentities.get(externalreference.sitename).set(externalreference.refidentifier, externalreference.url); @@ -542,10 +453,10 @@ export class ResultLandingService { } getEnermapsDetails(id: string) { - let url = properties.enermapsURL+"/api/db/metadata?shared_id=eq."+id; - return this.http.get((properties.useLongCache)? (properties.cacheUrl+encodeURIComponent(url)): url) - // return this.http.get(url) - .pipe(map(res => this.parseEnermapsDetails(res))); + let url = properties.enermapsURL + "/api/db/metadata?shared_id=eq." + id; + return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) + // return this.http.get(url) + .pipe(map(res => this.parseEnermapsDetails(res))); } parseEnermapsDetails(response: any) { @@ -554,9 +465,9 @@ export class ResultLandingService { let entries = []; let keys = metadata ? Object.keys(metadata) : null; - for(let key of keys) { - if(key != "shared_id" && key && metadata[key]) { - entries.push([key+"", metadata[key]+""]); + for (let key of keys) { + if (key != "shared_id" && key && metadata[key]) { + entries.push([key + "", metadata[key] + ""]); } } return entries; diff --git a/searchPages/searchUtils/searchResult.component.html b/searchPages/searchUtils/searchResult.component.html index 59631a29..f8ff5b0b 100644 --- a/searchPages/searchUtils/searchResult.component.html +++ b/searchPages/searchUtils/searchResult.component.html @@ -1,9 +1,9 @@
    -
  • +
  • + [showSubjects]="showSubjects" [result]="result" [showEnermaps]="showEnermaps" + [isCard]="isMobile" [isMobile]="isMobile">
diff --git a/searchPages/searchUtils/searchResult.component.ts b/searchPages/searchUtils/searchResult.component.ts index 79402ff3..3dfb7b26 100644 --- a/searchPages/searchUtils/searchResult.component.ts +++ b/searchPages/searchUtils/searchResult.component.ts @@ -2,18 +2,19 @@ import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core' import {SearchResult} from '../../utils/entities/searchResult'; import {EnvProperties} from '../../utils/properties/env-properties'; import {ResultPreview} from "../../utils/result-preview/result-preview"; -import {HttpClient} from "@angular/common/http"; import {OrcidService} from "../../orcid/orcid.service"; import {Session} from "../../login/utils/helper.class"; import {properties} from "../../../../environments/environment"; +import {LayoutService} from "../../dashboard/sharedComponents/sidebar/layout.service"; +import {Subscription} from "rxjs"; @Component({ selector: 'search-result', templateUrl: 'searchResult.component.html' }) -export class SearchResultComponent implements OnInit, OnChanges { +export class SearchResultComponent implements OnInit, OnChanges { @Input() results: SearchResult[]; - previewResults:ResultPreview[]; + previewResults: ResultPreview[]; @Input() status: number; @Input() type: string; @Input() showLoading: boolean = false; @@ -22,62 +23,73 @@ export class SearchResultComponent implements OnInit, OnChanges { @Input() custom_class: string = ""; @Input() properties: EnvProperties; @Input() showEnermaps: boolean; + public isMobile: boolean = false; + private subscriptions: any[] = []; - constructor( private http: HttpClient/*ATHENA CODE*/ - , private orcidService: OrcidService) { + constructor(private orcidService: OrcidService, + private layoutService: LayoutService) { } - - ngOnInit() {} - sub; + + ngOnInit() { + this.subscriptions.push(this.layoutService.isMobile.subscribe(isMobile => { + this.isMobile = isMobile; + })); + console.log(this.results); + } + ngOnDestroy() { - if(this.sub){ - this.sub.unsubscribe(); - } - } - initialize(){ - this.previewResults = []; - for(let result of this.results){ - this.previewResults.push(this.getResultPreview(result)); - } - - if((properties.adminToolsPortalType == "explore" || properties.adminToolsPortalType == "community" || properties.adminToolsPortalType == "aggregator") - && Session.isLoggedIn() && this.results && this.results.length > 0 - && (this.type == "result" || this.type == "publication" || this.type == "dataset" || this.type == "software" || this.type == "other") - ) { - this.orcidService.getPutCodes(this.previewResults.map( - previewResult => { - if(previewResult.identifiers) { - let pidsArray: string[] = []; - for(let key of Array.from(previewResult.identifiers.keys())) { - pidsArray = pidsArray.concat(previewResult.identifiers.get(key)); - } - return pidsArray;//.join(); - } - })).subscribe( - putCodes => { - for (let i = 0; i < this.previewResults.length; i++) { - if(this.previewResults[i].identifiers) { - this.previewResults[i].orcidPutCodes = putCodes[i]; - // console.debug(i, this.previewResults[i].orcidPutCodes); - } - } - }, error => { - - } - ); - } + this.subscriptions.forEach(subscription => { + if(subscription instanceof Subscription) { + subscription.unsubscribe(); + } + }) } ngOnChanges(changes: SimpleChanges): void { - if (changes.results) { + if (changes.results) { this.initialize(); } } - public getResultPreview(result: SearchResult): ResultPreview { - return ResultPreview.searchResultConvert(result, (result.entityType)?result.entityType:this.type); + + initialize() { + this.previewResults = []; + for (let result of this.results) { + this.previewResults.push(this.getResultPreview(result)); + } + + if ((properties.adminToolsPortalType == "explore" || properties.adminToolsPortalType == "community" || properties.adminToolsPortalType == "aggregator") + && Session.isLoggedIn() && this.results && this.results.length > 0 + && (this.type == "result" || this.type == "publication" || this.type == "dataset" || this.type == "software" || this.type == "other") + ) { + this.subscriptions.push(this.orcidService.getPutCodes(this.previewResults.map( + previewResult => { + if (previewResult.identifiers) { + let pidsArray: string[] = []; + for (let key of Array.from(previewResult.identifiers.keys())) { + pidsArray = pidsArray.concat(previewResult.identifiers.get(key)); + } + return pidsArray;//.join(); + } + })).subscribe( + putCodes => { + for (let i = 0; i < this.previewResults.length; i++) { + if (this.previewResults[i].identifiers) { + this.previewResults[i].orcidPutCodes = putCodes[i]; + // console.debug(i, this.previewResults[i].orcidPutCodes); + } + } + }, error => { + + } + )); + } } - - + + public getResultPreview(result: SearchResult): ResultPreview { + return ResultPreview.searchResultConvert(result, (result.entityType) ? result.entityType : this.type); + } + + public quote(params: string): string { return '"' + params + '"'; } diff --git a/services/searchResearchResults.service.ts b/services/searchResearchResults.service.ts index 0b450eb7..d83cd21b 100644 --- a/services/searchResearchResults.service.ts +++ b/services/searchResearchResults.service.ts @@ -7,20 +7,20 @@ import {ParsingFunctions} from '../landingPages/landing-utils/parsingFunctions.c import {EnvProperties} from '../utils/properties/env-properties'; import {map} from "rxjs/operators"; import {properties} from "../../../environments/environment"; +import {HostedByCollectedFrom} from "../utils/result-preview/result-preview"; @Injectable() export class SearchResearchResultsService { - private sizeOfDescription: number = 270; public parsingFunctions: ParsingFunctions = new ParsingFunctions(); - constructor(private http: HttpClient=null) { + constructor(private http: HttpClient = null) { } - - + + search(resultType: string, params: string, refineParams: string, page: number, size: number, sortBy: string, refineFields: string[], properties: EnvProperties): any { let link = properties.searchAPIURLLAst + this.getEntityQueryName(resultType, true); - + let url = link + "?"; if (params != null && params != '') { url += params; @@ -32,21 +32,21 @@ export class SearchResearchResultsService { url += "&sortBy=" + sortBy; } 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(resultType, res['results'], properties), RefineResultsUtils.parse(res['refineResults'], refineFields, "publication")])); + .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties), RefineResultsUtils.parse(res['refineResults'], refineFields, "publication")])); } - + searchById(resultType: string, id: string, properties: EnvProperties): any { let url = properties.searchAPIURLLAst + this.getEntityQueryName(resultType, true) + "/" + id + "?format=json"; - + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - .pipe(map(res => this.parseResults(resultType, res, properties))); + .pipe(map(res => this.parseResults(resultType, res, properties))); } - + searchAggregators(resultType: string, id: string, params: string, refineParams: string, page: number, size: number, properties: EnvProperties): any { let link = properties.searchAPIURLLAst + this.getEntityQueryName(resultType, true); - + let url = link + "?" + "&format=json"; if (params != null && params != '') { url += params; @@ -55,33 +55,33 @@ export class SearchResearchResultsService { url += refineParams; } url += "&page=" + (page - 1) + "&size=" + size; - + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - .pipe(map(res => this.parseRefineResults(id, res['refineResults']))); + .pipe(map(res => this.parseRefineResults(id, res['refineResults']))); } - + searchByListOfDOI(resultType: string, DOIs: string[], refineParams: string, page: number, size: number, refineFields: string[], properties: EnvProperties): any { let link = properties.searchAPIURLLAst + this.getEntityQueryName(resultType, true); - + let url = link + "?" + "&format=json&"; var doisParams = ""; - + for (var i = 0; i < DOIs.length; i++) { doisParams += (doisParams.length > 0 ? "&" : "") + 'doi="' + DOIs[i] + '"'; } if (doisParams.length > 0) { url += "&" + doisParams; - + } if (refineParams != null && refineParams != '') { url += refineParams; } 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(resultType, res['results'], properties), RefineResultsUtils.parse(res['refineResults'], refineFields, "publication")])); + .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties), RefineResultsUtils.parse(res['refineResults'], refineFields, "publication")])); } - + advancedSearch(resultType: string, params: string, page: number, size: number, sortBy: string, properties: EnvProperties, refineParams: string = null, refineFields: string[] = null, refineQuery: string = null): any { let url = properties.searchResourcesAPIURL; var basicQuery = "(oaftype exact result) and (resulttypeid exact " + this.getEntityQueryName(resultType, false) + ") "; @@ -101,14 +101,14 @@ export class SearchResearchResultsService { if (refineQuery) { url += "&" + refineQuery; } - + url += "&page=" + (page - 1) + "&size=" + size; url += "&format=json"; - + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties), RefineResultsUtils.parse(res['refineResults'], refineFields, "publication")])); + .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties), RefineResultsUtils.parse(res['refineResults'], refineFields, "publication")])); } - + advancedSearchResults(resultType: string, params: string, page: number, size: number, sortBy: string, properties: EnvProperties, refineParams: string = null, refineFields: string[] = null, refineQuery: string = null): any { let url = properties.searchAPIURLLAst + "resources2/?format=json"; if (params != null && params != '') { @@ -124,30 +124,30 @@ export class SearchResearchResultsService { if (refineQuery) { url += "&" + refineQuery; } - + url += "&page=" + (page - 1) + "&size=" + size; // url += "&format=json"; - + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties), RefineResultsUtils.parse(res['refineResults'], refineFields, "publication")])); + .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties), RefineResultsUtils.parse(res['refineResults'], refineFields, "publication")])); } - + searchResultForEntity(resultType: string, params: string, page: number, size: number, properties: EnvProperties): any { let link = properties.searchAPIURLLAst; //let url = link+params+"/"+this.getEntityQueryName(resultType,true)+ "?format=json"; //url += "&page="+(page-1)+"&size="+size; //url += "&sortBy=resultdateofacceptance,descending"; - + //let url = link+"/resources2?format=json&query="+params+" sortBy resultdateofacceptance/sort.descending&type="+this.getEntityQueryName(resultType,true); - + let url = link + "/" + this.getEntityQueryName(resultType, true); url += "?format=json"; url += "&fq=" + params; url += "&sortBy=resultdateofacceptance,descending"; 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(resultType, res['results'], properties)])); + .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties)])); } //???? why different from above? @@ -157,9 +157,9 @@ export class SearchResearchResultsService { url += "&sortBy=resultdateofacceptance,descending"; 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(resultType, res['results'], properties)])); + .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties)])); } - + searchForMyOrcidLinks(resultType: string, orcidQuery: string, typeQuery: string, page: number, size: number): any { let url = properties.searchAPIURLLAst + "resources2/?format=json"; if (orcidQuery != null && orcidQuery != '') { @@ -167,14 +167,14 @@ export class SearchResearchResultsService { } url += typeQuery; 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(resultType, res['results'], properties)])); + .pipe(map(res => [res['meta'].total, this.parseResults(resultType, res['results'], properties)])); } - + parseResults(resultType: string, data: any, properties: EnvProperties): SearchResult[] { let results: SearchResult[] = []; - if(data == null) { + if (data == null) { return results; } @@ -182,135 +182,16 @@ export class SearchResearchResultsService { for (let i = 0; i < length; i++) { let resData = Array.isArray(data) ? data[i]['result']['metadata']['oaf:entity']['oaf:result'] : data['result']['metadata']['oaf:entity']['oaf:result']; - + var result: SearchResult = new SearchResult(); if (resData['resulttype']) { result.entityType = resData['resulttype']['classname']; } else { result.entityType = resultType; } - result.types = new Array(); - let types = new Set(); - - let instance; - let length = Array.isArray(resData['children']['instance']) ? resData['children']['instance'].length : 1; - - for (let i = 0; i < length; i++) { - instance = Array.isArray(resData['children']['instance']) ? resData['children']['instance'][i] : resData['children']['instance']; - this.parsingFunctions.parseTypes(result.types, types, instance); - } - // Measure - result.measure = new Array(); - if (resData['measure'] && Array.isArray(resData['measure'])) { - for (let i = 0; i < resData['measure'].length; i++) { - if (resData['measure'][i].id == 'influence') { - result.measure[1] = resData['measure'][i].class; - if (resData['measure'][i].class == 'C1') { - result.measure[3] = 'Top 0.01% in'; - } else if (resData['measure'][i].class == 'C2') { - result.measure[3] = 'Top 0.1% in'; - } else if (resData['measure'][i].class == 'C3') { - result.measure[3] = 'Top 1% in'; - } else if (resData['measure'][i].class == 'C4') { - result.measure[3] = 'Top 10% in'; - } else if (resData['measure'][i].class == 'A') { - result.measure[3] = 'Exceptional'; - } else if (resData['measure'][i].class == 'B') { - result.measure[3] = 'Substantial'; - } else { - result.measure[3] = 'Average'; - } - } - if (resData['measure'][i].id == 'popularity') { - result.measure[0] = resData['measure'][i].class; - if (resData['measure'][i].class == 'C1') { - result.measure[2] = 'Top 0.01% in'; - } else if (resData['measure'][i].class == 'C2') { - result.measure[2] = 'Top 0.1% in'; - } else if (resData['measure'][i].class == 'C3') { - result.measure[2] = 'Top 1% in'; - } else if (resData['measure'][i].class == 'C4') { - result.measure[2] = 'Top 10% in'; - } else if (resData['measure'][i].class == 'A') { - result.measure[2] = 'Exceptional'; - } else if (resData['measure'][i].class == 'B') { - result.measure[2] = 'Substantial'; - } else { - result.measure[2] = 'Average'; - } - } - } - } - /////////////////////////// Athena Code /////////////////////////// - if (resData['pid']) { - if (!Array.isArray(resData['pid'])) { - if (resData['pid'].classid && resData['pid'].classid == 'doi') { - if (resData['pid'].content != '' && resData['pid'].content != null) { - result.DOIs.push((resData['pid'].content+"").replace("https://doi.org/", "")); - } - } - } else { - for (let i = 0; i < resData['pid'].length; i++) { - if (resData['pid'][i].classid == 'doi') { - if (resData['pid'][i].content != '' && resData['pid'][i].content != null && resData['pid'][i].content) { - result.DOIs.push((resData['pid'][i].content+"").replace("https://doi.org/", "")); - } - } - } - } - result.identifiers = this.parsingFunctions.parseIdentifiers(resData['pid']); - } - /////////////////////////// Athena Code /////////////////////////// - if (resData['programmingLanguage'] && resData['programmingLanguage'] != null) { - result.programmingLanguages = new Array(); - - if (!Array.isArray(resData['programmingLanguage'])) { - if (resData['programmingLanguage'].classname != "Undetermined" && resData['programmingLanguage'].classname) { - result.programmingLanguages.push(resData['programmingLanguage'].classname); - } - } else { - for (let i = 0; i < resData['programmingLanguage'].length; i++) { - if (resData['programmingLanguage'][i].classname != "Undetermined" && resData['programmingLanguage'][i].classname) { - result.programmingLanguages.push(resData['programmingLanguage'][i].classname); - } - } - } - } - - if (resData['language'] && resData['language'] != null) { - result.languages = new Array(); - - if (!Array.isArray(resData['language'])) { - if (resData['language'].classname != "Undetermined" && resData['language'].classname) { - result.languages.push(resData['language'].classname); - } - } else { - for (let i = 0; i < resData['language'].length; i++) { - if (resData['language'][i].classname != "Undetermined" && resData['language'][i].classname) { - result.languages.push(resData['language'][i].classname); - } - } - } - } - - if (resData['country'] && resData['country'] != null) { - result.countriesForResults = new Array(); - - if (!Array.isArray(resData['country'])) { - if (resData['country'].classname != "Undetermined" && resData['country'].classname) { - result.countriesForResults.push(resData['country'].classname); - } - } else { - for (let i = 0; i < resData['country'].length; i++) { - if (resData['country'][i].classname != "Undetermined" && resData['country'][i].classname) { - result.countriesForResults.push(resData['country'][i].classname); - } - } - } - } - + result['title'] = {"name": '', "accessMode": ''}; - + if (Array.isArray(resData['title'])) { for (let i = 0; i < resData['title'].length; i++) { if (resData['title'][i] && resData['title'][i].content) { @@ -329,7 +210,107 @@ export class SearchResearchResultsService { } else { result['title'].name = (resData['title'] && resData['title'].content) ? StringUtils.HTMLToString(String(resData['title'].content)) : ""; } - + + if (resData['bestaccessright'] && resData['bestaccessright'].hasOwnProperty("classname")) { + result['title'].accessMode = resData['bestaccessright'].classname; + } + + result.types = new Array(); + let types = new Set(); + + let instance; + let length = Array.isArray(resData['children']['instance']) ? resData['children']['instance'].length : 1; + for (let i = 0; i < length; i++) { + instance = Array.isArray(resData['children']['instance']) ? resData['children']['instance'][i] : resData['children']['instance']; + this.parsingFunctions.parseTypes(result.types, types, instance); + if(instance?.hasOwnProperty("hostedby")) { + result.hostedBy_collectedFrom = new Array(); + if(instance.hasOwnProperty("webresource")) { + let url = Array.isArray(instance['webresource'])?instance['webresource'][0].url:instance['webresource'].url; + if(url.includes('&')) { + url = url.replace(/&/gmu, '&'); + } + if(instance.hasOwnProperty("hostedby")) { + this.parsingFunctions.parseHostedBy_collectedFrom(result.hostedBy_collectedFrom, instance, url, result.title.accessMode); + } + result.hostedBy_collectedFrom.sort(this.parsingFunctions.compareHostedByCollectedFrom); + } + } + let journal = resData['journal']?resData['journal'].content:null; + result.hostedBy_collectedFrom = this.parsingFunctions.addPublisherToHostedBy_collectedFrom( + result.hostedBy_collectedFrom, result.publisher, + journal, result.identifiers); + } + // Measure + result.measure = this.parsingFunctions.parseMeasures(resData['measure']); + /////////////////////////// Athena Code /////////////////////////// + if (resData['pid']) { + if (!Array.isArray(resData['pid'])) { + if (resData['pid'].classid && resData['pid'].classid == 'doi') { + if (resData['pid'].content != '' && resData['pid'].content != null) { + result.DOIs.push((resData['pid'].content + "").replace("https://doi.org/", "")); + } + } + } else { + for (let i = 0; i < resData['pid'].length; i++) { + if (resData['pid'][i].classid == 'doi') { + if (resData['pid'][i].content != '' && resData['pid'][i].content != null && resData['pid'][i].content) { + result.DOIs.push((resData['pid'][i].content + "").replace("https://doi.org/", "")); + } + } + } + } + result.identifiers = this.parsingFunctions.parseIdentifiers(resData['pid']); + } + /////////////////////////// Athena Code /////////////////////////// + if (resData['programmingLanguage'] && resData['programmingLanguage'] != null) { + result.programmingLanguages = new Array(); + + if (!Array.isArray(resData['programmingLanguage'])) { + if (resData['programmingLanguage'].classname != "Undetermined" && resData['programmingLanguage'].classname) { + result.programmingLanguages.push(resData['programmingLanguage'].classname); + } + } else { + for (let i = 0; i < resData['programmingLanguage'].length; i++) { + if (resData['programmingLanguage'][i].classname != "Undetermined" && resData['programmingLanguage'][i].classname) { + result.programmingLanguages.push(resData['programmingLanguage'][i].classname); + } + } + } + } + + if (resData['language'] && resData['language'] != null) { + result.languages = new Array(); + + if (!Array.isArray(resData['language'])) { + if (resData['language'].classname != "Undetermined" && resData['language'].classname) { + result.languages.push(resData['language'].classname); + } + } else { + for (let i = 0; i < resData['language'].length; i++) { + if (resData['language'][i].classname != "Undetermined" && resData['language'][i].classname) { + result.languages.push(resData['language'][i].classname); + } + } + } + } + + if (resData['country'] && resData['country'] != null) { + result.countriesForResults = new Array(); + + if (!Array.isArray(resData['country'])) { + if (resData['country'].classname != "Undetermined" && resData['country'].classname) { + result.countriesForResults.push(resData['country'].classname); + } + } else { + for (let i = 0; i < resData['country'].length; i++) { + if (resData['country'][i].classname != "Undetermined" && resData['country'][i].classname) { + result.countriesForResults.push(resData['country'][i].classname); + } + } + } + } + result['id'] = Array.isArray(data) ? data[i]['result']['header']['dri:objIdentifier'] : data['result']['header']['dri:objIdentifier']; result['objId'] = result['id']; let canId = ParsingFunctions.parseRelCanonicalId(Array.isArray(data) ? data[i] : data, "result"); @@ -337,16 +318,13 @@ export class SearchResearchResultsService { result['id'] = canId; } result['relcanId'] = result['id']; - - if (resData['bestaccessright'] && resData['bestaccessright'].hasOwnProperty("classname")) { - result['title'].accessMode = resData['bestaccessright'].classname; - } + 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")) { if (relation['to'].class && relation['to'].class.toLowerCase() == "isproducedby") { result['projects'] = this.parseProjects(result['projects'], relation); @@ -354,22 +332,22 @@ export class SearchResearchResultsService { } } } - + if (resData.hasOwnProperty("creator") && resData['creator'] != null) { if (result['authors'] == undefined) { result['authors'] = new Array<{ "fullName": string, "orcid": string, "orcid_pending": string }>(); } - + let authors = resData['creator']; let length = Array.isArray(authors) ? authors.length : 1; - + for (let i = 0; i < length; i++) { let author = Array.isArray(authors) ? authors[i] : authors; if (author) { - if(author.orcid) { + if (author.orcid) { author.orcid = author.orcid.toUpperCase(); } - if(author.orcid_pending) { + if (author.orcid_pending) { author.orcid_pending = author.orcid_pending.toUpperCase(); } result['authors'][author.rank] = { @@ -383,20 +361,20 @@ export class SearchResearchResultsService { return (item != undefined && item.fullName != undefined); }); } - + var date: string = (resData.dateofacceptance ? resData.dateofacceptance : '') + ''; // transform to string in case it is an integer result.year = (date && (date).indexOf('-') !== -1) ? date.split('-')[0] : date; let abstracts = this.parsingFunctions.parseDescription(resData.description, true); - result.description = abstracts; + result.description = abstracts; // if (result.description && result.description.length > this.sizeOfDescription) { // result.description = result.description.substring(0, this.sizeOfDescription) + "..."; // } - + if (resData.embargoenddate && resData.embargoenddate != '') { result.embargoEndDate = Dates.getDate(resData.embargoenddate); } - + if (!Array.isArray(resData.publisher)) { result.publisher = resData.publisher; } else { @@ -408,14 +386,14 @@ export class SearchResearchResultsService { } } } - if(resData['context'] != null) { + if (resData['context'] != null) { result.enermapsId = ParsingFunctions.getEnermapsConceptId(this.parsingFunctions.parseContexts(resData['context'])); } results.push(result); } return results; } - + parseProjects(projects: { "id": string, "acronym": string, "title": string, "funderShortname": string, "funderName": string, @@ -432,15 +410,15 @@ export class SearchResearchResultsService { "code": string }>(); } - + let countProjects = projects.length; - + projects[countProjects] = { "id": "", "acronym": "", "title": "", "funderShortname": "", "funderName": "", "code": "" }; - + if (relation.title != 'unidentified') { projects[countProjects]['id'] = relation['to'].content; projects[countProjects]['acronym'] = relation.acronym; @@ -452,36 +430,36 @@ export class SearchResearchResultsService { projects[countProjects]['title'] = ""; projects[countProjects]['code'] = ""; } - + if (relation.hasOwnProperty("funding")) { let fundingLength = Array.isArray(relation['funding']) ? relation['funding'].length : 1; - + for (let z = 0; z < fundingLength; z++) { let fundingData = Array.isArray(relation['funding']) ? relation['funding'][z] : relation['funding']; - + if (fundingData.hasOwnProperty("funder")) { projects[countProjects]['funderShortname'] = fundingData['funder'].shortname; projects[countProjects]['funderName'] = fundingData['funder'].name; } } } - + return projects; } - + parseRefineResults(id: string, data: any): any { var results: any = []; if (data.hasOwnProperty("resulthostingdatasource")) { let length = Array.isArray(data['resulthostingdatasource']) ? data['resulthostingdatasource'].length : 1; - + for (let i = 0; i < length; i++) { let datasource = Array.isArray(data['resulthostingdatasource']) ? data['resulthostingdatasource'][i] : data['resulthostingdatasource']; - + let result: { "name": string, "id": string, "count": number } = {"name": "", "id": "", "count": 0}; result['name'] = datasource.name; result['id'] = datasource.id.split("||")[0]; result['count'] = datasource.count; - + if (result['id'] != id && result['name'] != "Unknown Repository") { results.push(result); } @@ -489,19 +467,19 @@ export class SearchResearchResultsService { } return results; } - + private numOfResults(url: string, properties: EnvProperties): any { return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - .pipe(map(res => res['total'])); + .pipe(map(res => res['total'])); } - + numOfEntityResults(resultType: string, id: string, entity: string, properties: EnvProperties): any { var parameters: string = ""; parameters = this.getEntityQueryName(entity, true) + "/" + id + "/" + this.getEntityQueryName(resultType, true) + "/count"; let url = properties.searchAPIURLLAst + parameters + "?format=json"; return this.numOfResults(url, properties); } - + numOfResearchOutcomes(params: string, properties: EnvProperties, refineParams: string = null): any { let url = properties.searchAPIURLLAst + "resources2/?format=json&size=0&type=results"; if (params.length > 0) { @@ -518,20 +496,20 @@ export class SearchResearchResultsService { // } 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'])); + .pipe(map(res => res['meta']['total'])); } - + numOfSearchResults(resultType: string, params: string, properties: EnvProperties, refineParams: string = null): any { let url = properties.searchAPIURLLAst + this.getEntityQueryName(resultType, true) + "/count?format=json"; if (params.length > 0) { var DOIs: string[] = DOI.getDOIsFromString(params); var doisParams = ""; - + for (var i = 0; i < DOIs.length; i++) { doisParams += (doisParams.length > 0 ? "&" : "") + 'doi="' + DOIs[i] + '"'; } @@ -541,30 +519,30 @@ export class SearchResearchResultsService { url += "&q=" + StringUtils.URIEncode(params); } } - + if (refineParams != null && refineParams != '') { url += refineParams; } return this.numOfResults(url, properties); } - + numOfSearchResultsLinkedToPub(resultType: string, properties: EnvProperties): any { let url = properties.searchAPIURLLAst + "resources?query=" + encodeURIComponent("( (oaftype exact result) and (resulttypeid exact " + resultType + ") and (relresulttype=publication) )") + "&page=0&size=0&format=json"; return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - .pipe(map(res => res['meta']['total'])); + .pipe(map(res => res['meta']['total'])); } - + countTotalResults(resultType: string, properties: EnvProperties, refineParams: string = null): any { let url = properties.searchAPIURLLAst + this.getEntityQueryName(resultType, true) + "/count?format=json" + refineParams; return this.numOfResults(url, properties); } - + /* private quote(word: any): string { return '"'+word+'"'; } */ - + private getEntityQueryName(entityType: string, plural: boolean) { if (entityType == "publication" || entityType == "dataset" || entityType == "organization" || entityType == "datasource" || entityType == "project") { if (plural) { @@ -578,8 +556,8 @@ export class SearchResearchResultsService { } public countCollectedResultsWithFundingInfo(datasourceId: string) { - let url = properties.searchAPIURLLAst + "resources?query=" + encodeURIComponent("(oaftype=result and collectedfromdatasourceid exact \""+datasourceId+"\" and relprojectid=*)") + "&page=0&size=0&format=json"; + let url = properties.searchAPIURLLAst + "resources?query=" + encodeURIComponent("(oaftype=result and collectedfromdatasourceid exact \"" + datasourceId + "\" and relprojectid=*)") + "&page=0&size=0&format=json"; return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) - .pipe(map(res => res['meta']['total'])); + .pipe(map(res => res['meta']['total'])); } } diff --git a/utils/entities/searchResult.ts b/utils/entities/searchResult.ts index 63bb5054..ff22f9fe 100644 --- a/utils/entities/searchResult.ts +++ b/utils/entities/searchResult.ts @@ -1,36 +1,37 @@ -import {Author, Organization, Project, ResultTitle} from "../result-preview/result-preview"; +import {Author, HostedByCollectedFrom, Organization, Project, ResultTitle} from "../result-preview/result-preview"; +import {Measure} from "./resultLandingInfo"; export class SearchResult { title: ResultTitle; id: string; relcanId: string; objId: string; - DOIs: string[]=[]; + DOIs: string[] = []; identifiers: Map; - measure: Array; + measure: Measure; //publications & datasets & orp & software & projects & dataproviders: description: string; //publications & datasets & orp & software & organizations: projects: Project[]; - + //datasets & orp & publications & software year: string; embargoEndDate: Date | string; authors: Author[]; countriesForResults: string[]; languages: string[]; - + //datasets & orp & software: publisher: string; - + //software programmingLanguages: string[]; - + //dataproviders & projects: organizations: Organization[]; - + //projects: acronym: string; code: string; @@ -43,10 +44,10 @@ export class SearchResult { endYear: number; openAccessMandatePublications: boolean; openAccessMandateDatasets: boolean; - + hostedBy_collectedFrom: HostedByCollectedFrom[]; //organizations: country: string; - + //dataproviders: englishname: string; type: string; @@ -56,11 +57,12 @@ export class SearchResult { compatibilityUNKNOWN: boolean; countries: string[]; subjects: string[]; - + entityType: string; types: string[]; - enermapsId:string; + enermapsId: string; + constructor() { } - + } diff --git a/utils/result-preview/result-preview.component.html b/utils/result-preview/result-preview.component.html index 23c67d02..b59b7ee9 100644 --- a/utils/result-preview/result-preview.component.html +++ b/utils/result-preview/result-preview.component.html @@ -1,20 +1,22 @@
-
- Enermaps tool preview -
+
- -
+ +
- -
- {{type}} - . - - {{beforeTitle.join(' . ')}} - - - . Embargo End Date: {{result.embargoEndDate | date: 'dd MMM yyyy'}} - -
+ +
+ {{type}} + . + + {{beforeTitle.join(' . ')}} + + + . Embargo End Date: {{result.embargoEndDate | date: 'dd MMM yyyy'}} + +
-
+
{{result.accessMode}} {{' '}} - @@ -101,7 +103,8 @@ {{' '}} + class="uk-label uk-label-success uk-text-truncate " + title="Open Access mandate for {{openaireEntities.DATASETS}}"> Open Access mandate for {{openaireEntities.DATASETS}} {{' '}} {{' '}} - {{programmingLanguage}} {{" "}} - - - - - + + + + {{result.compatibility}} {{' '}} - + class="uk-label" [class.uk-label-danger]="deposit" title="OpenAIRE Compatibility"> {{result.compatibility}} in OpenAIRE {{' '}}
@@ -151,7 +154,7 @@ {{openaireEntities.PROJECT}} Code: - {{result.code}} + {{result.code}} @@ -176,7 +179,7 @@
Authors:  + [showAll]=false>
@@ -189,7 +192,7 @@
+ class="uk-margin-small-bottom"> {{(result.countries.length == 1) ? 'Country' : 'Countries'}}: {{country}}{{(i < (result.countries.slice(0, 10).length - 1)) ? ", " : ""}} @@ -205,7 +208,7 @@ | {{ project.acronym ? project.acronym : (project.title.length > 25 ? - project.title.substring(0, 25) + '...' : project.title)}} + project.title.substring(0, 25) + '...' : project.title)}} ({{project.code}}) , @@ -214,7 +217,7 @@
+ class="uk-margin-small-bottom"> Partners: {{organization.name}} @@ -223,7 +226,8 @@ ...
-
+
+ class="uk-margin-small-bottom"> Subject: {{subject}} @@ -252,18 +256,19 @@
+ class="uk-margin-small-bottom"> - - - + + + class="uk-margin-auto-left"> + [resultId]="result.relcanId" [resultTitle]="result.title" + [type]="result.resultType" [pageType]="'search'" + [putCodes]="result.orcidPutCodes" [givenPutCode]="true" [identifiers]="result.identifiers"> - + Added in ORCID: @@ -415,5 +426,5 @@ -
+
diff --git a/utils/result-preview/result-preview.component.less b/utils/result-preview/result-preview.component.less index ee271cfc..d0ddcd5d 100644 --- a/utils/result-preview/result-preview.component.less +++ b/utils/result-preview/result-preview.component.less @@ -1,10 +1,17 @@ // Impact Factors -.popularity-A svg .a, .popularity-C1 svg .a, .popularity-C2 svg .a, .influence-A svg .a, .influence-C1 svg .a, .influence-C2 svg .a { - fill:#d51717; +.popularity-A, .popularity-C1, .popularity-C2, .influence-A, .influence-C1, .influence-C2 { + & svg a { + fill: #d51717; + } } -.popularity-B svg .a, .popularity-C3 svg .a, .popularity-C4 svg .a, .influence-B svg .a, .influence-C3 svg .a, .influence-C4 svg .a { - fill: #e1920a; + +.popularity-B, .popularity-C3, .popularity-C4, .influence-B, .influence-C3, .influence-C4 { + & svg a { + fill: #e1920a; + } } -.popularity-C svg .a, .popularity-C5 svg .a, .influence-C svg .a, .influence-C5 svg .a { - fill: #444; -} \ No newline at end of file + +.popularity-C, .popularity-C5, .influence-C, .influence-C5 { + & svg a { + fill: #444; + }} \ No newline at end of file diff --git a/utils/result-preview/result-preview.component.ts b/utils/result-preview/result-preview.component.ts index a53f4506..e6a6f884 100644 --- a/utils/result-preview/result-preview.component.ts +++ b/utils/result-preview/result-preview.component.ts @@ -12,7 +12,7 @@ import {HelperFunctions} from "../HelperFunctions.class"; @Component({ selector: 'result-preview', templateUrl: 'result-preview.component.html', - styleUrls: ['result-preview.component.less'] + styleUrls: ['result-preview.component.less'] }) export class ResultPreviewComponent implements OnInit, OnChanges { @Input() result: ResultPreview; @@ -23,7 +23,8 @@ export class ResultPreviewComponent implements OnInit, OnChanges { @Input() modal: AlertModal = null; @Input() promoteWebsiteURL: boolean = false; @Input() hasLink: boolean = true; - @Input() isCard: boolean = false; + @Input() isCard: boolean = false; + @Input() isMobile: boolean = false; public routerHelper: RouterHelper = new RouterHelper(); public urlParam: string; public url: string; @@ -34,11 +35,11 @@ export class ResultPreviewComponent implements OnInit, OnChanges { @Input() showOrcid: boolean = true; @Input() showEnermaps: boolean = false; @Input() deposit: boolean = false; - @Input() provenanceActionVocabulary = null; - @Input() relationsVocabulary = null; + @Input() provenanceActionVocabulary = null; + @Input() relationsVocabulary = null; ngOnInit(): void { - if(this.hasLink) { + if (this.hasLink) { if (this.result.resultType === "publication") { this.urlParam = "articleId"; this.url = properties.searchLinkToPublication.split('?')[0]; @@ -52,9 +53,9 @@ export class ResultPreviewComponent implements OnInit, OnChanges { this.urlParam = "orpId"; this.url = properties.searchLinkToOrp.split('?')[0]; } else if (this.result.resultType == "project") { - if(this.result.id) { + if (this.result.id) { this.urlParam = "projectId"; - }else if(this.result.code && this.result.funderShortname){ + } else if (this.result.code && this.result.funderShortname) { this.result.id = this.result.code; this.urlParam = "grantId"; } @@ -63,7 +64,7 @@ export class ResultPreviewComponent implements OnInit, OnChanges { this.urlParam = "organizationId"; this.url = properties.searchLinkToOrganization.split('?')[0]; } else if (this.result.resultType == "dataprovider") { - if(this.result.compatibilityUNKNOWN && properties.adminToolsPortalType == "eosc") { + if (this.result.compatibilityUNKNOWN && properties.adminToolsPortalType == "eosc") { this.urlParam = "serviceId"; this.url = properties.searchLinkToService.split('?')[0]; } else { @@ -80,100 +81,102 @@ export class ResultPreviewComponent implements OnInit, OnChanges { this.checkPID(); } this.initBeforeTitle(); - if(this.result.languages) { + if (this.result.languages) { this.result.languages = this.removeUnknown(this.result.languages); } - if(this.result.countries) { + if (this.result.countries) { this.result.countries = this.removeUnknown(this.result.countries); } } - + ngOnChanges(changes: SimpleChanges) { - if(changes.result && this.hasLink) { + if (changes.result && this.hasLink) { this.checkPID(); } } - + checkPID() { // if result has a pid use it as parameter instead of openaireId - let pid:Identifier =this.getPID(); - if(pid){ + let pid: Identifier = this.getPID(); + if (pid) { this.urlParam = "pid"; this.result.id = pid.id; - + } } + getPID() { return Identifier.getPIDFromIdentifiers(this.result.identifiers); } public initBeforeTitle() { - if(this.result.resultType && this.result.resultType !== 'dataprovider') { + if (this.result.resultType && this.result.resultType !== 'dataprovider') { this.type = this.getTypeName(this.result.resultType); } - if(this.result.types) { + if (this.result.types) { this.removeUnknown(this.removeDuplicates(this.result.types)).forEach(type => { this.beforeTitle.push(type); }); } - if(this.result.year) { + if (this.result.year) { this.beforeTitle.push(this.result.year.toString()); } - if(this.result.startYear && this.result.endYear) { + if (this.result.startYear && this.result.endYear) { this.beforeTitle.push(this.result.startYear.toString() + ' - ' + this.result.endYear.toString()); } - if(this.result.provenanceAction) { + if (this.result.provenanceAction) { let value = HelperFunctions.getVocabularyLabel(this.result.provenanceAction, this.provenanceActionVocabulary, false); - if(value) { + if (value) { this.beforeTitle.push(value); } - } - if(this.result.relationName) { + } + if (this.result.relationName) { this.beforeTitle.push(HelperFunctions.getVocabularyLabel(this.result.relationName, this.relationsVocabulary)); } // if(this.result.percentage) { // this.beforeTitle.push((this.result.relation ? this.result.relation+": " : "") + this.result.percentage.toString() + "%"); // } } - + public getTypeName(type: string): string { return StringUtils.getEntityName(type, false); } - + public removeUnknown(array: string[]): string[] { return array.filter(value => value.toLowerCase() !== 'unknown'); } - + public removeDuplicates(array: string[]): string[] { return array.filter(value => value.toLowerCase() !== this.result.resultType); } - + public accessClass(accessMode: string): string { - if(accessMode.toLowerCase().indexOf('open') !== -1) { + if (accessMode.toLowerCase().indexOf('open') !== -1) { return 'success'; - } else if(accessMode.toLowerCase() === 'not available') { + } else if (accessMode.toLowerCase() === 'not available') { return 'disabled'; // unknown } else { return 'disabled'; // closed } } - + public onClick() { - if(this.modal) { + if (this.modal) { this.modal.cancel(); } } - createParam(){ - if(this.urlParam == "grantId" ){ - return this.routerHelper.createQueryParams([this.urlParam,"funder"],[this.result.id,this.result.funderShortname]) + + createParam() { + if (this.urlParam == "grantId") { + return this.routerHelper.createQueryParams([this.urlParam, "funder"], [this.result.id, this.result.funderShortname]) } - return this.routerHelper.createQueryParam(this.urlParam,this.result.id) + return this.routerHelper.createQueryParam(this.urlParam, this.result.id) } public get isResultType() { return this.result.resultType == "publication" || this.result.resultType == "dataset" || - this.result.resultType == "software" || this.result.resultType == "other" || this.result.resultType == "result"; + this.result.resultType == "software" || this.result.resultType == "other" || this.result.resultType == "result"; } } diff --git a/utils/result-preview/result-preview.ts b/utils/result-preview/result-preview.ts index 4317b7c5..1d15616b 100644 --- a/utils/result-preview/result-preview.ts +++ b/utils/result-preview/result-preview.ts @@ -1,5 +1,5 @@ import {SearchResult} from "../entities/searchResult"; -import {ResultLandingInfo} from "../entities/resultLandingInfo"; +import {Measure, ResultLandingInfo} from "../entities/resultLandingInfo"; import {OrganizationInfo} from "../entities/organizationInfo"; export interface HostedByCollectedFrom { @@ -81,12 +81,12 @@ export class ResultPreview { countries: string[]; //Impact factor - DOI:string; - measure: Array; - + DOI: string; + measure: Measure; + //publications & datasets & orp & software & organizations: projects: Project[]; - + //datasets & orp & publications & software description: string; year: string; @@ -101,13 +101,13 @@ export class ResultPreview { //datasets & orp & software: publisher: string; - + //software programmingLanguages: string[]; - + //dataproviders & projects: organizations: Organization[]; - + //projects: acronym: string; code: string; @@ -120,10 +120,10 @@ export class ResultPreview { endYear: number; openAccessMandatePublications: boolean; openAccessMandateDatasets: boolean; - + //organizations: country: string; - + //dataproviders: englishname: string; websiteURL: string; @@ -131,10 +131,10 @@ export class ResultPreview { compatibility: string; compatibilityUNKNOWN: boolean; subjects: string[]; - + resultType: string; types: string[]; - + // Relation result relationName: string; relation: string; @@ -142,7 +142,8 @@ export class ResultPreview { provenanceAction: string; //enermaps id - image - enermapsId:string; + enermapsId: string; + public static searchResultConvert(result: SearchResult, type: string): ResultPreview { let resultPreview: ResultPreview = new ResultPreview(); resultPreview.id = result.id; @@ -151,9 +152,9 @@ export class ResultPreview { resultPreview.title = result.title.name; resultPreview.accessMode = result.title.accessMode; // resultPreview.sc39 = result.title.sc39; - if(result.countriesForResults) { + if (result.countriesForResults) { resultPreview.countries = result.countriesForResults; - } else if(result.country) { + } else if (result.country) { resultPreview.countries = [result.country]; } else { resultPreview.countries = result.countries; @@ -179,7 +180,7 @@ export class ResultPreview { resultPreview.openAccessMandatePublications = result.openAccessMandatePublications; resultPreview.openAccessMandateDatasets = result.openAccessMandateDatasets; resultPreview.englishname = result.englishname; - if(result.type) { + if (result.type) { resultPreview.types = [result.type]; } else { resultPreview.types = result.types; @@ -197,18 +198,18 @@ export class ResultPreview { // } resultPreview.identifiers = result.identifiers; resultPreview.enermapsId = result.enermapsId; - resultPreview.measure = result.measure; + resultPreview.measure = result.measure; return resultPreview; } - - public static resultLandingInfoConvert(result: ResultLandingInfo, type: string): ResultPreview { + + public static resultLandingInfoConvert(result: ResultLandingInfo, type: string): ResultPreview { let resultPreview: ResultPreview = new ResultPreview(); resultPreview.title = result.title; resultPreview.accessMode = result.accessMode; resultPreview.countries = result.countries; resultPreview.projects = result.fundedByProjects; resultPreview.description = result.description;//.length > 0 ? result.description[0] : ""; - if(result.dateofacceptance) { + if (result.dateofacceptance) { resultPreview.year = new Date(result.dateofacceptance).getFullYear().toString(); } resultPreview.embargoEndDate = result.embargoEndDate; @@ -224,13 +225,13 @@ export class ResultPreview { resultPreview.hostedBy_collectedFrom = result.hostedBy_collectedFrom; return resultPreview; } - + public static relationResultConvert(result: RelationResult): ResultPreview { let resultPreview: ResultPreview = new ResultPreview(); resultPreview.id = result.id; resultPreview.title = result.name; resultPreview.resultType = result.class; - if(result.date) { + if (result.date) { resultPreview.year = result.date.toString(); } resultPreview.relationName = result.relationName; @@ -239,19 +240,19 @@ export class ResultPreview { resultPreview.provenanceAction = result.provenanceAction; return resultPreview; } - + public static organizationConvert(result: Organization, relation: string = 'trust'): ResultPreview { let resultPreview: ResultPreview = new ResultPreview(); resultPreview.id = result.id; - if(result.name) { + if (result.name) { resultPreview.title = result.name; - if(result.shortname) { + if (result.shortname) { resultPreview.title += ' (' + result.shortname + ')'; } - } else if(result.shortname) { + } else if (result.shortname) { resultPreview.title = result.shortname; } - if(result.country) { + if (result.country) { resultPreview.countries = [result.country]; } resultPreview.relation = relation; @@ -260,25 +261,25 @@ export class ResultPreview { resultPreview.resultType = 'organization'; return resultPreview; } - + public static organizationInfoConvert(result: OrganizationInfo): ResultPreview { let resultPreview: ResultPreview = new ResultPreview(); - if(result.title && result.title.name) { + if (result.title && result.title.name) { resultPreview.title = result.title.name; - if(result.name) { + if (result.name) { resultPreview.title += ' (' + result.name + ')'; } - } else if(result.name) { + } else if (result.name) { resultPreview.title = result.name; } - if(result.country) { + if (result.country) { resultPreview.countries = [result.country]; } - if(result.title && result.title.url) { + if (result.title && result.title.url) { resultPreview.websiteURL = result.title.url; } resultPreview.resultType = 'organization'; return resultPreview; } - - } + +}